LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLLineNumberingImportContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 102 0.0 %
Date: 2014-04-14 Functions: 0 14 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 "XMLLineNumberingImportContext.hxx"
      21             : #include "XMLLineNumberingSeparatorImportContext.hxx"
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include <com/sun/star/text/XLineNumberingProperties.hpp>
      24             : #include <com/sun/star/style/LineNumberPosition.hpp>
      25             : #include <com/sun/star/style/NumberingType.hpp>
      26             : #include <sax/tools/converter.hxx>
      27             : #include <xmloff/xmlimp.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/xmlnmspe.hxx>
      30             : #include <xmloff/nmspmap.hxx>
      31             : #include <xmloff/xmltoken.hxx>
      32             : #include <xmloff/xmlnumi.hxx>
      33             : 
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::style;
      38             : using namespace ::xmloff::token;
      39             : 
      40             : using ::com::sun::star::beans::XPropertySet;
      41             : using ::com::sun::star::xml::sax::XAttributeList;
      42             : using ::com::sun::star::text::XLineNumberingProperties;
      43             : 
      44           0 : TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext );
      45             : 
      46             : 
      47           0 : XMLLineNumberingImportContext::XMLLineNumberingImportContext(
      48             :     SvXMLImport& rImport,
      49             :     sal_uInt16 nPrfx,
      50             :     const OUString& rLocalName,
      51             :     const Reference<XAttributeList> & xAttrList)
      52             : :   SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG)
      53             : ,   sCharStyleName("CharStyleName")
      54             : ,   sCountEmptyLines("CountEmptyLines")
      55             : ,   sCountLinesInFrames("CountLinesInFrames")
      56             : ,   sDistance("Distance")
      57             : ,   sInterval("Interval")
      58             : ,   sSeparatorText("SeparatorText")
      59             : ,   sNumberPosition("NumberPosition")
      60             : ,   sNumberingType("NumberingType")
      61             : ,   sIsOn("IsOn")
      62             : ,   sRestartAtEachPage("RestartAtEachPage")
      63             : ,   sSeparatorInterval("SeparatorInterval")
      64           0 : ,   sNumFormat(GetXMLToken(XML_1))
      65           0 : ,   sNumLetterSync(GetXMLToken(XML_FALSE))
      66             : ,   nOffset(-1)
      67             : ,   nNumberPosition(style::LineNumberPosition::LEFT)
      68             : ,   nIncrement(-1)
      69             : ,   nSeparatorIncrement(-1)
      70             : ,   bNumberLines(sal_True)
      71             : ,   bCountEmptyLines(sal_True)
      72             : ,   bCountInFloatingFrames(sal_False)
      73           0 : ,   bRestartNumbering(sal_False)
      74             : {
      75           0 : }
      76             : 
      77           0 : XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
      78             : {
      79           0 : }
      80             : 
      81           0 : void XMLLineNumberingImportContext::StartElement(
      82             :     const Reference<XAttributeList> & xAttrList)
      83             : {
      84             :     static const SvXMLTokenMapEntry aLineNumberingTokenMap[] =
      85             :     {
      86             :         { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME },
      87             :         { XML_NAMESPACE_TEXT, XML_NUMBER_LINES,
      88             :               XML_TOK_LINENUMBERING_NUMBER_LINES },
      89             :         { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES,
      90             :               XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES },
      91             :         { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES,
      92             :               XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES },
      93             :         { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE,
      94             :               XML_TOK_LINENUMBERING_RESTART_NUMBERING },
      95             :         { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET },
      96             :         { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT },
      97             :         { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
      98             :               XML_TOK_LINENUMBERING_NUM_LETTER_SYNC },
      99             :         { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
     100             :               XML_TOK_LINENUMBERING_NUMBER_POSITION },
     101             :         { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
     102             :     //  { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
     103             :     //        XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
     104             :     //  { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
     105             :     //  { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
     106             :     //        XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
     107             : 
     108             :         XML_TOKEN_MAP_END
     109             :     };
     110             : 
     111           0 :     SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
     112             : 
     113             :     // process attributes
     114           0 :     sal_Int16 nLength = xAttrList->getLength();
     115           0 :     for(sal_Int16 i=0; i<nLength; i++)
     116             :     {
     117           0 :         OUString sLocalName;
     118           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     119           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
     120             : 
     121             :         ProcessAttribute(
     122           0 :             (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
     123           0 :             xAttrList->getValueByIndex(i));
     124           0 :     }
     125           0 : }
     126             : 
     127           0 : void XMLLineNumberingImportContext::ProcessAttribute(
     128             :     enum LineNumberingToken eToken,
     129             :     const OUString& sValue)
     130             : {
     131           0 :     bool bTmp(false);
     132             :     sal_Int32 nTmp;
     133             : 
     134           0 :     switch (eToken)
     135             :     {
     136             :         case XML_TOK_LINENUMBERING_STYLE_NAME:
     137           0 :             sStyleName = sValue;
     138           0 :             break;
     139             : 
     140             :         case XML_TOK_LINENUMBERING_NUMBER_LINES:
     141           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     142             :             {
     143           0 :                 bNumberLines = bTmp;
     144             :             }
     145           0 :             break;
     146             : 
     147             :         case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES:
     148           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     149             :             {
     150           0 :                 bCountEmptyLines = bTmp;
     151             :             }
     152           0 :             break;
     153             : 
     154             :         case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES:
     155           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     156             :             {
     157           0 :                 bCountInFloatingFrames = bTmp;
     158             :             }
     159           0 :             break;
     160             : 
     161             :         case XML_TOK_LINENUMBERING_RESTART_NUMBERING:
     162           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
     163             :             {
     164           0 :                 bRestartNumbering = bTmp;
     165             :             }
     166           0 :             break;
     167             : 
     168             :         case XML_TOK_LINENUMBERING_OFFSET:
     169           0 :             if (GetImport().GetMM100UnitConverter().
     170             :                     convertMeasureToCore(nTmp, sValue))
     171             :             {
     172           0 :                 nOffset = nTmp;
     173             :             }
     174           0 :             break;
     175             : 
     176             :         case XML_TOK_LINENUMBERING_NUM_FORMAT:
     177           0 :             sNumFormat = sValue;
     178           0 :             break;
     179             : 
     180             :         case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC:
     181           0 :             sNumLetterSync = sValue;
     182           0 :             break;
     183             : 
     184             :         case XML_TOK_LINENUMBERING_NUMBER_POSITION:
     185             :         {
     186             :             static const SvXMLEnumMapEntry aLineNumberPositionMap[] =
     187             :             {
     188             :                 { XML_LEFT,     style::LineNumberPosition::LEFT },
     189             :                 { XML_RIGHT,    style::LineNumberPosition::RIGHT },
     190             :                 { XML_INSIDE,   style::LineNumberPosition::INSIDE },
     191             :                 { XML_OUTSIDE,  style::LineNumberPosition::OUTSIDE },
     192             :                 { XML_TOKEN_INVALID, 0 }
     193             :             };
     194             : 
     195             :             sal_uInt16 nTmp16;
     196           0 :             if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
     197             :                                                 aLineNumberPositionMap))
     198             :             {
     199           0 :                 nNumberPosition = nTmp16;
     200             :             }
     201           0 :             break;
     202             :         }
     203             : 
     204             :         case XML_TOK_LINENUMBERING_INCREMENT:
     205           0 :             if (::sax::Converter::convertNumber(nTmp, sValue, 0))
     206             :             {
     207           0 :                 nIncrement = (sal_Int16)nTmp;
     208             :             }
     209           0 :             break;
     210             :     }
     211           0 : }
     212             : 
     213           0 : void XMLLineNumberingImportContext::CreateAndInsert(bool)
     214             : {
     215             :     // insert and block mode is handled in insertStyleFamily
     216             : 
     217             :     // we'll try to get the LineNumberingProperties
     218           0 :     Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
     219           0 :                                                   UNO_QUERY);
     220           0 :     if (xSupplier.is())
     221             :     {
     222             :         Reference<XPropertySet> xLineNumbering =
     223           0 :             xSupplier->getLineNumberingProperties();
     224             : 
     225           0 :         if (xLineNumbering.is())
     226             :         {
     227           0 :             Any aAny;
     228             : 
     229             :             // set style name (if it exists)
     230           0 :             if ( GetImport().GetStyles()->FindStyleChildContext(
     231           0 :                             XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL )
     232             :             {
     233           0 :                 aAny <<= GetImport().GetStyleDisplayName(
     234           0 :                             XML_STYLE_FAMILY_TEXT_TEXT, sStyleName );
     235           0 :                 xLineNumbering->setPropertyValue(sCharStyleName, aAny);
     236             :             }
     237             : 
     238           0 :             aAny <<= sSeparator;
     239           0 :             xLineNumbering->setPropertyValue(sSeparatorText, aAny);
     240             : 
     241           0 :             aAny <<= nOffset;
     242           0 :             xLineNumbering->setPropertyValue(sDistance, aAny);
     243             : 
     244           0 :             aAny <<= nNumberPosition;
     245           0 :             xLineNumbering->setPropertyValue(sNumberPosition, aAny);
     246             : 
     247           0 :             if (nIncrement >= 0)
     248             :             {
     249           0 :                 aAny <<= nIncrement;
     250           0 :                 xLineNumbering->setPropertyValue(sInterval, aAny);
     251             :             }
     252             : 
     253           0 :             if (nSeparatorIncrement >= 0)
     254             :             {
     255           0 :                 aAny <<= nSeparatorIncrement;
     256           0 :                 xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
     257             :             }
     258             : 
     259           0 :             aAny.setValue(&bNumberLines, ::getBooleanCppuType());
     260           0 :             xLineNumbering->setPropertyValue(sIsOn, aAny);
     261             : 
     262           0 :             aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType());
     263           0 :             xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
     264             : 
     265           0 :             aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType());
     266           0 :             xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
     267             : 
     268           0 :             aAny.setValue(&bRestartNumbering, ::getBooleanCppuType());
     269           0 :             xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
     270             : 
     271           0 :             sal_Int16 nNumType = NumberingType::ARABIC;
     272           0 :             GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
     273             :                                                     sNumFormat,
     274           0 :                                                     sNumLetterSync );
     275           0 :             aAny <<= nNumType;
     276           0 :             xLineNumbering->setPropertyValue(sNumberingType, aAny);
     277           0 :         }
     278           0 :     }
     279           0 : }
     280             : 
     281           0 : SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext(
     282             :     sal_uInt16 nPrefix,
     283             :     const OUString& rLocalName,
     284             :     const Reference<XAttributeList> & xAttrList )
     285             : {
     286           0 :     if ( (nPrefix == XML_NAMESPACE_TEXT) &&
     287           0 :          IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) )
     288             :     {
     289           0 :         return new XMLLineNumberingSeparatorImportContext(GetImport(),
     290             :                                                           nPrefix, rLocalName,
     291           0 :                                                           *this);
     292             :     }
     293             :     else
     294             :     {
     295             :         // unknown element: default context
     296             :         return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
     297           0 :                                                       xAttrList);
     298             :     }
     299             : }
     300             : 
     301           0 : void XMLLineNumberingImportContext::SetSeparatorText(
     302             :     const OUString& sText)
     303             : {
     304           0 :     sSeparator = sText;
     305           0 : }
     306             : 
     307           0 : void XMLLineNumberingImportContext::SetSeparatorIncrement(
     308             :     sal_Int16 nIncr)
     309             : {
     310           0 :     nSeparatorIncrement = nIncr;
     311           0 : }
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10