Avoid new string allocations, when only checking if empty
[LibreOffice.git] / xmlscript / source / xmlmod_imexp / xmlmod_import.cxx
blob151ea458a434aa4026337be6b1f258bd58240d86
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 <sal/config.h>
22 #include <xmlscript/xmlns.h>
23 #include <com/sun/star/xml/sax/SAXException.hpp>
24 #include <sal/log.hxx>
26 #include "imp_share.hxx"
27 #include <utility>
28 #include <xml_import.hxx>
30 using namespace css;
31 using namespace css::uno;
33 namespace xmlscript
36 Reference< xml::input::XElement > ModuleElement::getParent()
38 return nullptr;
40 OUString ModuleElement::getLocalName()
42 return _aLocalName;
44 sal_Int32 ModuleElement::getUid()
46 return mxImport->XMLNS_SCRIPT_UID;
48 Reference< xml::input::XAttributes > ModuleElement::getAttributes()
50 return _xAttributes;
53 void ModuleElement::ignorableWhitespace(
54 OUString const & /*rWhitespaces*/ )
56 // not used
59 void ModuleElement::characters( OUString const & rChars )
61 _strBuffer.append( rChars );
64 void ModuleElement::processingInstruction(
65 OUString const & /*rTarget*/, OUString const & /*rData*/ )
69 void ModuleElement::endElement()
71 mxImport->mrModuleDesc.aCode = _strBuffer.makeStringAndClear();
74 Reference< xml::input::XElement > ModuleElement::startChildElement(
75 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
76 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
78 throw xml::sax::SAXException(u"unexpected element!"_ustr, Reference< XInterface >(), Any() );
81 ModuleElement::ModuleElement(
82 OUString aLocalName,
83 Reference< xml::input::XAttributes > const & xAttributes,
84 ModuleImport * pImport )
85 : mxImport( pImport )
86 , _aLocalName(std::move( aLocalName ))
87 , _xAttributes( xAttributes )
91 ModuleElement::~ModuleElement()
93 SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << _aLocalName );
96 // XRoot
98 void ModuleImport::startDocument(
99 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
101 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
104 void ModuleImport::endDocument()
106 // ignored
109 void ModuleImport::processingInstruction(
110 OUString const & /*rTarget*/, OUString const & /*rData*/ )
114 void ModuleImport::setDocumentLocator(
115 Reference< xml::sax::XLocator > const & /*xLocator*/ )
119 Reference< xml::input::XElement > ModuleImport::startRootElement(
120 sal_Int32 nUid, OUString const & rLocalName,
121 Reference< xml::input::XAttributes > const & xAttributes )
123 if (XMLNS_SCRIPT_UID != nUid)
125 throw xml::sax::SAXException( u"illegal namespace!"_ustr, Reference< XInterface >(), Any() );
127 // window
128 else if ( rLocalName == "module" )
130 mrModuleDesc.aName = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, u"name"_ustr );
131 mrModuleDesc.aLanguage = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, u"language"_ustr );
132 mrModuleDesc.aModuleType = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, u"moduleType"_ustr );
134 return new ModuleElement( rLocalName, xAttributes, this );
136 else
138 throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName, Reference< XInterface >(), Any() );
142 ModuleImport::~ModuleImport()
144 SAL_INFO("xmlscript.xmlmod", "ModuleImport::~ModuleImport()." );
147 Reference< xml::sax::XDocumentHandler >
148 importScriptModule( ModuleDescriptor& rMod )
150 return ::xmlscript::createDocumentHandler(new ModuleImport(rMod));
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */