LibreOffice Module xmloff (master)  1
XMLIndexTitleTemplateContext.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 
21 #include <xmloff/xmlictxt.hxx>
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 
30 
31 using ::com::sun::star::beans::XPropertySet;
32 using ::com::sun::star::uno::Any;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::xml::sax::XAttributeList;
37 
38 
40  SvXMLImport& rImport,
41  Reference<XPropertySet> & rPropSet,
42  sal_uInt16 nPrfx,
43  const OUString& rLocalName)
44 : SvXMLImportContext(rImport, nPrfx, rLocalName)
45 , bStyleNameOK(false)
46 , rTOCPropertySet(rPropSet)
47 {
48 }
49 
50 
52 {
53 }
54 
56  const Reference<XAttributeList> & xAttrList)
57 {
58  // there's only one attribute: style-name
59  sal_Int16 nLength = xAttrList->getLength();
60  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
61  {
62  OUString sLocalName;
63  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
64  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
65  &sLocalName );
66  if ( (XML_NAMESPACE_TEXT == nPrefix) &&
67  (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
68  {
69  sStyleName = xAttrList->getValueByIndex(nAttr);
70  OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
72  const Reference < css::container::XNameContainer >&
73  rStyles = GetImport().GetTextImport()->GetParaStyles();
74  bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
75  }
76  }
77 }
78 
80 {
81  Any aAny;
82 
83  aAny <<= sContent.makeStringAndClear();
84  rTOCPropertySet->setPropertyValue("Title", aAny);
85 
86  if (bStyleNameOK)
87  {
88  aAny <<= GetImport().GetStyleDisplayName(
90  sStyleName );
91  rTOCPropertySet->setPropertyValue("ParaStyleHeading", aAny);
92  }
93 }
94 
96  const OUString& sString)
97 {
98  sContent.append(sString);
99 }
100 
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
XMLIndexTitleTemplateContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > &rPropSet, sal_uInt16 nPrfx, const OUString &rLocalName)
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:594
css::uno::Reference< css::beans::XPropertySet > & rTOCPropertySet
virtual void EndElement() override
set values
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
virtual void Characters(const OUString &sString) override
pick up title characters
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1491
sal_Int32 nLength
Definition: xmltoken.cxx:36