1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "XMLIndexChapterInfoEntryContext.hxx"
23 #include <com/sun/star/text/ChapterFormat.hpp>
25 #include <sax/tools/converter.hxx>
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>
37 using namespace ::com::sun::star::text
;
38 using namespace ::xmloff::token
;
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
;
49 TYPEINIT1( XMLIndexChapterInfoEntryContext
, XMLIndexSimpleEntryContext
);
51 XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
53 XMLIndexTemplateContext
& rTemplate
,
55 const OUString
& rLocalName
,
57 XMLIndexSimpleEntryContext(rImport
,
58 (bT
? rTemplate
.sTokenEntryNumber
59 : rTemplate
.sTokenChapterInfo
),
60 rTemplate
, nPrfx
, rLocalName
),
61 nChapterInfo(ChapterFormat::NAME_NUMBER
),
62 bChapterInfoOK(false),
65 bOutlineLevelOK(false)
69 XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
73 static const SvXMLEnumMapEntry aChapterDisplayMap
[] =
75 { XML_NAME
, ChapterFormat::NAME
},
76 { XML_NUMBER
, ChapterFormat::NUMBER
},
77 { XML_NUMBER_AND_NAME
, ChapterFormat::NAME_NUMBER
},
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 }
85 void XMLIndexChapterInfoEntryContext::StartElement(
86 const Reference
<XAttributeList
> & xAttrList
)
88 // handle both, style name and bibliography info
89 sal_Int16 nLength
= xAttrList
->getLength();
90 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
93 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
94 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
96 if (XML_NAMESPACE_TEXT
== nPrefix
)
98 if ( IsXMLToken( sLocalName
, XML_STYLE_NAME
) )
100 sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
101 bCharStyleNameOK
= true;
103 else if ( IsXMLToken( sLocalName
, XML_DISPLAY
) )//i53420, always true, in TOC as well
106 if (SvXMLUnitConverter::convertEnum(
107 nTmp
, xAttrList
->getValueByIndex(nAttr
),
111 bChapterInfoOK
= true;
114 else if ( IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
117 if (::sax::Converter::convertNumber(nTmp
,
118 xAttrList
->getValueByIndex(nAttr
)))
120 //control on range is carried out in the UNO level
121 nOutlineLevel
= static_cast<sal_uInt16
>(nTmp
);
122 bOutlineLevelOK
= true;
128 // if we have a style name, set it!
129 if (bCharStyleNameOK
)
134 // if we have chaper info, set it!
138 /* Some of the index chapter information attributes written to ODF 1.1
139 and 1.2 don't reflect the displaying (#i89791#)
143 bool bConvert( false );
146 sal_Int32
nBuild( 0 );
147 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
148 if ( GetImport().IsTextDocInOOoFileFormat() ||
150 ( nUPD
== 680 || nUPD
== 645 || nUPD
== 641 ) ) )
157 if ( nChapterInfo
== ChapterFormat::NUMBER
)
159 nChapterInfo
= ChapterFormat::DIGIT
;
161 else if ( nChapterInfo
== ChapterFormat::NAME_NUMBER
)
163 nChapterInfo
= ChapterFormat::NO_PREFIX_SUFFIX
;
172 void XMLIndexChapterInfoEntryContext::FillPropertyValues(
173 ::com::sun::star::uno::Sequence
<
174 ::com::sun::star::beans::PropertyValue
> & rValues
)
176 // entry name and (optionally) style name in parent class
177 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
179 sal_Int32 nIndex
= bCharStyleNameOK
? 2 : 1;
183 // chapter info field
184 rValues
[nIndex
].Name
= rTemplateContext
.sChapterFormat
;
186 aAny
<<= nChapterInfo
;
187 rValues
[nIndex
].Value
= aAny
;
190 if( bOutlineLevelOK
)
192 rValues
[nIndex
].Name
= rTemplateContext
.sChapterLevel
;
194 aAny
<<= nOutlineLevel
;
195 rValues
[nIndex
].Value
= aAny
;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */