[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
After I looked at ColdWeb, I saw easy it would be to implement a web server 
with genesis. I've started working on a web server that is file based and 
contains a server-side scripting system like ASP or JSP. In may ways, this 
may mimic features of ASP.NET, mainly because I think the paradigm it takes 
to web development is very strong. I've named the project FrozenServer. The 
basic idea is as follows.

Files with a special extension (I chose .csp for "cold server pages", not 
very inventive but oh well), are translated into objects in the genesis db. 
These files are regular html pages, with special tags that the parser will 
pick up and generate methods for to be executed, etc. These tags are called 
coldc scripting elements, and I have a few in mind..and hopefully a couple 
more down the road for usefulness. It's easier to describe if I just show a 
sample csp page (eXtreme of course).

<coldc:directive name="inherit" value="$admin_page" />
<coldc:directive name="trusted" value="1" />

<coldc:event name="onLoad">
	if(.post("btnSign") == "Sign Guestbook") {
		.sign_book();
	} else {
		.display_book();
	}
</coldc:event>

<coldc:script name="sign_book">
	var name, email, message;
	name = .post("txtName");
	email = .post("txtEmail");
	message = .post("txtMessage");

	$guestbook.sign_book(name, email, message);
	.display_book("Thank you for signing my book!");
</coldc:script>

<coldc:script name="display_book">
	arg @args;
	.writeln("<html><head><body>");
	if(args) {
		.write("<h2>" + args + "</h2>");
	.writeln(.GetGuestBook());
	.writeln("<form method=\"post\" action=\"guestbook.csp\">");
	.writeln("Name <input type=\"text\" name=\"txtName\" /><br />");
	.writeln("Email <input type=\"text\" name=\"txtEmail\" /><br />");
	.writeln("Message <textarea cols=\"20\" rows=\"8\" 
name=\"txtMessage\"></textarea><br />");
	.writeln("<input type=\"submit\" name=\"btnSign\" value=\"Sign Guestbook\" 
/></form>");
	.write("</body></html>");
</coldc:script>

<coldc:script name="GetGuestBook">
	var ret, x;
	ret = "<table>";
	for x in ($guestbook.entries().keys()) {
		ret += "<tr><td><b>" + x + "</b></td><td>" + $guestbook.entries()[x] + 
"</td></tr>"
	}
	return ret + "</table>";
</coldc:script>

I chose to make all code in script-like elements instead of inline because I 
hate the way spagetti piles up in other envs like ASP. Basically, all coldc 
elements begin with coldc: (kind of like the new asp.NET for server-side 
controls).

To simply some tasks, I've also decided to make a <coldc:call /> element 
that calls a function and outputs the return value, so something like would 
work.

<coldc:script name="get_foo">
  return "<p>" + $some_object.calculate_monkey() + "</p>";
</coldc:script>
<html>
<head>
   <title>Hi there!</title>
</head>
<body>
<h1>Welcome to monkey land</h1>
<coldc:call name="get_foo" />
</body>
</html>

Perhaps even allow it call methods on objects directly.
<coldc:call name="$some_object.calculate_monkey()" />

or maybe the other way around.

<coldc:event name="onLoad">
  .assgin_element("ctrlFoo", $some_object.calculate_monkey());
</coldc:script>
<html>
<head>
   <title>Hi there!</title>
</head>
<body>
<h1>Welcome to monkey land</h1>
<coldc:element name="ctrlFoo" />
</body>
</html>

a object will be made based on the "inherit" directive, or a default like 
$web_page. on-the-fly methods are added for all coldc:script elements and 
coldc:events. An underlying event system will fire the event functions. 
directives and such will be processed as the file is parsed.

everything outside coldc:script's, etc. will be converted to strings, along 
with coldc:call's and such.

I'm still getting things worked out in my head, but I think such a system 
would be pretty extendable and useful.

One problem with not having inline code is that HTML is hard to manage mixed 
into strings in the code. A template system would help this, and maybe a 
<coldc:block>...html code here with template tokens</coldc:block> element 
would help that out too, while seperating logic from presentation (which is 
a very major goal of this project).

It would also be very easy to implement things like "server-side contorls.", 
such as automatic form handling using custom events, etc.

like <coldc:control name="formbox" attrib... />

having a base web control object and deriving controls with a fixed 
interface.

Also, a caching system could be put in that cached web page objects, though 
I'm not exactly sure how to do this, but I'll figure it out.

One thing that I'm not sure of is security. I know there's going to have to 
be some kind of wall so that csp's can't crash the server. Not sure the best 
way to do it though. On one extreme, csp's may only be able to access server 
control-like objects, and there would be wrappers for all genesis objects 
that were accesible from csp's. I really dunno.

But that's the ideas I've had I've gotten a good start. I already have a web 
server that loads up static documents from the file system, along with 
mime-type mappings. The parser stuff is about to begin.

Jeremy Lowery


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp