summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-01-04 21:51:43 +0000
committerrandomdan <randomdan@localhost>2013-01-04 21:51:43 +0000
commit328c6ef1b6ce90b7330a51f2492460d3646b81cf (patch)
treed022eb571f940a4b65b6276188fc5b1ab0b55244
parentAdd missing include required for older versions of Boost (diff)
downloadproject2-328c6ef1b6ce90b7330a51f2492460d3646b81cf.tar.bz2
project2-328c6ef1b6ce90b7330a51f2492460d3646b81cf.tar.xz
project2-328c6ef1b6ce90b7330a51f2492460d3646b81cf.zip
Use media-type for content type of XSL transformed documents
Allow setting up a default transformation chain with default presenters Remove mod_transform requirement from sites
-rw-r--r--project2/cgi/cgiEnvironment.cpp4
-rw-r--r--project2/cgi/cgiEnvironment.h2
-rw-r--r--project2/cgi/cgiStagePresent.cpp11
-rw-r--r--project2/xml/transformHtml.cpp6
-rw-r--r--project2/xml/transformHtml.h2
5 files changed, 20 insertions, 5 deletions
diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp
index 7bb68d2..439f6d8 100644
--- a/project2/cgi/cgiEnvironment.cpp
+++ b/project2/cgi/cgiEnvironment.cpp
@@ -34,6 +34,10 @@ CgiEnvironment::CgiEnvironment() :
cgiOptions
("cgi.defaultPresenter", Options::value(&defaultPresenter, "xml"),
"The default engine for formatting presentations")
+ ("cgi.transformContentType", Options::value(&transformContentType, "text/xml-xslt"),
+ "The content type specified to enable standard internal transformations")
+ ("cgi.transformTargetType", Options::value(&transformTargetType, "htmldocument"),
+ "The transform target type used in standard internal transformations")
("cgi.defaultPresent", Options::value(&defaultPresent, "index"),
"The present script to use when no other is specified")
("cgi.presentRoot", Options::value(&presentRoot, "present"),
diff --git a/project2/cgi/cgiEnvironment.h b/project2/cgi/cgiEnvironment.h
index cfe9c7b..6797a24 100644
--- a/project2/cgi/cgiEnvironment.h
+++ b/project2/cgi/cgiEnvironment.h
@@ -60,6 +60,8 @@ class CgiEnvironment : public Environment {
Glib::ustring errorContentType;
Glib::ustring errorTransformStyle;
std::string defaultPresent;
+ std::string transformContentType;
+ std::string transformTargetType;
std::string presentRoot;
std::string requestRoot;
std::string errorPresentRoot;
diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp
index 8e4a6ff..c66f409 100644
--- a/project2/cgi/cgiStagePresent.cpp
+++ b/project2/cgi/cgiStagePresent.cpp
@@ -11,7 +11,16 @@ CgiApplicationEngine::PresentStage::PresentStage(ScriptReaderPtr s) :
CommonObjects(s->root()),
CheckHost(s->root()),
ViewHost(s->root()),
- presenter([root,this] { return PresenterLoader::getFor(this->env()->defaultPresenter)->create(root, Default); })
+ presenter([root,this] {
+ auto p = PresenterLoader::getFor(this->env()->defaultPresenter)->create(root, Default);
+ auto xp = dynamic_cast<TransformSource *>(p);
+ auto cp = dynamic_cast<ContentPresenter *>(p);
+ if (xp && cp && cp->contentType == this->env()->transformContentType) {
+ auto h = TransformTargetLoader::getFor(this->env()->transformTargetType)->create(root, Default);
+ xp->addTarget(h, root);
+ }
+ return p;
+ })
{
s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsLoader>(&outputOptions));
s->loader.addLoadTarget(s->root(), Storer::into<PresenterLoader>(&presenter, Scripted));
diff --git a/project2/xml/transformHtml.cpp b/project2/xml/transformHtml.cpp
index 1070ada..bbc6549 100644
--- a/project2/xml/transformHtml.cpp
+++ b/project2/xml/transformHtml.cpp
@@ -8,8 +8,7 @@ HtmlDocument::HtmlDocument(ScriptNodePtr s, ObjectSource os) :
TransformSource(s, os),
SourceOf<HtmlDocument>(s, os),
SourceOf<WritableContent>(s, os),
- doc(NULL),
- contentType(s, "contenttype", "text/html")
+ doc(NULL)
{
}
@@ -45,7 +44,7 @@ HtmlDocument::writeTo(std::ostream & o, const std::string & encoding) const
Glib::ustring
HtmlDocument::getContentType() const
{
- return contentType();
+ return contentType;
}
WritableContent::Class
@@ -71,6 +70,7 @@ class TransformXmlToHtml : public TransformImpl<xmlpp::Document, HtmlDocument> {
if (!result->doc) {
throw xmlpp::exception("Failed to perform transformation");
}
+ result->contentType = (char*)(cur.get()->mediaType);
}
void configure(ScriptNodePtr e)
{
diff --git a/project2/xml/transformHtml.h b/project2/xml/transformHtml.h
index 7273bb0..0a6c432 100644
--- a/project2/xml/transformHtml.h
+++ b/project2/xml/transformHtml.h
@@ -14,7 +14,7 @@ class HtmlDocument : public SourceOf<HtmlDocument>, public WritableContent, publ
Class getContentClass() const;
Glib::ustring getContentType() const;
void writeTo(std::ostream &, const std::string & encoding) const;
- Variable contentType;
+ Glib::ustring contentType;
};
#endif