1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: relationshandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/core/relationshandler.hxx"
32 #include <rtl/ustrbuf.hxx>
34 #include "oox/helper/attributelist.hxx"
35 #include "oox/core/namespaces.hxx"
37 using ::rtl::OUString
;
38 using ::rtl::OUStringBuffer
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::xml::sax
;
45 // ============================================================================
49 /* Build path to relations file from passed fragment path, e.g.:
50 'path/path/file.xml' -> 'path/path/_rels/file.xml.rels'
51 'file.xml' -> '_rels/file.xml.rels'
54 OUString
lclGetRelationsPath( const OUString
& rFragmentPath
)
56 sal_Int32 nPathLen
= ::std::max
< sal_Int32
>( rFragmentPath
.lastIndexOf( '/' ) + 1, 0 );
58 OUStringBuffer( rFragmentPath
.copy( 0, nPathLen
) ). // file path including slash
59 appendAscii( "_rels/" ). // additional '_rels/' path
60 append( rFragmentPath
.copy( nPathLen
) ). // file name after path
61 appendAscii( ".rels" ). // '.rels' suffix
67 // ============================================================================
69 RelationsFragment::RelationsFragment( XmlFilterBase
& rFilter
, RelationsRef xRelations
) :
70 FragmentHandler( rFilter
, lclGetRelationsPath( xRelations
->getFragmentPath() ), xRelations
),
71 mxRelations( xRelations
)
75 Reference
< XFastContextHandler
> RelationsFragment::createFastChildContext(
76 sal_Int32 nElement
, const Reference
< XFastAttributeList
>& rxAttribs
) throw (SAXException
, RuntimeException
)
78 Reference
< XFastContextHandler
> xRet
;
79 AttributeList
aAttribs( rxAttribs
);
82 case NMSP_PACKAGE_RELATIONSHIPS
|XML_Relationship
:
85 aRelation
.maId
= aAttribs
.getString( XML_Id
, OUString() );
86 aRelation
.maType
= aAttribs
.getString( XML_Type
, OUString() );
87 aRelation
.maTarget
= aAttribs
.getString( XML_Target
, OUString() );
88 if( (aRelation
.maId
.getLength() > 0) && (aRelation
.maType
.getLength() > 0) && (aRelation
.maTarget
.getLength() > 0) )
90 sal_Int32 nTargetMode
= aAttribs
.getToken( XML_TargetMode
, XML_Internal
);
91 OSL_ENSURE( (nTargetMode
== XML_Internal
) || (nTargetMode
== XML_External
),
92 "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" );
93 aRelation
.mbExternal
= nTargetMode
!= XML_Internal
;
95 OSL_ENSURE( mxRelations
->count( aRelation
.maId
) == 0,
96 "RelationsFragment::createFastChildContext - relation identifier exists already" );
97 mxRelations
->insert( Relations::value_type( aRelation
.maId
, aRelation
) );
101 case NMSP_PACKAGE_RELATIONSHIPS
|XML_Relationships
:
102 xRet
= getFastContextHandler();
108 // ============================================================================