Add cache file type to path resolver
[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             XMLTOOLING_CACHE_FILE
53         };
54
55         /**
56          * Set the default package to use when resolving files.
57          *
58          * @param pkgname name of default package to use
59          */
60         virtual void setDefaultPackageName(const char* pkgname);
61
62         /**
63          * Set the default installation prefix to use when resolving files.
64          *
65          * @param prefix name of default prefix to use
66          */
67         virtual void setDefaultPrefix(const char* prefix);
68
69         /**
70          * Set the lib directory to use when resolving files.
71          * <p>If relative, the default prefix will be prepended.
72          *
73          * @param dir    the library directory to use
74          */
75         virtual void setLibDir(const char* dir);
76
77         /**
78          * Set the log directory to use when resolving files.
79          * <p>If relative, the default prefix will be prepended.
80          *
81          * @param dir    the log directory to use
82          */
83         virtual void setLogDir(const char* dir);
84
85         /**
86          * Set the XML directory to use when resolving files.
87          * <p>If relative, the default prefix will be prepended.
88          *
89          * @param dir    the XML directory to use
90          */
91         virtual void setXMLDir(const char* dir);
92
93         /**
94          * Set the run directory to use when resolving files.
95          * <p>If relative, the default prefix will be prepended.
96          *
97          * @param dir    the run directory to use
98          */
99         virtual void setRunDir(const char* dir);
100
101         /**
102          * Set the config directory to use when resolving files.
103          * <p>If relative, the default prefix will be prepended.
104          *
105          * @param dir    the config directory to use
106          */
107         virtual void setCfgDir(const char* dir);
108
109         /**
110          * Set the cache directory to use when resolving files.
111          * <p>If relative, the default prefix will be prepended.
112          *
113          * @param dir    the cache directory to use
114          */
115         virtual void setCacheDir(const char* dir);
116
117         /**
118          * Changes the input filename into an absolute pathname to the same file.
119          *
120          * @param s         filename to resolve
121          * @param filetype  type of file being resolved
122          * @param pkgname   application package name to use in resolving the file (or nullptr for the default)
123          * @param prefix    installation prefix to use in resolving the file (or nullptr for the default)
124          *
125          * @return a const reference to the input string
126          */
127         virtual const std::string& resolve(std::string& s, file_type_t filetype, const char* pkgname=nullptr, const char* prefix=nullptr) const;
128
129     private:
130         bool isAbsolute(const char* s) const;
131
132         std::string m_defaultPackage,m_defaultPrefix,m_lib,m_log,m_xml,m_run,m_cfg,m_cache;
133     };
134 };
135
136 #endif /* __xmltooling_pathres_h__ */