summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2007-04-14 14:29:22 +0000
committerpixel <pixel>2007-04-14 14:29:22 +0000
commitbbdabec18228665d548557f1c78159486cffc54d (patch)
treeef3163e39cf75de86208b8a30e62392304a08137 /lib
parent215e6d6ef338cd3eb1c36c118be4ff01f87376f3 (diff)
Creation of the HtmlSkinner class.
Diffstat (limited to 'lib')
-rw-r--r--lib/Action.cc20
-rw-r--r--lib/HtmlSkinner.cc33
-rw-r--r--lib/HttpServ.cc15
3 files changed, 46 insertions, 22 deletions
diff --git a/lib/Action.cc b/lib/Action.cc
index 23f96d0..2fb0e2a 100644
--- a/lib/Action.cc
+++ b/lib/Action.cc
@@ -8,6 +8,7 @@
Action * Action::start = 0;
static int counter = 0;
+static HtmlSkinner default_skinner;
static String genurl(const String & u) {
if (u.strlen()) {
@@ -19,9 +20,12 @@ static String genurl(const String & u) {
}
}
-Action::Action(const String & u) : next(start), prev(0), URL(genurl(u)), hastoclean(false), accessed(false) {
+Action::Action(const String & u, HtmlSkinner * _skin) : next(start), prev(0), URL(genurl(u)), hastoclean(false), accessed(false), skin(_skin) {
start = this;
if (next) next->prev = this;
+ if (!skin) {
+ skin = &default_skinner;
+ }
}
Action::~Action() {
@@ -57,17 +61,15 @@ Action * Action::Look4URL(const String & URL) {
*/
void Action::SendHead(Handle * h) {
- (*h) << "<HTML><HEAD><TITLE>" << GetTitle() << "</TITLE>" << endnl <<
- "<META http-equiv=\"Content-Style-Type\" content=\"text/css\">" << endnl <<
- "<LINK REL=STYLESHEET HREF=\"/image/style.css\" TYPE=\"text/css\">" << endnl <<
- "</HEAD><BODY BGCOLOR=\"#aaaaaa\" BACKGROUND=\"/image/grain.png\">" << endnl <<
- "<center><TABLE WIDTH=\"50%\" BORDER=3 cellspacing=1 BGCOLOR=\"#ffffff\"><TR><TD>" << endnl <<
- "<center><b><h1>" << GetTitle() << "</h1></b></center></TD></TR></TABLE><P>" << endnl <<
- "<TABLE WIDTH=\"80%\" BORDER=2 cellspacing=1 BGCOLOR=\"#ffffff\"><TR><TD>" << endnl;
+ (*h) << skin->Header(GetTitle());
}
void Action::SendFoot(Handle * h) {
- (*h) << "</TABLE></TD></TR></BODY></HTML>" << endnl;
+ (*h) << skin->Footer();
+}
+
+HtmlSkinner * Action::GetSkinner() {
+ return skin;
}
String Action::GetURL(void) {
diff --git a/lib/HtmlSkinner.cc b/lib/HtmlSkinner.cc
new file mode 100644
index 0000000..31ed083
--- /dev/null
+++ b/lib/HtmlSkinner.cc
@@ -0,0 +1,33 @@
+#include "HtmlSkinner.h"
+
+HtmlSkinner::HtmlSkinner() {
+}
+
+HtmlSkinner::~HtmlSkinner() {
+}
+
+String HtmlSkinner::Redirect(const String & location) {
+ return "<HTML><HEAD><TITLE>301 - Moved Permanently</TITLE></HEAD>\n"
+ "<BODY><center><b><h2>You should be redirected <a href=\"" + location + "\">here</a> shortly</h2></b></center>\n"
+ "</BODY></HTML>\n";
+}
+
+String HtmlSkinner::Error(const String & location) {
+ return "<HTML><HEAD><TITLE>404 - Error</TITLE></HEAD>\n"
+ "<BODY><center><b><h2>The server was unable to process your query</h2></b></center>\n"
+ "Click <A HREF=\"/\">here</A> to go the main page.</BODY></HTML>\n";
+}
+
+String HtmlSkinner::Header(const String & title) {
+ return "<HTML><HEAD><TITLE>" + title + "</TITLE>\n"
+ "<META http-equiv=\"Content-Style-Type\" content=\"text/css\">\n"
+ "<LINK REL=STYLESHEET HREF=\"/image/style.css\" TYPE=\"text/css\">\n"
+ "</HEAD><BODY BGCOLOR=\"#aaaaaa\" BACKGROUND=\"/image/grain.png\">\n"
+ "<center><TABLE WIDTH=\"50%\" BORDER=3 cellspacing=1 BGCOLOR=\"#ffffff\"><TR><TD>\n"
+ "<center><b><h1>" + title + "</h1></b></center></TD></TR></TABLE><P>\n"
+ "<TABLE WIDTH=\"80%\" BORDER=2 cellspacing=1 BGCOLOR=\"#ffffff\"><TR><TD>\n";
+}
+
+String HtmlSkinner::Footer() {
+ return "</TABLE></TD></TR></BODY></HTML>";
+}
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 1105745..9a59dc2 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -359,10 +359,7 @@ void ProcessRequest::SendRedirect(Handle * s) {
"Cache-Control: no-cache" << endhl <<
"Connection: closed" << endhl <<
"Content-Type: text/html" << endhl << endhl <<
- "<HTML><HEAD><TITLE>301 - Moved Permanently</TITLE></HEAD>" << endnl <<
- "<BODY><center><b><h2>You should be redirected to the " << endnl << endnl <<
- "<a href=\"http://" << host << "/bin/start\">start page</a></h2></b></center>" << endnl <<
- "</BODY></HTML>" << endnl;
+ p->GetSkinner()->Redirect("http://" + host + "/bin/start");
}
/*
@@ -391,15 +388,7 @@ void ProcessRequest::SendHeads(Handle * s, const String & mime, const String & e
*/
void ProcessRequest::ShowError(Handle * s) {
- *s << "HTTP/1.1 404 Not Found" << endhl <<
- "Server: " << name << endhl <<
- "Cache-Control: no-cache" << endhl <<
- "Connection: closed" << endhl <<
- "Content-Type: text/html" << endhl << endhl <<
- "<HTML><HEAD><TITLE>404 - Error</TITLE></HEAD>" << endnl <<
- "<BODY><center><b><h2>The server was unable to process your query</h2></b></center>" << endnl <<
- "Click <A HREF=\"/\">here</A> to go the main page." <<
- "</BODY></HTML>" << endnl;
+ *s << p->GetSkinner()->Error("");
}
/*