Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLIndexChapterInfoEntryContext.cxx
blobca75b6fc693d3ae0826e2f2526480f93bd187f25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexChapterInfoEntryContext.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexChapterInfoEntryContext.hxx"
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 "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <com/sun/star/text/ChapterFormat.hpp>
47 using namespace ::com::sun::star::text;
48 using namespace ::xmloff::token;
50 using ::rtl::OUString;
51 using ::com::sun::star::beans::PropertyValue;
52 using ::com::sun::star::beans::PropertyValues;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::Sequence;
55 using ::com::sun::star::uno::Any;
56 using ::com::sun::star::xml::sax::XAttributeList;
60 TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext);
62 XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
63 SvXMLImport& rImport,
64 XMLIndexTemplateContext& rTemplate,
65 sal_uInt16 nPrfx,
66 const OUString& rLocalName,
67 sal_Bool bT ) :
68 XMLIndexSimpleEntryContext(rImport,
69 (bT ? rTemplate.sTokenEntryNumber
70 : rTemplate.sTokenChapterInfo),
71 rTemplate, nPrfx, rLocalName),
72 nChapterInfo(ChapterFormat::NAME_NUMBER),
73 bChapterInfoOK(sal_False),
74 bTOC( bT ),
75 nOutlineLevel( 0 ),
76 bOutlineLevelOK(sal_False)
80 XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
84 static const SvXMLEnumMapEntry aChapterDisplayMap[] =
86 { XML_NAME, ChapterFormat::NAME },
87 { XML_NUMBER, ChapterFormat::NUMBER },
88 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
89 //---> i89791
90 // enabled for ODF 1.2, full index support in 3.0
91 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
92 //<---
93 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
94 { XML_TOKEN_INVALID, 0 }
97 void XMLIndexChapterInfoEntryContext::StartElement(
98 const Reference<XAttributeList> & xAttrList)
100 // handle both, style name and bibliography info
101 sal_Int16 nLength = xAttrList->getLength();
102 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
104 OUString sLocalName;
105 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
106 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
107 &sLocalName );
108 if (XML_NAMESPACE_TEXT == nPrefix)
110 if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
112 sCharStyleName = xAttrList->getValueByIndex(nAttr);
113 bCharStyleNameOK = sal_True;
115 else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
117 sal_uInt16 nTmp;
118 if (SvXMLUnitConverter::convertEnum(
119 nTmp, xAttrList->getValueByIndex(nAttr),
120 aChapterDisplayMap))
122 nChapterInfo = nTmp;
123 bChapterInfoOK = sal_True;
126 else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
128 sal_Int32 nTmp;
130 if (SvXMLUnitConverter::convertNumber(nTmp, xAttrList->getValueByIndex(nAttr)))
132 //control on range is carried out in the UNO level
133 nOutlineLevel = static_cast<sal_uInt16>(nTmp);
134 bOutlineLevelOK = sal_True;
140 // if we have a style name, set it!
141 if (bCharStyleNameOK)
143 nValues++;
146 // if we have chaper info, set it!
147 if (bChapterInfoOK)
149 nValues++;
150 // --> OD 2008-06-26 #i89791#
151 if ( !bTOC )
153 bool bConvert( false );
155 sal_Int32 nUPD( 0 );
156 sal_Int32 nBuild( 0 );
157 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
158 if ( GetImport().IsTextDocInOOoFileFormat() ||
159 ( bBuildIdFound &&
160 ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
162 bConvert = true;
165 if ( bConvert )
167 if ( nChapterInfo == ChapterFormat::NUMBER )
169 nChapterInfo = ChapterFormat::DIGIT;
171 else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
173 nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
177 // <--
179 if (bOutlineLevelOK)
180 nValues++;
183 void XMLIndexChapterInfoEntryContext::FillPropertyValues(
184 ::com::sun::star::uno::Sequence<
185 ::com::sun::star::beans::PropertyValue> & rValues)
187 // entry name and (optionally) style name in parent class
188 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
190 sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
192 if( bChapterInfoOK )
194 // chapter info field
195 rValues[nIndex].Name = rTemplateContext.sChapterFormat;
196 Any aAny;
197 aAny <<= nChapterInfo;
198 rValues[nIndex].Value = aAny;
199 nIndex++;
201 if( bOutlineLevelOK )
203 rValues[nIndex].Name = rTemplateContext.sChapterLevel;
204 Any aAny;
205 aAny <<= nOutlineLevel;
206 rValues[nIndex].Value = aAny;