Line data Source code
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 :
27 : #include "XMLIndexTemplateContext.hxx"
28 : #include <xmloff/xmlictxt.hxx>
29 : #include <xmloff/xmlimp.hxx>
30 : #include <xmloff/txtimp.hxx>
31 : #include <xmloff/nmspmap.hxx>
32 : #include <xmloff/xmlnmspe.hxx>
33 : #include <xmloff/xmltoken.hxx>
34 : #include <xmloff/xmluconv.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::beans::PropertyValues;
42 : using ::com::sun::star::uno::Reference;
43 : using ::com::sun::star::uno::Sequence;
44 : using ::com::sun::star::uno::Any;
45 : using ::com::sun::star::xml::sax::XAttributeList;
46 :
47 :
48 :
49 0 : TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext);
50 :
51 80 : XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
52 : SvXMLImport& rImport,
53 : XMLIndexTemplateContext& rTemplate,
54 : sal_uInt16 nPrfx,
55 : const OUString& rLocalName,
56 : bool bT ) :
57 : XMLIndexSimpleEntryContext(rImport,
58 : (bT ? rTemplate.sTokenEntryNumber
59 : : rTemplate.sTokenChapterInfo),
60 : rTemplate, nPrfx, rLocalName),
61 : nChapterInfo(ChapterFormat::NAME_NUMBER),
62 : bChapterInfoOK(false),
63 : bTOC( bT ),
64 : nOutlineLevel( 0 ),
65 80 : bOutlineLevelOK(false)
66 : {
67 80 : }
68 :
69 160 : XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
70 : {
71 160 : }
72 :
73 : static const SvXMLEnumMapEntry aChapterDisplayMap[] =
74 : {
75 : { XML_NAME, ChapterFormat::NAME },
76 : { XML_NUMBER, ChapterFormat::NUMBER },
77 : { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
78 : //---> i89791
79 : // enabled for ODF 1.2, full index support in 3.0
80 : { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
81 : { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
82 : { XML_TOKEN_INVALID, 0 }
83 : };
84 :
85 80 : void XMLIndexChapterInfoEntryContext::StartElement(
86 : const Reference<XAttributeList> & xAttrList)
87 : {
88 : // handle both, style name and bibliography info
89 80 : sal_Int16 nLength = xAttrList->getLength();
90 93 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
91 : {
92 13 : OUString sLocalName;
93 13 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
94 13 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
95 26 : &sLocalName );
96 13 : if (XML_NAMESPACE_TEXT == nPrefix)
97 : {
98 13 : if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
99 : {
100 9 : sCharStyleName = xAttrList->getValueByIndex(nAttr);
101 9 : bCharStyleNameOK = true;
102 : }
103 4 : else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
104 : {
105 : sal_uInt16 nTmp;
106 8 : if (SvXMLUnitConverter::convertEnum(
107 4 : nTmp, xAttrList->getValueByIndex(nAttr),
108 8 : aChapterDisplayMap))
109 : {
110 4 : nChapterInfo = nTmp;
111 4 : bChapterInfoOK = true;
112 : }
113 : }
114 0 : else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
115 : {
116 : sal_Int32 nTmp;
117 0 : if (::sax::Converter::convertNumber(nTmp,
118 0 : xAttrList->getValueByIndex(nAttr)))
119 : {
120 : //control on range is carried out in the UNO level
121 0 : nOutlineLevel = static_cast<sal_uInt16>(nTmp);
122 0 : bOutlineLevelOK = true;
123 : }
124 : }
125 : }
126 13 : }
127 :
128 : // if we have a style name, set it!
129 80 : if (bCharStyleNameOK)
130 : {
131 9 : nValues++;
132 : }
133 :
134 : // if we have chaper info, set it!
135 80 : if (bChapterInfoOK)
136 : {
137 4 : nValues++;
138 : /* Some of the index chapter information attributes written to ODF 1.1
139 : and 1.2 don't reflect the displaying (#i89791#)
140 : */
141 4 : if ( !bTOC )
142 : {
143 4 : bool bConvert( false );
144 : {
145 4 : sal_Int32 nUPD( 0 );
146 4 : sal_Int32 nBuild( 0 );
147 4 : const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
148 8 : if ( GetImport().IsTextDocInOOoFileFormat() ||
149 4 : ( bBuildIdFound &&
150 4 : ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
151 : {
152 4 : bConvert = true;
153 : }
154 : }
155 4 : if ( bConvert )
156 : {
157 4 : if ( nChapterInfo == ChapterFormat::NUMBER )
158 : {
159 4 : nChapterInfo = ChapterFormat::DIGIT;
160 : }
161 0 : else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
162 : {
163 0 : nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
164 : }
165 : }
166 : }
167 : }
168 80 : if (bOutlineLevelOK)
169 0 : nValues++;
170 80 : }
171 :
172 80 : void XMLIndexChapterInfoEntryContext::FillPropertyValues(
173 : ::com::sun::star::uno::Sequence<
174 : ::com::sun::star::beans::PropertyValue> & rValues)
175 : {
176 : // entry name and (optionally) style name in parent class
177 80 : XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
178 :
179 80 : sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
180 :
181 80 : if( bChapterInfoOK )
182 : {
183 : // chapter info field
184 4 : rValues[nIndex].Name = rTemplateContext.sChapterFormat;
185 4 : Any aAny;
186 4 : aAny <<= nChapterInfo;
187 4 : rValues[nIndex].Value = aAny;
188 4 : nIndex++;
189 : }
190 80 : if( bOutlineLevelOK )
191 : {
192 0 : rValues[nIndex].Name = rTemplateContext.sChapterLevel;
193 0 : Any aAny;
194 0 : aAny <<= nOutlineLevel;
195 0 : rValues[nIndex].Value = aAny;
196 : }
197 80 : }
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|