Branch data 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 : 273 : OUString lclGetRelationsPath( const OUString& rFragmentPath )
46 : : {
47 [ + - ]: 273 : sal_Int32 nPathLen = ::std::max< sal_Int32 >( rFragmentPath.lastIndexOf( '/' ) + 1, 0 );
48 : : return
49 : : OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ). // file path including slash
50 [ + - ][ + - ]: 546 : appendAscii( "_rels/" ). // additional '_rels/' path
51 [ + - ]: 819 : append( rFragmentPath.copy( nPathLen ) ). // file name after path
52 [ + - ]: 273 : appendAscii( ".rels" ). // '.rels' suffix
53 [ + - ]: 546 : makeStringAndClear();
54 : : }
55 : :
56 : : } // namespace
57 : :
58 : : // ============================================================================
59 : :
60 : 273 : RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, RelationsRef xRelations ) :
61 : 273 : FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ),
62 [ + - ][ + - ]: 546 : mxRelations( xRelations )
[ + - ]
63 : : {
64 : 273 : }
65 : :
66 : 762 : Reference< XFastContextHandler > RelationsFragment::createFastChildContext(
67 : : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
68 : : {
69 : 762 : Reference< XFastContextHandler > xRet;
70 [ + - ]: 762 : AttributeList aAttribs( rxAttribs );
71 [ + + - ]: 762 : switch( nElement )
72 : : {
73 : : case PR_TOKEN( Relationship ):
74 : : {
75 : 621 : Relation aRelation;
76 [ + - ]: 621 : aRelation.maId = aAttribs.getString( XML_Id, OUString() );
77 [ + - ]: 621 : aRelation.maType = aAttribs.getString( XML_Type, OUString() );
78 [ + - ]: 621 : aRelation.maTarget = aAttribs.getString( XML_Target, OUString() );
79 [ + - ][ + - ]: 621 : if( !aRelation.maId.isEmpty() && !aRelation.maType.isEmpty() && !aRelation.maTarget.isEmpty() )
[ + - ][ + - ]
80 : : {
81 [ + - ]: 621 : 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 : 621 : aRelation.mbExternal = nTargetMode != XML_Internal;
85 : :
86 : : OSL_ENSURE( mxRelations->count( aRelation.maId ) == 0,
87 : : "RelationsFragment::createFastChildContext - relation identifier exists already" );
88 [ + - ]: 621 : mxRelations->insert( Relations::value_type( aRelation.maId, aRelation ) );
89 : 621 : }
90 : : }
91 : 621 : break;
92 : : case PR_TOKEN( Relationships ):
93 [ + - ][ + - ]: 141 : xRet = getFastContextHandler();
94 : 141 : break;
95 : : }
96 [ + - ]: 762 : return xRet;
97 : : }
98 : :
99 : : // ============================================================================
100 : :
101 : : } // namespace core
102 : : } // namespace oox
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|