summaryrefslogtreecommitdiffstats
path: root/xmlscript/source/xmlmod_imexp
diff options
context:
space:
mode:
Diffstat (limited to 'xmlscript/source/xmlmod_imexp')
-rw-r--r--xmlscript/source/xmlmod_imexp/imp_share.hxx101
-rw-r--r--xmlscript/source/xmlmod_imexp/xmlmod_export.cxx63
-rw-r--r--xmlscript/source/xmlmod_imexp/xmlmod_import.cxx154
3 files changed, 318 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 000000000..f914c973b
--- /dev/null
+++ b/xmlscript/source/xmlmod_imexp/imp_share.hxx
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <xmlscript/xmlmod_imexp.hxx>
+
+#include <cppuhelper/implbase.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/ref.hxx>
+
+#include <com/sun/star/xml/input/XRoot.hpp>
+
+namespace xmlscript
+{
+
+// Script module import
+
+struct ModuleImport
+ : public ::cppu::WeakImplHelper< css::xml::input::XRoot >
+{
+ friend class ModuleElement;
+
+ ModuleDescriptor& mrModuleDesc;
+
+ sal_Int32 XMLNS_SCRIPT_UID;
+
+public:
+ explicit ModuleImport(ModuleDescriptor& rModuleDesc)
+ : mrModuleDesc(rModuleDesc)
+ , XMLNS_SCRIPT_UID(0)
+ {
+ }
+
+ virtual ~ModuleImport() override;
+
+ // XRoot
+ virtual void SAL_CALL startDocument(
+ css::uno::Reference< css::xml::input::XNamespaceMapping > const & xNamespaceMapping ) override;
+ virtual void SAL_CALL endDocument() override;
+ virtual void SAL_CALL processingInstruction(
+ OUString const & rTarget, OUString const & rData ) override;
+ virtual void SAL_CALL setDocumentLocator(
+ css::uno::Reference< css::xml::sax::XLocator > const & xLocator ) override;
+ virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startRootElement(
+ sal_Int32 nUid, OUString const & rLocalName,
+ css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
+};
+
+class ModuleElement
+ : public ::cppu::WeakImplHelper< css::xml::input::XElement >
+{
+ rtl::Reference<ModuleImport> mxImport;
+
+ OUString const _aLocalName;
+ css::uno::Reference< css::xml::input::XAttributes > _xAttributes;
+ OUStringBuffer _strBuffer{512};
+
+public:
+ ModuleElement(
+ OUString const & rLocalName,
+ css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
+ ModuleImport * pImport );
+ virtual ~ModuleElement() override;
+
+ // XElement
+ virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL getParent() override;
+ virtual OUString SAL_CALL getLocalName() override;
+ virtual sal_Int32 SAL_CALL getUid() override;
+ virtual css::uno::Reference< css::xml::input::XAttributes > SAL_CALL getAttributes() override;
+ virtual void SAL_CALL ignorableWhitespace(
+ OUString const & rWhitespaces ) override;
+ virtual void SAL_CALL characters( OUString const & rChars ) override;
+ virtual void SAL_CALL processingInstruction(
+ OUString const & rTarget, OUString const & rData ) override;
+ virtual void SAL_CALL endElement() override;
+ virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(
+ sal_Int32 nUid, OUString const & rLocalName,
+ css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
+};
+
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx
new file mode 100644
index 000000000..55b447561
--- /dev/null
+++ b/xmlscript/source/xmlmod_imexp/xmlmod_export.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <xmlscript/xmlmod_imexp.hxx>
+#include <xmlscript/xml_helper.hxx>
+#include <xmlscript/xmlns.h>
+#include <com/sun/star/xml/sax/XWriter.hpp>
+#include <rtl/ref.hxx>
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star;
+
+namespace xmlscript
+{
+
+void
+exportScriptModule(
+ Reference< xml::sax::XWriter > const & xOut,
+ const ModuleDescriptor& rMod )
+{
+ xOut->startDocument();
+
+ xOut->unknown(
+ "<!DOCTYPE script:module PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
+ " \"module.dtd\">");
+ xOut->ignorableWhitespace( OUString() );
+
+ OUString aModuleName( XMLNS_SCRIPT_PREFIX ":module" );
+ rtl::Reference<XMLElement> pModElement = new XMLElement( aModuleName );
+
+ pModElement->addAttribute( "xmlns:" XMLNS_SCRIPT_PREFIX, XMLNS_SCRIPT_URI );
+
+ pModElement->addAttribute( XMLNS_SCRIPT_PREFIX ":name", rMod.aName );
+ pModElement->addAttribute( XMLNS_SCRIPT_PREFIX ":language", rMod.aLanguage );
+ if( !rMod.aModuleType.isEmpty() )
+ pModElement->addAttribute( XMLNS_SCRIPT_PREFIX ":moduleType", rMod.aModuleType );
+
+ xOut->ignorableWhitespace( OUString() );
+ xOut->startElement( aModuleName, pModElement );
+ xOut->characters( rMod.aCode );
+ xOut->endElement( aModuleName );
+ xOut->endDocument();
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx
new file mode 100644
index 000000000..2751d9856
--- /dev/null
+++ b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx
@@ -0,0 +1,154 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <xmlscript/xmlns.h>
+#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <sal/log.hxx>
+
+#include "imp_share.hxx"
+#include <xml_import.hxx>
+
+using namespace css;
+using namespace css::uno;
+
+namespace xmlscript
+{
+
+Reference< xml::input::XElement > ModuleElement::getParent()
+{
+ return nullptr;
+}
+OUString ModuleElement::getLocalName()
+{
+ return _aLocalName;
+}
+sal_Int32 ModuleElement::getUid()
+{
+ return mxImport->XMLNS_SCRIPT_UID;
+}
+Reference< xml::input::XAttributes > ModuleElement::getAttributes()
+{
+ return _xAttributes;
+}
+
+void ModuleElement::ignorableWhitespace(
+ OUString const & /*rWhitespaces*/ )
+{
+ // not used
+}
+
+void ModuleElement::characters( OUString const & rChars )
+{
+ _strBuffer.append( rChars );
+}
+
+void ModuleElement::processingInstruction(
+ OUString const & /*rTarget*/, OUString const & /*rData*/ )
+{
+}
+
+void ModuleElement::endElement()
+{
+ mxImport->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("unexpected element!", Reference< XInterface >(), Any() );
+}
+
+ModuleElement::ModuleElement(
+ OUString const & rLocalName,
+ Reference< xml::input::XAttributes > const & xAttributes,
+ ModuleImport * pImport )
+ : mxImport( pImport )
+ , _aLocalName( rLocalName )
+ , _xAttributes( xAttributes )
+{
+}
+
+ModuleElement::~ModuleElement()
+{
+ SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << _aLocalName );
+}
+
+// XRoot
+
+void ModuleImport::startDocument(
+ Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
+{
+ XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
+}
+
+void ModuleImport::endDocument()
+{
+ // ignored
+}
+
+void ModuleImport::processingInstruction(
+ OUString const & /*rTarget*/, OUString const & /*rData*/ )
+{
+}
+
+void ModuleImport::setDocumentLocator(
+ Reference< xml::sax::XLocator > const & /*xLocator*/ )
+{
+}
+
+Reference< xml::input::XElement > ModuleImport::startRootElement(
+ sal_Int32 nUid, OUString const & rLocalName,
+ Reference< xml::input::XAttributes > const & xAttributes )
+{
+ if (XMLNS_SCRIPT_UID != nUid)
+ {
+ throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
+ }
+ // window
+ else if ( rLocalName == "module" )
+ {
+ mrModuleDesc.aName = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "name" );
+ mrModuleDesc.aLanguage = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "language" );
+ mrModuleDesc.aModuleType = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "moduleType" );
+
+ return new ModuleElement( rLocalName, xAttributes, this );
+ }
+ else
+ {
+ throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName, Reference< XInterface >(), Any() );
+ }
+}
+
+ModuleImport::~ModuleImport()
+{
+ SAL_INFO("xmlscript.xmlmod", "ModuleImport::~ModuleImport()." );
+}
+
+Reference< xml::sax::XDocumentHandler >
+importScriptModule( ModuleDescriptor& rMod )
+{
+ return ::xmlscript::createDocumentHandler(new ModuleImport(rMod));
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */