My Project
Package.h
1 /*-----------------------------------------------------------------------
2 Copyright F2I-CONSULTING, (2014-2016)
3 
4 philippe.verney@f2i-consulting.com
5 
6 This software is a computer program whose purpose is to access to data formatted using Energistics standards.
7 
8 This software is governed by the CeCILL-B license under French law and
9 abiding by the rules of distribution of free software. You can use,
10 modify and/ or redistribute the software under the terms of the CeCILL-B
11 license as circulated by CEA, CNRS and INRIA at the following URL
12 "http://www.cecill.info".
13 
14 As a counterpart to the access to the source code and rights to copy,
15 modify and redistribute granted by the license, users are provided only
16 with a limited warranty and the software's author, the holder of the
17 economic rights, and the successive licensors have only limited
18 liability.
19 
20 In this respect, the user's attention is drawn to the risks associated
21 with loading, using, modifying and/or developing or reproducing the
22 software by the user in light of its specific status of free software,
23 that may mean that it is complicated to manipulate, and that also
24 therefore means that it is reserved for developers and experienced
25 professionals having in-depth computer knowledge. Users are therefore
26 encouraged to load and test the software's suitability as regards their
27 requirements in conditions enabling the security of their systems and/or
28 data to be ensured and, more generally, to use and operate it in the
29 same conditions as regards security.
30 
31 The fact that you are presently reading this means that you have had
32 knowledge of the CeCILL-B license and that you accept its terms.
33 -----------------------------------------------------------------------*/
34 #ifndef PACKAGE_H
35 #define PACKAGE_H
36 
37 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
38 #include <unordered_map>
39 #else
40 #include <tr1/unordered_map>
41 #endif
42 
43 #include "FileCoreProperties.h"
44 #include "FileContentType.h"
45 #include "FileRelationship.h"
46 
47 namespace epc
48 {
49  class Package
50  {
51 
52  private :
53  class CheshireCat; // Not defined here but in the cpp
54  CheshireCat * d_ptr; // opaque pointer
55 
56 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
57  typedef std::unordered_map<std::string, class FilePart*> PartMap;
58 #else
59  typedef std::tr1::unordered_map<std::string, class FilePart*> PartMap;
60 #endif
61 
66  void writeStringIntoNewPart(const std::string &input, const std::string & partPath);
67 
68  static const char* CORE_PROP_REL_TYPE;
69  static const char* EXTENDED_CORE_PROP_REL_TYPE;
70 
71  public:
75  Package();
76 
80  Package(const FileCoreProperties & pkgFileCP, const FileContentType & pkgFileCT, const FileRelationship & pkgFileRS, const PartMap & pkgFileP, const std::string & pkgPathName);
81 
85  ~Package();
86 
90  void openForWriting(const std::string & pkgPathName, bool useZip64 = false);
91 
95  void openForReading(const std::string & pkgPathName);
96 
100  void close();
101 
106 
110  const FileContentType& getFileContentType() const;
111 
116 
120  const PartMap & getAllFilePart() const;
121 
125  const std::string & getPathname() const;
126 
131  void setFileFileCoreProperties(const FileCoreProperties & pkgFileCP);
132 
137 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
138  std::unordered_map< std::string, std::string > & getExtendedCoreProperty();
139 #else
140  std::tr1::unordered_map< std::string, std::string > & getExtendedCoreProperty();
141 #endif
142 
148  void addProperty(const CoreProperty::TypeProperty & pkgTypeProperty, const std::string & pkgPropertyValue);
149 
154  void setFileContentType(const FileContentType & pkgFileCT);
155 
160  void addContentType(const ContentType & contentType);
161 
166  void setPrincipalRelationship(const FileRelationship & pkgFileRS);
167 
172  void addRelationship(const Relationship & relationship);
173 
178  void setAllFilePart(const std::vector<class FilePart*> & pkgFilePart);
179 
184  class FilePart* createPart(const std::string & inputContent, const std::string & outputPartPath);
185 
189  class FilePart* findPart(const std::string & outputPartPath) const;
190 
194  bool fileExists(const std::string & filename) const;
195 
199  std::string extractFile(const std::string & filename, const std::string & password = "");
200 
201  void writePackage();
202  };
203 }
204 
205 #endif
void setPrincipalRelationship(const FileRelationship &pkgFileRS)
set the Relationships file.
Definition: Package.cpp:453
const FileCoreProperties & getFileCoreProperties() const
Definition: Package.cpp:352
void openForReading(const std::string &pkgPathName)
Definition: Package.cpp:262
void openForWriting(const std::string &pkgPathName, bool useZip64=false)
Definition: Package.cpp:232
bool fileExists(const std::string &filename) const
Definition: Package.cpp:671
~Package()
Definition: Package.cpp:227
void close()
Definition: Package.cpp:347
Definition: ContentType.h:41
Package()
Definition: Package.cpp:217
Definition: FileRelationship.h:47
Definition: FileCoreProperties.h:41
void addProperty(const CoreProperty::TypeProperty &pkgTypeProperty, const std::string &pkgPropertyValue)
add a Property in the CoreProperties file of package.
Definition: Package.cpp:391
void setAllFilePart(const std::vector< class FilePart * > &pkgFilePart)
set all Parts file.
Definition: FilePart.h:42
const std::string & getPathname() const
Definition: Package.cpp:372
const FileContentType & getFileContentType() const
Definition: Package.cpp:357
class FilePart * createPart(const std::string &inputContent, const std::string &outputPartPath)
Creates a part in the package and returns it. This part will be automatically destroy with the packag...
Definition: Package.cpp:463
std::string extractFile(const std::string &filename, const std::string &password="")
Definition: Package.cpp:679
TypeProperty
Definition: CoreProperty.h:49
Definition: ContentType.h:39
Definition: Package.h:49
Definition: FileContentType.h:48
class FilePart * findPart(const std::string &outputPartPath) const
Find a part corresponding to the given path.
Definition: Package.cpp:471
const FileRelationship & getPrincipalRelationship() const
Definition: Package.cpp:362
void setFileContentType(const FileContentType &pkgFileCT)
set the ContentTypes file.
Definition: Package.cpp:443
void addContentType(const ContentType &contentType)
add a ContentType in the ContentTypes file of package.
Definition: Package.cpp:448
Definition: Relationship.h:44
const PartMap & getAllFilePart() const
Definition: Package.cpp:367
void addRelationship(const Relationship &relationship)
add a Relationship in the Relationships file of package.
Definition: Package.cpp:458
std::tr1::unordered_map< std::string, std::string > & getExtendedCoreProperty()
Definition: Package.cpp:385
Definition: Package.cpp:150
void setFileFileCoreProperties(const FileCoreProperties &pkgFileCP)
set the CoreProperties file.
Definition: Package.cpp:377