LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexSourceBaseContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 48 72.9 %
Date: 2015-06-13 12:38:46 Functions: 5 12 41.7 %
Legend: Lines: hit not hit

          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 "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>
      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_IsRelativeTabstops[] = "IsRelativeTabstops";
      46             : 
      47             : static const SvXMLTokenMapEntry aIndexSourceTokenMap[] =
      48             : {
      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},
     143             : 
     144             :     XML_TOKEN_MAP_END
     145             : };
     146             : 
     147             : 
     148           0 : TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext );
     149             : 
     150          23 : 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          23 : ,   rIndexPropertySet(rPropSet)
     163             : {
     164          23 : }
     165             : 
     166          23 : XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
     167             : {
     168          23 : }
     169             : 
     170          23 : void XMLIndexSourceBaseContext::StartElement(
     171             :     const Reference<XAttributeList> & xAttrList)
     172             : {
     173          23 :     SvXMLTokenMap aTokenMap(aIndexSourceTokenMap);
     174             : 
     175             :     // process attributes
     176          23 :     sal_Int16 nLength = xAttrList->getLength();
     177          78 :     for(sal_Int16 i=0; i<nLength; i++)
     178             :     {
     179             :         // map to IndexSourceParamEnum
     180          55 :         OUString sLocalName;
     181          55 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     182         110 :             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
     183          55 :         sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName);
     184             : 
     185             :         // process attribute
     186             :         ProcessAttribute((enum IndexSourceParamEnum)nToken,
     187          55 :                          xAttrList->getValueByIndex(i));
     188          78 :     }
     189          23 : }
     190             : 
     191           0 : void XMLIndexSourceBaseContext::ProcessAttribute(
     192             :     enum IndexSourceParamEnum eParam,
     193             :     const OUString& rValue)
     194             : {
     195           0 :     switch (eParam)
     196             :     {
     197             :         case XML_TOK_INDEXSOURCE_INDEX_SCOPE:
     198           0 :             if ( IsXMLToken( rValue, XML_CHAPTER ) )
     199             :             {
     200           0 :                 bChapterIndex = true;
     201             :             }
     202           0 :             break;
     203             : 
     204             :         case XML_TOK_INDEXSOURCE_RELATIVE_TABS:
     205             :         {
     206           0 :             bool bTmp(false);
     207           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     208             :             {
     209           0 :                 bRelativeTabs = bTmp;
     210             :             }
     211           0 :             break;
     212             :         }
     213             : 
     214             :         default:
     215             :             // unknown attribute -> ignore
     216           0 :             break;
     217             :     }
     218           0 : }
     219             : 
     220          20 : void XMLIndexSourceBaseContext::EndElement()
     221             : {
     222          20 :     Any aAny;
     223             : 
     224          20 :     aAny.setValue(&bRelativeTabs, cppu::UnoType<bool>::get());
     225          20 :     rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny);
     226             : 
     227          20 :     aAny.setValue(&bChapterIndex, cppu::UnoType<bool>::get());
     228          20 :     rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny);
     229          20 : }
     230             : 
     231          27 : SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext(
     232             :     sal_uInt16 nPrefix,
     233             :     const OUString& rLocalName,
     234             :     const Reference<XAttributeList> & xAttrList )
     235             : {
     236          27 :     SvXMLImportContext* pContext = NULL;
     237             : 
     238          27 :     if (XML_NAMESPACE_TEXT == nPrefix)
     239             :     {
     240          27 :         if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) )
     241             :         {
     242          23 :             pContext = new XMLIndexTitleTemplateContext(GetImport(),
     243             :                                                         rIndexPropertySet,
     244          23 :                                                         nPrefix, rLocalName);
     245             :         }
     246           8 :         else if ( bUseLevelFormats &&
     247           4 :                   IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) )
     248             :         {
     249           4 :             pContext = new XMLIndexTOCStylesContext(GetImport(),
     250             :                                                     rIndexPropertySet,
     251           4 :                                                     nPrefix, rLocalName);
     252             :         }
     253             :         // else: unknown element in text namespace -> ignore
     254             :     }
     255             :     // else: unknown namespace -> ignore
     256             : 
     257             :     // use default context
     258          27 :     if (pContext == NULL)
     259             :     {
     260             :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
     261           0 :                                                           xAttrList);
     262             :     }
     263             : 
     264          27 :     return pContext;
     265             : }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11