diff --git a/configmgr/source/xml/elementformatter.cxx b/configmgr/source/xml/elementformatter.cxx new file mode 100644 index 000000000000..515dc62e0cbf --- /dev/null +++ b/configmgr/source/xml/elementformatter.cxx @@ -0,0 +1,403 @@ +/************************************************************************* + * + * $RCSfile: elementformatter.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "elementformatter.hxx" + +#ifndef CONFIGMGR_XML_STRINGS_HXX_ +#include "xmlstrings.hxx" +#endif + +#ifndef CONFIGMGR_TYPECONVERTER_HXX +#include "typeconverter.hxx" +#endif +#ifndef CONFIGMGR_MISC_ATTRIBUTELIST_HXX +#include "attributelist.hxx" +#endif + +#ifndef _RTL_USTRBUF_HXX_ +#include +#endif + +#include +#include + +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +ElementFormatter::ElementFormatter() +: m_aElementType(ElementType::unknown) +, m_xAttributes() +{ +} +// ----------------------------------------------------------------------------- + +ElementFormatter::~ElementFormatter() +{ +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::reset() +{ + m_aElementType = ElementType::unknown; + m_xAttributes.clear(); +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::addAttribute(OUString const & _anAttributeName, 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(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 OUString const sNamespaceDecl( RTL_CONSTASCII_USTRINGPARAM("xmlns:") ); + + addAttribute( sNamespaceDecl.concat(NS_PREFIX_OOR), NS_URI_OOR); + addAttribute( sNamespaceDecl.concat(NS_PREFIX_XS ), NS_URI_XS ); +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::prepareElement(ElementInfo const& _aInfo) +{ + if (!m_xAttributes.is()) + { + m_xAttributes.set( new AttributeListImpl() ); + addNamespaces(); + } + else + m_xAttributes->clear(); + + m_aElementType = _aInfo.type; + + addName(_aInfo.name); + addNodeFlags(_aInfo.flags); + addOperation(_aInfo.op); +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::addName(OUString const & _aName) +{ + // TODO: split off package part to ATTR_CONTEXT (?) + + if (_aName.getLength()) addAttribute(ATTR_NAME, _aName); +} +// ----------------------------------------------------------------------------- + +inline +void ElementFormatter::maybeAddFlag(FlagsType _eFlags, FlagsType _eSelect, OUString const & _anAttributeName, bool _bValue) +{ + if (_eFlags & _eSelect) addAttribute(_anAttributeName,_bValue); +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::addNodeFlags(FlagsType _eFlags) +{ + using namespace drafts::com::sun::star::configuration::backend;; + + maybeAddFlag(_eFlags,SchemaAttribute::REQUIRED, ATTR_FLAG_NULLABLE, false); + maybeAddFlag(_eFlags,SchemaAttribute::LOCALIZED, ATTR_FLAG_LOCALIZED); + maybeAddFlag(_eFlags,SchemaAttribute::EXTENSIBLE, ATTR_FLAG_EXTENSIBLE); + + maybeAddFlag(_eFlags,NodeAttribute::FINALIZED, ATTR_FLAG_FINALIZED); + maybeAddFlag(_eFlags,NodeAttribute::MANDATORY, ATTR_FLAG_MANDATORY); + maybeAddFlag(_eFlags,NodeAttribute::READONLY, ATTR_FLAG_READONLY); +} +// ----------------------------------------------------------------------------- + +void ElementFormatter::addOperation(Operation::Enum _eOp) +{ + switch (_eOp) + { + case Operation::none: break; + case Operation::modify: addAttribute(ATTR_OPERATION, OPERATION_MODIFY); break; + case Operation::replace: addAttribute(ATTR_OPERATION, OPERATION_REPLACE); break; + case Operation::remove: addAttribute(ATTR_OPERATION, 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(OUString const & _aElementType, OUString const & _aElementTypeModule) +{ +} +// ----------------------------------------------------------------------------- + +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(); + OUString aSimpleTypeName = toTypeName(aSimpleTypeClass); + + OUString sNsPrefix = (bList || aSimpleTypeClass == uno::TypeClass_ANY) ? NS_PREFIX_OOR : 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(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(OUString const& _sSeparator) +{ + addAttribute( ATTR_VALUESEPARATOR, _sSeparator); +} +// ----------------------------------------------------------------------------- + +OUString ElementFormatter::getElementTag() const +{ + switch (m_aElementType) + { + case ElementType::schema: return TAG_SCHEMA; + + case ElementType::component: return TAG_COMPONENT; + case ElementType::templates: return TAG_TEMPLATES; + + case ElementType::property: return TAG_PROP; + case ElementType::node: return TAG_NODE; + case ElementType::group: return TAG_GROUP; + case ElementType::set: return TAG_SET; + + case ElementType::import: return TAG_IMPORT; + case ElementType::instance: return TAG_INSTANCE; + case ElementType::item_type: return TAG_ITEMTYPE; + case ElementType::value: return TAG_VALUE; + + 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 OUString(); +} +// ----------------------------------------------------------------------------- + +uno::Reference< sax::XAttributeList > ElementFormatter::getElementAttributes() const +{ + return m_xAttributes.get(); +} +// ----------------------------------------------------------------------------- + +#if 0 +/// retrieve data type of a property, +uno::Type ElementParser::getPropertyValueType(SaxAttributeList const& xAttribs) const +{ + OUString sTypeName; + if (!this->maybeGetAttribute(xAttribs, ATTR_VALUETYPE, sTypeName)) + return uno::Type(); // => VOID + + uno::Type aType; + + if (matchSuffix(sTypeName,VALUETYPE_LIST_SUFFIX)) + { + OUString sBasicName = stripTypeName( stripSuffix(sTypeName,VALUETYPE_LIST_SUFFIX), NS_PREFIX_OOR ); + + aType = toListType(sBasicName); + } + else + { + OUString sBasicName = stripTypeName( sTypeName, NS_PREFIX_OOR ); + + aType = toType(sBasicName); + } + + if (aType == uno::Type()) + badValueType("Unknown type name: ", sTypeName); + + return aType; +} +// ----------------------------------------------------------------------------- + +/// retrieve element type and associated module name of a set, +bool ElementParser::getSetElementType(SaxAttributeList const& xAttribs, OUString& aElementType, OUString& aElementTypeModule) const +{ + if (!this->maybeGetAttribute(xAttribs, ATTR_ITEMTYPE, aElementType)) + return false; + + maybeGetAttribute(xAttribs, ATTR_ITEMTYPECOMPONENT, aElementTypeModule); + + return true; +} +// ----------------------------------------------------------------------------- + +/// retrieve instance type and associated module name of a set, +bool ElementParser::getInstanceType(SaxAttributeList const& xAttribs, OUString& aElementType, OUString& aElementTypeModule) const +{ + if (!this->maybeGetAttribute(xAttribs, ATTR_ITEMTYPE, aElementType)) + return false; + + maybeGetAttribute(xAttribs, ATTR_ITEMTYPECOMPONENT, aElementTypeModule); + + return true; +} +// ----------------------------------------------------------------------------- + +/// retrieve the component for an import or uses element, +bool ElementParser::getImportComponent(SaxAttributeList const& xAttribs, OUString& _rsComponent) const +{ + return this->maybeGetAttribute(xAttribs, ATTR_COMPONENT, _rsComponent); +} +// ----------------------------------------------------------------------------- + +// low-level internal methods +/// checks for presence of a boolean attribute and assigns its value if it exists (and is a bool) +bool ElementParser::maybeGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, bool& rAttributeValue) const +{ + OUString sAttribute; + + if ( !this->maybeGetAttribute(xAttribs, aAttributeName, sAttribute) ) + { + return false; + } + + else if (sAttribute.equals(ATTR_VALUE_TRUE)) + rAttributeValue = true; // will return true + + else if (sAttribute.equals(ATTR_VALUE_FALSE)) + rAttributeValue = false; // will return true + + else + { + OSL_ENSURE(sAttribute.getLength() == 0, "Invalid text found in boolean attribute"); + return false; + } + + return true; +} +// ----------------------------------------------------------------------------- + +/// checks for presence of an attribute and assigns its value if it exists +bool ElementParser::maybeGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, OUString& rAttributeValue) const +{ + return xAttribs.is() && impl_maybeGetAttribute(xAttribs, aAttributeName, rAttributeValue); +} +// ----------------------------------------------------------------------------- + +/// assigns an attribute value or an empty string if it doesn't exist +void ElementParser::alwaysGetAttribute(SaxAttributeList const& xAttribs, OUString const& aAttributeName, OUString& rAttributeValue) const +{ + if (xAttribs.is()) + rAttributeValue = xAttribs->getValueByName(aAttributeName); + else + rAttributeValue = OUString(); +} +#endif +// ----------------------------------------------------------------------------- +} // namespace +} // namespace + diff --git a/configmgr/source/xml/elementformatter.hxx b/configmgr/source/xml/elementformatter.hxx new file mode 100644 index 000000000000..5e5b40ff0a1c --- /dev/null +++ b/configmgr/source/xml/elementformatter.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * $RCSfile: elementformatter.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_ELEMENTFORMATTER_HXX +#define CONFIGMGR_XML_ELEMENTFORMATTER_HXX + +#ifndef CONFIGMGR_XML_ELEMENTINFO_HXX +#include "elementinfo.hxx" +#endif + +#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_ +#include +#endif + +#include + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + class AttributeListImpl; +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; + + using rtl::OUString; + +// ----------------------------------------------------------------------------- + class ElementFormatter + { + public: + typedef uno::Reference< sax::XAttributeList > SaxAttributeList; + typedef ElementInfo::FlagsType FlagsType; + 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); + + /// sets the instantiated type of a set item, + void addInstanceType(OUString const & _aElementType, 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(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(OUString const& _sSeparator); + + /// retrieve the tag to use for the current element + OUString getElementTag() const; + + /// retrieve the attributes to use for the current element + SaxAttributeList getElementAttributes() const; + + /// retrieve the attributes to use for an element with associated component + private: + void addNamespaces(); + /// sets an attributes for a node + void addName(OUString const & _aName); + /// sets attributes for nodes from the flags + void addNodeFlags(FlagsType _eFlags); + /// sets attributes for nodes from the flags + void addOperation(Operation::Enum _eOp); + /// sets attributes for nodes from the flags + void maybeAddFlag(FlagsType _eFlags, FlagsType _eSelect, + OUString const & _anAttributeName, bool _bValue = true); + + /// sets attributes for nodes + void addAttribute(OUString const & _anAttributeName, OUString const & _aValue); + void addAttribute(OUString const & _anAttributeName, bool _bValue); + + private: + ElementType::Enum m_aElementType; + rtl::Reference m_xAttributes; + }; +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- +} // namespace configmgr + +#endif + diff --git a/configmgr/source/xml/layerwriter.cxx b/configmgr/source/xml/layerwriter.cxx new file mode 100644 index 000000000000..5581ccb45493 --- /dev/null +++ b/configmgr/source/xml/layerwriter.cxx @@ -0,0 +1,347 @@ +/************************************************************************* + * + * $RCSfile: layerwriter.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "layerwriter.hxx" + +#ifndef CONFIGMGR_API_FACTORY_HXX_ +#include "confapifactory.hxx" +#endif +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace sax = ::com::sun::star::xml::sax; +// ----------------------------------------------------------------------------- + +uno::Reference< uno::XInterface > SAL_CALL instantiateLayerWriter +( CreationContext const& rServiceManager ) +{ + return * new LayerWriter(rServiceManager); +} +// ----------------------------------------------------------------------------- + +LayerWriter::LayerWriter(ServiceFactory const & _xSvcFactory) +: LayerWriterService_Base(_xSvcFactory) +, m_bInProperty(false) +{ +} +// ----------------------------------------------------------------------------- + +LayerWriter::~LayerWriter() +{ +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::startLayer( ) + throw (backenduno::MalformedDataException, uno::RuntimeException) +{ + m_aFormatter.reset(); + m_bInProperty = false; + + checkInElement(false); + + getWriteHandler()->startDocument(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::endLayer( ) + throw (backenduno::MalformedDataException, lang::IllegalAccessException, uno::RuntimeException) +{ + checkInElement(false); + + getWriteHandler()->endDocument(); + m_aFormatter.reset(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::overrideNode( const OUString& aName, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException) +{ + ElementInfo aInfo(aName, ElementType::node); + aInfo.flags = aAttributes; + aInfo.op = Operation::modify; + + m_aFormatter.prepareElement(aInfo); + + this->startNode(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::addOrReplaceNode( const OUString& aName, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + ElementInfo aInfo(aName, ElementType::node); + aInfo.flags = aAttributes; + aInfo.op = Operation::replace; + + m_aFormatter.prepareElement(aInfo); + + this->startNode(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::addOrReplaceNodeFromTemplate( const OUString& aName, const backenduno::TemplateIdentifier& aTemplate, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, beans::IllegalTypeException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + ElementInfo aInfo(aName, ElementType::node); + aInfo.flags = aAttributes; + aInfo.op = Operation::replace; + + m_aFormatter.prepareElement(aInfo); + m_aFormatter.addInstanceType(aTemplate.Name,aTemplate.Component); + + this->startNode(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::endNode( ) + throw (backenduno::MalformedDataException, uno::RuntimeException) +{ + checkInElement(true); + this->endElement(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::dropNode( const OUString& aName ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + ElementInfo aInfo(aName, ElementType::node); + aInfo.flags = 0; + aInfo.op = Operation::remove; + + m_aFormatter.prepareElement(aInfo); + + this->startNode(); + this->endElement(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::addProperty( const OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) + throw (backenduno::MalformedDataException, beans::PropertyExistException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + 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(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::addPropertyWithValue( const OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue ) + throw (backenduno::MalformedDataException, beans::PropertyExistException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + 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(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::overrideProperty( const OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) + throw (backenduno::MalformedDataException, beans::UnknownPropertyException, beans::IllegalTypeException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true); + + ElementInfo aInfo(aName, ElementType::property); + aInfo.flags = aAttributes; + aInfo.op = Operation::modify; + + m_aFormatter.prepareElement(aInfo); + + this->startProp(aType, false); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::endProperty( ) + throw (backenduno::MalformedDataException, uno::RuntimeException) +{ + checkInElement(true,true); + this->endElement(); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::setPropertyValue( const uno::Any& aValue ) + throw (backenduno::MalformedDataException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true,true); + this->writeValue(aValue); +} +// ----------------------------------------------------------------------------- + +void SAL_CALL LayerWriter::setPropertyValueForLocale( const uno::Any& aValue, const OUString& aLocale ) + throw (backenduno::MalformedDataException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException) +{ + checkInElement(true,true); + this->writeValue(aValue,aLocale); +} +// ----------------------------------------------------------------------------- + +void LayerWriter::raiseMalformedDataException(sal_Char const * pMsg) +{ + OSL_ASSERT(pMsg); + OUString sMsg = OUString::createFromAscii(pMsg); + + throw backenduno::MalformedDataException( sMsg, *this ); +} +// ----------------------------------------------------------------------------- + +void LayerWriter::raiseIllegalTypeException(sal_Char const * pMsg) +{ + OSL_ASSERT(pMsg); + OUString sMsg = OUString::createFromAscii(pMsg); + + throw beans::IllegalTypeException( sMsg, *this ); +} +// ----------------------------------------------------------------------------- + +void LayerWriter::checkInElement(bool bInElement, bool bInProperty) +{ + if (bInElement != m_aTagStack.empty()) + { + 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() +{ + OUString sTag = m_aFormatter.getElementTag(); + getWriteHandler()->startElement(sTag,m_aFormatter.getElementAttributes()); + 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()); + m_aTagStack.pop(); + m_bInProperty = false; +} +// ----------------------------------------------------------------------------- + +void LayerWriter::writeValue(uno::Any const & _aValue) +{ +} +// ----------------------------------------------------------------------------- + +void LayerWriter::writeValue(uno::Any const & _aValue, OUString const & _aLocale) +{ +} +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + } // namespace + +// ----------------------------------------------------------------------------- +} // namespace + diff --git a/configmgr/source/xml/layerwriter.hxx b/configmgr/source/xml/layerwriter.hxx new file mode 100644 index 000000000000..7c26b2d614da --- /dev/null +++ b/configmgr/source/xml/layerwriter.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * $RCSfile: layerwriter.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_LAYERWRITER_HXX +#define CONFIGMGR_XML_LAYERWRITER_HXX + +#ifndef CONFIGMGR_XML_WRITERSVC_HXX +#include "writersvc.hxx" +#endif + +#ifndef CONFIGMGR_XML_ELEMENTFORMATTER_HXX +#include "elementformatter.hxx" +#endif + +#include + +#ifndef INCLUDED_STACK +#include +#define INCLUDED_STACK +#endif + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace lang = ::com::sun::star::lang; + namespace beans = ::com::sun::star::beans; + namespace container = ::com::sun::star::container; + + namespace sax = ::com::sun::star::xml::sax; + namespace backenduno = ::drafts::com::sun::star::configuration::backend; + +// ----------------------------------------------------------------------------- + + + class LayerWriter : public LayerWriterService_Base + { + public: + explicit + LayerWriter(ServiceFactory const & _xSvcFactory); + virtual ~LayerWriter(); + + // XLayerHandler + public: + virtual void SAL_CALL + startLayer( ) + throw (backenduno::MalformedDataException, uno::RuntimeException); + + virtual void SAL_CALL + endLayer( ) + throw (backenduno::MalformedDataException, lang::IllegalAccessException, uno::RuntimeException); + + virtual void SAL_CALL + overrideNode( const OUString& aName, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + addOrReplaceNode( const OUString& aName, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + addOrReplaceNodeFromTemplate( const OUString& aName, const backenduno::TemplateIdentifier& aTemplate, sal_Int16 aAttributes ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, beans::IllegalTypeException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + endNode( ) + throw (backenduno::MalformedDataException, uno::RuntimeException); + + virtual void SAL_CALL + dropNode( const OUString& aName ) + throw (backenduno::MalformedDataException, container::NoSuchElementException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + overrideProperty( const OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) + throw (backenduno::MalformedDataException, beans::UnknownPropertyException, beans::IllegalTypeException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + addProperty( const OUString& aName, sal_Int16 aAttributes, const uno::Type& aType ) + throw (backenduno::MalformedDataException, beans::PropertyExistException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + addPropertyWithValue( const OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue ) + throw (backenduno::MalformedDataException, beans::PropertyExistException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + endProperty( ) + throw (backenduno::MalformedDataException, uno::RuntimeException); + + virtual void SAL_CALL + setPropertyValue( const uno::Any& aValue ) + throw (backenduno::MalformedDataException, beans::IllegalTypeException, lang::IllegalArgumentException, uno::RuntimeException); + + virtual void SAL_CALL + setPropertyValueForLocale( const uno::Any& aValue, const OUString& aLocale ) + throw (backenduno::MalformedDataException, beans::IllegalTypeException, lang::IllegalAccessException, lang::IllegalArgumentException, uno::RuntimeException); + + private: + 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, OUString const & _aLocale); + + void raiseMalformedDataException(sal_Char const * pMsg); + void raiseIllegalTypeException(sal_Char const * pMsg); + private: + typedef std::stack< OUString > TagStack; + TagStack m_aTagStack; + ElementFormatter m_aFormatter; + uno::Type m_aPropertyType; + bool m_bInProperty; + }; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- + +} // namespace configmgr +#endif + + + + diff --git a/configmgr/source/xml/makefile.mk b/configmgr/source/xml/makefile.mk index 5805bebc31a9..b0fa90c43fc4 100644 --- a/configmgr/source/xml/makefile.mk +++ b/configmgr/source/xml/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.16 $ +# $Revision: 1.17 $ # -# last change: $Author: jb $ $Date: 2002-05-16 11:00:29 $ +# last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -100,10 +100,13 @@ SLOFILES=\ $(SLO)$/binarybasereader.obj \ $(SLO)$/generatecache.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)$/xmlstrings.obj \ # --- Targets --- diff --git a/configmgr/source/xml/writersvc.cxx b/configmgr/source/xml/writersvc.cxx new file mode 100644 index 000000000000..87ee2273cd9f --- /dev/null +++ b/configmgr/source/xml/writersvc.cxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * $RCSfile: writersvc.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "writersvc.hxx" + +#ifndef CONFIGMGR_API_FACTORY_HXX_ +#include "confapifactory.hxx" +#endif + +#include +#include + +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + namespace uno = ::com::sun::star::uno; + namespace lang = ::com::sun::star::lang; + namespace io = ::com::sun::star::io; + namespace sax = ::com::sun::star::xml::sax; + namespace backenduno = drafts::com::sun::star::configuration::backend; +// ----------------------------------------------------------------------------- + +template +struct WriterServiceTraits; +// ----------------------------------------------------------------------------- +static inline void clear(OUString & _rs) { _rs = OUString(); } + +// ----------------------------------------------------------------------------- +template +WriterService::WriterService(CreationArg _xServiceFactory) +: m_xServiceFactory(_xServiceFactory) +, m_xWriter() +{ + if (!m_xServiceFactory.is()) + { + OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration XML Writer: Unexpected NULL context")); + throw uno::RuntimeException(sMessage,NULL); + } +} +// ----------------------------------------------------------------------------- + +// XInitialization +template +void SAL_CALL + WriterService::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; + } + + 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: + { + OUString sMessage( RTL_CONSTASCII_USTRINGPARAM("Too many arguments to initialize a Configuration Parser")); + throw lang::IllegalArgumentException(sMessage,*this,0); + } + } +} +// ----------------------------------------------------------------------------- + +template +inline +ServiceInfoHelper WriterService::getServiceInfo() +{ + return WriterServiceTraits::getServiceInfo(); +} +// ----------------------------------------------------------------------------- + +// XServiceInfo +template +::rtl::OUString SAL_CALL + WriterService::getImplementationName( ) + throw (uno::RuntimeException) +{ + return getServiceInfo().getImplementationName( ); +} +// ----------------------------------------------------------------------------- + +template +sal_Bool SAL_CALL + WriterService::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return getServiceInfo().supportsService( ServiceName ); +} +// ----------------------------------------------------------------------------- + +template +uno::Sequence< ::rtl::OUString > SAL_CALL + WriterService::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + return getServiceInfo().getSupportedServiceNames( ); +} +// ----------------------------------------------------------------------------- + +template +void SAL_CALL + WriterService::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 + { + SaxHandler xNewHandler = this->createHandler(); + + xDS.set( xNewHandler, uno::UNO_QUERY ); + if (!xDS.is()) + { + 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 +uno::Reference< io::XOutputStream > SAL_CALL + WriterService::getOutputStream( ) + throw (uno::RuntimeException) +{ + uno::Reference< io::XActiveDataSource > xDS( m_xWriter, uno::UNO_QUERY ); + + return xDS.is()? xDS->getOutputStream() : NULL; +} +// ----------------------------------------------------------------------------- + +template +uno::Reference< sax::XDocumentHandler > WriterService::getWriteHandler() + throw (uno::RuntimeException) +{ + if (!m_xWriter.is()) + m_xWriter = this->createHandler(); + + return m_xWriter; +} + +// ----------------------------------------------------------------------------- + +template +uno::Reference< sax::XDocumentHandler > WriterService::createHandler() const + throw (uno::RuntimeException) +{ + static rtl::OUString const k_sSaxWriterSvc( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ); + + return SaxHandler::query( getServiceFactory()->createInstance(k_sSaxWriterSvc) ); +} + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +AsciiServiceName const aLayerWriterServices[] = +{ + "com.sun.star.configuration.backend.xml.LayerWriter", + 0 +}; +const ServiceInfo aLayerWriterSI = +{ + "com.sun.star.comp.configuration.backend.xml.LayerWriter", + aLayerWriterServices +}; +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +template <> +struct WriterServiceTraits< backenduno::XLayerHandler > +{ + typedef backenduno::XLayerHandler Handler; + + static ServiceInfo const * getServiceInfo() + { return & aLayerWriterSI; } +}; +// ----------------------------------------------------------------------------- + +const ServiceInfo* getLayerWriterServiceInfo() +{ return & aLayerWriterSI; } +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +// instantiate here ! +template class WriterService< backenduno::XLayerHandler >; + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + } // namespace + +// ----------------------------------------------------------------------------- +} // namespace + diff --git a/configmgr/source/xml/writersvc.hxx b/configmgr/source/xml/writersvc.hxx new file mode 100644 index 000000000000..d79747e850a0 --- /dev/null +++ b/configmgr/source/xml/writersvc.hxx @@ -0,0 +1,177 @@ +/************************************************************************* + * + * $RCSfile: writersvc.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jb $ $Date: 2002-05-27 10:39:04 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2002 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_XML_WRITERSVC_HXX +#define CONFIGMGR_XML_WRITERSVC_HXX + +#ifndef CONFIGMGR_SERVICEINFOHELPER_HXX_ +#include "serviceinfohelper.hxx" +#endif + +#ifndef _CPPUHELPER_IMPLBASE4_HXX_ +#include +#endif + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_ +#include +#endif + +// ----------------------------------------------------------------------------- +namespace drafts { +namespace com { namespace sun { namespace star { namespace configuration { namespace backend { + class XLayerHandler; +} } } } } +} +// ----------------------------------------------------------------------------- + +namespace configmgr +{ +// ----------------------------------------------------------------------------- + namespace xml + { +// ----------------------------------------------------------------------------- + using rtl::OUString; + 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 WriterService : public ::cppu::WeakImplHelper4< + lang::XInitialization, + lang::XServiceInfo, + io::XActiveDataSource, + BackendInterface + > + { + public: + typedef uno::Reference< lang::XMultiServiceFactory > const & CreationArg; + + explicit + WriterService(CreationArg _xServiceFactory); + + // 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: + typedef uno::Reference< sax::XDocumentHandler > SaxHandler; + typedef uno::Reference< lang::XMultiServiceFactory > ServiceFactory; + + ServiceFactory getServiceFactory() const + { return m_xServiceFactory; } + + SaxHandler getWriteHandler() throw (uno::RuntimeException); + private: + ServiceFactory m_xServiceFactory; + SaxHandler m_xWriter; + + SaxHandler createHandler() const throw (uno::RuntimeException); + + static ServiceInfoHelper getServiceInfo(); + }; + +// ----------------------------------------------------------------------------- + typedef WriterService< drafts::com::sun::star::configuration::backend::XLayerHandler > + LayerWriterService_Base; +// ----------------------------------------------------------------------------- + } // namespace xml +// ----------------------------------------------------------------------------- + +} // namespace configmgr +#endif + + + +