1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "XMLIndexChapterInfoEntryContext.hxx"
29cdf0e10cSrcweir #include "XMLIndexTemplateContext.hxx"
30cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
32cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
33cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
34cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
36cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
37cdf0e10cSrcweir #include <com/sun/star/text/ChapterFormat.hpp>
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star::text;
41cdf0e10cSrcweir using namespace ::xmloff::token;
42cdf0e10cSrcweir
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
45cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValues;
46cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
47cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
48cdf0e10cSrcweir using ::com::sun::star::uno::Any;
49cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir
53cdf0e10cSrcweir TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext);
54cdf0e10cSrcweir
XMLIndexChapterInfoEntryContext(SvXMLImport & rImport,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName,sal_Bool bT)55cdf0e10cSrcweir XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
56cdf0e10cSrcweir SvXMLImport& rImport,
57cdf0e10cSrcweir XMLIndexTemplateContext& rTemplate,
58cdf0e10cSrcweir sal_uInt16 nPrfx,
59cdf0e10cSrcweir const OUString& rLocalName,
60cdf0e10cSrcweir sal_Bool bT ) :
61cdf0e10cSrcweir XMLIndexSimpleEntryContext(rImport,
62cdf0e10cSrcweir (bT ? rTemplate.sTokenEntryNumber
63cdf0e10cSrcweir : rTemplate.sTokenChapterInfo),
64cdf0e10cSrcweir rTemplate, nPrfx, rLocalName),
65cdf0e10cSrcweir nChapterInfo(ChapterFormat::NAME_NUMBER),
66cdf0e10cSrcweir bChapterInfoOK(sal_False),
67cdf0e10cSrcweir bTOC( bT ),
68cdf0e10cSrcweir nOutlineLevel( 0 ),
69cdf0e10cSrcweir bOutlineLevelOK(sal_False)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
~XMLIndexChapterInfoEntryContext()73cdf0e10cSrcweir XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir static const SvXMLEnumMapEntry aChapterDisplayMap[] =
78cdf0e10cSrcweir {
79cdf0e10cSrcweir { XML_NAME, ChapterFormat::NAME },
80cdf0e10cSrcweir { XML_NUMBER, ChapterFormat::NUMBER },
81cdf0e10cSrcweir { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
82cdf0e10cSrcweir //---> i89791
83cdf0e10cSrcweir // enabled for ODF 1.2, full index support in 3.0
84cdf0e10cSrcweir { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
85cdf0e10cSrcweir //<---
86cdf0e10cSrcweir { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
87cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
88cdf0e10cSrcweir };
89cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & xAttrList)90cdf0e10cSrcweir void XMLIndexChapterInfoEntryContext::StartElement(
91cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // handle both, style name and bibliography info
94cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
95cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir OUString sLocalName;
98cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
99cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
100cdf0e10cSrcweir &sLocalName );
101cdf0e10cSrcweir if (XML_NAMESPACE_TEXT == nPrefix)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir sCharStyleName = xAttrList->getValueByIndex(nAttr);
106cdf0e10cSrcweir bCharStyleNameOK = sal_True;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
109cdf0e10cSrcweir {
110cdf0e10cSrcweir sal_uInt16 nTmp;
111cdf0e10cSrcweir if (SvXMLUnitConverter::convertEnum(
112cdf0e10cSrcweir nTmp, xAttrList->getValueByIndex(nAttr),
113cdf0e10cSrcweir aChapterDisplayMap))
114cdf0e10cSrcweir {
115cdf0e10cSrcweir nChapterInfo = nTmp;
116cdf0e10cSrcweir bChapterInfoOK = sal_True;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir sal_Int32 nTmp;
122cdf0e10cSrcweir
123cdf0e10cSrcweir if (SvXMLUnitConverter::convertNumber(nTmp, xAttrList->getValueByIndex(nAttr)))
124cdf0e10cSrcweir {
125cdf0e10cSrcweir //control on range is carried out in the UNO level
126cdf0e10cSrcweir nOutlineLevel = static_cast<sal_uInt16>(nTmp);
127cdf0e10cSrcweir bOutlineLevelOK = sal_True;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir // if we have a style name, set it!
134cdf0e10cSrcweir if (bCharStyleNameOK)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir nValues++;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // if we have chaper info, set it!
140cdf0e10cSrcweir if (bChapterInfoOK)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir nValues++;
143cdf0e10cSrcweir // --> OD 2008-06-26 #i89791#
144cdf0e10cSrcweir if ( !bTOC )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir bool bConvert( false );
147cdf0e10cSrcweir {
148cdf0e10cSrcweir sal_Int32 nUPD( 0 );
149cdf0e10cSrcweir sal_Int32 nBuild( 0 );
150cdf0e10cSrcweir const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
151cdf0e10cSrcweir if ( GetImport().IsTextDocInOOoFileFormat() ||
152cdf0e10cSrcweir ( bBuildIdFound &&
153cdf0e10cSrcweir ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir bConvert = true;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir if ( bConvert )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir if ( nChapterInfo == ChapterFormat::NUMBER )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir nChapterInfo = ChapterFormat::DIGIT;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir // <--
171cdf0e10cSrcweir }
172cdf0e10cSrcweir if (bOutlineLevelOK)
173cdf0e10cSrcweir nValues++;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
FillPropertyValues(::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & rValues)176cdf0e10cSrcweir void XMLIndexChapterInfoEntryContext::FillPropertyValues(
177cdf0e10cSrcweir ::com::sun::star::uno::Sequence<
178cdf0e10cSrcweir ::com::sun::star::beans::PropertyValue> & rValues)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir // entry name and (optionally) style name in parent class
181cdf0e10cSrcweir XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
182cdf0e10cSrcweir
183cdf0e10cSrcweir sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
184cdf0e10cSrcweir
185cdf0e10cSrcweir if( bChapterInfoOK )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir // chapter info field
188cdf0e10cSrcweir rValues[nIndex].Name = rTemplateContext.sChapterFormat;
189cdf0e10cSrcweir Any aAny;
190cdf0e10cSrcweir aAny <<= nChapterInfo;
191cdf0e10cSrcweir rValues[nIndex].Value = aAny;
192cdf0e10cSrcweir nIndex++;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir if( bOutlineLevelOK )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir rValues[nIndex].Name = rTemplateContext.sChapterLevel;
197cdf0e10cSrcweir Any aAny;
198cdf0e10cSrcweir aAny <<= nOutlineLevel;
199cdf0e10cSrcweir rValues[nIndex].Value = aAny;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir }
202