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 <com/sun/star/xml/sax/XAttributeList.hpp>
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/xmlictxt.hxx>
23 #include <sax/fastattribs.hxx>
24 #include <comphelper/attributelist.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26 #include <sal/log.hxx>
28 using namespace ::com::sun::star
;
30 SvXMLImportContext::SvXMLImportContext( SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
31 const OUString
& rLName
)
36 , mbPrefixAndLocalNameFilledIn(true)
40 SvXMLImportContext::SvXMLImportContext( SvXMLImport
& rImp
)
44 , mbPrefixAndLocalNameFilledIn(false)
48 SvXMLImportContext::~SvXMLImportContext()
52 SvXMLImportContextRef
SvXMLImportContext::CreateChildContext( sal_uInt16
/*nPrefix*/,
53 const OUString
& /*rLocalName*/,
54 const uno::Reference
<xml::sax::XAttributeList
>& )
59 void SvXMLImportContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& )
63 void SvXMLImportContext::endFastElement(sal_Int32
)
67 // css::xml::sax::XFastContextHandler:
68 void SAL_CALL
SvXMLImportContext::startFastElement(sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
70 const OUString
& rPrefix
= SvXMLImport::getNamespacePrefixFromToken(nElement
, &GetImport().GetNamespaceMap());
71 const OUString
& rLocalName
= SvXMLImport::getNameFromToken( nElement
);
72 startUnknownElement( SvXMLImport::aDefaultNamespace
, (rPrefix
.isEmpty())? rLocalName
: rPrefix
+ SvXMLImport::aNamespaceSeparator
+ rLocalName
, Attribs
);
73 mrImport
.maAttrList
->Clear();
74 mrImport
.maNamespaceHandler
->addNSDeclAttributes( mrImport
.maAttrList
);
76 for( auto &it
: sax_fastparser::castToFastAttributeList( Attribs
) )
78 sal_Int32 nToken
= it
.getToken();
79 const OUString
& rAttrNamespacePrefix
= SvXMLImport::getNamespacePrefixFromToken(nToken
, &GetImport().GetNamespaceMap());
80 OUString sAttrName
= SvXMLImport::getNameFromToken( nToken
);
81 if ( !rAttrNamespacePrefix
.isEmpty() )
82 sAttrName
= rAttrNamespacePrefix
+ SvXMLImport::aNamespaceSeparator
+ sAttrName
;
84 mrImport
.maAttrList
->AddAttribute( sAttrName
, "CDATA", it
.toString() );
87 const uno::Sequence
< xml::Attribute
> unknownAttribs
= Attribs
->getUnknownAttributes();
88 for ( const auto& rUnknownAttrib
: unknownAttribs
)
90 const OUString
& rAttrValue
= rUnknownAttrib
.Value
;
91 const OUString
& rAttrName
= rUnknownAttrib
.Name
;
92 // note: rAttrName is expected to be namespace-prefixed here
93 mrImport
.maAttrList
->AddAttribute( rAttrName
, "CDATA", rAttrValue
);
95 StartElement( mrImport
.maAttrList
.get() );
98 void SAL_CALL
SvXMLImportContext::startUnknownElement(const OUString
& /*rNamespace*/, const OUString
& /*rElementName*/,
99 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
103 void SAL_CALL
SvXMLImportContext::endUnknownElement (const OUString
& /*rNamespace*/, const OUString
& /*rElementName*/)
107 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
SvXMLImportContext::createFastChildContext
108 (sal_Int32
/*Element*/, const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
113 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
SvXMLImportContext::createUnknownChildContext
114 (const OUString
& /*rNamespace*/, const OUString
& /*rName*/, const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
119 void SAL_CALL
SvXMLImportContext::characters(const OUString
&/*rChars*/)
124 css::uno::Any SAL_CALL
SvXMLImportContext::queryInterface( const css::uno::Type
& aType
)
126 css::uno::Any a
= ::cppu::queryInterface(
128 static_cast< XFastContextHandler
* >(this),
129 static_cast< XTypeProvider
* >(this),
130 static_cast< css::uno::XInterface
* >(static_cast< XFastContextHandler
* >(this)));
136 css::uno::Sequence
< css::uno::Type
> SAL_CALL
SvXMLImportContext::getTypes()
138 return { cppu::UnoType
<XFastContextHandler
>::get(),
139 cppu::UnoType
<XTypeProvider
>::get() };
142 css::uno::Sequence
< sal_Int8
> SAL_CALL
SvXMLImportContext::getImplementationId()
144 return css::uno::Sequence
<sal_Int8
>();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */