Bump version to 6.4.0.12
[LibreOffice.git] / xmloff / source / core / xmlictxt.cxx
blob092b1845c18c8f46ca7474ba94235594bc8c8c3d
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 <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>
27 using namespace ::com::sun::star;
29 SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp, sal_uInt16 nPrfx,
30 const OUString& rLName )
31 : m_nRefCount(0)
32 , mrImport(rImp)
33 , mnPrefix(nPrfx)
34 , maLocalName(rLName)
38 SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp )
39 : m_nRefCount(0)
40 , mrImport(rImp)
41 , mnPrefix(0)
45 SvXMLImportContext::~SvXMLImportContext()
49 SvXMLImportContextRef SvXMLImportContext::CreateChildContext( sal_uInt16 nPrefix,
50 const OUString& rLocalName,
51 const uno::Reference<xml::sax::XAttributeList>& )
53 return new SvXMLImportContext(mrImport, nPrefix, rLocalName);
56 void SvXMLImportContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& )
60 void SvXMLImportContext::EndElement()
64 void SvXMLImportContext::Characters( const OUString& )
68 // css::xml::sax::XFastContextHandler:
69 void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
71 mrImport.isFastContext = false;
72 const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &GetImport().GetNamespaceMap());
73 const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
74 startUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName, Attribs );
77 void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamespace*/, const OUString & rElementName,
78 const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
80 if ( mrImport.maAttrList.is() )
81 mrImport.maAttrList->Clear();
82 else
83 mrImport.maAttrList = new comphelper::AttributeList;
85 mrImport.maNamespaceHandler->addNSDeclAttributes( mrImport.maAttrList );
87 if ( Attribs.is() )
89 sax_fastparser::FastAttributeList *pAttribList =
90 sax_fastparser::FastAttributeList::castToFastAttributeList( Attribs );
92 for( auto &it : *pAttribList )
94 sal_Int32 nToken = it.getToken();
95 const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetImport().GetNamespaceMap());
96 OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
97 if ( !rAttrNamespacePrefix.isEmpty() )
98 sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
100 mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() );
103 const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
104 for ( const auto& rUnknownAttrib : unknownAttribs )
106 const OUString& rAttrValue = rUnknownAttrib.Value;
107 const OUString& rAttrName = rUnknownAttrib.Name;
108 // note: rAttrName is expected to be namespace-prefixed here
109 mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
112 mrImport.startElement( rElementName, mrImport.maAttrList.get() );
115 void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement)
117 mrImport.isFastContext = false;
118 const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &GetImport().GetNamespaceMap());
119 const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
120 endUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName );
123 void SAL_CALL SvXMLImportContext::endUnknownElement (const OUString & /*rNamespace*/, const OUString & rElementName)
125 mrImport.endElement( rElementName );
128 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createFastChildContext
129 (sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
131 // Call CreateFastContext only if it's the first element of the document
132 if ( mrImport.maFastContexts.empty() )
133 return mrImport.CreateFastContext( Element, Attribs );
134 else
135 return new SvXMLImportContext( GetImport() );
138 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createUnknownChildContext
139 (const OUString &, const OUString &, const uno::Reference< xml::sax::XFastAttributeList > &)
141 return this;
144 void SAL_CALL SvXMLImportContext::characters(const OUString &rChars)
146 mrImport.Characters( rChars );
149 // XInterface
150 css::uno::Any SAL_CALL SvXMLImportContext::queryInterface( const css::uno::Type& aType )
152 css::uno::Any a = ::cppu::queryInterface(
153 aType,
154 static_cast< XFastContextHandler* >(this),
155 static_cast< XTypeProvider* >(this),
156 static_cast< css::uno::XInterface* >(static_cast< XFastContextHandler* >(this)));
158 return a;
161 // XTypeProvider
162 css::uno::Sequence< css::uno::Type > SAL_CALL SvXMLImportContext::getTypes()
164 return { cppu::UnoType<XFastContextHandler>::get(),
165 cppu::UnoType<XTypeProvider>::get() };
168 css::uno::Sequence< sal_Int8 > SAL_CALL SvXMLImportContext::getImplementationId()
170 return css::uno::Sequence<sal_Int8>();
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */