summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/element/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/plugins/element/fetch')
-rw-r--r--src/uscxml/plugins/element/fetch/FetchElement.cpp134
-rw-r--r--src/uscxml/plugins/element/fetch/FetchElement.h20
2 files changed, 77 insertions, 77 deletions
diff --git a/src/uscxml/plugins/element/fetch/FetchElement.cpp b/src/uscxml/plugins/element/fetch/FetchElement.cpp
index 33cb76e..eabe0a2 100644
--- a/src/uscxml/plugins/element/fetch/FetchElement.cpp
+++ b/src/uscxml/plugins/element/fetch/FetchElement.cpp
@@ -19,90 +19,90 @@ bool connect(pluma::Host& host) {
#endif
boost::shared_ptr<ExecutableContentImpl> FetchElement::create(Interpreter* interpreter) {
- boost::shared_ptr<FetchElement> invoker = boost::shared_ptr<FetchElement>(new FetchElement());
+ boost::shared_ptr<FetchElement> invoker = boost::shared_ptr<FetchElement>(new FetchElement());
invoker->_interpreter = interpreter;
return invoker;
}
FetchElement::~FetchElement() {
- URLFetcher::breakURL(_targetUrl);
+ URLFetcher::breakURL(_targetUrl);
}
-
+
void FetchElement::downloadCompleted(const URL& url) {
- Event event;
- event.name = _callback;
-
- std::string content = url.getInContent();
- std::map<std::string, std::string> headerFields = url.getInHeaderFields();
-
- if (false) {
- } else if (boost::iequals(_type, "text")) {
- event.data.atom = content;
- event.data.type = Data::VERBATIM;
- } else if (boost::iequals(_type, "url")) {
- } else if (boost::iequals(_type, "json")) {
- event.data = Data::fromJSON(content);
- } else if (boost::iequals(_type, "xml")) {
- event = Event::fromXML(content);
- }
-
- _interpreter->receive(event);
+ Event event;
+ event.name = _callback;
+
+ std::string content = url.getInContent();
+ std::map<std::string, std::string> headerFields = url.getInHeaderFields();
+
+ if (false) {
+ } else if (boost::iequals(_type, "text")) {
+ event.data.atom = content;
+ event.data.type = Data::VERBATIM;
+ } else if (boost::iequals(_type, "url")) {
+ } else if (boost::iequals(_type, "json")) {
+ event.data = Data::fromJSON(content);
+ } else if (boost::iequals(_type, "xml")) {
+ event = Event::fromXML(content);
+ }
+
+ _interpreter->receive(event);
}
-
+
void FetchElement::downloadFailed(const URL& url, int errorCode) {
- Event event;
- event.name = _callback + ".failed";
-
- _interpreter->receive(event);
+ Event event;
+ event.name = _callback + ".failed";
+
+ _interpreter->receive(event);
}
void FetchElement::enterElement(const Arabica::DOM::Node<std::string>& node) {
- if (!HAS_ATTR(node, "target") && !HAS_ATTR(node, "targetexpr")) {
- LOG(ERROR) << "Fetch element requires target or targetexpr";
- return;
- }
- if (HAS_ATTR(node, "targetexpr") && !_interpreter->getDataModel()) {
- LOG(ERROR) << "Fetch element with targetexpr requires datamodel";
- return;
- }
- _target = (HAS_ATTR(node, "target") ? ATTR(node, "target") : _interpreter->getDataModel().evalAsString(ATTR(node, "targetexpr")));
-
- if (!HAS_ATTR(node, "callback") && !HAS_ATTR(node, "callbackexpr")) {
- LOG(ERROR) << "Fetch element requires callback or callbackexpr";
- return;
- }
- if (HAS_ATTR(node, "callbackexpr") && !_interpreter->getDataModel()) {
- LOG(ERROR) << "Fetch element with callbackexpr requires datamodel";
- return;
- }
- _callback = (HAS_ATTR(node, "callback") ? ATTR(node, "callback") : _interpreter->getDataModel().evalAsString(ATTR(node, "callbackexpr")));
-
- _type = (HAS_ATTR(node, "type") ? ATTR(node, "type") : "text");
- if (!boost::iequals(_type, "text") &&
- !boost::iequals(_type, "url") &&
- !boost::iequals(_type, "json") &&
- !boost::iequals(_type, "xml")) {
- LOG(ERROR) << "Fetch element type attribute not one of text, url, json, xml.";
- return;
- }
-
- _targetUrl = URL(_target);
- if (!_targetUrl.isAbsolute()) {
- if (!_interpreter->toAbsoluteURI(_targetUrl)) {
- LOG(ERROR) << "Cannot transform " << _target << " into absolute URL";
- return;
- }
- }
-
- _targetUrl.addMonitor(this);
- URLFetcher::fetchURL(_targetUrl);
-
+ if (!HAS_ATTR(node, "target") && !HAS_ATTR(node, "targetexpr")) {
+ LOG(ERROR) << "Fetch element requires target or targetexpr";
+ return;
+ }
+ if (HAS_ATTR(node, "targetexpr") && !_interpreter->getDataModel()) {
+ LOG(ERROR) << "Fetch element with targetexpr requires datamodel";
+ return;
+ }
+ _target = (HAS_ATTR(node, "target") ? ATTR(node, "target") : _interpreter->getDataModel().evalAsString(ATTR(node, "targetexpr")));
+
+ if (!HAS_ATTR(node, "callback") && !HAS_ATTR(node, "callbackexpr")) {
+ LOG(ERROR) << "Fetch element requires callback or callbackexpr";
+ return;
+ }
+ if (HAS_ATTR(node, "callbackexpr") && !_interpreter->getDataModel()) {
+ LOG(ERROR) << "Fetch element with callbackexpr requires datamodel";
+ return;
+ }
+ _callback = (HAS_ATTR(node, "callback") ? ATTR(node, "callback") : _interpreter->getDataModel().evalAsString(ATTR(node, "callbackexpr")));
+
+ _type = (HAS_ATTR(node, "type") ? ATTR(node, "type") : "text");
+ if (!boost::iequals(_type, "text") &&
+ !boost::iequals(_type, "url") &&
+ !boost::iequals(_type, "json") &&
+ !boost::iequals(_type, "xml")) {
+ LOG(ERROR) << "Fetch element type attribute not one of text, url, json, xml.";
+ return;
+ }
+
+ _targetUrl = URL(_target);
+ if (!_targetUrl.isAbsolute()) {
+ if (!_interpreter->toAbsoluteURI(_targetUrl)) {
+ LOG(ERROR) << "Cannot transform " << _target << " into absolute URL";
+ return;
+ }
+ }
+
+ _targetUrl.addMonitor(this);
+ URLFetcher::fetchURL(_targetUrl);
+
}
void FetchElement::exitElement(const Arabica::DOM::Node<std::string>& node) {
-
+
}
} \ No newline at end of file
diff --git a/src/uscxml/plugins/element/fetch/FetchElement.h b/src/uscxml/plugins/element/fetch/FetchElement.h
index 0229048..aadbb7c 100644
--- a/src/uscxml/plugins/element/fetch/FetchElement.h
+++ b/src/uscxml/plugins/element/fetch/FetchElement.h
@@ -8,7 +8,7 @@
#endif
namespace uscxml {
-
+
class FetchElement : public ExecutableContentImpl, public URLMonitor {
public:
FetchElement() {}
@@ -22,23 +22,23 @@ public:
std::string getNamespace() {
return "http://www.w3.org/2005/07/scxml";
}
-
+
bool processChildren() {
return false;
}
-
+
void enterElement(const Arabica::DOM::Node<std::string>& node);
void exitElement(const Arabica::DOM::Node<std::string>& node);
- void downloadCompleted(const URL& url);
- void downloadFailed(const URL& url, int errorCode);
+ void downloadCompleted(const URL& url);
+ void downloadFailed(const URL& url, int errorCode);
protected:
- URL _targetUrl;
- std::string _target;
- std::string _callback;
- std::string _type;
+ URL _targetUrl;
+ std::string _target;
+ std::string _callback;
+ std::string _type;
};
-
+
#ifdef BUILD_AS_PLUGINS
PLUMA_INHERIT_PROVIDER(FetchElement, Element);
#endif