Fesapi  0.13.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
Package.h
1 /*-----------------------------------------------------------------------
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"; you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 -----------------------------------------------------------------------*/
19 
20 
21 
22 #ifndef PACKAGE_H
23 #define PACKAGE_H
24 
25 #include <vector>
26 #include <string>
27 
28 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
29 #include <unordered_map>
30 #else
31 #include <tr1/unordered_map>
32 #endif
33 
34 #include "FileCoreProperties.h"
35 #include "FileContentType.h"
36 #include "FileRelationship.h"
37 #include "FilePart.h"
38 
39 namespace epc
40 {
41  class Package
42  {
43 
44  private :
45  class CheshireCat; // Not defined here but in the cpp
46  CheshireCat * d_ptr; // opaque pointer
47 
48 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
49  typedef std::unordered_map<std::string, FilePart> PartMap;
50 #else
51  typedef std::tr1::unordered_map<std::string, FilePart> PartMap;
52 #endif
53 
58  void writeStringIntoNewPart(const std::string &input, const std::string & partPath);
59 
60  static const char* CORE_PROP_REL_TYPE;
61  static const char* EXTENDED_CORE_PROP_REL_TYPE;
62 
63  public:
67  Package();
68 
72  Package(const FileCoreProperties & pkgFileCP, const FileContentType & pkgFileCT, const FileRelationship & pkgFileRS, const PartMap & pkgFileP, const std::string & pkgPathName);
73 
77  ~Package();
78 
82  void openForWriting(const std::string & pkgPathName, bool useZip64 = false);
83 
88  std::vector<std::string> openForReading(const std::string & pkgPathName);
89 
93  void close();
94 
99 
103  const FileContentType& getFileContentType() const;
104 
109 
113  const PartMap & getAllFilePart() const;
114 
118  const std::string & getPathname() const;
119 
124  void setFileFileCoreProperties(const FileCoreProperties & pkgFileCP);
125 
130 #if (defined(_WIN32) && _MSC_VER >= 1600) || defined(__APPLE__)
131  std::unordered_map< std::string, std::string > & getExtendedCoreProperty();
132 #else
133  std::tr1::unordered_map< std::string, std::string > & getExtendedCoreProperty();
134 #endif
135 
141  void addProperty(const CoreProperty::TypeProperty & pkgTypeProperty, const std::string & pkgPropertyValue);
142 
147  void setFileContentType(const FileContentType & pkgFileCT);
148 
153  void addContentType(const ContentType & contentType);
154 
159  void setPrincipalRelationship(const FileRelationship & pkgFileRS);
160 
165  void addRelationship(const Relationship & relationship);
166 
171  FilePart* createPart(const std::string & inputContent, const std::string & outputPartPath);
172 
176  const FilePart* findPart(const std::string & outputPartPath) const;
177 
181  bool fileExists(const std::string & filename) const;
182 
186  std::string extractFile(const std::string & filename, const std::string & password = "");
187 
188  void writePackage();
189  };
190 }
191 
192 #endif
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
void setPrincipalRelationship(const FileRelationship &pkgFileRS)
set the Relationships file.
Definition: Package.cpp:442
const FilePart * findPart(const std::string &outputPartPath) const
Find a part corresponding to the given path.
Definition: Package.cpp:460
const FileCoreProperties & getFileCoreProperties() const
Definition: Package.cpp:339
void openForWriting(const std::string &pkgPathName, bool useZip64=false)
Definition: Package.cpp:215
bool fileExists(const std::string &filename) const
Definition: Package.cpp:660
~Package()
Definition: Package.cpp:210
void close()
Definition: Package.cpp:334
Definition: ContentType.h:28
Package()
Definition: Package.cpp:200
Definition: FileRelationship.h:31
Definition: FileCoreProperties.h:29
void addProperty(const CoreProperty::TypeProperty &pkgTypeProperty, const std::string &pkgPropertyValue)
add a Property in the CoreProperties file of package.
Definition: Package.cpp:378
Definition: FilePart.h:30
const std::string & getPathname() const
Definition: Package.cpp:359
const FileContentType & getFileContentType() const
Definition: Package.cpp:344
std::vector< std::string > openForReading(const std::string &pkgPathName)
Definition: Package.cpp:241
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:452
std::string extractFile(const std::string &filename, const std::string &password="")
Definition: Package.cpp:668
TypeProperty
Definition: CoreProperty.h:36
Definition: ContentType.h:26
Definition: Package.h:41
Definition: FileContentType.h:36
const FileRelationship & getPrincipalRelationship() const
Definition: Package.cpp:349
void setFileContentType(const FileContentType &pkgFileCT)
set the ContentTypes file.
Definition: Package.cpp:432
void addContentType(const ContentType &contentType)
add a ContentType in the ContentTypes file of package.
Definition: Package.cpp:437
Definition: Relationship.h:32
const PartMap & getAllFilePart() const
Definition: Package.cpp:354
void addRelationship(const Relationship &relationship)
add a Relationship in the Relationships file of package.
Definition: Package.cpp:447
std::tr1::unordered_map< std::string, std::string > & getExtendedCoreProperty()
Definition: Package.cpp:372
Definition: Package.cpp:137
void setFileFileCoreProperties(const FileCoreProperties &pkgFileCP)
set the CoreProperties file.
Definition: Package.cpp:364