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 : #ifndef INCLUDED_OOX_CORE_RELATIONS_HXX
21 : #define INCLUDED_OOX_CORE_RELATIONS_HXX
22 :
23 : #include <oox/helper/helper.hxx>
24 : #include <oox/dllapi.h>
25 : #include <map>
26 : #include <memory>
27 :
28 : namespace oox {
29 : namespace core {
30 :
31 :
32 :
33 : /** Expands to an OUString containing an 'officeDocument' transitional relation type created
34 : from the passed literal(!) ASCII(!) character array. */
35 : #define CREATE_OFFICEDOC_RELATION_TYPE( ascii ) \
36 : ( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/" ascii )
37 :
38 : /** Expands to an OUString containing an 'officeDocument' strict relation type created
39 : from the passed literal(!) ASCII(!) character array. */
40 : #define CREATE_OFFICEDOC_RELATION_TYPE_STRICT( ascii ) \
41 : ( "http://purl.oclc.org/ooxml/officeDocument/relationships/" ascii )
42 :
43 : /** Expands to an OUString containing a 'package' relation type created from
44 : the passed literal(!) ASCII(!) character array. */
45 : #define CREATE_PACKAGE_RELATION_TYPE( ascii ) \
46 : ( "http://schemas.openxmlformats.org/package/2006/relationships/" ascii )
47 :
48 : /** Expands to an OUString containing an MS Office specific relation type
49 : created from the passed literal(!) ASCII(!) character array. */
50 : #define CREATE_MSOFFICE_RELATION_TYPE( ascii ) \
51 : ( "http://schemas.microsoft.com/office/2006/relationships/" ascii )
52 :
53 : #define CREATE_XL_CONTENT_TYPE( ascii ) \
54 : ( "application/vnd.openxmlformats-officedocument.spreadsheetml." ascii "+xml" )
55 :
56 72040 : struct Relation
57 : {
58 : OUString maId;
59 : OUString maType;
60 : OUString maTarget;
61 : bool mbExternal;
62 :
63 14458 : Relation() : mbExternal( false ) {}
64 : };
65 :
66 :
67 :
68 : class Relations;
69 : typedef std::shared_ptr< Relations > RelationsRef;
70 :
71 4805 : class OOX_DLLPUBLIC Relations
72 : {
73 : public:
74 : explicit Relations( const OUString& rFragmentPath );
75 :
76 75 : size_t size() const { return maMap.size(); }
77 : size_t count( const OUString& rId ) const { return maMap.count( rId ); }
78 882 : ::std::map< OUString, Relation >::const_iterator begin() const
79 : {
80 882 : return maMap.begin();
81 : }
82 882 : ::std::map< OUString, Relation >::const_iterator end() const
83 : {
84 882 : return maMap.end();
85 : }
86 14375 : void insert( const ::std::map< OUString, Relation >::value_type& rVal )
87 : {
88 14375 : maMap.insert( rVal );
89 14375 : }
90 :
91 : /** Returns the path of the fragment this relations collection is related to. */
92 3923 : const OUString& getFragmentPath() const { return maFragmentPath; }
93 :
94 : /** Returns the relation with the passed relation identifier. */
95 : const Relation* getRelationFromRelId( const OUString& rId ) const;
96 : /** Returns the first relation with the passed type. */
97 : const Relation* getRelationFromFirstType( const OUString& rType ) const;
98 : /** Returns the first relation with the passed type. */
99 : const Relation* getRelationFromFirstTypeFromOfficeDoc( const OUString& rType ) const;
100 : /** Finds all relations associated with the passed type. */
101 : RelationsRef getRelationsFromTypeFromOfficeDoc( const OUString& rType ) const;
102 :
103 : /** Returns the external target of the relation with the passed relation identifier. */
104 : OUString getExternalTargetFromRelId( const OUString& rRelId ) const;
105 : /** Returns the internal target of the relation with the passed relation identifier. */
106 : OUString getInternalTargetFromRelId( const OUString& rRelId ) const;
107 :
108 : /** Returns the full fragment path for the target of the passed relation. */
109 : OUString getFragmentPathFromRelation( const Relation& rRelation ) const;
110 : /** Returns the full fragment path for the passed relation identifier. */
111 : OUString getFragmentPathFromRelId( const OUString& rRelId ) const;
112 : /** Returns the full fragment path for the first relation of the passed type. */
113 : OUString getFragmentPathFromFirstType( const OUString& rType ) const;
114 : OUString getFragmentPathFromFirstTypeFromOfficeDoc( const OUString& rType ) const;
115 :
116 : private:
117 : ::std::map< OUString, Relation > maMap;
118 : OUString maFragmentPath;
119 : };
120 :
121 :
122 :
123 : } // namespace core
124 : } // namespace oox
125 :
126 : #endif
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|