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 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::xml::sax;
30 :
31 : namespace {
32 :
33 : /* Build path to relations file from passed fragment path, e.g.:
34 : 'path/path/file.xml' -> 'path/path/_rels/file.xml.rels'
35 : 'file.xml' -> '_rels/file.xml.rels'
36 : '' -> '_rels/.rels'
37 : */
38 5908 : OUString lclGetRelationsPath( const OUString& rFragmentPath )
39 : {
40 5908 : sal_Int32 nPathLen = ::std::max< sal_Int32 >( rFragmentPath.lastIndexOf( '/' ) + 1, 0 );
41 : return
42 : OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ). // file path including slash
43 11816 : appendAscii( "_rels/" ). // additional '_rels/' path
44 17724 : append( rFragmentPath.copy( nPathLen ) ). // file name after path
45 5908 : appendAscii( ".rels" ). // '.rels' suffix
46 11816 : makeStringAndClear();
47 : }
48 :
49 : } // namespace
50 :
51 5908 : RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, RelationsRef xRelations ) :
52 5908 : FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ),
53 11816 : mxRelations( xRelations )
54 : {
55 5908 : }
56 :
57 28606 : Reference< XFastContextHandler > RelationsFragment::createFastChildContext(
58 : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException, std::exception)
59 : {
60 28606 : Reference< XFastContextHandler > xRet;
61 57212 : AttributeList aAttribs( rxAttribs );
62 28606 : switch( nElement )
63 : {
64 : case PR_TOKEN( Relationship ):
65 : {
66 24782 : Relation aRelation;
67 24782 : aRelation.maId = aAttribs.getString( XML_Id, OUString() );
68 24782 : aRelation.maType = aAttribs.getString( XML_Type, OUString() );
69 24782 : aRelation.maTarget = aAttribs.getString( XML_Target, OUString() );
70 24782 : if( !aRelation.maId.isEmpty() && !aRelation.maType.isEmpty() && !aRelation.maTarget.isEmpty() )
71 : {
72 24780 : sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal );
73 : OSL_ENSURE( (nTargetMode == XML_Internal) || (nTargetMode == XML_External),
74 : "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" );
75 24780 : aRelation.mbExternal = nTargetMode != XML_Internal;
76 :
77 : OSL_ENSURE( mxRelations->count( aRelation.maId ) == 0,
78 : "RelationsFragment::createFastChildContext - relation identifier exists already" );
79 24780 : mxRelations->insert( ::std::map< OUString, Relation >::value_type( aRelation.maId, aRelation ) );
80 24782 : }
81 : }
82 24782 : break;
83 : case PR_TOKEN( Relationships ):
84 3824 : xRet = getFastContextHandler();
85 3824 : break;
86 : }
87 57212 : return xRet;
88 : }
89 :
90 : } // namespace core
91 : } // namespace oox
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|