LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexTableSourceContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 40 85.0 %
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 "XMLIndexTableSourceContext.hxx"
      22             : 
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XIndexReplace.hpp>
      25             : #include <com/sun/star/text/ReferenceFieldPart.hpp>
      26             : 
      27             : #include <sax/tools/converter.hxx>
      28             : 
      29             : #include "XMLIndexTemplateContext.hxx"
      30             : #include "XMLIndexTitleTemplateContext.hxx"
      31             : #include "XMLIndexTOCStylesContext.hxx"
      32             : #include <xmloff/xmlictxt.hxx>
      33             : #include <xmloff/xmlimp.hxx>
      34             : #include <xmloff/txtimp.hxx>
      35             : #include <xmloff/xmlnmspe.hxx>
      36             : #include <xmloff/nmspmap.hxx>
      37             : #include <xmloff/xmltoken.hxx>
      38             : #include <xmloff/xmluconv.hxx>
      39             : #include <rtl/ustring.hxx>
      40             : 
      41             : 
      42             : using namespace ::com::sun::star::text;
      43             : using namespace ::xmloff::token;
      44             : 
      45             : using ::com::sun::star::beans::XPropertySet;
      46             : using ::com::sun::star::uno::Reference;
      47             : using ::com::sun::star::uno::Any;
      48             : using ::com::sun::star::xml::sax::XAttributeList;
      49             : 
      50             : const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels";
      51             : const sal_Char sAPI_LabelCategory[] = "LabelCategory";
      52             : const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
      53             : 
      54             : 
      55           0 : TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
      56             : 
      57             : 
      58          10 : XMLIndexTableSourceContext::XMLIndexTableSourceContext(
      59             :     SvXMLImport& rImport, sal_uInt16 nPrfx,
      60             :     const OUString& rLocalName, Reference<XPropertySet> & rPropSet)
      61             :     : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
      62             :                                   rPropSet, false)
      63             :     , sCreateFromLabels(sAPI_CreateFromLabels)
      64             :     , sLabelCategory(sAPI_LabelCategory)
      65             :     , sLabelDisplayType(sAPI_LabelDisplayType)
      66             :     , nDisplayFormat(0)
      67             :     , bSequenceOK(false)
      68             :     , bDisplayFormatOK(false)
      69          10 :     , bUseCaption(true)
      70             : {
      71          10 : }
      72             : 
      73          14 : XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
      74             : {
      75          14 : }
      76             : 
      77             : static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
      78             : {
      79             : 
      80             :     { XML_TEXT,                 ReferenceFieldPart::TEXT },
      81             :     { XML_CATEGORY_AND_VALUE,   ReferenceFieldPart::CATEGORY_AND_NUMBER },
      82             :     { XML_CAPTION,              ReferenceFieldPart::ONLY_CAPTION },
      83             : 
      84             :     // wrong values that previous versions wrote:
      85             :     { XML_CHAPTER,              ReferenceFieldPart::CATEGORY_AND_NUMBER },
      86             :     { XML_PAGE,                 ReferenceFieldPart::ONLY_CAPTION },
      87             : 
      88             :     { XML_TOKEN_INVALID,        0 }
      89             : };
      90             : 
      91          20 : void XMLIndexTableSourceContext::ProcessAttribute(
      92             :     enum IndexSourceParamEnum eParam,
      93             :     const OUString& rValue)
      94             : {
      95          20 :     bool bTmp(false);
      96             : 
      97          20 :     switch (eParam)
      98             :     {
      99             :         case XML_TOK_INDEXSOURCE_USE_CAPTION:
     100           0 :             if (::sax::Converter::convertBool(bTmp, rValue))
     101             :             {
     102           0 :                 bUseCaption = bTmp;
     103             :             }
     104           0 :             break;
     105             : 
     106             :         case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
     107          10 :             sSequence = rValue;
     108          10 :             bSequenceOK = true;
     109          10 :             break;
     110             : 
     111             :         case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
     112             :         {
     113             :              sal_uInt16 nTmp;
     114          10 :              if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
     115             :                                                  lcl_aReferenceTypeTokenMap))
     116             :             {
     117          10 :                  nDisplayFormat = nTmp;
     118          10 :                  bDisplayFormatOK = true;
     119             :              }
     120          10 :             break;
     121             :         }
     122             : 
     123             :         default:
     124           0 :             XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
     125           0 :             break;
     126             :     }
     127          20 : }
     128             : 
     129             : 
     130          10 : void XMLIndexTableSourceContext::EndElement()
     131             : {
     132          10 :     Any aAny;
     133             : 
     134          10 :     aAny.setValue(&bUseCaption, ::getBooleanCppuType());
     135          10 :     rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
     136             : 
     137          10 :     if (bSequenceOK)
     138             :     {
     139          10 :         aAny <<= sSequence;
     140          10 :         rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
     141             :     }
     142             : 
     143          10 :     if (bDisplayFormatOK)
     144             :     {
     145          10 :         aAny <<= nDisplayFormat;
     146          10 :         rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
     147             :     }
     148             : 
     149          10 :     XMLIndexSourceBaseContext::EndElement();
     150          10 : }
     151             : 
     152             : 
     153           8 : SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
     154             :     sal_uInt16 nPrefix,
     155             :     const OUString& rLocalName,
     156             :     const Reference<XAttributeList> & xAttrList )
     157             : {
     158          16 :     if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
     159           8 :          ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
     160             :     {
     161           4 :         return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
     162             :                                            nPrefix, rLocalName,
     163             :                                            aLevelNameTableMap,
     164             :                                            XML_TOKEN_INVALID, // no outline-level attr
     165             :                                            aLevelStylePropNameTableMap,
     166           4 :                                            aAllowedTokenTypesTable);
     167             :     }
     168             :     else
     169             :     {
     170             :         return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
     171             :                                                              rLocalName,
     172           4 :                                                              xAttrList);
     173             :     }
     174             : 
     175             : }
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10