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 .
20 #include "XMLIndexTOCSourceContext.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XIndexReplace.hpp>
23 #include <sax/tools/converter.hxx>
24 #include "XMLIndexTemplateContext.hxx"
25 #include <xmloff/xmlictxt.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/txtimp.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <rtl/ustring.hxx>
33 using namespace ::xmloff::token
;
35 using ::com::sun::star::beans::XPropertySet
;
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::uno::Any
;
39 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
41 Reference
<XPropertySet
> & rPropSet
)
42 : XMLIndexSourceBaseContext(rImport
, rPropSet
, UseStyles::Level
)
43 // use all chapters by default
44 , nOutlineLevel(rImport
.GetTextImport()->GetChapterNumbering()->getCount())
47 , bUseParagraphStyles(false)
51 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
55 void XMLIndexTOCSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter
& aIter
)
57 switch (aIter
.getToken())
59 case XML_ELEMENT(TEXT
, XML_OUTLINE_LEVEL
):
60 if ( IsXMLToken( aIter
, XML_NONE
) )
62 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
63 // OUTLINE_LEVEL with values none|1..10. For backwards
64 // compatibility, 'none' must still be read.
70 if (::sax::Converter::convertNumber(
71 nTmp
, aIter
.toView(), 1, GetImport().GetTextImport()->
72 GetChapterNumbering()->getCount()))
80 case XML_ELEMENT(TEXT
, XML_USE_OUTLINE_LEVEL
):
83 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
91 case XML_ELEMENT(TEXT
, XML_USE_INDEX_MARKS
):
94 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
101 case XML_ELEMENT(TEXT
, XML_USE_INDEX_SOURCE_STYLES
):
104 if (::sax::Converter::convertBool(bTmp
, aIter
.toView()))
106 bUseParagraphStyles
= bTmp
;
112 // default: ask superclass
113 XMLIndexSourceBaseContext::ProcessAttribute(aIter
);
118 void XMLIndexTOCSourceContext::endFastElement(sal_Int32 nElement
)
120 rIndexPropertySet
->setPropertyValue("CreateFromMarks", css::uno::Any(bUseMarks
));
121 rIndexPropertySet
->setPropertyValue("CreateFromOutline", css::uno::Any(bUseOutline
));
122 rIndexPropertySet
->setPropertyValue("CreateFromLevelParagraphStyles", css::uno::Any(bUseParagraphStyles
));
124 rIndexPropertySet
->setPropertyValue("Level", css::uno::Any(static_cast<sal_Int16
>(nOutlineLevel
)));
126 // process common attributes
127 XMLIndexSourceBaseContext::endFastElement(nElement
);
130 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLIndexTOCSourceContext::createFastChildContext(
132 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
134 if ( nElement
== XML_ELEMENT(TEXT
, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE
) )
136 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet
,
139 aLevelStylePropNameTOCMap
,
140 aAllowedTokenTypesTOC
, true );
144 return XMLIndexSourceBaseContext::createFastChildContext(nElement
,
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */