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 0 : XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
52 : SvXMLImport& rImport,
53 : XMLIndexTemplateContext& rTemplate,
54 : sal_uInt16 nPrfx,
55 : const OUString& rLocalName,
56 : sal_Bool bT ) :
57 : XMLIndexSimpleEntryContext(rImport,
58 : (bT ? rTemplate.sTokenEntryNumber
59 : : rTemplate.sTokenChapterInfo),
60 : rTemplate, nPrfx, rLocalName),
61 : nChapterInfo(ChapterFormat::NAME_NUMBER),
62 : bChapterInfoOK(sal_False),
63 : bTOC( bT ),
64 : nOutlineLevel( 0 ),
65 0 : bOutlineLevelOK(sal_False)
66 : {
67 0 : }
68 :
69 0 : XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
70 : {
71 0 : }
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 0 : void XMLIndexChapterInfoEntryContext::StartElement(
86 : const Reference<XAttributeList> & xAttrList)
87 : {
88 : // handle both, style name and bibliography info
89 0 : sal_Int16 nLength = xAttrList->getLength();
90 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
91 : {
92 0 : OUString sLocalName;
93 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
94 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
95 0 : &sLocalName );
96 0 : if (XML_NAMESPACE_TEXT == nPrefix)
97 : {
98 0 : if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
99 : {
100 0 : sCharStyleName = xAttrList->getValueByIndex(nAttr);
101 0 : bCharStyleNameOK = sal_True;
102 : }
103 0 : else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
104 : {
105 : sal_uInt16 nTmp;
106 0 : if (SvXMLUnitConverter::convertEnum(
107 0 : nTmp, xAttrList->getValueByIndex(nAttr),
108 0 : aChapterDisplayMap))
109 : {
110 0 : nChapterInfo = nTmp;
111 0 : bChapterInfoOK = sal_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 = sal_True;
123 : }
124 : }
125 : }
126 0 : }
127 :
128 : // if we have a style name, set it!
129 0 : if (bCharStyleNameOK)
130 : {
131 0 : nValues++;
132 : }
133 :
134 : // if we have chaper info, set it!
135 0 : if (bChapterInfoOK)
136 : {
137 0 : 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 0 : if ( !bTOC )
142 : {
143 0 : bool bConvert( false );
144 : {
145 0 : sal_Int32 nUPD( 0 );
146 0 : sal_Int32 nBuild( 0 );
147 0 : const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
148 0 : if ( GetImport().IsTextDocInOOoFileFormat() ||
149 0 : ( bBuildIdFound &&
150 0 : ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
151 : {
152 0 : bConvert = true;
153 : }
154 : }
155 0 : if ( bConvert )
156 : {
157 0 : if ( nChapterInfo == ChapterFormat::NUMBER )
158 : {
159 0 : 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 0 : if (bOutlineLevelOK)
169 0 : nValues++;
170 0 : }
171 :
172 0 : 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 0 : XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
178 :
179 0 : sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
180 :
181 0 : if( bChapterInfoOK )
182 : {
183 : // chapter info field
184 0 : rValues[nIndex].Name = rTemplateContext.sChapterFormat;
185 0 : Any aAny;
186 0 : aAny <<= nChapterInfo;
187 0 : rValues[nIndex].Value = aAny;
188 0 : nIndex++;
189 : }
190 0 : 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 0 : }
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|