/src/libreoffice/xmloff/source/text/XMLIndexChapterInfoEntryContext.cxx
Line | Count | Source |
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 | | |
21 | | #include "XMLIndexChapterInfoEntryContext.hxx" |
22 | | |
23 | | #include <com/sun/star/text/ChapterFormat.hpp> |
24 | | |
25 | | #include <sax/tools/converter.hxx> |
26 | | #include <sal/log.hxx> |
27 | | |
28 | | #include "XMLIndexTemplateContext.hxx" |
29 | | #include <xmloff/xmlimp.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 | | |
43 | | |
44 | | XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext( |
45 | | SvXMLImport& rImport, |
46 | | XMLIndexTemplateContext& rTemplate, |
47 | | bool bT ) : |
48 | 0 | XMLIndexSimpleEntryContext(rImport, |
49 | 0 | (bT ? u"TokenEntryNumber"_ustr |
50 | 0 | : u"TokenChapterInfo"_ustr), |
51 | 0 | rTemplate), |
52 | 0 | nChapterInfo(ChapterFormat::NAME_NUMBER), |
53 | 0 | bChapterInfoOK(false), |
54 | 0 | bTOC( bT ), |
55 | 0 | nOutlineLevel( 0 ), |
56 | 0 | bOutlineLevelOK(false) |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext() |
61 | 0 | { |
62 | 0 | } |
63 | | |
64 | | const SvXMLEnumMapEntry<sal_uInt16> aChapterDisplayMap[] = |
65 | | { |
66 | | { XML_NAME, ChapterFormat::NAME }, |
67 | | { XML_NUMBER, ChapterFormat::NUMBER }, |
68 | | { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER }, |
69 | | //---> i89791 |
70 | | // enabled for ODF 1.2, full index support in 3.0 |
71 | | { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX }, |
72 | | { XML_PLAIN_NUMBER, ChapterFormat::DIGIT }, |
73 | | { XML_TOKEN_INVALID, 0 } |
74 | | }; |
75 | | |
76 | | void XMLIndexChapterInfoEntryContext::startFastElement( |
77 | | sal_Int32 /*nElement*/, |
78 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
79 | 0 | { |
80 | | // handle both, style name and bibliography info |
81 | 0 | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
82 | 0 | { |
83 | 0 | switch(aIter.getToken()) |
84 | 0 | { |
85 | 0 | case XML_ELEMENT(TEXT, XML_STYLE_NAME): |
86 | 0 | { |
87 | 0 | m_sCharStyleName = aIter.toString(); |
88 | 0 | m_bCharStyleNameOK = true; |
89 | 0 | break; |
90 | 0 | } |
91 | 0 | case XML_ELEMENT(TEXT, XML_DISPLAY): //i53420, always true, in TOC as well |
92 | 0 | { |
93 | 0 | sal_uInt16 nTmp; |
94 | 0 | if (SvXMLUnitConverter::convertEnum(nTmp, aIter.toView(), aChapterDisplayMap)) |
95 | 0 | { |
96 | 0 | nChapterInfo = nTmp; |
97 | 0 | bChapterInfoOK = true; |
98 | 0 | } |
99 | 0 | break; |
100 | 0 | } |
101 | 0 | case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL): |
102 | 0 | { |
103 | 0 | sal_Int32 nTmp; |
104 | 0 | if (::sax::Converter::convertNumber(nTmp, aIter.toView(), 0, SAL_MAX_INT16)) |
105 | 0 | { |
106 | | //control on range is carried out in the UNO level |
107 | 0 | nOutlineLevel = static_cast<sal_uInt16>(nTmp); |
108 | 0 | bOutlineLevelOK = true; |
109 | 0 | } |
110 | 0 | break; |
111 | 0 | } |
112 | 0 | default: |
113 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
114 | 0 | } |
115 | 0 | } |
116 | | |
117 | | // if we have a style name, set it! |
118 | 0 | if (m_bCharStyleNameOK) |
119 | 0 | { |
120 | 0 | m_nValues++; |
121 | 0 | } |
122 | | |
123 | | // if we have chapter info, set it! |
124 | 0 | if (bChapterInfoOK) |
125 | 0 | { |
126 | 0 | m_nValues++; |
127 | | /* Some of the index chapter information attributes written to ODF 1.1 |
128 | | and 1.2 don't reflect the displaying (#i89791#) |
129 | | */ |
130 | 0 | if ( !bTOC ) |
131 | 0 | { |
132 | 0 | bool bConvert( false ); |
133 | 0 | { |
134 | 0 | sal_Int32 nUPD( 0 ); |
135 | 0 | sal_Int32 nBuild( 0 ); |
136 | 0 | const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild ); |
137 | 0 | if ( GetImport().IsTextDocInOOoFileFormat() || |
138 | 0 | ( bBuildIdFound && |
139 | 0 | ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) ) |
140 | 0 | { |
141 | 0 | bConvert = true; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | if ( bConvert ) |
145 | 0 | { |
146 | 0 | if ( nChapterInfo == ChapterFormat::NUMBER ) |
147 | 0 | { |
148 | 0 | nChapterInfo = ChapterFormat::DIGIT; |
149 | 0 | } |
150 | 0 | else if ( nChapterInfo == ChapterFormat::NAME_NUMBER ) |
151 | 0 | { |
152 | 0 | nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX; |
153 | 0 | } |
154 | 0 | } |
155 | 0 | } |
156 | 0 | } |
157 | 0 | if (bOutlineLevelOK) |
158 | 0 | m_nValues++; |
159 | 0 | } |
160 | | |
161 | | void XMLIndexChapterInfoEntryContext::FillPropertyValues( |
162 | | css::uno::Sequence<css::beans::PropertyValue> & rValues) |
163 | 0 | { |
164 | | // entry name and (optionally) style name in parent class |
165 | 0 | XMLIndexSimpleEntryContext::FillPropertyValues(rValues); |
166 | |
|
167 | 0 | sal_Int32 nIndex = m_bCharStyleNameOK ? 2 : 1; |
168 | 0 | auto pValues = rValues.getArray(); |
169 | |
|
170 | 0 | if( bChapterInfoOK ) |
171 | 0 | { |
172 | | // chapter info field |
173 | 0 | pValues[nIndex].Name = "ChapterFormat"; |
174 | 0 | pValues[nIndex].Value <<= nChapterInfo; |
175 | 0 | nIndex++; |
176 | 0 | } |
177 | 0 | if( bOutlineLevelOK ) |
178 | 0 | { |
179 | 0 | pValues[nIndex].Name = "ChapterLevel"; |
180 | 0 | pValues[nIndex].Value <<= nOutlineLevel; |
181 | 0 | } |
182 | 0 | } |
183 | | |
184 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |