LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexBibliographyConfigurationContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 71 118 60.2 %
Date: 2014-11-03 Functions: 6 12 50.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 "XMLIndexBibliographyConfigurationContext.hxx"
      21             : #include "XMLIndexBibliographyEntryContext.hxx"
      22             : #include <xmloff/xmlictxt.hxx>
      23             : #include <xmloff/xmlimp.hxx>
      24             : #include <xmloff/txtimp.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <xmloff/xmlnmspe.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <sax/tools/converter.hxx>
      30             : #include <rtl/ustring.hxx>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      33             : 
      34             : using namespace ::com::sun::star::text;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::xmloff::token;
      37             : 
      38             : using ::com::sun::star::xml::sax::XAttributeList;
      39             : using ::com::sun::star::beans::PropertyValue;
      40             : using ::com::sun::star::beans::XPropertySet;
      41             : using ::com::sun::star::lang::XMultiServiceFactory;
      42             : 
      43             : const sal_Char sAPI_FieldMaster_Bibliography[] =
      44             :                                 "com.sun.star.text.FieldMaster.Bibliography";
      45             : 
      46             : 
      47           0 : TYPEINIT1( XMLIndexBibliographyConfigurationContext, SvXMLStyleContext );
      48             : 
      49           4 : XMLIndexBibliographyConfigurationContext::XMLIndexBibliographyConfigurationContext(
      50             :     SvXMLImport& rImport,
      51             :     sal_uInt16 nPrfx,
      52             :     const OUString& rLocalName,
      53             :     const Reference<XAttributeList> & xAttrList) :
      54             :         SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG),
      55             :         sFieldMaster_Bibliography(
      56             :             sAPI_FieldMaster_Bibliography),
      57             :         sBracketBefore("BracketBefore"),
      58             :         sBracketAfter("BracketAfter"),
      59             :         sIsNumberEntries("IsNumberEntries"),
      60             :         sIsSortByPosition("IsSortByPosition"),
      61             :         sSortKeys("SortKeys"),
      62             :         sSortKey("SortKey"),
      63             :         sIsSortAscending("IsSortAscending"),
      64             :         sSortAlgorithm("SortAlgorithm"),
      65             :         sLocale("Locale"),
      66             :         sSuffix(),
      67             :         sPrefix(),
      68             :         sAlgorithm(),
      69             :         maLanguageTagODF(),
      70             :         bNumberedEntries(false),
      71           4 :         bSortByPosition(true)
      72             : {
      73           4 : }
      74             : 
      75           8 : XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
      76             : {
      77           8 : }
      78             : 
      79           4 : void XMLIndexBibliographyConfigurationContext::StartElement(
      80             :     const Reference<XAttributeList> & xAttrList)
      81             : {
      82           4 :     sal_Int16 nLength = xAttrList->getLength();
      83          24 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      84             :     {
      85          20 :         OUString sLocalName;
      86          20 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      87          20 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      88          40 :                               &sLocalName );
      89             : 
      90             :         ProcessAttribute(nPrefix, sLocalName,
      91          20 :                          xAttrList->getValueByIndex(nAttr));
      92             :         // else: ignore
      93          20 :     }
      94           4 : }
      95             : 
      96          20 : void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
      97             :     sal_uInt16 nPrefix,
      98             :     const OUString& sLocalName,
      99             :     const OUString& sValue)
     100             : {
     101          20 :     if( XML_NAMESPACE_TEXT == nPrefix )
     102             :     {
     103          12 :         if( IsXMLToken(sLocalName, XML_PREFIX) )
     104             :         {
     105           4 :             sPrefix = sValue;
     106             :         }
     107           8 :         else if( IsXMLToken(sLocalName, XML_SUFFIX) )
     108             :         {
     109           4 :             sSuffix = sValue;
     110             :         }
     111           4 :         else if( IsXMLToken(sLocalName, XML_NUMBERED_ENTRIES) )
     112             :         {
     113           0 :             bool bTmp(false);
     114           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     115             :             {
     116           0 :                 bNumberedEntries = bTmp;
     117             :             }
     118             :         }
     119           4 :         else if( IsXMLToken(sLocalName, XML_SORT_BY_POSITION) )
     120             :         {
     121           0 :             bool bTmp(false);
     122           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     123             :             {
     124           0 :                 bSortByPosition = bTmp;
     125             :             }
     126             :         }
     127           4 :         else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) )
     128             :         {
     129           4 :             sAlgorithm = sValue;
     130             :         }
     131             :     }
     132           8 :     else if( XML_NAMESPACE_FO == nPrefix )
     133             :     {
     134           8 :         if( IsXMLToken(sLocalName, XML_LANGUAGE) )
     135             :         {
     136           4 :             maLanguageTagODF.maLanguage = sValue;
     137             :         }
     138           4 :         else if( IsXMLToken(sLocalName, XML_SCRIPT) )
     139             :         {
     140           0 :             maLanguageTagODF.maScript = sValue;
     141             :         }
     142           4 :         else if( IsXMLToken(sLocalName, XML_COUNTRY) )
     143             :         {
     144           4 :             maLanguageTagODF.maCountry = sValue;
     145             :         }
     146             :     }
     147           0 :     else if( XML_NAMESPACE_STYLE == nPrefix )
     148             :     {
     149           0 :         if( IsXMLToken(sLocalName, XML_RFC_LANGUAGE_TAG) )
     150             :         {
     151           0 :             maLanguageTagODF.maRfcLanguageTag = sValue;
     152             :         }
     153             :     }
     154          20 : }
     155             : 
     156             : 
     157           0 : SvXMLImportContext *XMLIndexBibliographyConfigurationContext::CreateChildContext(
     158             :     sal_uInt16 nPrefix,
     159             :     const OUString& rLocalName,
     160             :     const Reference<XAttributeList> & xAttrList )
     161             : {
     162           0 :     OUString sKey;
     163           0 :     sal_Bool bSort(sal_True);
     164             : 
     165             :     // process children here and use default context!
     166           0 :     if ( ( nPrefix == XML_NAMESPACE_TEXT ) &&
     167           0 :          IsXMLToken( rLocalName, XML_SORT_KEY ) )
     168             :     {
     169           0 :         sal_Int16 nLength = xAttrList->getLength();
     170           0 :         for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     171             :         {
     172           0 :             OUString sLocalName;
     173           0 :             sal_uInt16 nPrfx = GetImport().GetNamespaceMap().
     174           0 :                 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     175           0 :                                   &sLocalName );
     176             : 
     177           0 :             if (nPrfx == XML_NAMESPACE_TEXT)
     178             :             {
     179           0 :                 if ( IsXMLToken( sLocalName, XML_KEY ) )
     180             :                 {
     181           0 :                     sKey = xAttrList->getValueByIndex(nAttr);
     182             :                 }
     183           0 :                 else if ( IsXMLToken( sLocalName, XML_SORT_ASCENDING ) )
     184             :                 {
     185           0 :                     bool bTmp(false);
     186           0 :                     if (::sax::Converter::convertBool(
     187           0 :                         bTmp, xAttrList->getValueByIndex(nAttr)))
     188             :                     {
     189           0 :                         bSort = bTmp;
     190             :                     }
     191             :                 }
     192             :             }
     193           0 :         }
     194             : 
     195             :         // valid data?
     196             :         sal_uInt16 nKey;
     197           0 :         if (SvXMLUnitConverter::convertEnum(nKey, sKey,
     198             :                                             aBibliographyDataFieldMap))
     199             :         {
     200             : 
     201           0 :             Any aAny;
     202           0 :             Sequence<PropertyValue> aKey(2);
     203             : 
     204           0 :             PropertyValue aNameValue;
     205           0 :             aNameValue.Name = sSortKey;
     206           0 :             aAny <<= (sal_Int16)nKey;
     207           0 :             aNameValue.Value = aAny;
     208           0 :             aKey[0] = aNameValue;
     209             : 
     210           0 :             PropertyValue aSortValue;
     211           0 :             aSortValue.Name = sIsSortAscending;
     212           0 :             aAny.setValue(&bSort, ::getBooleanCppuType());
     213           0 :             aSortValue.Value = aAny;
     214           0 :             aKey[1] = aSortValue;
     215             : 
     216           0 :             aSortKeys.push_back(aKey);
     217             :         }
     218             :     }
     219             : 
     220             :     return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
     221           0 :                                                   xAttrList);
     222             : }
     223             : 
     224           4 : void XMLIndexBibliographyConfigurationContext::CreateAndInsert(bool)
     225             : {
     226             :     // (code almost the same as export...)
     227             : 
     228             :     // insert and block mode is handled in insertStyleFamily
     229             : 
     230             :     // first: get field master
     231             :     // (we'll create one, and get the only master for this type)
     232           4 :     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
     233           4 :     if( xFactory.is() )
     234             :     {
     235           4 :         Sequence<OUString> aServices = xFactory->getAvailableServiceNames();
     236           4 :         bool bFound(false);
     237           4 :         sal_Int32 i(0);
     238           4 :         sal_Int32 nServiceCount(aServices.getLength());
     239         512 :         while (i < nServiceCount && !bFound)
     240             :         {
     241         504 :             if (aServices[i].equals(sFieldMaster_Bibliography))
     242             :             // here we should use a method which compares in reverse order if available
     243             :             // #85282#
     244           4 :                 bFound = true;
     245             :             else
     246         500 :                 i++;
     247             :         }
     248           4 :         if (bFound)
     249             :         {
     250             :             Reference<XInterface> xIfc =
     251           4 :                 xFactory->createInstance(sFieldMaster_Bibliography);
     252           4 :             if( xIfc.is() )
     253             :             {
     254           4 :                 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
     255           8 :                 Any aAny;
     256             : 
     257           4 :                 aAny <<= sSuffix;
     258           4 :                 xPropSet->setPropertyValue(sBracketAfter, aAny);
     259             : 
     260           4 :                 aAny <<= sPrefix;
     261           4 :                 xPropSet->setPropertyValue(sBracketBefore, aAny);
     262             : 
     263           4 :                 aAny.setValue(&bNumberedEntries, ::getBooleanCppuType());
     264           4 :                 xPropSet->setPropertyValue(sIsNumberEntries, aAny);
     265             : 
     266           4 :                 aAny.setValue(&bSortByPosition, ::getBooleanCppuType());
     267           4 :                 xPropSet->setPropertyValue(sIsSortByPosition, aAny);
     268             : 
     269           4 :                 if( !maLanguageTagODF.isEmpty() )
     270             :                 {
     271           4 :                     aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
     272           4 :                     xPropSet->setPropertyValue(sLocale, aAny);
     273             :                 }
     274             : 
     275           4 :                 if( !sAlgorithm.isEmpty() )
     276             :                 {
     277           4 :                     aAny <<= sAlgorithm;
     278           4 :                     xPropSet->setPropertyValue(sSortAlgorithm, aAny);
     279             :                 }
     280             : 
     281           4 :                 sal_Int32 nCount = aSortKeys.size();
     282           8 :                 Sequence<Sequence<PropertyValue> > aKeysSeq(nCount);
     283           4 :                 for(i = 0; i < nCount; i++)
     284             :                 {
     285           0 :                     aKeysSeq[i] = aSortKeys[i];
     286             :                 }
     287           4 :                 aAny <<= aKeysSeq;
     288           8 :                 xPropSet->setPropertyValue(sSortKeys, aAny);
     289           4 :             }
     290             :             // else: can't get FieldMaster -> ignore
     291           4 :         }
     292           4 :     }
     293             :     // else: can't even get Factory -> ignore
     294           4 : }
     295             : 
     296             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10