bump product version to 5.0.4.1
[LibreOffice.git] / xmlscript / source / xmlmod_imexp / xmlmod_import.cxx
bloba14e7a237d9e2251db13d99f08a57b884ec48392
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <sal/log.hxx>
24 #include "imp_share.hxx"
25 #include "xml_import.hxx"
27 using namespace css;
28 using namespace css::uno;
30 namespace xmlscript
33 Reference< xml::input::XElement > ModuleElement::getParent()
34 throw (RuntimeException, std::exception)
36 return static_cast< xml::input::XElement * >( _pParent );
38 OUString ModuleElement::getLocalName()
39 throw (RuntimeException, std::exception)
41 return _aLocalName;
43 sal_Int32 ModuleElement::getUid()
44 throw (RuntimeException, std::exception)
46 return _pImport->XMLNS_SCRIPT_UID;
48 Reference< xml::input::XAttributes > ModuleElement::getAttributes()
49 throw (RuntimeException, std::exception)
51 return _xAttributes;
54 void ModuleElement::ignorableWhitespace(
55 OUString const & /*rWhitespaces*/ )
56 throw (xml::sax::SAXException, RuntimeException, std::exception)
58 // not used
61 void ModuleElement::characters( OUString const & rChars )
62 throw (xml::sax::SAXException, RuntimeException, std::exception)
64 _StrBuffer.append( rChars );
67 void ModuleElement::processingInstruction(
68 OUString const & /*rTarget*/, OUString const & /*rData*/ )
69 throw (xml::sax::SAXException, RuntimeException, std::exception)
73 void ModuleElement::endElement()
74 throw (xml::sax::SAXException, RuntimeException, std::exception)
76 _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
79 Reference< xml::input::XElement > ModuleElement::startChildElement(
80 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
81 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
82 throw (xml::sax::SAXException, RuntimeException, std::exception)
84 throw xml::sax::SAXException("unexpected element!", Reference< XInterface >(), Any() );
87 ModuleElement::ModuleElement(
88 OUString const & rLocalName,
89 Reference< xml::input::XAttributes > const & xAttributes,
90 ModuleElement * pParent, ModuleImport * pImport )
91 : _pImport( pImport )
92 , _pParent( pParent )
93 , _aLocalName( rLocalName )
94 , _xAttributes( xAttributes )
96 _pImport->acquire();
98 if (_pParent)
100 _pParent->acquire();
104 ModuleElement::~ModuleElement()
106 _pImport->release();
108 if (_pParent)
110 _pParent->release();
113 #if OSL_DEBUG_LEVEL > 1
114 OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
115 SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << aStr.getStr() );
116 #endif
119 // XRoot
121 void ModuleImport::startDocument(
122 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
123 throw (xml::sax::SAXException, RuntimeException, std::exception)
125 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
126 XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri( XMLNS_LIBRARY_URI );
127 XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( XMLNS_XLINK_URI );
130 void ModuleImport::endDocument()
131 throw (xml::sax::SAXException, RuntimeException, std::exception)
133 // ignored
136 void ModuleImport::processingInstruction(
137 OUString const & /*rTarget*/, OUString const & /*rData*/ )
138 throw (xml::sax::SAXException, RuntimeException, std::exception)
142 void ModuleImport::setDocumentLocator(
143 Reference< xml::sax::XLocator > const & /*xLocator*/ )
144 throw (xml::sax::SAXException, RuntimeException, std::exception)
148 Reference< xml::input::XElement > ModuleImport::startRootElement(
149 sal_Int32 nUid, OUString const & rLocalName,
150 Reference< xml::input::XAttributes > const & xAttributes )
151 throw (xml::sax::SAXException, RuntimeException, std::exception)
153 if (XMLNS_SCRIPT_UID != nUid)
155 throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
157 // window
158 else if ( rLocalName == "module" )
160 mrModuleDesc.aName = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "name" );
161 mrModuleDesc.aLanguage = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "language" );
162 mrModuleDesc.aModuleType = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "moduleType" );
164 return new ModuleElement( rLocalName, xAttributes, 0, this );
166 else
168 throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName, Reference< XInterface >(), Any() );
172 ModuleImport::~ModuleImport()
174 #if OSL_DEBUG_LEVEL > 1
175 SAL_INFO("xmlscript.xmlmod", "ModuleImport::~ModuleImport()." );
176 #endif
179 Reference< xml::sax::XDocumentHandler >
180 SAL_CALL importScriptModule( ModuleDescriptor& rMod )
182 return ::xmlscript::createDocumentHandler(
183 static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */