Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XMLIndexChapterInfoEntryContext.hxx"
31 : :
32 : : #include <com/sun/star/text/ChapterFormat.hpp>
33 : :
34 : : #include <sax/tools/converter.hxx>
35 : :
36 : : #include "XMLIndexTemplateContext.hxx"
37 : : #include <xmloff/xmlictxt.hxx>
38 : : #include <xmloff/xmlimp.hxx>
39 : : #include <xmloff/txtimp.hxx>
40 : : #include <xmloff/nmspmap.hxx>
41 : : #include "xmloff/xmlnmspe.hxx"
42 : : #include <xmloff/xmltoken.hxx>
43 : : #include <xmloff/xmluconv.hxx>
44 : :
45 : :
46 : : using namespace ::com::sun::star::text;
47 : : using namespace ::xmloff::token;
48 : :
49 : : using ::rtl::OUString;
50 : : using ::com::sun::star::beans::PropertyValue;
51 : : using ::com::sun::star::beans::PropertyValues;
52 : : using ::com::sun::star::uno::Reference;
53 : : using ::com::sun::star::uno::Sequence;
54 : : using ::com::sun::star::uno::Any;
55 : : using ::com::sun::star::xml::sax::XAttributeList;
56 : :
57 : :
58 : :
59 [ # # ][ # # ]: 0 : TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext);
60 : :
61 : 40 : XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
62 : : SvXMLImport& rImport,
63 : : XMLIndexTemplateContext& rTemplate,
64 : : sal_uInt16 nPrfx,
65 : : const OUString& rLocalName,
66 : : sal_Bool bT ) :
67 : : XMLIndexSimpleEntryContext(rImport,
68 : : (bT ? rTemplate.sTokenEntryNumber
69 : : : rTemplate.sTokenChapterInfo),
70 : : rTemplate, nPrfx, rLocalName),
71 : : nChapterInfo(ChapterFormat::NAME_NUMBER),
72 : : bChapterInfoOK(sal_False),
73 : : bTOC( bT ),
74 : : nOutlineLevel( 0 ),
75 [ + - ]: 40 : bOutlineLevelOK(sal_False)
76 : : {
77 : 40 : }
78 : :
79 : 40 : XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
80 : : {
81 [ - + ]: 80 : }
82 : :
83 : : static const SvXMLEnumMapEntry aChapterDisplayMap[] =
84 : : {
85 : : { XML_NAME, ChapterFormat::NAME },
86 : : { XML_NUMBER, ChapterFormat::NUMBER },
87 : : { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
88 : : //---> i89791
89 : : // enabled for ODF 1.2, full index support in 3.0
90 : : { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
91 : : { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
92 : : { XML_TOKEN_INVALID, 0 }
93 : : };
94 : :
95 : 40 : void XMLIndexChapterInfoEntryContext::StartElement(
96 : : const Reference<XAttributeList> & xAttrList)
97 : : {
98 : : // handle both, style name and bibliography info
99 : 40 : sal_Int16 nLength = xAttrList->getLength();
100 [ - + ]: 40 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
101 : : {
102 : 0 : OUString sLocalName;
103 : 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
104 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
105 [ # # # # ]: 0 : &sLocalName );
106 [ # # ]: 0 : if (XML_NAMESPACE_TEXT == nPrefix)
107 : : {
108 [ # # ][ # # ]: 0 : if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
109 : : {
110 [ # # ][ # # ]: 0 : sCharStyleName = xAttrList->getValueByIndex(nAttr);
111 : 0 : bCharStyleNameOK = sal_True;
112 : : }
113 [ # # ][ # # ]: 0 : else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
114 : : {
115 : : sal_uInt16 nTmp;
116 [ # # ]: 0 : if (SvXMLUnitConverter::convertEnum(
117 [ # # ]: 0 : nTmp, xAttrList->getValueByIndex(nAttr),
118 [ # # ][ # # ]: 0 : aChapterDisplayMap))
119 : : {
120 : 0 : nChapterInfo = nTmp;
121 : 0 : bChapterInfoOK = sal_True;
122 : : }
123 : : }
124 [ # # ][ # # ]: 0 : else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
125 : : {
126 : : sal_Int32 nTmp;
127 [ # # # # ]: 0 : if (::sax::Converter::convertNumber(nTmp,
128 [ # # ][ # # ]: 0 : xAttrList->getValueByIndex(nAttr)))
129 : : {
130 : : //control on range is carried out in the UNO level
131 : 0 : nOutlineLevel = static_cast<sal_uInt16>(nTmp);
132 : 0 : bOutlineLevelOK = sal_True;
133 : : }
134 : : }
135 : : }
136 : 0 : }
137 : :
138 : : // if we have a style name, set it!
139 [ - + ]: 40 : if (bCharStyleNameOK)
140 : : {
141 : 0 : nValues++;
142 : : }
143 : :
144 : : // if we have chaper info, set it!
145 [ - + ]: 40 : if (bChapterInfoOK)
146 : : {
147 : 0 : nValues++;
148 : : /* Some of the index chapter information attributes written to ODF 1.1
149 : : and 1.2 don't reflect the displaying (#i89791#)
150 : : */
151 [ # # ]: 0 : if ( !bTOC )
152 : : {
153 : 0 : bool bConvert( false );
154 : : {
155 : 0 : sal_Int32 nUPD( 0 );
156 : 0 : sal_Int32 nBuild( 0 );
157 [ # # ]: 0 : const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
158 [ # # ][ # # ]: 0 : if ( GetImport().IsTextDocInOOoFileFormat() ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
159 : : ( bBuildIdFound &&
160 : : ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
161 : : {
162 : 0 : bConvert = true;
163 : : }
164 : : }
165 [ # # ]: 0 : if ( bConvert )
166 : : {
167 [ # # ]: 0 : if ( nChapterInfo == ChapterFormat::NUMBER )
168 : : {
169 : 0 : nChapterInfo = ChapterFormat::DIGIT;
170 : : }
171 [ # # ]: 0 : else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
172 : : {
173 : 0 : nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
174 : : }
175 : : }
176 : : }
177 : : }
178 [ - + ]: 40 : if (bOutlineLevelOK)
179 : 0 : nValues++;
180 : 40 : }
181 : :
182 : 40 : void XMLIndexChapterInfoEntryContext::FillPropertyValues(
183 : : ::com::sun::star::uno::Sequence<
184 : : ::com::sun::star::beans::PropertyValue> & rValues)
185 : : {
186 : : // entry name and (optionally) style name in parent class
187 : 40 : XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
188 : :
189 [ - + ]: 40 : sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
190 : :
191 [ - + ]: 40 : if( bChapterInfoOK )
192 : : {
193 : : // chapter info field
194 [ # # ]: 0 : rValues[nIndex].Name = rTemplateContext.sChapterFormat;
195 : 0 : Any aAny;
196 [ # # ]: 0 : aAny <<= nChapterInfo;
197 [ # # ]: 0 : rValues[nIndex].Value = aAny;
198 : 0 : nIndex++;
199 : : }
200 [ - + ]: 40 : if( bOutlineLevelOK )
201 : : {
202 [ # # ]: 0 : rValues[nIndex].Name = rTemplateContext.sChapterLevel;
203 : 0 : Any aAny;
204 [ # # ]: 0 : aAny <<= nOutlineLevel;
205 [ # # ]: 0 : rValues[nIndex].Value = aAny;
206 : : }
207 : 40 : }
208 : :
209 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|