Bump for 4.0-15
[LibreOffice.git] / xmlscript / source / xmlmod_imexp / xmlmod_import.cxx
blobec13ec5bfb5ebe6c400b083693b5a603f7e559bf
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 "imp_share.hxx"
21 #include "xml_import.hxx"
23 namespace xmlscript
26 //##################################################################################################
28 //__________________________________________________________________________________________________
29 Reference< xml::input::XElement > ModuleElement::getParent()
30 throw (RuntimeException)
32 return static_cast< xml::input::XElement * >( _pParent );
34 //__________________________________________________________________________________________________
35 OUString ModuleElement::getLocalName()
36 throw (RuntimeException)
38 return _aLocalName;
40 //__________________________________________________________________________________________________
41 sal_Int32 ModuleElement::getUid()
42 throw (RuntimeException)
44 return _pImport->XMLNS_SCRIPT_UID;
46 //__________________________________________________________________________________________________
47 Reference< xml::input::XAttributes > ModuleElement::getAttributes()
48 throw (RuntimeException)
50 return _xAttributes;
52 //__________________________________________________________________________________________________
53 void ModuleElement::ignorableWhitespace(
54 OUString const & /*rWhitespaces*/ )
55 throw (xml::sax::SAXException, RuntimeException)
57 // not used
59 //__________________________________________________________________________________________________
60 void ModuleElement::characters( OUString const & rChars )
61 throw (xml::sax::SAXException, RuntimeException)
63 _StrBuffer.append( rChars );
65 //__________________________________________________________________________________________________
66 void ModuleElement::processingInstruction(
67 OUString const & /*rTarget*/, OUString const & /*rData*/ )
68 throw (xml::sax::SAXException, RuntimeException)
71 //__________________________________________________________________________________________________
72 void ModuleElement::endElement()
73 throw (xml::sax::SAXException, RuntimeException)
75 _pImport->mrModuleDesc.aCode = _StrBuffer.makeStringAndClear();
77 //__________________________________________________________________________________________________
78 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)
83 throw xml::sax::SAXException("unexpected element!", Reference< XInterface >(), Any() );
86 //__________________________________________________________________________________________________
87 ModuleElement::ModuleElement(
88 OUString const & rLocalName,
89 Reference< xml::input::XAttributes > const & xAttributes,
90 ModuleElement * pParent, ModuleImport * pImport )
91 SAL_THROW(())
92 : _pImport( pImport )
93 , _pParent( pParent )
94 , _aLocalName( rLocalName )
95 , _xAttributes( xAttributes )
97 _pImport->acquire();
99 if (_pParent)
101 _pParent->acquire();
104 //__________________________________________________________________________________________________
105 ModuleElement::~ModuleElement()
106 SAL_THROW(())
108 _pImport->release();
110 if (_pParent)
112 _pParent->release();
115 #if OSL_DEBUG_LEVEL > 1
116 OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
117 OSL_TRACE( "ModuleElement::~ModuleElement(): %s", aStr.getStr() );
118 #endif
121 //##################################################################################################
123 // XRoot
125 //______________________________________________________________________________
126 void ModuleImport::startDocument(
127 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
128 throw (xml::sax::SAXException, RuntimeException)
130 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
131 XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri( XMLNS_LIBRARY_URI );
132 XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( XMLNS_XLINK_URI );
135 //__________________________________________________________________________________________________
136 void ModuleImport::endDocument()
137 throw (xml::sax::SAXException, RuntimeException)
139 // ignored
141 //__________________________________________________________________________________________________
142 void ModuleImport::processingInstruction(
143 OUString const & /*rTarget*/, OUString const & /*rData*/ )
144 throw (xml::sax::SAXException, RuntimeException)
147 //__________________________________________________________________________________________________
148 void ModuleImport::setDocumentLocator(
149 Reference< xml::sax::XLocator > const & /*xLocator*/ )
150 throw (xml::sax::SAXException, RuntimeException)
153 //__________________________________________________________________________________________________
154 Reference< xml::input::XElement > ModuleImport::startRootElement(
155 sal_Int32 nUid, OUString const & rLocalName,
156 Reference< xml::input::XAttributes > const & xAttributes )
157 throw (xml::sax::SAXException, RuntimeException)
159 if (XMLNS_SCRIPT_UID != nUid)
161 throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
163 // window
164 else if ( rLocalName == "module" )
166 mrModuleDesc.aName = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "name" );
167 mrModuleDesc.aLanguage = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "language" );
168 mrModuleDesc.aModuleType = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "moduleType" );
170 return new ModuleElement( rLocalName, xAttributes, 0, this );
172 else
174 throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName, Reference< XInterface >(), Any() );
177 //__________________________________________________________________________________________________
178 ModuleImport::~ModuleImport()
179 SAL_THROW(())
181 #if OSL_DEBUG_LEVEL > 1
182 OSL_TRACE( "ModuleImport::~ModuleImport()." );
183 #endif
186 //##################################################################################################
188 Reference< xml::sax::XDocumentHandler >
189 SAL_CALL importScriptModule( ModuleDescriptor& rMod )
190 SAL_THROW( (Exception) )
192 return ::xmlscript::createDocumentHandler(
193 static_cast< xml::input::XRoot * >( new ModuleImport( rMod ) ) );
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */