1e1d5bd03SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3e1d5bd03SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4e1d5bd03SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5e1d5bd03SAndrew Rist  * distributed with this work for additional information
6e1d5bd03SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7e1d5bd03SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8e1d5bd03SAndrew Rist  * "License"); you may not use this file except in compliance
9e1d5bd03SAndrew Rist  * with the License.  You may obtain a copy of the License at
10e1d5bd03SAndrew Rist  *
11e1d5bd03SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12e1d5bd03SAndrew Rist  *
13e1d5bd03SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14e1d5bd03SAndrew Rist  * software distributed under the License is distributed on an
15e1d5bd03SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e1d5bd03SAndrew Rist  * KIND, either express or implied.  See the License for the
17e1d5bd03SAndrew Rist  * specific language governing permissions and limitations
18e1d5bd03SAndrew Rist  * under the License.
19e1d5bd03SAndrew Rist  *
20e1d5bd03SAndrew Rist  *************************************************************/
21e1d5bd03SAndrew Rist 
22e1d5bd03SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlscript.hxx"
26cdf0e10cSrcweir #include "imp_share.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
31cdf0e10cSrcweir 
32*b63233d8Sdamjan #include <xml_import.hxx>
33cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace xmlscript
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //##################################################################################################
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //__________________________________________________________________________________________________
getParent()42cdf0e10cSrcweir Reference< xml::input::XElement > ModuleElement::getParent()
43cdf0e10cSrcweir     throw (RuntimeException)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     return static_cast< xml::input::XElement * >( _pParent );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir //__________________________________________________________________________________________________
getLocalName()48cdf0e10cSrcweir OUString ModuleElement::getLocalName()
49cdf0e10cSrcweir     throw (RuntimeException)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     return _aLocalName;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir //__________________________________________________________________________________________________
getUid()54cdf0e10cSrcweir sal_Int32 ModuleElement::getUid()
55cdf0e10cSrcweir     throw (RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     return _pImport->XMLNS_SCRIPT_UID;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir //__________________________________________________________________________________________________
getAttributes()60cdf0e10cSrcweir Reference< xml::input::XAttributes > ModuleElement::getAttributes()
61cdf0e10cSrcweir     throw (RuntimeException)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     return _xAttributes;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir //__________________________________________________________________________________________________
ignorableWhitespace(OUString const &)66cdf0e10cSrcweir void ModuleElement::ignorableWhitespace(
67cdf0e10cSrcweir     OUString const & /*rWhitespaces*/ )
68cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     // not used
71cdf0e10cSrcweir }
72cdf0e10cSrcweir //__________________________________________________________________________________________________
characters(OUString const & rChars)73cdf0e10cSrcweir void ModuleElement::characters( OUString const & rChars )
74cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     _StrBuffer.append( rChars );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir //__________________________________________________________________________________________________
processingInstruction(OUString const &,OUString const &)79cdf0e10cSrcweir void ModuleElement::processingInstruction(
80cdf0e10cSrcweir     OUString const & /*rTarget*/, OUString const & /*rData*/ )
81cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir //__________________________________________________________________________________________________
endElement()85cdf0e10cSrcweir void ModuleElement::endElement()
86cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir //__________________________________________________________________________________________________
startChildElement(sal_Int32,OUString const &,Reference<xml::input::XAttributes> const &)91cdf0e10cSrcweir Reference< xml::input::XElement > ModuleElement::startChildElement(
92cdf0e10cSrcweir     sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
93cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & /*xAttributes*/ )
94cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     throw xml::sax::SAXException(
97cdf0e10cSrcweir         OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
98cdf0e10cSrcweir         Reference< XInterface >(), Any() );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //__________________________________________________________________________________________________
ModuleElement(OUString const & rLocalName,Reference<xml::input::XAttributes> const & xAttributes,ModuleElement * pParent,ModuleImport * pImport)102cdf0e10cSrcweir ModuleElement::ModuleElement(
103cdf0e10cSrcweir     OUString const & rLocalName,
104cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & xAttributes,
105cdf0e10cSrcweir     ModuleElement * pParent, ModuleImport * pImport )
106cdf0e10cSrcweir     SAL_THROW( () )
107cdf0e10cSrcweir     : _pImport( pImport )
108cdf0e10cSrcweir     , _pParent( pParent )
109cdf0e10cSrcweir     , _aLocalName( rLocalName )
110cdf0e10cSrcweir     , _xAttributes( xAttributes )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     _pImport->acquire();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     if (_pParent)
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         _pParent->acquire();
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir //__________________________________________________________________________________________________
~ModuleElement()120cdf0e10cSrcweir ModuleElement::~ModuleElement()
121cdf0e10cSrcweir     SAL_THROW( () )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     _pImport->release();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     if (_pParent)
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         _pParent->release();
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
131cdf0e10cSrcweir     OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
132cdf0e10cSrcweir     OSL_TRACE( "ModuleElement::~ModuleElement(): %s\n", aStr.getStr() );
133cdf0e10cSrcweir #endif
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //##################################################################################################
137cdf0e10cSrcweir 
138cdf0e10cSrcweir // XRoot
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //______________________________________________________________________________
startDocument(Reference<xml::input::XNamespaceMapping> const & xNamespaceMapping)141cdf0e10cSrcweir void ModuleImport::startDocument(
142cdf0e10cSrcweir     Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
143cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri(
146cdf0e10cSrcweir         OUSTR(XMLNS_SCRIPT_URI) );
147cdf0e10cSrcweir     XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri(
148cdf0e10cSrcweir         OUSTR(XMLNS_LIBRARY_URI) );
149cdf0e10cSrcweir     XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri(
150cdf0e10cSrcweir         OUSTR(XMLNS_XLINK_URI) );
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //__________________________________________________________________________________________________
endDocument()154cdf0e10cSrcweir void ModuleImport::endDocument()
155cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     // ignored
158cdf0e10cSrcweir }
159cdf0e10cSrcweir //__________________________________________________________________________________________________
processingInstruction(OUString const &,OUString const &)160cdf0e10cSrcweir void ModuleImport::processingInstruction(
161cdf0e10cSrcweir     OUString const & /*rTarget*/, OUString const & /*rData*/ )
162cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir }
165cdf0e10cSrcweir //__________________________________________________________________________________________________
setDocumentLocator(Reference<xml::sax::XLocator> const &)166cdf0e10cSrcweir void ModuleImport::setDocumentLocator(
167cdf0e10cSrcweir     Reference< xml::sax::XLocator > const & /*xLocator*/ )
168cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir }
171cdf0e10cSrcweir //__________________________________________________________________________________________________
startRootElement(sal_Int32 nUid,OUString const & rLocalName,Reference<xml::input::XAttributes> const & xAttributes)172cdf0e10cSrcweir Reference< xml::input::XElement > ModuleImport::startRootElement(
173cdf0e10cSrcweir     sal_Int32 nUid, OUString const & rLocalName,
174cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & xAttributes )
175cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     if (XMLNS_SCRIPT_UID != nUid)
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         throw xml::sax::SAXException(
180cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
181cdf0e10cSrcweir             Reference< XInterface >(), Any() );
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir     // window
184cdf0e10cSrcweir     else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("module") ))
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         mrModuleDesc.aName = xAttributes->getValueByUidName(
187cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
188cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
189cdf0e10cSrcweir         mrModuleDesc.aLanguage = xAttributes->getValueByUidName(
190cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
191cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("language") ) );
192cdf0e10cSrcweir         mrModuleDesc.aModuleType = xAttributes->getValueByUidName(
193cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
194cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("moduleType") ) );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         return new ModuleElement( rLocalName, xAttributes, 0, this );
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir     else
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         throw xml::sax::SAXException(
201cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM(
202cdf0e10cSrcweir                           "illegal root element (expected module) given: ") ) +
203cdf0e10cSrcweir             rLocalName, Reference< XInterface >(), Any() );
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir //__________________________________________________________________________________________________
~ModuleImport()207cdf0e10cSrcweir ModuleImport::~ModuleImport()
208cdf0e10cSrcweir     SAL_THROW( () )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
211cdf0e10cSrcweir     OSL_TRACE( "ModuleImport::~ModuleImport().\n" );
212cdf0e10cSrcweir #endif
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //##################################################################################################
216cdf0e10cSrcweir 
217cdf0e10cSrcweir Reference< xml::sax::XDocumentHandler >
importScriptModule(ModuleDescriptor & rMod)218cdf0e10cSrcweir SAL_CALL importScriptModule( ModuleDescriptor& rMod )
219cdf0e10cSrcweir     SAL_THROW( (Exception) )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     return ::xmlscript::createDocumentHandler(
222cdf0e10cSrcweir         static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227