summaryrefslogtreecommitdiff
path: root/configmgr
diff options
context:
space:
mode:
authorsb <sb@openoffice.org>2009-11-10 10:30:50 +0100
committersb <sb@openoffice.org>2009-11-10 10:30:50 +0100
commitefa6cd05d30bc5c660c289d9252e07c619eefa6b (patch)
treee1a9e4872448be662036c31780353414aa57e837 /configmgr
parent4f61c8f406d95f895bb4e74c8538e3129c017805 (diff)
sb111: #i101955# the span returned by XmlReader::getAttributeValue is only valid until the next call to nextItem or getAttributeValue
Diffstat (limited to 'configmgr')
-rw-r--r--configmgr/source/makefile.mk2
-rw-r--r--configmgr/source/valueparser.cxx21
-rw-r--r--configmgr/source/valueparser.hxx5
-rw-r--r--configmgr/source/xcsparser.cxx161
-rw-r--r--configmgr/source/xcuparser.cxx252
-rw-r--r--configmgr/source/xcuparser.hxx3
-rw-r--r--configmgr/source/xmldata.cxx21
-rw-r--r--configmgr/source/xmldata.hxx7
-rw-r--r--configmgr/source/xmlreader.hxx2
9 files changed, 270 insertions, 204 deletions
diff --git a/configmgr/source/makefile.mk b/configmgr/source/makefile.mk
index 38a412394028..ae51a7c2a323 100644
--- a/configmgr/source/makefile.mk
+++ b/configmgr/source/makefile.mk
@@ -64,8 +64,8 @@ SLOFILES = \
$(SLO)/valueparser.obj \
$(SLO)/writemodfile.obj \
$(SLO)/xcdparser.obj \
- $(SLO)/xcuparser.obj \
$(SLO)/xcsparser.obj \
+ $(SLO)/xcuparser.obj \
$(SLO)/xmldata.obj \
$(SLO)/xmlreader.obj
diff --git a/configmgr/source/valueparser.cxx b/configmgr/source/valueparser.cxx
index 061aeca7a4ac..479485311826 100644
--- a/configmgr/source/valueparser.cxx
+++ b/configmgr/source/valueparser.cxx
@@ -162,14 +162,14 @@ template< typename T > css::uno::Any parseSingleValue(Span const & text) {
}
template< typename T > css::uno::Any parseListValue(
- Span const & separator, Span const & text)
+ rtl::OString const & separator, Span const & text)
{
comphelper::SequenceAsVector< T > seq;
Span sep;
- if (separator.is()) {
- sep = separator;
- } else {
+ if (separator.getLength() == 0) {
sep = Span(RTL_CONSTASCII_STRINGPARAM(" "));
+ } else {
+ sep = Span(separator.getStr(), separator.getLength());
}
if (text.length != 0) {
for (Span t(text);;) {
@@ -192,7 +192,9 @@ template< typename T > css::uno::Any parseListValue(
return css::uno::makeAny(seq.getAsConstList());
}
-css::uno::Any parseValue(Span const & separator, Span const & text, Type type) {
+css::uno::Any parseValue(
+ rtl::OString const & separator, Span const & text, Type type)
+{
switch (type) {
case TYPE_ANY:
throw css::uno::RuntimeException(
@@ -249,7 +251,7 @@ XmlReader::Text ValueParser::getTextMode() const {
case STATE_IT:
return
(type_ == TYPE_STRING || type_ == TYPE_STRING_LIST ||
- separator_.is())
+ separator_.getLength() != 0)
? XmlReader::TEXT_RAW : XmlReader::TEXT_NORMALIZED;
default:
break;
@@ -268,7 +270,7 @@ bool ValueParser::startElement(
case STATE_TEXT:
if (ns == XmlReader::NAMESPACE_NONE &&
name.equals(RTL_CONSTASCII_STRINGPARAM("it")) &&
- isListType(type_) && !separator_.is())
+ isListType(type_) && separator_.getLength() == 0)
{
checkEmptyPad(reader);
state_ = STATE_IT;
@@ -392,7 +394,7 @@ bool ValueParser::endElement(XmlReader const & reader) {
OSL_ASSERT(false); // this cannot happen
break;
}
- separator_.clear();
+ separator_ = rtl::OString();
node_.clear();
}
break;
@@ -401,7 +403,8 @@ bool ValueParser::endElement(XmlReader const & reader) {
state_ = State(state_ - 1);
break;
case STATE_IT:
- items_.push_back(parseValue(Span(), pad_.get(), elementType(type_)));
+ items_.push_back(
+ parseValue(rtl::OString(), pad_.get(), elementType(type_)));
pad_.clear();
state_ = STATE_TEXT;
break;
diff --git a/configmgr/source/valueparser.hxx b/configmgr/source/valueparser.hxx
index 6153966f54ca..d0e3c9162856 100644
--- a/configmgr/source/valueparser.hxx
+++ b/configmgr/source/valueparser.hxx
@@ -36,10 +36,10 @@
#include "boost/noncopyable.hpp"
#include "rtl/ref.hxx"
+#include "rtl/string.hxx"
#include "rtl/ustring.hxx"
#include "pad.hxx"
-#include "span.hxx"
#include "type.hxx"
#include "xmlreader.hxx"
@@ -50,6 +50,7 @@ namespace com { namespace sun { namespace star { namespace uno {
namespace configmgr {
class Node;
+class Span;
class ValueParser: private boost::noncopyable {
public:
@@ -73,7 +74,7 @@ public:
int getLayer() const;
Type type_;
- Span separator_;
+ rtl::OString separator_;
private:
void checkEmptyPad(XmlReader const & reader) const;
diff --git a/configmgr/source/xcsparser.cxx b/configmgr/source/xcsparser.cxx
index 898853061993..d1f2201cf084 100644
--- a/configmgr/source/xcsparser.cxx
+++ b/configmgr/source/xcsparser.cxx
@@ -40,6 +40,7 @@
#include "rtl/ref.hxx"
#include "rtl/strbuf.hxx"
#include "rtl/string.h"
+#include "rtl/string.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
@@ -274,8 +275,10 @@ void XcsParser::characters(Span const & text) {
void XcsParser::handleComponentSchema(XmlReader & reader) {
//TODO: oor:version, xml:lang attributes
- Span attrPackage;
- Span attrName;
+ rtl::OStringBuffer buf;
+ buf.append('.');
+ bool hasPackage = false;
+ bool hasName = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -285,14 +288,35 @@ void XcsParser::handleComponentSchema(XmlReader & reader) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("package")))
{
- attrPackage = reader.getAttributeValue(false);
+ if (hasPackage) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "multiple component-schema package attributes"
+ " in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ hasPackage = true;
+ Span s(reader.getAttributeValue(false));
+ buf.insert(0, s.begin, s.length);
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ if (hasName) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "multiple component-schema name attributes in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ hasName = true;
+ Span s(reader.getAttributeValue(false));
+ buf.append(s.begin, s.length);
}
}
- if (!attrPackage.is()) {
+ if (!hasPackage) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
@@ -300,7 +324,7 @@ void XcsParser::handleComponentSchema(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
@@ -308,18 +332,16 @@ void XcsParser::handleComponentSchema(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OStringBuffer buf;
- buf.append(attrPackage.begin, attrPackage.length);
- buf.append('.');
- buf.append(attrName.begin, attrName.length);
componentName_ = xmldata::convertFromUtf8(
Span(buf.getStr(), buf.getLength()));
}
void XcsParser::handleNodeRef(XmlReader & reader) {
- Span attrName;
- Span attrComponent;
- Span attrNodeType;
+ bool hasName = false;
+ rtl::OUString name;
+ rtl::OUString component(componentName_);
+ bool hasNodeType = false;
+ rtl::OUString nodeType;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -329,18 +351,22 @@ void XcsParser::handleNodeRef(XmlReader & reader) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
{
- attrComponent = reader.getAttributeValue(false);
+ component = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
{
- attrNodeType = reader.getAttributeValue(false);
+ hasNodeType = true;
+ nodeType = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no node-ref name attribute in ")) +
@@ -351,28 +377,27 @@ void XcsParser::handleNodeRef(XmlReader & reader) {
data_->getTemplate(
valueParser_.getLayer(),
xmldata::parseTemplateReference(
- attrComponent, attrNodeType, componentName_, 0)));
+ component, hasNodeType, nodeType, 0)));
if (!tmpl.is()) {
//TODO: this can erroneously happen as long as import/uses attributes
// are not correctly processed
throw css::uno::RuntimeException(
- (rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("unknown node-ref ")) +
- xmldata::convertFromUtf8(attrName) +
- rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" in ")) +
+ (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unknown node-ref ")) +
+ name + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
rtl::Reference< Node > node(tmpl->clone());
node->setLayer(valueParser_.getLayer());
- elements_.push(Element(node, xmldata::convertFromUtf8(attrName)));
+ elements_.push(Element(node, name));
}
void XcsParser::handleProp(XmlReader & reader) {
- Span attrName;
- Span attrType;
- Span attrLocalized;
- Span attrNillable;
+ bool hasName = false;
+ rtl::OUString name;
+ valueParser_.type_ = TYPE_ERROR;
+ bool localized = false;
+ bool nillable = true;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -382,29 +407,30 @@ void XcsParser::handleProp(XmlReader & reader) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("type")))
{
- attrType = reader.getAttributeValue(true);
+ valueParser_.type_ = xmldata::parseType(
+ reader, reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("localized")))
{
- attrLocalized = reader.getAttributeValue(true);
+ localized = xmldata::parseBoolean(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("nillable")))
{
- attrNillable = reader.getAttributeValue(true);
+ nillable = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no prop name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- valueParser_.type_ = xmldata::parseType(reader, attrType);
if (valueParser_.type_ == TYPE_ERROR) {
throw css::uno::RuntimeException(
(rtl::OUString(
@@ -412,8 +438,6 @@ void XcsParser::handleProp(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- bool localized = xmldata::parseBoolean(attrLocalized, false);
- bool nillable = xmldata::parseBoolean(attrNillable, true);
elements_.push(
Element(
(localized
@@ -424,7 +448,7 @@ void XcsParser::handleProp(XmlReader & reader) {
new PropertyNode(
valueParser_.getLayer(), valueParser_.type_, nillable,
css::uno::Any(), false))),
- xmldata::convertFromUtf8(attrName)));
+ name));
}
void XcsParser::handlePropValue(
@@ -441,15 +465,25 @@ void XcsParser::handlePropValue(
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator")))
{
attrSeparator = reader.getAttributeValue(false);
+ if (attrSeparator.length == 0) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "bad oor:separator attribute in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
}
}
- valueParser_.separator_ = attrSeparator;
+ valueParser_.separator_ = rtl::OString(
+ attrSeparator.begin, attrSeparator.length);
valueParser_.start(property);
}
void XcsParser::handleGroup(XmlReader & reader, bool isTemplate) {
- Span attrName;
- Span attrExtensible;
+ bool hasName = false;
+ rtl::OUString name;
+ bool extensible = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -459,37 +493,38 @@ void XcsParser::handleGroup(XmlReader & reader, bool isTemplate) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("extensible")))
{
- attrExtensible = reader.getAttributeValue(true);
+ extensible = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no group name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OUString name(xmldata::convertFromUtf8(attrName));
if (isTemplate) {
name = Data::fullTemplateName(componentName_, name);
}
elements_.push(
Element(
new GroupNode(
- valueParser_.getLayer(),
- xmldata::parseBoolean(attrExtensible, false),
+ valueParser_.getLayer(), extensible,
isTemplate ? name : rtl::OUString()),
name));
}
void XcsParser::handleSet(XmlReader & reader, bool isTemplate) {
- Span attrName;
- Span attrComponent;
- Span attrNodeType;
+ bool hasName = false;
+ rtl::OUString name;
+ rtl::OUString component(componentName_);
+ bool hasNodeType = false;
+ rtl::OUString nodeType;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -499,25 +534,28 @@ void XcsParser::handleSet(XmlReader & reader, bool isTemplate) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
{
- attrComponent = reader.getAttributeValue(false);
+ component = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
{
- attrNodeType = reader.getAttributeValue(false);
+ hasNodeType = true;
+ nodeType = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no set name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OUString name(xmldata::convertFromUtf8(attrName));
if (isTemplate) {
name = Data::fullTemplateName(componentName_, name);
}
@@ -526,14 +564,15 @@ void XcsParser::handleSet(XmlReader & reader, bool isTemplate) {
new SetNode(
valueParser_.getLayer(),
xmldata::parseTemplateReference(
- attrComponent, attrNodeType, componentName_, 0),
+ component, hasNodeType, nodeType, 0),
isTemplate ? name : rtl::OUString()),
name));
}
void XcsParser::handleSetItem(XmlReader & reader, SetNode * set) {
- Span attrComponent;
- Span attrNodeType;
+ rtl::OUString component(componentName_);
+ bool hasNodeType;
+ rtl::OUString nodeType;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -543,16 +582,18 @@ void XcsParser::handleSetItem(XmlReader & reader, SetNode * set) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
{
- attrComponent = reader.getAttributeValue(false);
+ component = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
{
- attrNodeType = reader.getAttributeValue(false);
+ hasNodeType = true;
+ nodeType = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
}
}
set->getAdditionalTemplateNames().push_back(
- xmldata::parseTemplateReference(
- attrComponent, attrNodeType, componentName_, 0));
+ xmldata::parseTemplateReference(component, hasNodeType, nodeType, 0));
elements_.push(Element(rtl::Reference< Node >(), rtl::OUString()));
}
diff --git a/configmgr/source/xcuparser.cxx b/configmgr/source/xcuparser.cxx
index 13ee7c0d49eb..a26d24f5abc8 100644
--- a/configmgr/source/xcuparser.cxx
+++ b/configmgr/source/xcuparser.cxx
@@ -40,6 +40,7 @@
#include "rtl/ref.hxx"
#include "rtl/strbuf.hxx"
#include "rtl/string.h"
+#include "rtl/string.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
@@ -233,32 +234,33 @@ void XcuParser::characters(Span const & text) {
valueParser_.characters(text);
}
-XcuParser::Operation XcuParser::parseOperation(
- Span const & text, Operation defaultOperation)
-{
- if (!text.is()) {
- return defaultOperation;
- } else if (text.equals(RTL_CONSTASCII_STRINGPARAM("modify"))) {
+XcuParser::Operation XcuParser::parseOperation(Span const & text) {
+ OSL_ASSERT(text.is());
+ if (text.equals(RTL_CONSTASCII_STRINGPARAM("modify"))) {
return OPERATION_MODIFY;
- } else if (text.equals(RTL_CONSTASCII_STRINGPARAM("replace"))) {
+ }
+ if (text.equals(RTL_CONSTASCII_STRINGPARAM("replace"))) {
return OPERATION_REPLACE;
- } else if (text.equals(RTL_CONSTASCII_STRINGPARAM("fuse"))) {
+ }
+ if (text.equals(RTL_CONSTASCII_STRINGPARAM("fuse"))) {
return OPERATION_FUSE;
- } else if (text.equals(RTL_CONSTASCII_STRINGPARAM("remove"))) {
+ }
+ if (text.equals(RTL_CONSTASCII_STRINGPARAM("remove"))) {
return OPERATION_REMOVE;
- } else {
- throw css::uno::RuntimeException(
- (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid op ")) +
- xmldata::convertFromUtf8(text)),
- css::uno::Reference< css::uno::XInterface >());
}
+ throw css::uno::RuntimeException(
+ (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid op ")) +
+ xmldata::convertFromUtf8(text)),
+ css::uno::Reference< css::uno::XInterface >());
}
void XcuParser::handleComponentData(XmlReader & reader) {
- Span attrPackage;
- Span attrName;
- Span attrOp;
- Span attrFinalized;
+ rtl::OStringBuffer buf;
+ buf.append('.');
+ bool hasPackage = false;
+ bool hasName = false;
+ Operation op = OPERATION_MODIFY;
+ bool finalized = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -268,22 +270,43 @@ void XcuParser::handleComponentData(XmlReader & reader) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("package")))
{
- attrPackage = reader.getAttributeValue(false);
+ if (hasPackage) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "multiple component-update package attributes"
+ " in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ hasPackage = true;
+ Span s(reader.getAttributeValue(false));
+ buf.insert(0, s.begin, s.length);
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ if (hasName) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "multiple component-update name attributes in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ hasName = true;
+ Span s(reader.getAttributeValue(false));
+ buf.append(s.begin, s.length);
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("op")))
{
- attrOp = reader.getAttributeValue(true);
+ op = parseOperation(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("finalized")))
{
- attrFinalized = reader.getAttributeValue(true);
+ finalized = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrPackage.is()) {
+ if (!hasPackage) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
@@ -291,7 +314,7 @@ void XcuParser::handleComponentData(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
@@ -299,10 +322,6 @@ void XcuParser::handleComponentData(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OStringBuffer buf;
- buf.append(attrPackage.begin, attrPackage.length);
- buf.append('.');
- buf.append(attrName.begin, attrName.length);
componentName_ = xmldata::convertFromUtf8(
Span(buf.getStr(), buf.getLength()));
rtl::Reference< Node > node(
@@ -316,7 +335,7 @@ void XcuParser::handleComponentData(XmlReader & reader) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- switch (parseOperation(attrOp, OPERATION_MODIFY)) {
+ switch (op) {
case OPERATION_MODIFY:
case OPERATION_FUSE:
break;
@@ -329,8 +348,7 @@ void XcuParser::handleComponentData(XmlReader & reader) {
css::uno::Reference< css::uno::XInterface >());
}
int finalizedLayer = std::min(
- (xmldata::parseBoolean(attrFinalized, false)
- ? valueParser_.getLayer() : Data::NO_LAYER),
+ finalized ? valueParser_.getLayer() : Data::NO_LAYER,
node->getFinalized());
node->setFinalized(finalizedLayer);
state_.push(State(node, finalizedLayer < valueParser_.getLayer()));
@@ -382,9 +400,9 @@ void XcuParser::handleItem(XmlReader & reader) {
}
void XcuParser::handlePropValue(XmlReader & reader, PropertyNode * prop) {
- Span attrNil;
- Span attrSeparator;
- Span attrExternal;
+ bool nil = false;
+ rtl::OString separator;
+ rtl::OUString external;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -394,18 +412,35 @@ void XcuParser::handlePropValue(XmlReader & reader, PropertyNode * prop) {
if (attrNs == XmlReader::NAMESPACE_XSI &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("nil")))
{
- attrNil = reader.getAttributeValue(true);
+ nil = xmldata::parseBoolean(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator")))
{
- attrSeparator = reader.getAttributeValue(false);
+ Span s(reader.getAttributeValue(false));
+ if (s.length == 0) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "bad oor:separator attribute in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ separator = rtl::OString(s.begin, s.length);
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("external")))
{
- attrExternal = reader.getAttributeValue(true);
+ external = xmldata::convertFromUtf8(reader.getAttributeValue(true));
+ if (external.getLength() == 0) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "bad oor:external attribute value in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
}
}
- if (xmldata::parseBoolean(attrNil, false)) {
+ if (nil) {
if (!prop->isNillable()) {
throw css::uno::RuntimeException(
(rtl::OUString(
@@ -414,7 +449,7 @@ void XcuParser::handlePropValue(XmlReader & reader, PropertyNode * prop) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- if (attrExternal.is()) {
+ if (external.getLength() != 0) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
@@ -424,31 +459,22 @@ void XcuParser::handlePropValue(XmlReader & reader, PropertyNode * prop) {
}
prop->setValue(valueParser_.getLayer(), css::uno::Any());
state_.push(State());
- } else if (attrExternal.is()) {
- rtl::OUString external(xmldata::convertFromUtf8(attrExternal));
- if (external.getLength() == 0) {
- throw css::uno::RuntimeException(
- (rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM(
- "bad oor:external attribute value in ")) +
- reader.getUrl()),
- css::uno::Reference< css::uno::XInterface >());
- }
+ } else if (external.getLength() == 0) {
+ valueParser_.separator_ = separator;
+ valueParser_.start(prop);
+ } else {
prop->setExternal(valueParser_.getLayer(), external);
state_.push(State());
- } else {
- valueParser_.separator_ = attrSeparator;
- valueParser_.start(prop);
}
}
void XcuParser::handleLocpropValue(
XmlReader & reader, LocalizedPropertyNode * locprop)
{
- Span attrLang;
- Span attrNil;
- Span attrSeparator;
- Span attrOp;
+ rtl::OUString name;
+ bool nil = false;
+ rtl::OString separator;
+ Operation op = OPERATION_FUSE;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -458,25 +484,30 @@ void XcuParser::handleLocpropValue(
if (attrNs == XmlReader::NAMESPACE_XML &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("lang")))
{
- attrLang = reader.getAttributeValue(false);
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_XSI &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("nil")))
{
- attrNil = reader.getAttributeValue(true);
+ nil = xmldata::parseBoolean(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator")))
{
- attrSeparator = reader.getAttributeValue(false);
+ Span s(reader.getAttributeValue(false));
+ if (s.length == 0) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "bad oor:separator attribute in ")) +
+ reader.getUrl()),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ separator = rtl::OString(s.begin, s.length);
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("op")))
{
- attrOp = reader.getAttributeValue(true);
+ op = parseOperation(reader.getAttributeValue(true));
}
}
- rtl::OUString name;
- if (attrLang.is()) {
- name = xmldata::convertFromUtf8(attrLang);
- }
NodeMap::iterator i(locprop->getMembers().find(name));
if (i != locprop->getMembers().end() &&
i->second->getLayer() > valueParser_.getLayer())
@@ -484,7 +515,6 @@ void XcuParser::handleLocpropValue(
state_.push(State()); // ignored
return;
}
- bool nil = xmldata::parseBoolean(attrNil, false);
if (nil && !locprop->isNillable()) {
throw css::uno::RuntimeException(
(rtl::OUString(
@@ -493,7 +523,7 @@ void XcuParser::handleLocpropValue(
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- switch (parseOperation(attrOp, OPERATION_FUSE)) {
+ switch (op) {
case OPERATION_FUSE:
if (nil) {
if (i == locprop->getMembers().end()) {
@@ -505,7 +535,7 @@ void XcuParser::handleLocpropValue(
}
state_.push(State());
} else {
- valueParser_.separator_ = attrSeparator;
+ valueParser_.separator_ = separator;
valueParser_.start(locprop, name);
}
if (!modificationPath_.empty()) {
@@ -538,10 +568,11 @@ void XcuParser::handleLocpropValue(
}
void XcuParser::handleGroupProp(XmlReader & reader, GroupNode * group) {
- Span attrName;
- Span attrType;
- Span attrOp;
- Span attrFinalized;
+ bool hasName = false;
+ rtl::OUString name;
+ Type type = TYPE_ERROR;
+ Operation op = OPERATION_MODIFY;
+ bool finalized = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -551,30 +582,29 @@ void XcuParser::handleGroupProp(XmlReader & reader, GroupNode * group) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("type")))
{
- attrType = reader.getAttributeValue(true);
+ type = xmldata::parseType(reader, reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("op")))
{
- attrOp = reader.getAttributeValue(true);
+ op = parseOperation(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("finalized")))
{
- attrFinalized = reader.getAttributeValue(true);
+ finalized = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no prop name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OUString name(xmldata::convertFromUtf8(attrName));
- Type type = xmldata::parseType(reader, attrType);
if (type == TYPE_ANY) {
throw css::uno::RuntimeException(
(rtl::OUString(
@@ -583,8 +613,6 @@ void XcuParser::handleGroupProp(XmlReader & reader, GroupNode * group) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- Operation op = parseOperation(attrOp, OPERATION_MODIFY);
- bool finalized = xmldata::parseBoolean(attrFinalized, false);
NodeMap::iterator i(group->getMembers().find(name));
if (i == group->getMembers().end()) {
handleUnknownGroupProp(reader, group, name, type, op, finalized);
@@ -786,9 +814,10 @@ void XcuParser::handleLocalizedGroupProp(
void XcuParser::handleGroupNode(
XmlReader & reader, rtl::Reference< Node > const & group)
{
- Span attrName;
- Span attrOp;
- Span attrFinalized;
+ bool hasName = false;
+ rtl::OUString name;
+ Operation op = OPERATION_MODIFY;
+ bool finalized = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -798,25 +827,25 @@ void XcuParser::handleGroupNode(
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("op")))
{
- attrOp = reader.getAttributeValue(true);
+ op = parseOperation(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("finalized")))
{
- attrFinalized = reader.getAttributeValue(true);
+ finalized = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no node name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OUString name(xmldata::convertFromUtf8(attrName));
rtl::Reference< Node > child(
Data::findNode(valueParser_.getLayer(), group->getMembers(), name));
if (!child.is()) {
@@ -826,7 +855,6 @@ void XcuParser::handleGroupNode(
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- Operation op(parseOperation(attrOp, OPERATION_MODIFY));
if (op != OPERATION_MODIFY && op != OPERATION_FUSE) {
throw css::uno::RuntimeException(
(rtl::OUString(
@@ -836,8 +864,7 @@ void XcuParser::handleGroupNode(
css::uno::Reference< css::uno::XInterface >());
}
int finalizedLayer = std::min(
- (xmldata::parseBoolean(attrFinalized, false)
- ? valueParser_.getLayer() : Data::NO_LAYER),
+ finalized ? valueParser_.getLayer() : Data::NO_LAYER,
child->getFinalized());
child->setFinalized(finalizedLayer);
state_.push(
@@ -850,12 +877,14 @@ void XcuParser::handleGroupNode(
}
void XcuParser::handleSetNode(XmlReader & reader, SetNode * set) {
- Span attrName;
- Span attrComponent;
- Span attrNodeType;
- Span attrOp;
- Span attrFinalized;
- Span attrMandatory;
+ bool hasName = false;
+ rtl::OUString name;
+ rtl::OUString component(componentName_);
+ bool hasNodeType = false;
+ rtl::OUString nodeType;
+ Operation op = OPERATION_MODIFY;
+ bool finalized = false;
+ bool mandatory = false;
for (;;) {
XmlReader::Namespace attrNs;
Span attrLn;
@@ -865,41 +894,43 @@ void XcuParser::handleSetNode(XmlReader & reader, SetNode * set) {
if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
{
- attrName = reader.getAttributeValue(false);
+ hasName = true;
+ name = xmldata::convertFromUtf8(reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
{
- attrComponent = reader.getAttributeValue(false);
+ component = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
{
- attrNodeType = reader.getAttributeValue(false);
+ hasNodeType = true;
+ nodeType = xmldata::convertFromUtf8(
+ reader.getAttributeValue(false));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("op")))
{
- attrOp = reader.getAttributeValue(true);
+ op = parseOperation(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("finalized")))
{
- attrFinalized = reader.getAttributeValue(true);
+ finalized = xmldata::parseBoolean(reader.getAttributeValue(true));
} else if (attrNs == XmlReader::NAMESPACE_OOR &&
attrLn.equals(RTL_CONSTASCII_STRINGPARAM("mandatory")))
{
- attrMandatory = reader.getAttributeValue(true);
+ mandatory = xmldata::parseBoolean(reader.getAttributeValue(true));
}
}
- if (!attrName.is()) {
+ if (!hasName) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("no node name attribute in ")) +
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- rtl::OUString name(xmldata::convertFromUtf8(attrName));
rtl::OUString templateName(
xmldata::parseTemplateReference(
- attrComponent, attrNodeType, componentName_,
- &set->getDefaultTemplateName()));
+ component, hasNodeType, nodeType, &set->getDefaultTemplateName()));
if (!set->isValidTemplate(templateName)) {
throw css::uno::RuntimeException(
(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("set member node ")) +
@@ -923,11 +954,8 @@ void XcuParser::handleSetNode(XmlReader & reader, SetNode * set) {
reader.getUrl()),
css::uno::Reference< css::uno::XInterface >());
}
- Operation op(parseOperation(attrOp, OPERATION_MODIFY));
- int finalizedLayer = xmldata::parseBoolean(attrFinalized, false)
- ? valueParser_.getLayer() : Data::NO_LAYER;
- int mandatoryLayer = xmldata::parseBoolean(attrMandatory, false)
- ? valueParser_.getLayer() : Data::NO_LAYER;
+ int finalizedLayer = finalized ? valueParser_.getLayer() : Data::NO_LAYER;
+ int mandatoryLayer = mandatory ? valueParser_.getLayer() : Data::NO_LAYER;
NodeMap::iterator i(set->getMembers().find(name));
if (i != set->getMembers().end()) {
finalizedLayer = std::min(finalizedLayer, i->second->getFinalized());
diff --git a/configmgr/source/xcuparser.hxx b/configmgr/source/xcuparser.hxx
index 23ceb6cdb3d6..169ce1deeda8 100644
--- a/configmgr/source/xcuparser.hxx
+++ b/configmgr/source/xcuparser.hxx
@@ -74,8 +74,7 @@ private:
enum Operation {
OPERATION_MODIFY, OPERATION_REPLACE, OPERATION_FUSE, OPERATION_REMOVE };
- static Operation parseOperation(
- Span const & text, Operation defaultOperation);
+ static Operation parseOperation(Span const & text);
void handleComponentData(XmlReader & reader);
diff --git a/configmgr/source/xmldata.cxx b/configmgr/source/xmldata.cxx
index 151627725aaf..710bb6db4e15 100644
--- a/configmgr/source/xmldata.cxx
+++ b/configmgr/source/xmldata.cxx
@@ -91,9 +91,7 @@ rtl::OUString convertFromUtf8(Span const & text) {
}
Type parseType(XmlReader const & reader, Span const & text) {
- if (!text.is()) {
- return TYPE_ERROR;
- }
+ OSL_ASSERT(text.is());
sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
if (i >= 0) {
switch (reader.getNamespace(Span(text.begin, i))) {
@@ -173,10 +171,8 @@ Type parseType(XmlReader const & reader, Span const & text) {
css::uno::Reference< css::uno::XInterface >());
}
-bool parseBoolean(Span const & text, bool deflt) {
- if (!text.is()) {
- return deflt;
- }
+bool parseBoolean(Span const & text) {
+ OSL_ASSERT(text.is());
if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
return true;
}
@@ -190,11 +186,10 @@ bool parseBoolean(Span const & text, bool deflt) {
}
rtl::OUString parseTemplateReference(
- Span const & component, Span const & nodeType,
- rtl::OUString const & componentName,
- rtl::OUString const * defaultTemplateName)
+ rtl::OUString const & component, bool hasNodeType,
+ rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName)
{
- if (!nodeType.is()) {
+ if (!hasNodeType) {
if (defaultTemplateName != 0) {
return *defaultTemplateName;
}
@@ -203,9 +198,7 @@ rtl::OUString parseTemplateReference(
RTL_CONSTASCII_USTRINGPARAM("missing node-type attribute")),
css::uno::Reference< css::uno::XInterface >());
}
- return Data::fullTemplateName(
- component.is() ? convertFromUtf8(component) : componentName,
- convertFromUtf8(nodeType));
+ return Data::fullTemplateName(component, nodeType);
}
}
diff --git a/configmgr/source/xmldata.hxx b/configmgr/source/xmldata.hxx
index 862a4e0de194..8d0e7059a5ca 100644
--- a/configmgr/source/xmldata.hxx
+++ b/configmgr/source/xmldata.hxx
@@ -47,12 +47,11 @@ rtl::OUString convertFromUtf8(Span const & text);
Type parseType(XmlReader const & reader, Span const & text);
-bool parseBoolean(Span const & text, bool deflt);
+bool parseBoolean(Span const & text);
rtl::OUString parseTemplateReference(
- Span const & component, Span const & nodeType,
- rtl::OUString const & componentName,
- rtl::OUString const * defaultTemplateName);
+ rtl::OUString const & component, bool hasNodeType,
+ rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName);
}
diff --git a/configmgr/source/xmlreader.hxx b/configmgr/source/xmlreader.hxx
index 25b5e8d95d3d..fb883877adae 100644
--- a/configmgr/source/xmlreader.hxx
+++ b/configmgr/source/xmlreader.hxx
@@ -71,6 +71,8 @@ public:
bool nextAttribute(Namespace * ns, Span * localName);
+ // the span returned by getAttributeValue is only valid until the next call
+ // to nextItem or getAttributeValue
Span getAttributeValue(bool fullyNormalize);
Namespace getNamespace(Span const & prefix) const;