LibreOffice Module xmloff (master)  1
XMLIndexTOCStylesContext.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 <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XIndexReplace.hpp>
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/txtimp.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <sax/tools/converter.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <rtl/ustring.hxx>
32 
33 
34 using namespace ::xmloff::token;
35 
36 using ::com::sun::star::beans::XPropertySet;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::container::XIndexReplace;
41 using ::com::sun::star::xml::sax::XAttributeList;
42 
43 
44 
46  SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
47  : SvXMLImportContext(rImport)
48  , rTOCPropertySet(rPropSet)
49  , nOutlineLevel(0)
50 {
51 }
52 
54 {
55 }
56 
58  sal_Int32 /*nElement*/,
59  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
60 {
61  // find text:outline-level attribute
62  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
63  {
64  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL) )
65  {
66  sal_Int32 nTmp;
68  nTmp, aIter.toView(), 1,
69  GetImport().GetTextImport()->GetChapterNumbering()->
70  getCount()))
71  {
72  // API numbers 0..9, we number 1..10
73  nOutlineLevel = nTmp-1;
74  }
75  break;
76  }
77  }
78 }
79 
81 {
82  // if valid...
83  if (nOutlineLevel < 0)
84  return;
85 
86  // copy vector into sequence
87  const sal_Int32 nCount = aStyleNames.size();
88  Sequence<OUString> aStyleNamesSequence(nCount);
89  for(sal_Int32 i = 0; i < nCount; i++)
90  {
91  aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
93  aStyleNames[i] );
94  }
95 
96  // get index replace
97  Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
98  Reference<XIndexReplace> xIndexReplace;
99  aAny >>= xIndexReplace;
100 
101  // set style names
102  xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
103 }
104 
105 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
106  sal_Int32 nElement,
107  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
108 {
109  // check for index-source-style
110  if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
111  {
112  // find text:style-name attribute and record in aStyleNames
113  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
114  {
115  if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
116  {
117  aStyleNames.push_back(aIter.toString());
118  break;
119  }
120  }
121  }
122 
123  // always return default context; we already got the interesting info
124  return new SvXMLImportContext(GetImport());
125 }
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:600
::std::vector< OUString > aStyleNames
style names for this level
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
int nCount
int i
SvXMLImportContext(SvXMLImport &rImport)
A contexts constructor does anything that is required if an element starts.
Definition: xmlictxt.cxx:30
XMLIndexTOCStylesContext(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
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
css::uno::Reference< css::beans::XPropertySet > & rTOCPropertySet
XPropertySet of the index.
sal_Int32 nOutlineLevel
outline level
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual ~XMLIndexTOCStylesContext() override
TEXT
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)