LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlannoi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 70 83 84.3 %
Date: 2014-04-11 Functions: 10 11 90.9 %
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 "xmlannoi.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "xmlconti.hxx"
      23             : #include "XMLTableShapeImportHelper.hxx"
      24             : 
      25             : #include <xmloff/xmltkmap.hxx>
      26             : #include <xmloff/nmspmap.hxx>
      27             : #include <xmloff/xmlnmspe.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : 
      30             : using namespace com::sun::star;
      31             : using namespace xmloff::token;
      32             : 
      33          15 : ScXMLAnnotationData::ScXMLAnnotationData() :
      34             :     mbUseShapePos( false ),
      35          15 :     mbShown( false )
      36             : {
      37          15 : }
      38             : 
      39          15 : ScXMLAnnotationData::~ScXMLAnnotationData()
      40             : {
      41          15 : }
      42             : 
      43          15 : ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport& rImport,
      44             :                                       sal_uInt16 nPrfx,
      45             :                                       const OUString& rLName,
      46             :                                       const uno::Reference<xml::sax::XAttributeList>& xAttrList,
      47             :                                       ScXMLAnnotationData& rAnnotationData,
      48             :                                       ScXMLTableRowCellContext* pTempCellContext) :
      49             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      50             :     mrAnnotationData( rAnnotationData ),
      51             :     pCellContext(pTempCellContext),
      52          15 :     pShapeContext(NULL)
      53             : {
      54          15 :     uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
      55          15 :     if (xLocalShapes.is())
      56             :     {
      57          15 :         XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
      58          15 :         pTableShapeImport->SetAnnotation(this);
      59          15 :         pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
      60          30 :             GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, true);
      61             :     }
      62             : 
      63          15 :     pCellContext = pTempCellContext;
      64          15 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      65          15 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
      66         103 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      67             :     {
      68          88 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
      69         176 :         OUString aLocalName;
      70          88 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      71          88 :                                             sAttrName, &aLocalName );
      72         176 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
      73             : 
      74          88 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      75             :         {
      76             :             case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
      77             :             {
      78           0 :                 maAuthorBuffer = sValue;
      79             :             }
      80           0 :             break;
      81             :             case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
      82             :             {
      83           0 :                 maCreateDateBuffer = sValue;
      84             :             }
      85           0 :             break;
      86             :             case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
      87             :             {
      88           0 :                 maCreateDateStringBuffer = sValue;
      89             :             }
      90           0 :             break;
      91             :             case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
      92             :             {
      93           8 :                 mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
      94             :             }
      95           8 :             break;
      96             :             case XML_TOK_TABLE_ANNOTATION_ATTR_X:
      97             :             {
      98          10 :                 mrAnnotationData.mbUseShapePos = true;
      99             :             }
     100          10 :             break;
     101             :             case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
     102             :             {
     103          10 :                 mrAnnotationData.mbUseShapePos = true;
     104             :             }
     105          10 :             break;
     106             :         }
     107         103 :     }
     108          15 : }
     109             : 
     110          30 : ScXMLAnnotationContext::~ScXMLAnnotationContext()
     111             : {
     112          30 : }
     113             : 
     114          15 : void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
     115             : {
     116          15 :     if (pShapeContext)
     117          15 :         pShapeContext->StartElement(xAttrList);
     118          15 : }
     119             : 
     120          48 : SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix,
     121             :                                             const OUString& rLName,
     122             :                                             const ::com::sun::star::uno::Reference<
     123             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     124             : {
     125          48 :     SvXMLImportContext *pContext = 0;
     126             : 
     127          48 :     if( XML_NAMESPACE_DC == nPrefix )
     128             :     {
     129          19 :         if( IsXMLToken( rLName, XML_CREATOR ) )
     130             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     131           4 :                                             rLName, xAttrList, maAuthorBuffer);
     132          15 :         else if( IsXMLToken( rLName, XML_DATE ) )
     133             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     134          15 :                                             rLName, xAttrList, maCreateDateBuffer);
     135             :     }
     136          29 :     else if( XML_NAMESPACE_META == nPrefix )
     137             :     {
     138           0 :         if( IsXMLToken( rLName, XML_DATE_STRING ) )
     139             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     140           0 :                                             rLName, xAttrList, maCreateDateStringBuffer);
     141             :     }
     142             : 
     143          48 :     if( !pContext && pShapeContext )
     144          29 :         pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
     145             : 
     146          48 :     if( !pContext )
     147           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     148             : 
     149          48 :     return pContext;
     150             : }
     151             : 
     152           0 : void ScXMLAnnotationContext::Characters( const OUString& rChars )
     153             : {
     154           0 :     maTextBuffer.append(rChars);
     155           0 : }
     156             : 
     157          15 : void ScXMLAnnotationContext::EndElement()
     158             : {
     159          15 :     if (pShapeContext)
     160             :     {
     161          15 :         pShapeContext->EndElement();
     162          15 :         delete pShapeContext;
     163          15 :         pShapeContext = NULL;
     164             :     }
     165             : 
     166          15 :     mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
     167          15 :     mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
     168          15 :     if (mrAnnotationData.maCreateDate.isEmpty())
     169           0 :         mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
     170          15 :     mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
     171             : 
     172          15 :     XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
     173          15 :     pTableShapeImport->SetAnnotation(NULL);
     174          15 : }
     175             : 
     176          15 : void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
     177             :                                        const OUString& rStyleName, const OUString& rTextStyle )
     178             : {
     179          15 :     mrAnnotationData.mxShape = rxShape;
     180          15 :     mrAnnotationData.mxShapes = rxShapes;
     181          15 :     mrAnnotationData.maStyleName = rStyleName;
     182          15 :     mrAnnotationData.maTextStyle = rTextStyle;
     183          15 : }
     184             : 
     185          15 : void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const OUString& rName, const ESelection& rSelection )
     186             : {
     187          15 :     mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );
     188          15 : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10