summaryrefslogtreecommitdiff
path: root/ACE/ace/XML_Utils/XML_Schema_Resolver.h
blob: 9ad59f422a3fb94443b63851591264e943f942ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * @file XML_Schema_Resolver.h
 * @author Will Otte <wotte@dre.vanderbilt.edu>
 *
 * Resolves schema locations.
 */

#ifndef ACE_XML_SCHEMA_RESOLVER_H
#define ACE_XML_SCHEMA_RESOLVER_H
#include /**/ "ace/pre.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "XML_Utils_Export.h"
#include "XercesString.h"

#include <xercesc/sax/EntityResolver.hpp>
#include <vector>
#include <string>

using namespace xercesc;

namespace XML
{
  // forward decl.
  struct NoOp_Resolver;

  /**
    * @class XML_Schema_Resolver
    * @brief Resolves schema locations
    *
    * Template argument Resolver should be a functor with an operation
    * const ACE_TCHAR * operator () (...arguments from resolveEntity...)
    */
  template <typename Resolver = NoOp_Resolver>
  class XML_Schema_Resolver
    : public virtual EntityResolver
  {
  public:
    XML_Schema_Resolver (void);

    XML_Schema_Resolver (Resolver &resolver);

    /// This function is called by the Xerces infrastructure to
    /// actually resolve the location of a schema.
    virtual InputSource * resolveEntity (const XMLCh *const publicId,
                                         const XMLCh *const systemId);

    Resolver &get_resolver (void);

  private:
    XML_Schema_Resolver (XML_Schema_Resolver<Resolver> &);

    Resolver resolver_;
  };

  /**
    * @class NoOp_Resolver
    * @brief Resolver that does nothing.
    */
  struct NoOp_Resolver
  {
    const XMLCh* operator() (const XMLCh *const,
                              const XMLCh *const systemId) const
    { return systemId; };
  };

  /**
    * @class Basic_Resolver
    * @brief Resolves a schema location from a fixed path.
    */
  struct Basic_Resolver
  {
    Basic_Resolver (const ACE_TCHAR *path);

    XMLCh* operator() (const XMLCh *const publicId,
                        const XMLCh *const systemId) const;
    XStr path_;
  };

  /**
    * @class Environment_Resolver
    * @brief Resolves a schema location from a path from an environment variable.
    */
  struct XML_Utils_Export Environment_Resolver
  {
    Environment_Resolver (void);

    Environment_Resolver (const ACE_TCHAR *variable,
                          const ACE_TCHAR *path);

    void add_path (const ACE_TCHAR *variable,
                    const ACE_TCHAR *path);

    XMLCh* operator() (const XMLCh *const publicId,
                        const XMLCh *const systemId) const;

    std::vector<XStr> paths_;
  };
}

#include "XML_Schema_Resolver.tpp"

#include /**/ "ace/post.h"

#endif /*  ACE_XML_SCHEMA_RESOLVER_H */