LCOV - code coverage report
Current view: top level - libreoffice/oox/source/core - relationshandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 27 100.0 %
Date: 2012-12-27 Functions: 3 3 100.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 "oox/core/relationshandler.hxx"
      21             : 
      22             : #include <rtl/ustrbuf.hxx>
      23             : #include "oox/helper/attributelist.hxx"
      24             : 
      25             : namespace oox {
      26             : namespace core {
      27             : 
      28             : // ============================================================================
      29             : 
      30             : using namespace ::com::sun::star::uno;
      31             : using namespace ::com::sun::star::xml::sax;
      32             : 
      33             : using ::rtl::OUString;
      34             : using ::rtl::OUStringBuffer;
      35             : 
      36             : // ============================================================================
      37             : 
      38             : namespace {
      39             : 
      40             : /*  Build path to relations file from passed fragment path, e.g.:
      41             :         'path/path/file.xml'    -> 'path/path/_rels/file.xml.rels'
      42             :         'file.xml'              -> '_rels/file.xml.rels'
      43             :         ''                      -> '_rels/.rels'
      44             :  */
      45         126 : OUString lclGetRelationsPath( const OUString& rFragmentPath )
      46             : {
      47         126 :     sal_Int32 nPathLen = ::std::max< sal_Int32 >( rFragmentPath.lastIndexOf( '/' ) + 1, 0 );
      48             :     return
      49             :         OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ).    // file path including slash
      50         252 :         appendAscii( "_rels/" ).                                // additional '_rels/' path
      51         378 :         append( rFragmentPath.copy( nPathLen ) ).               // file name after path
      52         126 :         appendAscii( ".rels" ).                                 // '.rels' suffix
      53         252 :         makeStringAndClear();
      54             : }
      55             : 
      56             : } // namespace
      57             : 
      58             : // ============================================================================
      59             : 
      60         126 : RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, RelationsRef xRelations ) :
      61         126 :     FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ),
      62         252 :     mxRelations( xRelations )
      63             : {
      64         126 : }
      65             : 
      66         374 : Reference< XFastContextHandler > RelationsFragment::createFastChildContext(
      67             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
      68             : {
      69         374 :     Reference< XFastContextHandler > xRet;
      70         374 :     AttributeList aAttribs( rxAttribs );
      71         374 :     switch( nElement )
      72             :     {
      73             :         case PR_TOKEN( Relationship ):
      74             :         {
      75         306 :             Relation aRelation;
      76         306 :             aRelation.maId     = aAttribs.getString( XML_Id, OUString() );
      77         306 :             aRelation.maType   = aAttribs.getString( XML_Type, OUString() );
      78         306 :             aRelation.maTarget = aAttribs.getString( XML_Target, OUString() );
      79         306 :             if( !aRelation.maId.isEmpty() && !aRelation.maType.isEmpty() && !aRelation.maTarget.isEmpty() )
      80             :             {
      81         306 :                 sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal );
      82             :                 OSL_ENSURE( (nTargetMode == XML_Internal) || (nTargetMode == XML_External),
      83             :                     "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" );
      84         306 :                 aRelation.mbExternal = nTargetMode != XML_Internal;
      85             : 
      86             :                 OSL_ENSURE( mxRelations->count( aRelation.maId ) == 0,
      87             :                     "RelationsFragment::createFastChildContext - relation identifier exists already" );
      88         306 :                 mxRelations->insert( Relations::value_type( aRelation.maId, aRelation ) );
      89         306 :             }
      90             :         }
      91         306 :         break;
      92             :         case PR_TOKEN( Relationships ):
      93          68 :             xRet = getFastContextHandler();
      94          68 :         break;
      95             :     }
      96         374 :     return xRet;
      97             : }
      98             : 
      99             : // ============================================================================
     100             : 
     101             : } // namespace core
     102             : } // namespace oox
     103             : 
     104             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10