SmartArt: text alignment
[LibreOffice.git] / oox / source / core / relationshandler.cxx
blobe5228313a69092fae61624772d6be07eb04f3e75
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/core/relationshandler.hxx"
22 #include <rtl/ustrbuf.hxx>
23 #include "oox/helper/attributelist.hxx"
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
27 namespace oox {
28 namespace core {
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
33 namespace {
35 /* Build path to relations file from passed fragment path, e.g.:
36 'path/path/file.xml' -> 'path/path/_rels/file.xml.rels'
37 'file.xml' -> '_rels/file.xml.rels'
38 '' -> '_rels/.rels'
40 OUString lclGetRelationsPath( const OUString& rFragmentPath )
42 sal_Int32 nPathLen = ::std::max< sal_Int32 >( rFragmentPath.lastIndexOf( '/' ) + 1, 0 );
43 return
44 OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ). // file path including slash
45 append( "_rels/" ). // additional '_rels/' path
46 append( rFragmentPath.copy( nPathLen ) ). // file name after path
47 append( ".rels" ). // '.rels' suffix
48 makeStringAndClear();
51 } // namespace
53 RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, const RelationsRef& xRelations ) :
54 FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ),
55 mxRelations( xRelations )
59 Reference< XFastContextHandler > RelationsFragment::createFastChildContext(
60 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
62 Reference< XFastContextHandler > xRet;
63 AttributeList aAttribs( rxAttribs );
64 switch( nElement )
66 case PR_TOKEN( Relationship ):
68 Relation aRelation;
69 aRelation.maId = aAttribs.getString( XML_Id, OUString() );
70 aRelation.maType = aAttribs.getString( XML_Type, OUString() );
71 aRelation.maTarget = aAttribs.getString( XML_Target, OUString() );
72 if( !aRelation.maId.isEmpty() && !aRelation.maType.isEmpty() && !aRelation.maTarget.isEmpty() )
74 sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal );
75 SAL_WARN_IF( (nTargetMode != XML_Internal) && (nTargetMode != XML_External), "oox",
76 "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" );
77 aRelation.mbExternal = nTargetMode != XML_Internal;
79 SAL_WARN_IF( mxRelations->count( aRelation.maId ) != 0, "oox",
80 "RelationsFragment::createFastChildContext - relation identifier exists already" );
81 mxRelations->insert( ::std::map< OUString, Relation >::value_type( aRelation.maId, aRelation ) );
84 break;
85 case PR_TOKEN( Relationships ):
86 xRet = getFastContextHandler();
87 break;
89 return xRet;
92 } // namespace core
93 } // namespace oox
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */