2010-10-12 08:53:47 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-08-07 03:25:27 -05:00
|
|
|
/*************************************************************************
|
2010-02-25 08:59:15 -06:00
|
|
|
*
|
2009-08-07 03:25:27 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
2010-02-25 08:59:15 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2009-08-07 03:25:27 -05:00
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* This file is part of OpenOffice.org.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2010-02-25 08:59:15 -06:00
|
|
|
*
|
2009-08-07 03:25:27 -05:00
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "precompiled_configmgr.hxx"
|
|
|
|
#include "sal/config.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2009-09-22 10:15:42 -05:00
|
|
|
#include "com/sun/star/uno/Reference.hxx"
|
2009-08-07 03:25:27 -05:00
|
|
|
#include "com/sun/star/uno/RuntimeException.hpp"
|
|
|
|
#include "com/sun/star/uno/XInterface.hpp"
|
|
|
|
#include "osl/diagnose.h"
|
|
|
|
#include "rtl/ref.hxx"
|
|
|
|
#include "rtl/string.h"
|
2010-08-12 03:22:02 -05:00
|
|
|
#include "rtl/textenc.h"
|
2009-08-07 03:25:27 -05:00
|
|
|
#include "rtl/ustrbuf.hxx"
|
|
|
|
#include "rtl/ustring.h"
|
|
|
|
#include "rtl/ustring.hxx"
|
|
|
|
#include "sal/types.h"
|
|
|
|
|
2010-08-12 03:22:02 -05:00
|
|
|
#include "additions.hxx"
|
2009-08-07 03:25:27 -05:00
|
|
|
#include "data.hxx"
|
|
|
|
#include "groupnode.hxx"
|
|
|
|
#include "node.hxx"
|
|
|
|
#include "nodemap.hxx"
|
|
|
|
#include "setnode.hxx"
|
|
|
|
|
|
|
|
namespace configmgr {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
namespace css = com::sun::star;
|
|
|
|
|
2009-09-07 10:10:16 -05:00
|
|
|
bool decode(
|
|
|
|
rtl::OUString const & encoded, sal_Int32 begin, sal_Int32 end,
|
|
|
|
rtl::OUString * decoded)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(
|
|
|
|
begin >= 0 && begin <= end && end <= encoded.getLength() &&
|
|
|
|
decoded != 0);
|
|
|
|
rtl::OUStringBuffer buf;
|
|
|
|
while (begin != end) {
|
|
|
|
sal_Unicode c = encoded[begin++];
|
|
|
|
if (c == '&') {
|
|
|
|
if (encoded.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("amp;"), begin))
|
|
|
|
{
|
|
|
|
buf.append(sal_Unicode('&'));
|
|
|
|
begin += RTL_CONSTASCII_LENGTH("amp;");
|
|
|
|
} else if (encoded.matchAsciiL(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("quot;"), begin))
|
|
|
|
{
|
|
|
|
buf.append(sal_Unicode('"'));
|
|
|
|
begin += RTL_CONSTASCII_LENGTH("quot;");
|
|
|
|
} else if (encoded.matchAsciiL(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("apos;"), begin))
|
|
|
|
{
|
|
|
|
buf.append(sal_Unicode('\''));
|
|
|
|
begin += RTL_CONSTASCII_LENGTH("apos;");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
OSL_ASSERT(begin <= end);
|
|
|
|
} else {
|
|
|
|
buf.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*decoded = buf.makeStringAndClear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-07 03:25:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
rtl::OUString Data::createSegment(
|
|
|
|
rtl::OUString const & templateName, rtl::OUString const & name)
|
|
|
|
{
|
|
|
|
if (templateName.getLength() == 0) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
rtl::OUStringBuffer buf(templateName);
|
|
|
|
//TODO: verify template name contains no bad chars?
|
|
|
|
buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("['"));
|
|
|
|
for (sal_Int32 i = 0; i < name.getLength(); ++i) {
|
|
|
|
sal_Unicode c = name[i];
|
|
|
|
switch (c) {
|
|
|
|
case '&':
|
|
|
|
buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("&"));
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("""));
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("'"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buf.append(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("']"));
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 Data::parseSegment(
|
|
|
|
rtl::OUString const & path, sal_Int32 index, rtl::OUString * name,
|
|
|
|
bool * setElement, rtl::OUString * templateName)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(
|
|
|
|
index >= 0 && index <= path.getLength() && name != 0 &&
|
|
|
|
setElement != 0);
|
|
|
|
sal_Int32 i = index;
|
|
|
|
while (i < path.getLength() && path[i] != '/' && path[i] != '[') {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i == path.getLength() || path[i] == '/') {
|
|
|
|
*name = path.copy(index, i - index);
|
|
|
|
*setElement = false;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (templateName != 0) {
|
|
|
|
if (i - index == 1 && path[index] == '*') {
|
|
|
|
*templateName = rtl::OUString();
|
|
|
|
} else {
|
|
|
|
*templateName = path.copy(index, i - index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (++i == path.getLength()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sal_Unicode del = path[i++];
|
|
|
|
if (del != '\'' && del != '"') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sal_Int32 j = path.indexOf(del, i);
|
|
|
|
if (j == -1 || j + 1 == path.getLength() || path[j + 1] != ']' ||
|
2009-09-07 10:10:16 -05:00
|
|
|
!decode(path, i, j, name))
|
2009-08-07 03:25:27 -05:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*setElement = true;
|
|
|
|
return j + 2;
|
|
|
|
}
|
|
|
|
|
2009-09-08 07:59:07 -05:00
|
|
|
rtl::OUString Data::fullTemplateName(
|
|
|
|
rtl::OUString const & component, rtl::OUString const & name)
|
|
|
|
{
|
2009-10-09 08:13:55 -05:00
|
|
|
if (component.indexOf(':') != -1 || name.indexOf(':') != -1) {
|
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"bad component/name pair containing colon ")) +
|
|
|
|
component + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) +
|
|
|
|
name),
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
2009-09-08 07:59:07 -05:00
|
|
|
rtl::OUStringBuffer buf(component);
|
|
|
|
buf.append(sal_Unicode(':'));
|
|
|
|
buf.append(name);
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2009-10-09 08:13:55 -05:00
|
|
|
bool Data::equalTemplateNames(
|
|
|
|
rtl::OUString const & shortName, rtl::OUString const & longName)
|
|
|
|
{
|
|
|
|
if (shortName.indexOf(':') == -1) {
|
|
|
|
sal_Int32 i = longName.indexOf(':') + 1;
|
|
|
|
OSL_ASSERT(i > 0);
|
|
|
|
return
|
|
|
|
rtl_ustr_compare_WithLength(
|
|
|
|
shortName.getStr(), shortName.getLength(),
|
|
|
|
longName.getStr() + i, longName.getLength() - i) ==
|
|
|
|
0;
|
|
|
|
} else {
|
|
|
|
return shortName == longName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-07 03:25:27 -05:00
|
|
|
rtl::Reference< Node > Data::findNode(
|
|
|
|
int layer, NodeMap const & map, rtl::OUString const & name)
|
|
|
|
{
|
|
|
|
NodeMap::const_iterator i(map.find(name));
|
2009-09-16 10:01:38 -05:00
|
|
|
return i == map.end() || i->second->getLayer() > layer
|
2009-08-07 03:25:27 -05:00
|
|
|
? rtl::Reference< Node >() : i->second;
|
|
|
|
}
|
|
|
|
|
2009-09-22 10:15:42 -05:00
|
|
|
rtl::Reference< Node > Data::resolvePathRepresentation(
|
2010-04-16 04:36:30 -05:00
|
|
|
rtl::OUString const & pathRepresentation,
|
|
|
|
rtl::OUString * canonicRepresentation, Path * path, int * finalizedLayer)
|
2009-09-22 10:15:42 -05:00
|
|
|
const
|
2009-08-07 03:25:27 -05:00
|
|
|
{
|
2009-09-22 10:15:42 -05:00
|
|
|
if (pathRepresentation.getLength() == 0 || pathRepresentation[0] != '/') {
|
2009-08-07 03:25:27 -05:00
|
|
|
throw css::uno::RuntimeException(
|
2009-09-22 10:15:42 -05:00
|
|
|
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
|
|
|
pathRepresentation),
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
2009-08-07 03:25:27 -05:00
|
|
|
}
|
|
|
|
rtl::OUString seg;
|
|
|
|
bool setElement;
|
2010-04-16 04:36:30 -05:00
|
|
|
rtl::OUString templateName;
|
2009-09-22 10:15:42 -05:00
|
|
|
sal_Int32 n = parseSegment(pathRepresentation, 1, &seg, &setElement, 0);
|
2009-08-07 03:25:27 -05:00
|
|
|
if (n == -1 || setElement)
|
|
|
|
{
|
|
|
|
throw css::uno::RuntimeException(
|
2009-09-22 10:15:42 -05:00
|
|
|
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
|
|
|
pathRepresentation),
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
2009-08-07 03:25:27 -05:00
|
|
|
}
|
|
|
|
NodeMap::const_iterator i(components.find(seg));
|
2010-04-16 04:36:30 -05:00
|
|
|
rtl::OUStringBuffer canonic;
|
2009-09-22 10:15:42 -05:00
|
|
|
if (path != 0) {
|
|
|
|
path->clear();
|
|
|
|
}
|
|
|
|
rtl::Reference< Node > parent;
|
2009-08-07 03:25:27 -05:00
|
|
|
int finalized = NO_LAYER;
|
|
|
|
for (rtl::Reference< Node > p(i == components.end() ? 0 : i->second);;) {
|
|
|
|
if (!p.is()) {
|
|
|
|
return p;
|
|
|
|
}
|
2010-04-16 04:36:30 -05:00
|
|
|
if (canonicRepresentation != 0) {
|
|
|
|
canonic.append(sal_Unicode('/'));
|
|
|
|
canonic.append(createSegment(templateName, seg));
|
|
|
|
}
|
2009-09-22 10:15:42 -05:00
|
|
|
if (path != 0) {
|
|
|
|
path->push_back(seg);
|
2009-08-07 03:25:27 -05:00
|
|
|
}
|
|
|
|
finalized = std::min(finalized, p->getFinalized());
|
2009-09-22 10:15:42 -05:00
|
|
|
if (n != pathRepresentation.getLength() &&
|
|
|
|
pathRepresentation[n++] != '/')
|
|
|
|
{
|
2009-08-07 03:25:27 -05:00
|
|
|
throw css::uno::RuntimeException(
|
2009-09-22 10:15:42 -05:00
|
|
|
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
|
|
|
pathRepresentation),
|
2009-08-07 03:25:27 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
// for backwards compatibility, ignore a final slash
|
2009-09-22 10:15:42 -05:00
|
|
|
if (n == pathRepresentation.getLength()) {
|
2010-04-16 04:36:30 -05:00
|
|
|
if (canonicRepresentation != 0) {
|
|
|
|
*canonicRepresentation = canonic.makeStringAndClear();
|
|
|
|
}
|
2009-08-07 03:25:27 -05:00
|
|
|
if (finalizedLayer != 0) {
|
|
|
|
*finalizedLayer = finalized;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2009-09-22 10:15:42 -05:00
|
|
|
parent = p;
|
2010-04-16 04:36:30 -05:00
|
|
|
templateName = rtl::OUString();
|
2009-09-22 10:15:42 -05:00
|
|
|
n = parseSegment(
|
|
|
|
pathRepresentation, n, &seg, &setElement, &templateName);
|
2009-08-07 03:25:27 -05:00
|
|
|
if (n == -1) {
|
|
|
|
throw css::uno::RuntimeException(
|
2009-09-22 10:15:42 -05:00
|
|
|
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
|
|
|
pathRepresentation),
|
2009-08-07 03:25:27 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
2009-09-17 06:35:30 -05:00
|
|
|
// For backwards compatibility, allow set members to be accessed with
|
|
|
|
// simple path segments, like group members:
|
|
|
|
p = p->getMember(seg);
|
2009-08-07 03:25:27 -05:00
|
|
|
if (setElement) {
|
2009-09-22 10:15:42 -05:00
|
|
|
switch (parent->kind()) {
|
2009-09-11 03:11:42 -05:00
|
|
|
case Node::KIND_LOCALIZED_PROPERTY:
|
|
|
|
if (templateName.getLength() != 0) {
|
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
2009-09-22 10:15:42 -05:00
|
|
|
pathRepresentation),
|
2009-09-11 03:11:42 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Node::KIND_SET:
|
|
|
|
if (templateName.getLength() != 0 &&
|
2009-09-22 10:15:42 -05:00
|
|
|
!dynamic_cast< SetNode * >(parent.get())->isValidTemplate(
|
2009-09-11 03:11:42 -05:00
|
|
|
templateName))
|
|
|
|
{
|
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
2009-09-22 10:15:42 -05:00
|
|
|
pathRepresentation),
|
2009-09-11 03:11:42 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2009-08-07 03:25:27 -05:00
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
2009-09-22 10:15:42 -05:00
|
|
|
pathRepresentation),
|
2009-08-07 03:25:27 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
if (templateName.getLength() != 0 && p != 0) {
|
2009-10-09 08:13:55 -05:00
|
|
|
OSL_ASSERT(p->getTemplateName().getLength() != 0);
|
|
|
|
if (!equalTemplateNames(templateName, p->getTemplateName())) {
|
2009-08-07 03:25:27 -05:00
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM("bad path ")) +
|
2009-09-22 10:15:42 -05:00
|
|
|
pathRepresentation),
|
2009-08-07 03:25:27 -05:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rtl::Reference< Node > Data::getTemplate(
|
|
|
|
int layer, rtl::OUString const & fullName) const
|
|
|
|
{
|
|
|
|
return findNode(layer, templates, fullName);
|
|
|
|
}
|
|
|
|
|
2010-08-12 03:22:02 -05:00
|
|
|
Additions * Data::addExtensionXcuAdditions(
|
|
|
|
rtl::OUString const & url, int layer)
|
|
|
|
{
|
|
|
|
rtl::Reference< ExtensionXcu > item(new ExtensionXcu);
|
|
|
|
ExtensionXcuAdditions::iterator i(
|
|
|
|
extensionXcuAdditions_.insert(
|
|
|
|
ExtensionXcuAdditions::value_type(
|
|
|
|
url, rtl::Reference< ExtensionXcu >())).first);
|
|
|
|
if (i->second.is()) {
|
|
|
|
throw css::uno::RuntimeException(
|
|
|
|
(rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"already added extension xcu ")) +
|
|
|
|
url),
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
i->second = item;
|
|
|
|
item->layer = layer;
|
|
|
|
return &item->additions;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtl::Reference< Data::ExtensionXcu > Data::removeExtensionXcuAdditions(
|
|
|
|
rtl::OUString const & url)
|
|
|
|
{
|
|
|
|
ExtensionXcuAdditions::iterator i(extensionXcuAdditions_.find(url));
|
|
|
|
if (i == extensionXcuAdditions_.end()) {
|
|
|
|
// This can happen, as migration of pre OOo 3.3 UserInstallation
|
|
|
|
// extensions in dp_registry::backend::configuration::BackendImpl::
|
|
|
|
// PackageImpl::processPackage_ can cause just-in-time creation of
|
|
|
|
// extension xcu files that are never added via addExtensionXcuAdditions
|
|
|
|
// (also, there might be url spelling differences between calls to
|
|
|
|
// addExtensionXcuAdditions and removeExtensionXcuAdditions?):
|
|
|
|
OSL_TRACE(
|
|
|
|
"unknown configmgr::Data::removeExtensionXcuAdditions(%s)",
|
|
|
|
rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr());
|
|
|
|
return rtl::Reference< ExtensionXcu >();
|
|
|
|
}
|
|
|
|
rtl::Reference< ExtensionXcu > item(i->second);
|
|
|
|
extensionXcuAdditions_.erase(i);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2009-08-07 03:25:27 -05:00
|
|
|
}
|
2010-10-12 08:53:47 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|