Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
34 :
35 :
36 :
37 : using namespace ::xmloff::token;
38 :
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;
43 :
44 : const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
45 : const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline";
46 : const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
47 : const sal_Char sAPI_Level[] = "Level";
48 : const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
49 :
50 :
51 0 : TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext );
52 :
53 2 : XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
54 : SvXMLImport& rImport,
55 : sal_uInt16 nPrfx,
56 : const OUString& rLocalName,
57 : Reference<XPropertySet> & rPropSet)
58 : : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True)
59 : , sCreateFromMarks(sAPI_CreateFromMarks)
60 : , sLevel(sAPI_Level)
61 : , sCreateFromOutline(sAPI_CreateFromOutline)
62 : , sCreateFromLevelParagraphStyles(sAPI_CreateFromLevelParagraphStyles)
63 : // use all chapters by default
64 4 : , nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
65 : , bUseOutline(sal_True)
66 : , bUseMarks(sal_True)
67 6 : , bUseParagraphStyles(sal_False)
68 : {
69 2 : }
70 :
71 4 : XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
72 : {
73 4 : }
74 :
75 2 : void XMLIndexTOCSourceContext::ProcessAttribute(
76 : enum IndexSourceParamEnum eParam,
77 : const OUString& rValue)
78 : {
79 2 : switch (eParam)
80 : {
81 : case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL:
82 2 : if ( IsXMLToken( rValue, XML_NONE ) )
83 : {
84 : // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
85 : // OUTLINE_LEVEL with values none|1..10. For backwards
86 : // compatibility, 'none' must still be read.
87 0 : bUseOutline = sal_False;
88 : }
89 : else
90 : {
91 : sal_Int32 nTmp;
92 4 : if (::sax::Converter::convertNumber(
93 2 : nTmp, rValue, 1, GetImport().GetTextImport()->
94 4 : GetChapterNumbering()->getCount()))
95 : {
96 2 : bUseOutline = sal_True;
97 2 : nOutlineLevel = nTmp;
98 : }
99 : }
100 2 : break;
101 :
102 : case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL:
103 : {
104 0 : bool bTmp(false);
105 0 : if (::sax::Converter::convertBool(bTmp, rValue))
106 : {
107 0 : bUseOutline = bTmp;
108 : }
109 0 : break;
110 : }
111 :
112 :
113 : case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
114 : {
115 0 : bool bTmp(false);
116 0 : if (::sax::Converter::convertBool(bTmp, rValue))
117 : {
118 0 : bUseMarks = bTmp;
119 : }
120 0 : break;
121 : }
122 :
123 : case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
124 : {
125 0 : bool bTmp(false);
126 0 : if (::sax::Converter::convertBool(bTmp, rValue))
127 : {
128 0 : bUseParagraphStyles = bTmp;
129 : }
130 0 : break;
131 : }
132 :
133 : default:
134 : // default: ask superclass
135 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
136 0 : break;
137 : }
138 2 : }
139 :
140 2 : void XMLIndexTOCSourceContext::EndElement()
141 : {
142 2 : Any aAny;
143 :
144 2 : aAny.setValue(&bUseMarks, ::getBooleanCppuType());
145 2 : rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
146 :
147 2 : aAny.setValue(&bUseOutline, ::getBooleanCppuType());
148 2 : rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny);
149 :
150 2 : aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType());
151 2 : rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
152 :
153 2 : aAny <<= (sal_Int16)nOutlineLevel;
154 2 : rIndexPropertySet->setPropertyValue(sLevel, aAny);
155 :
156 : // process common attributes
157 2 : XMLIndexSourceBaseContext::EndElement();
158 2 : }
159 :
160 :
161 22 : SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext(
162 : sal_uInt16 nPrefix,
163 : const OUString& rLocalName,
164 : const Reference<XAttributeList> & xAttrList )
165 : {
166 44 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
167 22 : IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) )
168 : {
169 20 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
170 : nPrefix, rLocalName,
171 : aSvLevelNameTOCMap,
172 : XML_OUTLINE_LEVEL,
173 : aLevelStylePropNameTOCMap,
174 20 : aAllowedTokenTypesTOC, sal_True );
175 : }
176 : else
177 : {
178 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
179 : rLocalName,
180 2 : xAttrList);
181 : }
182 : }
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|