1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include "XMLIndexChapterInfoEntryContext.hxx"
32 #include <com/sun/star/text/ChapterFormat.hpp>
34 #include <sax/tools/converter.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 "xmloff/xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
46 using namespace ::com::sun::star::text
;
47 using namespace ::xmloff::token
;
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
;
59 TYPEINIT1( XMLIndexChapterInfoEntryContext
, XMLIndexSimpleEntryContext
);
61 XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
63 XMLIndexTemplateContext
& rTemplate
,
65 const OUString
& rLocalName
,
67 XMLIndexSimpleEntryContext(rImport
,
68 (bT
? rTemplate
.sTokenEntryNumber
69 : rTemplate
.sTokenChapterInfo
),
70 rTemplate
, nPrfx
, rLocalName
),
71 nChapterInfo(ChapterFormat::NAME_NUMBER
),
72 bChapterInfoOK(sal_False
),
75 bOutlineLevelOK(sal_False
)
79 XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
83 static const SvXMLEnumMapEntry aChapterDisplayMap
[] =
85 { XML_NAME
, ChapterFormat::NAME
},
86 { XML_NUMBER
, ChapterFormat::NUMBER
},
87 { XML_NUMBER_AND_NAME
, ChapterFormat::NAME_NUMBER
},
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 }
95 void XMLIndexChapterInfoEntryContext::StartElement(
96 const Reference
<XAttributeList
> & xAttrList
)
98 // handle both, style name and bibliography info
99 sal_Int16 nLength
= xAttrList
->getLength();
100 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
103 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
104 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
106 if (XML_NAMESPACE_TEXT
== nPrefix
)
108 if ( IsXMLToken( sLocalName
, XML_STYLE_NAME
) )
110 sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
111 bCharStyleNameOK
= sal_True
;
113 else if ( IsXMLToken( sLocalName
, XML_DISPLAY
) )//i53420, always true, in TOC as well
116 if (SvXMLUnitConverter::convertEnum(
117 nTmp
, xAttrList
->getValueByIndex(nAttr
),
121 bChapterInfoOK
= sal_True
;
124 else if ( IsXMLToken( sLocalName
, XML_OUTLINE_LEVEL
) )
127 if (::sax::Converter::convertNumber(nTmp
,
128 xAttrList
->getValueByIndex(nAttr
)))
130 //control on range is carried out in the UNO level
131 nOutlineLevel
= static_cast<sal_uInt16
>(nTmp
);
132 bOutlineLevelOK
= sal_True
;
138 // if we have a style name, set it!
139 if (bCharStyleNameOK
)
144 // if we have chaper info, set it!
148 /* Some of the index chapter information attributes written to ODF 1.1
149 and 1.2 don't reflect the displaying (#i89791#)
153 bool bConvert( false );
156 sal_Int32
nBuild( 0 );
157 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
158 if ( GetImport().IsTextDocInOOoFileFormat() ||
160 ( nUPD
== 680 || nUPD
== 645 || nUPD
== 641 ) ) )
167 if ( nChapterInfo
== ChapterFormat::NUMBER
)
169 nChapterInfo
= ChapterFormat::DIGIT
;
171 else if ( nChapterInfo
== ChapterFormat::NAME_NUMBER
)
173 nChapterInfo
= ChapterFormat::NO_PREFIX_SUFFIX
;
182 void XMLIndexChapterInfoEntryContext::FillPropertyValues(
183 ::com::sun::star::uno::Sequence
<
184 ::com::sun::star::beans::PropertyValue
> & rValues
)
186 // entry name and (optionally) style name in parent class
187 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
189 sal_Int32 nIndex
= bCharStyleNameOK
? 2 : 1;
193 // chapter info field
194 rValues
[nIndex
].Name
= rTemplateContext
.sChapterFormat
;
196 aAny
<<= nChapterInfo
;
197 rValues
[nIndex
].Value
= aAny
;
200 if( bOutlineLevelOK
)
202 rValues
[nIndex
].Name
= rTemplateContext
.sChapterLevel
;
204 aAny
<<= nOutlineLevel
;
205 rValues
[nIndex
].Value
= aAny
;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */