xlnt
manifest.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024 xlnt-community
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE
22 //
23 // @license: http://www.opensource.org/licenses/mit-license.php
24 // @author: see AUTHORS file
25 
26 #pragma once
27 
28 #include <string>
29 #include <unordered_map>
30 
31 #include <xlnt/xlnt_config.hpp>
32 #include <xlnt/packaging/relationship.hpp>
33 #include <xlnt/utils/path.hpp>
34 
35 namespace xlnt {
36 
41 class XLNT_API manifest
42 {
43 public:
47  void clear();
48 
53  std::vector<path> parts() const;
54 
55  // Relationships
56 
60  bool has_relationship(const path &source, relationship_type type) const;
61 
65  bool has_relationship(const path &source, const std::string &rel_id) const;
66 
71  class relationship relationship(const path &source, relationship_type type) const;
72 
77  class relationship relationship(const path &source, const std::string &rel_id) const;
78 
82  std::vector<xlnt::relationship> relationships(const path &source) const;
83 
87  std::vector<xlnt::relationship> relationships(const path &source, relationship_type type) const;
88 
93  path canonicalize(const std::vector<xlnt::relationship> &rels) const;
94 
98  std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode);
99 
103  std::string register_relationship(const class relationship &rel);
104 
111  std::unordered_map<std::string, std::string> unregister_relationship(const uri &source, const std::string &rel_id);
112 
113  // Content Types
114 
118  std::string content_type(const path &part) const;
119 
120  // Default Content Types
121 
125  bool has_default_type(const std::string &extension) const;
126 
130  std::vector<std::string> extensions_with_default_types() const;
131 
135  std::string default_type(const std::string &extension) const;
136 
140  void register_default_type(const std::string &extension, const std::string &type);
141 
145  void unregister_default_type(const std::string &extension);
146 
147  // Override Content Types
148 
153  bool has_override_type(const path &part) const;
154 
159  std::string override_type(const path &part) const;
160 
164  std::vector<path> parts_with_overriden_types() const;
165 
169  void register_override_type(const path &part, const std::string &type);
170 
174  void unregister_override_type(const path &part);
175 
176  bool operator==(const manifest &other) const;
177 
178 private:
182  std::string next_relationship_id(const path &part) const;
183 
187  std::unordered_map<std::string, std::string> default_content_types_;
188 
192  std::unordered_map<path, std::string> override_content_types_;
193 
197  std::unordered_map<path, std::unordered_map<std::string, xlnt::relationship>> relationships_;
198 };
199 
200 } // namespace xlnt
Represents an association between a source Package or part, and a target object which can be a part o...
Definition: relationship.hpp:103
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
Encapsulates a uniform resource identifier (URI) as described by RFC 3986.
Definition: uri.hpp:38
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Encapsulates a path that points to location in a filesystem.
Definition: path.hpp:38
relationship_type
All package relationships must be one of these defined types.
Definition: relationship.hpp:54
target_mode
Specifies whether the target of a relationship is inside or outside the Package.
Definition: relationship.hpp:39
The manifest keeps track of all files in the OOXML package and their type and relationships.
Definition: manifest.hpp:41