From 47692bfc1275bfa24a7fb2627cc263142549d29d Mon Sep 17 00:00:00 2001 From: sb Date: Mon, 2 Nov 2009 12:49:32 +0100 Subject: sb111: #i101955# moved configmgr2/ to configmgr/ --- configmgr/source/xml/basicparser.cxx | 536 --------------------------- configmgr/source/xml/basicparser.hxx | 178 --------- configmgr/source/xml/elementformatter.cxx | 324 ----------------- configmgr/source/xml/elementformatter.hxx | 118 ------ configmgr/source/xml/elementinfo.hxx | 119 ------ configmgr/source/xml/elementparser.cxx | 585 ------------------------------ configmgr/source/xml/elementparser.hxx | 125 ------- configmgr/source/xml/layerparser.cxx | 371 ------------------- configmgr/source/xml/layerparser.hxx | 119 ------ configmgr/source/xml/layerwriter.cxx | 544 --------------------------- configmgr/source/xml/layerwriter.hxx | 169 --------- configmgr/source/xml/makefile.mk | 70 ---- configmgr/source/xml/matchlocale.cxx | 387 -------------------- configmgr/source/xml/parsersvc.cxx | 385 -------------------- configmgr/source/xml/parsersvc.hxx | 117 ------ configmgr/source/xml/schemaparser.cxx | 409 --------------------- configmgr/source/xml/schemaparser.hxx | 135 ------- configmgr/source/xml/simpletypehelper.cxx | 57 --- configmgr/source/xml/typeconverter.cxx | 354 ------------------ configmgr/source/xml/valueconverter.cxx | 504 ------------------------- configmgr/source/xml/valueformatter.cxx | 498 ------------------------- configmgr/source/xml/valueformatter.hxx | 84 ----- configmgr/source/xml/writersvc.cxx | 261 ------------- configmgr/source/xml/writersvc.hxx | 124 ------- configmgr/source/xml/xmlstrings.cxx | 140 ------- configmgr/source/xml/xmlstrings.hxx | 134 ------- 26 files changed, 6847 deletions(-) delete mode 100644 configmgr/source/xml/basicparser.cxx delete mode 100644 configmgr/source/xml/basicparser.hxx delete mode 100644 configmgr/source/xml/elementformatter.cxx delete mode 100644 configmgr/source/xml/elementformatter.hxx delete mode 100644 configmgr/source/xml/elementinfo.hxx delete mode 100644 configmgr/source/xml/elementparser.cxx delete mode 100644 configmgr/source/xml/elementparser.hxx delete mode 100644 configmgr/source/xml/layerparser.cxx delete mode 100644 configmgr/source/xml/layerparser.hxx delete mode 100644 configmgr/source/xml/layerwriter.cxx delete mode 100644 configmgr/source/xml/layerwriter.hxx delete mode 100644 configmgr/source/xml/makefile.mk delete mode 100644 configmgr/source/xml/matchlocale.cxx delete mode 100644 configmgr/source/xml/parsersvc.cxx delete mode 100644 configmgr/source/xml/parsersvc.hxx delete mode 100644 configmgr/source/xml/schemaparser.cxx delete mode 100644 configmgr/source/xml/schemaparser.hxx delete mode 100644 configmgr/source/xml/simpletypehelper.cxx delete mode 100644 configmgr/source/xml/typeconverter.cxx delete mode 100644 configmgr/source/xml/valueconverter.cxx delete mode 100644 configmgr/source/xml/valueformatter.cxx delete mode 100644 configmgr/source/xml/valueformatter.hxx delete mode 100644 configmgr/source/xml/writersvc.cxx delete mode 100644 configmgr/source/xml/writersvc.hxx delete mode 100644 configmgr/source/xml/xmlstrings.cxx delete mode 100644 configmgr/source/xml/xmlstrings.hxx (limited to 'configmgr/source/xml') diff --git a/configmgr/source/xml/basicparser.cxx b/configmgr/source/xml/basicparser.cxx deleted file mode 100644 index 4f7455679688..000000000000 --- a/configmgr/source/xml/basicparser.cxx +++ /dev/null @@ -1,536 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: basicparser.cxx,v $ - * $Revision: 1.11 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "basicparser.hxx" -#include -#include "valuetypeconverter.hxx" -// ----------------------------------------------------------------------------- - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - -namespace -{ - static inline - uno::Reference< script::XTypeConverter > createTCV(uno::Reference< uno::XComponentContext > const & _xContext) - { - OSL_ENSURE(_xContext.is(),"Cannot create Parser without a Context"); - - static const rtl::OUString k_sTCVService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")); - - uno::Reference< lang::XMultiComponentFactory > xSvcFactory = _xContext->getServiceManager(); - return uno::Reference< script::XTypeConverter >::query(xSvcFactory->createInstanceWithContext(k_sTCVService,_xContext)); - } -} -// ----------------------------------------------------------------------------- - -struct BasicParser::ValueData : ValueConverter -{ - rtl::OUString content; - rtl::OUString locale; - bool isLocalized; - - ValueData(uno::Type const& _aType, uno::Reference< script::XTypeConverter > const & _xTCV) - : ValueConverter(_aType, _xTCV) - , content() - , locale() - , isLocalized(false) - { - } - - uno::Any convertToAny() const - { - return ValueConverter::convertToAny(this->content); - } - - rtl::OUString toString() const - { - return this->content; - } - - uno::Sequence toStringList() const - { - return ValueConverter::splitStringList(this->content); - } - - void setLocalized(rtl::OUString const & _aLocale) - { - isLocalized = true; - locale = _aLocale; - } -}; -// ----------------------------------------------------------------------------- - -BasicParser::BasicParser(uno::Reference< uno::XComponentContext > const & _xContext) -: m_xTypeConverter( createTCV(_xContext) ) -, m_xLocator(NULL) -, m_aDataParser(Logger(_xContext)) -, m_aNodes() -, m_aValueType() -, m_pValueData(NULL) -, m_nSkipLevels(0) -, m_bEmpty(true) -, m_bInProperty(false) -{ - if (!m_xTypeConverter.is()) - throw uno::RuntimeException(); - - OSL_DEBUG_ONLY( dbgUpdateLocation() ); -} -// ----------------------------------------------------------------------------- - -BasicParser::~BasicParser() -{ - delete m_pValueData; -} -// ----------------------------------------------------------------------------- - -#if OSL_DEBUG_LEVEL > 0 -void BasicParser::dbgUpdateLocation() -{ -#ifndef DBG_UTIL - rtl::OUString dbgPublicId, dbgSystemId; - sal_Int32 dbgLineNo, dbgColumnNo; -#endif // OSL_DEBUG_LEVEL - - if (m_xLocator.is()) - { - dbgPublicId = m_xLocator->getPublicId(); - dbgSystemId = m_xLocator->getSystemId(); - dbgLineNo = m_xLocator->getLineNumber(); - dbgColumnNo = m_xLocator->getColumnNumber(); - } - else - { - dbgPublicId = dbgSystemId = rtl::OUString::createFromAscii("<<>>"); - dbgLineNo = dbgColumnNo = -1; - } -} -#endif -// ----------------------------------------------------------------------------- -void SAL_CALL BasicParser::startDocument( ) - throw (sax::SAXException, uno::RuntimeException) -{ - m_aDataParser.reset(); - m_aValueType = uno::Type(); - m_bInProperty = false; - m_nSkipLevels = 0; - - delete m_pValueData, m_pValueData = NULL; - - while (!m_aNodes.empty()) m_aNodes.pop(); - - m_bEmpty = true; - - OSL_DEBUG_ONLY( dbgUpdateLocation() ); -} -// ----------------------------------------------------------------------------- - -void SAL_CALL BasicParser::endDocument( ) throw (sax::SAXException, uno::RuntimeException) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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 rtl::OUString& aChars ) - throw (sax::SAXException, uno::RuntimeException) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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 rtl::OUString& aWhitespaces ) - throw (sax::SAXException, uno::RuntimeException) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - 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 rtl::OUString& /*aTarget*/, const rtl::OUString& /*aData*/ ) - throw (sax::SAXException, uno::RuntimeException) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - 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; - OSL_DEBUG_ONLY( dbgUpdateLocation() ); -} -// ----------------------------------------------------------------------------- - -void BasicParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& /*xAttribs*/ ) -{ - { (void)aInfo; } - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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_DEBUG_ONLY( dbgUpdateLocation() ); - - 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_DEBUG_ONLY( dbgUpdateLocation() ); - - 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" ); - - try - { - m_aValueType = getDataParser().getPropertyValueType(xAttribs); - } - catch (ElementParser::BadValueType & error) - { - raiseParseException(error.message()); - } - - m_bInProperty = true; - - 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_DEBUG_ONLY( dbgUpdateLocation() ); - - 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(); - m_bInProperty = false; - - OSL_POSTCOND( !isInProperty(), "Could not get mark end of property" ); -} -// ----------------------------------------------------------------------------- - -uno::Type BasicParser::getActivePropertyType() -{ - return m_aValueType; -} -// ----------------------------------------------------------------------------- - -bool BasicParser::isInProperty() -{ - return m_bInProperty; -} -// ----------------------------------------------------------------------------- - -bool BasicParser::isInUnhandledProperty() -{ - return m_bEmpty && m_bInProperty; -} -// ----------------------------------------------------------------------------- - -void BasicParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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, m_xTypeConverter); - - m_pValueData->setIsNull( getDataParser().isNull(xAttribs) ); - - m_pValueData->setSeparator( getDataParser().getSeparator(xAttribs) ); - - OSL_ENSURE( !m_pValueData->hasSeparator() || - !m_pValueData->isTypeSet() || - m_pValueData->isList(), - "Warning: Spurious oor:separator on value that is not a list"); - OSL_ENSURE( !m_pValueData->hasSeparator() || - !m_pValueData->isNull(), - "Warning: Spurious oor:separator on value that is not a list"); - - rtl::OUString aLocale; - if ( getDataParser().getLanguage(xAttribs,aLocale) ) - m_pValueData->setLocalized( aLocale ); -} -// ----------------------------------------------------------------------------- - -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; -} -// ----------------------------------------------------------------------------- - -rtl::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_DEBUG_ONLY( dbgUpdateLocation() ); - - OSL_ASSERT( isInValueData() ); - - uno::Any aResult; - - if (m_pValueData->isTypeSet()) - try - { - aResult = m_pValueData->convertToAny(); - } - catch (script::CannotConvertException & e) - { - this->raiseParseException(uno::makeAny(e),"Configuration XML Parser - Invalid Data: Cannot convert value to type of property" ); - } - else if (m_pValueData->isNull()) - { - // nothing to do - } - else if (m_pValueData->hasSeparator() || m_pValueData->isList()) - { - aResult <<= m_pValueData->toStringList(); - } - else - { - aResult <<= m_pValueData->toString(); - } - return aResult; -} -// ----------------------------------------------------------------------------- - -/// end collecting data for a value -void BasicParser::endValueData() -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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 rtl::OUString& aName, const uno::Reference< sax::XAttributeList >& /*xAttribs*/ ) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - m_aNodes.push( ElementInfo(aName) ); - ++m_nSkipLevels; -} -// ----------------------------------------------------------------------------- - -bool BasicParser::wasSkipping( const rtl::OUString& aName ) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - 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 ) - SAL_THROW((sax::SAXException, uno::RuntimeException)) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid Data: "; - - rtl::OUString sMessage = rtl::OUString::createFromAscii(_pMsg); - - uno::Exception aEx; - if (_aTargetException >>= aEx) - sMessage += aEx.Message; - - getLogger().error(sMessage,"parse","configuration::xml::BasicParser"); - throw sax::SAXException( sMessage, *this, _aTargetException ); -} -// ----------------------------------------------------------------------------- - -void BasicParser::raiseParseException( sal_Char const * _pMsg ) - SAL_THROW((sax::SAXException, uno::RuntimeException)) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - if (_pMsg == 0) _pMsg = "Configuration XML Parser: Invalid XML"; - - rtl::OUString const sMessage = rtl::OUString::createFromAscii(_pMsg); - - getLogger().error(sMessage,"parse","configuration::xml::BasicParser"); - throw sax::SAXException( sMessage, *this, uno::Any() ); -} -// ----------------------------------------------------------------------------- - -void BasicParser::raiseParseException( rtl::OUString const & sMessage ) - SAL_THROW((sax::SAXException, uno::RuntimeException)) -{ - OSL_DEBUG_ONLY( dbgUpdateLocation() ); - - if (sMessage.getLength() == 0) raiseParseException(NULL); - - getLogger().error(sMessage,"parse","configuration::xml::BasicParser"); - throw sax::SAXException( sMessage, *this, uno::Any() ); -} -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - } // namespace - -// ----------------------------------------------------------------------------- -} // namespace - diff --git a/configmgr/source/xml/basicparser.hxx b/configmgr/source/xml/basicparser.hxx deleted file mode 100644 index eaf40cf07c18..000000000000 --- a/configmgr/source/xml/basicparser.hxx +++ /dev/null @@ -1,178 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: basicparser.hxx,v $ - * $Revision: 1.10 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_BASICPARSER_HXX -#define CONFIGMGR_XML_BASICPARSER_HXX - -#include "elementparser.hxx" -#include "utility.hxx" -#include "stack.hxx" -#ifndef CONFIGMGR_LOGGER_HXX_ -#include "logger.hxx" -#endif -#include -#include - -namespace com { namespace sun { namespace star { namespace script { - class XTypeConverter; -} } } } - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - - class BasicParser - : public cppu::WeakImplHelper1 - { - struct ValueData; - - uno::Reference< com::sun::star::script::XTypeConverter > - m_xTypeConverter; - uno::Reference< sax::XLocator > m_xLocator; - ElementParser m_aDataParser; - Stack< ElementInfo > m_aNodes; - uno::Type m_aValueType; - ValueData * m_pValueData; - sal_uInt16 m_nSkipLevels; - bool m_bEmpty; - bool m_bInProperty; - -#if OSL_DEBUG_LEVEL > 0 -#ifdef DBG_UTIL - rtl::OUString dbgPublicId, dbgSystemId; - sal_Int32 dbgLineNo, dbgColumnNo; -#endif // DBG_UTIL - void dbgUpdateLocation(); -#endif // OSL_DEBUG_LEVEL - - public: - explicit BasicParser(uno::Reference< uno::XComponentContext > const & _xContext); - 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 rtl::OUString& aChars ) - throw (sax::SAXException, uno::RuntimeException); - - virtual void SAL_CALL - ignorableWhitespace( const rtl::OUString& aWhitespaces ) - throw (sax::SAXException, uno::RuntimeException); - - virtual void SAL_CALL - processingInstruction( const rtl::OUString& aTarget, const rtl::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; } - - Logger const & getLogger() { return m_aDataParser.logger(); } - - /// 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 - rtl::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 rtl::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 rtl::OUString& aTag ); - - protected: - void raiseParseException( uno::Any const & _aTargetException, sal_Char const * _pMsg = NULL) - SAL_THROW((sax::SAXException, uno::RuntimeException)); - void raiseParseException( sal_Char const * _pMsg ) - SAL_THROW((sax::SAXException, uno::RuntimeException)); - void raiseParseException( rtl::OUString const & aMsg ) - SAL_THROW((sax::SAXException, uno::RuntimeException)); - }; -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/elementformatter.cxx b/configmgr/source/xml/elementformatter.cxx deleted file mode 100644 index fb883f9d28d8..000000000000 --- a/configmgr/source/xml/elementformatter.cxx +++ /dev/null @@ -1,324 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: elementformatter.cxx,v $ - * $Revision: 1.17 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "elementformatter.hxx" -#include "xmlstrings.hxx" -#include "typeconverter.hxx" - -#include - -#include - -#include -#include - -// ----------------------------------------------------------------------------- - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - -ElementFormatter::ElementFormatter() -: m_aElementType(ElementType::unknown) -, m_xAttributes() -{ -} -// ----------------------------------------------------------------------------- - -ElementFormatter::~ElementFormatter() -{ -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::reset() -{ - m_aElementType = ElementType::unknown; - m_xAttributes.clear(); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addAttribute(rtl::OUString const & _anAttributeName, rtl::OUString const & _aValue) -{ - OSL_PRECOND(m_xAttributes.is(),"Trying to add an attribute to a non-existing list"); - - m_xAttributes->AddAttribute(_anAttributeName, - XML_ATTRTYPE_CDATA, - _aValue); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addAttribute(rtl::OUString const & _anAttributeName, bool _bValue) -{ - OSL_PRECOND(m_xAttributes.is(),"Trying to add an attribute to a non-existing list"); - - m_xAttributes->AddAttribute(_anAttributeName, - XML_ATTRTYPE_CDATA, - _bValue ? ATTR_VALUE_TRUE : ATTR_VALUE_FALSE); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addNamespaces() -{ - static rtl::OUString const sNamespaceDecl( RTL_CONSTASCII_USTRINGPARAM("xmlns:") ); - - addAttribute( sNamespaceDecl.concat(NS_PREFIX_OOR), static_cast(NS_URI_OOR)); - addAttribute( sNamespaceDecl.concat(NS_PREFIX_XS ), static_cast(NS_URI_XS )); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::prepareElement(ElementInfo const& _aInfo) -{ - if (!m_xAttributes.is()) - { - m_xAttributes.set( new ::comphelper::AttributeList() ); - addNamespaces(); - } - else - m_xAttributes->Clear(); - - m_aElementType = _aInfo.type; - - addName(_aInfo.name); - addNodeFlags(_aInfo.flags); - addOperation(_aInfo.op); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::prepareSimpleElement(ElementType::Enum _eType) -{ - if (!m_xAttributes.is()) - { - m_xAttributes.set( new ::comphelper::AttributeList() ); - addNamespaces(); - } - else - m_xAttributes->Clear(); - - m_aElementType = _eType; -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addName(rtl::OUString const & _aName) -{ - if (_aName.getLength()) - { - switch( m_aElementType ) - { - case ElementType::schema: - case ElementType::layer: - { - sal_Int32 nIndex = _aName.lastIndexOf('.'); - - rtl::OUString aNodeName = _aName.copy(nIndex + 1); - addAttribute(ATTR_NAME, aNodeName); - - OSL_ENSURE(nIndex > 0,"Found component root element without a package part in its name"); - if (nIndex > 0) - { - rtl::OUString aPackage = _aName.copy(0, nIndex); - addAttribute(ATTR_PACKAGE, aPackage); - } - } - break; - - default: - addAttribute(ATTR_NAME, _aName); - break; - } - } -} -// ----------------------------------------------------------------------------- - -inline -void ElementFormatter::maybeAddFlag(sal_Int16 _eFlags, sal_Int16 _eSelect, rtl::OUString const & _anAttributeName, bool _bValue) -{ - if (_eFlags & _eSelect) addAttribute(_anAttributeName,_bValue); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addNodeFlags(sal_Int16 _eFlags) -{ - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::SchemaAttribute::REQUIRED, ATTR_FLAG_NULLABLE, false); - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::SchemaAttribute::LOCALIZED, ATTR_FLAG_LOCALIZED); - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::SchemaAttribute::EXTENSIBLE, ATTR_FLAG_EXTENSIBLE); - - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::NodeAttribute::FINALIZED, ATTR_FLAG_FINALIZED); - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::NodeAttribute::MANDATORY, ATTR_FLAG_MANDATORY); - maybeAddFlag(_eFlags,com::sun::star::configuration::backend::NodeAttribute::READONLY, ATTR_FLAG_READONLY); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addOperation(Operation::Enum _eOp) -{ - switch (_eOp) - { - case Operation::none: break; - case Operation::modify: break ; //addAttribute(ATTR_OPERATION, static_cast(OPERATION_MODIFY)); break; - case Operation::clear: OSL_ENSURE(false,"'clear' operation is not yet supported"); break ; - //addAttribute(ATTR_OPERATION, static_cast(OPERATION_CLEAR)); break; - case Operation::replace: addAttribute(ATTR_OPERATION, static_cast(OPERATION_REPLACE)); break; - case Operation::fuse: addAttribute(ATTR_OPERATION, static_cast(OPERATION_FUSE)); break; - case Operation::remove: addAttribute(ATTR_OPERATION, static_cast(OPERATION_REMOVE)); break; - - case Operation::unknown: - OSL_ENSURE(false, "ElementFormatter: Trying to add attribute for 'unknown' operation"); - break; - default: - OSL_ENSURE(false, "ElementFormatter: Trying to add attribute for invalid operation"); - break; - } -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addInstanceType(rtl::OUString const & /*_aElementType*/, rtl::OUString const & /*_aElementTypeModule*/) -{ -} -// ----------------------------------------------------------------------------- - -static ::rtl::OUString toXmlTypeName(const uno::TypeClass& _rTypeClass) -{ - ::rtl::OUString aRet; - switch(_rTypeClass) - { - case uno::TypeClass_BOOLEAN: aRet = VALUETYPE_BOOLEAN; break; - case uno::TypeClass_SHORT: aRet = VALUETYPE_SHORT; break; - case uno::TypeClass_LONG: aRet = VALUETYPE_INT; break; - case uno::TypeClass_HYPER: aRet = VALUETYPE_LONG; break; - case uno::TypeClass_DOUBLE: aRet = VALUETYPE_DOUBLE; break; - case uno::TypeClass_STRING: aRet = VALUETYPE_STRING; break; - case uno::TypeClass_SEQUENCE: aRet = VALUETYPE_BINARY; break; - case uno::TypeClass_ANY: aRet = VALUETYPE_ANY; break; - default: - OSL_ENSURE(false,"Cannot get type name: unknown typeclass"); - break; - } - return aRet; -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addPropertyValueType(uno::Type const& _aType) -{ - if (_aType == uno::Type()) return; - - bool bList = false; - uno::Type aSimpleType = getBasicType(_aType, bList); - uno::TypeClass aSimpleTypeClass = aSimpleType.getTypeClass(); - rtl::OUString aSimpleTypeName = toXmlTypeName(aSimpleTypeClass); - - rtl::OUString sNsPrefix = (bList || aSimpleTypeClass == uno::TypeClass_ANY) ? - rtl::OUString( NS_PREFIX_OOR ) : rtl::OUString( NS_PREFIX_XS ); - - rtl::OUStringBuffer aTypeNameBuf(sNsPrefix); - - if (sNsPrefix.getLength()) - aTypeNameBuf. append(k_NS_SEPARATOR); - - aTypeNameBuf. append(aSimpleTypeName); - - if (bList) - aTypeNameBuf. append(VALUETYPE_LIST_SUFFIX); - - addAttribute( ATTR_VALUETYPE, aTypeNameBuf.makeStringAndClear()); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addLanguage(rtl::OUString const & _sLanguage) -{ - OSL_ENSURE(_sLanguage.getLength(), "ElementFormatter: Trying to add empty language attribute"); - addAttribute(EXT_ATTR_LANGUAGE, _sLanguage); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addIsNull(bool _bIsNull) -{ - addAttribute( EXT_ATTR_NULL, _bIsNull); -} -// ----------------------------------------------------------------------------- - -void ElementFormatter::addSeparator(rtl::OUString const& _sSeparator) -{ - addAttribute( ATTR_VALUESEPARATOR, _sSeparator); -} -// ----------------------------------------------------------------------------- - -rtl::OUString ElementFormatter::getElementTag() const -{ - switch (m_aElementType) - { - case ElementType::schema: return rtl::OUString( TAG_SCHEMA ); - case ElementType::layer: return rtl::OUString( TAG_LAYER ); - - case ElementType::component: return rtl::OUString( TAG_COMPONENT ); - case ElementType::templates: return rtl::OUString( TAG_TEMPLATES ); - - case ElementType::property: return rtl::OUString( TAG_PROP ); - case ElementType::node: return rtl::OUString( TAG_NODE ); - case ElementType::group: return rtl::OUString( TAG_GROUP ); - case ElementType::set: return rtl::OUString( TAG_SET ); - - case ElementType::import: return rtl::OUString( TAG_IMPORT ); - case ElementType::instance: return rtl::OUString( TAG_INSTANCE ); - case ElementType::item_type: return rtl::OUString( TAG_ITEMTYPE ); - case ElementType::value: return rtl::OUString( TAG_VALUE ); - case ElementType::uses: return rtl::OUString( TAG_USES ); - - case ElementType::unknown: - OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for 'unknown' element type"); - break; - case ElementType::other: - OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for 'other' element type"); - break; - default: - OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for invalid element type"); - break; - } - return rtl::OUString(); -} -// ----------------------------------------------------------------------------- - -uno::Reference< sax::XAttributeList > ElementFormatter::getElementAttributes() const -{ - return m_xAttributes.get(); -} -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -} // namespace -} // namespace - diff --git a/configmgr/source/xml/elementformatter.hxx b/configmgr/source/xml/elementformatter.hxx deleted file mode 100644 index 0e7d92489c93..000000000000 --- a/configmgr/source/xml/elementformatter.hxx +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: elementformatter.hxx,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_ELEMENTFORMATTER_HXX -#define CONFIGMGR_XML_ELEMENTFORMATTER_HXX - -#include "elementinfo.hxx" -#include - -#include - -namespace comphelper { - class AttributeList; -} - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; - -// ----------------------------------------------------------------------------- - class ElementFormatter - { - public: - ElementFormatter(); - ~ElementFormatter(); - - /// reset the formatter for a new document - void reset(); - - /// resets the formatter for a new element type - void prepareElement(ElementInfo const& _aInfo); - - /// resets the formatter for a new element type - void prepareSimpleElement(ElementType::Enum _eType); - - /// sets the instantiated type of a set item, - void addInstanceType(rtl::OUString const & _aElementType, rtl::OUString const & _aElementTypeModule); - - /// retrieve element type and associated module name of a set, - void addPropertyValueType(uno::Type const& _aType); - - /// add a language for the current element - void addLanguage(rtl::OUString const & _sLanguage); - - /// adds a value attribute to the attribute list - void addIsNull(bool _bIsNull = true); - - /// adds a value attribute to the attribute list - void addSeparator(rtl::OUString const& _sSeparator); - - /// retrieve the tag to use for the current element - rtl::OUString getElementTag() const; - - /// retrieve the attributes to use for the current element - uno::Reference< sax::XAttributeList > getElementAttributes() const; - - /// retrieve the attributes to use for an element with associated component - private: - void addNamespaces(); - /// sets an attributes for a node - void addName(rtl::OUString const & _aName); - /// sets attributes for nodes from the flags - void addNodeFlags(sal_Int16 _eFlags); - /// sets attributes for nodes from the flags - void addOperation(Operation::Enum _eOp); - /// sets attributes for nodes from the flags - void maybeAddFlag(sal_Int16 _eFlags, sal_Int16 _eSelect, - rtl::OUString const & _anAttributeName, bool _bValue = true); - - /// sets attributes for nodes - void addAttribute(rtl::OUString const & _anAttributeName, rtl::OUString const & _aValue); - void addAttribute(rtl::OUString const & _anAttributeName, bool _bValue); - - private: - ElementType::Enum m_aElementType; - rtl::Reference< ::comphelper::AttributeList> m_xAttributes; - }; -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- -} // namespace configmgr - -#endif - diff --git a/configmgr/source/xml/elementinfo.hxx b/configmgr/source/xml/elementinfo.hxx deleted file mode 100644 index 6c22ca360c01..000000000000 --- a/configmgr/source/xml/elementinfo.hxx +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: elementinfo.hxx,v $ - * $Revision: 1.9 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -/* PLEASE DON'T DELETE ANY COMMENT LINES, ALSO IT'S UNNECESSARY. */ - -#ifndef CONFIGMGR_XML_ELEMENTINFO_HXX -#define CONFIGMGR_XML_ELEMENTINFO_HXX - -#include -#include - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace ElementType - { - enum Enum - { - unknown, - - schema, - layer, - - component, - templates, - - property, - node, - group, - set, - - import, - instance, - item_type, - value, - uses, - - other - }; - } -// ----------------------------------------------------------------------------- - namespace Operation - { - enum Enum - { - none, - - modify, - clear, - - replace, - fuse, - remove, - - unknown - }; - } -// ----------------------------------------------------------------------------- - struct ElementInfo - { - explicit - ElementInfo(ElementType::Enum _type = ElementType::unknown) - : name() - , type(_type) - , op(Operation::none) - , flags() - {} - - explicit - ElementInfo(rtl::OUString const & _name, ElementType::Enum _type = ElementType::unknown) - : name(_name) - , type(_type) - , op(Operation::none) - , flags() - {} - - - rtl::OUString name; - ElementType::Enum type; - Operation::Enum op; - sal_Int16 flags; - }; -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- -} // namespace configmgr - -#endif - diff --git a/configmgr/source/xml/elementparser.cxx b/configmgr/source/xml/elementparser.cxx deleted file mode 100644 index 663294a0b97c..000000000000 --- a/configmgr/source/xml/elementparser.cxx +++ /dev/null @@ -1,585 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: elementparser.cxx,v $ - * $Revision: 1.16 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "elementparser.hxx" -#include "xmlstrings.hxx" -#include "typeconverter.hxx" - -#include -#include - -#include - -// ----------------------------------------------------------------------------- - -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, rtl::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, rtl::OUString const& aAttributeName, /* OUT */ rtl::OUString& rAttributeValue) -{ - OSL_PRECOND( xAttribs.is(), "ERROR: NULL Attribute list"); - - rtl::OUString aValue = xAttribs->getValueByName(aAttributeName); - if( aValue.getLength()!=0) - { - rAttributeValue = aValue; - return true; - } - return false; -} -// ----------------------------------------------------------------------------- - -/// retrieve the (almost) complete information for an element -ElementInfo ElementParser::parseElementInfo(rtl::OUString const& _sTag, uno::Reference< sax::XAttributeList > const& _xAttribs) const -{ - ElementType::Enum aType = this->getNodeType(_sTag,_xAttribs); - - ElementInfo aInfo( this->getName(_sTag,_xAttribs,aType), aType ); - - aInfo.op = this->getOperation(_xAttribs,aType); - aInfo.flags = this->getNodeFlags(_xAttribs,aType); - - return aInfo; -} -// ----------------------------------------------------------------------------- - -ElementType::Enum ElementParser::getNodeType(rtl::OUString const& _sElementName, uno::Reference< sax::XAttributeList > const& _xAttribs) const -{ - { (void)_xAttribs; } - 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_LAYER)) - eResult = ElementType::layer; - - 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 if (_sElementName.equals(TAG_USES)) - eResult = ElementType::uses; - - // #109668# maintain support for old tag on load - else if (_sElementName.equals(DEPRECATED_TAG_LAYER)) - { - logger().warning("Layer starts with invalid root tag \"oor:node\". Use \"oor:component-data\" instead.", - "getNodeType()","configmgr::xml::ElementParser"); - eResult = ElementType::layer; - } - - else - eResult = ElementType::other; - - return eResult; -} -// ----------------------------------------------------------------------------- - -/// takes the node name from either an attribute or the element name -rtl::OUString ElementParser::getName(rtl::OUString const& _sElementName, uno::Reference< sax::XAttributeList > const& _xAttribs, ElementType::Enum _eType) const -{ - rtl::OUString aName; - rtl::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); - OSL_ENSURE(bPackage, "configmgr::xml::ElementParser: Found schema without package."); - break; - - case ElementType::layer: - bPackage = this->maybeGetAttribute(_xAttribs,ATTR_PACKAGE,aPackage); - - if (!bPackage) // for compatibility we still support 'oor:context' - { - bPackage = this->maybeGetAttribute(_xAttribs,ATTR_CONTEXT,aPackage); - - if (bPackage) - { - // TODO: log this - OSL_TRACE("configmgr::xml::ElementParser: Found obsolete layer attribute " - "oor:context=\"%s\" in component \"%s\".\n", - rtl::OUStringToOString(aPackage,RTL_TEXTENCODING_ASCII_US).getStr(), - rtl::OUStringToOString(aName,RTL_TEXTENCODING_ASCII_US).getStr()); - } - } - - OSL_ENSURE(bPackage, "configmgr::xml::ElementParser: Found layer without package."); - break; - - case ElementType::node: - 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::uses: - 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); - break; - - default: - if (!bNameFound) return _sElementName; - break; - } - - OSL_ENSURE(aName.getLength(),"Found empty name tag on element"); - - if (bPackage) - { - static const sal_Unicode chPackageSep = '.'; - - aName = aPackage.concat(rtl::OUString(&chPackageSep,1)).concat(aName); - } - else - { - OSL_ENSURE(!this->maybeGetAttribute(_xAttribs,ATTR_PACKAGE,aPackage), - "configmgr::xml::ElementParser: Found unexpected 'oor:package' on inner or unknown node." ); - } - - return aName; -} -// ----------------------------------------------------------------------------- - -Operation::Enum ElementParser::getOperation(uno::Reference< sax::XAttributeList > const& xAttribs,ElementType::Enum _eType) const -{ - rtl::OUString sOpName; - if ((_eType != ElementType::property) && (_eType !=ElementType::node)) - { - return Operation::none; - } - - 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_FUSE)) - return Operation::fuse; - - else if (sOpName.equals(OPERATION_REMOVE)) - return Operation::remove; -#if 0 - else if (sOpName.equals(OPERATION_CLEAR)) - return Operation::clear; -#endif - else - return Operation::unknown; -} -// ----------------------------------------------------------------------------- - - -/// retrieve the locale stored in the attribute list -bool ElementParser::getLanguage(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString& _rsLanguage) const -{ - return this->maybeGetAttribute(xAttribs, EXT_ATTR_LANGUAGE, _rsLanguage); -} -// ----------------------------------------------------------------------------- - -/// reads attributes for nodes from the attribute list -sal_Int16 ElementParser::getNodeFlags(uno::Reference< sax::XAttributeList > const& xAttribs,ElementType::Enum _eType) const -{ - namespace NodeAttribute = ::com::sun::star::configuration::backend::NodeAttribute; - namespace SchemaAttribute = ::com::sun::star::configuration::backend::SchemaAttribute; - - bool bValue; - - sal_Int16 aResult = 0; - - switch(_eType) - { - case ElementType::property : - 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_READONLY, bValue) && bValue) - aResult |= NodeAttribute::READONLY; - if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_FINALIZED, bValue) && bValue) - aResult |= NodeAttribute::FINALIZED; - break; - - case ElementType::node: - 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; - break; - - case ElementType::group: - case ElementType::set: - if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_EXTENSIBLE, bValue) && bValue) - aResult |= SchemaAttribute::EXTENSIBLE; - break; - - case ElementType::layer: - if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_READONLY, bValue) && bValue) - aResult |= NodeAttribute::READONLY; - if (this->maybeGetAttribute(xAttribs, ATTR_FLAG_FINALIZED, bValue) && bValue) - aResult |= NodeAttribute::FINALIZED; - break; - - default: - break; - - } - return aResult; -} -// ----------------------------------------------------------------------------- -static -void badValueType(Logger const & logger, sal_Char const * _pMsg, rtl::OUString const & _sType) -{ - rtl::OUStringBuffer sMessageBuf; - sMessageBuf.appendAscii( "Configuration XML parser: Bad value type attribute: " ); - if (_pMsg) sMessageBuf.appendAscii(_pMsg); - - const sal_Unicode kQuote = '"'; - sMessageBuf.append(kQuote).append(_sType).append(kQuote); - - rtl::OUString const sMessage = sMessageBuf.makeStringAndClear(); - logger.error(sMessage); - throw ElementParser::BadValueType(sMessage); -} -// ----------------------------------------------------------------------------- -static -inline -sal_Bool matchNsPrefix(rtl::OUString const & _sString, rtl::OUString const & _sPrefix) -{ - return _sString.match(_sPrefix) && - _sString.getStr()[_sPrefix.getLength()] == k_NS_SEPARATOR; -} -// ----------------------------------------------------------------------------- -static -inline -sal_Bool matchSuffix(rtl::OUString const & _sString, rtl::OUString const & _sSuffix) -{ - sal_Int32 nSuffixStart = _sString.getLength() - _sSuffix.getLength(); - if (nSuffixStart < 0) - return false; - - return _sString.match(_sSuffix,nSuffixStart); -} -// ----------------------------------------------------------------------------- -static -inline -rtl::OUString stripNsPrefix(rtl::OUString const & _sString, rtl::OUString const & _sPrefix) -{ - OSL_ASSERT( matchNsPrefix(_sString,_sPrefix) ); - - return _sString.copy(_sPrefix.getLength() + 1); -} -// ----------------------------------------------------------------------------- -static -inline -rtl::OUString stripSuffix(rtl::OUString const & _sString, rtl::OUString const & _sSuffix) -{ - OSL_ASSERT( matchSuffix(_sString,_sSuffix) ); - - sal_Int32 nSuffixStart = _sString.getLength() - _sSuffix.getLength(); - - return _sString.copy(0,nSuffixStart); -} -// ----------------------------------------------------------------------------- -static -inline -rtl::OUString stripTypeName(Logger const & logger, rtl::OUString const & _sString, rtl::OUString const & _sPrefix) -{ - if ( matchNsPrefix(_sString,_sPrefix)) - return stripNsPrefix(_sString, _sPrefix); - - badValueType(logger, "Missing expected namespace prefix on type name: ", _sString); - - return _sString; -} -// ----------------------------------------------------------------------------- -static -uno::Type xmlToScalarType(const rtl::OUString& _rType) -{ - uno::Type aRet; - - if (_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BOOLEAN)) - aRet = ::getBooleanCppuType(); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_SHORT)) - aRet = ::getCppuType(static_cast(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_INT)) - aRet = ::getCppuType(static_cast(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_LONG)) - aRet = ::getCppuType(static_cast(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_DOUBLE)) - aRet = ::getCppuType(static_cast< double const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_STRING)) - aRet = ::getCppuType(static_cast(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BINARY)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_ANY)) - aRet = ::getCppuType(static_cast(0)); - - else - OSL_ENSURE(false,"Cannot parse: Unknown value type"); - - return aRet; -} -// ----------------------------------------------------------------------------- -uno::Type xmlToListType(const rtl::OUString& _aElementType) -{ - uno::Type aRet; - - if (_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BOOLEAN)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_SHORT)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_INT)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_LONG)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_DOUBLE)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_STRING)) - aRet = ::getCppuType(static_cast const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BINARY)) - aRet = ::getCppuType(static_cast > const*>(0)); - - else - OSL_ENSURE(false,"Cannot parse: Unknown list value type"); - - return aRet; -} -// ----------------------------------------------------------------------------- -/// retrieve data type of a property, -uno::Type ElementParser::getPropertyValueType(uno::Reference< sax::XAttributeList > const& xAttribs) const -{ - rtl::OUString sTypeName; - if (!this->maybeGetAttribute(xAttribs, ATTR_VALUETYPE, sTypeName)) - return uno::Type(); // => VOID - - uno::Type aType; - - // valuetype names are either 'xs:' or 'oor:' or 'oor:-list' - if (matchSuffix(sTypeName,VALUETYPE_LIST_SUFFIX)) - { - rtl::OUString sBasicName = stripTypeName( mLogger, stripSuffix(sTypeName,VALUETYPE_LIST_SUFFIX), NS_PREFIX_OOR ); - - aType = xmlToListType(sBasicName); - } - else - { - rtl::OUString sPrefix = matchNsPrefix(sTypeName,NS_PREFIX_OOR) ? rtl::OUString( NS_PREFIX_OOR ) : rtl::OUString( NS_PREFIX_XS ); - - rtl::OUString sBasicName = stripTypeName( mLogger, sTypeName, sPrefix ); - - aType = xmlToScalarType(sBasicName); - } - - if (aType == uno::Type()) - badValueType(mLogger,"Unknown type name: ", sTypeName); - - return aType; -} -// ----------------------------------------------------------------------------- - -/// retrieve element type and associated module name of a set, -bool ElementParser::getSetElementType(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString& aElementType, rtl::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(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString& aElementType, rtl::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(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString& _rsComponent) const -{ - return this->maybeGetAttribute(xAttribs, ATTR_COMPONENT, _rsComponent); -} -// ----------------------------------------------------------------------------- - -/// reads attributes for values from the attribute list -bool ElementParser::isNull(uno::Reference< sax::XAttributeList > const& _xAttribs) const -{ - bool bNull; - return maybeGetAttribute(_xAttribs, EXT_ATTR_NULL, bNull) && bNull; -} -// ----------------------------------------------------------------------------- - -/// reads attributes for values from the attribute list -rtl::OUString ElementParser::getSeparator(uno::Reference< sax::XAttributeList > const& _xAttribs) const -{ - rtl::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(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString const& aAttributeName, bool& rAttributeValue) const -{ - rtl::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(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString const& aAttributeName, rtl::OUString& rAttributeValue) const -{ - return xAttribs.is() && impl_maybeGetAttribute(xAttribs, aAttributeName, rAttributeValue); -} - -// ----------------------------------------------------------------------------- -} // namespace -} // namespace - diff --git a/configmgr/source/xml/elementparser.hxx b/configmgr/source/xml/elementparser.hxx deleted file mode 100644 index 78d5797bc6bf..000000000000 --- a/configmgr/source/xml/elementparser.hxx +++ /dev/null @@ -1,125 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: elementparser.hxx,v $ - * $Revision: 1.7 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_ELEMENTPARSER_HXX -#define CONFIGMGR_XML_ELEMENTPARSER_HXX - -#include "elementinfo.hxx" -#include "logger.hxx" -#include - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; - -// ----------------------------------------------------------------------------- - class ElementParser - { - Logger mLogger; - public: - class BadValueType - { - rtl::OUString mMessage; - public: - BadValueType(rtl::OUString const & aMessage) : mMessage(aMessage) {} - - rtl::OUString message() const { return mMessage.getStr(); } - }; - public: - explicit - ElementParser(Logger const & xLogger) - : mLogger(xLogger) - {} - - Logger const & logger() const { return mLogger; } - - /// reset the parser for a new document - void reset() - {} - - /// retrieve the (almost) complete information for an element - ElementInfo parseElementInfo(rtl::OUString const& _sTag, uno::Reference< sax::XAttributeList > const& _xAttribs) const; - - /// retrieve the node name for an element - ElementType::Enum getNodeType(rtl::OUString const& _sTag, uno::Reference< sax::XAttributeList > const& xAttribs) const; - - /// retrieve the node name for an element - rtl::OUString getName(rtl::OUString const& _sTag, uno::Reference< sax::XAttributeList > const& xAttribs, ElementType::Enum eType = ElementType::unknown) const; - - /// query whether the node has an operation - Operation::Enum getOperation(uno::Reference< sax::XAttributeList > const& xAttribs, ElementType::Enum _eType) const; - - /// retrieve the language (if any) stored in the attribute list - bool getLanguage(uno::Reference< sax::XAttributeList > const& xAttribs, rtl::OUString & _rsLanguage) const; - - /// reads attributes for nodes from the attribute list - sal_Int16 getNodeFlags(uno::Reference< sax::XAttributeList > const& xAttribs, ElementType::Enum _eType) const; - - /// retrieve element type and associated module name of a set, - bool getSetElementType(uno::Reference< sax::XAttributeList > const& _xAttribs, rtl::OUString& _rsElementType, rtl::OUString& _rsElementTypeModule) const; - - /// retrieve the instance type and associated module name of a instance, - bool getInstanceType(uno::Reference< sax::XAttributeList > const& _xAttribs, rtl::OUString& _rsElementType, rtl::OUString& _rsElementTypeModule) const; - - /// retrieve the component for an import or uses element, - bool getImportComponent(uno::Reference< sax::XAttributeList > const& _xAttribs, rtl::OUString& _rsComponent) const; - - /// retrieve element type and associated module name of a set, - uno::Type getPropertyValueType(uno::Reference< sax::XAttributeList > const& _xAttribs) const; - // throw( BadValueType ) - - /// reads a value attribute from the attribute list - bool isNull(uno::Reference< sax::XAttributeList > const& _xAttribs) const; - - /// reads a value attribute from the attribute list - rtl::OUString getSeparator(uno::Reference< sax::XAttributeList > 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(uno::Reference< sax::XAttributeList > const& _xAttribs, rtl::OUString const& _aAttributeName, bool& _rbAttributeValue) const; - - /// checks for presence of an attribute and assigns its value if it exists - bool maybeGetAttribute(uno::Reference< sax::XAttributeList > const& _xAttribs, rtl::OUString const& _aAttributeName, rtl::OUString& _rsAttributeValue) const; - }; -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- -} // namespace configmgr - -#endif - diff --git a/configmgr/source/xml/layerparser.cxx b/configmgr/source/xml/layerparser.cxx deleted file mode 100644 index db87f4ffe3e4..000000000000 --- a/configmgr/source/xml/layerparser.cxx +++ /dev/null @@ -1,371 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: layerparser.cxx,v $ - * $Revision: 1.15 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "com/sun/star/configuration/backend/NodeAttribute.hpp" -#include "layerparser.hxx" - -// ----------------------------------------------------------------------------- -#include "wrapexception.hxx" - -#define WRAP_PARSE_EXCEPTIONS() \ - PASS_EXCEPTION(sax::SAXException) \ - PASS_EXCEPTION(uno::RuntimeException) \ - WRAP_CONFIGDATA_EXCEPTIONS( raiseParseException ) \ - WRAP_OTHER_EXCEPTIONS( raiseParseException ) - -#define WRAP_PARSE_EXCEPTIONS_MSG( msg ) \ - PASS_EXCEPTION(sax::SAXException) \ - PASS_EXCEPTION(uno::RuntimeException) \ - WRAP_CONFIGDATA_EXCEPTIONS1( raiseParseException, msg ) \ - WRAP_OTHER_EXCEPTIONS1( raiseParseException, msg ) - -// ----------------------------------------------------------------------------- - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - -LayerParser::LayerParser(uno::Reference< uno::XComponentContext > const & _xContext, uno::Reference< backenduno::XLayerHandler > const & _xHandler) -: BasicParser(_xContext) -, m_xHandler(_xHandler) -, m_bRemoved(false) -, m_bNewProp(false) -{ - if (!m_xHandler.is()) - { - rtl::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(); - - try - { - OSL_ENSURE(isEmptyNode(), "BasicParser does not mark new document as empty"); - - m_xHandler->startLayer(); - m_bRemoved = false; - m_bNewProp = false; - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Starting layer") -} -// ----------------------------------------------------------------------------- - -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(); - - try - { - m_xHandler->endLayer(); - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Ending layer") -} -// ----------------------------------------------------------------------------- - -void SAL_CALL LayerParser::startElement( const rtl::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); - - try - { - 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::layer: - 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 - Warning: ignoring unknown element tag\n"); - this->startSkipping( aName, xAttribs ); - return; - } - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Starting Element") -} -// ----------------------------------------------------------------------------- - -void SAL_CALL LayerParser::endElement( const rtl::OUString& aName ) - throw (sax::SAXException, uno::RuntimeException) -{ - if ( this->wasSkipping(aName) ) - return; - - try - { - 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"); - } - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Ending Element") -} -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -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,false); - break; - - case Operation::clear: - m_xHandler->overrideNode(aInfo.name,aInfo.flags,true); - break; - - case Operation::replace: - case Operation::fuse: - { - backenduno::TemplateIdentifier aTemplate; - sal_Int16 flags = aInfo.flags; - if (aInfo.op == Operation::fuse) { - flags |= - com::sun::star::configuration::backend::NodeAttribute::FUSE; - } - if (getDataParser().getInstanceType(xAttribs,aTemplate.Name,aTemplate.Component)) - m_xHandler->addOrReplaceNodeFromTemplate(aInfo.name,aTemplate,flags); - else - m_xHandler->addOrReplaceNode(aInfo.name,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: - m_xHandler->overrideProperty(aInfo.name,aInfo.flags,getActivePropertyType(),false); - OSL_ASSERT(!m_bNewProp); - break; - - case Operation::clear: - m_xHandler->overrideProperty(aInfo.name,aInfo.flags,getActivePropertyType(),true); - OSL_ASSERT(!m_bNewProp); - break; - - case Operation::replace: - // defer to later - m_bNewProp = true; - break; - - case Operation::fuse: - this->raiseParseException("Layer parser: Invalid Data: operation 'fuse' is not permitted for properties"); - - 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"); - } - OSL_POSTCOND(this->isInUnhandledProperty(),"Error: Property not reckognized as unhandled"); -} -// ----------------------------------------------------------------------------- - -void LayerParser::addOrReplaceCurrentProperty(const uno::Any& aValue) -{ - const ElementInfo& currentInfo = getActiveNodeInfo() ; - - OSL_ASSERT(currentInfo.op == Operation::replace) ; - - if (aValue.hasValue()) - { - m_xHandler->addPropertyWithValue(currentInfo.name, - currentInfo.flags, aValue) ; - } - else - { - m_xHandler->addProperty(currentInfo.name, currentInfo.flags, - getActivePropertyType()) ; - } -} -// ----------------------------------------------------------------------------- - -void LayerParser::endProperty() -{ - OSL_ASSERT(!this->isInRemoved()); - - if (m_bNewProp) - { - OSL_ASSERT(getActiveNodeInfo().op == Operation::replace); - if (this->isInUnhandledProperty()) - { - // No value tag is treated as NULL - addOrReplaceCurrentProperty( uno::Any() ) ; - } - m_bNewProp = false; - } - else - { - OSL_ASSERT(getActiveNodeInfo().op != Operation::replace); - m_xHandler->endProperty(); - } - - BasicParser::endProperty(); -} -// ----------------------------------------------------------------------------- - -void LayerParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) -{ - this->checkNotRemoved(); - - BasicParser::startValueData(xAttribs); -} -// ----------------------------------------------------------------------------- - -void LayerParser::endValueData() -{ - uno::Any aValue = this->getCurrentValue(); - - if (m_bNewProp) - { - if (this->isValueDataLocalized()) - getLogger().warning("Language attribute ignored for value of added property.", - "endValueData()","configuration::xml::SchemaParser"); - - addOrReplaceCurrentProperty(aValue) ; - } - else if (this->isValueDataLocalized()) - { - rtl::OUString aLocale = this->getValueDataLocale(); - - m_xHandler->setPropertyValueForLocale(aValue,aLocale); - } - else - { - m_xHandler->setPropertyValue(aValue); - } - - BasicParser::endValueData(); - - OSL_POSTCOND(!this->isInUnhandledProperty(),"Error: Property not reckognized as unhandled"); -} -// ----------------------------------------------------------------------------- - -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 deleted file mode 100644 index 3916c3e869db..000000000000 --- a/configmgr/source/xml/layerparser.hxx +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: layerparser.hxx,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_LAYERPARSER_HXX -#define CONFIGMGR_XML_LAYERPARSER_HXX - -#include "basicparser.hxx" - -#include - -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 = ::com::sun::star::configuration::backend; - -// ----------------------------------------------------------------------------- - - - class LayerParser : public BasicParser - { - public: - LayerParser(uno::Reference< uno::XComponentContext > const & _xContext, uno::Reference< backenduno::XLayerHandler > 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 rtl::OUString& aName, const uno::Reference< sax::XAttributeList >& xAttribs ) - throw (sax::SAXException, uno::RuntimeException); - - virtual void SAL_CALL - endElement( const rtl::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(); - - /** - Forces the addition or replacement of a property. - As it is possible to "replace" an existing property, - even though this amounts to a modify, this method - first tries to add a new property and failing that, - to replace the value of an existing one. - - @param aValue value to be set for the property - */ - void addOrReplaceCurrentProperty(const uno::Any& aValue) ; - - bool isInRemoved() const { return m_bRemoved; } - void checkNotRemoved(); - private: - uno::Reference< backenduno::XLayerHandler > m_xHandler; - bool m_bRemoved; - bool m_bNewProp; - }; -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/layerwriter.cxx b/configmgr/source/xml/layerwriter.cxx deleted file mode 100644 index 409be06660d0..000000000000 --- a/configmgr/source/xml/layerwriter.cxx +++ /dev/null @@ -1,544 +0,0 @@ -/************************************************************************* -* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: layerwriter.cxx,v $ - * $Revision: 1.15 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * -************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "layerwriter.hxx" - -#ifndef CONFIGMGR_API_FACTORY_HXX_ -#include "confapifactory.hxx" -#endif -#include "valueformatter.hxx" -#include -#include -#include -#include -// ----------------------------------------------------------------------------- - -namespace configmgr -{ - // ----------------------------------------------------------------------------- - namespace xml - { - // ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace io = ::com::sun::star::io; - namespace sax = ::com::sun::star::xml::sax; - // ----------------------------------------------------------------------------- - - uno::Reference< uno::XInterface > SAL_CALL instantiateLayerWriter - ( uno::Reference< uno::XComponentContext > const& xContext ) - { - return * new LayerWriter(xContext); - } - // ----------------------------------------------------------------------------- - - namespace - { - static inline - uno::Reference< script::XTypeConverter > createTCV(uno::Reference< lang::XMultiServiceFactory > const & _xSvcFactory) - { - OSL_ENSURE(_xSvcFactory.is(),"Cannot create Write Formatter without a ServiceManager"); - - static const rtl::OUString k_sTCVService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")); - - return uno::Reference< script::XTypeConverter >::query(_xSvcFactory->createInstance(k_sTCVService)); - } - // ----------------------------------------------------------------------------- - static - void translateSAXException( sax::SAXException & aSAXException, - backenduno::XLayerHandler * context) - { - rtl::OUString sMessage = aSAXException.Message; - - uno::Any const & aWrappedException = aSAXException.WrappedException; - if (aWrappedException.hasValue()) - { - if (aWrappedException.getValueTypeClass() != uno::TypeClass_EXCEPTION) - OSL_ENSURE(false, "ERROR: WrappedException is not an exception"); - - else if (sMessage.getLength() == 0) - sMessage = static_cast(aWrappedException.getValue())->Message; - - // assume that a SAXException with WrappedException indicates a storage access error - throw backenduno::BackendAccessException(sMessage,context,aWrappedException); - } - else - { - // assume that a SAXException without WrappedException indicates non-well-formed data - throw backenduno::MalformedDataException(sMessage,context,uno::makeAny(aSAXException)); - } - } - // ----------------------------------------------------------------------------- - static inline uno::Type getIOExceptionType() - { - io::IOException const * const ioexception = 0; - return ::getCppuType(ioexception); - } - static inline uno::Type getNotConnectedExceptionType() - { - io::NotConnectedException const * const ncexception = 0; - return ::getCppuType(ncexception); - } - static - void translateIOException(uno::Any const & anIOException, - backenduno::XLayerHandler * context) - { - OSL_ASSERT(anIOException.isExtractableTo(getIOExceptionType())); - io::IOException const * pException = static_cast(anIOException.getValue()); - rtl::OUString sMessage = pException->Message; - - if (anIOException.isExtractableTo(getNotConnectedExceptionType())) - { - throw backenduno::ConnectionLostException(sMessage,context,anIOException); - } - else - { - throw backenduno::BackendAccessException(sMessage,context,anIOException); - } - } - // ----------------------------------------------------------------------------- - } - // ----------------------------------------------------------------------------- - - LayerWriter::LayerWriter(uno::Reference< uno::XComponentContext > const & _xContext) - : WriterService< ::com::sun::star::configuration::backend::XLayerHandler >(_xContext) - , m_xTCV( createTCV( WriterService< ::com::sun::star::configuration::backend::XLayerHandler >::getServiceFactory() ) ) - , m_bInProperty(false) - , m_bStartedDocument(false) - { - } - // ----------------------------------------------------------------------------- - - LayerWriter::~LayerWriter() - { - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::startLayer( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - m_aFormatter.reset(); - m_bInProperty = false; - m_bStartedDocument = false; - - checkInElement(false); - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::endLayer( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(false); - try - { - if (!m_bStartedDocument) - { - uno::Reference< io::XOutputStream > aStream = this->getOutputStream( ); - aStream->closeOutput(); - } - else - { - getWriteHandler()->endDocument(); - m_aFormatter.reset(); - m_bStartedDocument = false; - } - } - catch (sax::SAXException & xe) { translateSAXException(xe,this); } - catch (io::NotConnectedException & ioe) { translateIOException(uno::makeAny(ioe),this); } - catch (io::BufferSizeExceededException & ioe) { translateIOException(uno::makeAny(ioe),this); } - catch (io::IOException & ioe) { translateIOException(uno::makeAny(ioe),this); } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::overrideNode( const rtl::OUString& aName, sal_Int16 aAttributes, sal_Bool bClear ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - try - { - if (!m_bStartedDocument) - { - getWriteHandler()->startDocument(); - m_bStartedDocument = true; - } - ElementInfo aInfo(aName, this->isInElement() ? ElementType::node : ElementType::layer); - aInfo.flags = aAttributes; - aInfo.op = bClear ? Operation::clear : Operation::modify; - - m_aFormatter.prepareElement(aInfo); - - this->startNode(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void LayerWriter::prepareAddOrReplaceElement( - rtl::OUString const & name, sal_Int16 attributes) - { - ElementInfo info(name, ElementType::node); - info.flags = attributes & - ~com::sun::star::configuration::backend::NodeAttribute::FUSE; - info.op = - (attributes & - com::sun::star::configuration::backend::NodeAttribute::FUSE) - == 0 - ? Operation::replace : Operation::fuse; - m_aFormatter.prepareElement(info); - } - - void SAL_CALL LayerWriter::addOrReplaceNode( const rtl::OUString& aName, sal_Int16 aAttributes ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - prepareAddOrReplaceElement(aName, aAttributes); - - this->startNode(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::addOrReplaceNodeFromTemplate( const rtl::OUString& aName, const backenduno::TemplateIdentifier& aTemplate, sal_Int16 aAttributes ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - prepareAddOrReplaceElement(aName, aAttributes); - m_aFormatter.addInstanceType(aTemplate.Name,aTemplate.Component); - - this->startNode(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::endNode( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - try - { - this->endElement(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::dropNode( const rtl::OUString& aName ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - ElementInfo aInfo(aName, ElementType::node); - aInfo.flags = 0; - aInfo.op = Operation::remove; - - m_aFormatter.prepareElement(aInfo); - - this->startNode(); - this->endElement(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::addProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - ElementInfo aInfo(aName, ElementType::property); - aInfo.flags = aAttributes; - aInfo.op = Operation::replace; - - m_aFormatter.prepareElement(aInfo); - - this->startProp(aType, true); - this->writeValue(uno::Any()); - this->endElement(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::addPropertyWithValue( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - ElementInfo aInfo(aName, ElementType::property); - aInfo.flags = aAttributes; - aInfo.op = Operation::replace; - - m_aFormatter.prepareElement(aInfo); - - this->startProp(aValue.getValueType(), true); - this->writeValue(aValue); - this->endElement(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::overrideProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType, sal_Bool bClear ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - checkInElement(true); - - try - { - ElementInfo aInfo(aName, ElementType::property); - aInfo.flags = aAttributes; - aInfo.op = bClear ? Operation::modify : Operation::modify; - - m_aFormatter.prepareElement(aInfo); - - this->startProp(aType, aType.getTypeClass() != uno::TypeClass_VOID); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::endProperty( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - try - { - checkInElement(true,true); - this->endElement(); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::setPropertyValue( const uno::Any& aValue ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - try - { - checkInElement(true,true); - this->writeValue(aValue); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void SAL_CALL LayerWriter::setPropertyValueForLocale( const uno::Any& aValue, const rtl::OUString& aLocale ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException) - { - try - { - checkInElement(true,true); - this->writeValue(aValue,aLocale); - } - catch (sax::SAXException & xe) - { - translateSAXException(xe,this); - } - } - // ----------------------------------------------------------------------------- - - void LayerWriter::raiseMalformedDataException(sal_Char const * pMsg) - { - OSL_ASSERT(pMsg); - rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg); - - throw backenduno::MalformedDataException( sMsg, *this, uno::Any() ); - } - // ----------------------------------------------------------------------------- - - void LayerWriter::raiseIllegalTypeException(sal_Char const * pMsg) - { - OSL_ASSERT(pMsg); - rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg); - - com::sun::star::beans::IllegalTypeException e( sMsg, *this ); - throw backenduno::MalformedDataException( sMsg, *this, uno::makeAny(e) ); - } - // ----------------------------------------------------------------------------- - - bool LayerWriter::isInElement() const - { - return !m_aTagStack.empty(); - } - // ----------------------------------------------------------------------------- - - void LayerWriter::checkInElement(bool bInElement, bool bInProperty) - { - if (bInElement != this->isInElement()) - { - sal_Char const * pMsg = bInElement ? - "LayerWriter: Illegal Data: Operation requires a started node" : - "LayerWriter: Illegal Data: There is a started node already" ; - raiseMalformedDataException(pMsg); - } - - if (bInProperty != m_bInProperty) - { - sal_Char const * pMsg = bInProperty ? - "LayerWriter: Illegal Data: Operation requires a started property" : - "LayerWriter: Illegal Data: There is a started property already" ; - raiseMalformedDataException(pMsg); - } - } - // ----------------------------------------------------------------------------- - - void LayerWriter::startNode() - { - rtl::OUString sTag = m_aFormatter.getElementTag(); - getWriteHandler()->startElement(sTag,m_aFormatter.getElementAttributes()); - getWriteHandler()->ignorableWhitespace(rtl::OUString()); - m_aTagStack.push(sTag); - } - // ----------------------------------------------------------------------------- - - void LayerWriter::startProp(uno::Type const & _aType, bool bNeedType) - { - if (bNeedType && _aType == uno::Type()) - raiseIllegalTypeException("LayerWriter: Illegal Data: Cannot add VOID property"); - - m_aFormatter.addPropertyValueType(_aType); - - startNode(); - - m_aPropertyType = _aType; - m_bInProperty = true; - } - // ----------------------------------------------------------------------------- - - void LayerWriter::endElement() - { - OSL_ASSERT(!m_aTagStack.empty()); // checks done elsewhere - - getWriteHandler()->endElement(m_aTagStack.top()); - getWriteHandler()->ignorableWhitespace(rtl::OUString()); - - m_aTagStack.pop(); - m_bInProperty = false; - } - // ----------------------------------------------------------------------------- - - void LayerWriter::writeValue(uno::Any const & _aValue) - { - m_aFormatter.prepareSimpleElement( ElementType::value ); - outputValue(_aValue); - } - // ----------------------------------------------------------------------------- - - void LayerWriter::writeValue(uno::Any const & _aValue, rtl::OUString const & _aLocale) - { - m_aFormatter.prepareSimpleElement( ElementType::value ); - m_aFormatter.addLanguage(_aLocale); - outputValue(_aValue); - } - // ----------------------------------------------------------------------------- - - void LayerWriter::outputValue(uno::Any const & _aValue) - { - ValueFormatter aValueFormatter(_aValue); - - aValueFormatter.addValueAttributes(m_aFormatter); - - rtl::OUString sTag = m_aFormatter.getElementTag(); - rtl::OUString sContent = aValueFormatter.getContent( this->m_xTCV ); - - uno::Reference< sax::XDocumentHandler > xOut = getWriteHandler(); - xOut->startElement(sTag, m_aFormatter.getElementAttributes()); - - if (sContent.getLength()) xOut->characters(sContent); - - xOut->endElement(sTag); - xOut->ignorableWhitespace(rtl::OUString()); - } - // ----------------------------------------------------------------------------- - - // ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- - } // namespace - - // ----------------------------------------------------------------------------- -} // namespace - diff --git a/configmgr/source/xml/layerwriter.hxx b/configmgr/source/xml/layerwriter.hxx deleted file mode 100644 index 3917d3e60af1..000000000000 --- a/configmgr/source/xml/layerwriter.hxx +++ /dev/null @@ -1,169 +0,0 @@ -/************************************************************************* -* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: layerwriter.hxx,v $ - * $Revision: 1.13 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * -************************************************************************/ - -#ifndef CONFIGMGR_XML_LAYERWRITER_HXX -#define CONFIGMGR_XML_LAYERWRITER_HXX - -#include "writersvc.hxx" -#include "elementformatter.hxx" -#include "stack.hxx" -#include - -namespace com { namespace sun { namespace star { namespace script { - class XTypeConverter; -} } } } - -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 = ::com::sun::star::configuration::backend; - - // ----------------------------------------------------------------------------- - - - class LayerWriter : public WriterService< ::com::sun::star::configuration::backend::XLayerHandler > - { - public: - explicit - LayerWriter(uno::Reference< uno::XComponentContext > const & _xContext); - virtual ~LayerWriter(); - - // XLayerHandler - public: - virtual void SAL_CALL - startLayer( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - endLayer( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - overrideNode( const rtl::OUString& aName, sal_Int16 aAttributes, sal_Bool bClear ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - addOrReplaceNode( const rtl::OUString& aName, sal_Int16 aAttributes ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - addOrReplaceNodeFromTemplate( const rtl::OUString& aName, const backenduno::TemplateIdentifier& aTemplate, sal_Int16 aAttributes ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - endNode( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - dropNode( const rtl::OUString& aName ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - overrideProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType, sal_Bool bClear ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - addProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - addPropertyWithValue( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - endProperty( ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - setPropertyValue( const uno::Any& aValue ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - virtual void SAL_CALL - setPropertyValueForLocale( const uno::Any& aValue, const rtl::OUString& aLocale ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - uno::RuntimeException); - - private: - bool isInElement() const; - void checkInElement(bool bInElement, bool bInProperty = false); - - void startNode(); - void startProp(uno::Type const & _aType, bool bNeedType); - - void endElement(); - - void writeValue(uno::Any const & _aValue); - void writeValue(uno::Any const & _aValue, rtl::OUString const & _aLocale); - - void outputValue(uno::Any const & _aValue); - - void raiseMalformedDataException(sal_Char const * pMsg); - void raiseIllegalTypeException(sal_Char const * pMsg); - - void prepareAddOrReplaceElement( - rtl::OUString const & name, sal_Int16 attributes); - - private: - uno::Reference< com::sun::star::script::XTypeConverter > m_xTCV; - Stack< rtl::OUString > m_aTagStack; - ElementFormatter m_aFormatter; - uno::Type m_aPropertyType; - bool m_bInProperty; - bool m_bStartedDocument; - }; - // ----------------------------------------------------------------------------- - } // namespace xml - // ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/makefile.mk b/configmgr/source/xml/makefile.mk deleted file mode 100644 index 61d3ac65572f..000000000000 --- a/configmgr/source/xml/makefile.mk +++ /dev/null @@ -1,70 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2008 by Sun Microsystems, Inc. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# $RCSfile: makefile.mk,v $ -# -# $Revision: 1.27 $ -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. - -PRJINC=$(PRJ)$/source -PRJNAME=configmgr -TARGET=xml -ENABLE_EXCEPTIONS=TRUE - -# --- Settings --- - -.INCLUDE : settings.mk -.INCLUDE : $(PRJ)$/makefile.pmk - -.IF "$(OS)"=="SOLARIS" && "$(COM)"!="GCC" -CFLAGSCXX+=-instances=static -.ENDIF - -# --- Files --- - - -SLOFILES=\ - $(SLO)$/matchlocale.obj \ - $(SLO)$/typeconverter.obj \ - $(SLO)$/simpletypehelper.obj \ - $(SLO)$/valueconverter.obj \ - $(SLO)$/elementparser.obj \ - $(SLO)$/elementformatter.obj \ - $(SLO)$/basicparser.obj \ - $(SLO)$/layerparser.obj \ - $(SLO)$/schemaparser.obj \ - $(SLO)$/parsersvc.obj \ - $(SLO)$/writersvc.obj \ - $(SLO)$/layerwriter.obj \ - $(SLO)$/valueformatter.obj \ - $(SLO)$/xmlstrings.obj \ - -# --- Targets --- - -.INCLUDE : target.mk - diff --git a/configmgr/source/xml/matchlocale.cxx b/configmgr/source/xml/matchlocale.cxx deleted file mode 100644 index b0cf48092bb6..000000000000 --- a/configmgr/source/xml/matchlocale.cxx +++ /dev/null @@ -1,387 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: matchlocale.cxx,v $ - * $Revision: 1.12 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include "matchlocale.hxx" - -#include - -#include -#include - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace localehelper - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - -#define ARRAYSIZE( arr ) (sizeof(arr) / sizeof 0[arr] ) -// ----------------------------------------------------------------------------- - struct StaticLocale - { - char const * aLanguage; - char const * aCountry; - }; - - char const * const c_sAnyLanguage = "*"; // exported ! - char const * const c_sDefLanguage = "x-default"; // exported ! - - char const * const c_sNoCountry = ""; - - char const * const c_sLanguageEnglish = "en"; - char const * const c_sCountryUS = "US"; - - StaticLocale const c_aFallbackLocales[] = - { - { c_sLanguageEnglish, c_sCountryUS }, // english [cannot make 'en' better than 'en-US' :-(] - { c_sAnyLanguage, c_sNoCountry } // just take the first you find - }; - std::vector< com::sun::star::lang::Locale >::size_type const c_nFallbackLocales = ARRAYSIZE(c_aFallbackLocales); - -// ----------------------------------------------------------------------------- - bool isAnyLanguage(rtl::OUString const & _sLanguage) - { - return !!_sLanguage.equalsAscii(c_sAnyLanguage); - } - -// ----------------------------------------------------------------------------- - bool isDefaultLanguage(rtl::OUString const & _sLanguage) - { - return !!_sLanguage.equalsAscii(c_sDefLanguage); - } - -// ----------------------------------------------------------------------------- - rtl::OUString getAnyLanguage() - { - return rtl::OUString::createFromAscii( c_sAnyLanguage ); - } - -// ----------------------------------------------------------------------------- - rtl::OUString getDefaultLanguage() - { - return rtl::OUString::createFromAscii( c_sDefLanguage ); - } - -// ----------------------------------------------------------------------------- - com::sun::star::lang::Locale getAnyLocale() - { - return com::sun::star::lang::Locale( getAnyLanguage(), rtl::OUString(), rtl::OUString() ); - } - -// ----------------------------------------------------------------------------- - com::sun::star::lang::Locale getDefaultLocale() - { - return com::sun::star::lang::Locale( getDefaultLanguage(), rtl::OUString(), rtl::OUString() ); - } - -// ----------------------------------------------------------------------------- - static inline sal_Int32 countrySeparatorPos(rtl::OUString const& aLocaleName_) - { - sal_Int32 pos = aLocaleName_.indexOf('-'); - if (pos == 1) // allow for x-LL or i-LL - pos = aLocaleName_.indexOf('-',pos+1); - - if (pos < 0) - pos = aLocaleName_.indexOf('_'); - - return pos; - } - // ------------------------------------------------------------------------- - static inline sal_Int32 countryLength(rtl::OUString const& aLocaleName_, sal_Int32 nCountryPos) - { - sal_Int32 pos1 = aLocaleName_.indexOf('.',nCountryPos); - sal_Int32 pos2 = aLocaleName_.indexOf('_',nCountryPos); - - if (pos1 < 0) pos1 = aLocaleName_.getLength(); - - if (pos2 < 0 || pos1 < pos2) - return pos1 - nCountryPos; - - else - return pos2 - nCountryPos; - } - // ------------------------------------------------------------------------- - static inline void splitLocaleString(rtl::OUString const& aLocaleName_, rtl::OUString& rLanguage_, rtl::OUString& rCountry_) - { - sal_Int32 nCountryPos = countrySeparatorPos(aLocaleName_); - if (nCountryPos >= 0) - { - rLanguage_ = aLocaleName_.copy(0,nCountryPos).toAsciiLowerCase(); - - ++nCountryPos; // advance past separator - sal_Int32 nCountryLength = countryLength(aLocaleName_, nCountryPos); - - rCountry_ = aLocaleName_.copy(nCountryPos,nCountryLength).toAsciiUpperCase(); - } - else - { - rLanguage_ = aLocaleName_.toAsciiLowerCase(); - rCountry_ = rtl::OUString(); - } - } -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// conversion helpers -com::sun::star::lang::Locale makeLocale(rtl::OUString const& sLocaleName_) -{ - com::sun::star::lang::Locale aResult; - splitLocaleString(sLocaleName_, aResult.Language, aResult.Country); - return aResult; -} -rtl::OUString makeIsoLocale(com::sun::star::lang::Locale const& aUnoLocale_) -{ - rtl::OUStringBuffer aResult(aUnoLocale_.Language.toAsciiLowerCase()); - if (aUnoLocale_.Country.getLength()) - { - aResult.append( sal_Unicode('-') ).append(aUnoLocale_.Country.toAsciiUpperCase()); - } - return aResult.makeStringAndClear(); -} -static -com::sun::star::lang::Locale makeLocale(StaticLocale const& aConstLocale_) -{ - com::sun::star::lang::Locale aResult; - aResult.Language = rtl::OUString::createFromAscii(aConstLocale_.aLanguage); - aResult.Country = rtl::OUString::createFromAscii(aConstLocale_.aCountry); - return aResult; -} -// ----------------------------------------------------------------------------- -template -inline -void addLocaleSeq_impl(T const* first, T const* last, std::vector< com::sun::star::lang::Locale >& rSeq) -{ - com::sun::star::lang::Locale (* const xlate)(T const&) = &makeLocale; - - std::transform(first, last, std::back_inserter(rSeq), xlate); -} -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -template -inline -std::vector< com::sun::star::lang::Locale > makeLocaleSeq_impl(uno::Sequence< T > const& aLocales_) -{ - sal_Int32 const nLocaleCount = aLocales_.getLength(); - - T const* pLocaleBegin = aLocales_.getConstArray(); - - std::vector< com::sun::star::lang::Locale > aResult; - aResult.reserve( nLocaleCount + c_nFallbackLocales ); // make room for fallback stuff as well - - addLocaleSeq_impl(pLocaleBegin, pLocaleBegin + nLocaleCount, aResult); - - return aResult; -} -// ----------------------------------------------------------------------------- - -void addFallbackLocales(std::vector< com::sun::star::lang::Locale >& aTargetList_) -{ - addLocaleSeq_impl(c_aFallbackLocales, c_aFallbackLocales + c_nFallbackLocales, aTargetList_); -} -// ----------------------------------------------------------------------------- - -std::vector< com::sun::star::lang::Locale > makeLocaleSequence(uno::Sequence const& sLocaleNames_) -{ - return makeLocaleSeq_impl(sLocaleNames_); -} -// ----------------------------------------------------------------------------- - -uno::Sequence makeIsoSequence(std::vector< com::sun::star::lang::Locale > const& aLocales_) -{ - std::vector< com::sun::star::lang::Locale >::size_type const nLocaleCount = aLocales_.size(); - sal_Int32 const nSeqSize = sal_Int32(nLocaleCount); - OSL_ASSERT( nSeqSize >= 0 && sal_uInt32(nSeqSize) == nLocaleCount ); - - uno::Sequence aResult(nSeqSize); - std::transform(aLocales_.begin(), aLocales_.end(), aResult.getArray(), &makeIsoLocale); - - return aResult; -} -// ----------------------------------------------------------------------------- -bool designatesAllLocales(com::sun::star::lang::Locale const& aLocale_) -{ - return aLocale_.Language.equalsAscii(c_sAnyLanguage); -} -bool designatesAllLocales(std::vector< com::sun::star::lang::Locale > const& aLocales_) -{ - return aLocales_.size() <= 1 && - (aLocales_.size() == 0 || designatesAllLocales(aLocales_)); -} -// ----------------------------------------------------------------------------- - -MatchQuality match(com::sun::star::lang::Locale const& aLocale_, com::sun::star::lang::Locale const& aTarget_) -{ - // check language - if (!aLocale_.Language.equals(aTarget_.Language)) - { - // can we accept any language - if (aTarget_.Language.equalsAscii(c_sAnyLanguage)) - return MATCH_LANGUAGE; - - return MISMATCH; - } - - // check for exact match - else if (aLocale_.Country.equals(aTarget_.Country)) - return MATCH_LOCALE; - - // check for plain language - else if (aLocale_.Country.getLength() == 0) - return MATCH_LANGUAGE_PLAIN; - - // so we are left with the wrong country - else - return MATCH_LANGUAGE; -} - -// ----------------------------------------------------------------------------- - -/// check the given position and quality, if they are an improvement -bool MatchResult::improve(std::vector< com::sun::star::lang::Locale >::size_type nPos_, MatchQuality eQuality_) -{ - // is this a match at all ? - if (eQuality_ == MISMATCH) - return false; - - // is the position worse ? - if (nPos_ > m_nPos ) - return false; - - // is this just a non-positive quality change ? - if (nPos_ == m_nPos && eQuality_ <= m_eQuality) - return false; - - // Improvement found - m_nPos = nPos_; - m_eQuality = eQuality_; - - return true; -} - -// ----------------------------------------------------------------------------- - -bool isMatch(com::sun::star::lang::Locale const& aLocale_, std::vector< com::sun::star::lang::Locale > const& aTarget_, MatchQuality eRequiredQuality_) -{ - std::vector< com::sun::star::lang::Locale >::size_type const nEnd = aTarget_.size(); - - for (std::vector< com::sun::star::lang::Locale >::size_type nPos = 0; nPos < nEnd; ++nPos) - { - MatchQuality eQuality = match(aLocale_, aTarget_[nPos]); - if (eQuality >= eRequiredQuality_) - { - return true; - } - } - return false; -} -// ----------------------------------------------------------------------------- - -static -inline -std::vector< com::sun::star::lang::Locale >::size_type getSearchLimitPosition(MatchResult const& aPrevMatch_,std::vector< com::sun::star::lang::Locale > const& aTarget_) -{ - std::vector< com::sun::star::lang::Locale >::size_type nSize = aTarget_.size(); - - if (aPrevMatch_.isMatch()) - { - std::vector< com::sun::star::lang::Locale >::size_type nMatchPos = aPrevMatch_.position(); - - OSL_ENSURE(nMatchPos < nSize,"localehelper::getSearchLimitPosition: ERROR - previous position is out-of-bounds"); - - if (nMatchPos < nSize) - { - return nMatchPos + 1; - } - } - return nSize; -} -// ----------------------------------------------------------------------------- - -bool improveMatch(MatchResult& rMatch_, com::sun::star::lang::Locale const& aLocale_, std::vector< com::sun::star::lang::Locale > const& aTarget_) -{ - std::vector< com::sun::star::lang::Locale >::size_type const nEnd = getSearchLimitPosition(rMatch_,aTarget_); - - for (std::vector< com::sun::star::lang::Locale >::size_type nPos = 0; nPos < nEnd; ++nPos) - { - if (rMatch_.improve(nPos, match(aLocale_, aTarget_[nPos]))) - { - return true; - } - } - return false; -} -// ----------------------------------------------------------------------------- - - -// ----------------------------------------------------------------------------- -// class FindBestLocale -// ----------------------------------------------------------------------------- - -inline -void FindBestLocale::implSetTarget(std::vector< com::sun::star::lang::Locale > const& aTarget_) -{ - m_aTarget = aTarget_; - addFallbackLocales(m_aTarget); -} -// ----------------------------------------------------------------------------- - -FindBestLocale::FindBestLocale(com::sun::star::lang::Locale const& aTarget_) -{ - std::vector< com::sun::star::lang::Locale > aSeq(1,aTarget_); - implSetTarget( aSeq ); -} -// ----------------------------------------------------------------------------- - -bool FindBestLocale::accept(com::sun::star::lang::Locale const& aLocale_) -{ - return improveMatch(m_aResult, aLocale_, m_aTarget); -} -// ----------------------------------------------------------------------------- - -void FindBestLocale::reset(bool bNeedLocale_) -{ - if (bNeedLocale_) - m_aResult.reset(); - - else // mark as best match already (no improvement possible) - m_aResult = m_aResult.best(); -} -// ----------------------------------------------------------------------------- - - } // namespace locale helper -// ----------------------------------------------------------------------------- - -} // namespace - - diff --git a/configmgr/source/xml/parsersvc.cxx b/configmgr/source/xml/parsersvc.cxx deleted file mode 100644 index 8f835b1725e2..000000000000 --- a/configmgr/source/xml/parsersvc.cxx +++ /dev/null @@ -1,385 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: parsersvc.cxx,v $ - * $Revision: 1.11 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "parsersvc.hxx" - -#ifndef CONFIGMGR_API_FACTORY_HXX_ -#include "confapifactory.hxx" -#endif -#include "schemaparser.hxx" -#include "layerparser.hxx" -#include -#include -#include -#include -#include -#include -#include -#include -// ----------------------------------------------------------------------------- - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - namespace io = ::com::sun::star::io; - namespace sax = ::com::sun::star::xml::sax; - namespace backenduno = ::com::sun::star::configuration::backend; -// ----------------------------------------------------------------------------- - -template -struct ParserServiceTraits; -// ----------------------------------------------------------------------------- -static inline void clear(rtl::OUString & _rs) { _rs = rtl::OUString(); } - -// ----------------------------------------------------------------------------- -template -ParserService::ParserService(uno::Reference< uno::XComponentContext > const & _xContext) -: m_xContext(_xContext) -, m_aInputSource() -{ - if (!m_xContext.is()) - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration Parser: NULL Context")); - throw uno::RuntimeException(sMessage,NULL); - } -} -// ----------------------------------------------------------------------------- - -// XInitialization -template -void SAL_CALL - ParserService::initialize( const uno::Sequence< uno::Any >& aArguments ) - throw (uno::Exception, uno::RuntimeException) -{ - switch(aArguments.getLength()) - { - case 0: - break; - - case 1: - if (aArguments[0] >>= m_aInputSource) - break; - - if (aArguments[0] >>= m_aInputSource.aInputStream) - break; - - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Cannot use argument to initialize a Configuration Parser" - "- InputSource or XInputStream expected")); - throw lang::IllegalArgumentException(sMessage,*this,1); - } - default: - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Too many arguments to initialize a Configuration Parser")); - throw lang::IllegalArgumentException(sMessage,*this,0); - } - } -} -// ----------------------------------------------------------------------------- - -template -inline -ServiceInfoHelper ParserService::getServiceInfo() -{ - return ParserServiceTraits::getServiceInfo(); -} -// ----------------------------------------------------------------------------- - -// XServiceInfo -template -::rtl::OUString SAL_CALL - ParserService::getImplementationName( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getImplementationName(); -} -// ----------------------------------------------------------------------------- - -template -sal_Bool SAL_CALL - ParserService::supportsService( const ::rtl::OUString& ServiceName ) - throw (uno::RuntimeException) -{ - return getServiceInfo().supportsService( ServiceName ); -} -// ----------------------------------------------------------------------------- - -template -uno::Sequence< ::rtl::OUString > SAL_CALL - ParserService::getSupportedServiceNames( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getSupportedServiceNames( ); -} -// ----------------------------------------------------------------------------- - -template -void SAL_CALL - ParserService::setInputStream( const uno::Reference< io::XInputStream >& aStream ) - throw (uno::RuntimeException) -{ - clear( m_aInputSource.sEncoding ); - clear( m_aInputSource.sSystemId ); - // clear( m_aInputSource.sPublicId ); - m_aInputSource.aInputStream = aStream; -} -// ----------------------------------------------------------------------------- - -template -uno::Reference< io::XInputStream > SAL_CALL - ParserService::getInputStream( ) - throw (uno::RuntimeException) -{ - return m_aInputSource.aInputStream; -} -// ----------------------------------------------------------------------------- - -template -void ParserService::parse(uno::Reference< sax::XDocumentHandler > const & _xHandler) -// throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_PRECOND( _xHandler.is(), "ParserService: No SAX handler to parse to"); - - rtl::OUString const k_sSaxParserService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")); - - uno::Reference< lang::XMultiComponentFactory > xServiceFactory = m_xContext->getServiceManager(); - - uno::Reference< sax::XParser > xParser = uno::Reference< sax::XParser >::query( xServiceFactory->createInstanceWithContext(k_sSaxParserService,m_xContext) ); - - if (!xParser.is()) - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration Parser: Cannot create SAX Parser")); - throw uno::RuntimeException(sMessage,*this); - } - - try - { - xParser->setDocumentHandler(_xHandler); - - sax::InputSource aInputSourceCopy = m_aInputSource; - //Set the sax input stream to null, an input stream can only be parsed once - m_aInputSource.aInputStream = NULL; - xParser->parseStream( aInputSourceCopy ); - } - catch (sax::SAXException & e) - { - uno::Any aWrapped = e.WrappedException.hasValue() ? e.WrappedException : uno::makeAny( e ); - rtl::OUString sSAXMessage = e.Message; - - // Expatwrap SAX service doubly wraps its errors ?? - sax::SAXException eInner; - if (aWrapped >>= eInner) - { - if (eInner.WrappedException.hasValue()) aWrapped = eInner.WrappedException; - - rtl::OUStringBuffer sMsgBuf(eInner.Message); - sMsgBuf.appendAscii("- {Parser Error: ").append(sSAXMessage).appendAscii(" }."); - sSAXMessage = sMsgBuf.makeStringAndClear(); - } - - static backenduno::MalformedDataException const * const forDataError = 0; - static lang::WrappedTargetException const * const forWrappedError = 0; - if (aWrapped.isExtractableTo(getCppuType(forDataError)) || - aWrapped.isExtractableTo(getCppuType(forWrappedError))) - { - cppu::throwException(aWrapped); - - OSL_ASSERT(!"not reached"); - } - - rtl::OUStringBuffer sMessageBuf; - sMessageBuf.appendAscii("Configuration Parser: a ").append( aWrapped.getValueTypeName() ); - sMessageBuf.appendAscii(" occurred while parsing: "); - sMessageBuf.append(sSAXMessage); - - throw lang::WrappedTargetException(sMessageBuf.makeStringAndClear(),*this,aWrapped); - } -} - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -sal_Char const * const aSchemaParserServices[] = -{ - "com.sun.star.configuration.backend.xml.SchemaParser", - 0 -}; -const ServiceImplementationInfo aSchemaParserSI = -{ - "com.sun.star.comp.configuration.backend.xml.SchemaParser", - aSchemaParserServices, - 0 -}; -// ----------------------------------------------------------------------------- -sal_Char const * const aLayerParserServices[] = -{ - "com.sun.star.configuration.backend.xml.LayerParser", - 0 -}; -const ServiceImplementationInfo aLayerParserSI = -{ - "com.sun.star.comp.configuration.backend.xml.LayerParser", - aLayerParserServices, - 0 -}; -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -template <> -struct ParserServiceTraits< backenduno::XSchema > -{ - static ServiceImplementationInfo const * getServiceInfo() - { return & aSchemaParserSI; } -}; -// ----------------------------------------------------------------------------- -template <> -struct ParserServiceTraits< backenduno::XLayer > -{ - static ServiceImplementationInfo const * getServiceInfo() - { return & aLayerParserSI; } -}; -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -class SchemaParserService : public ParserService< backenduno::XSchema > -{ -public: - SchemaParserService(uno::Reference< uno::XComponentContext > const & _xContext) - : ParserService< backenduno::XSchema >(_xContext) - { - } - - virtual void SAL_CALL readSchema( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException); - - virtual void SAL_CALL readComponent( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException); - - virtual void SAL_CALL readTemplates( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException); -}; -// ----------------------------------------------------------------------------- - -class LayerParserService : public ParserService< backenduno::XLayer > -{ -public: - LayerParserService(uno::Reference< uno::XComponentContext > const & _xContext) - : ParserService< backenduno::XLayer >(_xContext) - { - } - - virtual void SAL_CALL readData( uno::Reference< backenduno::XLayerHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException); -}; - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL instantiateSchemaParser( uno::Reference< uno::XComponentContext > const& xContext ) -{ - return * new SchemaParserService(xContext); -} -uno::Reference< uno::XInterface > SAL_CALL instantiateLayerParser( uno::Reference< uno::XComponentContext > const& xContext ) -{ - return * new LayerParserService(xContext); -} -// ----------------------------------------------------------------------------- -const ServiceRegistrationInfo* getSchemaParserServiceInfo() -{ return getRegistrationInfo(& aSchemaParserSI); } -const ServiceRegistrationInfo* getLayerParserServiceInfo() -{ return getRegistrationInfo(& aLayerParserSI); } -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -static rtl::OUString nullHandlerMessage(char const * where) -{ - OSL_ASSERT(where); - rtl::OUString msg = rtl::OUString::createFromAscii(where); - return msg.concat(rtl::OUString::createFromAscii(": Error - NULL handler passed.")); -} -// ----------------------------------------------------------------------------- -void SAL_CALL SchemaParserService::readSchema( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException) -{ - if (!aHandler.is()) - throw lang::NullPointerException(nullHandlerMessage("SchemaParserService::readSchema"),*this); - - uno::Reference< sax::XDocumentHandler > xHandler = new SchemaParser(this->getContext(),aHandler, SchemaParser::selectAll); - this->parse( xHandler ); -} -// ----------------------------------------------------------------------------- -void SAL_CALL SchemaParserService::readComponent( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException) -{ - if (!aHandler.is()) - throw lang::NullPointerException(nullHandlerMessage("SchemaParserService::readComponent"),*this); - - uno::Reference< sax::XDocumentHandler > xHandler = new SchemaParser(this->getContext(),aHandler, SchemaParser::selectComponent); - this->parse( xHandler ); -} -// ----------------------------------------------------------------------------- -void SAL_CALL SchemaParserService::readTemplates( uno::Reference< backenduno::XSchemaHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException) -{ - if (!aHandler.is()) - throw lang::NullPointerException(nullHandlerMessage("SchemaParserService::readTemplates"),*this); - - uno::Reference< sax::XDocumentHandler > xHandler = new SchemaParser(this->getContext(),aHandler, SchemaParser::selectTemplates); - this->parse( xHandler ); -} -// ----------------------------------------------------------------------------- -void SAL_CALL LayerParserService::readData( uno::Reference< backenduno::XLayerHandler > const & aHandler ) - throw (backenduno::MalformedDataException, lang::WrappedTargetException, - lang::NullPointerException, uno::RuntimeException) -{ - if (!aHandler.is()) - throw lang::NullPointerException(nullHandlerMessage("LayerParserService::readData"),*this); - - uno::Reference< sax::XDocumentHandler > xHandler = new LayerParser(this->getContext(),aHandler); - this->parse( xHandler ); -} -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - } // namespace - -// ----------------------------------------------------------------------------- -} // namespace - diff --git a/configmgr/source/xml/parsersvc.hxx b/configmgr/source/xml/parsersvc.hxx deleted file mode 100644 index cd0cf30b329e..000000000000 --- a/configmgr/source/xml/parsersvc.hxx +++ /dev/null @@ -1,117 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: parsersvc.hxx,v $ - * $Revision: 1.8 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_PARSERSVC_HXX -#define CONFIGMGR_XML_PARSERSVC_HXX - -#include "serviceinfohelper.hxx" -#include -#include -#include -#include -#include -#include -#include - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - namespace io = ::com::sun::star::io; - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - - template - class ParserService : public ::cppu::WeakImplHelper4< - lang::XInitialization, - lang::XServiceInfo, - io::XActiveDataSink, - BackendInterface - > - { - public: - explicit - ParserService(uno::Reference< uno::XComponentContext > const & _xContext); - - // XInitialization - virtual void SAL_CALL - initialize( const uno::Sequence< uno::Any >& aArguments ) - throw (uno::Exception, uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL - getImplementationName( ) - throw (uno::RuntimeException); - - virtual sal_Bool SAL_CALL - supportsService( const ::rtl::OUString& ServiceName ) - throw (uno::RuntimeException); - - virtual uno::Sequence< ::rtl::OUString > SAL_CALL - getSupportedServiceNames( ) - throw (uno::RuntimeException); - - // XActiveDataSink - virtual void SAL_CALL - setInputStream( const uno::Reference< io::XInputStream >& aStream ) - throw (uno::RuntimeException); - - virtual uno::Reference< io::XInputStream > SAL_CALL - getInputStream( ) - throw (uno::RuntimeException); - - protected: - uno::Reference< uno::XComponentContext > getContext() const - { return m_xContext; } - - void parse(uno::Reference< sax::XDocumentHandler > const & _xHandler); - // throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException); - - private: - uno::Reference< uno::XComponentContext > m_xContext; - sax::InputSource m_aInputSource; - - static ServiceInfoHelper getServiceInfo(); - }; - -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/schemaparser.cxx b/configmgr/source/xml/schemaparser.cxx deleted file mode 100644 index 1fd1cea90bb7..000000000000 --- a/configmgr/source/xml/schemaparser.cxx +++ /dev/null @@ -1,409 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: schemaparser.cxx,v $ - * $Revision: 1.13 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "schemaparser.hxx" - -// ----------------------------------------------------------------------------- -#include "wrapexception.hxx" - -#define WRAP_PARSE_EXCEPTIONS() \ - PASS_EXCEPTION(sax::SAXException) \ - PASS_EXCEPTION(uno::RuntimeException) \ - WRAP_CONFIGDATA_EXCEPTIONS( raiseParseException ) \ - WRAP_OTHER_EXCEPTIONS( raiseParseException ) - -#define WRAP_PARSE_EXCEPTIONS_MSG( msg ) \ - PASS_EXCEPTION(sax::SAXException) \ - PASS_EXCEPTION(uno::RuntimeException) \ - WRAP_CONFIGDATA_EXCEPTIONS1( raiseParseException, msg ) \ - WRAP_OTHER_EXCEPTIONS1( raiseParseException, msg ) - -// ----------------------------------------------------------------------------- - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace sax = ::com::sun::star::xml::sax; -// ----------------------------------------------------------------------------- - -SchemaParser::SchemaParser(uno::Reference< uno::XComponentContext > const & _xContext, uno::Reference< backenduno::XSchemaHandler > const & _xHandler, Select _selector) -: BasicParser(_xContext) -, m_xHandler(_xHandler) -, m_sComponent() -, m_selector(_selector) -, m_selected(selectNone) -{ - if (!m_xHandler.is()) - { - rtl::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 = rtl::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 rtl::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); - - try - { - 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); - this->startSkipping( aName, xAttribs ); - break; - - case ElementType::uses: - this->startSkipping( aName, xAttribs ); - break; - - case ElementType::instance: - this->handleInstance(aInfo,xAttribs); - this->startSkipping( aName, xAttribs ); - break; - - case ElementType::item_type: - this->handleItemType(aInfo,xAttribs); - this->startSkipping( aName, xAttribs ); - break; - - case ElementType::layer: - 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 - Error: invalid element type value\n"); - OSL_ENSURE( aInfo.type >= ElementType::other, "Schema XML parser - Unexpected: found layer element in schema data\n"); - // accept (and skip) unknown (ElementType::other) tags in schema to allow documentation and constraints to pass without assertion - //OSL_ENSURE( aInfo.type < ElementType::other, "Schema XML parser - Warning: ignoring unknown element tag\n"); - - this->startSkipping( aName, xAttribs ); - OSL_ASSERT( this->isSkipping() ); - return; - } - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Starting Element") - - 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 rtl::OUString& aName ) - throw (sax::SAXException, uno::RuntimeException) -{ - if ( this->wasSkipping(aName) ) - return; - - try - { - 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(); - } - WRAP_PARSE_EXCEPTIONS_MSG("LayerParser - Ending Element") -} -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -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 = rtl::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