LCOV - code coverage report
Current view: top level - sc/source/filter/xml - celltextparacontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 187 203 92.1 %
Date: 2014-11-03 Functions: 42 47 89.4 %
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             : 
      10             : #include "celltextparacontext.hxx"
      11             : #include "xmlimprt.hxx"
      12             : #include "xmlcelli.hxx"
      13             : 
      14             : #include <xmloff/nmspmap.hxx>
      15             : #include <comphelper/string.hxx>
      16             : 
      17             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      18             : 
      19             : using namespace com::sun::star;
      20             : 
      21       12550 : ScXMLCellTextParaContext::ScXMLCellTextParaContext(
      22             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLTableRowCellContext& rParent) :
      23             :     ScXMLImportContext(rImport, nPrefix, rLName),
      24       12550 :     mrParentCxt(rParent)
      25             : {
      26       12550 : }
      27             : 
      28       12550 : void ScXMLCellTextParaContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
      29             : {
      30       12550 : }
      31             : 
      32       12550 : void ScXMLCellTextParaContext::EndElement()
      33             : {
      34       12550 :     if (!maContent.isEmpty())
      35       10646 :         mrParentCxt.PushParagraphSpan(maContent, OUString());
      36             : 
      37       12550 :     mrParentCxt.PushParagraphEnd();
      38       12550 : }
      39             : 
      40       10808 : void ScXMLCellTextParaContext::Characters(const OUString& rChars)
      41             : {
      42       10808 :     maContent += rChars;
      43       10808 : }
      44             : 
      45         804 : SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
      46             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
      47             : {
      48         804 :     if (!maContent.isEmpty())
      49             :     {
      50          52 :         mrParentCxt.PushParagraphSpan(maContent, OUString());
      51          52 :         maContent = OUString();
      52             :     }
      53             : 
      54         804 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextParaElemTokenMap();
      55         804 :     switch (rTokenMap.Get(nPrefix, rLocalName))
      56             :     {
      57             :         case XML_TOK_CELL_TEXT_S:
      58          12 :             return new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, *this);
      59             :         case XML_TOK_CELL_TEXT_SPAN:
      60         780 :             return new ScXMLCellTextSpanContext(GetScImport(), nPrefix, rLocalName, *this);
      61             :         case XML_TOK_CELL_TEXT_SHEET_NAME:
      62           2 :             return new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, *this);
      63             :         case XML_TOK_CELL_TEXT_DATE:
      64           2 :             return new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, *this);
      65             :         case XML_TOK_CELL_TEXT_TITLE:
      66           2 :             return new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, *this);
      67             :         case XML_TOK_CELL_TEXT_URL:
      68           6 :             return new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, *this);
      69             :         default:
      70             :             ;
      71             :     }
      72             : 
      73           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
      74             : }
      75             : 
      76         788 : void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
      77             : {
      78         788 :     mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
      79         788 : }
      80             : 
      81           4 : void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
      82             : {
      83           4 :     mrParentCxt.PushParagraphFieldSheetName(rStyleName);
      84           4 : }
      85             : 
      86           4 : void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
      87             : {
      88           4 :     mrParentCxt.PushParagraphFieldDate(rStyleName);
      89           4 : }
      90             : 
      91           4 : void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
      92             : {
      93           4 :     mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
      94           4 : }
      95             : 
      96           8 : void ScXMLCellTextParaContext::PushFieldURL(
      97             :     const OUString& rURL, const OUString& rRep, const OUString& rStyleName)
      98             : {
      99           8 :     mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName);
     100           8 : }
     101             : 
     102         780 : ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
     103             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     104             :     ScXMLImportContext(rImport, nPrefix, rLName),
     105         780 :     mrParentCxt(rParent)
     106             : {
     107         780 : }
     108             : 
     109         780 : void ScXMLCellTextSpanContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
     110             : {
     111         780 :     if (!xAttrList.is())
     112         780 :         return;
     113             : 
     114         780 :     OUString aLocalName;
     115         780 :     sal_Int16 nAttrCount = xAttrList->getLength();
     116             : 
     117         780 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanAttrTokenMap();
     118        1560 :     for (sal_Int16 i = 0; i < nAttrCount; ++i)
     119             :     {
     120         780 :         sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
     121        1560 :             xAttrList->getNameByIndex(i), &aLocalName);
     122             : 
     123         780 :         const OUString& rAttrValue = xAttrList->getValueByIndex(i);
     124         780 :         sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
     125         780 :         switch (nToken)
     126             :         {
     127             :             case XML_TOK_CELL_TEXT_SPAN_ATTR_STYLE_NAME:
     128         780 :                 maStyleName = rAttrValue;
     129         780 :             break;
     130             :             default:
     131             :                 ;
     132             :         }
     133        1560 :     }
     134             : }
     135             : 
     136         780 : void ScXMLCellTextSpanContext::EndElement()
     137             : {
     138         780 :     if (!maContent.isEmpty())
     139             :     {
     140         772 :         mrParentCxt.PushSpan(maContent, maStyleName);
     141             :     }
     142         780 : }
     143             : 
     144         774 : void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
     145             : {
     146         774 :     maContent += rChars;
     147         774 : }
     148             : 
     149          10 : SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
     150             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     151             : {
     152          10 :     if (!maContent.isEmpty())
     153             :     {
     154           2 :         mrParentCxt.PushSpan(maContent, maStyleName);
     155           2 :         maContent = OUString();
     156             :     }
     157             : 
     158          10 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanElemTokenMap();
     159          10 :     switch (rTokenMap.Get(nPrefix, rLocalName))
     160             :     {
     161             :         case XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME:
     162             :         {
     163           2 :             ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
     164           2 :             p->SetStyleName(maStyleName);
     165           2 :             return p;
     166             :         }
     167             :         case XML_TOK_CELL_TEXT_SPAN_ELEM_DATE:
     168             :         {
     169           2 :             ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
     170           2 :             p->SetStyleName(maStyleName);
     171           2 :             return p;
     172             :         }
     173             :         case XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE:
     174             :         {
     175           2 :             ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
     176           2 :             p->SetStyleName(maStyleName);
     177           2 :             return p;
     178             :         }
     179             :         case XML_TOK_CELL_TEXT_SPAN_ELEM_URL:
     180             :         {
     181           2 :             ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
     182           2 :             p->SetStyleName(maStyleName);
     183           2 :             return p;
     184             :         }
     185             :         case XML_TOK_CELL_TEXT_SPAN_ELEM_S:
     186             :         {
     187           2 :             ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
     188           2 :             p->SetStyleName(maStyleName);
     189           2 :             return p;
     190             :         }
     191             :         default:
     192             :             ;
     193             :     }
     194             : 
     195           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     196             : }
     197             : 
     198           4 : ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
     199             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     200             :     ScXMLImportContext(rImport, nPrefix, rLName),
     201           4 :     mrParentCxt(rParent)
     202             : {
     203           4 : }
     204             : 
     205           2 : void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
     206             : {
     207           2 :     maStyleName = rStyleName;
     208           2 : }
     209             : 
     210           4 : void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     211             : {
     212             :     // <text:sheet-name> has no attributes (that I'm aware of).
     213           4 : }
     214             : 
     215           4 : void ScXMLCellFieldSheetNameContext::EndElement()
     216             : {
     217           4 :     mrParentCxt.PushFieldSheetName(maStyleName);
     218           4 : }
     219             : 
     220           4 : void ScXMLCellFieldSheetNameContext::Characters(const OUString& /*rChars*/)
     221             : {
     222           4 : }
     223             : 
     224           0 : SvXMLImportContext* ScXMLCellFieldSheetNameContext::CreateChildContext(
     225             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     226             : {
     227           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     228             : }
     229             : 
     230           4 : ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
     231             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     232             :     ScXMLImportContext(rImport, nPrefix, rLName),
     233           4 :     mrParentCxt(rParent)
     234             : {
     235           4 : }
     236             : 
     237           2 : void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
     238             : {
     239           2 :     maStyleName = rStyleName;
     240           2 : }
     241             : 
     242           4 : void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     243             : {
     244           4 : }
     245             : 
     246           4 : void ScXMLCellFieldDateContext::EndElement()
     247             : {
     248           4 :     mrParentCxt.PushFieldDate(maStyleName);
     249           4 : }
     250             : 
     251           4 : void ScXMLCellFieldDateContext::Characters(const OUString& /*rChars*/)
     252             : {
     253           4 : }
     254             : 
     255           0 : SvXMLImportContext* ScXMLCellFieldDateContext::CreateChildContext(
     256             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     257             : {
     258           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     259             : }
     260             : 
     261           4 : ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
     262             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     263             :     ScXMLImportContext(rImport, nPrefix, rLName),
     264           4 :     mrParentCxt(rParent)
     265             : {
     266           4 : }
     267             : 
     268           2 : void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
     269             : {
     270           2 :     maStyleName = rStyleName;
     271           2 : }
     272             : 
     273           4 : void ScXMLCellFieldTitleContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     274             : {
     275           4 : }
     276             : 
     277           4 : void ScXMLCellFieldTitleContext::EndElement()
     278             : {
     279           4 :     mrParentCxt.PushFieldTitle(maStyleName);
     280           4 : }
     281             : 
     282           4 : void ScXMLCellFieldTitleContext::Characters(const OUString& /*rChars*/)
     283             : {
     284           4 : }
     285             : 
     286           0 : SvXMLImportContext* ScXMLCellFieldTitleContext::CreateChildContext(
     287             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     288             : {
     289           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     290             : }
     291             : 
     292           8 : ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
     293             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     294             :     ScXMLImportContext(rImport, nPrefix, rLName),
     295           8 :     mrParentCxt(rParent)
     296             : {
     297           8 : }
     298             : 
     299           2 : void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
     300             : {
     301           2 :     maStyleName = rStyleName;
     302           2 : }
     303             : 
     304           8 : void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
     305             : {
     306           8 :     if (!xAttrList.is())
     307           8 :         return;
     308             : 
     309           8 :     OUString aLocalName;
     310           8 :     sal_Int16 nAttrCount = xAttrList->getLength();
     311             : 
     312           8 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextURLAttrTokenMap();
     313          24 :     for (sal_Int16 i = 0; i < nAttrCount; ++i)
     314             :     {
     315          16 :         sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
     316          32 :             xAttrList->getNameByIndex(i), &aLocalName);
     317             : 
     318          16 :         const OUString& rAttrValue = xAttrList->getValueByIndex(i);
     319          16 :         sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
     320          16 :         switch (nToken)
     321             :         {
     322             :             case XML_TOK_CELL_TEXT_URL_ATTR_UREF:
     323           8 :                 maURL = rAttrValue;
     324           8 :             break;
     325             :             case XML_TOK_CELL_TEXT_URL_ATTR_TYPE:
     326             :                 // Ignored for now.
     327           8 :             break;
     328             :             default:
     329             :                 ;
     330             :         }
     331          24 :     }
     332             : }
     333             : 
     334           8 : void ScXMLCellFieldURLContext::EndElement()
     335             : {
     336           8 :     mrParentCxt.PushFieldURL(maURL, maRep, maStyleName);
     337           8 : }
     338             : 
     339           8 : void ScXMLCellFieldURLContext::Characters(const OUString& rChars)
     340             : {
     341           8 :     maRep += rChars;
     342           8 : }
     343             : 
     344           0 : SvXMLImportContext* ScXMLCellFieldURLContext::CreateChildContext(
     345             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     346             : {
     347           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     348             : }
     349             : 
     350          14 : ScXMLCellFieldSContext::ScXMLCellFieldSContext(
     351             :     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     352             :     ScXMLImportContext(rImport, nPrefix, rLName),
     353             :     mrParentCxt(rParent),
     354          14 :     mnCount(1)
     355             : {
     356          14 : }
     357             : 
     358           2 : void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
     359             : {
     360           2 :     maStyleName = rStyleName;
     361           2 : }
     362             : 
     363          14 : void ScXMLCellFieldSContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
     364             : {
     365          14 :     if (!xAttrList.is())
     366          14 :         return;
     367             : 
     368          14 :     OUString aLocalName;
     369          14 :     sal_Int16 nAttrCount = xAttrList->getLength();
     370             : 
     371          14 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSAttrTokenMap();
     372          24 :     for (sal_Int16 i = 0; i < nAttrCount; ++i)
     373             :     {
     374          10 :         sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
     375          20 :             xAttrList->getNameByIndex(i), &aLocalName);
     376             : 
     377          10 :         const OUString& rAttrValue = xAttrList->getValueByIndex(i);
     378          10 :         sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
     379          10 :         switch (nToken)
     380             :         {
     381             :             case XML_TOK_CELL_TEXT_S_ATTR_C:
     382          10 :                 mnCount = rAttrValue.toInt32();
     383          10 :                 if (mnCount <= 0)
     384           0 :                     mnCount = 1;     // worth a warning?
     385          10 :             break;
     386             :             default:
     387             :                 ;
     388             :         }
     389          24 :     }
     390             : }
     391             : 
     392          14 : void ScXMLCellFieldSContext::EndElement()
     393             : {
     394          14 :     if (mnCount)
     395          14 :         PushSpaces();
     396          14 : }
     397             : 
     398           0 : SvXMLImportContext* ScXMLCellFieldSContext::CreateChildContext(
     399             :     sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
     400             : {
     401             :     // <text:s> does not have child elements, but ...
     402           0 :     if (mnCount)
     403             :     {
     404           0 :         PushSpaces();
     405           0 :         mnCount = 0;
     406             :     }
     407             : 
     408           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     409             : }
     410             : 
     411          14 : void ScXMLCellFieldSContext::PushSpaces()
     412             : {
     413          14 :     if (mnCount > 0)
     414             :     {
     415          14 :         if (mnCount == 1)
     416           4 :             mrParentCxt.PushSpan(" ", maStyleName);
     417             :         else
     418             :         {
     419          10 :             OUStringBuffer aBuf( mnCount);
     420          10 :             comphelper::string::padToLength( aBuf, mnCount, ' ');
     421          10 :             mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
     422             :         }
     423             :     }
     424         242 : }
     425             : 
     426             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10