LibreOffice Module xmlscript (master) 1
xmlmod_import.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <xmlscript/xmlns.h>
23#include <com/sun/star/xml/sax/SAXException.hpp>
24#include <sal/log.hxx>
25
26#include "imp_share.hxx"
27#include <utility>
28#include <xml_import.hxx>
29
30using namespace css;
31using namespace css::uno;
32
33namespace xmlscript
34{
35
36Reference< xml::input::XElement > ModuleElement::getParent()
37{
38 return nullptr;
39}
41{
42 return _aLocalName;
43}
45{
46 return mxImport->XMLNS_SCRIPT_UID;
47}
48Reference< xml::input::XAttributes > ModuleElement::getAttributes()
49{
50 return _xAttributes;
51}
52
54 OUString const & /*rWhitespaces*/ )
55{
56 // not used
57}
58
59void ModuleElement::characters( OUString const & rChars )
60{
61 _strBuffer.append( rChars );
62}
63
65 OUString const & /*rTarget*/, OUString const & /*rData*/ )
66{
67}
68
70{
71 mxImport->mrModuleDesc.aCode = _strBuffer.makeStringAndClear();
72}
73
74Reference< xml::input::XElement > ModuleElement::startChildElement(
75 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
76 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
77{
78 throw xml::sax::SAXException("unexpected element!", Reference< XInterface >(), Any() );
79}
80
82 OUString aLocalName,
83 Reference< xml::input::XAttributes > const & xAttributes,
84 ModuleImport * pImport )
85 : mxImport( pImport )
86 , _aLocalName(std::move( aLocalName ))
87 , _xAttributes( xAttributes )
88{
89}
90
92{
93 SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << _aLocalName );
94}
95
96// XRoot
97
99 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
100{
101 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
102}
103
105{
106 // ignored
107}
108
110 OUString const & /*rTarget*/, OUString const & /*rData*/ )
111{
112}
113
115 Reference< xml::sax::XLocator > const & /*xLocator*/ )
116{
117}
118
119Reference< xml::input::XElement > ModuleImport::startRootElement(
120 sal_Int32 nUid, OUString const & rLocalName,
121 Reference< xml::input::XAttributes > const & xAttributes )
122{
123 if (XMLNS_SCRIPT_UID != nUid)
124 {
125 throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
126 }
127 // window
128 else if ( rLocalName == "module" )
129 {
130 mrModuleDesc.aName = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "name" );
131 mrModuleDesc.aLanguage = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "language" );
132 mrModuleDesc.aModuleType = xAttributes->getValueByUidName( XMLNS_SCRIPT_UID, "moduleType" );
133
134 return new ModuleElement( rLocalName, xAttributes, this );
135 }
136 else
137 {
138 throw xml::sax::SAXException("illegal root element (expected module) given: " + rLocalName, Reference< XInterface >(), Any() );
139 }
140}
141
143{
144 SAL_INFO("xmlscript.xmlmod", "ModuleImport::~ModuleImport()." );
145}
146
147Reference< xml::sax::XDocumentHandler >
149{
151}
152
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL ignorableWhitespace(OUString const &rWhitespaces) override
virtual sal_Int32 SAL_CALL getUid() override
virtual void SAL_CALL processingInstruction(OUString const &rTarget, OUString const &rData) override
virtual css::uno::Reference< css::xml::input::XAttributes > SAL_CALL getAttributes() override
css::uno::Reference< css::xml::input::XAttributes > _xAttributes
rtl::Reference< ModuleImport > mxImport
virtual ~ModuleElement() override
virtual void SAL_CALL characters(OUString const &rChars) override
virtual void SAL_CALL endElement() override
ModuleElement(OUString aLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, ModuleImport *pImport)
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
virtual OUString SAL_CALL getLocalName() override
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL getParent() override
#define SAL_INFO(area, stream)
Reference< xml::sax::XDocumentHandler > importScriptModule(ModuleDescriptor &rMod)
css::uno::Reference< css::xml::sax::XDocumentHandler > createDocumentHandler(css::uno::Reference< css::xml::input::XRoot > const &xRoot)
Creates a document handler to be used for SAX1 parser that can handle namespaces.
virtual void SAL_CALL endDocument() override
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startRootElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
virtual void SAL_CALL processingInstruction(OUString const &rTarget, OUString const &rData) override
virtual void SAL_CALL startDocument(css::uno::Reference< css::xml::input::XNamespaceMapping > const &xNamespaceMapping) override
virtual void SAL_CALL setDocumentLocator(css::uno::Reference< css::xml::sax::XLocator > const &xLocator) override
virtual ~ModuleImport() override
constexpr OUStringLiteral XMLNS_SCRIPT_URI
Definition: xmlns.h:26