a19cc89dbff0b944fb949c4f500cabdc62092c75
[shibboleth/cpp-xmltooling.git] / xmltooling / util / PathResolver.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/util/PathResolver.h
19  *
20  * Resolves local filenames into absolute pathnames.
21  */
22
23 #if !defined(__xmltooling_pathres_h__)
24 #define __xmltooling_pathres_h__
25
26 #include <xmltooling/base.h>
27
28 #include <string>
29
30 namespace xmltooling {
31     /**
32      * Resolves local filenames into absolute pathnames.
33      */
34     class XMLTOOL_API PathResolver
35     {
36         MAKE_NONCOPYABLE(PathResolver);
37     public:
38         PathResolver();
39         virtual ~PathResolver();
40
41         /** Types of file resources to resolve. */
42         enum file_type_t {
43             XMLTOOLING_LIB_FILE,
44             XMLTOOLING_LOG_FILE,
45             XMLTOOLING_XML_FILE,
46             XMLTOOLING_RUN_FILE,
47             XMLTOOLING_CFG_FILE
48         };
49
50         /**
51          * Set the default package to use when resolving files.
52          *
53          * @param pkgname name of default package to use
54          */
55         virtual void setDefaultPackageName(const char* pkgname);
56
57         /**
58          * Set the default installation prefix to use when resolving files.
59          *
60          * @param prefix name of default prefix to use
61          */
62         virtual void setDefaultPrefix(const char* prefix);
63
64         /**
65          * Set the lib directory to use when resolving files.
66          * <p>If relative, the default prefix will be prepended.
67          *
68          * @param dir    the library directory to use
69          */
70         virtual void setLibDir(const char* dir);
71
72         /**
73          * Set the log directory to use when resolving files.
74          * <p>If relative, the default prefix will be prepended.
75          *
76          * @param dir    the log directory to use
77          */
78         virtual void setLogDir(const char* dir);
79
80         /**
81          * Set the XML directory to use when resolving files.
82          * <p>If relative, the default prefix will be prepended.
83          *
84          * @param dir    the XML directory to use
85          */
86         virtual void setXMLDir(const char* dir);
87
88         /**
89          * Set the run directory to use when resolving files.
90          * <p>If relative, the default prefix will be prepended.
91          *
92          * @param dir    the run directory to use
93          */
94         virtual void setRunDir(const char* dir);
95
96         /**
97          * Set the config directory to use when resolving files.
98          * <p>If relative, the default prefix will be prepended.
99          *
100          * @param dir    the config directory to use
101          */
102         virtual void setCfgDir(const char* dir);
103
104         /**
105          * Changes the input filename into an absolute pathname to the same file.
106          *
107          * @param s         filename to resolve
108          * @param filetype  type of file being resolved
109          * @param pkgname   application package name to use in resolving the file (or nullptr for the default)
110          * @param prefix    installation prefix to use in resolving the file (or nullptr for the default)
111          *
112          * @return a const reference to the input string
113          */
114         virtual const std::string& resolve(std::string& s, file_type_t filetype, const char* pkgname=nullptr, const char* prefix=nullptr) const;
115
116     private:
117         bool isAbsolute(const char* s) const;
118
119         std::string m_defaultPackage,m_defaultPrefix,m_lib,m_log,m_xml,m_run,m_cfg;
120     };
121 };
122
123 #endif /* __xmltooling_pathres_h__ */