LibreOffice Module xmloff (master)  1
XMLIndexTOCSourceContext.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 <sax/tools/converter.hxx>
25 #include <xmloff/xmlictxt.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/txtimp.hxx>
28 #include <xmloff/xmlnmspe.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <rtl/ustring.hxx>
31 
32 
33 using namespace ::xmloff::token;
34 
35 using ::com::sun::star::beans::XPropertySet;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 
41  SvXMLImport& rImport,
42  sal_uInt16 nPrfx,
43  const OUString& rLocalName,
44  Reference<XPropertySet> & rPropSet)
45 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, true)
46  // use all chapters by default
47 , nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
48 , bUseOutline(true)
49 , bUseMarks(true)
50 , bUseParagraphStyles(false)
51 {
52 }
53 
55 {
56 }
57 
59  enum IndexSourceParamEnum eParam,
60  const OUString& rValue)
61 {
62  switch (eParam)
63  {
65  if ( IsXMLToken( rValue, XML_NONE ) )
66  {
67  // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
68  // OUTLINE_LEVEL with values none|1..10. For backwards
69  // compatibility, 'none' must still be read.
70  bUseOutline = false;
71  }
72  else
73  {
74  sal_Int32 nTmp;
76  nTmp, rValue, 1, GetImport().GetTextImport()->
77  GetChapterNumbering()->getCount()))
78  {
79  bUseOutline = true;
80  nOutlineLevel = nTmp;
81  }
82  }
83  break;
84 
86  {
87  bool bTmp(false);
88  if (::sax::Converter::convertBool(bTmp, rValue))
89  {
90  bUseOutline = bTmp;
91  }
92  break;
93  }
94 
95 
97  {
98  bool bTmp(false);
99  if (::sax::Converter::convertBool(bTmp, rValue))
100  {
101  bUseMarks = bTmp;
102  }
103  break;
104  }
105 
107  {
108  bool bTmp(false);
109  if (::sax::Converter::convertBool(bTmp, rValue))
110  {
111  bUseParagraphStyles = bTmp;
112  }
113  break;
114  }
115 
116  default:
117  // default: ask superclass
119  break;
120  }
121 }
122 
124 {
125  rIndexPropertySet->setPropertyValue("CreateFromMarks", css::uno::Any(bUseMarks));
126  rIndexPropertySet->setPropertyValue("CreateFromOutline", css::uno::Any(bUseOutline));
127  rIndexPropertySet->setPropertyValue("CreateFromLevelParagraphStyles", css::uno::Any(bUseParagraphStyles));
128 
129  rIndexPropertySet->setPropertyValue("Level", css::uno::Any(static_cast<sal_Int16>(nOutlineLevel)));
130 
131  // process common attributes
133 }
134 
136  sal_uInt16 nPrefix,
137  const OUString& rLocalName,
138  const Reference<XAttributeList> & xAttrList )
139 {
140  if ( (XML_NAMESPACE_TEXT == nPrefix) &&
142  {
144  nPrefix, rLocalName,
148  aAllowedTokenTypesTOC, true );
149  }
150  else
151  {
153  rLocalName,
154  xAttrList);
155  }
156 }
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
static bool convertBool(bool &rBool, const OUString &rString)
const char * aLevelStylePropNameTOCMap[]
Superclass for index source elements.
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
const bool aAllowedTokenTypesTOC[]
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
virtual ~XMLIndexTOCSourceContext() override
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
virtual void ProcessAttribute(enum IndexSourceParamEnum eParam, const OUString &rValue) override
virtual void ProcessAttribute(enum IndexSourceParamEnum eParam, const OUString &rValue)
XMLIndexTOCSourceContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, css::uno::Reference< css::beans::XPropertySet > &rPropSet)
Import index entry templates.
css::uno::Reference< css::beans::XPropertySet > & rIndexPropertySet
tab stops relative to margin or indent?
Handling of tokens in XML:
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
const SvXMLEnumMapEntry< sal_uInt16 > aSvLevelNameTOCMap[]
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)