diff options
Diffstat (limited to 'xmlscript/source/xmlmod_imexp')
-rw-r--r-- | xmlscript/source/xmlmod_imexp/imp_share.hxx | 143 | ||||
-rw-r--r-- | xmlscript/source/xmlmod_imexp/makefile.mk | 49 | ||||
-rw-r--r-- | xmlscript/source/xmlmod_imexp/xmlmod_export.cxx | 80 | ||||
-rw-r--r-- | xmlscript/source/xmlmod_imexp/xmlmod_import.cxx | 230 |
4 files changed, 502 insertions, 0 deletions
diff --git a/xmlscript/source/xmlmod_imexp/imp_share.hxx b/xmlscript/source/xmlmod_imexp/imp_share.hxx new file mode 100644 index 000000000000..b5b42fc56625 --- /dev/null +++ b/xmlscript/source/xmlmod_imexp/imp_share.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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. + * + ************************************************************************/ + +#include <xmlscript/xmlmod_imexp.hxx> + +#include <cppuhelper/implbase1.hxx> +#include <rtl/ustrbuf.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> + +#include <com/sun/star/xml/input/XRoot.hpp> + +#include <vector> + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) + + +using namespace ::rtl; +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace xmlscript +{ + +//================================================================================================== +// Script module import + +//================================================================================================== +struct ModuleImport + : public ::cppu::WeakImplHelper1< xml::input::XRoot > +{ + friend class ModuleElement; + + ModuleDescriptor& mrModuleDesc; + + sal_Int32 XMLNS_SCRIPT_UID; + sal_Int32 XMLNS_LIBRARY_UID; + sal_Int32 XMLNS_XLINK_UID; + +public: + inline ModuleImport( ModuleDescriptor& rModuleDesc ) + SAL_THROW( () ) + : mrModuleDesc( rModuleDesc ) {} + virtual ~ModuleImport() + SAL_THROW( () ); + + // XRoot + virtual void SAL_CALL startDocument( + Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL endDocument() + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL processingInstruction( + OUString const & rTarget, OUString const & rData ) + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL setDocumentLocator( + Reference< xml::sax::XLocator > const & xLocator ) + throw (xml::sax::SAXException, RuntimeException); + virtual Reference< xml::input::XElement > SAL_CALL startRootElement( + sal_Int32 nUid, OUString const & rLocalName, + Reference< xml::input::XAttributes > const & xAttributes ) + throw (xml::sax::SAXException, RuntimeException); +}; + +//================================================================================================== +class ModuleElement + : public ::cppu::WeakImplHelper1< xml::input::XElement > +{ +protected: + ModuleImport * _pImport; + ModuleElement * _pParent; + + OUString _aLocalName; + Reference< xml::input::XAttributes > _xAttributes; + ::rtl::OUStringBuffer _StrBuffer; + +public: + ModuleElement( + OUString const & rLocalName, + Reference< xml::input::XAttributes > const & xAttributes, + ModuleElement * pParent, ModuleImport * pImport ) + SAL_THROW( () ); + virtual ~ModuleElement() + SAL_THROW( () ); + + // XElement + virtual Reference< xml::input::XElement > SAL_CALL getParent() + throw (RuntimeException); + virtual OUString SAL_CALL getLocalName() + throw (RuntimeException); + virtual sal_Int32 SAL_CALL getUid() + throw (RuntimeException); + virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes() + throw (RuntimeException); + virtual void SAL_CALL ignorableWhitespace( + OUString const & rWhitespaces ) + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL characters( OUString const & rChars ) + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL processingInstruction( + OUString const & rTarget, OUString const & rData ) + throw (xml::sax::SAXException, RuntimeException); + virtual void SAL_CALL endElement() + throw (xml::sax::SAXException, RuntimeException); + virtual Reference< xml::input::XElement > SAL_CALL startChildElement( + sal_Int32 nUid, OUString const & rLocalName, + Reference< xml::input::XAttributes > const & xAttributes ) + throw (xml::sax::SAXException, RuntimeException); +}; + +//================================================================================================== + +} diff --git a/xmlscript/source/xmlmod_imexp/makefile.mk b/xmlscript/source/xmlmod_imexp/makefile.mk new file mode 100644 index 000000000000..174bf94c75ae --- /dev/null +++ b/xmlscript/source/xmlmod_imexp/makefile.mk @@ -0,0 +1,49 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# 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=..$/.. + +PRJNAME=xmlscript +TARGET=xmlmod_imexp +NO_BSYMBOLIC=TRUE +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" +#----------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/xmlmod_import.obj \ + $(SLO)$/xmlmod_export.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : $(PRJ)$/util$/target.pmk + +.ENDIF # L10N_framework +.INCLUDE : target.mk diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx new file mode 100644 index 000000000000..781d2d779dda --- /dev/null +++ b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_xmlscript.hxx" + +#include <xmlscript/xmlmod_imexp.hxx> +#include <xmlscript/xml_helper.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star; +using namespace rtl; + +namespace xmlscript +{ + +//================================================================================================== + +void +SAL_CALL exportScriptModule( + Reference< xml::sax::XExtendedDocumentHandler > const & xOut, + const ModuleDescriptor& rMod ) + SAL_THROW( (Exception) ) +{ + xOut->startDocument(); + + OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM( + "<!DOCTYPE script:module PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\"" + " \"module.dtd\">" ) ); + xOut->unknown( aDocTypeStr ); + xOut->ignorableWhitespace( OUString() ); + + OUString aModuleName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":module") ); + XMLElement* pModElement = new XMLElement( aModuleName ); + Reference< xml::sax::XAttributeList > xAttributes( pModElement ); + + pModElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_SCRIPT_PREFIX) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_URI) ) ); + + pModElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":name") ), + rMod.aName ); + pModElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":language") ), + rMod.aLanguage ); + if( rMod.aModuleType.getLength()>0 ) + pModElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":moduleType") ), + rMod.aModuleType ); + + xOut->ignorableWhitespace( OUString() ); + xOut->startElement( aModuleName, xAttributes ); + xOut->characters( rMod.aCode ); + xOut->endElement( aModuleName ); + xOut->endDocument(); +} + +} + diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx new file mode 100644 index 000000000000..7f38f915aa62 --- /dev/null +++ b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx @@ -0,0 +1,230 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_xmlscript.hxx" +#include "imp_share.hxx" + +#include <osl/diagnose.h> + +#include <rtl/ustrbuf.hxx> + +#include <xmlscript/xml_import.hxx> +#include <comphelper/processfactory.hxx> + + +namespace xmlscript +{ + +//################################################################################################## + +//__________________________________________________________________________________________________ +Reference< xml::input::XElement > ModuleElement::getParent() + throw (RuntimeException) +{ + return static_cast< xml::input::XElement * >( _pParent ); +} +//__________________________________________________________________________________________________ +OUString ModuleElement::getLocalName() + throw (RuntimeException) +{ + return _aLocalName; +} +//__________________________________________________________________________________________________ +sal_Int32 ModuleElement::getUid() + throw (RuntimeException) +{ + return _pImport->XMLNS_SCRIPT_UID; +} +//__________________________________________________________________________________________________ +Reference< xml::input::XAttributes > ModuleElement::getAttributes() + throw (RuntimeException) +{ + return _xAttributes; +} +//__________________________________________________________________________________________________ +void ModuleElement::ignorableWhitespace( + OUString const & /*rWhitespaces*/ ) + throw (xml::sax::SAXException, RuntimeException) +{ + // not used +} +//__________________________________________________________________________________________________ +void ModuleElement::characters( OUString const & rChars ) + throw (xml::sax::SAXException, RuntimeException) +{ + _StrBuffer.append( rChars ); +} +//__________________________________________________________________________________________________ +void ModuleElement::processingInstruction( + OUString const & /*rTarget*/, OUString const & /*rData*/ ) + throw (xml::sax::SAXException, RuntimeException) +{ +} +//__________________________________________________________________________________________________ +void ModuleElement::endElement() + throw (xml::sax::SAXException, RuntimeException) +{ + _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear(); +} +//__________________________________________________________________________________________________ +Reference< xml::input::XElement > ModuleElement::startChildElement( + sal_Int32 /*nUid*/, OUString const & /*rLocalName*/, + Reference< xml::input::XAttributes > const & /*xAttributes*/ ) + throw (xml::sax::SAXException, RuntimeException) +{ + throw xml::sax::SAXException( + OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ), + Reference< XInterface >(), Any() ); +} + +//__________________________________________________________________________________________________ +ModuleElement::ModuleElement( + OUString const & rLocalName, + Reference< xml::input::XAttributes > const & xAttributes, + ModuleElement * pParent, ModuleImport * pImport ) + SAL_THROW( () ) + : _pImport( pImport ) + , _pParent( pParent ) + , _aLocalName( rLocalName ) + , _xAttributes( xAttributes ) +{ + _pImport->acquire(); + + if (_pParent) + { + _pParent->acquire(); + } +} +//__________________________________________________________________________________________________ +ModuleElement::~ModuleElement() + SAL_THROW( () ) +{ + _pImport->release(); + + if (_pParent) + { + _pParent->release(); + } + +#if OSL_DEBUG_LEVEL > 1 + OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) ); + OSL_TRACE( "ModuleElement::~ModuleElement(): %s\n", aStr.getStr() ); +#endif +} + +//################################################################################################## + +// XRoot + +//______________________________________________________________________________ +void ModuleImport::startDocument( + Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) + throw (xml::sax::SAXException, RuntimeException) +{ + XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( + OUSTR(XMLNS_SCRIPT_URI) ); + XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri( + OUSTR(XMLNS_LIBRARY_URI) ); + XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( + OUSTR(XMLNS_XLINK_URI) ); +} + +//__________________________________________________________________________________________________ +void ModuleImport::endDocument() + throw (xml::sax::SAXException, RuntimeException) +{ + // ignored +} +//__________________________________________________________________________________________________ +void ModuleImport::processingInstruction( + OUString const & /*rTarget*/, OUString const & /*rData*/ ) + throw (xml::sax::SAXException, RuntimeException) +{ +} +//__________________________________________________________________________________________________ +void ModuleImport::setDocumentLocator( + Reference< xml::sax::XLocator > const & /*xLocator*/ ) + throw (xml::sax::SAXException, RuntimeException) +{ +} +//__________________________________________________________________________________________________ +Reference< xml::input::XElement > ModuleImport::startRootElement( + sal_Int32 nUid, OUString const & rLocalName, + Reference< xml::input::XAttributes > const & xAttributes ) + throw (xml::sax::SAXException, RuntimeException) +{ + if (XMLNS_SCRIPT_UID != nUid) + { + throw xml::sax::SAXException( + OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ), + Reference< XInterface >(), Any() ); + } + // window + else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("module") )) + { + mrModuleDesc.aName = xAttributes->getValueByUidName( + XMLNS_SCRIPT_UID, + OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) ); + mrModuleDesc.aLanguage = xAttributes->getValueByUidName( + XMLNS_SCRIPT_UID, + OUString( RTL_CONSTASCII_USTRINGPARAM("language") ) ); + mrModuleDesc.aModuleType = xAttributes->getValueByUidName( + XMLNS_SCRIPT_UID, + OUString( RTL_CONSTASCII_USTRINGPARAM("moduleType") ) ); + + return new ModuleElement( rLocalName, xAttributes, 0, this ); + } + else + { + throw xml::sax::SAXException( + OUString( RTL_CONSTASCII_USTRINGPARAM( + "illegal root element (expected module) given: ") ) + + rLocalName, Reference< XInterface >(), Any() ); + } +} +//__________________________________________________________________________________________________ +ModuleImport::~ModuleImport() + SAL_THROW( () ) +{ +#if OSL_DEBUG_LEVEL > 1 + OSL_TRACE( "ModuleImport::~ModuleImport().\n" ); +#endif +} + +//################################################################################################## + +Reference< xml::sax::XDocumentHandler > +SAL_CALL importScriptModule( ModuleDescriptor& rMod ) + SAL_THROW( (Exception) ) +{ + return ::xmlscript::createDocumentHandler( + static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) ); +} + +} + |