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/namespacemap.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <sal/log.hxx>
27 
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 
31 
32 using ::com::sun::star::beans::XPropertySet;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::xml::sax::XAttributeList;
38 
39 
41  SvXMLImport& rImport,
42  Reference<XPropertySet> & rPropSet)
43 : SvXMLImportContext(rImport)
44 , bStyleNameOK(false)
45 , rTOCPropertySet(rPropSet)
46 {
47 }
48 
49 
51 {
52 }
53 
55  sal_Int32 /*nElement*/,
56  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
57 {
58  // there's only one attribute: style-name
59  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
60  {
61  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
62  {
63  sStyleName = aIter.toString();
64  OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
66  const Reference < css::container::XNameContainer >&
67  rStyles = GetImport().GetTextImport()->GetParaStyles();
68  bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
69  }
70  else
71  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
72  }
73 }
74 
76 {
77  Any aAny;
78 
79  aAny <<= sContent.makeStringAndClear();
80  rTOCPropertySet->setPropertyValue("Title", aAny);
81 
82  if (bStyleNameOK)
83  {
84  aAny <<= GetImport().GetStyleDisplayName(
86  sStyleName );
87  rTOCPropertySet->setPropertyValue("ParaStyleHeading", aAny);
88  }
89 }
90 
92  const OUString& sString)
93 {
94  sContent.append(sString);
95 }
96 
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3508
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:600
css::uno::Reference< css::beans::XPropertySet > & rTOCPropertySet
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
virtual void SAL_CALL characters(const OUString &sString) override
pick up title characters
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
process parameters
XMLIndexTitleTemplateContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > &rPropSet)
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:1406
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
set values
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
TEXT