Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "imp_share.hxx"
21 : : #include "xml_import.hxx"
22 : :
23 : : namespace xmlscript
24 : : {
25 : :
26 : : //##################################################################################################
27 : :
28 : : //__________________________________________________________________________________________________
29 : 0 : Reference< xml::input::XElement > ModuleElement::getParent()
30 : : throw (RuntimeException)
31 : : {
32 [ # # ]: 0 : return static_cast< xml::input::XElement * >( _pParent );
33 : : }
34 : : //__________________________________________________________________________________________________
35 : 0 : OUString ModuleElement::getLocalName()
36 : : throw (RuntimeException)
37 : : {
38 : 0 : return _aLocalName;
39 : : }
40 : : //__________________________________________________________________________________________________
41 : 0 : sal_Int32 ModuleElement::getUid()
42 : : throw (RuntimeException)
43 : : {
44 : 0 : return _pImport->XMLNS_SCRIPT_UID;
45 : : }
46 : : //__________________________________________________________________________________________________
47 : 0 : Reference< xml::input::XAttributes > ModuleElement::getAttributes()
48 : : throw (RuntimeException)
49 : : {
50 : 0 : return _xAttributes;
51 : : }
52 : : //__________________________________________________________________________________________________
53 : 0 : void ModuleElement::ignorableWhitespace(
54 : : OUString const & /*rWhitespaces*/ )
55 : : throw (xml::sax::SAXException, RuntimeException)
56 : : {
57 : : // not used
58 : 0 : }
59 : : //__________________________________________________________________________________________________
60 : 10454 : void ModuleElement::characters( OUString const & rChars )
61 : : throw (xml::sax::SAXException, RuntimeException)
62 : : {
63 : 10454 : _StrBuffer.append( rChars );
64 : 10454 : }
65 : : //__________________________________________________________________________________________________
66 : 0 : void ModuleElement::processingInstruction(
67 : : OUString const & /*rTarget*/, OUString const & /*rData*/ )
68 : : throw (xml::sax::SAXException, RuntimeException)
69 : : {
70 : 0 : }
71 : : //__________________________________________________________________________________________________
72 : 74 : void ModuleElement::endElement()
73 : : throw (xml::sax::SAXException, RuntimeException)
74 : : {
75 : 74 : _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
76 : 74 : }
77 : : //__________________________________________________________________________________________________
78 : 0 : Reference< xml::input::XElement > ModuleElement::startChildElement(
79 : : sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
80 : : Reference< xml::input::XAttributes > const & /*xAttributes*/ )
81 : : throw (xml::sax::SAXException, RuntimeException)
82 : : {
83 : : throw xml::sax::SAXException(
84 : : OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
85 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
86 : : }
87 : :
88 : : //__________________________________________________________________________________________________
89 : 74 : ModuleElement::ModuleElement(
90 : : OUString const & rLocalName,
91 : : Reference< xml::input::XAttributes > const & xAttributes,
92 : : ModuleElement * pParent, ModuleImport * pImport )
93 : : SAL_THROW(())
94 : : : _pImport( pImport )
95 : : , _pParent( pParent )
96 : : , _aLocalName( rLocalName )
97 : 74 : , _xAttributes( xAttributes )
98 : : {
99 : 74 : _pImport->acquire();
100 : :
101 [ - + ]: 74 : if (_pParent)
102 : : {
103 : 0 : _pParent->acquire();
104 : : }
105 : 74 : }
106 : : //__________________________________________________________________________________________________
107 : 74 : ModuleElement::~ModuleElement()
108 : : SAL_THROW(())
109 : : {
110 : 74 : _pImport->release();
111 : :
112 [ - + ]: 74 : if (_pParent)
113 : : {
114 : 0 : _pParent->release();
115 : : }
116 : :
117 : : #if OSL_DEBUG_LEVEL > 1
118 : : OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
119 : : OSL_TRACE( "ModuleElement::~ModuleElement(): %s", aStr.getStr() );
120 : : #endif
121 [ - + ]: 148 : }
122 : :
123 : : //##################################################################################################
124 : :
125 : : // XRoot
126 : :
127 : : //______________________________________________________________________________
128 : 74 : void ModuleImport::startDocument(
129 : : Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
130 : : throw (xml::sax::SAXException, RuntimeException)
131 : : {
132 : 74 : XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri(
133 [ + - ]: 74 : OUSTR(XMLNS_SCRIPT_URI) );
134 : 74 : XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri(
135 [ + - ]: 74 : OUSTR(XMLNS_LIBRARY_URI) );
136 : 74 : XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri(
137 [ + - ]: 74 : OUSTR(XMLNS_XLINK_URI) );
138 : 74 : }
139 : :
140 : : //__________________________________________________________________________________________________
141 : 74 : void ModuleImport::endDocument()
142 : : throw (xml::sax::SAXException, RuntimeException)
143 : : {
144 : : // ignored
145 : 74 : }
146 : : //__________________________________________________________________________________________________
147 : 0 : void ModuleImport::processingInstruction(
148 : : OUString const & /*rTarget*/, OUString const & /*rData*/ )
149 : : throw (xml::sax::SAXException, RuntimeException)
150 : : {
151 : 0 : }
152 : : //__________________________________________________________________________________________________
153 : 74 : void ModuleImport::setDocumentLocator(
154 : : Reference< xml::sax::XLocator > const & /*xLocator*/ )
155 : : throw (xml::sax::SAXException, RuntimeException)
156 : : {
157 : 74 : }
158 : : //__________________________________________________________________________________________________
159 : 74 : Reference< xml::input::XElement > ModuleImport::startRootElement(
160 : : sal_Int32 nUid, OUString const & rLocalName,
161 : : Reference< xml::input::XAttributes > const & xAttributes )
162 : : throw (xml::sax::SAXException, RuntimeException)
163 : : {
164 [ - + ]: 74 : if (XMLNS_SCRIPT_UID != nUid)
165 : : {
166 : : throw xml::sax::SAXException(
167 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
168 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
169 : : }
170 : : // window
171 [ + - ]: 74 : else if ( rLocalName == "module" )
172 : : {
173 : 74 : mrModuleDesc.aName = xAttributes->getValueByUidName(
174 : : XMLNS_SCRIPT_UID,
175 [ + - ]: 74 : OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
176 : 74 : mrModuleDesc.aLanguage = xAttributes->getValueByUidName(
177 : : XMLNS_SCRIPT_UID,
178 [ + - ]: 74 : OUString( RTL_CONSTASCII_USTRINGPARAM("language") ) );
179 : 74 : mrModuleDesc.aModuleType = xAttributes->getValueByUidName(
180 : : XMLNS_SCRIPT_UID,
181 [ + - ]: 74 : OUString( RTL_CONSTASCII_USTRINGPARAM("moduleType") ) );
182 : :
183 [ + - ][ + - ]: 74 : return new ModuleElement( rLocalName, xAttributes, 0, this );
184 : : }
185 : : else
186 : : {
187 : : throw xml::sax::SAXException(
188 : : OUString( RTL_CONSTASCII_USTRINGPARAM(
189 : : "illegal root element (expected module) given: ") ) +
190 [ # # ][ # # ]: 0 : rLocalName, Reference< XInterface >(), Any() );
191 : : }
192 : : }
193 : : //__________________________________________________________________________________________________
194 : 74 : ModuleImport::~ModuleImport()
195 : : SAL_THROW(())
196 : : {
197 : : #if OSL_DEBUG_LEVEL > 1
198 : : OSL_TRACE( "ModuleImport::~ModuleImport()." );
199 : : #endif
200 [ - + ]: 148 : }
201 : :
202 : : //##################################################################################################
203 : :
204 : : Reference< xml::sax::XDocumentHandler >
205 : 74 : SAL_CALL importScriptModule( ModuleDescriptor& rMod )
206 : : SAL_THROW( (Exception) )
207 : : {
208 : : return ::xmlscript::createDocumentHandler(
209 [ + - ][ + - ]: 74 : static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );
[ + - ]
210 : : }
211 : :
212 : : }
213 : :
214 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|