diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-11-29 11:23:09 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-11-29 11:34:09 +0100 |
commit | 053108588dd634838457ba81e7dc70e82aa50e02 (patch) | |
tree | 8d3eacd7eb5811849d10237af3848c895ca776b0 | |
parent | 6042f8610e18bb7d41654b896adff0b41a06bbe5 (diff) |
Support optional dependencies among .xcd files
...that are effectively ignored if the depended-on file does not exist. This
will be needed by a subsequent commit to make PDF Import optionally installable.
Change-Id: I2283be3ce75f52811a371f41aa8784f507425ee3
-rw-r--r-- | configmgr/source/components.cxx | 20 | ||||
-rw-r--r-- | configmgr/source/parsemanager.cxx | 6 | ||||
-rw-r--r-- | configmgr/source/parsemanager.hxx | 4 | ||||
-rw-r--r-- | configmgr/source/parser.hxx | 6 | ||||
-rw-r--r-- | configmgr/source/valueparser.cxx | 4 | ||||
-rw-r--r-- | configmgr/source/valueparser.hxx | 4 | ||||
-rw-r--r-- | configmgr/source/xcdparser.cxx | 42 | ||||
-rw-r--r-- | configmgr/source/xcdparser.hxx | 14 | ||||
-rw-r--r-- | configmgr/source/xcsparser.cxx | 6 | ||||
-rw-r--r-- | configmgr/source/xcsparser.hxx | 4 | ||||
-rw-r--r-- | configmgr/source/xcuparser.cxx | 6 | ||||
-rw-r--r-- | configmgr/source/xcuparser.hxx | 4 | ||||
-rw-r--r-- | officecfg/registry/data.dtd | 3 |
13 files changed, 84 insertions, 39 deletions
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 6476cd841fd5..82b4be70d9bb 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -23,6 +23,7 @@ #include <cassert> #include <cstddef> #include <list> +#include <set> #include "com/sun/star/beans/Optional.hpp" #include "com/sun/star/beans/UnknownPropertyException.hpp" @@ -92,7 +93,7 @@ void parseXcsFile( assert(partial == 0 && modifications == 0 && additions == 0); (void) partial; (void) modifications; (void) additions; bool ok = rtl::Reference< ParseManager >( - new ParseManager(url, new XcsParser(layer, data)))->parse(); + new ParseManager(url, new XcsParser(layer, data)))->parse(0); assert(ok); (void) ok; // avoid warnings } @@ -107,7 +108,7 @@ void parseXcuFile( new ParseManager( url, new XcuParser(layer, data, partial, modifications, additions)))-> - parse(); + parse(0); assert(ok); (void) ok; // avoid warnings } @@ -724,7 +725,8 @@ void Components::parseXcdFiles(int layer, rtl::OUString const & url) { css::uno::Reference< css::uno::XInterface >()); } UnresolvedList unres; - XcdParser::Dependencies deps; + std::set< OUString > existingDeps; + std::set< OUString > processedDeps; for (;;) { osl::DirectoryItem i; osl::FileBase::RC rc = dir.getNextItem(i, SAL_MAX_UINT32); @@ -758,10 +760,12 @@ void Components::parseXcdFiles(int layer, rtl::OUString const & url) { rtl::OUString name( file.copy( 0, file.getLength() - RTL_CONSTASCII_LENGTH(".xcd"))); + existingDeps.insert(name); rtl::Reference< ParseManager > manager; try { manager = new ParseManager( - stat.getFileURL(), new XcdParser(layer, deps, data_)); + stat.getFileURL(), + new XcdParser(layer, processedDeps, data_)); } catch (css::container::NoSuchElementException & e) { throw css::uno::RuntimeException( (rtl::OUString( @@ -770,8 +774,8 @@ void Components::parseXcdFiles(int layer, rtl::OUString const & url) { e.Message), css::uno::Reference< css::uno::XInterface >()); } - if (manager->parse()) { - deps.insert(name); + if (manager->parse(0)) { + processedDeps.insert(name); } else { unres.push_back(UnresolvedListItem(name, manager)); } @@ -781,8 +785,8 @@ void Components::parseXcdFiles(int layer, rtl::OUString const & url) { while (!unres.empty()) { bool resolved = false; for (UnresolvedList::iterator i(unres.begin()); i != unres.end();) { - if (i->manager->parse()) { - deps.insert(i->name); + if (i->manager->parse(&existingDeps)) { + processedDeps.insert(i->name); unres.erase(i++); resolved = true; } else { diff --git a/configmgr/source/parsemanager.cxx b/configmgr/source/parsemanager.cxx index a280f9518924..27f3f2028956 100644 --- a/configmgr/source/parsemanager.cxx +++ b/configmgr/source/parsemanager.cxx @@ -20,6 +20,7 @@ #include "sal/config.h" #include <cassert> +#include <set> #include "com/sun/star/container/NoSuchElementException.hpp" #include "com/sun/star/uno/RuntimeException.hpp" @@ -62,7 +63,7 @@ ParseManager::ParseManager( (void)id; } -bool ParseManager::parse() { +bool ParseManager::parse(std::set< OUString > const * existingDependencies) { for (;;) { switch (itemData_.is() ? xmlreader::XmlReader::RESULT_BEGIN @@ -70,7 +71,8 @@ bool ParseManager::parse() { parser_->getTextMode(), &itemData_, &itemNamespaceId_)) { case xmlreader::XmlReader::RESULT_BEGIN: - if (!parser_->startElement(reader_, itemNamespaceId_, itemData_)) + if (!parser_->startElement( + reader_, itemNamespaceId_, itemData_, existingDependencies)) { return false; } diff --git a/configmgr/source/parsemanager.hxx b/configmgr/source/parsemanager.hxx index bf886437d325..2760ab2fc939 100644 --- a/configmgr/source/parsemanager.hxx +++ b/configmgr/source/parsemanager.hxx @@ -22,6 +22,8 @@ #include "sal/config.h" +#include <set> + #include "com/sun/star/container/NoSuchElementException.hpp" #include "com/sun/star/uno/RuntimeException.hpp" #include "rtl/ref.hxx" @@ -44,7 +46,7 @@ public: com::sun::star::container::NoSuchElementException, com::sun::star::uno::RuntimeException)); - bool parse(); + bool parse(std::set< rtl::OUString > const * existingDependencies); enum { NAMESPACE_OOR = 1, NAMESPACE_XS = 2, NAMESPACE_XSI = 3 }; diff --git a/configmgr/source/parser.hxx b/configmgr/source/parser.hxx index 69afc4c1f6b4..c2e905c61fbd 100644 --- a/configmgr/source/parser.hxx +++ b/configmgr/source/parser.hxx @@ -23,10 +23,12 @@ #include "sal/config.h" #include <memory> +#include <set> #include "salhelper/simplereferenceobject.hxx" #include "xmlreader/xmlreader.hxx" +namespace rtl { class OUString; } namespace xmlreader { struct Span; } namespace configmgr { @@ -36,8 +38,8 @@ public: virtual xmlreader::XmlReader::Text getTextMode() = 0; virtual bool startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) - = 0; + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< rtl::OUString > const * existingDependencies) = 0; virtual void endElement(xmlreader::XmlReader const & reader) = 0; diff --git a/configmgr/source/valueparser.cxx b/configmgr/source/valueparser.cxx index 929d52cf37f9..75ddef26e077 100644 --- a/configmgr/source/valueparser.cxx +++ b/configmgr/source/valueparser.cxx @@ -20,6 +20,7 @@ #include "sal/config.h" #include <cassert> +#include <set> #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" @@ -287,7 +288,8 @@ xmlreader::XmlReader::Text ValueParser::getTextMode() const { } bool ValueParser::startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< rtl::OUString > const *) { if (!node_.is()) { return false; diff --git a/configmgr/source/valueparser.hxx b/configmgr/source/valueparser.hxx index 19a1753bcab4..de28ce6d7488 100644 --- a/configmgr/source/valueparser.hxx +++ b/configmgr/source/valueparser.hxx @@ -22,6 +22,7 @@ #include "sal/config.h" +#include <set> #include <vector> #include "boost/noncopyable.hpp" @@ -51,7 +52,8 @@ public: xmlreader::XmlReader::Text getTextMode() const; bool startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name); + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const *); bool endElement(); diff --git a/configmgr/source/xcdparser.cxx b/configmgr/source/xcdparser.cxx index d89f619e0238..d7bc544ad7ae 100644 --- a/configmgr/source/xcdparser.cxx +++ b/configmgr/source/xcdparser.cxx @@ -21,6 +21,7 @@ #include <cassert> #include <climits> +#include <set> #include "com/sun/star/uno/Reference.hxx" #include "com/sun/star/uno/RuntimeException.hpp" @@ -45,8 +46,10 @@ namespace css = com::sun::star; } -XcdParser::XcdParser(int layer, Dependencies const & dependencies, Data & data): - layer_(layer), dependencies_(dependencies), data_(data), state_(STATE_START) +XcdParser::XcdParser( + int layer, std::set< OUString > const & processedDependencies, Data & data): + layer_(layer), processedDependencies_(processedDependencies), data_(data), + state_(STATE_START) {} XcdParser::~XcdParser() {} @@ -57,12 +60,14 @@ xmlreader::XmlReader::Text XcdParser::getTextMode() { } bool XcdParser::startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies) { if (nestedParser_.is()) { assert(nesting_ != LONG_MAX); ++nesting_; - return nestedParser_->startElement(reader, nsId, name); + return nestedParser_->startElement( + reader, nsId, name, existingDependencies); } switch (state_) { case STATE_START: @@ -77,7 +82,8 @@ bool XcdParser::startElement( if (nsId == xmlreader::XmlReader::NAMESPACE_NONE && name.equals(RTL_CONSTASCII_STRINGPARAM("dependency"))) { - if (dependency_.isEmpty()) { + if (dependencyFile_.isEmpty()) { + dependencyOptional_ = false; xmlreader::Span attrFile; for (;;) { int attrNsId; @@ -90,6 +96,13 @@ bool XcdParser::startElement( attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file"))) { attrFile = reader.getAttributeValue(false); + } else if ((attrNsId == + xmlreader::XmlReader::NAMESPACE_NONE) && + attrLn.equals( + RTL_CONSTASCII_STRINGPARAM("optional"))) + { + dependencyOptional_ = xmldata::parseBoolean( + reader.getAttributeValue(true)); } } if (!attrFile.is()) { @@ -100,8 +113,8 @@ bool XcdParser::startElement( reader.getUrl()), css::uno::Reference< css::uno::XInterface >()); } - dependency_ = attrFile.convertFromUtf8(); - if (dependency_.isEmpty()) { + dependencyFile_ = attrFile.convertFromUtf8(); + if (dependencyFile_.isEmpty()) { throw css::uno::RuntimeException( (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( @@ -110,11 +123,16 @@ bool XcdParser::startElement( css::uno::Reference< css::uno::XInterface >()); } } - if (dependencies_.find(dependency_) == dependencies_.end()) { + if ((processedDependencies_.find(dependencyFile_) == + processedDependencies_.end()) && + (!dependencyOptional_ || existingDependencies == 0 || + (existingDependencies->find(dependencyFile_) != + existingDependencies->end()))) + { return false; } state_ = STATE_DEPENDENCY; - dependency_ = rtl::OUString(); + dependencyFile_ = rtl::OUString(); return true; } state_ = STATE_COMPONENTS; @@ -125,14 +143,16 @@ bool XcdParser::startElement( { nestedParser_ = new XcsParser(layer_, data_); nesting_ = 1; - return nestedParser_->startElement(reader, nsId, name); + return nestedParser_->startElement( + reader, nsId, name, existingDependencies); } if (nsId == ParseManager::NAMESPACE_OOR && name.equals(RTL_CONSTASCII_STRINGPARAM("component-data"))) { nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0); nesting_ = 1; - return nestedParser_->startElement(reader, nsId, name); + return nestedParser_->startElement( + reader, nsId, name, existingDependencies); } break; default: // STATE_DEPENDENCY diff --git a/configmgr/source/xcdparser.hxx b/configmgr/source/xcdparser.hxx index 97d6062d7549..ca17964f5f03 100644 --- a/configmgr/source/xcdparser.hxx +++ b/configmgr/source/xcdparser.hxx @@ -38,9 +38,9 @@ struct Data; class XcdParser: public Parser { public: - typedef std::set< rtl::OUString > Dependencies; - - XcdParser(int layer, Dependencies const & dependencies, Data & data); + XcdParser( + int layer, std::set< OUString > const & processedDependencies, + Data & data); private: virtual ~XcdParser(); @@ -48,7 +48,8 @@ private: virtual xmlreader::XmlReader::Text getTextMode(); virtual bool startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name); + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies); virtual void endElement(xmlreader::XmlReader const & reader); @@ -58,10 +59,11 @@ private: STATE_START, STATE_DEPENDENCIES, STATE_DEPENDENCY, STATE_COMPONENTS }; int layer_; - Dependencies const & dependencies_; + std::set< OUString > const & processedDependencies_; Data & data_; State state_; - rtl::OUString dependency_; + rtl::OUString dependencyFile_; + bool dependencyOptional_; rtl::Reference< Parser > nestedParser_; long nesting_; }; diff --git a/configmgr/source/xcsparser.cxx b/configmgr/source/xcsparser.cxx index fe760eb28cff..686bfdb003eb 100644 --- a/configmgr/source/xcsparser.cxx +++ b/configmgr/source/xcsparser.cxx @@ -21,6 +21,7 @@ #include <cassert> #include <cstddef> +#include <set> #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" @@ -127,9 +128,10 @@ xmlreader::XmlReader::Text XcsParser::getTextMode() { } bool XcsParser::startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies) { - if (valueParser_.startElement(reader, nsId, name)) { + if (valueParser_.startElement(reader, nsId, name, existingDependencies)) { return true; } if (state_ == STATE_START) { diff --git a/configmgr/source/xcsparser.hxx b/configmgr/source/xcsparser.hxx index 63ecac78af13..930f4093471e 100644 --- a/configmgr/source/xcsparser.hxx +++ b/configmgr/source/xcsparser.hxx @@ -22,6 +22,7 @@ #include "sal/config.h" +#include <set> #include <stack> #include "rtl/ref.hxx" @@ -49,7 +50,8 @@ private: virtual xmlreader::XmlReader::Text getTextMode(); virtual bool startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name); + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< rtl::OUString > const * existingDependencies); virtual void endElement(xmlreader::XmlReader const & reader); diff --git a/configmgr/source/xcuparser.cxx b/configmgr/source/xcuparser.cxx index 496774762035..56f9e2133c9a 100644 --- a/configmgr/source/xcuparser.cxx +++ b/configmgr/source/xcuparser.cxx @@ -21,6 +21,7 @@ #include <algorithm> #include <cassert> +#include <set> #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" @@ -77,9 +78,10 @@ xmlreader::XmlReader::Text XcuParser::getTextMode() { } bool XcuParser::startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies) { - if (valueParser_.startElement(reader, nsId, name)) { + if (valueParser_.startElement(reader, nsId, name, existingDependencies)) { return true; } if (state_.empty()) { diff --git a/configmgr/source/xcuparser.hxx b/configmgr/source/xcuparser.hxx index 85d63c9138e6..1b9f318b458c 100644 --- a/configmgr/source/xcuparser.hxx +++ b/configmgr/source/xcuparser.hxx @@ -22,6 +22,7 @@ #include "sal/config.h" +#include <set> #include <stack> #include "rtl/ref.hxx" @@ -61,7 +62,8 @@ private: virtual xmlreader::XmlReader::Text getTextMode(); virtual bool startElement( - xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name); + xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name, + std::set< OUString > const * existingDependencies); virtual void endElement(xmlreader::XmlReader const & reader); diff --git a/officecfg/registry/data.dtd b/officecfg/registry/data.dtd index 921814d0fc97..2c9bce6d6428 100644 --- a/officecfg/registry/data.dtd +++ b/officecfg/registry/data.dtd @@ -22,7 +22,8 @@ <!ELEMENT dependency EMPTY> <!ATTLIST dependency - file CDATA #REQUIRED> + file CDATA #REQUIRED + optional (false | true) #IMPLIED> <!ENTITY % component-schema.dtd SYSTEM "component-schema.dtd"> %component-schema.dtd; |