2 * Copyright 2001-2009 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/util/PathResolver.h
20 * Resolves local filenames into absolute pathnames.
23 #if !defined(__xmltooling_pathres_h__)
24 #define __xmltooling_pathres_h__
26 #include <xmltooling/base.h>
30 namespace xmltooling {
32 * Resolves local filenames into absolute pathnames.
34 class XMLTOOL_API PathResolver
36 MAKE_NONCOPYABLE(PathResolver);
39 virtual ~PathResolver() {}
41 /** Types of file resources to resolve. */
51 * Set the default package to use when resolving files.
53 * @param pkgname name of default package to use
55 virtual void setDefaultPackageName(const char* pkgname) {
56 m_defaultPackage = pkgname;
60 * Set the default installation prefix to use when resolving files.
62 * @param prefix name of default prefix to use
64 virtual void setDefaultPrefix(const char* prefix) {
65 m_defaultPrefix = prefix;
69 * Set the lib directory to use when resolving files.
70 * <p>If relative, the default prefix will be prepended.
72 * @param dir the library directory to use
74 virtual void setLibDir(const char* dir) {
79 * Set the log directory to use when resolving files.
80 * <p>If relative, the default prefix will be prepended.
82 * @param dir the log directory to use
84 virtual void setLogDir(const char* dir) {
89 * Set the XML directory to use when resolving files.
90 * <p>If relative, the default prefix will be prepended.
92 * @param dir the XML directory to use
94 virtual void setXMLDir(const char* dir) {
99 * Set the run directory to use when resolving files.
100 * <p>If relative, the default prefix will be prepended.
102 * @param dir the run directory to use
104 virtual void setRunDir(const char* dir) {
109 * Set the config directory to use when resolving files.
110 * <p>If relative, the default prefix will be prepended.
112 * @param dir the config directory to use
114 virtual void setCfgDir(const char* dir) {
119 * Changes the input filename into an absolute pathname to the same file.
121 * @param s filename to resolve
122 * @param filetype type of file being resolved
123 * @param pkgname application package name to use in resolving the file (or NULL for the default)
124 * @param prefix installation prefix to use in resolving the file (or NULL for the default)
126 * @return a const reference to the input string
128 virtual const std::string& resolve(std::string& s, file_type_t filetype, const char* pkgname=NULL, const char* prefix=NULL) const;
131 bool isAbsolute(const char* s) const {
137 return (*(s+1) == '.' || *(s+1) == '/' || *(s+1) == '\\');
139 return *(s+1) == ':';
142 std::string m_defaultPackage,m_defaultPrefix,m_lib,m_log,m_xml,m_run,m_cfg;
146 #endif /* __xmltooling_pathres_h__ */