bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLIndexSourceBaseContext.cxx
blobf7d29f44304eade075b8c7ee9a1d975ad5e7f641
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XMLIndexSourceBaseContext.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XIndexReplace.hpp>
23 #include "XMLIndexTemplateContext.hxx"
24 #include "XMLIndexTitleTemplateContext.hxx"
25 #include "XMLIndexTOCStylesContext.hxx"
26 #include <xmloff/xmlictxt.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/txtimp.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <sax/tools/converter.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_CreateFromChapter[] = "CreateFromChapter";
45 const sal_Char sAPI_IsRelativeTabstops[] = "IsRelativeTabstops";
47 static const SvXMLTokenMapEntry aIndexSourceTokenMap[] =
49 { XML_NAMESPACE_TEXT,
50 XML_OUTLINE_LEVEL,
51 XML_TOK_INDEXSOURCE_OUTLINE_LEVEL},
52 { XML_NAMESPACE_TEXT,
53 XML_USE_INDEX_MARKS,
54 XML_TOK_INDEXSOURCE_USE_INDEX_MARKS },
55 { XML_NAMESPACE_TEXT,
56 XML_INDEX_SCOPE,
57 XML_TOK_INDEXSOURCE_INDEX_SCOPE },
58 { XML_NAMESPACE_TEXT,
59 XML_RELATIVE_TAB_STOP_POSITION,
60 XML_TOK_INDEXSOURCE_RELATIVE_TABS } ,
61 { XML_NAMESPACE_TEXT,
62 XML_USE_OTHER_OBJECTS,
63 XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS },
64 { XML_NAMESPACE_TEXT,
65 XML_USE_SPREADSHEET_OBJECTS,
66 XML_TOK_INDEXSOURCE_USE_SHEET },
67 { XML_NAMESPACE_TEXT,
68 XML_USE_CHART_OBJECTS,
69 XML_TOK_INDEXSOURCE_USE_CHART },
70 { XML_NAMESPACE_TEXT,
71 XML_USE_DRAW_OBJECTS,
72 XML_TOK_INDEXSOURCE_USE_DRAW },
73 { XML_NAMESPACE_TEXT,
74 XML_USE_IMAGE_OBJECTS,
75 XML_TOK_INDEXSOURCE_USE_IMAGE },
76 { XML_NAMESPACE_TEXT,
77 XML_USE_MATH_OBJECTS,
78 XML_TOK_INDEXSOURCE_USE_MATH },
79 { XML_NAMESPACE_TEXT,
80 XML_MAIN_ENTRY_STYLE_NAME,
81 XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE },
82 { XML_NAMESPACE_TEXT,
83 XML_IGNORE_CASE,
84 XML_TOK_INDEXSOURCE_IGNORE_CASE },
85 { XML_NAMESPACE_TEXT,
86 XML_ALPHABETICAL_SEPARATORS,
87 XML_TOK_INDEXSOURCE_SEPARATORS },
88 { XML_NAMESPACE_TEXT,
89 XML_COMBINE_ENTRIES,
90 XML_TOK_INDEXSOURCE_COMBINE_ENTRIES },
91 { XML_NAMESPACE_TEXT,
92 XML_COMBINE_ENTRIES_WITH_DASH,
93 XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH },
94 { XML_NAMESPACE_TEXT,
95 XML_USE_KEYS_AS_ENTRIES,
96 XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES },
97 { XML_NAMESPACE_TEXT,
98 XML_COMBINE_ENTRIES_WITH_PP,
99 XML_TOK_INDEXSOURCE_COMBINE_WITH_PP },
100 { XML_NAMESPACE_TEXT,
101 XML_CAPITALIZE_ENTRIES,
102 XML_TOK_INDEXSOURCE_CAPITALIZE },
103 { XML_NAMESPACE_TEXT,
104 XML_USE_OBJECTS,
105 XML_TOK_INDEXSOURCE_USE_OBJECTS },
106 { XML_NAMESPACE_TEXT,
107 XML_USE_GRAPHICS,
108 XML_TOK_INDEXSOURCE_USE_GRAPHICS },
109 { XML_NAMESPACE_TEXT,
110 XML_USE_TABLES,
111 XML_TOK_INDEXSOURCE_USE_TABLES },
112 { XML_NAMESPACE_TEXT,
113 XML_USE_FLOATING_FRAMES,
114 XML_TOK_INDEXSOURCE_USE_FRAMES },
115 { XML_NAMESPACE_TEXT,
116 XML_COPY_OUTLINE_LEVELS,
117 XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS },
118 { XML_NAMESPACE_TEXT,
119 XML_USE_CAPTION,
120 XML_TOK_INDEXSOURCE_USE_CAPTION },
121 { XML_NAMESPACE_TEXT,
122 XML_CAPTION_SEQUENCE_NAME,
123 XML_TOK_INDEXSOURCE_SEQUENCE_NAME },
124 { XML_NAMESPACE_TEXT,
125 XML_CAPTION_SEQUENCE_FORMAT,
126 XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT },
127 { XML_NAMESPACE_TEXT,
128 XML_COMMA_SEPARATED,
129 XML_TOK_INDEXSOURCE_COMMA_SEPARATED },
130 { XML_NAMESPACE_TEXT,
131 XML_USE_INDEX_SOURCE_STYLES,
132 XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES },
133 { XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
134 XML_TOK_INDEXSOURCE_SORT_ALGORITHM },
135 { XML_NAMESPACE_STYLE, XML_RFC_LANGUAGE_TAG, XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG },
136 { XML_NAMESPACE_FO, XML_LANGUAGE, XML_TOK_INDEXSOURCE_LANGUAGE },
137 { XML_NAMESPACE_FO, XML_SCRIPT, XML_TOK_INDEXSOURCE_SCRIPT },
138 { XML_NAMESPACE_FO, XML_COUNTRY, XML_TOK_INDEXSOURCE_COUNTRY },
139 { XML_NAMESPACE_TEXT, XML_INDEX_NAME, XML_TOK_INDEXSOURCE_USER_INDEX_NAME },
140 { XML_NAMESPACE_TEXT,
141 XML_USE_OUTLINE_LEVEL,
142 XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL},
144 XML_TOKEN_MAP_END
148 TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext );
150 XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
151 SvXMLImport& rImport,
152 sal_uInt16 nPrfx,
153 const OUString& rLocalName,
154 Reference<XPropertySet> & rPropSet,
155 bool bLevelFormats)
156 : SvXMLImportContext(rImport, nPrfx, rLocalName)
157 , sCreateFromChapter(sAPI_CreateFromChapter)
158 , sIsRelativeTabstops(sAPI_IsRelativeTabstops)
159 , bUseLevelFormats(bLevelFormats)
160 , bChapterIndex(false)
161 , bRelativeTabs(true)
162 , rIndexPropertySet(rPropSet)
166 XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
170 void XMLIndexSourceBaseContext::StartElement(
171 const Reference<XAttributeList> & xAttrList)
173 SvXMLTokenMap aTokenMap(aIndexSourceTokenMap);
175 // process attributes
176 sal_Int16 nLength = xAttrList->getLength();
177 for(sal_Int16 i=0; i<nLength; i++)
179 // map to IndexSourceParamEnum
180 OUString sLocalName;
181 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
182 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
183 sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName);
185 // process attribute
186 ProcessAttribute((enum IndexSourceParamEnum)nToken,
187 xAttrList->getValueByIndex(i));
191 void XMLIndexSourceBaseContext::ProcessAttribute(
192 enum IndexSourceParamEnum eParam,
193 const OUString& rValue)
195 switch (eParam)
197 case XML_TOK_INDEXSOURCE_INDEX_SCOPE:
198 if ( IsXMLToken( rValue, XML_CHAPTER ) )
200 bChapterIndex = true;
202 break;
204 case XML_TOK_INDEXSOURCE_RELATIVE_TABS:
206 bool bTmp(false);
207 if (::sax::Converter::convertBool(bTmp, rValue))
209 bRelativeTabs = bTmp;
211 break;
214 default:
215 // unknown attribute -> ignore
216 break;
220 void XMLIndexSourceBaseContext::EndElement()
222 Any aAny;
224 aAny.setValue(&bRelativeTabs, cppu::UnoType<bool>::get());
225 rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny);
227 aAny.setValue(&bChapterIndex, cppu::UnoType<bool>::get());
228 rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny);
231 SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext(
232 sal_uInt16 nPrefix,
233 const OUString& rLocalName,
234 const Reference<XAttributeList> & xAttrList )
236 SvXMLImportContext* pContext = NULL;
238 if (XML_NAMESPACE_TEXT == nPrefix)
240 if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) )
242 pContext = new XMLIndexTitleTemplateContext(GetImport(),
243 rIndexPropertySet,
244 nPrefix, rLocalName);
246 else if ( bUseLevelFormats &&
247 IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) )
249 pContext = new XMLIndexTOCStylesContext(GetImport(),
250 rIndexPropertySet,
251 nPrefix, rLocalName);
253 // else: unknown element in text namespace -> ignore
255 // else: unknown namespace -> ignore
257 // use default context
258 if (pContext == NULL)
260 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
261 xAttrList);
264 return pContext;
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */