1*ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ca5ec200SAndrew Rist * distributed with this work for additional information 6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10*ca5ec200SAndrew Rist * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ca5ec200SAndrew Rist * 13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17*ca5ec200SAndrew Rist * specific language governing permissions and limitations 18*ca5ec200SAndrew Rist * under the License. 19*ca5ec200SAndrew Rist * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/core/relationshandler.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 27cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace oox { 30cdf0e10cSrcweir namespace core { 31cdf0e10cSrcweir 32cdf0e10cSrcweir // ============================================================================ 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 36cdf0e10cSrcweir 37cdf0e10cSrcweir using ::rtl::OUString; 38cdf0e10cSrcweir using ::rtl::OUStringBuffer; 39cdf0e10cSrcweir 40cdf0e10cSrcweir // ============================================================================ 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace { 43cdf0e10cSrcweir 44cdf0e10cSrcweir /* Build path to relations file from passed fragment path, e.g.: 45cdf0e10cSrcweir 'path/path/file.xml' -> 'path/path/_rels/file.xml.rels' 46cdf0e10cSrcweir 'file.xml' -> '_rels/file.xml.rels' 47cdf0e10cSrcweir '' -> '_rels/.rels' 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir OUString lclGetRelationsPath( const OUString& rFragmentPath ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir sal_Int32 nPathLen = ::std::max< sal_Int32 >( rFragmentPath.lastIndexOf( '/' ) + 1, 0 ); 52cdf0e10cSrcweir return 53cdf0e10cSrcweir OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ). // file path including slash 54cdf0e10cSrcweir appendAscii( "_rels/" ). // additional '_rels/' path 55cdf0e10cSrcweir append( rFragmentPath.copy( nPathLen ) ). // file name after path 56cdf0e10cSrcweir appendAscii( ".rels" ). // '.rels' suffix 57cdf0e10cSrcweir makeStringAndClear(); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir } // namespace 61cdf0e10cSrcweir 62cdf0e10cSrcweir // ============================================================================ 63cdf0e10cSrcweir 64cdf0e10cSrcweir RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, RelationsRef xRelations ) : 65cdf0e10cSrcweir FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ), 66cdf0e10cSrcweir mxRelations( xRelations ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir Reference< XFastContextHandler > RelationsFragment::createFastChildContext( 71cdf0e10cSrcweir sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 74cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 75cdf0e10cSrcweir switch( nElement ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir case PR_TOKEN( Relationship ): 78cdf0e10cSrcweir { 79cdf0e10cSrcweir Relation aRelation; 80cdf0e10cSrcweir aRelation.maId = aAttribs.getString( XML_Id, OUString() ); 81cdf0e10cSrcweir aRelation.maType = aAttribs.getString( XML_Type, OUString() ); 82cdf0e10cSrcweir aRelation.maTarget = aAttribs.getString( XML_Target, OUString() ); 83cdf0e10cSrcweir if( (aRelation.maId.getLength() > 0) && (aRelation.maType.getLength() > 0) && (aRelation.maTarget.getLength() > 0) ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal ); 86cdf0e10cSrcweir OSL_ENSURE( (nTargetMode == XML_Internal) || (nTargetMode == XML_External), 87cdf0e10cSrcweir "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" ); 88cdf0e10cSrcweir aRelation.mbExternal = nTargetMode != XML_Internal; 89cdf0e10cSrcweir 90cdf0e10cSrcweir OSL_ENSURE( mxRelations->count( aRelation.maId ) == 0, 91cdf0e10cSrcweir "RelationsFragment::createFastChildContext - relation identifier exists already" ); 92cdf0e10cSrcweir mxRelations->insert( Relations::value_type( aRelation.maId, aRelation ) ); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir } 95cdf0e10cSrcweir break; 96cdf0e10cSrcweir case PR_TOKEN( Relationships ): 97cdf0e10cSrcweir xRet = getFastContextHandler(); 98cdf0e10cSrcweir break; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir return xRet; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ============================================================================ 104cdf0e10cSrcweir 105cdf0e10cSrcweir } // namespace core 106cdf0e10cSrcweir } // namespace oox 107