LibreOffice Module xmloff (master)  1
XMLSectionSourceImportContext.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 
22 #include <com/sun/star/text/SectionFileLink.hpp>
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/namespacemap.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 
31 
32 using ::com::sun::star::beans::XPropertySet;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::xml::sax::XAttributeList;
35 
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::text;
38 using namespace ::xmloff::token;
39 
40 
42  SvXMLImport& rImport,
43  sal_uInt16 nPrfx,
44  const OUString& rLocalName,
45  Reference<XPropertySet> & rSectPropSet) :
46  SvXMLImportContext(rImport, nPrfx, rLocalName),
47  rSectionPropertySet(rSectPropSet)
48 {
49 }
50 
52 {
53 }
54 
55 namespace {
57 {
58  XML_TOK_SECTION_XLINK_HREF,
59  XML_TOK_SECTION_TEXT_FILTER_NAME,
60  XML_TOK_SECTION_TEXT_SECTION_NAME
61 };
62 
63 }
64 
66 {
67  { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF },
68  { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME },
70  XML_TOK_SECTION_TEXT_SECTION_NAME },
72 };
73 
74 
76  const Reference<XAttributeList> & xAttrList)
77 {
78  static const SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
79  OUString sURL;
80  OUString sFilterName;
81  OUString sSectionName;
82 
83  sal_Int16 nLength = xAttrList->getLength();
84  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85  {
86  OUString sLocalName;
87  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89  &sLocalName );
90 
91  switch (aTokenMap.Get(nPrefix, sLocalName))
92  {
93  case XML_TOK_SECTION_XLINK_HREF:
94  sURL = xAttrList->getValueByIndex(nAttr);
95  break;
96 
97  case XML_TOK_SECTION_TEXT_FILTER_NAME:
98  sFilterName = xAttrList->getValueByIndex(nAttr);
99  break;
100 
101  case XML_TOK_SECTION_TEXT_SECTION_NAME:
102  sSectionName = xAttrList->getValueByIndex(nAttr);
103  break;
104 
105  default:
106  ; // ignore
107  break;
108  }
109  }
110 
111  if (!sURL.isEmpty() || !sFilterName.isEmpty())
112  {
113  SectionFileLink aFileLink;
114  aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL );
115  aFileLink.FilterName = sFilterName;
116 
117  rSectionPropertySet->setPropertyValue("FileLink", Any(aFileLink));
118  }
119 
120  if (!sSectionName.isEmpty())
121  {
122  rSectionPropertySet->setPropertyValue("LinkRegion", Any(sSectionName));
123  }
124 }
125 
127 {
128  // this space intentionally left blank.
129 }
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XMLTokenEnum const aTokenMap[]
Definition: Oasis2OOo.cxx:1145
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
constexpr sal_uInt16 XML_NAMESPACE_XLINK
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
XMLSectionSourceImportContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, css::uno::Reference< css::beans::XPropertySet > &rSectPropSet)
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
css::uno::Reference< css::beans::XPropertySet > & rSectionPropertySet
constexpr sal_uInt16 XML_NAMESPACE_TEXT
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
const SvXMLTokenMapEntry aSectionSourceTokenMap[]
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1690
Handling of tokens in XML:
sal_Int32 nLength
Definition: xmltoken.cxx:36