LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLTextPContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 79 63.3 %
Date: 2012-12-27 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             : #include "XMLTextPContext.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "xmlcelli.hxx"
      23             : #include <xmloff/xmlnmspe.hxx>
      24             : #include <xmloff/xmltoken.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <com/sun/star/text/XTextCursor.hpp>
      27             : 
      28             : using namespace com::sun::star;
      29             : using namespace xmloff::token;
      30             : 
      31             : class ScXMLTextTContext : public SvXMLImportContext
      32             : {
      33             :     const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
      34           0 :     ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
      35             : public:
      36             :     ScXMLTextTContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
      37             :                         const ::rtl::OUString& rLName,
      38             :                         const ::com::sun::star::uno::Reference<
      39             :                                         ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
      40             :                         ScXMLTextPContext* pTextPContext);
      41             : 
      42             :     virtual ~ScXMLTextTContext();
      43             : };
      44             : 
      45             : 
      46           0 : ScXMLTextTContext::ScXMLTextTContext( ScXMLImport& rImport,
      47             :                                       sal_uInt16 nPrfx,
      48             :                                       const ::rtl::OUString& rLName,
      49             :                                       const ::com::sun::star::uno::Reference<
      50             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
      51             :                                       ScXMLTextPContext* pTextPContext) :
      52           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
      53             : {
      54           0 :     if (pTextPContext)
      55             :     {
      56           0 :         sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
      57           0 :         rtl::OUString aLocalName;
      58           0 :         sal_Int32 nCount(1);
      59           0 :         for( sal_Int16 i=0; i < nAttrCount; ++i )
      60             :         {
      61           0 :             sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
      62           0 :                                                 xAttrList->getNameByIndex( i ), &aLocalName ));
      63           0 :             const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
      64             : 
      65           0 :             if ((nPrefix == XML_NAMESPACE_TEXT) && IsXMLToken(aLocalName, XML_C))
      66           0 :                 nCount = sValue.toInt32();
      67           0 :         }
      68           0 :         pTextPContext->AddSpaces(nCount);
      69             :     }
      70           0 : }
      71             : 
      72           0 : ScXMLTextTContext::~ScXMLTextTContext()
      73             : {
      74           0 : }
      75             : 
      76             : //------------------------------------------------------------------
      77             : 
      78         322 : ScXMLTextPContext::ScXMLTextPContext( ScXMLImport& rImport,
      79             :                                       sal_uInt16 nPrfx,
      80             :                                       const ::rtl::OUString& rLName,
      81             :                                       const ::com::sun::star::uno::Reference<
      82             :                                       ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
      83             :                                       ScXMLTableRowCellContext* pTempCellContext) :
      84             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      85             :     xAttrList(xTempAttrList),
      86             :     pTextPContext(NULL),
      87             :     pCellContext(pTempCellContext),
      88             :     sLName(rLName),
      89             :     sSimpleContent(),
      90             :     pContentBuffer(NULL),
      91         322 :     nPrefix(nPrfx)
      92             : {
      93             :     // here are no attributes
      94         322 : }
      95             : 
      96         966 : ScXMLTextPContext::~ScXMLTextPContext()
      97             : {
      98         322 :     if (pTextPContext)
      99           1 :         delete pTextPContext;
     100         322 :     if (pContentBuffer)
     101           6 :         delete pContentBuffer;
     102         644 : }
     103             : 
     104           0 : void ScXMLTextPContext::AddSpaces(sal_Int32 nSpaceCount)
     105             : {
     106             :     // use pContentBuffer
     107           0 :     if ( !pContentBuffer )
     108           0 :         pContentBuffer = new rtl::OUStringBuffer( sSimpleContent );
     109             : 
     110           0 :     sal_Char* pChars = new sal_Char[nSpaceCount];
     111           0 :     memset(pChars, ' ', nSpaceCount);
     112           0 :     pContentBuffer->appendAscii(pChars, nSpaceCount);
     113           0 : }
     114             : 
     115           1 : SvXMLImportContext *ScXMLTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
     116             :                                             const ::rtl::OUString& rLName,
     117             :                                             const ::com::sun::star::uno::Reference<
     118             :                                           ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList )
     119             : {
     120           1 :     SvXMLImportContext *pContext(NULL);
     121           2 :     if (!pTextPContext &&
     122             :         (nTempPrefix == XML_NAMESPACE_TEXT) &&
     123           1 :         IsXMLToken(rLName, XML_S))
     124           0 :         pContext = new ScXMLTextTContext( GetScImport(), nTempPrefix, rLName, xTempAttrList, this);
     125             :     else
     126             :     {
     127           1 :         if (!pTextPContext)
     128             :         {
     129           1 :             rtl::OUString sSetString;
     130           1 :             if ( pContentBuffer )
     131           0 :                 sSetString = pContentBuffer->makeStringAndClear();
     132             :             else
     133           1 :                 sSetString = sSimpleContent;
     134             : 
     135           1 :             sal_Unicode cNonSpace(0);
     136             : 
     137           1 :             sal_Int32 nLength = sSetString.getLength();
     138           1 :             if ( nLength > 0 )
     139             :             {
     140           1 :                 sal_Unicode cLast = sSetString.getStr()[ nLength - 1 ];
     141           1 :                 if ( cLast != (sal_Unicode)' ' )
     142             :                 {
     143             :                     // #i53253# To keep XMLParaContext's whitespace handling in sync,
     144             :                     // if there's a non-space character at the end of the existing string,
     145             :                     // it has to be processed by XMLParaContext.
     146             : 
     147           1 :                     cNonSpace = cLast;
     148           1 :                     sSetString = sSetString.copy( 0, nLength - 1 );  // remove from the string for SetCursorOnTextImport
     149             :                 }
     150             :             }
     151             : 
     152           1 :             pCellContext->SetCursorOnTextImport( sSetString );
     153             : 
     154           1 :             pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
     155           2 :                                     GetScImport(), nPrefix, sLName, xAttrList);
     156             : 
     157           1 :             if ( cNonSpace != 0 )
     158             :             {
     159             :                 // pass non-space character through XMLParaContext, so a following space isn't ignored
     160           1 :                 pTextPContext->Characters( rtl::OUString( cNonSpace ) );
     161           1 :             }
     162             :         }
     163           1 :         if (pTextPContext)
     164           1 :             pContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
     165             :     }
     166             : 
     167           1 :     if( !pContext )
     168           0 :         pContext = new SvXMLImportContext( GetScImport(), nTempPrefix, rLName );
     169             : 
     170           1 :     return pContext;
     171             : }
     172             : 
     173         334 : void ScXMLTextPContext::Characters( const ::rtl::OUString& rChars )
     174             : {
     175         334 :     if (!pTextPContext)
     176             :     {
     177             :         // For the first call to an empty context, copy (ref-counted) the OUString.
     178             :         // The OUStringBuffer is used only if there is more complex content.
     179             : 
     180         334 :         if ( !pContentBuffer && sSimpleContent.isEmpty() )
     181         320 :             sSimpleContent = rChars;
     182             :         else
     183             :         {
     184          14 :             if ( !pContentBuffer )
     185           6 :                 pContentBuffer = new rtl::OUStringBuffer( sSimpleContent );
     186          14 :             pContentBuffer->append(rChars);
     187             :         }
     188             :     }
     189             :     else
     190           0 :         pTextPContext->Characters(rChars);
     191         334 : }
     192             : 
     193         322 : void ScXMLTextPContext::EndElement()
     194             : {
     195         322 :     if (!pTextPContext)
     196             :     {
     197         321 :         if ( pContentBuffer )
     198           6 :             pCellContext->SetString(pContentBuffer->makeStringAndClear());
     199             :         else
     200         315 :             pCellContext->SetString(sSimpleContent);
     201             :     }
     202             :     else
     203             :     {
     204           1 :         pTextPContext->EndElement();
     205           1 :         GetScImport().SetRemoveLastChar(sal_True);
     206             :     }
     207         322 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10