diff options
Diffstat (limited to 'configmgr2')
-rw-r--r-- | configmgr2/prj/build.lst | 2 | ||||
-rw-r--r-- | configmgr2/source/components.cxx | 3 | ||||
-rw-r--r-- | configmgr2/source/data.cxx | 60 | ||||
-rw-r--r-- | configmgr2/source/data.hxx | 3 | ||||
-rw-r--r-- | configmgr2/source/makefile.mk | 6 | ||||
-rw-r--r-- | configmgr2/source/writemodfile.cxx | 605 | ||||
-rw-r--r-- | configmgr2/source/writemodfile.hxx | 45 | ||||
-rw-r--r-- | configmgr2/source/xml.cxx | 566 | ||||
-rw-r--r-- | configmgr2/source/xml.hxx | 7 |
9 files changed, 715 insertions, 582 deletions
diff --git a/configmgr2/prj/build.lst b/configmgr2/prj/build.lst index c11b3b6fc776..2fd4e03fa442 100644 --- a/configmgr2/prj/build.lst +++ b/configmgr2/prj/build.lst @@ -1,3 +1,3 @@ -cg configmgr : BOOST:boost comphelper cppu cppuhelper libxml2 offuh sal salhelper stlport NULL +cg configmgr : BOOST:boost comphelper cppu cppuhelper offuh sal salhelper stlport NULL cg configmgr\inc nmake - all cg_inc NULL cg configmgr\source nmake - all cg_source cg_inc NULL diff --git a/configmgr2/source/components.cxx b/configmgr2/source/components.cxx index b85326514079..c748dd1bb727 100644 --- a/configmgr2/source/components.cxx +++ b/configmgr2/source/components.cxx @@ -46,6 +46,7 @@ #include "components.hxx" #include "data.hxx" #include "node.hxx" +#include "writemodfile.hxx" #include "xml.hxx" namespace configmgr { @@ -105,7 +106,7 @@ void Components::addModification(rtl::OUString const & path) { } void Components::writeModifications() { - xml::writeModFile(getModificationFileUrl(), data_); + writeModFile(getModificationFileUrl(), data_); } void Components::insertXcsFile(int layer, rtl::OUString const & fileUri) { diff --git a/configmgr2/source/data.cxx b/configmgr2/source/data.cxx index 2c75696284a5..2c589d0de2a8 100644 --- a/configmgr2/source/data.cxx +++ b/configmgr2/source/data.cxx @@ -48,7 +48,6 @@ #include "node.hxx" #include "nodemap.hxx" #include "setnode.hxx" -#include "xml.hxx" namespace configmgr { @@ -61,6 +60,43 @@ bool isPrefix(rtl::OUString const & prefix, rtl::OUString const & path) { path[prefix.getLength()] == '/'; } +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; +} + } rtl::OUString Data::createSegment( @@ -125,7 +161,7 @@ sal_Int32 Data::parseSegment( } sal_Int32 j = path.indexOf(del, i); if (j == -1 || j + 1 == path.getLength() || path[j + 1] != ']' || - !xml::decodeXml(path, i, j, name)) + !decode(path, i, j, name)) { return -1; } @@ -133,6 +169,26 @@ sal_Int32 Data::parseSegment( return j + 2; } +rtl::OUString Data::parseLastSegment( + rtl::OUString const & path, rtl::OUString * name) +{ + OSL_ASSERT(name != 0); + sal_Int32 i = path.getLength(); + OSL_ASSERT(i > 0 && path[i - 1] != '/'); + if (path[i - 1] == ']') { + OSL_ASSERT(i > 2 && (path[i - 2] == '\'' || (path[i - 2] == '"'))); + sal_Int32 j = path.lastIndexOf(path[i - 2], i - 2); + OSL_ASSERT(j > 0); + decode(path, j + 1, i - 2, name); + i = path.lastIndexOf('/', j); + } else { + i = path.lastIndexOf('/'); + *name = path.copy(i + 1); + } + OSL_ASSERT(i != -1); + return path.copy(0, i); +} + rtl::Reference< Node > Data::findNode( int layer, NodeMap const & map, rtl::OUString const & name) { diff --git a/configmgr2/source/data.hxx b/configmgr2/source/data.hxx index 5703d0927513..e2338478d92e 100644 --- a/configmgr2/source/data.hxx +++ b/configmgr2/source/data.hxx @@ -62,6 +62,9 @@ struct Data: private boost::noncopyable { rtl::OUString const & path, sal_Int32 index, rtl::OUString * name, bool * setElement, rtl::OUString * templateName); + static rtl::OUString parseLastSegment( + rtl::OUString const & path, rtl::OUString * name); + static rtl::Reference< Node > findNode( int layer, NodeMap const & map, rtl::OUString const & name); diff --git a/configmgr2/source/makefile.mk b/configmgr2/source/makefile.mk index 2f40701f5ae8..199d98ae05ce 100644 --- a/configmgr2/source/makefile.mk +++ b/configmgr2/source/makefile.mk @@ -38,10 +38,6 @@ VISIBILITY_HIDDEN = TRUE CDEFS += -DOOO_DLLIMPLEMENTATION_CONFIGMGR -.IF "$(SYSTEM_LIBXML)" == "YES" -CFLAGS += $(LIBXML_CFLAGS) -.ENDIF - SLOFILES = \ $(SLO)$/access.obj \ $(SLO)$/childaccess.obj \ @@ -62,6 +58,7 @@ SLOFILES = \ $(SLO)$/setnode.obj \ $(SLO)$/type.obj \ $(SLO)$/update.obj \ + $(SLO)$/writemodfile.obj \ $(SLO)$/xml.obj \ $(SLO)$/xmlreader.obj @@ -71,7 +68,6 @@ SHL1STDLIBS = \ $(COMPHELPERLIB) \ $(CPPUHELPERLIB) \ $(CPPULIB) \ - $(LIBXML2LIB) \ $(SALHELPERLIB) \ $(SALLIB) SHL1TARGET = configmgr diff --git a/configmgr2/source/writemodfile.cxx b/configmgr2/source/writemodfile.cxx new file mode 100644 index 000000000000..d67c3cb4df43 --- /dev/null +++ b/configmgr2/source/writemodfile.cxx @@ -0,0 +1,605 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* $RCSfile: code,v $ +* +* $Revision: 1.4 $ +* +* 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. +************************************************************************/ + +#include "precompiled_configmgr.hxx" +#include "sal/config.h" + +#include "boost/noncopyable.hpp" +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/XInterface.hpp" +#include "osl/diagnose.h" +#include "osl/file.h" +#include "osl/file.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/textcvt.h" +#include "rtl/textenc.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +#include "data.hxx" +#include "groupnode.hxx" +#include "layer.hxx" +#include "localizedpropertynode.hxx" +#include "localizedvaluenode.hxx" +#include "node.hxx" +#include "nodemap.hxx" +#include "propertynode.hxx" +#include "span.hxx" +#include "type.hxx" +#include "writemodfile.hxx" + +namespace configmgr { + +namespace { + +namespace css = com::sun::star; + +rtl::OString convertToUtf8( + rtl::OUString const & text, sal_Int32 offset, sal_Int32 length) +{ + OSL_ASSERT( + offset <= text.getLength() && text.getLength() - offset >= length); + rtl::OString s; + if (!rtl_convertUStringToString( + &s.pData, text.pData->buffer + offset, length, + RTL_TEXTENCODING_UTF8, + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | + RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) + { + throw css::uno::RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("cannot convert to UTF-8")), + css::uno::Reference< css::uno::XInterface >()); + } + return s; +} + +struct TempFile: public boost::noncopyable { + rtl::OUString url; + oslFileHandle handle; + bool closed; + + TempFile(): handle(0), closed(false) {} + + ~TempFile(); +}; + +TempFile::~TempFile() { + if (handle != 0) { + if (!closed) { + oslFileError e = osl_closeFile(handle); + if (e != osl_File_E_None) { + OSL_TRACE( + "osl_closeFile failed with %ld", static_cast< long >(e)); + } + } + osl::FileBase::RC e = osl::File::remove(url); + if (e != osl::FileBase::E_None) { + OSL_TRACE("osl_removeFile failed with %ld", static_cast< long >(e)); + } + } +} + +void writeData(oslFileHandle handle, char const * begin, sal_Int32 length) { + OSL_ASSERT(length >= 0); + sal_uInt64 n; + if ((osl_writeFile(handle, begin, static_cast< sal_uInt32 >(length), &n) != + osl_File_E_None) || + n != static_cast< sal_uInt32 >(length)) + { + throw css::uno::RuntimeException( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("write failure")), + css::uno::Reference< css::uno::XInterface >()); + } +} + +void writeData(oslFileHandle handle, rtl::OString const & text) { + writeData(handle, text.getStr(), text.getLength()); +} + +void writeAttributeValue(oslFileHandle handle, rtl::OUString const & value) { + sal_Int32 i = 0; + sal_Int32 j = i; + for (; j < value.getLength(); ++j) { + OSL_ASSERT( + value[j] == 0x0009 || value[j] == 0x000A || value[j] == 0x000D || + (value[j] >= 0x0020 && value[j] != 0xFFFE && value[j] != 0xFFFF)); + switch(value[j]) { + case '\x09': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("	")); + i = j + 1; + break; + case '\x0A': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("
")); + i = j + 1; + break; + case '\x0D': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("
")); + i = j + 1; + break; + case '"': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM(""")); + i = j + 1; + break; + case '&': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("&")); + i = j + 1; + break; + case '<': + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<")); + i = j + 1; + break; + default: + break; + } + } + writeData(handle, convertToUtf8(value, i, j - i)); +} + +void writeValueContent(oslFileHandle handle, sal_Bool value) { + if (value) { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("true")); + } else { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("false")); + } +} + +void writeValueContent(oslFileHandle handle, sal_Int16 value) { + writeData(handle, rtl::OString::valueOf(static_cast< sal_Int32 >(value))); +} + +void writeValueContent(oslFileHandle handle, sal_Int32 value) { + writeData(handle, rtl::OString::valueOf(value)); +} + +void writeValueContent(oslFileHandle handle, sal_Int64 value) { + writeData(handle, rtl::OString::valueOf(value)); +} + +void writeValueContent(oslFileHandle handle, double value) { + writeData(handle, rtl::OString::valueOf(value)); +} + +void writeValueContent(oslFileHandle handle, rtl::OUString const & value) { + sal_Int32 i = 0; + sal_Int32 j = i; + for (; j < value.getLength(); ++j) { + sal_Unicode c = value[j]; + if ((c < 0x0020 && c != 0x0009 && c != 0x000A && c != 0x000D) || + c == 0xFFFE || c == 0xFFFF) + { + writeData(handle, convertToUtf8(value, i, j - i)); + writeData( + handle, RTL_CONSTASCII_STRINGPARAM("<unicode oor:scalar=\"")); + writeData( + handle, rtl::OString::valueOf(static_cast< sal_Int32 >(c))); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"/>")); + i = j + 1; + } else if (c == '\x0D') { + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("
")); + i = j + 1; + } else if (c == '&') { + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("&")); + i = j + 1; + } else if (c == '<') { + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<")); + i = j + 1; + } else if (c == '>') { + // "MUST, for compatibility, be escaped [...] when it appears in the + // string ']]>'": + writeData(handle, convertToUtf8(value, i, j - i)); + writeData(handle, RTL_CONSTASCII_STRINGPARAM(">")); + i = j + 1; + } + } + writeData(handle, convertToUtf8(value, i, j - i)); +} + +void writeValueContent( + oslFileHandle handle, css::uno::Sequence< sal_Int8 > const & value) +{ + for (sal_Int32 i = 0; i < value.getLength(); ++i) { + static char const hexDigit[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', + 'D', 'E', 'F' }; + writeData(handle, hexDigit + ((value[i] >> 4) & 0xF), 1); + writeData(handle, hexDigit + (value[i] & 0xF), 1); + } +} + +template< typename T > void writeSingleValue( + oslFileHandle handle, css::uno::Any const & value) +{ + writeData(handle, RTL_CONSTASCII_STRINGPARAM(">")); + T val = T(); + value >>= val; + writeValueContent(handle, val); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</value>")); +} + +template< typename T > void writeListValue( + oslFileHandle handle, css::uno::Any const & value) +{ + writeData(handle, RTL_CONSTASCII_STRINGPARAM(">")); + css::uno::Sequence< T > val; + value >>= val; + for (sal_Int32 i = 0; i < val.getLength(); ++i) { + if (i != 0) { + writeData(handle, RTL_CONSTASCII_STRINGPARAM(" ")); + } + writeValueContent(handle, val[i]); + } + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</value>")); +} + +template< typename T > void writeItemListValue( + oslFileHandle handle, css::uno::Any const & value) +{ + writeData(handle, RTL_CONSTASCII_STRINGPARAM(">")); + css::uno::Sequence< T > val; + value >>= val; + for (sal_Int32 i = 0; i < val.getLength(); ++i) { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<it>")); + writeValueContent(handle, val[i]); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</it>")); + } + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</value>")); +} + +void writeValue(oslFileHandle handle, Type type, css::uno::Any const & value) { + switch (type) { + case TYPE_NIL: + writeData(handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>")); + break; + case TYPE_BOOLEAN: + writeSingleValue< sal_Bool >(handle, value); + break; + case TYPE_SHORT: + writeSingleValue< sal_Int16 >(handle, value); + break; + case TYPE_INT: + writeSingleValue< sal_Int32 >(handle, value); + break; + case TYPE_LONG: + writeSingleValue< sal_Int64 >(handle, value); + break; + case TYPE_DOUBLE: + writeSingleValue< double >(handle, value); + break; + case TYPE_STRING: + writeSingleValue< rtl::OUString >(handle, value); + break; + case TYPE_HEXBINARY: + writeSingleValue< css::uno::Sequence< sal_Int8 > >(handle, value); + break; + case TYPE_BOOLEAN_LIST: + writeListValue< sal_Bool >(handle, value); + break; + case TYPE_SHORT_LIST: + writeListValue< sal_Int16 >(handle, value); + break; + case TYPE_INT_LIST: + writeListValue< sal_Int32 >(handle, value); + break; + case TYPE_LONG_LIST: + writeListValue< sal_Int64 >(handle, value); + break; + case TYPE_DOUBLE_LIST: + writeListValue< double >(handle, value); + break; + case TYPE_STRING_LIST: + writeItemListValue< rtl::OUString >(handle, value); + break; + case TYPE_HEXBINARY_LIST: + writeItemListValue< css::uno::Sequence< sal_Int8 > >(handle, value); + break; + default: // TYPE_ERROR, TYPE_ANY + OSL_ASSERT(false); // this cannot happen + } +} + +void writeNode( + oslFileHandle handle, rtl::Reference< Node > const & parent, + rtl::OUString const & name, rtl::Reference< Node > const & node, + bool topLevel) +{ + static Span const typeNames[] = { + Span(), Span(), Span(), // TYPE_ERROR, TYPE_NIL, TYPE_ANY + Span(RTL_CONSTASCII_STRINGPARAM("xs:boolean")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:short")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:int")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:long")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:double")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:string")), + Span(RTL_CONSTASCII_STRINGPARAM("xs:hexBinary")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:boolean-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:short-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:int-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:long-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:double-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:string-list")), + Span(RTL_CONSTASCII_STRINGPARAM("oor:hexBinary-list")) }; + switch (node->kind()) { + case Node::KIND_PROPERTY: + { + PropertyNode * prop = dynamic_cast< PropertyNode * >(node.get()); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\"")); + writeAttributeValue(handle, name); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"fuse\"")); + Type type = prop->getType(); + if (type == TYPE_ANY) { + type = mapType(prop->getValue()); + if (type != TYPE_ERROR) { //TODO + writeData( + handle, RTL_CONSTASCII_STRINGPARAM(" oor:type=\"")); + writeData( + handle, typeNames[type].begin, typeNames[type].length); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"")); + } + } + writeData(handle, "><value"); + writeValue(handle, type, prop->getValue()); + writeData(handle, "</prop>"); + } + break; + case Node::KIND_LOCALIZED_PROPERTY: + { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\"")); + writeAttributeValue(handle, name); + writeData( + handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"fuse\">")); + for (NodeMap::iterator i(node->getMembers().begin()); + i != node->getMembers().end(); ++i) + { + if (!i->second->isRemoved()) { + writeNode( + handle, node, i->first, i->second, + topLevel && node->getLayer() != NO_LAYER); + } + } + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</prop>")); + } + break; + case Node::KIND_LOCALIZED_VALUE: + { + LocalizedValueNode * locval = dynamic_cast< LocalizedValueNode * >( + node.get()); + if (locval->isRemoved() + ? topLevel && locval->getLayer() == NO_LAYER + : !topLevel || locval->getLayer() == NO_LAYER) + { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<value")); + if (name.getLength() != 0) { + writeData( + handle, RTL_CONSTASCII_STRINGPARAM(" xml:lang=\"")); + writeAttributeValue(handle, name); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"")); + } + if (locval->isRemoved()) { + writeData( + handle, + RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"remove\"/>")); + } else { + Type type = dynamic_cast< LocalizedPropertyNode * >( + parent.get())->getType(); + if (type == TYPE_ANY) { + type = mapType(locval->getValue()); + if (type != TYPE_ERROR) { // TODO + writeData( + handle, + RTL_CONSTASCII_STRINGPARAM(" oor:type=\"")); + writeData( + handle, + typeNames[type].begin, typeNames[type].length); + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"")); + } + } + writeValue(handle, type, locval->getValue()); + } + } + } + break; + case Node::KIND_GROUP: + case Node::KIND_SET: + { + writeData(handle, RTL_CONSTASCII_STRINGPARAM("<node oor:name=\"")); + writeAttributeValue(handle, name); + if (node->getTemplateName().getLength() != 0) { // set member + writeData( + handle, + RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"replace")); + } + writeData(handle, RTL_CONSTASCII_STRINGPARAM("\">")); + for (NodeMap::iterator i(node->getMembers().begin()); + i != node->getMembers().end(); ++i) + { + if (!i->second->isRemoved()) { + writeNode(handle, node, i->first, i->second, false); + } + } + writeData(handle, RTL_CONSTASCII_STRINGPARAM("</node>")); + } + break; + } +} + +} + +void writeModFile(rtl::OUString const & url, Data const & data) { + sal_Int32 i = url.lastIndexOf('/'); + OSL_ASSERT(i != -1); + rtl::OUString dir(url.copy(0, i)); + switch (osl::Directory::createPath(dir)) { + case osl::FileBase::E_None: + case osl::FileBase::E_EXIST: + break; + default: + throw css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("cannot create directory ")) + + dir), + css::uno::Reference< css::uno::XInterface >()); + } + TempFile tmp; + if (osl::FileBase::createTempFile(&dir, &tmp.handle, &tmp.url) != + osl::FileBase::E_None) + { + throw css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "cannot create temporary file in ")) + + dir), + css::uno::Reference< css::uno::XInterface >()); + } + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?><oor:items" + " xmlns:oor=\"http://openoffice.org/2001/registry\"" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">")); + //TODO: Do not write back information about those removed items that did not + // come from the .xcs/.xcu files, anyway (but had been added dynamically + // instead): + for (Data::Modifications::const_iterator j(data.modifications.begin()); + j != data.modifications.end(); ++j) + { + writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("<item oor:path=\"")); + rtl::OUString name; + rtl::OUString parentPath(Data::parseLastSegment(*j, &name)); + rtl::Reference< Node > parent; + rtl::Reference< Node > node(data.resolvePath(*j, 0, 0, 0, &parent, 0)); + if (node.is()) { + writeAttributeValue(tmp.handle, parentPath); + writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("\">")); + writeNode(tmp.handle, parent, name, node, true); + writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</item>")); + // It is never necessary to write the oor:mandatory attribute, as it + // cannot be set via the UNO API. + } else { + parent = data.resolvePath(parentPath, 0, 0, 0, 0, 0); + NodeMap::iterator k(parent->getMembers().find(name)); + if (k != parent->getMembers().end() && + k->second->getLayer() == NO_LAYER) + { + OSL_ASSERT(k->second->isRemoved()); + switch (parent->kind()) { + case Node::KIND_LOCALIZED_PROPERTY: + { + rtl::OUString parentName; + rtl::OUString grandparentPath( + Data::parseLastSegment(parentPath, &parentName)); + writeAttributeValue(tmp.handle, grandparentPath); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM("\"><prop oor:name=\"")); + writeAttributeValue(tmp.handle, parentName); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM( + "\" oor:op=\"fuse\"><value")); + if (name.getLength() != 0) { + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM(" xml:lang=\"")); + writeAttributeValue(tmp.handle, name); + writeData( + tmp.handle, RTL_CONSTASCII_STRINGPARAM("\"")); + } + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM( + " oor:op=\"remove\"/></prop></item>")); + } + break; + case Node::KIND_GROUP: + OSL_ASSERT( + dynamic_cast< GroupNode * >(parent.get())-> + isExtensible()); + writeAttributeValue(tmp.handle, parentPath); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM("\"><prop oor:name=\"")); + writeAttributeValue(tmp.handle, name); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM( + "\" oor:op=\"remove\"/></item>")); + break; + case Node::KIND_SET: + writeAttributeValue(tmp.handle, parentPath); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM("\"><node oor:name=\"")); + writeAttributeValue(tmp.handle, name); + writeData( + tmp.handle, + RTL_CONSTASCII_STRINGPARAM( + "\" oor:op=\"remove\"/></item>")); + break; + default: + OSL_ASSERT(false); // this cannot happen + break; + } + } + } + } + writeData(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</oor:items>")); + oslFileError e = osl_closeFile(tmp.handle); + tmp.closed = true; + if (e != osl_File_E_None) { + throw css::uno::RuntimeException( + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cannot close ")) + + tmp.url), + css::uno::Reference< css::uno::XInterface >()); + } + if (osl::File::move(tmp.url, url) != osl::FileBase::E_None) { + throw css::uno::RuntimeException( + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cannot move ")) + + tmp.url), + css::uno::Reference< css::uno::XInterface >()); + } + tmp.handle = 0; +} + +} diff --git a/configmgr2/source/writemodfile.hxx b/configmgr2/source/writemodfile.hxx new file mode 100644 index 000000000000..e7ad7e26d945 --- /dev/null +++ b/configmgr2/source/writemodfile.hxx @@ -0,0 +1,45 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2009 by Sun Microsystems, Inc. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* $RCSfile: code,v $ +* +* $Revision: 1.4 $ +* +* 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. +************************************************************************/ + +#ifndef INCLUDED_CONFIGMGR_WRITEMODFILE_HXX +#define INCLUDED_CONFIGMGR_WRITEMODFILE_HXX + +#include "sal/config.h" + +namespace rtl { class OUString; } + +namespace configmgr { + +struct Data; + +void writeModFile(rtl::OUString const & url, Data const & data); + +} + +#endif diff --git a/configmgr2/source/xml.cxx b/configmgr2/source/xml.cxx index 55bcfbccbbf6..4cbc92a47e50 100644 --- a/configmgr2/source/xml.cxx +++ b/configmgr2/source/xml.cxx @@ -42,11 +42,8 @@ #include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/uno/XInterface.hpp" #include "comphelper/sequenceasvector.hxx" -#include "libxml/xmlstring.h" -#include "libxml/xmlwriter.h" #include "osl/diagnose.h" #include "osl/file.hxx" -#include "osl/thread.hxx" #include "rtl/ref.hxx" #include "rtl/strbuf.hxx" #include "rtl/string.h" @@ -81,26 +78,6 @@ namespace { namespace css = com::sun::star; -rtl::OUString parseLastSegment( - rtl::OUString const & path, rtl::OUString * name) -{ - OSL_ASSERT(name != 0); - sal_Int32 i = path.getLength(); - OSL_ASSERT(i > 0 && path[i - 1] != '/'); - if (path[i - 1] == ']') { - OSL_ASSERT(i > 2 && (path[i - 2] == '\'' || (path[i - 2] == '"'))); - sal_Int32 j = path.lastIndexOf(path[i - 2], i - 2); - OSL_ASSERT(j > 0); - decodeXml(path, j + 1, i - 2, name); - i = path.lastIndexOf('/', j); - } else { - i = path.lastIndexOf('/'); - *name = path.copy(i + 1); - } - OSL_ASSERT(i != -1); - return path.copy(0, i); -} - rtl::OUString fullTemplateName( rtl::OUString const & component, rtl::OUString const & name) { @@ -111,10 +88,6 @@ rtl::OUString fullTemplateName( return buf.makeStringAndClear(); } -xmlChar const * xmlString(char const * str) { - return reinterpret_cast< xmlChar const * >(str); -} - rtl::OUString convertFromUtf8(Span const & text) { OSL_ASSERT(text.is()); rtl_uString * s = 0; @@ -132,56 +105,6 @@ rtl::OUString convertFromUtf8(Span const & text) { return rtl::OUString(s, SAL_NO_ACQUIRE); } -rtl::OString convertToUtf8( - rtl::OUString const & text, sal_Int32 offset, sal_Int32 length) -{ - OSL_ASSERT( - offset <= text.getLength() && text.getLength() - offset >= length); - rtl::OString s; - if (!rtl_convertUStringToString( - &s.pData, text.pData->buffer + offset, length, - RTL_TEXTENCODING_UTF8, - (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | - RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) - { - throw css::uno::RuntimeException( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("cannot convert to UTF-8")), - css::uno::Reference< css::uno::XInterface >()); - } - return s; -} - -rtl::OString convertToUtf8(rtl::OUString const & text) { - return convertToUtf8(text, 0, text.getLength()); -} - -rtl::OString convertToFilepath(rtl::OUString const & url) { - rtl::OUString path1; - if (osl::FileBase::getSystemPathFromFileURL(url, path1) != - osl::FileBase::E_None) - { - throw css::uno::RuntimeException( - (rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("cannot get system path for ")) + - url), - css::uno::Reference< css::uno::XInterface >()); - } - rtl::OString path2; - if (!path1.convertToString( - &path2, osl_getThreadTextEncoding(), - (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | - RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) - { - throw css::uno::RuntimeException( - (rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("cannot translate system path ")) + - path1), - css::uno::Reference< css::uno::XInterface >()); - } - return path2; -} - enum Operation { OPERATION_MODIFY, OPERATION_REPLACE, OPERATION_FUSE, OPERATION_REMOVE }; @@ -501,338 +424,6 @@ rtl::OUString parseTemplateReference( convertFromUtf8(nodeType)); } -struct XmlTextWriter: private boost::noncopyable { - xmlTextWriterPtr writer; - - explicit XmlTextWriter(xmlTextWriterPtr theWriter): writer(theWriter) {} - - ~XmlTextWriter() { xmlFreeTextWriter(writer); } -}; - -void writeBooleanValue(xmlTextWriterPtr writer, sal_Bool const & value) { - xmlTextWriterWriteString( - writer, xmlString(value ? "true" : "false")); -} - -void writeShortValue(xmlTextWriterPtr writer, sal_Int16 const & value) { - xmlTextWriterWriteString( - writer, xmlString(rtl::OString::valueOf(sal_Int32(value)).getStr())); -} - -void writeIntValue(xmlTextWriterPtr writer, sal_Int32 const & value) { - xmlTextWriterWriteString( - writer, xmlString(rtl::OString::valueOf(value).getStr())); -} - -void writeLongValue(xmlTextWriterPtr writer, sal_Int64 const & value) { - xmlTextWriterWriteString( - writer, xmlString(rtl::OString::valueOf(value).getStr())); -} - -void writeDoubleValue(xmlTextWriterPtr writer, double const & value) { - xmlTextWriterWriteString( - writer, xmlString(rtl::OString::valueOf(value).getStr())); -} - -void writeStringValue(xmlTextWriterPtr writer, rtl::OUString const & value) { - sal_Int32 i = 0; - sal_Int32 j = i; - for (; j < value.getLength(); ++j) { - sal_Unicode c = value[j]; - if ((c < 0x0020 && c != 0x0009 && c != 0x000A && c != 0x000D) || - c == 0xFFFE || c == 0xFFFF) - { - if (j > i) { - xmlTextWriterWriteString( - writer, - xmlString(convertToUtf8(value, i, j - i).getStr())); - } - xmlTextWriterStartElement(writer, xmlString("unicode")); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:scalar"), - xmlString( - rtl::OString::valueOf(static_cast< sal_Int32 >(c)). - getStr())); - xmlTextWriterEndElement(writer); - i = j + 1; - } - } - if (j > i) { - xmlTextWriterWriteString( - writer, xmlString(convertToUtf8(value, i, j - i).getStr())); - } -} - -void writeHexbinaryValue( - xmlTextWriterPtr writer, css::uno::Sequence< sal_Int8 > const & value) -{ - rtl::OStringBuffer buf; - for (sal_Int32 i = 0; i < value.getLength(); ++i) { - static char const hexDigit[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', - 'D', 'E', 'F' }; - buf.append(hexDigit[(value[i] >> 4) & 0xF]); - buf.append(hexDigit[value[i] & 0xF]); - } - xmlTextWriterWriteString( - writer, xmlString(buf.makeStringAndClear().getStr())); -} - -template< typename T > void writeListValue( - xmlTextWriterPtr writer, void (* write)(xmlTextWriterPtr, T const &), - css::uno::Any const & value) -{ - css::uno::Sequence< T > val; - value >>= val; - for (sal_Int32 i = 0; i < val.getLength(); ++i) { - if (i != 0) { - xmlTextWriterWriteString(writer, xmlString(" ")); - } - (*write)(writer, val[i]); - } -} - -template< typename T > void writeItemListValue( - xmlTextWriterPtr writer, void (* write)(xmlTextWriterPtr, T const &), - css::uno::Any const & value) -{ - css::uno::Sequence< T > val; - value >>= val; - for (sal_Int32 i = 0; i < val.getLength(); ++i) { - xmlTextWriterStartElement(writer, xmlString("it")); - (*write)(writer, val[i]); - xmlTextWriterEndElement(writer); - } -} - -void writeValue(xmlTextWriterPtr writer, Type type, css::uno::Any const & value) -{ - switch (type) { - case TYPE_NIL: - xmlTextWriterWriteAttribute( - writer, xmlString("xsi:nil"), xmlString("true")); - break; - case TYPE_BOOLEAN: - { - bool val = bool(); - value >>= val; - writeBooleanValue(writer, val); - } - break; - case TYPE_SHORT: - { - sal_Int16 val; - value >>= val; - writeShortValue(writer, val); - } - break; - case TYPE_INT: - { - sal_Int32 val; - value >>= val; - writeIntValue(writer, val); - } - break; - case TYPE_LONG: - { - sal_Int64 val; - value >>= val; - writeLongValue(writer, val); - } - break; - case TYPE_DOUBLE: - { - double val; - value >>= val; - writeDoubleValue(writer, val); - } - break; - case TYPE_STRING: - { - rtl::OUString val; - value >>= val; - writeStringValue(writer, val); - } - break; - case TYPE_HEXBINARY: - { - css::uno::Sequence< sal_Int8 > val; - value >>= val; - writeHexbinaryValue(writer, val); - } - break; - case TYPE_BOOLEAN_LIST: - writeListValue(writer, &writeBooleanValue, value); - break; - case TYPE_SHORT_LIST: - writeListValue(writer, &writeShortValue, value); - break; - case TYPE_INT_LIST: - writeListValue(writer, &writeIntValue, value); - break; - case TYPE_LONG_LIST: - writeListValue(writer, &writeLongValue, value); - break; - case TYPE_DOUBLE_LIST: - writeListValue(writer, &writeDoubleValue, value); - break; - case TYPE_STRING_LIST: - writeItemListValue(writer, &writeStringValue, value); - break; - case TYPE_HEXBINARY_LIST: - writeItemListValue(writer, &writeHexbinaryValue, value); - break; - default: // TYPE_ERROR, TYPE_ANY - OSL_ASSERT(false); - throw css::uno::RuntimeException( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")), - css::uno::Reference< css::uno::XInterface >()); - } -} - -void writeNode( - xmlTextWriterPtr writer, rtl::Reference< Node > const & parent, - rtl::OUString const & name, rtl::Reference< Node > const & node, - bool topLevel) -{ - static char const * const typeNames[] = { - 0, 0, 0, // TYPE_ERROR, TYPE_NIL, TYPE_ANY - "xs:boolean", // TYPE_BOOLEAN - "xs:short", // TYPE_SHORT - "xs:int", // TYPE_INT - "xs:long", // TYPE_LONG - "xs:double", // TYPE_DOUBLE - "xs:string", // TYPE_STRING - "xs:hexBinary", // TYPE_HEXBINARY - "oor:boolean-list", // TYPE_BOOLEAN_LIST - "oor:short-list", // TYPE_SHORT_LIST - "oor:int-list", // TYPE_INT_LIST - "oor:long-list", // TYPE_LONG_LIST - "oor:double-list", // TYPE_DOUBLE_LIST - "oor:string-list", // TYPE_STRING_LIST - "oor:hexBinary-list" }; // TYPE_HEXBINARY_LIST - switch (node->kind()) { - case Node::KIND_PROPERTY: - { - PropertyNode * prop = dynamic_cast< PropertyNode * >(node.get()); - xmlTextWriterStartElement(writer, xmlString("prop")); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:op"), xmlString("fuse")); - Type type = prop->getType(); - if (type == TYPE_ANY) { - type = mapType(prop->getValue()); - if (type != TYPE_ERROR) { //TODO - xmlTextWriterWriteAttribute( - writer, xmlString("oor:type"), - xmlString(typeNames[type])); - } - } - xmlTextWriterStartElement(writer, xmlString("value")); - writeValue(writer, type, prop->getValue()); - xmlTextWriterEndElement(writer); - xmlTextWriterEndElement(writer); - } - break; - case Node::KIND_LOCALIZED_PROPERTY: - { - xmlTextWriterStartElement(writer, xmlString("prop")); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:op"), xmlString("fuse")); - for (NodeMap::iterator i(node->getMembers().begin()); - i != node->getMembers().end(); ++i) - { - if (!i->second->isRemoved()) { - writeNode( - writer, node, i->first, i->second, - topLevel && node->getLayer() != NO_LAYER); - } - } - xmlTextWriterEndElement(writer); - } - break; - case Node::KIND_LOCALIZED_VALUE: - { - LocalizedValueNode * locval = dynamic_cast< LocalizedValueNode * >( - node.get()); - if (locval->isRemoved() - ? topLevel && locval->getLayer() == NO_LAYER - : !topLevel || locval->getLayer() == NO_LAYER) - { - xmlTextWriterStartElement(writer, xmlString("value")); - if (name.getLength() != 0) { - xmlTextWriterWriteAttribute( - writer, xmlString("xml:lang"), - xmlString(convertToUtf8(name).getStr())); - } - if (locval->isRemoved()) { - xmlTextWriterWriteAttribute( - writer, xmlString("oor:op"), xmlString("remove")); - } else { - Type type = dynamic_cast< LocalizedPropertyNode * >( - parent.get())->getType(); - if (type == TYPE_ANY) { - type = mapType(locval->getValue()); - if (type != TYPE_ERROR) { // TODO - xmlTextWriterWriteAttribute( - writer, xmlString("oor:type"), - xmlString(typeNames[type])); - } - } - writeValue(writer, type, locval->getValue()); - } - xmlTextWriterEndElement(writer); - } - } - break; - case Node::KIND_GROUP: - { - xmlTextWriterStartElement(writer, xmlString("node")); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - if (node->getTemplateName().getLength() != 0) { // set member - xmlTextWriterWriteAttribute( - writer, xmlString("oor:op"), xmlString("replace")); - } - for (NodeMap::iterator i(node->getMembers().begin()); - i != node->getMembers().end(); ++i) - { - if (!i->second->isRemoved()) { - writeNode(writer, node, i->first, i->second, false); - } - } - xmlTextWriterEndElement(writer); - } - break; - case Node::KIND_SET: - { - xmlTextWriterStartElement(writer, xmlString("node")); - xmlTextWriterWriteAttribute( - writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - if (node->getTemplateName().getLength() != 0) { // set member - xmlTextWriterWriteAttribute( - writer, xmlString("oor:op"), xmlString("replace")); - } - for (NodeMap::iterator i(node->getMembers().begin()); - i != node->getMembers().end(); ++i) - { - if (!i->second->isRemoved()) { - writeNode(writer, node, i->first, i->second, false); - } - } - xmlTextWriterEndElement(writer); - } - break; - } -} - class ValueParser: private boost::noncopyable { public: ValueParser(int layer): layer_(layer) {} @@ -2727,43 +2318,6 @@ void XcdParser::characters(Span const & text) { } } -bool decodeXml( - 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; -} - void parseXcsFile(rtl::OUString const & url, int layer, Data * data) { OSL_VERIFY( rtl::Reference< Reader >(new Reader(url, new XcsParser(layer, data)))-> @@ -2791,126 +2345,6 @@ void parseModFile(rtl::OUString const & url, Data * data) { parseXcuFile(url, NO_LAYER, data); //TODO: atomic check for existence } -void writeModFile(rtl::OUString const & url, Data const & data) { - XmlTextWriter writer( - xmlNewTextWriterFilename(convertToFilepath(url).getStr(), 0)); - if (writer.writer == 0) { - //TODO: As long as there is no UserInstallation directory yet, - // xmlNewTextWriterFilename will legitimately fail (but also print noise - // to stderr): - return; - } - xmlTextWriterStartDocument(writer.writer, 0, 0, 0); - xmlTextWriterStartElement(writer.writer, xmlString("oor:items")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("xmlns:oor"), - xmlString("http://openoffice.org/2001/registry")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("xmlns:xs"), - xmlString("http://www.w3.org/2001/XMLSchema")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("xmlns:xsi"), - xmlString("http://www.w3.org/2001/XMLSchema-instance")); - //TODO: Do not write back information about those removed items that did not - // come from the .xcs/.xcu files, anyway (but had been added dynamically - // instead): - for (Data::Modifications::const_iterator i(data.modifications.begin()); - i != data.modifications.end(); ++i) - { - rtl::OUString name; - rtl::OUString parentPath(parseLastSegment(*i, &name)); - rtl::Reference< Node > parent; - rtl::Reference< Node > node(data.resolvePath(*i, 0, 0, 0, &parent, 0)); - if (node.is()) { - xmlTextWriterStartElement(writer.writer, xmlString("item")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:path"), - xmlString(convertToUtf8(parentPath).getStr())); - writeNode(writer.writer, parent, name, node, true); - xmlTextWriterEndElement(writer.writer); - // It is never necessary to write the oor:mandatory attribute, as it - // cannot be set via the UNO API. - } else { - parent = data.resolvePath(parentPath, 0, 0, 0, 0, 0); - NodeMap::iterator j(parent->getMembers().find(name)); - if (j != parent->getMembers().end() && - j->second->getLayer() == NO_LAYER) - { - OSL_ASSERT(j->second->isRemoved()); - xmlTextWriterStartElement(writer.writer, xmlString("item")); - switch (parent->kind()) { - case Node::KIND_LOCALIZED_PROPERTY: - { - rtl::OUString parentName; - rtl::OUString grandparentPath( - parseLastSegment(parentPath, &parentName)); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:path"), - xmlString(convertToUtf8(grandparentPath).getStr())); - xmlTextWriterStartElement( - writer.writer, xmlString("prop")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:name"), - xmlString(convertToUtf8(parentName).getStr())); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:op"), - xmlString("fuse")); - xmlTextWriterStartElement( - writer.writer, xmlString("value")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("xml:lang"), - xmlString(convertToUtf8(name).getStr())); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:op"), - xmlString("remove")); - xmlTextWriterEndElement(writer.writer); - xmlTextWriterEndElement(writer.writer); - } - break; - case Node::KIND_GROUP: - OSL_ASSERT( - dynamic_cast< GroupNode * >(parent.get())-> - isExtensible()); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:path"), - xmlString(convertToUtf8(parentPath).getStr())); - xmlTextWriterStartElement(writer.writer, xmlString("prop")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:op"), - xmlString("remove")); - xmlTextWriterEndElement(writer.writer); - break; - case Node::KIND_SET: - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:path"), - xmlString(convertToUtf8(parentPath).getStr())); - xmlTextWriterStartElement(writer.writer, xmlString("node")); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:name"), - xmlString(convertToUtf8(name).getStr())); - xmlTextWriterWriteAttribute( - writer.writer, xmlString("oor:op"), - xmlString("remove")); - xmlTextWriterEndElement(writer.writer); - break; - default: - OSL_ASSERT(false); // this cannot happen - break; - } - xmlTextWriterEndElement(writer.writer); - } - } - } - if (xmlTextWriterEndDocument(writer.writer) == -1) { //TODO: check all -1? - throw css::uno::RuntimeException( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cannot write ")) + url, - css::uno::Reference< css::uno::XInterface >()); - } -} - } } diff --git a/configmgr2/source/xml.hxx b/configmgr2/source/xml.hxx index 555c25834337..b9d4971f7ba7 100644 --- a/configmgr2/source/xml.hxx +++ b/configmgr2/source/xml.hxx @@ -37,7 +37,6 @@ #include "rtl/ref.hxx" #include "rtl/ustring.hxx" -#include "sal/types.h" #include "salhelper/simplereferenceobject.hxx" #include "span.hxx" @@ -114,18 +113,12 @@ private: long nesting_; }; -bool decodeXml( //TODO - rtl::OUString const & encoded, sal_Int32 begin, sal_Int32 end, - rtl::OUString * decoded); - void parseXcsFile(rtl::OUString const & url, int layer, Data * data); void parseXcuFile(rtl::OUString const & url, int layer, Data * data); void parseModFile(rtl::OUString const & url, Data * data); -void writeModFile(rtl::OUString const & url, Data const & data); - } } |