2 * Copyright 2001-2007 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 {
33 * Resolves local filenames into absolute pathnames.
35 class XMLTOOL_API PathResolver
37 MAKE_NONCOPYABLE(PathResolver);
39 PathResolver() : m_defaultPackage("xmltooling"), m_defaultPrefix("/usr") {}
41 virtual ~PathResolver() {}
43 /** Types of file resources to resolve. */
53 * Set the default package to use when resolving files.
55 * @param pkgname name of default package to use
57 virtual void setDefaultPackageName(const char* pkgname) {
58 m_defaultPackage = pkgname;
62 * Set the default istallation prefix to use when resolving files.
64 * @param prefix name of default prefix to use
66 virtual void setDefaultPrefix(const char* prefix) {
67 m_defaultPrefix = prefix;
71 * Changes the input filename into an absolute pathname to the same file.
73 * @param s filename to resolve
74 * @param filetype type of file being resolved
75 * @param pkgname application package name to use in resolving the file (or NULL for the default)
76 * @param prefix installation prefix to use in resolving the file (or NULL for the default)
78 * @return a const reference to the input string
80 virtual const std::string& resolve(std::string& s, file_type_t filetype, const char* pkgname=NULL, const char* prefix=NULL) const;
83 bool isAbsolute(const char* s) const {
89 return (*(s+1) == '.' || *(s+1) == '/' || *(s+1) == '\\');
94 std::string m_defaultPackage,m_defaultPrefix;
98 #endif /* __xmltooling_pathres_h__ */