summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Interpreter.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-04-14 21:22:24 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-04-14 21:22:24 (GMT)
commit1c10bc4bf19c5ce73e3e10380e613da8bf93a1b0 (patch)
treed2f89e5c4564ef7e363f17eaee3800650a5ab4bd /src/uscxml/Interpreter.cpp
parent631b88e42c3fb7e10dee390d170854e40c31fac0 (diff)
downloaduscxml-1c10bc4bf19c5ce73e3e10380e613da8bf93a1b0.zip
uscxml-1c10bc4bf19c5ce73e3e10380e613da8bf93a1b0.tar.gz
uscxml-1c10bc4bf19c5ce73e3e10380e613da8bf93a1b0.tar.bz2
Refactored URLs and fixed Windows URL handling
Diffstat (limited to 'src/uscxml/Interpreter.cpp')
-rw-r--r--src/uscxml/Interpreter.cpp47
1 files changed, 9 insertions, 38 deletions
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index 0f98dc9..c951999 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -100,7 +100,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) {
if (boost::iequals(absUrl.scheme(), "file")) {
Arabica::SAX::InputSource<std::string> inputSource;
- inputSource.setSystemId(absUrl.path());
+ inputSource.setSystemId(absUrl.asString());
interpreter = fromInputSource(inputSource);
} else if (boost::iequals(absUrl.scheme(), "http")) {
// handle http per arabica
@@ -119,8 +119,11 @@ Interpreter Interpreter::fromURI(const std::string& uri) {
}
// try to establish URI root for relative src attributes in document
- if (interpreter)
- interpreter._impl->_baseURI = InterpreterImpl::toBaseURI(absUrl);
+ if (interpreter) {
+ interpreter._impl->_baseURI = URL::asBaseURL(absUrl);
+ } else {
+ LOG(ERROR) << "Cannot create interpreter from URI '" << absUrl.asString() << "'";
+ }
return interpreter;
}
@@ -186,38 +189,6 @@ void InterpreterImpl::setName(const std::string& name) {
}
}
-URL InterpreterImpl::toBaseURI(const URL& uri) {
- std::stringstream ssBaseURI;
- if (uri.scheme().size() > 0) {
- ssBaseURI << uri.scheme() << "://";
- } else {
- ssBaseURI << "file://";
- }
- if (uri.host().size() > 0) {
- ssBaseURI << uri.host();
- if (!boost::iequals(uri.port(), "0"))
- ssBaseURI << ":" << uri.port();
- }
- if (uri.path().size() > 0) {
- std::string uriPath = uri.path();
- uriPath = uriPath.substr(0, uriPath.find_last_of("/\\") + 1);
- ssBaseURI << uriPath;
- }
- return URL(ssBaseURI.str());
-}
-
-bool InterpreterImpl::toAbsoluteURI(URL& uri) {
- if (uri.isAbsolute())
- return true;
-
- if (_baseURI.asString().size() > 0) {
- if (uri.toAbsolute(_baseURI))
- return true;
- return false;
- }
- return false;
-}
-
InterpreterImpl::~InterpreterImpl() {
tthread::lock_guard<tthread::recursive_mutex> lock(_mutex);
if (_thread) {
@@ -481,7 +452,7 @@ void InterpreterImpl::processDOMorText(const Arabica::DOM::Node<std::string>& no
(HAS_ATTR(node, "srcexpr") && _dataModel)) {
std::stringstream srcContent;
URL sourceURL(HAS_ATTR(node, "srcexpr") ? _dataModel.evalAsString(ATTR(node, "srcexpr")) : ATTR(node, "src"));
- if (!toAbsoluteURI(sourceURL)) {
+ if (!sourceURL.toAbsolute(_baseURI)) {
LOG(ERROR) << LOCALNAME(node) << " element has relative src or srcexpr URI with no baseURI set.";
return;
}
@@ -785,7 +756,7 @@ void InterpreterImpl::invoke(const Arabica::DOM::Node<std::string>& element) {
}
if (source.length() > 0) {
URL srcURI(source);
- if (!toAbsoluteURI(srcURI)) {
+ if (!srcURI.toAbsolute(_baseURI)) {
LOG(ERROR) << "invoke element has relative src URI with no baseURI set.";
return;
}
@@ -1131,7 +1102,7 @@ void InterpreterImpl::executeContent(const Arabica::DOM::Node<std::string>& cont
if (_dataModel) {
if (HAS_ATTR(content, "src")) {
URL scriptUrl(ATTR(content, "src"));
- if (!toAbsoluteURI(scriptUrl)) {
+ if (!scriptUrl.toAbsolute(_baseURI)) {
LOG(ERROR) << "script element has relative URI " << ATTR(content, "src") << " with no base URI set for interpreter";
return;
}