1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_CORE_RELATIONS_HXX 25 #define OOX_CORE_RELATIONS_HXX 26 27 #include <map> 28 #include <boost/shared_ptr.hpp> 29 #include "oox/helper/helper.hxx" 30 31 namespace oox { 32 namespace core { 33 34 // ============================================================================ 35 36 /** Expands to an OUString containing an 'officeDocument' relation type created 37 from the passed literal(!) ASCII(!) character array. */ 38 #define CREATE_OFFICEDOC_RELATION_TYPE( ascii ) \ 39 CREATE_OUSTRING( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/" ascii ) 40 41 /** Expands to an OUString containing a 'package' relation type created from 42 the passed literal(!) ASCII(!) character array. */ 43 #define CREATE_PACKAGE_RELATION_TYPE( ascii ) \ 44 CREATE_OUSTRING( "http://schemas.openxmlformats.org/package/2006/relationships/" ascii ) 45 46 /** Expands to an OUString containing an MS Office specific relation type 47 created from the passed literal(!) ASCII(!) character array. */ 48 #define CREATE_MSOFFICE_RELATION_TYPE( ascii ) \ 49 CREATE_OUSTRING( "http://schemas.microsoft.com/office/2006/relationships/" ascii ) 50 51 // ============================================================================ 52 53 struct Relation 54 { 55 ::rtl::OUString maId; 56 ::rtl::OUString maType; 57 ::rtl::OUString maTarget; 58 bool mbExternal; 59 Relationoox::core::Relation60 inline explicit Relation() : mbExternal( false ) {} 61 }; 62 63 // ============================================================================ 64 65 class Relations; 66 typedef ::boost::shared_ptr< Relations > RelationsRef; 67 68 class Relations : public ::std::map< ::rtl::OUString, Relation > 69 { 70 public: 71 explicit Relations( const ::rtl::OUString& rFragmentPath ); 72 73 /** Returns the path of the fragment this relations collection is related to. */ getFragmentPath() const74 inline const ::rtl::OUString& getFragmentPath() const { return maFragmentPath; } 75 76 /** Returns the relation with the passed relation identifier. */ 77 const Relation* getRelationFromRelId( const ::rtl::OUString& rId ) const; 78 /** Returns the first relation with the passed type. */ 79 const Relation* getRelationFromFirstType( const ::rtl::OUString& rType ) const; 80 /** Finds all relations associated with the passed type. */ 81 RelationsRef getRelationsFromType( const ::rtl::OUString& rType ) const; 82 83 /** Returns the external target of the relation with the passed relation identifier. */ 84 ::rtl::OUString getExternalTargetFromRelId( const ::rtl::OUString& rRelId ) const; 85 /** Returns the external target of the first relation with the passed type. */ 86 ::rtl::OUString getExternalTargetFromFirstType( const ::rtl::OUString& rType ) const; 87 88 /** Returns the full fragment path for the target of the passed relation. */ 89 ::rtl::OUString getFragmentPathFromRelation( const Relation& rRelation ) const; 90 /** Returns the full fragment path for the passed relation identifier. */ 91 ::rtl::OUString getFragmentPathFromRelId( const ::rtl::OUString& rRelId ) const; 92 /** Returns the full fragment path for the first relation of the passed type. */ 93 ::rtl::OUString getFragmentPathFromFirstType( const ::rtl::OUString& rType ) const; 94 95 private: 96 ::rtl::OUString maFragmentPath; 97 }; 98 99 // ============================================================================ 100 101 } // namespace core 102 } // namespace oox 103 104 #endif 105