LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextFrameHyperlinkContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 51 67 76.1 %
Date: 2014-11-03 Functions: 10 13 76.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 <sax/tools/converter.hxx>
      21             : 
      22             : #include <xmloff/xmlimp.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include "XMLTextFrameContext.hxx"
      27             : #include "XMLTextFrameHyperlinkContext.hxx"
      28             : 
      29             : #include <txtparaimphint.hxx>
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::text;
      33             : using namespace ::com::sun::star::xml::sax;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::xmloff::token;
      36             : 
      37             : namespace drawing = com::sun::star::drawing;
      38             : 
      39          88 : TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
      40             : 
      41           4 : XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
      42             :         SvXMLImport& rImport,
      43             :         sal_uInt16 nPrfx, const OUString& rLName,
      44             :         const Reference< XAttributeList > & xAttrList,
      45             :         TextContentAnchorType eATyp ) :
      46             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      47             :     eDefaultAnchorType( eATyp ),
      48           4 :     bMap( false )
      49             : {
      50           4 :     OUString sShow;
      51             :     const SvXMLTokenMap& rTokenMap =
      52           4 :         GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
      53             : 
      54           4 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      55          20 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      56             :     {
      57          16 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      58          32 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      59             : 
      60          32 :         OUString aLocalName;
      61             :         sal_uInt16 nPrefix =
      62          16 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      63          16 :                                                             &aLocalName );
      64          16 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
      65             :         {
      66             :         case XML_TOK_TEXT_HYPERLINK_HREF:
      67           4 :             sHRef = GetImport().GetAbsoluteReference( rValue );
      68           4 :             break;
      69             :         case XML_TOK_TEXT_HYPERLINK_NAME:
      70           4 :             sName = rValue;
      71           4 :             break;
      72             :         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
      73           2 :             sTargetFrameName = rValue;
      74           2 :             break;
      75             :         case XML_TOK_TEXT_HYPERLINK_SHOW:
      76           2 :             sShow = rValue;
      77           2 :             break;
      78             :         case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
      79             :             {
      80           0 :                 bool bTmp(false);
      81           0 :                 if (::sax::Converter::convertBool( bTmp, rValue ))
      82             :                 {
      83           0 :                     bMap = bTmp;
      84             :                 }
      85             :             }
      86           0 :             break;
      87             :         }
      88          16 :     }
      89             : 
      90           4 :     if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
      91             :     {
      92           0 :         if( IsXMLToken( sShow, XML_NEW ) )
      93           0 :             sTargetFrameName = "_blank";
      94           0 :         else if( IsXMLToken( sShow, XML_REPLACE ) )
      95           0 :             sTargetFrameName = "_self";
      96           4 :     }
      97           4 : }
      98             : 
      99           8 : XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
     100             : {
     101           8 : }
     102             : 
     103           4 : void XMLTextFrameHyperlinkContext::EndElement()
     104             : {
     105           4 : }
     106             : 
     107           4 : SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
     108             :         sal_uInt16 nPrefix,
     109             :         const OUString& rLocalName,
     110             :         const Reference< XAttributeList > & xAttrList )
     111             : {
     112           4 :     SvXMLImportContext *pContext = 0;
     113           4 :     XMLTextFrameContext *pTextFrameContext = 0;
     114             : 
     115           4 :     if( XML_NAMESPACE_DRAW == nPrefix )
     116             :     {
     117           4 :         if( IsXMLToken( rLocalName, XML_FRAME ) )
     118           4 :             pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
     119             :                                                 rLocalName, xAttrList,
     120           4 :                                                 eDefaultAnchorType );
     121             :     }
     122             : 
     123           4 :     if( pTextFrameContext )
     124             :     {
     125           4 :         pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
     126           4 :         pContext = pTextFrameContext;
     127           4 :         xFrameContext = pContext;
     128             :     }
     129             :     else
     130           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     131             : 
     132           4 :     return pContext;
     133             : }
     134             : 
     135             : 
     136           4 : TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
     137             : {
     138           4 :     if( xFrameContext.Is() )
     139             :     {
     140           4 :         SvXMLImportContext *pContext = &xFrameContext;
     141           4 :         return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
     142             :     }
     143             :     else
     144           0 :         return eDefaultAnchorType;
     145             : 
     146             : }
     147             : 
     148           4 : Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
     149             : {
     150           4 :     Reference <XTextContent > xTxt;
     151           4 :     if( xFrameContext.Is() )
     152             :     {
     153           4 :         SvXMLImportContext *pContext = &xFrameContext;
     154           4 :         xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
     155             :     }
     156             : 
     157           4 :     return xTxt;
     158             : }
     159             : 
     160             : // Frame "to character": anchor moves from first to last char after saving (#i33242#)
     161           0 : Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
     162             : {
     163           0 :     Reference < drawing::XShape > xShape;
     164           0 :     if( xFrameContext.Is() )
     165             :     {
     166           0 :         SvXMLImportContext *pContext = &xFrameContext;
     167           0 :         xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
     168             :     }
     169             : 
     170           0 :     return xShape;
     171             : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10