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