LibreOffice Module xmloff (master)  1
XMLIndexChapterInfoEntryContext.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 
20 
22 
23 #include <com/sun/star/text/ChapterFormat.hpp>
24 
25 #include <sax/tools/converter.hxx>
26 
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/namespacemap.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/xmlement.hxx>
34 
35 
36 using namespace ::com::sun::star::text;
37 using namespace ::xmloff::token;
38 
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 
44 
46  SvXMLImport& rImport,
47  XMLIndexTemplateContext& rTemplate,
48  sal_uInt16 nPrfx,
49  const OUString& rLocalName,
50  bool bT ) :
52  (bT ? OUString("TokenEntryNumber")
53  : OUString("TokenChapterInfo")),
54  rTemplate, nPrfx, rLocalName),
55  nChapterInfo(ChapterFormat::NAME_NUMBER),
56  bChapterInfoOK(false),
57  bTOC( bT ),
58  nOutlineLevel( 0 ),
59  bOutlineLevelOK(false)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  { XML_NAME, ChapterFormat::NAME },
70  { XML_NUMBER, ChapterFormat::NUMBER },
71  { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
72  //---> i89791
73  // enabled for ODF 1.2, full index support in 3.0
74  { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
75  { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
76  { XML_TOKEN_INVALID, 0 }
77 };
78 
80  const Reference<XAttributeList> & xAttrList)
81 {
82  // handle both, style name and bibliography info
83  sal_Int16 nLength = xAttrList->getLength();
84  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85  {
86  OUString sLocalName;
87  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89  &sLocalName );
90  if (XML_NAMESPACE_TEXT == nPrefix)
91  {
92  if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
93  {
94  m_sCharStyleName = xAttrList->getValueByIndex(nAttr);
95  m_bCharStyleNameOK = true;
96  }
97  else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
98  {
99  sal_uInt16 nTmp;
101  nTmp, xAttrList->getValueByIndex(nAttr),
103  {
104  nChapterInfo = nTmp;
105  bChapterInfoOK = true;
106  }
107  }
108  else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
109  {
110  sal_Int32 nTmp;
112  xAttrList->getValueByIndex(nAttr)))
113  {
114 //control on range is carried out in the UNO level
115  nOutlineLevel = static_cast<sal_uInt16>(nTmp);
116  bOutlineLevelOK = true;
117  }
118  }
119  }
120  }
121 
122  // if we have a style name, set it!
123  if (m_bCharStyleNameOK)
124  {
125  m_nValues++;
126  }
127 
128  // if we have chapter info, set it!
129  if (bChapterInfoOK)
130  {
131  m_nValues++;
132  /* Some of the index chapter information attributes written to ODF 1.1
133  and 1.2 don't reflect the displaying (#i89791#)
134  */
135  if ( !bTOC )
136  {
137  bool bConvert( false );
138  {
139  sal_Int32 nUPD( 0 );
140  sal_Int32 nBuild( 0 );
141  const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
142  if ( GetImport().IsTextDocInOOoFileFormat() ||
143  ( bBuildIdFound &&
144  ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
145  {
146  bConvert = true;
147  }
148  }
149  if ( bConvert )
150  {
151  if ( nChapterInfo == ChapterFormat::NUMBER )
152  {
153  nChapterInfo = ChapterFormat::DIGIT;
154  }
155  else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
156  {
157  nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
158  }
159  }
160  }
161  }
162  if (bOutlineLevelOK)
163  m_nValues++;
164 }
165 
167  css::uno::Sequence<css::beans::PropertyValue> & rValues)
168 {
169  // entry name and (optionally) style name in parent class
171 
172  sal_Int32 nIndex = m_bCharStyleNameOK ? 2 : 1;
173 
174  if( bChapterInfoOK )
175  {
176  // chapter info field
177  rValues[nIndex].Name = "ChapterFormat";
178  rValues[nIndex].Value <<= nChapterInfo;
179  nIndex++;
180  }
181  if( bOutlineLevelOK )
182  {
183  rValues[nIndex].Name = "ChapterLevel";
184  rValues[nIndex].Value <<= nOutlineLevel;
185  }
186 }
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
sal_Int32 nIndex
static bool convertEnum(EnumT &rEnum, const OUString &rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:128
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
XMLIndexChapterInfoEntryContext(SvXMLImport &rImport, XMLIndexTemplateContext &rTemplate, sal_uInt16 nPrfx, const OUString &rLocalName, bool bTOC)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
Import index entry templates.
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues) override
fill property values for this template entry
bool getBuildIds(sal_Int32 &rUPD, sal_Int32 &rBuild) const
returns the upd and build id (f.e.
Definition: xmlimp.cxx:1914
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Import index entry templates.
Handling of tokens in XML:
const SvXMLEnumMapEntry< sal_uInt16 > aChapterDisplayMap[]
sal_Int32 nLength
Definition: xmltoken.cxx:36
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)