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/xmlnmspe.hxx>
27 #include <xmloff/nmspmap.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  sal_uInt16 nPrfx, const OUString& rLocalName)
48  : SvXMLImportContext(rImport, nPrfx, rLocalName)
49  , rTOCPropertySet(rPropSet)
50  , nOutlineLevel(0)
51 {
52 }
53 
55 {
56 }
57 
59  const Reference<XAttributeList> & xAttrList )
60 {
61  // find text:outline-level attribute
62  sal_Int16 nCount = xAttrList->getLength();
63  for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
64  {
65  OUString sLocalName;
66  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
67  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
68  &sLocalName );
69  if ( (XML_NAMESPACE_TEXT == nPrefix) &&
70  (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
71  {
72  sal_Int32 nTmp;
74  nTmp, xAttrList->getValueByIndex(nAttr), 1,
75  GetImport().GetTextImport()->GetChapterNumbering()->
76  getCount()))
77  {
78  // API numbers 0..9, we number 1..10
79  nOutlineLevel = nTmp-1;
80  }
81  }
82  }
83 }
84 
86 {
87  // if valid...
88  if (nOutlineLevel >= 0)
89  {
90  // copy vector into sequence
91  const sal_Int32 nCount = aStyleNames.size();
92  Sequence<OUString> aStyleNamesSequence(nCount);
93  for(sal_Int32 i = 0; i < nCount; i++)
94  {
95  aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
97  aStyleNames[i] );
98  }
99 
100  // get index replace
101  Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
102  Reference<XIndexReplace> xIndexReplace;
103  aAny >>= xIndexReplace;
104 
105  // set style names
106  xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
107  }
108 }
109 
111  sal_uInt16 p_nPrefix,
112  const OUString& rLocalName,
113  const Reference<XAttributeList> & xAttrList )
114 {
115  // check for index-source-style
116  if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
117  IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
118  {
119  // find text:style-name attribute and record in aStyleNames
120  sal_Int16 nCount = xAttrList->getLength();
121  for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
122  {
123  OUString sLocalName;
124  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
125  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
126  &sLocalName );
127  if ( (XML_NAMESPACE_TEXT == nPrefix) &&
128  IsXMLToken( sLocalName, XML_STYLE_NAME ) )
129  {
130  aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
131  }
132  }
133  }
134 
135  // always return default context; we already got the interesting info
136  return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
137  xAttrList);
138 }
139 
140 /* 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
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
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...
XMLIndexTOCStylesContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > &rPropSet, sal_uInt16 nPrfx, const OUString &rLocalName)
::std::vector< OUString > aStyleNames
style names for this level
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
int nCount
int i
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
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
Handling of tokens in XML:
css::uno::Reference< css::beans::XPropertySet > & rTOCPropertySet
XPropertySet of the index.
sal_Int32 nOutlineLevel
outline level
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:51
virtual ~XMLIndexTOCStylesContext() override
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)