LibreOffice Module xmloff (master)  1
xmlictxt.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 <com/sun/star/xml/sax/XAttributeList.hpp>
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/xmlictxt.hxx>
23 #include <sax/fastattribs.hxx>
26 #include <sal/log.hxx>
27 
28 using namespace ::com::sun::star;
29 
31  const OUString& rLName )
32  : mrImport(rImp)
33  , maLocalName(rLName)
34  , m_nRefCount(0)
35  , mnPrefix(nPrfx)
36  , mbPrefixAndLocalNameFilledIn(true)
37 {
38 }
39 
41  : mrImport(rImp)
42  , m_nRefCount(0)
43  , mnPrefix(0)
44  , mbPrefixAndLocalNameFilledIn(false)
45 {
46 }
47 
49 {
50 }
51 
53  const OUString& /*rLocalName*/,
54  const uno::Reference<xml::sax::XAttributeList>& )
55 {
56  return nullptr;
57 }
58 
59 void SvXMLImportContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& )
60 {
61 }
62 
64 {
65 }
66 
67 // css::xml::sax::XFastContextHandler:
68 void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
69 {
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 );
75 
76  for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) )
77  {
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;
83 
84  mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() );
85  }
86 
87  const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
88  for ( const auto& rUnknownAttrib : unknownAttribs )
89  {
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 );
94  }
96 }
97 
98 void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamespace*/, const OUString & /*rElementName*/,
99  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
100 {
101 }
102 
103 void SAL_CALL SvXMLImportContext::endUnknownElement (const OUString & /*rNamespace*/, const OUString & /*rElementName*/)
104 {
105 }
106 
107 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createFastChildContext
108  (sal_Int32 /*Element*/, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
109 {
110  return nullptr;
111 }
112 
113 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createUnknownChildContext
114  (const OUString & /*rNamespace*/, const OUString & /*rName*/, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
115 {
116  return nullptr;
117 }
118 
119 void SAL_CALL SvXMLImportContext::characters(const OUString &/*rChars*/)
120 {
121 }
122 
123 // XInterface
124 css::uno::Any SAL_CALL SvXMLImportContext::queryInterface( const css::uno::Type& aType )
125 {
126  css::uno::Any a = ::cppu::queryInterface(
127  aType,
128  static_cast< XFastContextHandler* >(this),
129  static_cast< XTypeProvider* >(this),
130  static_cast< css::uno::XInterface* >(static_cast< XFastContextHandler* >(this)));
131 
132  return a;
133 }
134 
135 // XTypeProvider
136 css::uno::Sequence< css::uno::Type > SAL_CALL SvXMLImportContext::getTypes()
137 {
140 }
141 
142 css::uno::Sequence< sal_Int8 > SAL_CALL SvXMLImportContext::getImplementationId()
143 {
144  return css::uno::Sequence<sal_Int8>();
145 }
146 
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & mrImport
Definition: xmlictxt.hxx:51
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
Definition: xmlictxt.cxx:103
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:68
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
StartElement is called after a context has been constructed and before an elements context is parsed...
Definition: xmlictxt.cxx:59
static constexpr OUStringLiteral aNamespaceSeparator
Definition: xmlimp.hxx:528
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:98
static constexpr OUStringLiteral aDefaultNamespace
Definition: xmlimp.hxx:527
virtual ~SvXMLImportContext()
A contexts destructor does anything that is required if an element ends.
Definition: xmlictxt.cxx:48
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) final override
Definition: xmlictxt.cxx:124
uno_Any a
rtl::Reference< SvXMLImportFastNamespaceHandler > maNamespaceHandler
Definition: xmlimp.hxx:230
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() final override
Definition: xmlictxt.cxx:142
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() final override
Definition: xmlictxt.cxx:136
static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap *pMap)
Definition: xmlimp.cxx:2004
css::uno::Type const & get()
rtl::Reference< comphelper::AttributeList > maAttrList
Definition: xmlimp.hxx:231
SvXMLImportContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName)
A contexts constructor does anything that is required if an element starts.
Definition: xmlictxt.cxx:30
static const OUString & getNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1989
DefTokenId nToken
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmlictxt.cxx:63
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:108
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Create a children element context.
Definition: xmlictxt.cxx:52
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
Definition: xmlictxt.cxx:119
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:114