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 "XMLIndexTitleTemplateContext.hxx"
26 #include "XMLIndexTOCStylesContext.hxx"
27 #include <xmloff/xmlictxt.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/txtimp.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <rtl/ustring.hxx>
37 using namespace ::xmloff::token
;
39 using ::com::sun::star::beans::XPropertySet
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Any
;
42 using ::com::sun::star::xml::sax::XAttributeList
;
44 const sal_Char sAPI_CreateFromOutline
[] = "CreateFromOutline";
45 const sal_Char sAPI_CreateFromMarks
[] = "CreateFromMarks";
46 const sal_Char sAPI_Level
[] = "Level";
47 const sal_Char sAPI_CreateFromLevelParagraphStyles
[] = "CreateFromLevelParagraphStyles";
50 TYPEINIT1( XMLIndexTOCSourceContext
, XMLIndexSourceBaseContext
);
52 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
55 const OUString
& rLocalName
,
56 Reference
<XPropertySet
> & rPropSet
)
57 : XMLIndexSourceBaseContext(rImport
, nPrfx
, rLocalName
, rPropSet
, true)
58 , sCreateFromMarks(sAPI_CreateFromMarks
)
60 , sCreateFromOutline(sAPI_CreateFromOutline
)
61 , sCreateFromLevelParagraphStyles(sAPI_CreateFromLevelParagraphStyles
)
62 // use all chapters by default
63 , nOutlineLevel(rImport
.GetTextImport()->GetChapterNumbering()->getCount())
66 , bUseParagraphStyles(false)
70 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
74 void XMLIndexTOCSourceContext::ProcessAttribute(
75 enum IndexSourceParamEnum eParam
,
76 const OUString
& rValue
)
80 case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL
:
81 if ( IsXMLToken( rValue
, XML_NONE
) )
83 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
84 // OUTLINE_LEVEL with values none|1..10. For backwards
85 // compatibility, 'none' must still be read.
91 if (::sax::Converter::convertNumber(
92 nTmp
, rValue
, 1, GetImport().GetTextImport()->
93 GetChapterNumbering()->getCount()))
101 case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL
:
104 if (::sax::Converter::convertBool(bTmp
, rValue
))
112 case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS
:
115 if (::sax::Converter::convertBool(bTmp
, rValue
))
122 case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES
:
125 if (::sax::Converter::convertBool(bTmp
, rValue
))
127 bUseParagraphStyles
= bTmp
;
133 // default: ask superclass
134 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
139 void XMLIndexTOCSourceContext::EndElement()
143 aAny
.setValue(&bUseMarks
, cppu::UnoType
<bool>::get());
144 rIndexPropertySet
->setPropertyValue(sCreateFromMarks
, aAny
);
146 aAny
.setValue(&bUseOutline
, cppu::UnoType
<bool>::get());
147 rIndexPropertySet
->setPropertyValue(sCreateFromOutline
, aAny
);
149 aAny
.setValue(&bUseParagraphStyles
, cppu::UnoType
<bool>::get());
150 rIndexPropertySet
->setPropertyValue(sCreateFromLevelParagraphStyles
, aAny
);
152 aAny
<<= (sal_Int16
)nOutlineLevel
;
153 rIndexPropertySet
->setPropertyValue(sLevel
, aAny
);
155 // process common attributes
156 XMLIndexSourceBaseContext::EndElement();
160 SvXMLImportContext
* XMLIndexTOCSourceContext::CreateChildContext(
162 const OUString
& rLocalName
,
163 const Reference
<XAttributeList
> & xAttrList
)
165 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
166 IsXMLToken(rLocalName
, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE
) )
168 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet
,
172 aLevelStylePropNameTOCMap
,
173 aAllowedTokenTypesTOC
, true );
177 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */