Update ooo320-m1
[ooovba.git] / xmlscript / source / xmlmod_imexp / xmlmod_import.cxx
blob61b636b382aa1e11a816762637609256aea928e2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlmod_import.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
33 #include "imp_share.hxx"
35 #include <osl/diagnose.h>
37 #include <rtl/ustrbuf.hxx>
39 #include <xmlscript/xml_import.hxx>
40 #include <comphelper/processfactory.hxx>
43 namespace xmlscript
46 //##################################################################################################
48 //__________________________________________________________________________________________________
49 Reference< xml::input::XElement > ModuleElement::getParent()
50 throw (RuntimeException)
52 return static_cast< xml::input::XElement * >( _pParent );
54 //__________________________________________________________________________________________________
55 OUString ModuleElement::getLocalName()
56 throw (RuntimeException)
58 return _aLocalName;
60 //__________________________________________________________________________________________________
61 sal_Int32 ModuleElement::getUid()
62 throw (RuntimeException)
64 return _pImport->XMLNS_SCRIPT_UID;
66 //__________________________________________________________________________________________________
67 Reference< xml::input::XAttributes > ModuleElement::getAttributes()
68 throw (RuntimeException)
70 return _xAttributes;
72 //__________________________________________________________________________________________________
73 void ModuleElement::ignorableWhitespace(
74 OUString const & /*rWhitespaces*/ )
75 throw (xml::sax::SAXException, RuntimeException)
77 // not used
79 //__________________________________________________________________________________________________
80 void ModuleElement::characters( OUString const & rChars )
81 throw (xml::sax::SAXException, RuntimeException)
83 _StrBuffer.append( rChars );
85 //__________________________________________________________________________________________________
86 void ModuleElement::processingInstruction(
87 OUString const & /*rTarget*/, OUString const & /*rData*/ )
88 throw (xml::sax::SAXException, RuntimeException)
91 //__________________________________________________________________________________________________
92 void ModuleElement::endElement()
93 throw (xml::sax::SAXException, RuntimeException)
95 _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
97 //__________________________________________________________________________________________________
98 Reference< xml::input::XElement > ModuleElement::startChildElement(
99 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
100 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
101 throw (xml::sax::SAXException, RuntimeException)
103 throw xml::sax::SAXException(
104 OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
105 Reference< XInterface >(), Any() );
108 //__________________________________________________________________________________________________
109 ModuleElement::ModuleElement(
110 OUString const & rLocalName,
111 Reference< xml::input::XAttributes > const & xAttributes,
112 ModuleElement * pParent, ModuleImport * pImport )
113 SAL_THROW( () )
114 : _pImport( pImport )
115 , _pParent( pParent )
116 , _aLocalName( rLocalName )
117 , _xAttributes( xAttributes )
119 _pImport->acquire();
121 if (_pParent)
123 _pParent->acquire();
126 //__________________________________________________________________________________________________
127 ModuleElement::~ModuleElement()
128 SAL_THROW( () )
130 _pImport->release();
132 if (_pParent)
134 _pParent->release();
137 #if OSL_DEBUG_LEVEL > 1
138 OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
139 OSL_TRACE( "ModuleElement::~ModuleElement(): %s\n", aStr.getStr() );
140 #endif
143 //##################################################################################################
145 // XRoot
147 //______________________________________________________________________________
148 void ModuleImport::startDocument(
149 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
150 throw (xml::sax::SAXException, RuntimeException)
152 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri(
153 OUSTR(XMLNS_SCRIPT_URI) );
154 XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri(
155 OUSTR(XMLNS_LIBRARY_URI) );
156 XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri(
157 OUSTR(XMLNS_XLINK_URI) );
160 //__________________________________________________________________________________________________
161 void ModuleImport::endDocument()
162 throw (xml::sax::SAXException, RuntimeException)
164 // ignored
166 //__________________________________________________________________________________________________
167 void ModuleImport::processingInstruction(
168 OUString const & /*rTarget*/, OUString const & /*rData*/ )
169 throw (xml::sax::SAXException, RuntimeException)
172 //__________________________________________________________________________________________________
173 void ModuleImport::setDocumentLocator(
174 Reference< xml::sax::XLocator > const & /*xLocator*/ )
175 throw (xml::sax::SAXException, RuntimeException)
178 //__________________________________________________________________________________________________
179 Reference< xml::input::XElement > ModuleImport::startRootElement(
180 sal_Int32 nUid, OUString const & rLocalName,
181 Reference< xml::input::XAttributes > const & xAttributes )
182 throw (xml::sax::SAXException, RuntimeException)
184 if (XMLNS_SCRIPT_UID != nUid)
186 throw xml::sax::SAXException(
187 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
188 Reference< XInterface >(), Any() );
190 // window
191 else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("module") ))
193 mrModuleDesc.aName = xAttributes->getValueByUidName(
194 XMLNS_LIBRARY_UID,
195 OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
196 mrModuleDesc.aLanguage = xAttributes->getValueByUidName(
197 XMLNS_XLINK_UID,
198 OUString( RTL_CONSTASCII_USTRINGPARAM("language") ) );
200 return new ModuleElement( rLocalName, xAttributes, 0, this );
202 else
204 throw xml::sax::SAXException(
205 OUString( RTL_CONSTASCII_USTRINGPARAM(
206 "illegal root element (expected module) given: ") ) +
207 rLocalName, Reference< XInterface >(), Any() );
210 //__________________________________________________________________________________________________
211 ModuleImport::~ModuleImport()
212 SAL_THROW( () )
214 #if OSL_DEBUG_LEVEL > 1
215 OSL_TRACE( "ModuleImport::~ModuleImport().\n" );
216 #endif
219 //##################################################################################################
221 Reference< xml::sax::XDocumentHandler >
222 SAL_CALL importScriptModule( ModuleDescriptor& rMod )
223 SAL_THROW( (Exception) )
225 return ::xmlscript::createDocumentHandler(
226 static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );