LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexTabStopEntryContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 42 53 79.2 %
Date: 2014-11-03 Functions: 5 10 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             : 
      21             : #include "XMLIndexTabStopEntryContext.hxx"
      22             : 
      23             : #include <sax/tools/converter.hxx>
      24             : 
      25             : #include "XMLIndexTemplateContext.hxx"
      26             : #include <xmloff/xmlictxt.hxx>
      27             : #include <xmloff/xmlimp.hxx>
      28             : #include <xmloff/txtimp.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <xmloff/xmltoken.hxx>
      32             : #include <xmloff/xmluconv.hxx>
      33             : #include <rtl/ustring.hxx>
      34             : #include <tools/debug.hxx>
      35             : 
      36             : using namespace ::xmloff::token;
      37             : 
      38             : using ::com::sun::star::uno::Sequence;
      39             : using ::com::sun::star::uno::Reference;
      40             : using ::com::sun::star::uno::Any;
      41             : using ::com::sun::star::beans::PropertyValue;
      42             : using ::com::sun::star::xml::sax::XAttributeList;
      43             : 
      44             : 
      45           0 : TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
      46             : 
      47         186 : XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
      48             :     SvXMLImport& rImport,
      49             :     XMLIndexTemplateContext& rTemplate,
      50             :     sal_uInt16 nPrfx,
      51             :     const OUString& rLocalName ) :
      52             :         XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
      53             :                                    rTemplate, nPrfx, rLocalName),
      54             :         sLeaderChar(),
      55             :         nTabPosition(0),
      56             :         bTabPositionOK(false),
      57             :         bTabRightAligned(false),
      58             :         bLeaderCharOK(false),
      59         186 :         bWithTab(true) // #i21237#
      60             : {
      61         186 : }
      62             : 
      63         372 : XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
      64             : {
      65         372 : }
      66             : 
      67         186 : void XMLIndexTabStopEntryContext::StartElement(
      68             :     const Reference<XAttributeList> & xAttrList)
      69             : {
      70             :     // process three attributes: type, position, leader char
      71         186 :     sal_Int16 nLength = xAttrList->getLength();
      72         558 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      73             :     {
      74         372 :         OUString sLocalName;
      75         372 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      76         372 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      77         744 :                               &sLocalName );
      78         744 :         OUString sAttr = xAttrList->getValueByIndex(nAttr);
      79         372 :         if (XML_NAMESPACE_STYLE == nPrefix)
      80             :         {
      81         372 :             if ( IsXMLToken( sLocalName, XML_TYPE ) )
      82             :             {
      83             :                 // if it's neither left nor right, value is
      84             :                 // ignored. Since left is default, we only need to
      85             :                 // check for right
      86         186 :                 bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
      87             :             }
      88         186 :             else if ( IsXMLToken( sLocalName, XML_POSITION ) )
      89             :             {
      90             :                 sal_Int32 nTmp;
      91           0 :                 if (GetImport().GetMM100UnitConverter().
      92             :                                         convertMeasureToCore(nTmp, sAttr))
      93             :                 {
      94           0 :                     nTabPosition = nTmp;
      95           0 :                     bTabPositionOK = true;
      96             :                 }
      97             :             }
      98         186 :             else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
      99             :             {
     100         186 :                 sLeaderChar = sAttr;
     101             :                 // valid only, if we have a char!
     102         186 :                 bLeaderCharOK = !sAttr.isEmpty();
     103             :             }
     104             :             // #i21237#
     105           0 :             else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
     106             :             {
     107           0 :                 bool bTmp(false);
     108           0 :                 if (::sax::Converter::convertBool(bTmp, sAttr))
     109           0 :                     bWithTab = bTmp;
     110             :             }
     111             :             // else: unknown style: attribute -> ignore
     112             :         }
     113             :         // else: no style attribute -> ignore
     114         372 :     }
     115             : 
     116             :     // how many entries? #i21237#
     117         186 :     nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
     118             : 
     119             :     // now try parent class (for character style)
     120         186 :     XMLIndexSimpleEntryContext::StartElement( xAttrList );
     121         186 : }
     122             : 
     123         186 : void XMLIndexTabStopEntryContext::FillPropertyValues(
     124             :     Sequence<PropertyValue> & rValues)
     125             : {
     126             :     // fill vlues from parent class (type + style name)
     127         186 :     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
     128             : 
     129             :     // get values array and next entry to be written;
     130         186 :     sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
     131         186 :     PropertyValue* pValues = rValues.getArray();
     132             : 
     133             :     // right aligned?
     134         186 :     pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
     135         186 :     pValues[nNextEntry].Value.setValue( &bTabRightAligned,
     136         372 :                                         ::getBooleanCppuType());
     137         186 :     nNextEntry++;
     138             : 
     139             :     // position
     140         186 :     if (bTabPositionOK)
     141             :     {
     142           0 :         pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
     143           0 :         pValues[nNextEntry].Value <<= nTabPosition;
     144           0 :         nNextEntry++;
     145             :     }
     146             : 
     147             :     // leader char
     148         186 :     if (bLeaderCharOK)
     149             :     {
     150         186 :         pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
     151         186 :         pValues[nNextEntry].Value <<= sLeaderChar;
     152         186 :         nNextEntry++;
     153             :     }
     154             : 
     155             :     // tab character #i21237#
     156         186 :      pValues[nNextEntry].Name = "WithTab";
     157         186 :     pValues[nNextEntry].Value.setValue( &bWithTab,
     158         372 :                                         ::getBooleanCppuType());
     159         186 :     nNextEntry++;
     160             : 
     161             :     // check whether we really filled all elements of the sequence
     162             :     DBG_ASSERT( nNextEntry == rValues.getLength(),
     163             :                 "length incorrectly precumputed!" );
     164         186 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10