LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexBibliographyConfigurationContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 118 0.0 %
Date: 2014-04-14 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 "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           0 : 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(sal_False),
      71           0 :         bSortByPosition(sal_True)
      72             : {
      73           0 : }
      74             : 
      75           0 : XMLIndexBibliographyConfigurationContext::~XMLIndexBibliographyConfigurationContext()
      76             : {
      77           0 : }
      78             : 
      79           0 : void XMLIndexBibliographyConfigurationContext::StartElement(
      80             :     const Reference<XAttributeList> & xAttrList)
      81             : {
      82           0 :     sal_Int16 nLength = xAttrList->getLength();
      83           0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      84             :     {
      85           0 :         OUString sLocalName;
      86           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      87           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      88           0 :                               &sLocalName );
      89             : 
      90             :         ProcessAttribute(nPrefix, sLocalName,
      91           0 :                          xAttrList->getValueByIndex(nAttr));
      92             :         // else: ignore
      93           0 :     }
      94           0 : }
      95             : 
      96           0 : void XMLIndexBibliographyConfigurationContext::ProcessAttribute(
      97             :     sal_uInt16 nPrefix,
      98             :     const OUString& sLocalName,
      99             :     const OUString& sValue)
     100             : {
     101           0 :     if( XML_NAMESPACE_TEXT == nPrefix )
     102             :     {
     103           0 :         if( IsXMLToken(sLocalName, XML_PREFIX) )
     104             :         {
     105           0 :             sPrefix = sValue;
     106             :         }
     107           0 :         else if( IsXMLToken(sLocalName, XML_SUFFIX) )
     108             :         {
     109           0 :             sSuffix = sValue;
     110             :         }
     111           0 :         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           0 :         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           0 :         else if( IsXMLToken(sLocalName, XML_SORT_ALGORITHM) )
     128             :         {
     129           0 :             sAlgorithm = sValue;
     130             :         }
     131             :     }
     132           0 :     else if( XML_NAMESPACE_FO == nPrefix )
     133             :     {
     134           0 :         if( IsXMLToken(sLocalName, XML_LANGUAGE) )
     135             :         {
     136           0 :             maLanguageTagODF.maLanguage = sValue;
     137             :         }
     138           0 :         else if( IsXMLToken(sLocalName, XML_SCRIPT) )
     139             :         {
     140           0 :             maLanguageTagODF.maScript = sValue;
     141             :         }
     142           0 :         else if( IsXMLToken(sLocalName, XML_COUNTRY) )
     143             :         {
     144           0 :             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           0 : }
     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           0 : 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           0 :     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
     233           0 :     if( xFactory.is() )
     234             :     {
     235           0 :         Sequence<OUString> aServices = xFactory->getAvailableServiceNames();
     236           0 :         sal_Bool bFound(sal_False);
     237           0 :         sal_Int32 i(0);
     238           0 :         sal_Int32 nServiceCount(aServices.getLength());
     239           0 :         while (i < nServiceCount && !bFound)
     240             :         {
     241           0 :             if (aServices[i].equals(sFieldMaster_Bibliography))
     242             :             // here we should use a method which compares in reverse order if available
     243             :             // #85282#
     244           0 :                 bFound = sal_True;
     245             :             else
     246           0 :                 i++;
     247             :         }
     248           0 :         if (bFound)
     249             :         {
     250             :             Reference<XInterface> xIfc =
     251           0 :                 xFactory->createInstance(sFieldMaster_Bibliography);
     252           0 :             if( xIfc.is() )
     253             :             {
     254           0 :                 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
     255           0 :                 Any aAny;
     256             : 
     257           0 :                 aAny <<= sSuffix;
     258           0 :                 xPropSet->setPropertyValue(sBracketAfter, aAny);
     259             : 
     260           0 :                 aAny <<= sPrefix;
     261           0 :                 xPropSet->setPropertyValue(sBracketBefore, aAny);
     262             : 
     263           0 :                 aAny.setValue(&bNumberedEntries, ::getBooleanCppuType());
     264           0 :                 xPropSet->setPropertyValue(sIsNumberEntries, aAny);
     265             : 
     266           0 :                 aAny.setValue(&bSortByPosition, ::getBooleanCppuType());
     267           0 :                 xPropSet->setPropertyValue(sIsSortByPosition, aAny);
     268             : 
     269           0 :                 if( !maLanguageTagODF.isEmpty() )
     270             :                 {
     271           0 :                     aAny <<= maLanguageTagODF.getLanguageTag().getLocale( false);
     272           0 :                     xPropSet->setPropertyValue(sLocale, aAny);
     273             :                 }
     274             : 
     275           0 :                 if( !sAlgorithm.isEmpty() )
     276             :                 {
     277           0 :                     aAny <<= sAlgorithm;
     278           0 :                     xPropSet->setPropertyValue(sSortAlgorithm, aAny);
     279             :                 }
     280             : 
     281           0 :                 sal_Int32 nCount = aSortKeys.size();
     282           0 :                 Sequence<Sequence<PropertyValue> > aKeysSeq(nCount);
     283           0 :                 for(i = 0; i < nCount; i++)
     284             :                 {
     285           0 :                     aKeysSeq[i] = aSortKeys[i];
     286             :                 }
     287           0 :                 aAny <<= aKeysSeq;
     288           0 :                 xPropSet->setPropertyValue(sSortKeys, aAny);
     289           0 :             }
     290             :             // else: can't get FieldMaster -> ignore
     291           0 :         }
     292           0 :     }
     293             :     // else: can't even get Factory -> ignore
     294           0 : }
     295             : 
     296             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10