diff options
author | sb <sb@openoffice.org> | 2010-03-10 16:47:22 +0100 |
---|---|---|
committer | sb <sb@openoffice.org> | 2010-03-10 16:47:22 +0100 |
commit | 2bd7376e52a2aa6da11962a4ff9495dec0c139db (patch) | |
tree | d27050da8508adaaaf940a30fd77751d86ec52fc /configmgr/source/xml | |
parent | 048f03264ce58c927c63460de84e5a87699998ba (diff) | |
parent | 8d8c715352d37c28e0e4987a29dbdb3e3db50ac8 (diff) |
tkr33: merged in DEV300_m74
Diffstat (limited to 'configmgr/source/xml')
26 files changed, 0 insertions, 6847 deletions
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 - * <http://www.openoffice.org/license.html> - * 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 <com/sun/star/xml/sax/SAXException.hpp> -#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<rtl::OUString> 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("<<<unknown>>>"); - 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 - * <http://www.openoffice.org/license.html> - * 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 <com/sun/star/xml/sax/XDocumentHandler.hpp> -#include <cppuhelper/implbase1.hxx> - -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<sax::XDocumentHandler> - { - 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 - * <http://www.openoffice.org/license.html> - * 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 <comphelper/attributelist.hxx> - -#include <rtl/ustrbuf.hxx> - -#include <com/sun/star/configuration/backend/SchemaAttribute.hpp> -#include <com/sun/star/configuration/backend/NodeAttribute.hpp> - -// ----------------------------------------------------------------------------- - -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<rtl::OUString const &>(NS_URI_OOR)); - addAttribute( sNamespaceDecl.concat(NS_PREFIX_XS ), static_cast<rtl::OUString const &>(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<rtl::OUString const &>(OPERATION_MODIFY)); break; - case Operation::clear: OSL_ENSURE(false,"'clear' operation is not yet supported"); break ; - //addAttribute(ATTR_OPERATION, static_cast<rtl::OUString const &>(OPERATION_CLEAR)); break; - case Operation::replace: addAttribute(ATTR_OPERATION, static_cast<rtl::OUString const &>(OPERATION_REPLACE)); break; - case Operation::fuse: addAttribute(ATTR_OPERATION, static_cast<rtl::OUString const &>(OPERATION_FUSE)); break; - case Operation::remove: addAttribute(ATTR_OPERATION, static_cast<rtl::OUString const &>(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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_ELEMENTFORMATTER_HXX -#define CONFIGMGR_XML_ELEMENTFORMATTER_HXX - -#include "elementinfo.hxx" -#include <com/sun/star/xml/sax/XAttributeList.hpp> - -#include <rtl/ref.hxx> - -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 - * <http://www.openoffice.org/license.html> - * 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 <sal/types.h> -#include <rtl/ustring.hxx> - -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 - * <http://www.openoffice.org/license.html> - * 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 <com/sun/star/configuration/backend/SchemaAttribute.hpp> -#include <com/sun/star/configuration/backend/NodeAttribute.hpp> - -#include <rtl/ustrbuf.hxx> - -// ----------------------------------------------------------------------------- - -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<sal_Int16 const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_INT)) - aRet = ::getCppuType(static_cast<sal_Int32 const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_LONG)) - aRet = ::getCppuType(static_cast<sal_Int64 const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_DOUBLE)) - aRet = ::getCppuType(static_cast< double const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_STRING)) - aRet = ::getCppuType(static_cast<rtl::OUString const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BINARY)) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int8> const*>(0)); - - else if(_rType.equalsIgnoreAsciiCaseAscii(VALUETYPE_ANY)) - aRet = ::getCppuType(static_cast<uno::Any const*>(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<uno::Sequence<sal_Bool> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_SHORT)) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int16> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_INT)) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int32> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_LONG)) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int64> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_DOUBLE)) - aRet = ::getCppuType(static_cast<uno::Sequence<double> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_STRING)) - aRet = ::getCppuType(static_cast<uno::Sequence<rtl::OUString> const*>(0)); - - else if(_aElementType.equalsIgnoreAsciiCaseAscii(VALUETYPE_BINARY)) - aRet = ::getCppuType(static_cast<uno::Sequence<uno::Sequence<sal_Int8> > 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:<type>' or 'oor:<type>' or 'oor:<type>-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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_ELEMENTPARSER_HXX -#define CONFIGMGR_XML_ELEMENTPARSER_HXX - -#include "elementinfo.hxx" -#include "logger.hxx" -#include <com/sun/star/xml/sax/XAttributeList.hpp> - -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 - * <http://www.openoffice.org/license.html> - * 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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_LAYERPARSER_HXX -#define CONFIGMGR_XML_LAYERPARSER_HXX - -#include "basicparser.hxx" - -#include <com/sun/star/configuration/backend/XLayerHandler.hpp> - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - - namespace sax = ::com::sun::star::xml::sax; - namespace backenduno = ::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 - * <http://www.openoffice.org/license.html> - * 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 <com/sun/star/beans/IllegalTypeException.hpp> -#include <com/sun/star/configuration/backend/BackendAccessException.hpp> -#include <com/sun/star/configuration/backend/ConnectionLostException.hpp> -#include <com/sun/star/configuration/backend/NodeAttribute.hpp> -// ----------------------------------------------------------------------------- - -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<uno::Exception const *>(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<io::IOException const *>(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 - * <http://www.openoffice.org/license.html> - * 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 <com/sun/star/configuration/backend/XLayerHandler.hpp> - -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 -# <http://www.openoffice.org/license.html> -# 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 - * <http://www.openoffice.org/license.html> - * 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 <rtl/ustrbuf.hxx> - -#include <algorithm> -#include <iterator> - -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 <class T> -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 <class T> -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<rtl::OUString> const& sLocaleNames_) -{ - return makeLocaleSeq_impl(sLocaleNames_); -} -// ----------------------------------------------------------------------------- - -uno::Sequence<rtl::OUString> 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<rtl::OUString> 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 - * <http://www.openoffice.org/license.html> - * 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 <rtl/ustrbuf.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <com/sun/star/configuration/backend/XSchema.hpp> -#include <com/sun/star/configuration/backend/XLayer.hpp> -#include <com/sun/star/lang/WrappedTargetException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/configuration/backend/MalformedDataException.hpp> -#include <com/sun/star/xml/sax/XParser.hpp> -// ----------------------------------------------------------------------------- - -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 <class BackendInterface> -struct ParserServiceTraits; -// ----------------------------------------------------------------------------- -static inline void clear(rtl::OUString & _rs) { _rs = rtl::OUString(); } - -// ----------------------------------------------------------------------------- -template <class BackendInterface> -ParserService<BackendInterface>::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 <class BackendInterface> -void SAL_CALL - ParserService<BackendInterface>::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 <class BackendInterface> -inline -ServiceInfoHelper ParserService<BackendInterface>::getServiceInfo() -{ - return ParserServiceTraits<BackendInterface>::getServiceInfo(); -} -// ----------------------------------------------------------------------------- - -// XServiceInfo -template <class BackendInterface> -::rtl::OUString SAL_CALL - ParserService<BackendInterface>::getImplementationName( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getImplementationName(); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -sal_Bool SAL_CALL - ParserService<BackendInterface>::supportsService( const ::rtl::OUString& ServiceName ) - throw (uno::RuntimeException) -{ - return getServiceInfo().supportsService( ServiceName ); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -uno::Sequence< ::rtl::OUString > SAL_CALL - ParserService<BackendInterface>::getSupportedServiceNames( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getSupportedServiceNames( ); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -void SAL_CALL - ParserService<BackendInterface>::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 <class BackendInterface> -uno::Reference< io::XInputStream > SAL_CALL - ParserService<BackendInterface>::getInputStream( ) - throw (uno::RuntimeException) -{ - return m_aInputSource.aInputStream; -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -void ParserService<BackendInterface>::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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_PARSERSVC_HXX -#define CONFIGMGR_XML_PARSERSVC_HXX - -#include "serviceinfohelper.hxx" -#include <cppuhelper/implbase4.hxx> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/io/XActiveDataSink.hpp> -#include <com/sun/star/xml/sax/InputSource.hpp> -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> - -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 BackendInterface> - 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 - * <http://www.openoffice.org/license.html> - * 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<Select>(m_selector & _select); - - return m_selected != 0; -} -// ----------------------------------------------------------------------------- - -void SchemaParser::startSection( Select _select, ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - if (this->select(_select)) - { - if (_select == selectComponent) - { - m_xHandler->startComponent(m_sComponent); - } - } - else - startSkipping(aInfo.name,xAttribs); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::endSection( ) -{ - if (m_selected == selectComponent) - { - m_xHandler->endComponent(); - } - m_selected = selectNone; -} -// ----------------------------------------------------------------------------- - -void SchemaParser::handleImport( ElementInfo const & /*aInfo*/, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - rtl::OUString aComponent; - if (getDataParser().getImportComponent(xAttribs,aComponent)) - m_xHandler->importComponent(aComponent); - - else - raiseParseException("Schema XML parser - Invalid data: Missing component attribute for import directive.\n"); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::handleInstance( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - backenduno::TemplateIdentifier aTemplate; - if (getDataParser().getInstanceType(xAttribs, aTemplate.Name, aTemplate.Component)) - m_xHandler->addInstance(aInfo.name, aTemplate); - - else - raiseParseException("Schema XML parser - Invalid data: Missing type information for instantiation directive.\n"); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::handleItemType( ElementInfo const & /*aInfo*/, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - backenduno::TemplateIdentifier aTemplate; - if (getDataParser().getInstanceType(xAttribs, aTemplate.Name, aTemplate.Component)) - m_xHandler->addItemType(aTemplate); - - else - raiseParseException("Schema XML parser - Invalid data: Missing type information for instantiation directive.\n"); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - bool bStartTemplate = ( !isInNode() && m_selected == selectTemplates ); - - BasicParser::startNode(aInfo,xAttribs); - - OSL_ASSERT(aInfo.type == ElementType::set || aInfo.type == ElementType::group); - - if (aInfo.type == ElementType::group) - { - if (bStartTemplate) - m_xHandler->startGroupTemplate( backenduno::TemplateIdentifier(aInfo.name,m_sComponent), aInfo.flags ); - - else - m_xHandler->startGroup( aInfo.name, aInfo.flags ); - } - else - { - backenduno::TemplateIdentifier aItemType; - - if (!getDataParser().getSetElementType(xAttribs, aItemType.Name, aItemType.Component)) - raiseParseException("Schema XML parser - Invalid data: Missing item-type information for set node.\n"); - - if (bStartTemplate) - m_xHandler->startSetTemplate( backenduno::TemplateIdentifier(aInfo.name,m_sComponent), aInfo.flags, aItemType ); - - else - m_xHandler->startSet( aInfo.name, aInfo.flags, aItemType ); - } -} -// ----------------------------------------------------------------------------- - -void SchemaParser::endNode() -{ - BasicParser::endNode(); - - bool bEndedTemplate = ( !isInNode() && m_selected == selectTemplates ); - - if (bEndedTemplate) - m_xHandler->endTemplate(); - - else - m_xHandler->endNode(); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ) -{ - BasicParser::startProperty(aInfo,xAttribs); - - OSL_ENSURE( isInUnhandledProperty(), "Property not recognizable as unhandled"); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::endProperty() -{ - if (isInUnhandledProperty()) - { - ElementInfo const & aInfo = this->getActiveNodeInfo(); - - m_xHandler->addProperty(aInfo.name, - aInfo.flags, - getActivePropertyType()); - } - - BasicParser::endProperty(); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::startValueData(const uno::Reference< sax::XAttributeList >& xAttribs) -{ - OSL_ENSURE( this->isInUnhandledProperty(),"Schema XML parser - multiple values in property are not permitted in the schema.\n"); - - BasicParser::startValueData(xAttribs); - - if (this->isValueDataLocalized()) - getLogger().warning("Language attributes on values are ignored in the schema.", - "endValueData()","configuration::xml::SchemaParser"); -} -// ----------------------------------------------------------------------------- - -void SchemaParser::endValueData() -{ - uno::Any aValue = this->getCurrentValue(); - - ElementInfo const & aInfo = this->getActiveNodeInfo(); - - if (aValue.hasValue()) - { - m_xHandler->addPropertyWithDefault(aInfo.name,aInfo.flags,aValue); - } - else - { - getLogger().warning("Found deprecated explicit NIL value in schema data.", - "endValueData()","configuration::xml::SchemaParser"); - m_xHandler->addProperty(aInfo.name,aInfo.flags,getActivePropertyType()); - } - - BasicParser::endValueData(); - - OSL_ENSURE( !isInUnhandledProperty(), "Property not recognizable as handled"); -} -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- - } // namespace - -// ----------------------------------------------------------------------------- -} // namespace - diff --git a/configmgr/source/xml/schemaparser.hxx b/configmgr/source/xml/schemaparser.hxx deleted file mode 100644 index 782eba72afa2..000000000000 --- a/configmgr/source/xml/schemaparser.hxx +++ /dev/null @@ -1,135 +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.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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_SCHEMAPARSER_HXX -#define CONFIGMGR_XML_SCHEMAPARSER_HXX - -#include "basicparser.hxx" - -#include <com/sun/star/configuration/backend/XSchemaHandler.hpp> - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - - namespace sax = ::com::sun::star::xml::sax; - namespace backenduno = ::com::sun::star::configuration::backend; - -// ----------------------------------------------------------------------------- - - - class SchemaParser : public BasicParser - { - public: - enum Select { - selectNone = 0, - selectComponent = 0x01, - selectTemplates = 0x02, - selectAll = 0x03 - }; - - public: - SchemaParser(uno::Reference< uno::XComponentContext > const & _xContext, uno::Reference< backenduno::XSchemaHandler > const & _xHandler, Select _selector); - virtual ~SchemaParser(); - - // XDocumentHandler - public: - virtual void SAL_CALL - startDocument( ) - throw (sax::SAXException, uno::RuntimeException); - - virtual void SAL_CALL - endDocument( ) throw (sax::SAXException, uno::RuntimeException); - - virtual void SAL_CALL - startElement( const 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 the schema - void startSchema( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - /// end the schema - void endSchema(); - - /// start a section (components or templates) - void startSection( Select _select, ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - /// end the current section - void endSection(); - - /// handle a import directive element - void handleImport( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - - /// start an node - void startNode( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - /// end a node - void endNode(); - - /// start a property - void startProperty( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - /// end a property - void endProperty(); - - /// start collecting data for a value - returns the locale of the value (property must have been started) - void startValueData(const uno::Reference< sax::XAttributeList >& xAttribs); - /// end collecting data for a value - returns the collected value - void endValueData(); - - /// handle a instance ref element - void handleInstance( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - /// handle a item-type declaration element - void handleItemType( ElementInfo const & aInfo, const uno::Reference< sax::XAttributeList >& xAttribs ); - - bool isSelected() const { return m_selected != selectNone; } - bool select(Select _select); - private: - uno::Reference< backenduno::XSchemaHandler > m_xHandler; - rtl::OUString m_sComponent; - Select m_selector; - Select m_selected; - }; -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/simpletypehelper.cxx b/configmgr/source/xml/simpletypehelper.cxx deleted file mode 100644 index 60785393d420..000000000000 --- a/configmgr/source/xml/simpletypehelper.cxx +++ /dev/null @@ -1,57 +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: simpletypehelper.cxx,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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "simpletypehelper.hxx" -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/uno/Any.hxx> - -namespace configmgr -{ - namespace uno = com::sun::star::uno; - namespace SimpleTypeHelper - { - - uno::Type getBooleanType() { return ::getBooleanCppuType(); } - - uno::Type getShortType() { return ::getCppuType(static_cast<sal_Int16 const*>(0)); } - uno::Type getIntType() { return ::getCppuType(static_cast<sal_Int32 const*>(0)); } - uno::Type getLongType() { return ::getCppuType(static_cast<sal_Int64 const*>(0)); } - - uno::Type getDoubleType() { return ::getCppuType(static_cast<double const*>(0)); } - - uno::Type getStringType() { return ::getCppuType(static_cast<rtl::OUString const*>(0)); } - - uno::Type getBinaryType() { return ::getCppuType(static_cast<uno::Sequence<sal_Int8> const*>(0)); } - uno::Type getAnyType() { return ::getCppuType(static_cast<uno::Any const*>(0)); } - } -} diff --git a/configmgr/source/xml/typeconverter.cxx b/configmgr/source/xml/typeconverter.cxx deleted file mode 100644 index 0f292db78de2..000000000000 --- a/configmgr/source/xml/typeconverter.cxx +++ /dev/null @@ -1,354 +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: typeconverter.cxx,v $ - * $Revision: 1.25 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include "typeconverter.hxx" -#include "utility.hxx" -#include "simpletypehelper.hxx" -#include <com/sun/star/script/XTypeConverter.hpp> -#include <com/sun/star/script/FailReason.hpp> -#include <com/sun/star/uno/Type.hxx> -#include <strdecl.hxx> -#include <typelib/typedescription.hxx> - - -#include <rtl/ustring.hxx> -#include <osl/diagnose.h> - -namespace uno = ::com::sun::star::uno; -namespace script = ::com::sun::star::script; -namespace lang = ::com::sun::star::lang; - -namespace configmgr -{ - -//-------------------------------------------------------------------------------------------------- - rtl::OUString toString(const uno::Reference< script::XTypeConverter >& xTypeConverter, const uno::Any& rValue) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) - { - rtl::OUString aRes; - uno::TypeClass aDestinationClass = rValue.getValueType().getTypeClass(); - - switch (aDestinationClass) - { - case uno::TypeClass_BOOLEAN: - case uno::TypeClass_CHAR: - case uno::TypeClass_BYTE: - case uno::TypeClass_SHORT: - case uno::TypeClass_LONG: - case uno::TypeClass_HYPER: - case uno::TypeClass_FLOAT: - case uno::TypeClass_DOUBLE: - if (!xTypeConverter.is()) - { - throw script::CannotConvertException( - ::rtl::OUString::createFromAscii("Missing Converter Service!"), - uno::Reference< uno::XInterface > (), - aDestinationClass, - script::FailReason::UNKNOWN, 0 - ); - } - xTypeConverter->convertToSimpleType(rValue, uno::TypeClass_STRING) >>= aRes; - break; - - case ::uno::TypeClass_STRING: - rValue >>= aRes; - break; - - default: - throw script::CannotConvertException( - ::rtl::OUString::createFromAscii("Unsupported type: ") + rValue.getValueType().getTypeName(), - uno::Reference< uno::XInterface > (), - aDestinationClass, - script::FailReason::TYPE_NOT_SUPPORTED, 0 - ); - - } - return aRes; - } - - uno::Any toAny(const uno::Reference< script::XTypeConverter >& xTypeConverter, const ::rtl::OUString& _rValue,const uno::TypeClass& _rTypeClass) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) - { - uno::Any aRes; - - if (uno::TypeClass_STRING == _rTypeClass) - { - aRes <<= _rValue; - } - else if (!xTypeConverter.is()) - { - throw script::CannotConvertException( - ::rtl::OUString::createFromAscii("Missing Converter Service!"), - uno::Reference< uno::XInterface > (), - _rTypeClass, - script::FailReason::UNKNOWN, 0 - ); - } - else try - { - aRes = xTypeConverter->convertToSimpleType(uno::makeAny(_rValue), _rTypeClass); - } - catch (script::CannotConvertException& ) - { - // ok, next try with trim() - ::rtl::OUString const sTrimmed = _rValue.trim(); - if (sTrimmed.getLength() != 0) - { - try - { - aRes = xTypeConverter->convertToSimpleType(uno::makeAny(sTrimmed), _rTypeClass); - - OSL_ENSURE(aRes.hasValue(),"Converted non-empty string to NULL\n"); - } - catch (script::CannotConvertException&) - { - OSL_ASSERT(!aRes.hasValue()); - } - catch (uno::Exception&) - { - OSL_ENSURE(false,"Unexpected exception from XTypeConverter::convertToSimpleType()\n"); - OSL_ASSERT(!aRes.hasValue()); - } - - if (!aRes.hasValue()) throw; - } - } - catch (lang::IllegalArgumentException& iae) - { - OSL_ENSURE(sal_False, "Illegal argument for typeconverter. Maybe invalid typeclass ?"); - throw script::CannotConvertException( - ::rtl::OUString::createFromAscii("Invalid Converter Argument:") + iae.Message, - uno::Reference< uno::XInterface > (), - _rTypeClass, - script::FailReason::UNKNOWN, 0 - ); - } - catch (uno::Exception& e) - { - OSL_ENSURE(false,"Unexpected exception from XTypeConverter::convertToSimpleType()\n"); - throw script::CannotConvertException( - ::rtl::OUString::createFromAscii("Unexpected TypeConverter Failure:") + e.Message, - uno::Reference< uno::XInterface > (), - _rTypeClass, - script::FailReason::UNKNOWN, 0 - ); - } - return aRes; - } - - ::rtl::OUString toTypeName(const uno::TypeClass& _rTypeClass) - { - ::rtl::OUString aRet; - switch(_rTypeClass) - { - case uno::TypeClass_BOOLEAN: aRet = TYPE_BOOLEAN; break; - case uno::TypeClass_SHORT: aRet = TYPE_SHORT; break; - case uno::TypeClass_LONG: aRet = TYPE_INT; break; - case uno::TypeClass_HYPER: aRet = TYPE_LONG; break; - case uno::TypeClass_DOUBLE: aRet = TYPE_DOUBLE; break; - case uno::TypeClass_STRING: aRet = TYPE_STRING; break; - case uno::TypeClass_SEQUENCE: aRet = TYPE_BINARY; break; - case uno::TypeClass_ANY: aRet = TYPE_ANY; break; - default: - { - ::rtl::OString aStr("Wrong typeclass! "); - aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass); - OSL_ENSURE(0,aStr.getStr()); - } - } - return aRet; - } - -// ************************************************************************* - uno::Type toType(const ::rtl::OUString& _rType) - { - uno::Type aRet; - - if (_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("boolean"))) aRet = SimpleTypeHelper::getBooleanType(); - - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("short"))) aRet = SimpleTypeHelper::getShortType(); - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("int"))) aRet = SimpleTypeHelper::getIntType(); - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("integer"))) aRet = SimpleTypeHelper::getIntType(); - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("long"))) aRet = SimpleTypeHelper::getLongType(); - - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("double"))) aRet = SimpleTypeHelper::getDoubleType(); - - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("string"))) aRet = SimpleTypeHelper::getStringType(); - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("binary"))) aRet = SimpleTypeHelper::getBinaryType(); -// else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("sequence"))) aRet = uno::TypeClass_SEQUENCE; - - else if(_rType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("any"))) aRet = SimpleTypeHelper::getAnyType(); - else - { - ::rtl::OString aStr("Unknown type! "); - aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(0,aStr.getStr()); - } - - return aRet; - } - uno::Type toListType(const ::rtl::OUString& _rsElementType) - { - uno::Type aRet; - - if (_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("boolean"))) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Bool> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("short"))) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int16> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("int"))) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int32> const*>(0)); - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("integer"))) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int32> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("long"))) - aRet = ::getCppuType(static_cast<uno::Sequence<sal_Int64> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("double"))) - aRet = ::getCppuType(static_cast<uno::Sequence<double> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("string"))) - aRet = ::getCppuType(static_cast<uno::Sequence<rtl::OUString> const*>(0)); - - else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("binary"))) - aRet = ::getCppuType(static_cast<uno::Sequence<uno::Sequence<sal_Int8> > const*>(0)); - -// else if(_rsElementType.equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("sequence"))) aRet = uno::TypeClass_SEQUENCE; - else - { - ::rtl::OString aStr("Unknown type! "); - aStr += rtl::OUStringToOString(_rsElementType,RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(0,aStr.getStr()); - } - - return aRet; - } - - uno::Type getSequenceElementType(uno::Type const& rSequenceType) - { - OSL_ENSURE(rSequenceType.getTypeClass() == uno::TypeClass_SEQUENCE, - "getSequenceElementType() must be called with a sequence type"); - - if (!(rSequenceType.getTypeClass() == uno::TypeClass_SEQUENCE)) - return uno::Type(); - - uno::TypeDescription aTD(rSequenceType); - typelib_IndirectTypeDescription* pSequenceTD = - reinterpret_cast< typelib_IndirectTypeDescription* >(aTD.get()); - - OSL_ASSERT(pSequenceTD); - OSL_ASSERT(pSequenceTD->pType); - - if ( pSequenceTD && pSequenceTD->pType ) - { - return uno::Type(pSequenceTD->pType); - } //if - - return uno::Type(); - } - uno::Type getBasicType(uno::Type const& rType, bool& bSequence) - { - bSequence = rType.getTypeClass() == uno::TypeClass_SEQUENCE && - rType != SimpleTypeHelper::getBinaryType(); - - if (!bSequence) - return rType; - - return getSequenceElementType(rType); - } - - - // template names -// ************************************************************************* - ::rtl::OUString toTemplateName(const uno::Type& _rType) - { - bool bList; - uno::Type aBaseType = getBasicType(_rType,bList); - return toTemplateName(aBaseType.getTypeClass(), bList); - } - - ::rtl::OUString toTemplateName(const uno::TypeClass& _rBasicType, bool bList) - { - return toTemplateName(toTypeName(_rBasicType), bList); - } - -// ************************************************************************* - uno::Type parseTemplateName(::rtl::OUString const& sTypeName) - { - uno::Type aRet; - - ::rtl::OUString sBasicTypeName; - bool bList; - if (parseTemplateName(sTypeName, sBasicTypeName,bList)) - aRet = toType(sBasicTypeName,bList); - // else leave as void - - return aRet; - } - -// ************************************************************************* - ::rtl::OUString toTemplateName(const ::rtl::OUString& _rBasicTypeName, bool bList) - { - ::rtl::OUString sName = TEMPLATE_MODULE_NATIVE_PREFIX + _rBasicTypeName; - if (bList) - sName += TEMPLATE_LIST_SUFFIX; - - - return sName; - } - - bool parseTemplateName(::rtl::OUString const& sTypeName, ::rtl::OUString& _rBasicName, bool& bList) - { - ::rtl::OUString const sSuffix( TEMPLATE_LIST_SUFFIX ); - - sal_Int32 nIndex = sTypeName.lastIndexOf(sSuffix); - if (nIndex >= 0 && nIndex + sSuffix.getLength() == sTypeName.getLength()) - { - bList = true; - _rBasicName = sTypeName.copy(0,nIndex); - } - else - { - bList = false; - _rBasicName = sTypeName; - } - // erase the default prefix 'cfg:' - if (_rBasicName.indexOf(TEMPLATE_MODULE_NATIVE_PREFIX) == 0) - _rBasicName = _rBasicName.copy(TEMPLATE_MODULE_NATIVE_PREFIX.m_nLen); - - return true; - - } -// ************************************************************************* - -} // namespace configmgr diff --git a/configmgr/source/xml/valueconverter.cxx b/configmgr/source/xml/valueconverter.cxx deleted file mode 100644 index 116d70d1852c..000000000000 --- a/configmgr/source/xml/valueconverter.cxx +++ /dev/null @@ -1,504 +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: valueconverter.cxx,v $ - * $Revision: 1.23 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "valuetypeconverter.hxx" -#include "typeconverter.hxx" - -inline sal_Bool rtl_ascii_isWhitespace( sal_Unicode ch ) -{ - return ch <= 0x20 && ch; -} - -namespace configmgr -{ -// ----------------------------------------------------------------------------- -static -void throwConversionError(sal_Char const* pErrorMsg) SAL_THROW((script::CannotConvertException)) -{ - OSL_ENSURE(false, pErrorMsg); - - script::CannotConvertException error; - error.Message = rtl::OUString::createFromAscii(pErrorMsg); - throw error; -} -// ----------------------------------------------------------------------------- -template <class Char> -inline -bool charInRange(Char ch, char from, char to) throw() -{ - return Char(from) <= ch && ch <= Char(to); -} - -// ----------------------------------------------------------------------------- -static -inline -unsigned makeHexNibble(unsigned char ch) SAL_THROW((script::CannotConvertException)) -{ - unsigned nRet = 0; - - if (charInRange(ch, '0', '9')) nRet = ch - unsigned('0'); - - else if (charInRange(ch, 'a', 'f')) nRet = ch - unsigned('a' - 10u); - - else if (charInRange(ch, 'A', 'F')) nRet = ch - unsigned('A' - 10u); - - else throwConversionError("Invalid Hex Character in binary value"); - - return nRet; -} - -// ----------------------------------------------------------------------------- -static -inline -unsigned readHexNibble(sal_Unicode ch) SAL_THROW((script::CannotConvertException)) -{ - if (!charInRange(ch, 0, 127)) throwConversionError("Non-Ascii Character in binary value"); - - return makeHexNibble(static_cast<unsigned char>(ch)); -} - -// ----------------------------------------------------------------------------- -static -inline -unsigned int readHexByte(sal_Unicode const*& pStr) SAL_THROW((script::CannotConvertException)) -{ - register unsigned int nHigh = readHexNibble(*pStr++); - register unsigned int nLow = readHexNibble(*pStr++); - return (nHigh << 4) | nLow; -} - -// ----------------------------------------------------------------------------- -static -void parseHexBinary(rtl::OUString const& aHexString_, uno::Sequence<sal_Int8>& rBinarySeq_) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - // PRE: aBinaryString with HexCode - // POST: rBinarySeq with the to Hex converted String - - sal_uInt32 nCount = aHexString_.getLength(); - sal_Unicode const * pHex = aHexString_.getStr(); - - if (nCount % 2) throwConversionError("Hex string has odd number of characters"); - nCount /= 2; - - rBinarySeq_.realloc(nCount); - sal_Int8 * pBinary = rBinarySeq_.getArray(); - - while (nCount--) - { - *pBinary++ = static_cast<sal_Int8>(readHexByte(pHex)); - } -} - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -uno::Sequence<sal_Int8> ValueConverter::parseBinary(rtl::OUString const& aBinaryString_) const - SAL_THROW((script::CannotConvertException, com::sun::star::uno::RuntimeException)) -{ - uno::Sequence<sal_Int8> aResultSeq; - - parseHexBinary(aBinaryString_,aResultSeq); - - return aResultSeq; -} - -// ----------------------------------------------------------------------------- -static inline -uno::Type getBinaryType() -{ - uno::Sequence<sal_Int8> const * const for_binary = 0; - return ::getCppuType(for_binary); -} - -// ----------------------------------------------------------------------------- -bool ValueConverter::isList() const -{ - return m_aType.getTypeClass() == uno::TypeClass_SEQUENCE && - m_aType != getBinaryType(); -} - -// ----------------------------------------------------------------------------- -uno::Any ValueConverter::convertToAny(rtl::OUString const& aContent) const - SAL_THROW((script::CannotConvertException, com::sun::star::uno::RuntimeException)) -{ - uno::Any aValue; - - if (this->isNull()) - { - OSL_ENSURE(aContent.trim().getLength() == 0, "ValueConverter: Non-empty Null Value - ignoring content"); - OSL_ASSERT(!aValue.hasValue()); - } - - else if (this->isList()) - { - std::vector< rtl::OUString > aContentList; - splitListData(aContent, aContentList); - convertListToAny(aContentList, aValue); - } - - else - { - convertScalarToAny(aContent, aValue); - } - - return aValue; -} - -// ----------------------------------------------------------------------------- -bool ValueConverter::convertScalarToAny(rtl::OUString const& aContent, uno::Any& rValue) const - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - OSL_PRECOND(!this->isNull(),"ValueConverter::convertScalarToAny - check for NULL before calling"); - OSL_ENSURE(m_aType.getTypeClass() != uno::TypeClass_ANY,"'Any' values must be NULL"); - - // check for Binary - if (m_aType == getBinaryType()) - { - com::sun::star::uno::Sequence<sal_Int8> aBinarySeq = parseBinary(aContent); - rValue <<= aBinarySeq; - } - - else - { - rValue = toAny(m_xTypeConverter, aContent, m_aType.getTypeClass()); - } - - return !! rValue.hasValue(); -} - -// ----------------------------------------------------------------------------- -template <class T> -bool convertListToSequence(std::vector< rtl::OUString > const& aStringList, uno::Sequence< T >& rSequence, uno::TypeClass aElementTypeClass, ValueConverter const& rConverter) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - OSL_ASSERT(aElementTypeClass == ::getCppuType(static_cast<T const*>(0)).getTypeClass()); - - rSequence.realloc(aStringList.size()); - - sal_uInt32 nPos = 0; - - for(std::vector< rtl::OUString >::const_iterator it = aStringList.begin(); - it != aStringList.end(); - ++it) - { - uno::Any aValueAny = toAny(rConverter.getTypeConverter(), *it, aElementTypeClass); - - if (aValueAny >>= rSequence[nPos]) - ++nPos; - - else if (!aValueAny.hasValue()) - OSL_ENSURE(false,"UNEXPECTED: Found NULL value in List - ignoring value !"); - - else - OSL_ENSURE(false,"ERROR: Cannot extract converted value into List - skipping value !"); - } - - bool bOK = (nPos == aStringList.size()); - - if (!bOK) - { - OSL_ASSERT(nPos < aStringList.size()); - rSequence.realloc(nPos); - } - return bOK; -} - -// ----------------------------------------------------------------------------- -// special conversion for string sequence - -static -inline -void stringListToSequence(uno::Sequence< rtl::OUString > & rSequence, std::vector< rtl::OUString > const & aStringList) -{ - rSequence .realloc( aStringList.size() ); - - std::copy( aStringList.begin(), aStringList.end(), rSequence.getArray() ); -} -// ----------------------------------------------------------------------------- - -static -inline -std::vector< rtl::OUString > sequenceToStringList(uno::Sequence< rtl::OUString > const & aSequence) -{ - rtl::OUString const * const pBegin = aSequence.getConstArray(); - rtl::OUString const * const pEnd = pBegin + aSequence.getLength(); - - return std::vector< rtl::OUString >(pBegin,pEnd); -} -// ----------------------------------------------------------------------------- - -uno::Sequence< rtl::OUString > ValueConverter::splitStringList(rtl::OUString const& aContent) const -{ - std::vector< rtl::OUString > aList; - splitListData(aContent, aList); - - uno::Sequence< rtl::OUString > aResult; - stringListToSequence(aResult,aList); - - return aResult; -} -// ----------------------------------------------------------------------------- - -uno::Any ValueConverter::convertListToAny(uno::Sequence< rtl::OUString > const& aContentList) const - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - uno::Any aResult; - std::vector< rtl::OUString > const aStringList = sequenceToStringList(aContentList); - convertListToAny(aStringList,aResult); - return aResult; -} -// ----------------------------------------------------------------------------- -// special overload for binary sequence - -// template<> // use an explicit specialization -bool convertListToSequence(std::vector< rtl::OUString > const& aStringList, uno::Sequence< uno::Sequence<sal_Int8> >& rSequence, uno::TypeClass aElementTypeClass, ValueConverter const& rParser ) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - { (void)aElementTypeClass; } - OSL_ASSERT(aElementTypeClass == uno::TypeClass_SEQUENCE); - - rSequence.realloc(aStringList.size()); - - sal_uInt32 nPos = 0; - - for(std::vector< rtl::OUString >::const_iterator it = aStringList.begin(); - it != aStringList.end(); - ++it) - { - rSequence[nPos++] = rParser.parseBinary(*it); - } - return true; -} - -// ----------------------------------------------------------------------------- -// special overload for string sequence - -// template<> // use an explicit specialization -bool convertListToSequence(std::vector< rtl::OUString > const& aStringList, uno::Sequence< rtl::OUString >& rSequence, uno::TypeClass aElementTypeClass, ValueConverter const& /*rParser*/ ) - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - { (void)aElementTypeClass; } - OSL_ASSERT(aElementTypeClass == uno::TypeClass_STRING); - - stringListToSequence(rSequence, aStringList); - - return true; -} - -// ----------------------------------------------------------------------------- - -#define MAYBE_EXTRACT_SEQUENCE( type ) \ - if (aElementType == ::getCppuType( (type const *)0)) \ - { \ - com::sun::star::uno::Sequence< type > aSequence; \ - convertListToSequence(aContentList,aSequence,aElementTypeClass, *this); \ - rValue <<= aSequence; \ - } - -bool ValueConverter::convertListToAny(std::vector< rtl::OUString > const& aContentList, uno::Any& rValue) const - SAL_THROW((script::CannotConvertException , com::sun::star::uno::RuntimeException)) -{ - OSL_PRECOND(!this->isNull(),"ValueConverter::convertListToAny - check for NULL before calling"); - OSL_ENSURE(m_aType.getTypeClass() == uno::TypeClass_SEQUENCE,"'Any' not allowed for lists"); - - uno::Type aElementType = getSequenceElementType(m_aType); - uno::TypeClass aElementTypeClass = aElementType.getTypeClass(); - - OSL_ENSURE(aElementTypeClass != uno::TypeClass_ANY,"'Any' not allowed for list elements"); - - MAYBE_EXTRACT_SEQUENCE( rtl::OUString ) - else - MAYBE_EXTRACT_SEQUENCE( sal_Bool ) - else - MAYBE_EXTRACT_SEQUENCE( sal_Int16 ) - else - MAYBE_EXTRACT_SEQUENCE( sal_Int32 ) - else - MAYBE_EXTRACT_SEQUENCE( sal_Int64 ) - else - MAYBE_EXTRACT_SEQUENCE( double ) - else - MAYBE_EXTRACT_SEQUENCE( com::sun::star::uno::Sequence<sal_Int8> ) - else - { - OSL_ENSURE(false, "Unknown element type in list"); - throwConversionError("Invalid value-type found in list value"); - } - - return !! rValue.hasValue(); -} -#undef MAYBE_EXTRACT_SEQUENCE - -// ----------------------------------------------------------------------------- -namespace -{ - sal_Int32 const NO_MORE_TOKENS = -1; - struct OTokenizeByWhitespace - { - - static inline bool isWhitespace(sal_Unicode ch) - { - // note: for definition of whitescape see also - // canUseWhitespace(rtl::OUString const&) - // in xmlformater.cxx - // ----------------------------------------------------------------------------- - return rtl_ascii_isWhitespace(ch) ? true : false; - } - - sal_Int32 findFirstTokenStart(rtl::OUString const& sText) const SAL_THROW(()) - { - return findNextTokenStart(sText,0); - } - - sal_Int32 findNextTokenStart(rtl::OUString const& sText, sal_Int32 nPrevTokenEnd) const SAL_THROW(()) - { - sal_Int32 const nEnd = sText.getLength(); - sal_Int32 nPos = nPrevTokenEnd; - - OSL_PRECOND( nPos == 0 || (0 < nPos && nPos < nEnd && isWhitespace(sText[nPos])) || nPos == nEnd, - "Invalid nPrevTokenEnd"); - - while (nPos < nEnd && isWhitespace(sText[nPos])) - { - ++nPos; - } - - if (nPos < nEnd) - return nPos; - else - return NO_MORE_TOKENS; - } - - sal_Int32 findTokenEnd(rtl::OUString const& sText, sal_Int32 nTokenStart) const SAL_THROW(()) - { - sal_Int32 const nEnd = sText.getLength(); - sal_Int32 nPos = nTokenStart; - - OSL_PRECOND( 0 <= nPos && nPos < nEnd && !isWhitespace(sText[nPos]), - "Invalid nTokenStart"); - - while (nPos < nEnd && !isWhitespace(sText[nPos])) - { - ++nPos; - } - - return nPos; - } - }; -// ----------------------------------------------------------------------------- - struct OTokenizeBySeparator - { - rtl::OUString const sSeparator; - OTokenizeBySeparator(rtl::OUString const& _sSeparator) SAL_THROW(()) - : sSeparator(_sSeparator) - { - OSL_PRECOND(sSeparator.trim().getLength() > 0, "Invalid empty separator string"); - } - - sal_Int32 findFirstTokenStart(rtl::OUString const& /*sText*/) const SAL_THROW(()) - { - return 0; - } - sal_Int32 findNextTokenStart(rtl::OUString const& sText, sal_Int32 nPrevTokenEnd) const SAL_THROW(()) - { - sal_Int32 const nEnd = sText.getLength(); - sal_Int32 nPos = nPrevTokenEnd; - OSL_PRECOND( nPos == nEnd || (0 <= nPos && nPos < nEnd && sText.indexOf(sSeparator, nPos) == nPos), - "Invalid nPrevTokenEnd"); - - if (nPos < nEnd) - return nPos + sSeparator.getLength(); - else - return NO_MORE_TOKENS; - } - sal_Int32 findTokenEnd(rtl::OUString const& sText, sal_Int32 nTokenStart) const SAL_THROW(()) - { - sal_Int32 const nEnd = sText.getLength(); - OSL_PRECOND( 0 <= nTokenStart && nTokenStart <= nEnd , - "Invalid nTokenStart"); - - sal_Int32 nPos = sText.indexOf(sSeparator,nTokenStart); - - if (nPos >= 0) - return nPos; - else - return nEnd; - } - }; -// ----------------------------------------------------------------------------- - template <class Tokenizer> - void tokenizeListData(Tokenizer const& aTokenizer, rtl::OUString const& aContent, std::vector< rtl::OUString >& rContentList) - SAL_THROW(()) - { - sal_Int32 nTokenPos = aTokenizer.findFirstTokenStart(aContent); - - while(nTokenPos != NO_MORE_TOKENS) - { - sal_Int32 nTokenEnd = aTokenizer.findTokenEnd(aContent, nTokenPos); - - // this is what the tokenizer must provide - OSL_ASSERT(0 <= nTokenPos && nTokenPos <= nTokenEnd && nTokenEnd <= aContent.getLength()); - - rContentList.push_back( aContent.copy(nTokenPos, nTokenEnd-nTokenPos) ); - - nTokenPos= aTokenizer.findNextTokenStart(aContent, nTokenEnd); - } - } -// ----------------------------------------------------------------------------- -} -// ----------------------------------------------------------------------------- -void ValueConverter::splitListData(rtl::OUString const& aContent, std::vector< rtl::OUString >& rContentList) const - SAL_THROW(()) -{ - rtl::OUString sSeparator = m_sSeparator; - - bool bSeparateByWhitespace = (sSeparator.trim().getLength() == 0); - - if (bSeparateByWhitespace) - { - OSL_ENSURE( sSeparator.getLength()==0 || sSeparator.equalsAscii(" "), - "Unexpected whitespace-only separator"); - - tokenizeListData( OTokenizeByWhitespace(), aContent, rContentList ); - } - else - { - OSL_ENSURE( sSeparator.trim()==sSeparator, - "Unexpected whitespace in separator"); - - tokenizeListData( OTokenizeBySeparator(sSeparator), aContent, rContentList ); - } -} -// ----------------------------------------------------------------------------- - -} // namespace diff --git a/configmgr/source/xml/valueformatter.cxx b/configmgr/source/xml/valueformatter.cxx deleted file mode 100644 index 213f668e6f90..000000000000 --- a/configmgr/source/xml/valueformatter.cxx +++ /dev/null @@ -1,498 +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: valueformatter.cxx,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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "valueformatter.hxx" -#include "elementformatter.hxx" -#include "xmlstrings.hxx" -#include "typeconverter.hxx" -#include "simpletypehelper.hxx" -#include <rtl/ustrbuf.hxx> -#include <com/sun/star/uno/Sequence.hxx> - -#ifndef INCLUDED_ALGORITHM -#include <algorithm> -#define INCLUDED_ALGORITHM -#endif - -namespace configmgr -{ - namespace uno = com::sun::star::uno; - - namespace xml - { - -//========================================================================== -//= Helper -//========================================================================== - -// ----------------------------------------------------------------------------- -namespace -{ -// ----------------------------------------------------------------------------- - -static -inline -bool isWhitespaceCharacter( sal_Unicode ch ) -{ - return ch <= 0x20 && ch; -} -// ----------------------------------------------------------------------------- - -static -inline -bool isWhitespaceString(rtl::OUString const & aStr) -{ - sal_Unicode const * const pBegin = aStr.getStr(); - sal_Unicode const * const pEnd = pBegin + aStr.getLength(); - - // BACK: true, if any whitespace in string or string is empty - if (pBegin == pEnd) - return true; - - sal_Unicode const * const pSpace = std::find_if(pBegin,pEnd,isWhitespaceCharacter); - - return pSpace != pEnd; -} -// ----------------------------------------------------------------------------- - -static -bool hasWhitespaceString( uno::Sequence< rtl::OUString > const & aSeq) -{ - // BACK: true, if whitespace Separator is ok, (no whitespace in Strings, no empty strings) - rtl::OUString const * const pBegin = aSeq.getConstArray(); - rtl::OUString const * const pEnd = pBegin + aSeq.getLength(); - - rtl::OUString const * const pSpace = std::find_if(pBegin,pEnd,isWhitespaceString); - - return pSpace != pEnd; -} -// ----------------------------------------------------------------------------- - -struct HasSubString -{ - HasSubString(rtl::OUString const & _aSubStr) - : m_aSubStr(_aSubStr) - {} - - bool operator()(rtl::OUString const & _aStr) - { return _aStr.indexOf(m_aSubStr) >= 0; } - - rtl::OUString const m_aSubStr; -}; -// ----------------------------------------------------------------------------- - -static -bool hasStringWithSubstring(const uno::Sequence< rtl::OUString > &aSeq, rtl::OUString const & _aSubStr) -{ - rtl::OUString const * const pBegin = aSeq.getConstArray(); - rtl::OUString const * const pEnd = pBegin + aSeq.getLength(); - - rtl::OUString const * const pSpace = std::find_if(pBegin,pEnd,HasSubString(_aSubStr)); - - return pSpace != pEnd; -} -// ----------------------------------------------------------------------------- - - -template <class Element_> -struct IsEmptySequence -{ - bool operator()(uno::Sequence<Element_> const & aSeq) const - { - return aSeq.getLength() == 0; - } -}; -// ----------------------------------------------------------------------------- - -template <class Element_> -bool hasEmptySequence(uno::Sequence< uno::Sequence<Element_> > const & aSeqSeq) -{ - // BACK: true, if whitespace Separator is ok, (no whitespace in Strings, no empty strings) - uno::Sequence<Element_> const * const pBegin = aSeqSeq.getConstArray(); - uno::Sequence<Element_> const * const pEnd = pBegin + aSeqSeq.getLength(); - - uno::Sequence<Element_> const * const pEmpty = std::find_if(pBegin, pEnd, IsEmptySequence<Element_>() ); - - return pEmpty != pEnd; -} -// ----------------------------------------------------------------------------- - -inline -bool canUseSeparator(uno::Sequence< rtl::OUString > const & aSeq, rtl::OUString const & aSeparator) -{ - return ! hasStringWithSubstring(aSeq,aSeparator); -} -// ----------------------------------------------------------------------------- - -inline -bool canUseWhitespaceSeparator(uno::Sequence< rtl::OUString > const & aSeq) -{ - return ! hasWhitespaceString(aSeq); -} -// ----------------------------------------------------------------------------- - -template <class Element_> -inline -bool canUseWhitespaceSeparator(const uno::Sequence< uno::Sequence<Element_> > &aSeq) -{ - return ! hasEmptySequence(aSeq); -} -// ----------------------------------------------------------------------------- - -class Separator -{ - rtl::OUString m_sValue; -public: - // ----------------------------------------------------------------------------- - Separator() : m_sValue() {} - // ----------------------------------------------------------------------------- - bool isDefault() const { return m_sValue.getLength() == 0; } - // ----------------------------------------------------------------------------- - rtl::OUString value() const { return isDefault() ? static_cast<rtl::OUString>(SEPARATOR_WHITESPACE) : m_sValue; } - // ----------------------------------------------------------------------------- - - bool check(const uno::Sequence<rtl::OUString> &aSeq) const - { - return isDefault() ? canUseWhitespaceSeparator(aSeq) : canUseSeparator(aSeq, m_sValue); - } - - // ----------------------------------------------------------------------------- - bool trySeparator(rtl::OUString const& sSep, const uno::Sequence<rtl::OUString> & aSeq) - { - OSL_ENSURE( ! isWhitespaceString(sSep), "There should be no spaces in non-default separators"); - // BACK: true, if Separator is ok, not in Strings - if (!canUseSeparator(aSeq, sSep)) - return false; - this->setSeparator(sSep); - return true; - } - // ----------------------------------------------------------------------------- - void setSeparator(rtl::OUString const& sSep) - { - m_sValue = sSep; - } - // ----------------------------------------------------------------------------- -}; -// ----------------------------------------------------------------------------- -#define ASCII( STRING_LIT_ ) ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STRING_LIT_ ) ) ) -// ----------------------------------------------------------------------------- -static -Separator createSeparator(const uno::Any& aAny) -{ - Separator aResult; - - // create a Separator which isn't in any value - if (aAny.getValueTypeClass() == uno::TypeClass_SEQUENCE) - { - uno::Type aElementType = configmgr::getSequenceElementType(aAny.getValueType()); - if (aElementType.getTypeClass() == uno::TypeClass_STRING) - { - // only in strings we need to search a separator - uno::Sequence<rtl::OUString> aSeq; - - OSL_VERIFY (aAny >>= aSeq); - - bool bValidSeparator = - canUseWhitespaceSeparator(aSeq) || - aResult.trySeparator(ASCII(","), aSeq) || - aResult.trySeparator(ASCII(";"), aSeq) || - aResult.trySeparator(ASCII(":"), aSeq) || - aResult.trySeparator(ASCII("|"), aSeq) || - aResult.trySeparator(ASCII("#"), aSeq) || - aResult.trySeparator(ASCII("-#*=+#-"), aSeq); - - if (!bValidSeparator) - { - OSL_TRACE("ERROR: configuration formatter: Could not create Separator for string list"); - OSL_ENSURE(false, "ERROR: Could not create Separator for string list"); - } - else - { - // maybe the whitespace test was invalid ? - OSL_ENSURE(aResult.check(aSeq), "Found Separator does not pass check ?!"); - } - } - else if (aElementType == SimpleTypeHelper::getBinaryType()) - { - // only in strings we need to search a separator - uno::Sequence< uno::Sequence<sal_Int8> > aSeq; - OSL_VERIFY(aAny >>= aSeq); - - if (!canUseWhitespaceSeparator(aSeq)) - { - aResult.setSeparator( ASCII(":") ); - } - } - } - - // DefaultSeparator - return aResult; -} -#undef ASCII -// ----------------------------------------------------------------------------- -static -inline -sal_Unicode hexNibble(sal_uInt8 _nNibble) -{ - OSL_ASSERT(_nNibble <= 0x0F); - - const sal_uInt8 cDecOffset = sal_uInt8('0'); - const sal_uInt8 cHexOffset = sal_uInt8('a') - 10; - - return _nNibble + (_nNibble<10 ? cDecOffset : cHexOffset); -} - -// ----------------------------------------------------------------------------- -static -inline -void appendHex(rtl::OUStringBuffer& rBuff, sal_uInt8 _nByte) -{ - rBuff.append( hexNibble(_nByte >> 4) ); - rBuff.append( hexNibble(_nByte & 0x0f) ); -} - -// ----------------------------------------------------------------------------- -static -rtl::OUString binaryToHex(const uno::Sequence<sal_Int8>& _aBinarySeq) -{ - sal_Int32 const nLength = _aBinarySeq.getLength(); - - rtl::OUStringBuffer sHex(2*nLength); - - for (sal_Int32 nPos = 0;nPos < nLength; ++nPos) - { - appendHex( sHex, _aBinarySeq[nPos] ); - } - - OSL_ASSERT(sHex.getLength() == 2*nLength); - return sHex.makeStringAndClear();; -} -// ----------------------------------------------------------------------------- -rtl::OUString formatSimpleValue(uno::Any const & _aValue, uno::Reference< script::XTypeConverter > const & _xTCV) -{ - rtl::OUString sResult; - - if (_aValue.hasValue()) - { - if (_aValue .getValueType() == SimpleTypeHelper::getBinaryType()) - { - uno::Sequence<sal_Int8> aBinarySeq; - - OSL_VERIFY(_aValue >>= aBinarySeq); - - sResult = binaryToHex(aBinarySeq); - } - else - { - // cannot have nested any - OSL_ASSERT(_aValue.getValueTypeClass() != uno::TypeClass_ANY); - - sResult = toString(_xTCV, _aValue); - } - } - return sResult; -} - -// ----------------------------------------------------------------------------- -template <class Element_> -rtl::OUString formatSequence(uno::Sequence< Element_ > const& aSequence, rtl::OUString const& sSeparator, uno::Reference< script::XTypeConverter > const & _xTCV) -{ - rtl::OUStringBuffer aResult; - - if (sal_Int32 const nLength = aSequence.getLength()) - { - Element_ const * pSeq = aSequence.getConstArray(); - - aResult = formatSimpleValue( uno::makeAny(pSeq[0]),_xTCV); - - for(sal_Int32 i=1; i<nLength; ++i) - { - aResult.append( sSeparator ); - aResult.append( formatSimpleValue(uno::makeAny(pSeq[i]),_xTCV) ); - } - } - - return aResult.makeStringAndClear(); -} -// ----------------------------------------------------------------------------- -// template <> // optimized overload for String -rtl::OUString formatSequence(uno::Sequence< rtl::OUString > const& aSequence, rtl::OUString const& sSeparator, uno::Reference< script::XTypeConverter > const & ) -{ - rtl::OUStringBuffer aResult; - - if (sal_Int32 const nLength = aSequence.getLength()) - { - rtl::OUString const * pSeq = aSequence.getConstArray(); - - aResult = pSeq[0]; - - for(sal_Int32 i=1; i<nLength; ++i) - { - aResult.append( sSeparator ).append( pSeq[i] ); - } - } - - return aResult.makeStringAndClear(); -} - -// ----------------------------------------------------------------------------- - -#define CASE_WRITE_SEQUENCE(TYPE_CLASS, DATA_TYPE) \ - case TYPE_CLASS: \ - { \ - uno::Sequence< DATA_TYPE > aData; \ - OSL_ENSURE( ::getCppuType(static_cast< DATA_TYPE const*>(0)).getTypeClass() == (TYPE_CLASS), \ - "Usage Error for CASE_WRITE_SEQUENCE: Type extracted does not match type class"); \ - OSL_VERIFY( _aValue >>= aData ); \ - aResult = formatSequence(aData,sSeparator,xTCV); \ - } break \ - -rtl::OUString formatSequenceValue(uno::Any const& _aValue, rtl::OUString const& sSeparator, uno::Reference< script::XTypeConverter > const & xTCV) -{ - rtl::OUString aResult; - - uno::Type aElementType = getSequenceElementType( _aValue.getValueType() ); - - switch(aElementType.getTypeClass()) - { - CASE_WRITE_SEQUENCE( uno::TypeClass_BOOLEAN, sal_Bool ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_SHORT, sal_Int16 ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_LONG, sal_Int32 ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_HYPER, sal_Int64 ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_DOUBLE, double ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_STRING, rtl::OUString ); - - CASE_WRITE_SEQUENCE( uno::TypeClass_SEQUENCE, uno::Sequence<sal_Int8> ); - - default: - OSL_ENSURE(false, "Unexpected typeclass for sequence elements"); - break; - } - - return aResult; -} - -#undef CASE_WRITE_SEQUENCE -// ----------------------------------------------------------------------------- -} // anonymous namspace -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -static inline bool isListVal(uno::Any const & _aValue) -{ - bool bList = false; - if (_aValue.hasValue()) - { - getBasicType(_aValue.getValueType(),bList); - } - return bList; -} -// ----------------------------------------------------------------------------- -void ValueFormatter::makeSeparator() -{ - if (isListVal(m_aValue)) - { - Separator aSeparator = createSeparator(m_aValue); - - m_sSeparator = aSeparator.value(); - m_bUseSeparator = !aSeparator.isDefault(); - - OSL_POSTCOND( this->isList() , "ValueFormatter: Could not mark as list"); - } - else - { - m_sSeparator = rtl::OUString(); - m_bUseSeparator = false; - - OSL_POSTCOND( !this->isList(), "ValueFormatter: Could not mark as non-list"); - } -} -// ----------------------------------------------------------------------------- - -rtl::OUString ValueFormatter::getContent(uno::Reference< script::XTypeConverter > const & _xTCV) const -{ - rtl::OUString aResult; - try - { - if (this->isList()) - { - aResult = formatSequenceValue(m_aValue, m_sSeparator, _xTCV); - } - else - { - aResult = formatSimpleValue(m_aValue, _xTCV); - } - } - catch (script::CannotConvertException& cce) - { - rtl::OUString const sMessage(RTL_CONSTASCII_USTRINGPARAM("Configuration: Could not convert value to XML representation: ")); - throw uno::RuntimeException(sMessage + cce.Message, cce.Context); - } - - return aResult; -} -// ----------------------------------------------------------------------------- - -bool ValueFormatter::addValueAttributes(ElementFormatter & _rFormatter) const -{ - // do we have a NULL value - if (!m_aValue.hasValue()) - { - _rFormatter.addIsNull(); - return false; - } - - // create a sequence separator - if (m_bUseSeparator) - { - OSL_ASSERT(this->isList()); - _rFormatter.addSeparator(m_sSeparator); - } - - return true; -} -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -} // namespace xml - -// ----------------------------------------------------------------------------- -} // namespace configmgr - - diff --git a/configmgr/source/xml/valueformatter.hxx b/configmgr/source/xml/valueformatter.hxx deleted file mode 100644 index 2b1f30b0fef7..000000000000 --- a/configmgr/source/xml/valueformatter.hxx +++ /dev/null @@ -1,84 +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: valueformatter.hxx,v $ - * $Revision: 1.4 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_VALUEFORMATTER_HXX -#define CONFIGMGR_XML_VALUEFORMATTER_HXX - -#include <com/sun/star/script/XTypeConverter.hpp> - -namespace configmgr -{ -// ----------------------------------------------------------------------------- - namespace xml - { -// ----------------------------------------------------------------------------- - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - namespace script= ::com::sun::star::script; -// ----------------------------------------------------------------------------- - class ElementFormatter; -// ----------------------------------------------------------------------------- - - // Value to XML (String) conversions - class ValueFormatter - { - public: - explicit - ValueFormatter(uno::Any const & _aValue) - : m_aValue(_aValue) - { - makeSeparator(); - } - - void reset(uno::Any const & _aValue) - { m_aValue = _aValue; makeSeparator(); } - - bool addValueAttributes(ElementFormatter & _rFormatter) const; - - bool hasContent() const; - - rtl::OUString getContent(uno::Reference< script::XTypeConverter > const & _xTCV) const; - - private: - bool isList() const { return m_sSeparator.getLength() != 0; } - void makeSeparator(); - - uno::Any m_aValue; - rtl::OUString m_sSeparator; - bool m_bUseSeparator; - }; -// ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- - } -// ----------------------------------------------------------------------------- -} // namespace - -#endif diff --git a/configmgr/source/xml/writersvc.cxx b/configmgr/source/xml/writersvc.cxx deleted file mode 100644 index 454549c00c50..000000000000 --- a/configmgr/source/xml/writersvc.cxx +++ /dev/null @@ -1,261 +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: writersvc.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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "writersvc.hxx" - -#ifndef CONFIGMGR_API_FACTORY_HXX_ -#include "confapifactory.hxx" -#endif -#include <com/sun/star/configuration/backend/XLayerHandler.hpp> -#include <com/sun/star/lang/WrappedTargetException.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> - -// ----------------------------------------------------------------------------- - -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 <class BackendInterface> -struct WriterServiceTraits; -// ----------------------------------------------------------------------------- -static inline void clear(rtl::OUString & _rs) { _rs = rtl::OUString(); } - -// ----------------------------------------------------------------------------- -template <class BackendInterface> -WriterService<BackendInterface>::WriterService(uno::Reference< uno::XComponentContext > const & _xContext) -: m_xServiceFactory(_xContext->getServiceManager(), uno::UNO_QUERY) -, m_xWriter() -{ - if (!m_xServiceFactory.is()) - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration XML Writer: Context has no service manager")); - throw uno::RuntimeException(sMessage,NULL); - } -} -// ----------------------------------------------------------------------------- - -// XInitialization -template <class BackendInterface> -void SAL_CALL - WriterService<BackendInterface>::initialize( const uno::Sequence< uno::Any >& aArguments ) - throw (uno::Exception, uno::RuntimeException) -{ - switch(aArguments.getLength()) - { - case 0: - { - break; - } - - case 1: - { - if (aArguments[0] >>= m_xWriter) - break; - - uno::Reference< io::XOutputStream > xStream; - - if (aArguments[0] >>= xStream) - { - this->setOutputStream(xStream); - break; - } - - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Cannot use argument to initialize a Configuration XML Writer" - "- SAX XDocumentHandler or XOutputStream 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 <class BackendInterface> -inline -ServiceInfoHelper WriterService<BackendInterface>::getServiceInfo() -{ - return WriterServiceTraits<BackendInterface>::getServiceInfo(); -} -// ----------------------------------------------------------------------------- - -// XServiceInfo -template <class BackendInterface> -::rtl::OUString SAL_CALL - WriterService<BackendInterface>::getImplementationName( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getImplementationName( ); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -sal_Bool SAL_CALL - WriterService<BackendInterface>::supportsService( const ::rtl::OUString& ServiceName ) - throw (uno::RuntimeException) -{ - return getServiceInfo().supportsService( ServiceName ); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -uno::Sequence< ::rtl::OUString > SAL_CALL - WriterService<BackendInterface>::getSupportedServiceNames( ) - throw (uno::RuntimeException) -{ - return getServiceInfo().getSupportedServiceNames( ); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -void SAL_CALL - WriterService<BackendInterface>::setOutputStream( const uno::Reference< io::XOutputStream >& aStream ) - throw (uno::RuntimeException) -{ - uno::Reference< io::XActiveDataSource > xDS( m_xWriter, uno::UNO_QUERY ); - - if (xDS.is()) - { - xDS->setOutputStream(aStream); - } - else - { - uno::Reference< sax::XDocumentHandler > xNewHandler = this->createHandler(); - - xDS.set( xNewHandler, uno::UNO_QUERY ); - if (!xDS.is()) - { - rtl::OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration XML Writer: Cannot set output stream to sax.Writer - missing interface XActiveDataSource.")); - throw uno::RuntimeException(sMessage,*this); - } - xDS->setOutputStream(aStream); - - m_xWriter = xNewHandler; - } -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -uno::Reference< io::XOutputStream > SAL_CALL - WriterService<BackendInterface>::getOutputStream( ) - throw (uno::RuntimeException) -{ - uno::Reference< io::XActiveDataSource > xDS( m_xWriter, uno::UNO_QUERY ); - - return xDS.is()? xDS->getOutputStream() : uno::Reference< io::XOutputStream >(); -} -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -uno::Reference< sax::XDocumentHandler > WriterService<BackendInterface>::getWriteHandler() - throw (uno::RuntimeException) -{ - if (!m_xWriter.is()) - m_xWriter = this->createHandler(); - - return m_xWriter; -} - -// ----------------------------------------------------------------------------- - -template <class BackendInterface> -uno::Reference< sax::XDocumentHandler > WriterService<BackendInterface>::createHandler() const - throw (uno::RuntimeException) -{ - try - { - static rtl::OUString const k_sSaxWriterSvc( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ); - - return uno::Reference< sax::XDocumentHandler >::query( getServiceFactory()->createInstance(k_sSaxWriterSvc) ); - } - catch (uno::RuntimeException& ) { throw; } - catch (uno::Exception& e) - { - lang::XInitialization * const pThis = const_cast<WriterService *>(this); - throw lang::WrappedTargetRuntimeException(e.Message, pThis, uno::makeAny(e)); - } -} - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -sal_Char const * const aLayerWriterServices[] = -{ - "com.sun.star.configuration.backend.xml.LayerWriter", - 0 -}; -extern // needed by SunCC 5.2, if used from template -const ServiceImplementationInfo aLayerWriterSI = -{ - "com.sun.star.comp.configuration.backend.xml.LayerWriter", - aLayerWriterServices, - 0 -}; -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -template <> -struct WriterServiceTraits< backenduno::XLayerHandler > -{ - static ServiceImplementationInfo const * getServiceInfo() - { return & aLayerWriterSI; } -}; -// ----------------------------------------------------------------------------- - -const ServiceRegistrationInfo* getLayerWriterServiceInfo() -{ return getRegistrationInfo(& aLayerWriterSI); } -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - -// instantiate here ! -template class WriterService< backenduno::XLayerHandler >; - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - } // namespace - -// ----------------------------------------------------------------------------- -} // namespace - diff --git a/configmgr/source/xml/writersvc.hxx b/configmgr/source/xml/writersvc.hxx deleted file mode 100644 index a8bddb24b8cb..000000000000 --- a/configmgr/source/xml/writersvc.hxx +++ /dev/null @@ -1,124 +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: writersvc.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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef CONFIGMGR_XML_WRITERSVC_HXX -#define CONFIGMGR_XML_WRITERSVC_HXX - -#include "serviceinfohelper.hxx" -#include <cppuhelper/implbase4.hxx> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/io/XActiveDataSource.hpp> -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> - -// ----------------------------------------------------------------------------- - -namespace com { namespace sun { namespace star { namespace configuration { namespace backend { - class XLayerHandler; -} } } } } - -// ----------------------------------------------------------------------------- - -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 BackendInterface> - class WriterService : public ::cppu::WeakImplHelper4< - lang::XInitialization, - lang::XServiceInfo, - io::XActiveDataSource, - BackendInterface - > - { - public: - explicit - WriterService(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 - setOutputStream( const uno::Reference< io::XOutputStream >& aStream ) - throw (uno::RuntimeException); - - virtual uno::Reference< io::XOutputStream > SAL_CALL - getOutputStream( ) - throw (uno::RuntimeException); - - protected: - uno::Reference< lang::XMultiServiceFactory > getServiceFactory() const - { return m_xServiceFactory; } - - uno::Reference< sax::XDocumentHandler > getWriteHandler() throw (uno::RuntimeException); - private: - uno::Reference< lang::XMultiServiceFactory > m_xServiceFactory; - uno::Reference< sax::XDocumentHandler > m_xWriter; - - uno::Reference< sax::XDocumentHandler > createHandler() const throw (uno::RuntimeException); - - static ServiceInfoHelper getServiceInfo(); - }; - -// ----------------------------------------------------------------------------- - } // namespace xml -// ----------------------------------------------------------------------------- - -} // namespace configmgr -#endif - - - - diff --git a/configmgr/source/xml/xmlstrings.cxx b/configmgr/source/xml/xmlstrings.cxx deleted file mode 100644 index 06b223300659..000000000000 --- a/configmgr/source/xml/xmlstrings.cxx +++ /dev/null @@ -1,140 +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: xmlstrings.cxx,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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "xmlstrings.hxx" - -//......................................................................... -namespace configmgr -{ -//......................................................................... - - namespace xml - { -//---------------------------------------------------------------------------- -// For now: Include the fixed OOR prefix into (most) attribute names -#define OOR_PREFIX_ "oor:" -// ... but not into (most) tag names -#define OOR_TAG_PREFIX_ -// ... but into root tag names -#define OOR_ROOTTAG_PREFIX_ OOR_PREFIX_ -//---------------------------------------------------------------------------- - // extern declaration for strings used in the XML format - // namespace prefixes - IMPLEMENT_CONSTASCII_USTRING(NS_PREFIX_OOR, "oor"); - IMPLEMENT_CONSTASCII_USTRING(NS_PREFIX_XS, "xs"); - - // namespace urls - IMPLEMENT_CONSTASCII_USTRING(NS_URI_OOR,"http://openoffice.org/2001/registry"); - IMPLEMENT_CONSTASCII_USTRING(NS_URI_XS, "http://www.w3.org/2001/XMLSchema"); - - // tag names - IMPLEMENT_CONSTASCII_USTRING(TAG_SCHEMA, OOR_ROOTTAG_PREFIX_"component-schema"); - IMPLEMENT_CONSTASCII_USTRING(TAG_LAYER, OOR_ROOTTAG_PREFIX_"component-data"); - IMPLEMENT_CONSTASCII_USTRING(DEPRECATED_TAG_LAYER, OOR_ROOTTAG_PREFIX_"node"); - - IMPLEMENT_CONSTASCII_USTRING(TAG_COMPONENT, OOR_TAG_PREFIX_"component"); - IMPLEMENT_CONSTASCII_USTRING(TAG_TEMPLATES, OOR_TAG_PREFIX_"templates"); - - IMPLEMENT_CONSTASCII_USTRING(TAG_NODE, OOR_TAG_PREFIX_"node"); - IMPLEMENT_CONSTASCII_USTRING(TAG_GROUP, OOR_TAG_PREFIX_"group"); - IMPLEMENT_CONSTASCII_USTRING(TAG_SET, OOR_TAG_PREFIX_"set"); - IMPLEMENT_CONSTASCII_USTRING(TAG_PROP, OOR_TAG_PREFIX_"prop"); - - IMPLEMENT_CONSTASCII_USTRING(TAG_VALUE, OOR_TAG_PREFIX_"value"); - IMPLEMENT_CONSTASCII_USTRING(TAG_IMPORT, OOR_TAG_PREFIX_"import"); - IMPLEMENT_CONSTASCII_USTRING(TAG_INSTANCE, OOR_TAG_PREFIX_"node-ref"); - IMPLEMENT_CONSTASCII_USTRING(TAG_ITEMTYPE, OOR_TAG_PREFIX_"item"); - IMPLEMENT_CONSTASCII_USTRING(TAG_USES, OOR_TAG_PREFIX_"uses"); - - // attribute names - IMPLEMENT_CONSTASCII_USTRING(ATTR_NAME, OOR_PREFIX_"name"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_CONTEXT, OOR_PREFIX_"context"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_PACKAGE, OOR_PREFIX_"package"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_COMPONENT,OOR_PREFIX_"component"); - - IMPLEMENT_CONSTASCII_USTRING(ATTR_ITEMTYPE, OOR_PREFIX_"node-type"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_ITEMTYPECOMPONENT,OOR_PREFIX_"component"); - - IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUETYPE, OOR_PREFIX_"type"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUESEPARATOR, OOR_PREFIX_"separator"); - - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_EXTENSIBLE, OOR_PREFIX_"extensible"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_FINALIZED, OOR_PREFIX_"finalized"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_READONLY, OOR_PREFIX_"readonly"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_MANDATORY, OOR_PREFIX_"mandatory"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_NULLABLE, OOR_PREFIX_"nillable"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_FLAG_LOCALIZED, OOR_PREFIX_"localized"); - - IMPLEMENT_CONSTASCII_USTRING(ATTR_OPERATION, OOR_PREFIX_"op"); - - // attributes defined elsewhere - IMPLEMENT_CONSTASCII_USTRING(EXT_ATTR_LANGUAGE, "xml:lang"); - IMPLEMENT_CONSTASCII_USTRING(EXT_ATTR_NULL, "xsi:nil"); - - // attribute contents - // boolean constants - IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_TRUE, "true"); - IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_FALSE, "false"); - - // simple types names - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_BOOLEAN, "boolean"); - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_SHORT, "short"); - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_INT, "int"); - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_LONG, "long"); - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_DOUBLE, "double"); - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_STRING, "string"); - // Type: Sequence<bytes> - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_BINARY, "hexBinary"); - // Universal type: Any - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_ANY, "any"); - - // modifier suffix for list types - IMPLEMENT_CONSTASCII_USTRING(VALUETYPE_LIST_SUFFIX, "-list"); - - // States for update actions - IMPLEMENT_CONSTASCII_USTRING(OPERATION_MODIFY, "modify"); - IMPLEMENT_CONSTASCII_USTRING(OPERATION_REPLACE, "replace"); - IMPLEMENT_CONSTASCII_USTRING(OPERATION_FUSE, "fuse"); - IMPLEMENT_CONSTASCII_USTRING(OPERATION_REMOVE, "remove"); - - // the default separator for strings - IMPLEMENT_CONSTASCII_USTRING(SEPARATOR_WHITESPACE, " "); - - // Needed for building attribute lists - IMPLEMENT_CONSTASCII_USTRING(XML_ATTRTYPE_CDATA, "CDATA"); - - } // namespace xml - -} // namespace configmgr - - diff --git a/configmgr/source/xml/xmlstrings.hxx b/configmgr/source/xml/xmlstrings.hxx deleted file mode 100644 index a81d31e3fede..000000000000 --- a/configmgr/source/xml/xmlstrings.hxx +++ /dev/null @@ -1,134 +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: xmlstrings.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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef CONFIGMGR_XML_STRINGS_HXX_ -#define CONFIGMGR_XML_STRINGS_HXX_ - -#include "strings.hxx" - -//......................................................................... -namespace configmgr -{ -//......................................................................... - - namespace xml - { - // extern declaration for strings used in the XML format - // namespace prefixes - DECLARE_CONSTASCII_USTRING(NS_PREFIX_OOR); - DECLARE_CONSTASCII_USTRING(NS_PREFIX_XS); - - const sal_Unicode k_NS_SEPARATOR(':'); - - // namespace urls - DECLARE_CONSTASCII_USTRING(NS_URI_OOR); - DECLARE_CONSTASCII_USTRING(NS_URI_XS); - DECLARE_CONSTASCII_USTRING(NS_URI_XSI); - - // tag names - DECLARE_CONSTASCII_USTRING(TAG_SCHEMA); - DECLARE_CONSTASCII_USTRING(TAG_LAYER); - DECLARE_CONSTASCII_USTRING(DEPRECATED_TAG_LAYER); - - DECLARE_CONSTASCII_USTRING(TAG_COMPONENT); - DECLARE_CONSTASCII_USTRING(TAG_TEMPLATES); - - DECLARE_CONSTASCII_USTRING(TAG_NODE); - DECLARE_CONSTASCII_USTRING(TAG_GROUP); - DECLARE_CONSTASCII_USTRING(TAG_SET); - DECLARE_CONSTASCII_USTRING(TAG_PROP); - - DECLARE_CONSTASCII_USTRING(TAG_IMPORT); - DECLARE_CONSTASCII_USTRING(TAG_INSTANCE); - DECLARE_CONSTASCII_USTRING(TAG_ITEMTYPE); - DECLARE_CONSTASCII_USTRING(TAG_VALUE); - DECLARE_CONSTASCII_USTRING(TAG_USES); - - // attribute names - DECLARE_CONSTASCII_USTRING(ATTR_NAME); - DECLARE_CONSTASCII_USTRING(ATTR_CONTEXT); - DECLARE_CONSTASCII_USTRING(ATTR_PACKAGE); - DECLARE_CONSTASCII_USTRING(ATTR_COMPONENT); - - DECLARE_CONSTASCII_USTRING(ATTR_ITEMTYPE); - DECLARE_CONSTASCII_USTRING(ATTR_ITEMTYPECOMPONENT); - - DECLARE_CONSTASCII_USTRING(ATTR_VALUETYPE); - DECLARE_CONSTASCII_USTRING(ATTR_VALUESEPARATOR); - - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_EXTENSIBLE); - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_FINALIZED); - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_READONLY); - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_MANDATORY); - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_NULLABLE); - DECLARE_CONSTASCII_USTRING(ATTR_FLAG_LOCALIZED); - - DECLARE_CONSTASCII_USTRING(ATTR_OPERATION); - - // attributes defined elsewhere - DECLARE_CONSTASCII_USTRING(EXT_ATTR_LANGUAGE); - DECLARE_CONSTASCII_USTRING(EXT_ATTR_NULL); - - // attribute contents - // boolean constants - DECLARE_CONSTASCII_USTRING(ATTR_VALUE_TRUE); - DECLARE_CONSTASCII_USTRING(ATTR_VALUE_FALSE); - - // simple types names - DECLARE_CONSTASCII_USTRING(VALUETYPE_BOOLEAN); - DECLARE_CONSTASCII_USTRING(VALUETYPE_SHORT); - DECLARE_CONSTASCII_USTRING(VALUETYPE_INT); - DECLARE_CONSTASCII_USTRING(VALUETYPE_LONG); - DECLARE_CONSTASCII_USTRING(VALUETYPE_DOUBLE); - DECLARE_CONSTASCII_USTRING(VALUETYPE_STRING); - // Type: Sequence<bytes> - DECLARE_CONSTASCII_USTRING(VALUETYPE_BINARY); - // Universal type: Any - DECLARE_CONSTASCII_USTRING(VALUETYPE_ANY); - - // modifier suffix for list types - DECLARE_CONSTASCII_USTRING(VALUETYPE_LIST_SUFFIX); - - // States for update actions - DECLARE_CONSTASCII_USTRING(OPERATION_MODIFY); - DECLARE_CONSTASCII_USTRING(OPERATION_REPLACE); - DECLARE_CONSTASCII_USTRING(OPERATION_FUSE); - DECLARE_CONSTASCII_USTRING(OPERATION_REMOVE); - - // the default separator for strings - DECLARE_CONSTASCII_USTRING(SEPARATOR_WHITESPACE); - - // Needed for building attribute lists - DECLARE_CONSTASCII_USTRING(XML_ATTRTYPE_CDATA); - - } // namespace xml - -} // namespace configmgr -#endif - |