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>
26 #include <sal/log.hxx>
28 #include "XMLIndexTemplateContext.hxx"
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/xmlement.hxx>
36 using namespace ::com::sun::star::text
;
37 using namespace ::xmloff::token
;
39 using ::com::sun::star::beans::PropertyValue
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Sequence
;
44 XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
46 XMLIndexTemplateContext
& rTemplate
,
48 XMLIndexSimpleEntryContext(rImport
,
49 (bT
? u
"TokenEntryNumber"_ustr
50 : u
"TokenChapterInfo"_ustr
),
52 nChapterInfo(ChapterFormat::NAME_NUMBER
),
53 bChapterInfoOK(false),
56 bOutlineLevelOK(false)
60 XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
64 const SvXMLEnumMapEntry
<sal_uInt16
> aChapterDisplayMap
[] =
66 { XML_NAME
, ChapterFormat::NAME
},
67 { XML_NUMBER
, ChapterFormat::NUMBER
},
68 { XML_NUMBER_AND_NAME
, ChapterFormat::NAME_NUMBER
},
70 // enabled for ODF 1.2, full index support in 3.0
71 { XML_PLAIN_NUMBER_AND_NAME
, ChapterFormat::NO_PREFIX_SUFFIX
},
72 { XML_PLAIN_NUMBER
, ChapterFormat::DIGIT
},
73 { XML_TOKEN_INVALID
, 0 }
76 void XMLIndexChapterInfoEntryContext::startFastElement(
77 sal_Int32
/*nElement*/,
78 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
80 // handle both, style name and bibliography info
81 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
83 switch(aIter
.getToken())
85 case XML_ELEMENT(TEXT
, XML_STYLE_NAME
):
87 m_sCharStyleName
= aIter
.toString();
88 m_bCharStyleNameOK
= true;
91 case XML_ELEMENT(TEXT
, XML_DISPLAY
): //i53420, always true, in TOC as well
94 if (SvXMLUnitConverter::convertEnum(nTmp
, aIter
.toView(), aChapterDisplayMap
))
97 bChapterInfoOK
= true;
101 case XML_ELEMENT(TEXT
, XML_OUTLINE_LEVEL
):
104 if (::sax::Converter::convertNumber(nTmp
, aIter
.toView(), 0, SAL_MAX_INT16
))
106 //control on range is carried out in the UNO level
107 nOutlineLevel
= static_cast<sal_uInt16
>(nTmp
);
108 bOutlineLevelOK
= true;
113 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
117 // if we have a style name, set it!
118 if (m_bCharStyleNameOK
)
123 // if we have chapter info, set it!
127 /* Some of the index chapter information attributes written to ODF 1.1
128 and 1.2 don't reflect the displaying (#i89791#)
132 bool bConvert( false );
135 sal_Int32
nBuild( 0 );
136 const bool bBuildIdFound
= GetImport().getBuildIds( nUPD
, nBuild
);
137 if ( GetImport().IsTextDocInOOoFileFormat() ||
139 ( nUPD
== 680 || nUPD
== 645 || nUPD
== 641 ) ) )
146 if ( nChapterInfo
== ChapterFormat::NUMBER
)
148 nChapterInfo
= ChapterFormat::DIGIT
;
150 else if ( nChapterInfo
== ChapterFormat::NAME_NUMBER
)
152 nChapterInfo
= ChapterFormat::NO_PREFIX_SUFFIX
;
161 void XMLIndexChapterInfoEntryContext::FillPropertyValues(
162 css::uno::Sequence
<css::beans::PropertyValue
> & rValues
)
164 // entry name and (optionally) style name in parent class
165 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
167 sal_Int32 nIndex
= m_bCharStyleNameOK
? 2 : 1;
168 auto pValues
= rValues
.getArray();
172 // chapter info field
173 pValues
[nIndex
].Name
= "ChapterFormat";
174 pValues
[nIndex
].Value
<<= nChapterInfo
;
177 if( bOutlineLevelOK
)
179 pValues
[nIndex
].Name
= "ChapterLevel";
180 pValues
[nIndex
].Value
<<= nOutlineLevel
;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */