diff options
author | Jörg Barfurth <jb@openoffice.org> | 2002-05-16 10:00:29 +0000 |
---|---|---|
committer | Jörg Barfurth <jb@openoffice.org> | 2002-05-16 10:00:29 +0000 |
commit | cf02bbc455d459890f0a5ad4129594405ad49b7a (patch) | |
tree | fb59dd2d5eccf6a2dd136c5f4b512fcba4f7c2e7 /configmgr/source | |
parent | ef6b33fe8dc7e4670a63c3de5ed58d3ec1093bc1 (diff) |
#98489# Add parsers for new XML format
Diffstat (limited to 'configmgr/source')
-rw-r--r-- | configmgr/source/xml/basicparser.cxx | 462 | ||||
-rw-r--r-- | configmgr/source/xml/basicparser.hxx | 207 | ||||
-rw-r--r-- | configmgr/source/xml/elementinfo.hxx | 154 | ||||
-rw-r--r-- | configmgr/source/xml/elementparser.cxx | 487 | ||||
-rw-r--r-- | configmgr/source/xml/elementparser.hxx | 152 | ||||
-rw-r--r-- | configmgr/source/xml/layerparser.cxx | 337 | ||||
-rw-r--r-- | configmgr/source/xml/layerparser.hxx | 144 | ||||
-rw-r--r-- | configmgr/source/xml/makefile.mk | 10 | ||||
-rw-r--r-- | configmgr/source/xml/schemaparser.cxx | 403 | ||||
-rw-r--r-- | configmgr/source/xml/schemaparser.hxx | 169 | ||||
-rw-r--r-- | configmgr/source/xml/valueconverter.cxx | 209 | ||||
-rw-r--r-- | configmgr/source/xml/xmlstrings.cxx | 160 | ||||
-rw-r--r-- | configmgr/source/xml/xmlstrings.hxx | 162 |
13 files changed, 3052 insertions, 4 deletions
diff --git a/configmgr/source/xml/basicparser.cxx b/configmgr/source/xml/basicparser.cxx new file mode 100644 index 000000000000..517a5d7090d6 --- /dev/null +++ b/configmgr/source/xml/basicparser.cxx @@ -0,0 +1,462 @@ +/************************************************************************* + * + * $RCSfile: basicparser.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "basicparser.hxx" + +#ifndef _COM_SUN_STAR_XML_SAX_SAXEXCEPTION_HPP_ +#include <com/sun/star/xml/sax/SAXException.hpp> +#endif + +#ifndef CONFIGMGR_XML_VALUECONVERTER_HXX +#include "valueconverter.hxx" +#endif +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +namespace +{ + typedef uno::Reference< script::XTypeConverter > TypeConverter; + + static inline + uno::Reference< uno::XInterface > createTCV(BasicParser::ServiceFactory const & _xSvcFactory) + { + OSL_ENSURE(_xSvcFactory.is(),"Cannot create Parser without a ServiceManager"); + + static const rtl::OUString k_sTCVService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")); + + return TypeConverter::query(_xSvcFactory->createInstance(k_sTCVService)); + } + + static inline + TypeConverter asTCV(uno::Reference< uno::XInterface > const & _xTCV) + { + OSL_ASSERT(TypeConverter::query(_xTCV).get() == _xTCV.get()); + return static_cast< script::XTypeConverter * >(_xTCV.get()); + } +} +// ----------------------------------------------------------------------------- + +struct BasicParser::ValueData : ValueConverter +{ + OUString content; + OUString locale; + bool isLocalized; + + ValueData(uno::Type const& _aType, TypeConverter const & _xTCV) + : ValueConverter(_aType, _xTCV) + , content() + , locale() + , isLocalized(false) + { + } + + uno::Any convertToAny() const + { + return ValueConverter::convertToAny(this->content); + } + + void setLocalized(OUString const & _aLocale) + { + isLocalized = true; + locale = _aLocale; + } +}; +// ----------------------------------------------------------------------------- + +BasicParser::BasicParser(ServiceFactory const & _xSvcFactory) +: m_xTypeConverter( createTCV(_xSvcFactory) ) +, m_xLocator(NULL) +, m_aDataParser() +, m_aNodes() +, m_aValueType() +, m_pValueData(NULL) +, m_nSkipLevels(0) +, m_bEmpty() +{ + if (!m_xTypeConverter.is()) + throw uno::RuntimeException(); +} +// ----------------------------------------------------------------------------- + +BasicParser::~BasicParser() +{ + delete m_pValueData; +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::startDocument( ) + throw (sax::SAXException, uno::RuntimeException) +{ + m_aDataParser.reset(); + m_aValueType = uno::Type(); + m_nSkipLevels = 0; + + delete m_pValueData, m_pValueData = NULL; + + while (!m_aNodes.empty()) m_aNodes.pop(); + + m_bEmpty = true; +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::endDocument( ) throw (sax::SAXException, uno::RuntimeException) +{ + if (!m_aNodes.empty() || isSkipping() || isInValueData()) + raiseParseException( "Configuration XML Parser - Invalid XML: Unexpected end of document" ); + + m_xLocator.clear(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::characters( const OUString& aChars ) + throw (sax::SAXException, uno::RuntimeException) +{ + if (isInValueData()) + { + m_pValueData->content += aChars; + } +#ifdef CONFIG_XMLPARSER_VALIDATE_WHITESPACE + else + OSL_ENSURE( isSkipping() || aChars.trim().getLength() == 0, "Unexpected text content in configuration XML"); +#endif +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::ignorableWhitespace( const OUString& aWhitespaces ) + throw (sax::SAXException, uno::RuntimeException) +{ + if (isInValueData()) + { + OSL_ENSURE(false, "Configuration XML: Unexpected ignorable (!) whitespace instruction in value data"); + if (!m_pValueData->isNull()) + m_pValueData->content += aWhitespaces; + } +#ifdef CONFIG_XMLPARSER_VALIDATE_WHITESPACE + else + OSL_ENSURE( aChars.trim().getLength() == 0, "Unexpected non-space content in ignorable whitespace"); +#endif +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::processingInstruction( const OUString& aTarget, const OUString& aData ) + throw (sax::SAXException, uno::RuntimeException) +{ + OSL_ENSURE(false, "Unexpected processing instruction in Configuration XML"); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL BasicParser::setDocumentLocator( const uno::Reference< sax::XLocator >& xLocator ) + throw (sax::SAXException, uno::RuntimeException) +{ + m_xLocator = xLocator; +} +// ----------------------------------------------------------------------------- + +void BasicParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + OSL_ENSURE( !isSkipping(), "While skipping, call startSkipping() instead of startNode()"); + OSL_ENSURE( aInfo.type != ElementType::property, "For properties, call startProperty() instead of startNode()"); + + if (isInProperty()) + raiseParseException( "Configuration XML Parser - Invalid Data: Cannot have a node nested in a property" ); + + m_aNodes.push(aInfo); + m_bEmpty = (aInfo.flags != 0) || (aInfo.op > Operation::modify); + + OSL_POSTCOND( isInNode(), "Could not start a node "); +} +// ----------------------------------------------------------------------------- + +void BasicParser::endNode( ) +{ + OSL_ENSURE( !isSkipping(), "While skipping, honor wasSkipping() instead of calling endNode()"); + OSL_ENSURE( !isInProperty(), "For properties, call endProperty() instead of endNode()" ); + + ensureInNode(); + + m_aNodes.pop(); + m_bEmpty = false; +} +// ----------------------------------------------------------------------------- + +void BasicParser::ensureInNode( ) +{ + if (!isInNode()) + raiseParseException("Unexpected endElement without matching startElement"); +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isInNode( ) +{ + return ! m_aNodes.empty(); +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isEmptyNode( ) +{ + return m_bEmpty; +} +// ----------------------------------------------------------------------------- + +ElementInfo const & BasicParser::getActiveNodeInfo( ) +{ + ensureInNode(); + + return m_aNodes.top(); +} +// ----------------------------------------------------------------------------- + +void BasicParser::startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + OSL_ENSURE( !isSkipping(), "While skipping, call startSkipping() instead of startProperty()"); + OSL_ENSURE( aInfo.type == ElementType::property, "For non-property nodes, call startNode() instead of startProperty()"); + + if (isInProperty()) + raiseParseException( "Configuration XML Parser - Invalid Data: Properties may not nest" ); + + m_aValueType = getDataParser().getPropertyValueType(xAttribs); + + if (m_aValueType == uno::Type()) + raiseParseException( "Configuration XML Parser - Invalid Data: Property without a type" ); + + m_aNodes.push(aInfo); + m_bEmpty = true; + + OSL_POSTCOND( isInProperty(), "Could not get data to start a property" ); + OSL_POSTCOND( isInUnhandledProperty(), "Could not mark property as unhandled"); +} +// ----------------------------------------------------------------------------- + +void BasicParser::endProperty( ) +{ + OSL_ENSURE( !isSkipping(), "While skipping, honor wasSkipping() instead of calling endProperty()"); + OSL_ENSURE( isInProperty(), "For non-property nodes, call endNode() instead of endProperty()" ); + + ensureInNode(); + + m_aNodes.pop(); + m_bEmpty = false; + + m_aValueType = uno::Type(); + + OSL_POSTCOND( !isInProperty(), "Could not get mark end of property" ); +} +// ----------------------------------------------------------------------------- + +uno::Type BasicParser::getActivePropertyType() +{ + return m_aValueType; +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isInProperty() +{ + return m_aValueType.getTypeClass() != uno::TypeClass_VOID; +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isInUnhandledProperty() +{ + return m_bEmpty && m_aValueType.getTypeClass() != uno::TypeClass_VOID; +} +// ----------------------------------------------------------------------------- + +void BasicParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) +{ + if (!isInProperty()) + raiseParseException( "Configuration XML Parser - Invalid Data: A value may occur only within a property" ); + + if (m_aValueType.getTypeClass() == uno::TypeClass_ANY) + raiseParseException( "Configuration XML Parser - Invalid Data: Cannot have values for properties of type 'Any'" ); + + if (isInValueData()) + raiseParseException( "Configuration XML Parser - Invalid Data: Unexpected element while parsing value data" ); + + m_pValueData = new ValueData(m_aValueType, asTCV(m_xTypeConverter)); + + m_pValueData->setIsNull( getDataParser().isNull(xAttribs) ); + + OUString aLocale; + if ( getDataParser().getLanguage(xAttribs,aLocale) ) + m_pValueData->setLocalized( aLocale ); + + if (!m_pValueData->isNull() && m_pValueData->isList()) + m_pValueData->setSeparator( getDataParser().getSeparator(xAttribs) ); + + else + OSL_ENSURE(getDataParser().getSeparator(xAttribs).getLength() == 0, + "Warning: Spurious oor:separator on value that is not a list (or null)"); +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isInValueData() +{ + return m_pValueData != NULL; +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isValueDataLocalized() +{ + OSL_ENSURE(isInValueData(), "There is no value data that could be localized"); + + return m_pValueData && m_pValueData->isLocalized; +} +// ----------------------------------------------------------------------------- + +OUString BasicParser::getValueDataLocale() +{ + OSL_ENSURE(isValueDataLocalized(), "There is no value data or it is not localized"); + + return m_pValueData->locale; +} +// ----------------------------------------------------------------------------- + +uno::Any BasicParser::getCurrentValue() +{ + OSL_ASSERT( isInValueData() ); + + return m_pValueData->convertToAny(); +} +// ----------------------------------------------------------------------------- + +/// end collecting data for a value +void BasicParser::endValueData() +{ + OSL_ASSERT( isInValueData() ); + + delete m_pValueData, m_pValueData = NULL; + m_bEmpty = false; + + OSL_POSTCOND( !isInValueData(), "Could not end value data tag" ); + OSL_POSTCOND( !isInUnhandledProperty(), "Could not mark property as handled" ); +} +// ----------------------------------------------------------------------------- + +void BasicParser::startSkipping( const OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + m_aNodes.push( ElementInfo(aName) ); + ++m_nSkipLevels; +} +// ----------------------------------------------------------------------------- + +bool BasicParser::wasSkipping( const OUString& aName ) +{ + if (m_nSkipLevels == 0) return false; + + if (m_aNodes.empty()) + raiseParseException( "Configuration XML Parser - Invalid XML: Unexpected end of element (while skipping data)" ); + + if (aName != m_aNodes.top().name) + raiseParseException( "Configuration XML Parser - Invalid XML: End tag does not match start tag (while skipping data)" ); + + --m_nSkipLevels; + m_aNodes.pop(); + + return true; +} +// ----------------------------------------------------------------------------- + +bool BasicParser::isSkipping( ) +{ + return m_nSkipLevels != 0; +} +// ----------------------------------------------------------------------------- + +void BasicParser::raiseParseException( uno::Any const & _aTargetException, sal_Char const * _pMsg ) + CFG_THROW2 (sax::SAXException, uno::RuntimeException) +{ + if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid Data: "; + + OUString sMessage = OUString::createFromAscii(_pMsg); + + uno::Exception aEx; + if (_aTargetException >>= aEx) + sMessage += aEx.Message; + + throw sax::SAXException( sMessage, *this, _aTargetException ); +} +// ----------------------------------------------------------------------------- + +void BasicParser::raiseParseException( sal_Char const * _pMsg ) + CFG_THROW2 (sax::SAXException, uno::RuntimeException) +{ + if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid XML"; + + OUString const sMessage = OUString::createFromAscii(_pMsg); + + throw sax::SAXException( sMessage, *this, uno::Any() ); +} +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + } // namespace + +// ----------------------------------------------------------------------------- +} // namespace + diff --git a/configmgr/source/xml/basicparser.hxx b/configmgr/source/xml/basicparser.hxx new file mode 100644 index 000000000000..8a067013c5e8 --- /dev/null +++ b/configmgr/source/xml/basicparser.hxx @@ -0,0 +1,207 @@ +/************************************************************************* + * + * $RCSfile: basicparser.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_BASICPARSER_HXX +#define CONFIGMGR_XML_BASICPARSER_HXX + +#ifndef CONFIGMGR_XML_ELEMENTPARSER_HXX +#include "elementparser.hxx" +#endif +#ifndef CONFIGMGR_UTILITY_HXX_ +#include "utility.hxx" +#endif + +#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_ +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef INCLUDED_STACK +#include <stack> +#define INCLUDED_STACK +#endif + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace lang = ::com::sun::star::lang; + + namespace sax = ::com::sun::star::xml::sax; + + using rtl::OUString; +// ----------------------------------------------------------------------------- + + typedef ::cppu::WeakImplHelper1<sax::XDocumentHandler> Parser_Base; + + class BasicParser + : public Parser_Base + { + struct ValueData; + + uno::Reference< uno::XInterface > m_xTypeConverter; + uno::Reference< sax::XLocator > m_xLocator; + ElementParser m_aDataParser; + std::stack< ElementInfo > m_aNodes; + uno::Type m_aValueType; + ValueData * m_pValueData; + sal_uInt16 m_nSkipLevels; + bool m_bEmpty; + public: + typedef uno::Reference< lang::XMultiServiceFactory > ServiceFactory; + + explicit BasicParser(ServiceFactory const & _xSvcFactory); + virtual ~BasicParser(); + + // XDocumentHandler + public: + virtual void SAL_CALL + startDocument( ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + endDocument( ) throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + characters( const OUString& aChars ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + ignorableWhitespace( const OUString& aWhitespaces ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + processingInstruction( const OUString& aTarget, const OUString& aData ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + setDocumentLocator( const uno::Reference< sax::XLocator >& xLocator ) + throw (sax::SAXException, uno::RuntimeException); + + protected: + ElementParser const & getDataParser() const { return m_aDataParser; } + + /// start an node + void startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// are we in the content of a node ? + bool isInNode(); + /// are we in the content of node for which no content was started yet ? + bool isEmptyNode(); + /// make sure we are in the content of a node ? + void ensureInNode(); + /// get the info about of the node currently being processed + ElementInfo const & getActiveNodeInfo(); + /// end a node + void endNode(); + + /// start a property + void startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// are we in the content of a property node ? + bool isInProperty(); + /// are we in the content of a property node (and there has been no value for that property) ? + bool isInUnhandledProperty(); + /// get the data type of the active property ? + uno::Type getActivePropertyType(); + /// end a property + void endProperty(); + + /// start collecting data for a value - returns the locale of the value (property must have been started) + void startValueData(const uno::Reference< sax::XAttributeList >& xAttribs); + /// are we in the content of a property node ? + bool isInValueData(); + /// check if the current value data has a locale set + bool isValueDataLocalized(); + /// get the locale of the current value data, if localized + OUString getValueDataLocale(); + /// return the collected value + uno::Any getCurrentValue(); + /// end collecting data for a value + void endValueData(); + + /// start a node to be skipped + void startSkipping( const OUString& aTag, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// are we inside a skipped node ? + bool isSkipping( ); + /// ending a node: was this skipped ? + bool wasSkipping( const OUString& aTag ); + + protected: + void raiseParseException( uno::Any const & _aTargetException, sal_Char const * _pMsg = NULL) + CFG_THROW2 (sax::SAXException, uno::RuntimeException); + void raiseParseException( sal_Char const * _pMsg ) + CFG_THROW2 (sax::SAXException, uno::RuntimeException); + }; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- + +} // namespace configmgr +#endif + + + + diff --git a/configmgr/source/xml/elementinfo.hxx b/configmgr/source/xml/elementinfo.hxx new file mode 100644 index 000000000000..c21d858aa932 --- /dev/null +++ b/configmgr/source/xml/elementinfo.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * $RCSfile: elementinfo.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/* PLEASE DON'T DELETE ANY COMMENT LINES, ALSO IT'S UNNECESSARY. */ + +#ifndef CONFIGMGR_XML_ELEMENTINFO_HXX +#define CONFIGMGR_XML_ELEMENTINFO_HXX + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + typedef rtl::OUString ElementName; +// ----------------------------------------------------------------------------- + namespace ElementType + { + enum Enum + { + unknown, + + schema, + + component, + templates, + + property, + node, + group, + set, + + import, + instance, + item_type, + value, + + other + }; + }; +// ----------------------------------------------------------------------------- + namespace Operation + { + enum Enum + { + none, + + modify, + + replace, + remove, + + unknown + }; + }; +// ----------------------------------------------------------------------------- + struct ElementInfo + { + typedef sal_Int16 FlagsType; + + explicit + ElementInfo(ElementType::Enum _type = ElementType::unknown) + : name() + , type(_type) + , op() + , flags() + {} + + explicit + ElementInfo(ElementName const & _name, ElementType::Enum _type = ElementType::unknown) + : name(_name) + , type(_type) + , op() + , flags() + {} + + + ElementName name; + ElementType::Enum type; + Operation::Enum op; + FlagsType flags; + }; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- +} // namespace configmgr + +#endif + diff --git a/configmgr/source/xml/elementparser.cxx b/configmgr/source/xml/elementparser.cxx new file mode 100644 index 000000000000..eac4ef3c24d7 --- /dev/null +++ b/configmgr/source/xml/elementparser.cxx @@ -0,0 +1,487 @@ +/************************************************************************* + * + * $RCSfile: elementparser.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "elementparser.hxx" + +#ifndef CONFIGMGR_XML_STRINGS_HXX_ +#include "xmlstrings.hxx" +#endif + +#ifndef CONFIGMGR_TYPECONVERTER_HXX +#include "typeconverter.hxx" +#endif + +#include <drafts/com/sun/star/configuration/backend/SchemaAttribute.hpp> +#include <drafts/com/sun/star/configuration/backend/NodeAttribute.hpp> + +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +static +inline +sal_Int16 impl_getIndexByName(uno::Reference< sax::XAttributeList > const& xAttribs, OUString const& aAttributeName) +{ + OSL_PRECOND( xAttribs.is(), "ERROR: NULL Attribute list"); + + sal_Int16 nIndex = xAttribs->getLength(); + + while (--nIndex >= 0) + { + if (xAttribs->getNameByIndex(nIndex).equals(aAttributeName)) + break; + } + // nIndex == -1 if not found + + return nIndex; +} +// ----------------------------------------------------------------------------- +static +inline +bool impl_maybeGetAttribute(uno::Reference< sax::XAttributeList > const& xAttribs, OUString const& aAttributeName, /* OUT */ OUString& rAttributeValue) +{ + OSL_PRECOND( xAttribs.is(), "ERROR: NULL Attribute list"); + + sal_Int16 const nEnd = xAttribs->getLength(); + + for(sal_Int16 nIndex = 0; nIndex < nEnd; ++nIndex) + { + if (xAttribs->getNameByIndex(nIndex).equals(aAttributeName)) + { + rAttributeValue = xAttribs->getValueByIndex(nIndex); + break; + } + } + // nIndex >= nEnd if not found + + return nIndex < nEnd; // broke out of loop when found +} +// ----------------------------------------------------------------------------- + +/// retrieve the (almost) complete information for an element +ElementInfo ElementParser::parseElementInfo(OUString const& _sTag, SaxAttributeList const& _xAttribs) const +{ + ElementType::Enum aType = this->getNodeType(_sTag,_xAttribs); + + ElementInfo aInfo( this->getName(_sTag,_xAttribs,aType), aType ); + + aInfo.op = this->getOperation(_xAttribs); + aInfo.flags = this->getNodeFlags(_xAttribs); + + return aInfo; +} +// ----------------------------------------------------------------------------- + +ElementType::Enum ElementParser::getNodeType(OUString const& _sElementName, SaxAttributeList const& _xAttribs) const +{ + OSL_PRECOND( _xAttribs.is(), "ERROR: NULL Attribute list"); + + // todo: make this use a table, if necessary + ElementType::Enum eResult = ElementType::unknown; + if (_sElementName.equals(TAG_VALUE)) + eResult = ElementType::value; + + else if (_sElementName.equals(TAG_PROP)) + eResult = ElementType::property; + + else if (_sElementName.equals(TAG_NODE)) + eResult = ElementType::node; + + else if (_sElementName.equals(TAG_GROUP)) + eResult = ElementType::group; + + else if (_sElementName.equals(TAG_SET)) + eResult = ElementType::set; + + else if (_sElementName.equals(TAG_INSTANCE)) + eResult = ElementType::instance; + + else if (_sElementName.equals(TAG_ITEMTYPE)) + eResult = ElementType::item_type; + + else if (_sElementName.equals(TAG_IMPORT)) + eResult = ElementType::import; + + else if (_sElementName.equals(TAG_SCHEMA)) + eResult = ElementType::schema; + + else if (_sElementName.equals(TAG_COMPONENT)) + eResult = ElementType::component; + + else if (_sElementName.equals(TAG_TEMPLATES)) + eResult = ElementType::templates; + + else + eResult = ElementType::other; + + return eResult; +} +// ----------------------------------------------------------------------------- + +/// takes the node name from either an attribute or the element name +OUString ElementParser::getName(OUString const& _sElementName, SaxAttributeList const& _xAttribs, ElementType::Enum _eType) const +{ + OUString aName; + OUString aPackage; + + bool bNameFound = this->maybeGetAttribute(_xAttribs, ATTR_NAME, aName); + bool bPackage = false; + + switch (_eType) + { + case ElementType::schema: + bPackage = this->maybeGetAttribute(_xAttribs,ATTR_PACKAGE,aPackage); + break; + + case ElementType::node: + bPackage = this->maybeGetAttribute(_xAttribs,ATTR_CONTEXT,aPackage); + break; + + case ElementType::set: + case ElementType::group: + case ElementType::instance: + case ElementType::property: + break; + + // these have no name to speak of + case ElementType::value: + case ElementType::item_type: + case ElementType::import: + case ElementType::templates: + case ElementType::component: + OSL_ENSURE(!bNameFound, "Configuration Parser: Unexpected name attribute is ignored\n"); + return _sElementName; + + // for unknown prefer name to + case ElementType::unknown: + if (!bNameFound) return _sElementName; + + bPackage = + this->maybeGetAttribute(_xAttribs,ATTR_PACKAGE,aPackage) || + this->maybeGetAttribute(_xAttribs,ATTR_CONTEXT,aPackage); + break; + + default: + if (!bNameFound) return _sElementName; + break; + } + + if (bPackage) + { + static const sal_Unicode chPackageSep = '.'; + + aName = aPackage.concat(OUString(&chPackageSep,1)).concat(aName); + } + return aName; +} +// ----------------------------------------------------------------------------- + +Operation::Enum ElementParser::getOperation(SaxAttributeList const& xAttribs) const +{ + OUString sOpName; + if ( ! this->maybeGetAttribute(xAttribs,ATTR_OPERATION, sOpName) ) + return Operation::none; + + if (sOpName.equals(OPERATION_MODIFY)) + return Operation::modify; + + else if (sOpName.equals(OPERATION_REPLACE)) + return Operation::replace; + + else if (sOpName.equals(OPERATION_REMOVE)) + return Operation::remove; + + else + return Operation::unknown; +} +// ----------------------------------------------------------------------------- + + +/// retrieve the locale stored in the attribute list +bool ElementParser::getLanguage(SaxAttributeList const& xAttribs, OUString& _rsLanguage) const +{ + return this->maybeGetAttribute(xAttribs, EXT_ATTR_LANGUAGE, _rsLanguage); +} +// ----------------------------------------------------------------------------- + +/// reads attributes for nodes from the attribute list +ElementInfo::FlagsType ElementParser::getNodeFlags(SaxAttributeList const& xAttribs) const +{ + namespace NodeAttribute = drafts::com::sun::star::configuration::backend::NodeAttribute; + namespace SchemaAttribute = drafts::com::sun::star::configuration::backend::SchemaAttribute; + + bool bValue; + + ElementInfo::FlagsType aResult = 0; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_NULLABLE, bValue) && ! bValue) + aResult |= SchemaAttribute::REQUIRED; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_LOCALIZED, bValue) && bValue) + aResult |= SchemaAttribute::LOCALIZED; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_EXTENSIBLE, bValue) && bValue) + aResult |= SchemaAttribute::EXTENSIBLE; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_FINALIZED, bValue) && bValue) + aResult |= NodeAttribute::FINALIZED; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_MANDATORY, bValue) && bValue) + aResult |= NodeAttribute::MANDATORY; + + if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_READONLY, bValue) && bValue) + aResult |= NodeAttribute::READONLY; + + return aResult; +} +// ----------------------------------------------------------------------------- +static +void badValueType(sal_Char const * _pMsg, OUString const & _sExtra) +{ + rtl::OString sMessage( "Configuration XML parser: Bad value type attribute:" ); + sMessage += _pMsg; + sMessage += rtl::OUStringToOString(_sExtra,RTL_TEXTENCODING_ASCII_US); + + OSL_ENSURE(false, sMessage.getStr()); +// throw sax::SAXException(sMessage, NULL, uno::Any()); +} +// ----------------------------------------------------------------------------- +static +inline +sal_Bool matchPrefix(OUString const & _sString, OUString const & _sPrefix) +{ + return _sString.match(_sPrefix); +} +// ----------------------------------------------------------------------------- +static +inline +sal_Bool matchSuffix(OUString const & _sString, OUString const & _sSuffix) +{ + sal_Int32 nSuffixStart = _sString.getLength() - _sSuffix.getLength(); + if (nSuffixStart < 0) + return false; + + return _sString.match(_sSuffix,nSuffixStart); +} +// ----------------------------------------------------------------------------- +static +inline +OUString stripPrefix(OUString const & _sString, OUString const & _sPrefix) +{ + OSL_ASSERT( matchPrefix(_sString,_sPrefix) ); + + return _sString.copy(_sPrefix.getLength()); +} +// ----------------------------------------------------------------------------- +static +inline +OUString stripSuffix(OUString const & _sString, OUString const & _sSuffix) +{ + OSL_ASSERT( matchSuffix(_sString,_sSuffix) ); + + sal_Int32 nSuffixStart = _sString.getLength() - _sSuffix.getLength(); + + return _sString.copy(0,nSuffixStart); +} +// ----------------------------------------------------------------------------- +static +inline +OUString stripTypeName(OUString const & _sString, OUString const & _sPrefix) +{ + if (matchPrefix(_sString, _sPrefix)) + return stripPrefix(_sString, _sPrefix); + + badValueType("Missing expected prefix: ", _sPrefix); + + return _sString; +} +// ----------------------------------------------------------------------------- +/// retrieve data type of a property, +uno::Type ElementParser::getPropertyValueType(SaxAttributeList const& xAttribs) const +{ + OUString sTypeName; + if (!this->maybeGetAttribute(xAttribs, ATTR_VALUETYPE, sTypeName)) + return uno::Type(); // => VOID + + uno::Type aType; + + if (matchSuffix(sTypeName,VALUETYPE_LIST_SUFFIX)) + { + OUString sBasicName = stripTypeName( stripSuffix(sTypeName,VALUETYPE_LIST_SUFFIX), NS_PREFIX_OOR ); + + aType = toListType(sBasicName); + } + else + { + OUString sBasicName = stripTypeName( sTypeName, NS_PREFIX_OOR ); + + aType = toType(sBasicName); + } + + if (aType == uno::Type()) + badValueType("Unknown type name: ", sTypeName); + + return aType; +} +// ----------------------------------------------------------------------------- + +/// retrieve element type and associated module name of a set, +bool ElementParser::getSetElementType(SaxAttributeList const& xAttribs, OUString& aElementType, OUString& aElementTypeModule) const +{ + if (!this->maybeGetAttribute(xAttribs, ATTR_ITEMTYPE, aElementType)) + return false; + + maybeGetAttribute(xAttribs, ATTR_ITEMTYPECOMPONENT, aElementTypeModule); + + return true; +} +// ----------------------------------------------------------------------------- + +/// retrieve instance type and associated module name of a set, +bool ElementParser::getInstanceType(SaxAttributeList const& xAttribs, OUString& aElementType, OUString& aElementTypeModule) const +{ + if (!this->maybeGetAttribute(xAttribs, ATTR_ITEMTYPE, aElementType)) + return false; + + maybeGetAttribute(xAttribs, ATTR_ITEMTYPECOMPONENT, aElementTypeModule); + + return true; +} +// ----------------------------------------------------------------------------- + +/// retrieve the component for an import or uses element, +bool ElementParser::getImportComponent(SaxAttributeList const& xAttribs, OUString& _rsComponent) const +{ + return this->maybeGetAttribute(xAttribs, ATTR_COMPONENT, _rsComponent); +} +// ----------------------------------------------------------------------------- + +/// reads attributes for values from the attribute list +bool ElementParser::isNull(SaxAttributeList const& _xAttribs) const +{ + bool bNull; + return maybeGetAttribute(_xAttribs, EXT_ATTR_NULL, bNull) && bNull; +} +// ----------------------------------------------------------------------------- + +/// reads attributes for values from the attribute list +OUString ElementParser::getSeparator(SaxAttributeList const& _xAttribs) const +{ + OUString aSeparator; + maybeGetAttribute(_xAttribs, ATTR_VALUESEPARATOR, aSeparator); + return aSeparator; +} +// ----------------------------------------------------------------------------- + +// low-level internal methods +/// checks for presence of a boolean attribute and assigns its value if it exists (and is a bool) +bool ElementParser::maybeGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, bool& rAttributeValue) const +{ + OUString sAttribute; + + if ( !this->maybeGetAttribute(xAttribs, aAttributeName, sAttribute) ) + { + return false; + } + + else if (sAttribute.equals(ATTR_VALUE_TRUE)) + rAttributeValue = true; // will return true + + else if (sAttribute.equals(ATTR_VALUE_FALSE)) + rAttributeValue = false; // will return true + + else + { + OSL_ENSURE(sAttribute.getLength() == 0, "Invalid text found in boolean attribute"); + return false; + } + + return true; +} +// ----------------------------------------------------------------------------- + +/// checks for presence of an attribute and assigns its value if it exists +bool ElementParser::maybeGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, OUString& rAttributeValue) const +{ + return xAttribs.is() && impl_maybeGetAttribute(xAttribs, aAttributeName, rAttributeValue); +} +// ----------------------------------------------------------------------------- + +/// assigns an attribute value or an empty string if it doesn't exist +void ElementParser::alwaysGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, OUString& rAttributeValue) const +{ + if (xAttribs.is()) + rAttributeValue = xAttribs->getValueByName(aAttributeName); + else + rAttributeValue = OUString(); +} +// ----------------------------------------------------------------------------- +} // namespace +} // namespace + diff --git a/configmgr/source/xml/elementparser.hxx b/configmgr/source/xml/elementparser.hxx new file mode 100644 index 000000000000..4be2e1235520 --- /dev/null +++ b/configmgr/source/xml/elementparser.hxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * $RCSfile: elementparser.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_ELEMENTPARSER_HXX +#define CONFIGMGR_XML_ELEMENTPARSER_HXX + +#ifndef CONFIGMGR_XML_ELEMENTINFO_HXX +#include "elementinfo.hxx" +#endif + +#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_ +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#endif + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; + + using rtl::OUString; + +// ----------------------------------------------------------------------------- + class ElementParser + { + public: + typedef uno::Reference< sax::XAttributeList > SaxAttributeList; + public: + ElementParser() + {} + + /// reset the parser for a new document + void reset() + {} + + /// retrieve the (almost) complete information for an element + ElementInfo parseElementInfo(OUString const& _sTag, SaxAttributeList const& _xAttribs) const; + + /// retrieve the node name for an element + ElementType::Enum getNodeType(OUString const& _sTag, SaxAttributeList const& xAttribs) const; + + /// retrieve the node name for an element + ElementName getName(OUString const& _sTag, SaxAttributeList const& xAttribs, ElementType::Enum eType = ElementType::unknown) const; + + /// query whether the node has an operation + Operation::Enum getOperation(SaxAttributeList const& xAttribs) const; + + /// retrieve the language (if any) stored in the attribute list + bool getLanguage(SaxAttributeList const& xAttribs, OUString & _rsLanguage) const; + + /// reads attributes for nodes from the attribute list + ElementInfo::FlagsType getNodeFlags(SaxAttributeList const& xAttribs) const; + + /// retrieve element type and associated module name of a set, + bool getSetElementType(SaxAttributeList const& _xAttribs, OUString& _rsElementType, OUString& _rsElementTypeModule) const; + + /// retrieve the instance type and associated module name of a instance, + bool getInstanceType(SaxAttributeList const& _xAttribs, OUString& _rsElementType, OUString& _rsElementTypeModule) const; + + /// retrieve the component for an import or uses element, + bool getImportComponent(SaxAttributeList const& _xAttribs, OUString& _rsComponent) const; + + /// retrieve element type and associated module name of a set, + uno::Type getPropertyValueType(SaxAttributeList const& _xAttribs) const; + + /// reads a value attribute from the attribute list + bool isNull(SaxAttributeList const& _xAttribs) const; + + /// reads a value attribute from the attribute list + OUString getSeparator(SaxAttributeList const& _xAttribs) const; + + // low-level internal methods + + /// checks for presence of a boolean attribute and assigns its value if it exists (and is a bool) + bool maybeGetAttribute(SaxAttributeList const& _xAttribs, OUString const& _aAttributeName, bool& _rbAttributeValue) const; + + /// checks for presence of an attribute and assigns its value if it exists + bool maybeGetAttribute(SaxAttributeList const& _xAttribs, OUString const& _aAttributeName, OUString& _rsAttributeValue) const; + + /// assigns an attribute value or an empty string if it doesn't exist + void alwaysGetAttribute(SaxAttributeList const& _xAttribs, OUString const& _aAttributeName, OUString& _rsAttributeValue) const; + }; +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- +} // namespace configmgr + +#endif + diff --git a/configmgr/source/xml/layerparser.cxx b/configmgr/source/xml/layerparser.cxx new file mode 100644 index 000000000000..ab9d374606c1 --- /dev/null +++ b/configmgr/source/xml/layerparser.cxx @@ -0,0 +1,337 @@ +/************************************************************************* + * + * $RCSfile: layerparser.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "layerparser.hxx" + +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +LayerParser::LayerParser(ServiceFactory const & _xSvcFactory, uno::Reference< backenduno::XLayerHandler > const & _xHandler) +: BasicParser(_xSvcFactory) +, m_xHandler(_xHandler) +, m_bRemoved(false) +, m_bNewProp(false) +{ + if (!m_xHandler.is()) + { + OUString sMessage(RTL_CONSTASCII_USTRINGPARAM("Cannot create LayerParser: Unexpected NULL Handler")); + throw uno::RuntimeException(sMessage, NULL); + } +} +// ----------------------------------------------------------------------------- + +LayerParser::~LayerParser() +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerParser::startDocument( ) + throw (sax::SAXException, uno::RuntimeException) +{ + BasicParser::startDocument(); + + OSL_ENSURE(isEmptyNode(), "BasicParser does not mark new document as empty"); + + m_xHandler->startLayer(); + m_bRemoved = false; + m_bNewProp = false; +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerParser::endDocument( ) throw (sax::SAXException, uno::RuntimeException) +{ + if (isEmptyNode()) OSL_TRACE("Configuration Parser: XML layer document ended without any data"); + + BasicParser::endDocument(); + + m_xHandler->endLayer(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerParser::startElement( const OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) + throw (sax::SAXException, uno::RuntimeException) +{ + if ( this->isSkipping() ) + { + this->startSkipping( aName, xAttribs ); + return; + } + + ElementInfo aInfo = getDataParser().parseElementInfo(aName,xAttribs); + + switch (aInfo.type) + { + case ElementType::group: case ElementType::set: + OSL_ENSURE( false, "Layer XML parser - Unexpected: found group/set element (should be 'node')\n"); + // fall thru + case ElementType::node: + this->startNode(aInfo,xAttribs); + OSL_ASSERT( this->isInNode() && !this->isInProperty() ); + break; + + case ElementType::property: + this->startProperty(aInfo,xAttribs); + OSL_ASSERT( this->isInUnhandledProperty() ); + break; + + case ElementType::value: + this->startValueData(xAttribs); + OSL_ASSERT( this->isInValueData() ); + break; + + default: // skip unknown elements + OSL_ENSURE( aInfo.type >= ElementType::other, "Layer XML parser - Unexpected: found schema element in layer data\n"); + OSL_ENSURE( aInfo.type < ElementType::other, "Layer XML parser - Unexpected: found unknown element tag\n"); + this->startSkipping( aName, xAttribs ); + return; + } +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerParser::endElement( const OUString& aName ) + throw (sax::SAXException, uno::RuntimeException) +{ + if ( this->wasSkipping(aName) ) + return; + + if ( this->isInValueData()) + this->endValueData(); + + else if (this->isInProperty()) + this->endProperty(); + + else if (this->isInNode()) + this->endNode(); + + else + this->raiseParseException("Layer parser: Invalid XML: endElement without matching startElement"); + +} +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +void LayerParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + this->checkNotRemoved(); + + BasicParser::startNode(aInfo,xAttribs); + + switch (aInfo.op) + { + case Operation::none: + case Operation::modify: + m_xHandler->overrideNode(aInfo.name,aInfo.flags); + break; + + case Operation::replace: + { + backenduno::TemplateIdentifier aTemplate; + if (getDataParser().getInstanceType(xAttribs,aTemplate.Name,aTemplate.Component)) + m_xHandler->addOrReplaceNodeFromTemplate(aInfo.name,aTemplate,aInfo.flags); + else + m_xHandler->addOrReplaceNode(aInfo.name,aInfo.flags); + } + break; + + case Operation::remove: + m_xHandler->dropNode(aInfo.name); + m_bRemoved = true; + break; + + default: OSL_ASSERT(false); + case Operation::unknown: + this->raiseParseException("Layer parser: Invalid Data: unknown operation"); + } +} +// ----------------------------------------------------------------------------- + +void LayerParser::endNode() +{ + if (!this->isInRemoved()) + m_xHandler->endNode(); + else + m_bRemoved = false; + + BasicParser::endNode(); +} +// ----------------------------------------------------------------------------- + +void LayerParser::startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + this->checkNotRemoved(); + + BasicParser::startProperty(aInfo,xAttribs); + + switch (aInfo.op) + { + case Operation::none: + case Operation::modify: + case Operation::replace: + // defer to later + m_bNewProp = true; + break; + + case Operation::remove: + this->raiseParseException("Layer parser: Invalid Data: operation 'remove' is not permitted for properties"); + + default: OSL_ASSERT(false); + case Operation::unknown: + this->raiseParseException("Layer parser: Invalid Data: unknown operation"); + } +} +// ----------------------------------------------------------------------------- + +void LayerParser::endProperty() +{ + OSL_ASSERT(!this->isInRemoved()); + + if (m_bNewProp) + { + OSL_ASSERT(this->isEmptyNode()); + + ElementInfo const & aInfo = getActiveNodeInfo(); + switch (aInfo.op) + { + case Operation::none: + case Operation::modify: + OSL_ENSURE(aInfo.flags,"Warning: Empty property modification (and without attributes) in Layer"); + m_xHandler->overridePropertyAttributes(aInfo.name,aInfo.flags); + break; + + case Operation::replace: + m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); + break; + + default: + OSL_ASSERT(false); + } + m_bNewProp = false; + } + else + OSL_ASSERT(!this->isEmptyNode()); + + BasicParser::endProperty(); +} +// ----------------------------------------------------------------------------- + +void LayerParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) +{ + this->checkNotRemoved(); + + BasicParser::startValueData(xAttribs); +} +// ----------------------------------------------------------------------------- + +void LayerParser::endValueData() +{ + uno::Any aValue = this->getCurrentValue(); + + ElementInfo const & aInfo = this->getActiveNodeInfo(); + + if (this->isValueDataLocalized()) + { + OUString aLocale = this->getValueDataLocale(); + + if (m_bNewProp && aInfo.op == Operation::replace) + m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); + + m_xHandler->overridePropertyValueForLocale(aInfo.name,aLocale,aValue); + } + else + { + if (aInfo.op != Operation::replace) + m_xHandler->overridePropertyValue(aInfo.name,aInfo.flags,aValue); + + else if (aValue.hasValue()) + m_xHandler->addPropertyWithValue(aInfo.name,aInfo.flags,aValue); + + else + m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); + } + + m_bNewProp = false; + + BasicParser::endValueData(); +} +// ----------------------------------------------------------------------------- + +void LayerParser::checkNotRemoved() +{ + if (m_bRemoved) + raiseParseException("Layer parser: Invalid Data: Data inside removed node."); +} +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- + } // namespace + +// ----------------------------------------------------------------------------- +} // namespace + diff --git a/configmgr/source/xml/layerparser.hxx b/configmgr/source/xml/layerparser.hxx new file mode 100644 index 000000000000..4d435ce99378 --- /dev/null +++ b/configmgr/source/xml/layerparser.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: layerparser.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_LAYERPARSER_HXX +#define CONFIGMGR_XML_LAYERPARSER_HXX + +#ifndef CONFIGMGR_XML_BASICPARSER_HXX +#include "basicparser.hxx" +#endif + +#include <drafts/com/sun/star/configuration/backend/XLayerHandler.hpp> + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace lang = ::com::sun::star::lang; + + namespace sax = ::com::sun::star::xml::sax; + namespace backenduno = ::drafts::com::sun::star::configuration::backend; + +// ----------------------------------------------------------------------------- + + + class LayerParser : public BasicParser + { + public: + typedef uno::Reference< backenduno::XLayerHandler > HandlerRef; + + public: + LayerParser(ServiceFactory const & _xSvcFactory, HandlerRef const & _xHandler); + virtual ~LayerParser(); + + // XDocumentHandler + public: + virtual void SAL_CALL + startDocument( ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + endDocument( ) throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + startElement( const OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + endElement( const OUString& aName ) + throw (sax::SAXException, uno::RuntimeException); + + private: + /// start an node + void startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end a node + void endNode(); + + /// start a property + void startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end a property + void endProperty(); + + /// start collecting data for a value - returns the locale of the value (property must have been started) + void startValueData(const uno::Reference< sax::XAttributeList >& xAttribs); + /// end collecting data for a value - returns the collected value + void endValueData(); + + bool isInRemoved() const { return m_bRemoved; } + void checkNotRemoved(); + private: + HandlerRef m_xHandler; + bool m_bRemoved; + bool m_bNewProp; + }; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- + +} // namespace configmgr +#endif + + + + diff --git a/configmgr/source/xml/makefile.mk b/configmgr/source/xml/makefile.mk index 1ad9d64c8cfa..5805bebc31a9 100644 --- a/configmgr/source/xml/makefile.mk +++ b/configmgr/source/xml/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.15 $ +# $Revision: 1.16 $ # -# last change: $Author: dg $ $Date: 2001-09-18 19:14:53 $ +# last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -99,6 +99,12 @@ SLOFILES=\ $(SLO)$/binarydecide.obj \ $(SLO)$/binarybasereader.obj \ $(SLO)$/generatecache.obj \ + $(SLO)$/elementparser.obj \ + $(SLO)$/basicparser.obj \ + $(SLO)$/layerparser.obj \ + $(SLO)$/schemaparser.obj \ + $(SLO)$/parsersvc.obj \ + $(SLO)$/xmlstrings.obj \ # --- Targets --- diff --git a/configmgr/source/xml/schemaparser.cxx b/configmgr/source/xml/schemaparser.cxx new file mode 100644 index 000000000000..160a325ba0de --- /dev/null +++ b/configmgr/source/xml/schemaparser.cxx @@ -0,0 +1,403 @@ +/************************************************************************* + * + * $RCSfile: schemaparser.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "schemaparser.hxx" + +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +SchemaParser::SchemaParser(ServiceFactory const & _xSvcFactory, uno::Reference< backenduno::XSchemaHandler > const & _xHandler, Select _selector) +: BasicParser(_xSvcFactory) +, m_xHandler(_xHandler) +, m_sComponent() +, m_selector(_selector) +, m_selected(selectNone) +{ + if (!m_xHandler.is()) + { + OUString sMessage(RTL_CONSTASCII_USTRINGPARAM("Cannot create SchemaParser: Unexpected NULL Handler")); + throw uno::RuntimeException(sMessage, *this); + } + OSL_ENSURE(m_selector != selectNone, "Warning: Schema handler will handle no part of the schema"); +} +// ----------------------------------------------------------------------------- + +SchemaParser::~SchemaParser() +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL SchemaParser::startDocument( ) + throw (sax::SAXException, uno::RuntimeException) +{ + BasicParser::startDocument(); + + OSL_ENSURE(isEmptyNode(), "BasicParser does not mark new document as empty"); + + m_sComponent = OUString(); + m_selected = selectNone; +} +// ----------------------------------------------------------------------------- + +void SAL_CALL SchemaParser::endDocument( ) throw (sax::SAXException, uno::RuntimeException) +{ + if (isSelected()) + raiseParseException("Schema XML Parser: Invalid XML: Document ends while section is open"); + + if (isEmptyNode()) OSL_TRACE("Configuration Parser: XML schema document ended without any data"); + + BasicParser::endDocument(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL SchemaParser::startElement( const OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) + throw (sax::SAXException, uno::RuntimeException) +{ + if ( this->isSkipping() ) + { + this->startSkipping( aName, xAttribs ); + return; + } + + ElementInfo aInfo = getDataParser().parseElementInfo(aName,xAttribs); + + switch (aInfo.type) + { + case ElementType::schema: + this->startSchema(aInfo,xAttribs); + break; + + case ElementType::component: + this->startSection(selectComponent, aInfo, xAttribs); + break; + + case ElementType::templates: + this->startSection(selectTemplates, aInfo, xAttribs); + break; + + case ElementType::import: + this->handleImport(aInfo,xAttribs); + break; + + case ElementType::instance: + this->handleInstance(aInfo,xAttribs); + break; + + case ElementType::item_type: + this->handleItemType(aInfo,xAttribs); + break; + + case ElementType::node: + raiseParseException( "Schema XML parser - Invalid data: found unspecified 'node' element.\n"); + // fall thru + case ElementType::group: case ElementType::set: + this->startNode(aInfo,xAttribs); + OSL_ASSERT( this->isInNode() ); + break; + + case ElementType::property: + this->startProperty(aInfo,xAttribs); + OSL_ASSERT( this->isInUnhandledProperty() ); + break; + + case ElementType::value: + this->startValueData(xAttribs); + OSL_ASSERT( this->isInValueData() ); + break; + + default: // skip unknown elements + OSL_ENSURE( aInfo.type >= ElementType::other, "Schema XML parser - Unexpected: found layer element in schema data\n"); + OSL_ENSURE( aInfo.type < ElementType::other, "Schema XML parser - Unexpected: found unknown element tag\n"); + this->startSkipping( aName, xAttribs ); + OSL_ASSERT( this->isSkipping() ); + return; + } + + OSL_ENSURE(aInfo.op == Operation::none || this->isSkipping(), + "Schema Parser: The 'op' attribute is not supported in a schema"); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL SchemaParser::endElement( const OUString& aName ) + throw (sax::SAXException, uno::RuntimeException) +{ + if ( this->wasSkipping(aName) ) + return; + + if ( this->isInValueData()) + this->endValueData(); + + else if (this->isInProperty()) + this->endProperty(); + + else if (this->isInNode()) + this->endNode(); + + else if (this->isSelected()) + this->endSection(); + + else + this->endSchema(); + +} +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +void SchemaParser::startSchema( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + m_sComponent = aInfo.name; + m_xHandler->startSchema(); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::endSchema( ) +{ + m_xHandler->endSchema(); + m_sComponent = OUString(); +} +// ----------------------------------------------------------------------------- + +bool SchemaParser::select(Select _select) +{ + if (isSelected()) + raiseParseException("Schema XML parser - Invalid data: found start of section while a section is still open.\n"); + + m_selected = static_cast<Select>(m_selector & _select); + + return m_selected != 0; +} +// ----------------------------------------------------------------------------- + +void SchemaParser::startSection( Select _select, ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + if (this->select(_select)) + { + if (_select == selectComponent) + { + m_xHandler->startComponent(m_sComponent); + } + } + else + startSkipping(aInfo.name,xAttribs); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::endSection( ) +{ + if (m_selected == selectComponent) + { + m_xHandler->endComponent(); + } + m_selected = selectNone; +} +// ----------------------------------------------------------------------------- + +void SchemaParser::handleImport( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + OUString aComponent; + if (getDataParser().getImportComponent(xAttribs,aComponent)) + m_xHandler->importComponent(aComponent); + + else + raiseParseException("Schema XML parser - Invalid data: Missing component attribute for import directive.\n"); + + this->startSkipping(aInfo.name,xAttribs); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::handleInstance( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + backenduno::TemplateIdentifier aTemplate; + if (getDataParser().getInstanceType(xAttribs, aTemplate.Name, aTemplate.Component)) + m_xHandler->addInstance(aInfo.name, aTemplate); + + else + raiseParseException("Schema XML parser - Invalid data: Missing type information for instantiation directive.\n"); + + this->startSkipping(aInfo.name,xAttribs); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::handleItemType( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + backenduno::TemplateIdentifier aTemplate; + if (getDataParser().getInstanceType(xAttribs, aTemplate.Name, aTemplate.Component)) + m_xHandler->addItemType(aTemplate); + + else + raiseParseException("Schema XML parser - Invalid data: Missing type information for instantiation directive.\n"); + + this->startSkipping(aInfo.name,xAttribs); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + BasicParser::startNode(aInfo,xAttribs); + + OSL_ASSERT(aInfo.type == ElementType::set || aInfo.type == ElementType::group); + + bool bStartTemplate = ( !isInNode() && m_selected == selectTemplates ); + + using backenduno::TemplateIdentifier; + + if (aInfo.type == ElementType::group) + { + if (bStartTemplate) + m_xHandler->startGroupTemplate( TemplateIdentifier(aInfo.name,m_sComponent), aInfo.flags ); + + else + m_xHandler->startGroup( aInfo.name, aInfo.flags ); + } + else + { + TemplateIdentifier aItemType; + + if (!getDataParser().getSetElementType(xAttribs, aItemType.Name, aItemType.Component)) + raiseParseException("Schema XML parser - Invalid data: Missing item-type information for set node.\n"); + + if (bStartTemplate) + m_xHandler->startSetTemplate( TemplateIdentifier(aInfo.name,m_sComponent), aInfo.flags, aItemType ); + + else + m_xHandler->startSet( aInfo.name, aInfo.flags, aItemType ); + } +} +// ----------------------------------------------------------------------------- + +void SchemaParser::endNode() +{ + BasicParser::endNode(); + + bool bEndedTemplate = ( !isInNode() && m_selected == selectTemplates ); + + if (!bEndedTemplate) + m_xHandler->endTemplate(); + + else + m_xHandler->endNode(); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) +{ + BasicParser::startProperty(aInfo,xAttribs); + + OSL_ENSURE( isInUnhandledProperty(), "Property not recognizable as unhandled"); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::endProperty() +{ + if (isInUnhandledProperty()) + { + ElementInfo const & aInfo = this->getActiveNodeInfo(); + + m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); + } + + BasicParser::endProperty(); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) +{ + OSL_ENSURE( this->isInUnhandledProperty(),"Schema XML parser - multiple values in property are not permitted in the schema.\n"); + + BasicParser::startValueData(xAttribs); + + OSL_ENSURE(!this->isValueDataLocalized(),"Schema XML parser - language attributes on values are ignored in the schema.\n"); +} +// ----------------------------------------------------------------------------- + +void SchemaParser::endValueData() +{ + uno::Any aValue = this->getCurrentValue(); + + ElementInfo const & aInfo = this->getActiveNodeInfo(); + + if (aValue.hasValue()) + m_xHandler->addPropertyWithDefault(aInfo.name,aInfo.flags,aValue); + + else + m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); + + BasicParser::endValueData(); + + OSL_ENSURE( !isInUnhandledProperty(), "Property not recognizable as handled"); +} +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- + } // namespace + +// ----------------------------------------------------------------------------- +} // namespace + diff --git a/configmgr/source/xml/schemaparser.hxx b/configmgr/source/xml/schemaparser.hxx new file mode 100644 index 000000000000..188074cd3c4b --- /dev/null +++ b/configmgr/source/xml/schemaparser.hxx @@ -0,0 +1,169 @@ +/************************************************************************* + * + * $RCSfile: schemaparser.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_SCHEMAPARSER_HXX +#define CONFIGMGR_XML_SCHEMAPARSER_HXX + +#ifndef CONFIGMGR_XML_BASICPARSER_HXX +#include "basicparser.hxx" +#endif + +#include <drafts/com/sun/star/configuration/backend/XSchemaHandler.hpp> + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace lang = ::com::sun::star::lang; + + namespace sax = ::com::sun::star::xml::sax; + namespace backenduno = ::drafts::com::sun::star::configuration::backend; + +// ----------------------------------------------------------------------------- + + + class SchemaParser : public BasicParser + { + public: + typedef uno::Reference< backenduno::XSchemaHandler > HandlerRef; + enum Select { + selectNone = 0, + selectComponent = 0x01, + selectTemplates = 0x02, + selectAll = 0x03 + }; + + public: + SchemaParser(ServiceFactory const & _xSvcFactory, HandlerRef const & _xHandler, Select _selector); + virtual ~SchemaParser(); + + // XDocumentHandler + public: + virtual void SAL_CALL + startDocument( ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + endDocument( ) throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + startElement( const OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) + throw (sax::SAXException, uno::RuntimeException); + + virtual void SAL_CALL + endElement( const OUString& aName ) + throw (sax::SAXException, uno::RuntimeException); + + private: + /// start the schema + void startSchema( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end the schema + void endSchema(); + + /// start a section (components or templates) + void startSection( Select _select, ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end the current section + void endSection(); + + /// handle a import directive element + void handleImport( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + + /// start an node + void startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end a node + void endNode(); + + /// start a property + void startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// end a property + void endProperty(); + + /// start collecting data for a value - returns the locale of the value (property must have been started) + void startValueData(const uno::Reference< sax::XAttributeList >& xAttribs); + /// end collecting data for a value - returns the collected value + void endValueData(); + + /// handle a instance ref element + void handleInstance( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + /// handle a item-type declaration element + void handleItemType( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); + + bool isSelected() const { return m_selected != selectNone; } + bool select(Select _select); + private: + HandlerRef m_xHandler; + OUString m_sComponent; + Select m_selector; + Select m_selected; + }; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- + +} // namespace configmgr +#endif + + + + diff --git a/configmgr/source/xml/valueconverter.cxx b/configmgr/source/xml/valueconverter.cxx index 8b929ebef6df..4f53d5f0e21c 100644 --- a/configmgr/source/xml/valueconverter.cxx +++ b/configmgr/source/xml/valueconverter.cxx @@ -2,9 +2,9 @@ * * $RCSfile: valueconverter.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: jb $ $Date: 2002-05-10 08:48:59 $ + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -404,6 +404,185 @@ bool OValueConverter::convertListToAny(StringList const& aContentList, uno::Any& } // ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +uno::Sequence<sal_Int8> ValueConverter::parseBinary(OUString const& aBinaryString_) const + CFG_UNO_THROW1 ( script::CannotConvertException) +{ + uno::Sequence<sal_Int8> aResultSeq; + + parseHexBinary(aBinaryString_,aResultSeq); + + return aResultSeq; +} + +// ----------------------------------------------------------------------------- +static inline +uno::Type getBinaryType() +{ + uno::Sequence<sal_Int8> const * const for_binary = 0; + return ::getCppuType(for_binary); +} + +// ----------------------------------------------------------------------------- +bool ValueConverter::isList() const +{ + return m_aType.getTypeClass() == uno::TypeClass_SEQUENCE && + m_aType != getBinaryType(); +} + +// ----------------------------------------------------------------------------- +uno::Any ValueConverter::convertToAny(OUString const& aContent) const + CFG_UNO_THROW1( script::CannotConvertException) +{ + uno::Any aValue; + + if (this->isNull()) + { + OSL_ENSURE(aContent.trim().getLength() == 0, "ValueConverter: Non-empty Null Value - ignoring content"); + OSL_ASSERT(!aValue.hasValue()); + } + + else if (this->isList()) + { + StringList aContentList; + splitListData(aContent, aContentList); + convertListToAny(aContentList, aValue); + } + + else + { + convertScalarToAny(aContent, aValue); + } + + return aValue; +} + +// ----------------------------------------------------------------------------- +bool ValueConverter::convertScalarToAny(OUString const& aContent, uno::Any& rValue) const + CFG_UNO_THROW1 ( script::CannotConvertException ) +{ + OSL_PRECOND(!this->isNull(),"OValueConverter::convertScalarToAny - check for NULL before calling"); + OSL_ENSURE(m_aType.getTypeClass() != uno::TypeClass_ANY,"'Any' values must be NULL"); + + // check for Binary + if (m_aType == getBinaryType()) + { + Sequence<sal_Int8> aBinarySeq = parseBinary(aContent); + rValue <<= aBinarySeq; + } + + else + { + rValue = toAny(m_xTypeConverter, aContent, m_aType.getTypeClass()); + } + + return !! rValue.hasValue(); +} + +// ----------------------------------------------------------------------------- +template <class T> +bool convertListToSequence(StringList const& aStringList, uno::Sequence< T >& rSequence, uno::TypeClass aElementTypeClass, ValueConverter const& rConverter) + CFG_UNO_THROW1 ( script::CannotConvertException ) +{ + OSL_ASSERT(aElementTypeClass == ::getCppuType(static_cast<T const*>(0)).getTypeClass()); + + rSequence.realloc(aStringList.size()); + + sal_uInt32 nPos = 0; + + for(StringList::const_iterator it = aStringList.begin(); + it != aStringList.end(); + ++it) + { + uno::Any aValueAny = toAny(rConverter.getTypeConverter(), *it, aElementTypeClass); + + if (aValueAny >>= rSequence[nPos]) + ++nPos; + + else if (!aValueAny.hasValue()) + OSL_ENSURE(false,"UNEXPECTED: Found NULL value in List - ignoring value !"); + + else + OSL_ENSURE(false,"ERROR: Cannot extract converted value into List - skipping value !"); + } + + bool bOK = (nPos == aStringList.size()); + + if (!bOK) + { + OSL_ASSERT(nPos < aStringList.size()); + rSequence.realloc(nPos); + } + return bOK; +} + +// ----------------------------------------------------------------------------- +// special overload for binary sequence + +// template<> // use an explicit specialization +bool convertListToSequence(StringList const& aStringList, uno::Sequence< uno::Sequence<sal_Int8> >& rSequence, uno::TypeClass aElementTypeClass, ValueConverter const& rParser ) + CFG_UNO_THROW1 ( script::CannotConvertException ) +{ + OSL_ASSERT(aElementTypeClass == uno::TypeClass_SEQUENCE); + + rSequence.realloc(aStringList.size()); + + sal_uInt32 nPos = 0; + + for(StringList::const_iterator it = aStringList.begin(); + it != aStringList.end(); + ++it) + { + rSequence[nPos++] = rParser.parseBinary(*it); + } + return true; +} + +// ----------------------------------------------------------------------------- + +#define MAYBE_EXTRACT_SEQUENCE( type ) \ + if (aElementType == ::getCppuType( (type const *)0)) \ + { \ + Sequence< type > aSequence; \ + convertListToSequence(aContentList,aSequence,aElementTypeClass, *this); \ + rValue <<= aSequence; \ + } + +bool ValueConverter::convertListToAny(StringList const& aContentList, uno::Any& rValue) const + CFG_UNO_THROW1 ( script::CannotConvertException ) +{ + OSL_PRECOND(!this->isNull(),"OValueConverter::convertListToAny - check for NULL before calling"); + OSL_ENSURE(m_aType.getTypeClass() != uno::TypeClass_ANY,"'Any' not allowed for lists"); + + uno::Type aElementType = getSequenceElementType(m_aType); + uno::TypeClass aElementTypeClass = aElementType.getTypeClass(); + + OSL_ENSURE(aElementTypeClass != uno::TypeClass_ANY,"'Any' not allowed for list elements"); + + MAYBE_EXTRACT_SEQUENCE( OUString ) + else + MAYBE_EXTRACT_SEQUENCE( sal_Bool ) + else + MAYBE_EXTRACT_SEQUENCE( sal_Int16 ) + else + MAYBE_EXTRACT_SEQUENCE( sal_Int32 ) + else + MAYBE_EXTRACT_SEQUENCE( sal_Int64 ) + else + MAYBE_EXTRACT_SEQUENCE( double ) + else + MAYBE_EXTRACT_SEQUENCE( Sequence<sal_Int8> ) + else + { + OSL_ENSURE(false, "Unknown element type in list"); + throwConversionError("Invalid value-type found in list value"); + } + + return !! rValue.hasValue(); +} +#undef MAYBE_EXTRACT_SEQUENCE + +// ----------------------------------------------------------------------------- namespace { sal_Int32 const NO_MORE_TOKENS = -1; @@ -547,5 +726,31 @@ void OValueConverter::splitListData(OUString const& aContent, StringList& rConte } } // ----------------------------------------------------------------------------- +void ValueConverter::splitListData(OUString const& aContent, StringList& rContentList) const + CFG_NOTHROW( ) +{ + OUString sSeparator = m_sSeparator; + + bool bSeparateByWhitespace = (sSeparator.trim().getLength() == 0); + + OSL_ENSURE( bSeparateByWhitespace == (!sSeparator.getLength() || sSeparator.equals(DEFAULT_SEPARATOR)), + "Unexpected whitespace-only separator"); + + if (bSeparateByWhitespace) + { + OSL_ENSURE( sSeparator.getLength()==0 || sSeparator.equals(DEFAULT_SEPARATOR), + "Unexpected whitespace-only separator"); + + tokenizeListData( OTokenizeByWhitespace(), aContent, rContentList ); + } + else + { + OSL_ENSURE( sSeparator.trim()==sSeparator, + "Unexpected whitespace in separator"); + + tokenizeListData( OTokenizeBySeparator(sSeparator), aContent, rContentList ); + } +} +// ----------------------------------------------------------------------------- } // namespace diff --git a/configmgr/source/xml/xmlstrings.cxx b/configmgr/source/xml/xmlstrings.cxx new file mode 100644 index 000000000000..1fdf8a48866a --- /dev/null +++ b/configmgr/source/xml/xmlstrings.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: xmlstrings.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "xmlstrings.hxx" + +//......................................................................... +namespace configmgr +{ +//......................................................................... + + namespace xml + { +//---------------------------------------------------------------------------- +// For now: Include the fixed OOR prefix into (most) tag and attribute names +#define OOR_PREFIX_ "oor:" +//---------------------------------------------------------------------------- + // extern declaration for strings used in the XML format + // namespace prefixes + IMPLEMENT_CONSTASCII_USTRING(NS_PREFIX_OOR, "oor:"); + IMPLEMENT_CONSTASCII_USTRING(NS_PREFIX_XS, "xs:"); + + // namespace urls + IMPLEMENT_CONSTASCII_USTRING(NS_URI_OOR,"http://openoffice.org/2001/registry"); + IMPLEMENT_CONSTASCII_USTRING(NS_URI_XS, "http://www.w3.org/2001/XMLSchema"); + + // tag names + IMPLEMENT_CONSTASCII_USTRING(TAG_SCHEMA, OOR_PREFIX_"component-schema"); + + IMPLEMENT_CONSTASCII_USTRING(TAG_COMPONENT, OOR_PREFIX_"component"); + IMPLEMENT_CONSTASCII_USTRING(TAG_TEMPLATES, OOR_PREFIX_"templates"); + + IMPLEMENT_CONSTASCII_USTRING(TAG_NODE, OOR_PREFIX_"node"); + IMPLEMENT_CONSTASCII_USTRING(TAG_GROUP, OOR_PREFIX_"group"); + IMPLEMENT_CONSTASCII_USTRING(TAG_SET, OOR_PREFIX_"set"); + IMPLEMENT_CONSTASCII_USTRING(TAG_PROP, OOR_PREFIX_"prop"); + + IMPLEMENT_CONSTASCII_USTRING(TAG_VALUE, OOR_PREFIX_"value"); + IMPLEMENT_CONSTASCII_USTRING(TAG_IMPORT, OOR_PREFIX_"import"); + IMPLEMENT_CONSTASCII_USTRING(TAG_INSTANCE, OOR_PREFIX_"node-ref"); + IMPLEMENT_CONSTASCII_USTRING(TAG_ITEMTYPE, OOR_PREFIX_"item"); + + // attribute names + IMPLEMENT_CONSTASCII_USTRING(ATTR_NAME, OOR_PREFIX_"name"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_CONTEXT, OOR_PREFIX_"context"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_PACKAGE, OOR_PREFIX_"package"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_COMPONENT,OOR_PREFIX_"component"); + + IMPLEMENT_CONSTASCII_USTRING(ATTR_ITEMTYPE, OOR_PREFIX_"node-type"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_ITEMTYPECOMPONENT,OOR_PREFIX_"component"); + + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUETYPE, OOR_PREFIX_"type"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUESEPARATOR, OOR_PREFIX_"separator"); + + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_EXTENSIBLE, OOR_PREFIX_"extensible"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_FINALIZED, OOR_PREFIX_"finalized"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_READONLY, OOR_PREFIX_"readonly"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_MANDATORY, OOR_PREFIX_"mandatory"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_NULLABLE, OOR_PREFIX_"nillable"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_LOCALIZED, OOR_PREFIX_"localized"); + + IMPLEMENT_CONSTASCII_USTRING(ATTR_OPERATION, OOR_PREFIX_"op"); + + // attributes defined elsewhere + IMPLEMENT_CONSTASCII_USTRING(EXT_ATTR_LANGUAGE, "xml:lang"); + IMPLEMENT_CONSTASCII_USTRING(EXT_ATTR_NULL, "xsi:nil"); + + // attribute contents + // boolean constants + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_TRUE, "true"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_FALSE, "false"); + + // simple types names + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_BOOLEAN, "boolean"); + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_SHORT, "short"); + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_INT, "int"); + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_LONG, "long"); + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_DOUBLE, "double"); + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_STRING, "string"); + // Type: Sequence<bytes> + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_BINARY, "hexBinary"); + // Universal type: Any + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_ANY, "any"); + + // modifier suffix for list types + IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_LIST_SUFFIX, "-list"); + + // States for update actions + IMPLEMENT_CONSTASCII_USTRING(OPERATION_MODIFY, OOR_PREFIX_"modify"); + IMPLEMENT_CONSTASCII_USTRING(OPERATION_REPLACE, OOR_PREFIX_"replace"); + IMPLEMENT_CONSTASCII_USTRING(OPERATION_REMOVE, OOR_PREFIX_"remove"); + + // the default separator for strings + IMPLEMENT_CONSTASCII_USTRING(SEPARATOR_WHITESPACE, " "); + + // Needed for building attribute lists + IMPLEMENT_CONSTASCII_USTRING(XML_ATTRTYPE_CDATA, "CDATA"); + + } // namespace xml + +} // namespace configmgr + + diff --git a/configmgr/source/xml/xmlstrings.hxx b/configmgr/source/xml/xmlstrings.hxx new file mode 100644 index 000000000000..12f983e3c03b --- /dev/null +++ b/configmgr/source/xml/xmlstrings.hxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * $RCSfile: xmlstrings.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef CONFIGMGR_XML_STRINGS_HXX_ +#define CONFIGMGR_XML_STRINGS_HXX_ + +#ifndef _CONFIGMGR_STRINGS_HXX_ +#include "strings.hxx" +#endif + +//......................................................................... +namespace configmgr +{ +//......................................................................... + + namespace xml + { + // extern declaration for strings used in the XML format + // namespace prefixes + DECLARE_CONSTASCII_USTRING(NS_PREFIX_OOR); + DECLARE_CONSTASCII_USTRING(NS_PREFIX_XS); + + // namespace urls + DECLARE_CONSTASCII_USTRING(NS_URI_OOR); + DECLARE_CONSTASCII_USTRING(NS_URI_XS); + DECLARE_CONSTASCII_USTRING(NS_URI_XSI); + + // tag names + DECLARE_CONSTASCII_USTRING(TAG_SCHEMA); + + DECLARE_CONSTASCII_USTRING(TAG_COMPONENT); + DECLARE_CONSTASCII_USTRING(TAG_TEMPLATES); + + DECLARE_CONSTASCII_USTRING(TAG_NODE); + DECLARE_CONSTASCII_USTRING(TAG_GROUP); + DECLARE_CONSTASCII_USTRING(TAG_SET); + DECLARE_CONSTASCII_USTRING(TAG_PROP); + + DECLARE_CONSTASCII_USTRING(TAG_IMPORT); + DECLARE_CONSTASCII_USTRING(TAG_INSTANCE); + DECLARE_CONSTASCII_USTRING(TAG_ITEMTYPE); + DECLARE_CONSTASCII_USTRING(TAG_VALUE); + + // attribute names + DECLARE_CONSTASCII_USTRING(ATTR_NAME); + DECLARE_CONSTASCII_USTRING(ATTR_CONTEXT); + DECLARE_CONSTASCII_USTRING(ATTR_PACKAGE); + DECLARE_CONSTASCII_USTRING(ATTR_COMPONENT); + + DECLARE_CONSTASCII_USTRING(ATTR_ITEMTYPE); + DECLARE_CONSTASCII_USTRING(ATTR_ITEMTYPECOMPONENT); + + DECLARE_CONSTASCII_USTRING(ATTR_VALUETYPE); + DECLARE_CONSTASCII_USTRING(ATTR_VALUESEPARATOR); + + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_EXTENSIBLE); + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_FINALIZED); + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_READONLY); + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_MANDATORY); + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_NULLABLE); + DECLARE_CONSTASCII_USTRING(ATTR_FLAG_LOCALIZED); + + DECLARE_CONSTASCII_USTRING(ATTR_OPERATION); + + // attributes defined elsewhere + DECLARE_CONSTASCII_USTRING(EXT_ATTR_LANGUAGE); + DECLARE_CONSTASCII_USTRING(EXT_ATTR_NULL); + + // attribute contents + // boolean constants + DECLARE_CONSTASCII_USTRING(ATTR_VALUE_TRUE); + DECLARE_CONSTASCII_USTRING(ATTR_VALUE_FALSE); + + // simple types names + DECLARE_CONSTASCII_USTRING(VALUETYPE_BOOLEAN); + DECLARE_CONSTASCII_USTRING(VALUETYPE_BYTE); + DECLARE_CONSTASCII_USTRING(VALUETYPE_SHORT); + DECLARE_CONSTASCII_USTRING(VALUETYPE_INT); + DECLARE_CONSTASCII_USTRING(VALUETYPE_LONG); + DECLARE_CONSTASCII_USTRING(VALUETYPE_DOUBLE); + DECLARE_CONSTASCII_USTRING(VALUETYPE_STRING); + // Type: Sequence<bytes> + DECLARE_CONSTASCII_USTRING(VALUETYPE_BINARY); + // Universal type: Any + DECLARE_CONSTASCII_USTRING(VALUETYPE_ANY); + + // modifier suffix for list types + DECLARE_CONSTASCII_USTRING(VALUETYPE_LIST_SUFFIX); + + // States for update actions + DECLARE_CONSTASCII_USTRING(OPERATION_MODIFY); + DECLARE_CONSTASCII_USTRING(OPERATION_REPLACE); + DECLARE_CONSTASCII_USTRING(OPERATION_REMOVE); + + // the default separator for strings + DECLARE_CONSTASCII_USTRING(SEPARATOR_WHITESPACE); + + // Needed for building attribute lists + DECLARE_CONSTASCII_USTRING(XML_ATTRTYPE_CDATA); + + } // namespace xml + +} // namespace configmgr +#endif + |