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