LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexAlphabeticalSourceContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 88 54.5 %
Date: 2014-11-03 Functions: 6 11 54.5 %
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             : 
      21             : #include "XMLIndexAlphabeticalSourceContext.hxx"
      22             : 
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XIndexReplace.hpp>
      25             : 
      26             : #include <sax/tools/converter.hxx>
      27             : 
      28             : #include "XMLIndexTemplateContext.hxx"
      29             : #include "XMLIndexTitleTemplateContext.hxx"
      30             : #include "XMLIndexTOCStylesContext.hxx"
      31             : #include <xmloff/xmlictxt.hxx>
      32             : #include <xmloff/xmlimp.hxx>
      33             : #include <xmloff/txtimp.hxx>
      34             : #include <xmloff/xmlnmspe.hxx>
      35             : #include <xmloff/nmspmap.hxx>
      36             : #include <xmloff/xmltoken.hxx>
      37             : #include <xmloff/xmluconv.hxx>
      38             : #include <rtl/ustring.hxx>
      39             : 
      40             : 
      41             : 
      42             : 
      43             : using ::com::sun::star::beans::XPropertySet;
      44             : using ::com::sun::star::uno::Reference;
      45             : using ::com::sun::star::uno::Any;
      46             : using ::com::sun::star::xml::sax::XAttributeList;
      47             : using ::xmloff::token::IsXMLToken;
      48             : using ::xmloff::token::XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE;
      49             : using ::xmloff::token::XML_OUTLINE_LEVEL;
      50             : 
      51             : const sal_Char sAPI_MainEntryCharacterStyleName[] = "MainEntryCharacterStyleName";
      52             : const sal_Char sAPI_UseAlphabeticalSeparators[] = "UseAlphabeticalSeparators";
      53             : const sal_Char sAPI_UseCombinedEntries[] = "UseCombinedEntries";
      54             : const sal_Char sAPI_IsCaseSensitive[] = "IsCaseSensitive";
      55             : const sal_Char sAPI_UseKeyAsEntry[] = "UseKeyAsEntry";
      56             : const sal_Char sAPI_UseUpperCase[] = "UseUpperCase";
      57             : const sal_Char sAPI_UseDash[] = "UseDash";
      58             : const sal_Char sAPI_UsePP[] = "UsePP";
      59             : const sal_Char sAPI_SortAlgorithm[] = "SortAlgorithm";
      60             : const sal_Char sAPI_Locale[] = "Locale";
      61             : 
      62             : 
      63           0 : TYPEINIT1( XMLIndexAlphabeticalSourceContext, XMLIndexSourceBaseContext );
      64             : 
      65           4 : XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
      66             :     SvXMLImport& rImport,
      67             :     sal_uInt16 nPrfx,
      68             :     const OUString& rLocalName,
      69             :     Reference<XPropertySet> & rPropSet)
      70             : :   XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, false)
      71             : ,   sMainEntryCharacterStyleName(sAPI_MainEntryCharacterStyleName)
      72             : ,   sUseAlphabeticalSeparators(sAPI_UseAlphabeticalSeparators)
      73             : ,   sUseCombinedEntries(sAPI_UseCombinedEntries)
      74             : ,   sIsCaseSensitive(sAPI_IsCaseSensitive)
      75             : ,   sUseKeyAsEntry(sAPI_UseKeyAsEntry)
      76             : ,   sUseUpperCase(sAPI_UseUpperCase)
      77             : ,   sUseDash(sAPI_UseDash)
      78             : ,   sUsePP(sAPI_UsePP)
      79             : ,   sIsCommaSeparated("IsCommaSeparated")
      80             : ,   sSortAlgorithm(sAPI_SortAlgorithm)
      81             : ,   sLocale(sAPI_Locale)
      82             : ,   bMainEntryStyleNameOK(false)
      83             : ,   bSeparators(false)
      84             : ,   bCombineEntries(true)
      85             : ,   bCaseSensitive(true)
      86             : ,   bEntry(false)
      87             : ,   bUpperCase(false)
      88             : ,   bCombineDash(false)
      89             : ,   bCombinePP(true)
      90           4 : ,   bCommaSeparated(false)
      91             : {
      92           4 : }
      93             : 
      94           8 : XMLIndexAlphabeticalSourceContext::~XMLIndexAlphabeticalSourceContext()
      95             : {
      96           8 : }
      97             : 
      98          12 : void XMLIndexAlphabeticalSourceContext::ProcessAttribute(
      99             :     enum IndexSourceParamEnum eParam,
     100             :     const OUString& rValue)
     101             : {
     102          12 :     bool bTmp(false);
     103             : 
     104          12 :     switch (eParam)
     105             :     {
     106             :         case XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE:
     107             :             {
     108           0 :                 sMainEntryStyleName = rValue;
     109           0 :                 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
     110           0 :                     XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
     111             :                 const Reference < ::com::sun::star::container::XNameContainer >&
     112           0 :                     rStyles = GetImport().GetTextImport()->GetTextStyles();
     113           0 :                 bMainEntryStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
     114             :             }
     115           0 :             break;
     116             : 
     117             :         case XML_TOK_INDEXSOURCE_IGNORE_CASE:
     118           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     119             :             {
     120           0 :                 bCaseSensitive = !bTmp;
     121             :             }
     122           0 :             break;
     123             : 
     124             :         case XML_TOK_INDEXSOURCE_SEPARATORS:
     125           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     126             :             {
     127           0 :                 bSeparators = bTmp;
     128             :             }
     129           0 :             break;
     130             : 
     131             :         case XML_TOK_INDEXSOURCE_COMBINE_ENTRIES:
     132           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     133             :             {
     134           0 :                 bCombineEntries = bTmp;
     135             :             }
     136           0 :             break;
     137             : 
     138             :         case XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH:
     139           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     140             :             {
     141           0 :                 bCombineDash = bTmp;
     142             :             }
     143           0 :             break;
     144             :         case XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES:
     145           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     146             :             {
     147           0 :                 bEntry = bTmp;
     148             :             }
     149           0 :             break;
     150             : 
     151             :         case XML_TOK_INDEXSOURCE_COMBINE_WITH_PP:
     152           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     153             :             {
     154           0 :                 bCombinePP = bTmp;
     155             :             }
     156           0 :             break;
     157             : 
     158             :         case XML_TOK_INDEXSOURCE_CAPITALIZE:
     159           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     160             :             {
     161           0 :                 bUpperCase = bTmp;
     162             :             }
     163           0 :             break;
     164             : 
     165             :         case XML_TOK_INDEXSOURCE_COMMA_SEPARATED:
     166           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     167             :             {
     168           0 :                 bCommaSeparated = bTmp;
     169             :             }
     170           0 :             break;
     171             : 
     172             :         case XML_TOK_INDEXSOURCE_SORT_ALGORITHM:
     173           4 :             sAlgorithm = rValue;
     174           4 :             break;
     175             :         case XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG:
     176           0 :             maLanguageTagODF.maRfcLanguageTag = rValue;
     177           0 :             break;
     178             :         case XML_TOK_INDEXSOURCE_LANGUAGE:
     179           4 :             maLanguageTagODF.maLanguage = rValue;
     180           4 :             break;
     181             :         case XML_TOK_INDEXSOURCE_SCRIPT:
     182           0 :             maLanguageTagODF.maScript = rValue;
     183           0 :             break;
     184             :         case XML_TOK_INDEXSOURCE_COUNTRY:
     185           4 :             maLanguageTagODF.maCountry = rValue;
     186           4 :             break;
     187             : 
     188             :         default:
     189           0 :             XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
     190           0 :             break;
     191             :     }
     192          12 : }
     193             : 
     194           4 : void XMLIndexAlphabeticalSourceContext::EndElement()
     195             : {
     196             : 
     197           4 :     Any aAny;
     198             : 
     199           4 :     if (bMainEntryStyleNameOK)
     200             :     {
     201           0 :         aAny <<= GetImport().GetStyleDisplayName(
     202           0 :                             XML_STYLE_FAMILY_TEXT_TEXT, sMainEntryStyleName );
     203           0 :         rIndexPropertySet->setPropertyValue(sMainEntryCharacterStyleName,aAny);
     204             :     }
     205             : 
     206           4 :     aAny.setValue(&bSeparators, ::getBooleanCppuType());
     207           4 :     rIndexPropertySet->setPropertyValue(sUseAlphabeticalSeparators, aAny);
     208             : 
     209           4 :     aAny.setValue(&bCombineEntries, ::getBooleanCppuType());
     210           4 :     rIndexPropertySet->setPropertyValue(sUseCombinedEntries, aAny);
     211             : 
     212           4 :     aAny.setValue(&bCaseSensitive, ::getBooleanCppuType());
     213           4 :     rIndexPropertySet->setPropertyValue(sIsCaseSensitive, aAny);
     214             : 
     215           4 :     aAny.setValue(&bEntry, ::getBooleanCppuType());
     216           4 :     rIndexPropertySet->setPropertyValue(sUseKeyAsEntry, aAny);
     217             : 
     218           4 :     aAny.setValue(&bUpperCase, ::getBooleanCppuType());
     219           4 :     rIndexPropertySet->setPropertyValue(sUseUpperCase, aAny);
     220             : 
     221           4 :     aAny.setValue(&bCombineDash, ::getBooleanCppuType());
     222           4 :     rIndexPropertySet->setPropertyValue(sUseDash, aAny);
     223             : 
     224           4 :     aAny.setValue(&bCombinePP, ::getBooleanCppuType());
     225           4 :     rIndexPropertySet->setPropertyValue(sUsePP, aAny);
     226             : 
     227           4 :     aAny.setValue(&bCommaSeparated, ::getBooleanCppuType());
     228           4 :     rIndexPropertySet->setPropertyValue(sIsCommaSeparated, aAny);
     229             : 
     230             : 
     231           4 :     if (!sAlgorithm.isEmpty())
     232             :     {
     233           4 :         aAny <<= sAlgorithm;
     234           4 :         rIndexPropertySet->setPropertyValue(sSortAlgorithm, aAny);
     235             :     }
     236             : 
     237           4 :     if ( !maLanguageTagODF.isEmpty() )
     238             :     {
     239           4 :         aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
     240           4 :         rIndexPropertySet->setPropertyValue(sLocale, aAny);
     241             :     }
     242             : 
     243           4 :     XMLIndexSourceBaseContext::EndElement();
     244           4 : }
     245             : 
     246          20 : SvXMLImportContext* XMLIndexAlphabeticalSourceContext::CreateChildContext(
     247             :     sal_uInt16 nPrefix,
     248             :     const OUString& rLocalName,
     249             :     const Reference<XAttributeList> & xAttrList )
     250             : {
     251          40 :     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
     252          20 :          IsXMLToken( rLocalName, XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE ) )
     253             :     {
     254          16 :         return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
     255             :                                            nPrefix, rLocalName,
     256             :                                            aLevelNameAlphaMap,
     257             :                                            XML_OUTLINE_LEVEL,
     258             :                                            aLevelStylePropNameAlphaMap,
     259          16 :                                            aAllowedTokenTypesAlpha);
     260             :     }
     261             :     else
     262             :     {
     263             :         return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
     264             :                                                              rLocalName,
     265           4 :                                                              xAttrList);
     266             :     }
     267             : }
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10