LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - XMLIndexSourceBaseContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 47 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
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 ::rtl::OUString;
      40             : using ::com::sun::star::beans::XPropertySet;
      41             : using ::com::sun::star::uno::Reference;
      42             : using ::com::sun::star::uno::Any;
      43             : using ::com::sun::star::xml::sax::XAttributeList;
      44             : 
      45             : const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
      46             : const sal_Char sAPI_IsRelativeTabstops[] = "IsRelativeTabstops";
      47             : 
      48             : static SvXMLTokenMapEntry aIndexSourceTokenMap[] =
      49             : {
      50             :     { XML_NAMESPACE_TEXT,
      51             :           XML_OUTLINE_LEVEL,
      52             :           XML_TOK_INDEXSOURCE_OUTLINE_LEVEL},
      53             :     { XML_NAMESPACE_TEXT,
      54             :           XML_USE_INDEX_MARKS,
      55             :           XML_TOK_INDEXSOURCE_USE_INDEX_MARKS },
      56             :     { XML_NAMESPACE_TEXT,
      57             :           XML_INDEX_SCOPE,
      58             :           XML_TOK_INDEXSOURCE_INDEX_SCOPE },
      59             :     { XML_NAMESPACE_TEXT,
      60             :           XML_RELATIVE_TAB_STOP_POSITION,
      61             :           XML_TOK_INDEXSOURCE_RELATIVE_TABS } ,
      62             :     { XML_NAMESPACE_TEXT,
      63             :           XML_USE_OTHER_OBJECTS,
      64             :           XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS },
      65             :     { XML_NAMESPACE_TEXT,
      66             :           XML_USE_SPREADSHEET_OBJECTS,
      67             :           XML_TOK_INDEXSOURCE_USE_SHEET },
      68             :     { XML_NAMESPACE_TEXT,
      69             :           XML_USE_CHART_OBJECTS,
      70             :           XML_TOK_INDEXSOURCE_USE_CHART },
      71             :     { XML_NAMESPACE_TEXT,
      72             :           XML_USE_DRAW_OBJECTS,
      73             :           XML_TOK_INDEXSOURCE_USE_DRAW },
      74             :     { XML_NAMESPACE_TEXT,
      75             :           XML_USE_IMAGE_OBJECTS,
      76             :           XML_TOK_INDEXSOURCE_USE_IMAGE },
      77             :     { XML_NAMESPACE_TEXT,
      78             :           XML_USE_MATH_OBJECTS,
      79             :           XML_TOK_INDEXSOURCE_USE_MATH },
      80             :     { XML_NAMESPACE_TEXT,
      81             :           XML_MAIN_ENTRY_STYLE_NAME,
      82             :           XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE },
      83             :     { XML_NAMESPACE_TEXT,
      84             :           XML_IGNORE_CASE,
      85             :           XML_TOK_INDEXSOURCE_IGNORE_CASE },
      86             :     { XML_NAMESPACE_TEXT,
      87             :           XML_ALPHABETICAL_SEPARATORS,
      88             :           XML_TOK_INDEXSOURCE_SEPARATORS },
      89             :     { XML_NAMESPACE_TEXT,
      90             :           XML_COMBINE_ENTRIES,
      91             :           XML_TOK_INDEXSOURCE_COMBINE_ENTRIES },
      92             :     { XML_NAMESPACE_TEXT,
      93             :           XML_COMBINE_ENTRIES_WITH_DASH,
      94             :           XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH },
      95             :     { XML_NAMESPACE_TEXT,
      96             :           XML_USE_KEYS_AS_ENTRIES,
      97             :           XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES },
      98             :     { XML_NAMESPACE_TEXT,
      99             :           XML_COMBINE_ENTRIES_WITH_PP,
     100             :           XML_TOK_INDEXSOURCE_COMBINE_WITH_PP },
     101             :     { XML_NAMESPACE_TEXT,
     102             :           XML_CAPITALIZE_ENTRIES,
     103             :           XML_TOK_INDEXSOURCE_CAPITALIZE },
     104             :     { XML_NAMESPACE_TEXT,
     105             :           XML_USE_OBJECTS,
     106             :           XML_TOK_INDEXSOURCE_USE_OBJECTS },
     107             :     { XML_NAMESPACE_TEXT,
     108             :           XML_USE_GRAPHICS,
     109             :           XML_TOK_INDEXSOURCE_USE_GRAPHICS },
     110             :     { XML_NAMESPACE_TEXT,
     111             :           XML_USE_TABLES,
     112             :           XML_TOK_INDEXSOURCE_USE_TABLES },
     113             :     { XML_NAMESPACE_TEXT,
     114             :           XML_USE_FLOATING_FRAMES,
     115             :           XML_TOK_INDEXSOURCE_USE_FRAMES },
     116             :     { XML_NAMESPACE_TEXT,
     117             :           XML_COPY_OUTLINE_LEVELS,
     118             :           XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS },
     119             :     { XML_NAMESPACE_TEXT,
     120             :           XML_USE_CAPTION,
     121             :           XML_TOK_INDEXSOURCE_USE_CAPTION },
     122             :     { XML_NAMESPACE_TEXT,
     123             :           XML_CAPTION_SEQUENCE_NAME,
     124             :           XML_TOK_INDEXSOURCE_SEQUENCE_NAME },
     125             :     { XML_NAMESPACE_TEXT,
     126             :           XML_CAPTION_SEQUENCE_FORMAT,
     127             :           XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT },
     128             :     { XML_NAMESPACE_TEXT,
     129             :           XML_COMMA_SEPARATED,
     130             :           XML_TOK_INDEXSOURCE_COMMA_SEPARATED },
     131             :     { XML_NAMESPACE_TEXT,
     132             :           XML_USE_INDEX_SOURCE_STYLES,
     133             :           XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES },
     134             :     { XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
     135             :           XML_TOK_INDEXSOURCE_SORT_ALGORITHM },
     136             :     { XML_NAMESPACE_FO, XML_LANGUAGE, XML_TOK_INDEXSOURCE_LANGUAGE },
     137             :     { XML_NAMESPACE_FO, XML_COUNTRY, XML_TOK_INDEXSOURCE_COUNTRY },
     138             :     { XML_NAMESPACE_TEXT, XML_INDEX_NAME, XML_TOK_INDEXSOURCE_USER_INDEX_NAME },
     139             :     { XML_NAMESPACE_TEXT,
     140             :           XML_USE_OUTLINE_LEVEL,
     141             :           XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL},
     142             : 
     143             :     XML_TOKEN_MAP_END
     144             : };
     145             : 
     146             : 
     147           0 : TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext );
     148             : 
     149           0 : XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
     150             :     SvXMLImport& rImport,
     151             :     sal_uInt16 nPrfx,
     152             :     const OUString& rLocalName,
     153             :     Reference<XPropertySet> & rPropSet,
     154             :     sal_Bool bLevelFormats)
     155             : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
     156             : ,   sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromChapter))
     157             : ,   sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsRelativeTabstops))
     158             : ,   bUseLevelFormats(bLevelFormats)
     159             : ,   bChapterIndex(sal_False)
     160             : ,   bRelativeTabs(sal_True)
     161           0 : ,   rIndexPropertySet(rPropSet)
     162             : {
     163           0 : }
     164             : 
     165           0 : XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
     166             : {
     167           0 : }
     168             : 
     169           0 : void XMLIndexSourceBaseContext::StartElement(
     170             :     const Reference<XAttributeList> & xAttrList)
     171             : {
     172           0 :     SvXMLTokenMap aTokenMap(aIndexSourceTokenMap);
     173             : 
     174             :     // process attributes
     175           0 :     sal_Int16 nLength = xAttrList->getLength();
     176           0 :     for(sal_Int16 i=0; i<nLength; i++)
     177             :     {
     178             :         // map to IndexSourceParamEnum
     179           0 :         OUString sLocalName;
     180           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     181           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
     182           0 :         sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName);
     183             : 
     184             :         // process attribute
     185             :         ProcessAttribute((enum IndexSourceParamEnum)nToken,
     186           0 :                          xAttrList->getValueByIndex(i));
     187           0 :     }
     188           0 : }
     189             : 
     190           0 : void XMLIndexSourceBaseContext::ProcessAttribute(
     191             :     enum IndexSourceParamEnum eParam,
     192             :     const OUString& rValue)
     193             : {
     194           0 :     switch (eParam)
     195             :     {
     196             :         case XML_TOK_INDEXSOURCE_INDEX_SCOPE:
     197           0 :             if ( IsXMLToken( rValue, XML_CHAPTER ) )
     198             :             {
     199           0 :                 bChapterIndex = sal_True;
     200             :             }
     201           0 :             break;
     202             : 
     203             :         case XML_TOK_INDEXSOURCE_RELATIVE_TABS:
     204             :         {
     205           0 :             bool bTmp(false);
     206           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     207             :             {
     208           0 :                 bRelativeTabs = bTmp;
     209             :             }
     210             :             break;
     211             :         }
     212             : 
     213             :         default:
     214             :             // unknown attribute -> ignore
     215           0 :             break;
     216             :     }
     217           0 : }
     218             : 
     219           0 : void XMLIndexSourceBaseContext::EndElement()
     220             : {
     221           0 :     Any aAny;
     222             : 
     223           0 :     aAny.setValue(&bRelativeTabs, ::getBooleanCppuType());
     224           0 :     rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny);
     225             : 
     226           0 :     aAny.setValue(&bChapterIndex, ::getBooleanCppuType());
     227           0 :     rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny);
     228           0 : }
     229             : 
     230           0 : SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext(
     231             :     sal_uInt16 nPrefix,
     232             :     const OUString& rLocalName,
     233             :     const Reference<XAttributeList> & xAttrList )
     234             : {
     235           0 :     SvXMLImportContext* pContext = NULL;
     236             : 
     237           0 :     if (XML_NAMESPACE_TEXT == nPrefix)
     238             :     {
     239           0 :         if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) )
     240             :         {
     241           0 :             pContext = new XMLIndexTitleTemplateContext(GetImport(),
     242             :                                                         rIndexPropertySet,
     243           0 :                                                         nPrefix, rLocalName);
     244             :         }
     245           0 :         else if ( bUseLevelFormats &&
     246           0 :                   IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) )
     247             :         {
     248           0 :             pContext = new XMLIndexTOCStylesContext(GetImport(),
     249             :                                                     rIndexPropertySet,
     250           0 :                                                     nPrefix, rLocalName);
     251             :         }
     252             :         // else: unknown element in text namespace -> ignore
     253             :     }
     254             :     // else: unknown namespace -> ignore
     255             : 
     256             :     // use default context
     257           0 :     if (pContext == NULL)
     258             :     {
     259             :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
     260           0 :                                                           xAttrList);
     261             :     }
     262             : 
     263           0 :     return pContext;
     264             : }
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10