1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmlscript.hxx"
30*cdf0e10cSrcweir #include "imp_share.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <xmlscript/xml_import.hxx>
37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace xmlscript
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //##################################################################################################
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //__________________________________________________________________________________________________
46*cdf0e10cSrcweir Reference< xml::input::XElement > ModuleElement::getParent()
47*cdf0e10cSrcweir     throw (RuntimeException)
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     return static_cast< xml::input::XElement * >( _pParent );
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir //__________________________________________________________________________________________________
52*cdf0e10cSrcweir OUString ModuleElement::getLocalName()
53*cdf0e10cSrcweir     throw (RuntimeException)
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     return _aLocalName;
56*cdf0e10cSrcweir }
57*cdf0e10cSrcweir //__________________________________________________________________________________________________
58*cdf0e10cSrcweir sal_Int32 ModuleElement::getUid()
59*cdf0e10cSrcweir     throw (RuntimeException)
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     return _pImport->XMLNS_SCRIPT_UID;
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir //__________________________________________________________________________________________________
64*cdf0e10cSrcweir Reference< xml::input::XAttributes > ModuleElement::getAttributes()
65*cdf0e10cSrcweir     throw (RuntimeException)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     return _xAttributes;
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir //__________________________________________________________________________________________________
70*cdf0e10cSrcweir void ModuleElement::ignorableWhitespace(
71*cdf0e10cSrcweir     OUString const & /*rWhitespaces*/ )
72*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     // not used
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir //__________________________________________________________________________________________________
77*cdf0e10cSrcweir void ModuleElement::characters( OUString const & rChars )
78*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     _StrBuffer.append( rChars );
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir //__________________________________________________________________________________________________
83*cdf0e10cSrcweir void ModuleElement::processingInstruction(
84*cdf0e10cSrcweir     OUString const & /*rTarget*/, OUString const & /*rData*/ )
85*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir //__________________________________________________________________________________________________
89*cdf0e10cSrcweir void ModuleElement::endElement()
90*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir //__________________________________________________________________________________________________
95*cdf0e10cSrcweir Reference< xml::input::XElement > ModuleElement::startChildElement(
96*cdf0e10cSrcweir     sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
97*cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & /*xAttributes*/ )
98*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     throw xml::sax::SAXException(
101*cdf0e10cSrcweir         OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
102*cdf0e10cSrcweir         Reference< XInterface >(), Any() );
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir //__________________________________________________________________________________________________
106*cdf0e10cSrcweir ModuleElement::ModuleElement(
107*cdf0e10cSrcweir     OUString const & rLocalName,
108*cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & xAttributes,
109*cdf0e10cSrcweir     ModuleElement * pParent, ModuleImport * pImport )
110*cdf0e10cSrcweir     SAL_THROW( () )
111*cdf0e10cSrcweir     : _pImport( pImport )
112*cdf0e10cSrcweir     , _pParent( pParent )
113*cdf0e10cSrcweir     , _aLocalName( rLocalName )
114*cdf0e10cSrcweir     , _xAttributes( xAttributes )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     _pImport->acquire();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     if (_pParent)
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         _pParent->acquire();
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir //__________________________________________________________________________________________________
124*cdf0e10cSrcweir ModuleElement::~ModuleElement()
125*cdf0e10cSrcweir     SAL_THROW( () )
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     _pImport->release();
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     if (_pParent)
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         _pParent->release();
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
135*cdf0e10cSrcweir     OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
136*cdf0e10cSrcweir     OSL_TRACE( "ModuleElement::~ModuleElement(): %s\n", aStr.getStr() );
137*cdf0e10cSrcweir #endif
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir //##################################################################################################
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir // XRoot
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //______________________________________________________________________________
145*cdf0e10cSrcweir void ModuleImport::startDocument(
146*cdf0e10cSrcweir     Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
147*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri(
150*cdf0e10cSrcweir         OUSTR(XMLNS_SCRIPT_URI) );
151*cdf0e10cSrcweir     XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri(
152*cdf0e10cSrcweir         OUSTR(XMLNS_LIBRARY_URI) );
153*cdf0e10cSrcweir     XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri(
154*cdf0e10cSrcweir         OUSTR(XMLNS_XLINK_URI) );
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //__________________________________________________________________________________________________
158*cdf0e10cSrcweir void ModuleImport::endDocument()
159*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     // ignored
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir //__________________________________________________________________________________________________
164*cdf0e10cSrcweir void ModuleImport::processingInstruction(
165*cdf0e10cSrcweir     OUString const & /*rTarget*/, OUString const & /*rData*/ )
166*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir //__________________________________________________________________________________________________
170*cdf0e10cSrcweir void ModuleImport::setDocumentLocator(
171*cdf0e10cSrcweir     Reference< xml::sax::XLocator > const & /*xLocator*/ )
172*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir //__________________________________________________________________________________________________
176*cdf0e10cSrcweir Reference< xml::input::XElement > ModuleImport::startRootElement(
177*cdf0e10cSrcweir     sal_Int32 nUid, OUString const & rLocalName,
178*cdf0e10cSrcweir     Reference< xml::input::XAttributes > const & xAttributes )
179*cdf0e10cSrcweir     throw (xml::sax::SAXException, RuntimeException)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     if (XMLNS_SCRIPT_UID != nUid)
182*cdf0e10cSrcweir     {
183*cdf0e10cSrcweir         throw xml::sax::SAXException(
184*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
185*cdf0e10cSrcweir             Reference< XInterface >(), Any() );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir     // window
188*cdf0e10cSrcweir     else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("module") ))
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         mrModuleDesc.aName = xAttributes->getValueByUidName(
191*cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
192*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
193*cdf0e10cSrcweir         mrModuleDesc.aLanguage = xAttributes->getValueByUidName(
194*cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
195*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("language") ) );
196*cdf0e10cSrcweir         mrModuleDesc.aModuleType = xAttributes->getValueByUidName(
197*cdf0e10cSrcweir             XMLNS_SCRIPT_UID,
198*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("moduleType") ) );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         return new ModuleElement( rLocalName, xAttributes, 0, this );
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir     else
203*cdf0e10cSrcweir     {
204*cdf0e10cSrcweir         throw xml::sax::SAXException(
205*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM(
206*cdf0e10cSrcweir                           "illegal root element (expected module) given: ") ) +
207*cdf0e10cSrcweir             rLocalName, Reference< XInterface >(), Any() );
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir //__________________________________________________________________________________________________
211*cdf0e10cSrcweir ModuleImport::~ModuleImport()
212*cdf0e10cSrcweir     SAL_THROW( () )
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
215*cdf0e10cSrcweir     OSL_TRACE( "ModuleImport::~ModuleImport().\n" );
216*cdf0e10cSrcweir #endif
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir //##################################################################################################
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir Reference< xml::sax::XDocumentHandler >
222*cdf0e10cSrcweir SAL_CALL importScriptModule( ModuleDescriptor& rMod )
223*cdf0e10cSrcweir     SAL_THROW( (Exception) )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     return ::xmlscript::createDocumentHandler(
226*cdf0e10cSrcweir         static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231