LibreOffice Module xmloff (master)  1
XMLIndexSourceBaseContext.cxx
Go to the documentation of this file.
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 
21 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <xmloff/xmlictxt.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <sax/tools/converter.hxx>
30 #include <rtl/ustring.hxx>
31 
32 
33 using namespace ::xmloff::token;
34 
35 using ::com::sun::star::beans::XPropertySet;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 
41 {
136 
138 };
139 
140 
142  SvXMLImport& rImport,
143  sal_uInt16 nPrfx,
144  const OUString& rLocalName,
145  Reference<XPropertySet> & rPropSet,
146  bool bLevelFormats)
147 : SvXMLImportContext(rImport, nPrfx, rLocalName)
148 , bUseLevelFormats(bLevelFormats)
149 , bChapterIndex(false)
150 , bRelativeTabs(true)
151 , rIndexPropertySet(rPropSet)
152 {
153 }
154 
156 {
157 }
158 
160  const Reference<XAttributeList> & xAttrList)
161 {
162  static const SvXMLTokenMap aTokenMap(aIndexSourceTokenMap);
163 
164  // process attributes
165  sal_Int16 nLength = xAttrList->getLength();
166  for(sal_Int16 i=0; i<nLength; i++)
167  {
168  // map to IndexSourceParamEnum
169  OUString sLocalName;
170  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
171  GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
172  sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName);
173 
174  // process attribute
175  ProcessAttribute(static_cast<enum IndexSourceParamEnum>(nToken),
176  xAttrList->getValueByIndex(i));
177  }
178 }
179 
181  enum IndexSourceParamEnum eParam,
182  const OUString& rValue)
183 {
184  switch (eParam)
185  {
187  if ( IsXMLToken( rValue, XML_CHAPTER ) )
188  {
189  bChapterIndex = true;
190  }
191  break;
192 
194  {
195  bool bTmp(false);
196  if (::sax::Converter::convertBool(bTmp, rValue))
197  {
198  bRelativeTabs = bTmp;
199  }
200  break;
201  }
202 
203  default:
204  // unknown attribute -> ignore
205  break;
206  }
207 }
208 
210 {
211  rIndexPropertySet->setPropertyValue("IsRelativeTabstops", css::uno::Any(bRelativeTabs));
212  rIndexPropertySet->setPropertyValue("CreateFromChapter", css::uno::Any(bChapterIndex));
213 }
214 
216  sal_uInt16 nPrefix,
217  const OUString& rLocalName,
218  const Reference<XAttributeList> & /*xAttrList*/ )
219 {
220  SvXMLImportContextRef xContext;
221 
222  if (XML_NAMESPACE_TEXT == nPrefix)
223  {
224  if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) )
225  {
226  xContext = new XMLIndexTitleTemplateContext(GetImport(),
228  nPrefix, rLocalName);
229  }
230  else if ( bUseLevelFormats &&
231  IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) )
232  {
233  xContext = new XMLIndexTOCStylesContext(GetImport(),
235  nPrefix, rLocalName);
236  }
237  // else: unknown element in text namespace -> ignore
238  }
239  // else: unknown namespace -> ignore
240 
241  return xContext;
242 }
243 
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
static XMLTokenEnum const aTokenMap[]
Definition: Oasis2OOo.cxx:1145
static bool convertBool(bool &rBool, const OUString &rString)
static const SvXMLTokenMapEntry aIndexSourceTokenMap[]
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XMLIndexSourceBaseContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bLevelFormats)
bool bRelativeTabs
chapter-wise or document index?
int i
virtual void ProcessAttribute(enum IndexSourceParamEnum eParam, const OUString &rValue)
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:93
Import index title templates.
Import elements and their children.
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
constexpr sal_uInt16 XML_NAMESPACE_FO
Definition: xmlnmspe.hxx:34
css::uno::Reference< css::beans::XPropertySet > & rIndexPropertySet
tab stops relative to margin or indent?
DefTokenId nToken
Handling of tokens in XML:
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
sal_Int32 nLength
Definition: xmltoken.cxx:36