1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <xml_import.hxx>
30 using namespace css::uno
;
35 Reference
< xml::input::XElement
> ModuleElement::getParent()
39 OUString
ModuleElement::getLocalName()
43 sal_Int32
ModuleElement::getUid()
45 return mxImport
->XMLNS_SCRIPT_UID
;
47 Reference
< xml::input::XAttributes
> ModuleElement::getAttributes()
52 void ModuleElement::ignorableWhitespace(
53 OUString
const & /*rWhitespaces*/ )
58 void ModuleElement::characters( OUString
const & rChars
)
60 _strBuffer
.append( rChars
);
63 void ModuleElement::processingInstruction(
64 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
68 void ModuleElement::endElement()
70 mxImport
->mrModuleDesc
.aCode
= _strBuffer
.makeStringAndClear();
73 Reference
< xml::input::XElement
> ModuleElement::startChildElement(
74 sal_Int32
/*nUid*/, OUString
const & /*rLocalName*/,
75 Reference
< xml::input::XAttributes
> const & /*xAttributes*/ )
77 throw xml::sax::SAXException("unexpected element!", Reference
< XInterface
>(), Any() );
80 ModuleElement::ModuleElement(
81 OUString
const & rLocalName
,
82 Reference
< xml::input::XAttributes
> const & xAttributes
,
83 ModuleImport
* pImport
)
85 , _aLocalName( rLocalName
)
86 , _xAttributes( xAttributes
)
90 ModuleElement::~ModuleElement()
92 SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << _aLocalName
);
97 void ModuleImport::startDocument(
98 Reference
< xml::input::XNamespaceMapping
> const & xNamespaceMapping
)
100 XMLNS_SCRIPT_UID
= xNamespaceMapping
->getUidByUri( XMLNS_SCRIPT_URI
);
103 void ModuleImport::endDocument()
108 void ModuleImport::processingInstruction(
109 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
113 void ModuleImport::setDocumentLocator(
114 Reference
< xml::sax::XLocator
> const & /*xLocator*/ )
118 Reference
< xml::input::XElement
> ModuleImport::startRootElement(
119 sal_Int32 nUid
, OUString
const & rLocalName
,
120 Reference
< xml::input::XAttributes
> const & xAttributes
)
122 if (XMLNS_SCRIPT_UID
!= nUid
)
124 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
127 else if ( rLocalName
== "module" )
129 mrModuleDesc
.aName
= xAttributes
->getValueByUidName( XMLNS_SCRIPT_UID
, "name" );
130 mrModuleDesc
.aLanguage
= xAttributes
->getValueByUidName( XMLNS_SCRIPT_UID
, "language" );
131 mrModuleDesc
.aModuleType
= xAttributes
->getValueByUidName( XMLNS_SCRIPT_UID
, "moduleType" );
133 return new ModuleElement( rLocalName
, xAttributes
, this );
137 throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName
, Reference
< XInterface
>(), Any() );
141 ModuleImport::~ModuleImport()
143 SAL_INFO("xmlscript.xmlmod", "ModuleImport::~ModuleImport()." );
146 Reference
< xml::sax::XDocumentHandler
>
147 importScriptModule( ModuleDescriptor
& rMod
)
149 return ::xmlscript::createDocumentHandler(new ModuleImport(rMod
));
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */