LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - XMLSectionSourceImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 44 0.0 %
Date: 2012-12-27 Functions: 0 11 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 "XMLSectionSourceImportContext.hxx"
      21             : #include "XMLSectionImportContext.hxx"
      22             : #include <com/sun/star/text/SectionFileLink.hpp>
      23             : #include <xmloff/xmlictxt.hxx>
      24             : #include <xmloff/xmlimp.hxx>
      25             : #include <xmloff/txtimp.hxx>
      26             : #include <xmloff/nmspmap.hxx>
      27             : #include "xmloff/xmlnmspe.hxx"
      28             : #include <xmloff/xmltoken.hxx>
      29             : #include <com/sun/star/uno/Reference.h>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : 
      32             : 
      33             : using ::rtl::OUString;
      34             : using ::com::sun::star::beans::XPropertySet;
      35             : using ::com::sun::star::uno::Reference;
      36             : using ::com::sun::star::xml::sax::XAttributeList;
      37             : 
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::text;
      40             : using namespace ::xmloff::token;
      41             : 
      42             : 
      43           0 : TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext);
      44             : 
      45           0 : XMLSectionSourceImportContext::XMLSectionSourceImportContext(
      46             :     SvXMLImport& rImport,
      47             :     sal_uInt16 nPrfx,
      48             :     const OUString& rLocalName,
      49             :     Reference<XPropertySet> & rSectPropSet) :
      50             :         SvXMLImportContext(rImport, nPrfx, rLocalName),
      51           0 :         rSectionPropertySet(rSectPropSet)
      52             : {
      53           0 : }
      54             : 
      55           0 : XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
      56             : {
      57           0 : }
      58             : 
      59             : enum XMLSectionSourceToken
      60             : {
      61             :     XML_TOK_SECTION_XLINK_HREF,
      62             :     XML_TOK_SECTION_TEXT_FILTER_NAME,
      63             :     XML_TOK_SECTION_TEXT_SECTION_NAME
      64             : };
      65             : 
      66             : static SvXMLTokenMapEntry aSectionSourceTokenMap[] =
      67             : {
      68             :     { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF },
      69             :     { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME },
      70             :     { XML_NAMESPACE_TEXT, XML_SECTION_NAME,
      71             :                                         XML_TOK_SECTION_TEXT_SECTION_NAME },
      72             :     XML_TOKEN_MAP_END
      73             : };
      74             : 
      75             : 
      76           0 : void XMLSectionSourceImportContext::StartElement(
      77             :     const Reference<XAttributeList> & xAttrList)
      78             : {
      79           0 :     SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
      80           0 :     OUString sURL;
      81           0 :     OUString sFilterName;
      82           0 :     OUString sSectionName;
      83             : 
      84           0 :     sal_Int16 nLength = xAttrList->getLength();
      85           0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      86             :     {
      87           0 :         OUString sLocalName;
      88           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      89           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      90           0 :                               &sLocalName );
      91             : 
      92           0 :         switch (aTokenMap.Get(nPrefix, sLocalName))
      93             :         {
      94             :             case XML_TOK_SECTION_XLINK_HREF:
      95           0 :                 sURL = xAttrList->getValueByIndex(nAttr);
      96           0 :                 break;
      97             : 
      98             :             case XML_TOK_SECTION_TEXT_FILTER_NAME:
      99           0 :                 sFilterName = xAttrList->getValueByIndex(nAttr);
     100           0 :                 break;
     101             : 
     102             :             case XML_TOK_SECTION_TEXT_SECTION_NAME:
     103           0 :                 sSectionName = xAttrList->getValueByIndex(nAttr);
     104           0 :                 break;
     105             : 
     106             :             default:
     107             :                 ; // ignore
     108           0 :                 break;
     109             :         }
     110           0 :     }
     111             : 
     112             :     // we only need them once
     113           0 :     const OUString sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink"));
     114           0 :     const OUString sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion"));
     115             : 
     116           0 :     Any aAny;
     117           0 :     if (!sURL.isEmpty() || !sFilterName.isEmpty())
     118             :     {
     119           0 :         SectionFileLink aFileLink;
     120           0 :         aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL );
     121           0 :         aFileLink.FilterName = sFilterName;
     122             : 
     123           0 :         aAny <<= aFileLink;
     124           0 :         rSectionPropertySet->setPropertyValue(sFileLink, aAny);
     125             :     }
     126             : 
     127           0 :     if (!sSectionName.isEmpty())
     128             :     {
     129           0 :         aAny <<= sSectionName;
     130           0 :         rSectionPropertySet->setPropertyValue(sLinkRegion, aAny);
     131           0 :     }
     132           0 : }
     133             : 
     134           0 : void XMLSectionSourceImportContext::EndElement()
     135             : {
     136             :     // this space intentionally left blank.
     137           0 : }
     138             : 
     139           0 : SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext(
     140             :     sal_uInt16 nPrefix,
     141             :     const OUString& rLocalName,
     142             :     const Reference<XAttributeList> & )
     143             : {
     144             :     // ignore -> default context
     145           0 :     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
     146             : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10