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

Generated by: LCOV version 1.11