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