bioformats  5.1.3
EntityResolver.h
1 /*
2  * #%L
3  * OME-XERCES C++ library for working with Xerces C++.
4  * %%
5  * Copyright © 2006 - 2015 Open Microscopy Environment:
6  * - Massachusetts Institute of Technology
7  * - National Institutes of Health
8  * - University of Dundee
9  * - Board of Regents of the University of Wisconsin-Madison
10  * - Glencoe Software, Inc.
11  * %%
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  * this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * The views and conclusions contained in the software and documentation are
34  * those of the authors and should not be interpreted as representing official
35  * policies, either expressed or implied, of any organization.
36  * #L%
37  */
38 
39 #ifndef OME_COMMON_XML_ENTITYRESOLVER_H
40 #define OME_COMMON_XML_ENTITYRESOLVER_H
41 
42 #include <map>
43 #include <string>
44 
45 #include <ome/common/filesystem.h>
46 #include <ome/compat/memory.h>
47 
48 #include <xercesc/util/XMLEntityResolver.hpp>
49 
50 namespace ome
51 {
52  namespace common
53  {
54  namespace xml
55  {
56 
64  class EntityResolver : public xercesc::XMLEntityResolver
65  {
66  public:
69 
72 
80  xercesc::InputSource *
81  resolveEntity(xercesc::XMLResourceIdentifier* resource);
82 
83  private:
85  typedef std::pair<boost::filesystem::path, std::string> entity_cache;
87  typedef std::map<std::string, entity_cache> entity_map_type;
88 
98  xercesc::InputSource *
99  getSource(const std::string& resource);
100 
106  static
107  entity_map_type&
108  entities();
109 
114  {
115  public:
122  AutoRegisterEntity(const std::string& id,
123  const std::string& data);
124 
131  AutoRegisterEntity(const std::string& id,
132  const boost::filesystem::path& file);
133 
140 
141  private:
144 
148 
150  std::string id;
151  };
152 
157  {
158  public:
168  AutoRegisterCatalog(const boost::filesystem::path& catalog);
169 
176 
177  private:
180 
184 
186  std::vector<ome::compat::shared_ptr<AutoRegisterEntity> > registration;
187  };
188 
189  public:
194  {
195  public:
202  RegisterEntity(const std::string& id,
203  const std::string& data);
204 
211  RegisterEntity(const std::string& id,
212  const boost::filesystem::path& file);
213 
215  ~RegisterEntity();
216 
217  private:
219  ome::compat::shared_ptr<AutoRegisterEntity> registration;
220  };
221 
226  {
227  public:
237  RegisterCatalog(const boost::filesystem::path& catalog);
238 
241 
242  private:
244  ome::compat::shared_ptr<AutoRegisterCatalog> registration;
245  };
246 
247  friend class RegisterEntity;
248  friend class RegisterCatalog;
249  };
250 
251  }
252  }
253 }
254 
255 #endif // OME_COMMON_XML_ENTITYRESOLVER_H
256 
257 /*
258  * Local Variables:
259  * mode:C++
260  * End:
261  */
262 
Memory type substitution.
~AutoRegisterEntity()
Destructor.
Definition: EntityResolver.cpp:166
AutoRegisterCatalog(const boost::filesystem::path &catalog)
Register a catalog file with the entity resolver.
Definition: EntityResolver.cpp:171
Register an entity with the entity resolver.
Definition: EntityResolver.h:193
Automatically register and unregister an XML catalog with the entity resolver.
Definition: EntityResolver.h:156
xercesc::InputSource * resolveEntity(xercesc::XMLResourceIdentifier *resource)
Resolve an entity.
Definition: EntityResolver.cpp:74
std::map< std::string, entity_cache > entity_map_type
Entity mapping type.
Definition: EntityResolver.h:87
ome::compat::shared_ptr< AutoRegisterEntity > registration
Automatic registration.
Definition: EntityResolver.h:219
AutoRegisterEntity(const std::string &id, const std::string &data)
Register in-memory text data with the entity resolver.
Xerces entity resolver.
Definition: EntityResolver.h:64
~RegisterEntity()
Destructor.
Definition: EntityResolver.cpp:266
EntityResolver()
Constructor.
Definition: EntityResolver.cpp:64
xercesc::InputSource * getSource(const std::string &resource)
Get input source from file.
Definition: EntityResolver.cpp:102
static entity_map_type & entities()
Get entity mappings.
Definition: EntityResolver.cpp:153
Boost.Filesystem compatibility.
~RegisterCatalog()
Destructor.
Definition: EntityResolver.cpp:256
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
Register an XML catalog with the entity resolver.
Definition: EntityResolver.h:225
ome::compat::shared_ptr< AutoRegisterCatalog > registration
Automatic registration.
Definition: EntityResolver.h:244
std::vector< ome::compat::shared_ptr< AutoRegisterEntity > > registration
Registered entities from this catalog.
Definition: EntityResolver.h:186
RegisterCatalog(const boost::filesystem::path &catalog)
Register a catalog file with the entity resolver.
Definition: EntityResolver.cpp:251
std::string id
XML system ID.
Definition: EntityResolver.h:150
std::pair< boost::filesystem::path, std::string > entity_cache
Cached entity (path and content).
Definition: EntityResolver.h:85
Automatically register and unregister an entity with the entity resolver.
Definition: EntityResolver.h:113
~AutoRegisterCatalog()
Destructor.
Definition: EntityResolver.cpp:247
AutoRegisterEntity & operator=(const AutoRegisterEntity &)
Assignment operator (deleted).
AutoRegisterCatalog & operator=(const AutoRegisterCatalog &)
Assignment operator (deleted).
~EntityResolver()
Destructor.
Definition: EntityResolver.cpp:69
Xerces-C modern C++ wrapper.
Definition: Base.h:53
RegisterEntity(const std::string &id, const std::string &data)
Register in-memory text data with the entity resolver.