util/DateTime.h \
util/NDC.h \
util/ParserPool.h \
+ util/PathResolver.h \
util/Predicates.h \
util/ReloadableXMLFile.h \
util/ReplayCache.h \
util/DateTime.cpp \
util/NDC.cpp \
util/ParserPool.cpp \
+ util/PathResolver.cpp \
util/ReloadableXMLFile.cpp \
util/TemplateEngine.cpp \
util/URLEncoder.cpp \
#include "soap/SOAP.h"
#include "soap/SOAPTransport.h"
#include "util/NDC.h"
+#include "util/PathResolver.h"
#include "util/ReplayCache.h"
#include "util/StorageService.h"
#include "util/TemplateEngine.h"
}
#endif
+void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
+{
+ delete m_pathResolver;
+ m_pathResolver = pathResolver;
+}
+
void XMLToolingConfig::setTemplateEngine(TemplateEngine* templateEngine)
{
delete m_templateEngine;
m_keyInfoResolver = KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,NULL);
#endif
+ m_pathResolver = new PathResolver();
m_urlEncoder = new URLEncoder();
// Register xml:id as an ID attribute.
m_replayCache = NULL;
#endif
+ delete m_pathResolver;
+ m_pathResolver = NULL;
+
delete m_templateEngine;
m_templateEngine = NULL;
namespace xmltooling {
+ class XMLTOOL_API PathResolver;
class XMLTOOL_API TemplateEngine;
class XMLTOOL_API URLEncoder;
#ifndef XMLTOOLING_LITE
MAKE_NONCOPYABLE(XMLToolingConfig);
protected:
#ifndef XMLTOOLING_NO_XMLSEC
- XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
+ XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL),
+ m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
/** Global KeyInfoResolver instance. */
KeyInfoResolver* m_keyInfoResolver;
/** Global ReplayCache instance. */
ReplayCache* m_replayCache;
#else
- XMLToolingConfig() : m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
+ XMLToolingConfig() : m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
#endif
+ /** Global PathResolver instance. */
+ PathResolver* m_pathResolver;
+
/** Global TemplateEngine instance. */
TemplateEngine* m_templateEngine;
TemplateEngine* getTemplateEngine() const {
return m_templateEngine;
}
-
+
+ /**
+ * Sets the global PathResolver instance.
+ * This method must be externally synchronized with any code that uses the object.
+ * Any previously set object is destroyed.
+ *
+ * @param pathResolver new PathResolver instance to store
+ */
+ void setPathResolver(PathResolver* pathResolver);
+
+ /**
+ * Returns the global PathResolver instance.
+ *
+ * @return global PathResolver or NULL
+ */
+ PathResolver* getPathResolver() const {
+ return m_pathResolver;
+ }
+
/**
* List of catalog files to load into validating parser pool at initialization time.
* Like other path settings, the separator depends on the platform
--- /dev/null
+/*
+ * Copyright 2001-2007 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * PathResolver.cpp
+ *
+ * Resolves local filenames into absolute pathnames.
+ */
+
+#include "internal.h"
+#include "exceptions.h"
+#include "util/PathResolver.h"
+
+using namespace xmltooling;
+using namespace std;
+
+const string& PathResolver::resolve(string& s, file_type_t filetype, const char* pkgname, const char* prefix) const
+{
+#ifdef WIN32
+ static const char sep = '\\';
+#else
+ static const char sep = '/';
+#endif
+ if (!isAbsolute(s.c_str())) {
+ switch (filetype) {
+ case XMLTOOLING_LIB_FILE:
+ s = string(prefix ? prefix : m_defaultPrefix) + sep + "lib" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ break;
+
+ case XMLTOOLING_LOG_FILE:
+ if (prefix || m_defaultPrefix != "/usr")
+ s = string(prefix ? prefix : m_defaultPrefix) + sep + "var" + sep + "log" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ else
+ s = string(sep,1) + "var" + sep + "log" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ break;
+
+ case XMLTOOLING_XML_FILE:
+ s = string(prefix ? prefix : m_defaultPrefix) + sep + "share" + sep + "xml" + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ break;
+
+ case XMLTOOLING_RUN_FILE:
+ if (prefix || m_defaultPrefix != "/usr")
+ s = string(prefix ? prefix : m_defaultPrefix) + sep + "var" + sep + "run" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ else
+ s = string(sep,1) + "var" + sep + "run" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ break;
+
+ case XMLTOOLING_CFG_FILE:
+ if (prefix || m_defaultPrefix != "/usr")
+ s = string(prefix ? prefix : m_defaultPrefix) + sep + "etc" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ else
+ s = string(sep,1) + "etc" + sep + (pkgname ? pkgname : m_defaultPackage) + sep + s;
+ break;
+
+ default:
+ throw XMLToolingException("Unknown file type to resolve.");
+ }
+ }
+ return s;
+}
--- /dev/null
+/*
+ * Copyright 2001-2007 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file xmltooling/util/PathResolver.h
+ *
+ * Resolves local filenames into absolute pathnames.
+ */
+
+#if !defined(__xmltooling_pathres_h__)
+#define __xmltooling_pathres_h__
+
+#include <xmltooling/base.h>
+
+#include <string>
+
+namespace xmltooling {
+
+ /**
+ * Resolves local filenames into absolute pathnames.
+ */
+ class XMLTOOL_API PathResolver
+ {
+ MAKE_NONCOPYABLE(PathResolver);
+ public:
+ PathResolver() {}
+
+ virtual ~PathResolver() {}
+
+ /** Types of file resources to resolve. */
+ enum file_type_t {
+ XMLTOOLING_LIB_FILE,
+ XMLTOOLING_LOG_FILE,
+ XMLTOOLING_XML_FILE,
+ XMLTOOLING_RUN_FILE,
+ XMLTOOLING_CFG_FILE
+ };
+
+ /**
+ * Set the default package to use when resolving files.
+ *
+ * @param pkgname name of default package to use
+ */
+ virtual void setDefaultPackageName(const char* pkgname) {
+ m_defaultPackage = pkgname;
+ }
+
+ /**
+ * Set the default istallation prefix to use when resolving files.
+ *
+ * @param prefix name of default prefix to use
+ */
+ virtual void setDefaultPrefix(const char* prefix) {
+ m_defaultPrefix = prefix;
+ }
+
+ /**
+ * Changes the input filename into an absolute pathname to the same file.
+ *
+ * @param s filename to resolve
+ * @param filetype type of file being resolved
+ * @param pkgname application package name to use in resolving the file (or NULL for the default)
+ * @param prefix installation prefix to use in resolving the file (or NULL for the default)
+ *
+ * @return a const reference to the input string
+ */
+ virtual const std::string& resolve(std::string& s, file_type_t filetype, const char* pkgname=NULL, const char* prefix=NULL) const;
+
+ private:
+ bool isAbsolute(const char* s) const {
+ return (*s == '/' || *s == '\\' || *(s+1) == ':');
+ }
+
+ std::string m_defaultPackage,m_defaultPrefix;
+ };
+};
+
+#endif /* __xmltooling_pathres_h__ */
>\r
</File>\r
<File\r
+ RelativePath=".\util\PathResolver.cpp"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\ReloadableXMLFile.cpp"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\util\PathResolver.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\Predicates.h"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\util\PathResolver.cpp"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\ReloadableXMLFile.cpp"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\util\PathResolver.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\Predicates.h"\r
>\r
</File>\r