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 #include <sal/log.hxx>
27 
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmlement.hxx>
35 
36 
37 using namespace ::com::sun::star::text;
38 using namespace ::xmloff::token;
39 
40 using ::com::sun::star::beans::PropertyValue;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::xml::sax::XAttributeList;
44 
45 
47  SvXMLImport& rImport,
48  XMLIndexTemplateContext& rTemplate,
49  bool bT ) :
51  (bT ? OUString("TokenEntryNumber")
52  : OUString("TokenChapterInfo")),
53  rTemplate),
54  nChapterInfo(ChapterFormat::NAME_NUMBER),
55  bChapterInfoOK(false),
56  bTOC( bT ),
57  nOutlineLevel( 0 ),
58  bOutlineLevelOK(false)
59 {
60 }
61 
63 {
64 }
65 
67 {
68  { XML_NAME, ChapterFormat::NAME },
69  { XML_NUMBER, ChapterFormat::NUMBER },
70  { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
71  //---> i89791
72  // enabled for ODF 1.2, full index support in 3.0
73  { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
74  { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
75  { XML_TOKEN_INVALID, 0 }
76 };
77 
79  sal_Int32 /*nElement*/,
80  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
81 {
82  // handle both, style name and bibliography info
83  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
84  {
85  switch(aIter.getToken())
86  {
88  {
89  m_sCharStyleName = aIter.toString();
90  m_bCharStyleNameOK = true;
91  break;
92  }
93  case XML_ELEMENT(TEXT, XML_DISPLAY): //i53420, always true, in TOC as well
94  {
95  sal_uInt16 nTmp;
96  if (SvXMLUnitConverter::convertEnum(nTmp, aIter.toView(), aChapterDisplayMap))
97  {
98  nChapterInfo = nTmp;
99  bChapterInfoOK = true;
100  }
101  break;
102  }
104  {
105  sal_Int32 nTmp;
106  if (::sax::Converter::convertNumber(nTmp, aIter.toView()))
107  {
108 //control on range is carried out in the UNO level
109  nOutlineLevel = static_cast<sal_uInt16>(nTmp);
110  bOutlineLevelOK = true;
111  }
112  break;
113  }
114  default:
115  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
116  }
117  }
118 
119  // if we have a style name, set it!
120  if (m_bCharStyleNameOK)
121  {
122  m_nValues++;
123  }
124 
125  // if we have chapter info, set it!
126  if (bChapterInfoOK)
127  {
128  m_nValues++;
129  /* Some of the index chapter information attributes written to ODF 1.1
130  and 1.2 don't reflect the displaying (#i89791#)
131  */
132  if ( !bTOC )
133  {
134  bool bConvert( false );
135  {
136  sal_Int32 nUPD( 0 );
137  sal_Int32 nBuild( 0 );
138  const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
139  if ( GetImport().IsTextDocInOOoFileFormat() ||
140  ( bBuildIdFound &&
141  ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
142  {
143  bConvert = true;
144  }
145  }
146  if ( bConvert )
147  {
148  if ( nChapterInfo == ChapterFormat::NUMBER )
149  {
150  nChapterInfo = ChapterFormat::DIGIT;
151  }
152  else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
153  {
154  nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
155  }
156  }
157  }
158  }
159  if (bOutlineLevelOK)
160  m_nValues++;
161 }
162 
164  css::uno::Sequence<css::beans::PropertyValue> & rValues)
165 {
166  // entry name and (optionally) style name in parent class
168 
169  sal_Int32 nIndex = m_bCharStyleNameOK ? 2 : 1;
170 
171  if( bChapterInfoOK )
172  {
173  // chapter info field
174  rValues[nIndex].Name = "ChapterFormat";
175  rValues[nIndex].Value <<= nChapterInfo;
176  nIndex++;
177  }
178  if( bOutlineLevelOK )
179  {
180  rValues[nIndex].Name = "ChapterLevel";
181  rValues[nIndex].Value <<= nOutlineLevel;
182  }
183 }
184 
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
XMLIndexChapterInfoEntryContext(SvXMLImport &rImport, XMLIndexTemplateContext &rTemplate, bool bTOC)
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
Import index entry templates.
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
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:1814
Import index entry templates.
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
static bool convertEnum(EnumT &rEnum, std::u16string_view 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:145
const SvXMLEnumMapEntry< sal_uInt16 > aChapterDisplayMap[]
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
process parameters
TEXT
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)