Specification

Page Grammar

If you are new to parsing, you should look over the Introduction to Parsing.

Here's the grammar for Molly server pages.

The parser class is fc.web.page.PageParser. It is a hand-coded recursive-descent parser. The code can be modified easily to change the page syntax. Don't like using [[ brackets for code sections ? Change them to whatever you want !

You can also add new top-level tags of your own liking.

Class

Pages are translated into a class that implements the Page interface. In practice, generated pages are always a concrete subclass of PageImpl.

Pages cannot be subclassed further. You can, however, import and use any package within the page.

Instance

There is only 1 instance of each page. When the page is modified, it is translated again and recompiled. The a page class is loaded via a new classloader and therefore static/instance variables are set to their initial values.

Note: as with servlets, there can be multiple threads running the Initialization Pages cannot be defined with a constructor that takes arguments (for class loading reasons). The init method is invoked (once) when the page is loaded (and before it is run). This method acts as a pseudo contructor and should be used to initialize page instance/static variables as necessary.

Compiled files

Compiled pages are located in the web applications WEB-INF/molly_tmp/ directory.

Compilation errors have line numbers corresponding to the compiled java source. This java source can also be found at WEB-INF/molly_tmp and is very useful for debugging.

Note, however that any fixes to your code should be made to the page (*.mp) and not to the java source (*.java), since the java source will be rewritten whenever the page is modified.

Implicit variables

Pages are not servlets but are invoked by the PageServlet

Pages have access to implicit local variables. These implicit local variables are available in the render method of the page (hence can be used in text, code and hash sections):

out
The PrinterWriter to which one out.println(..), from within java code sections.

By default, this is a PrintWriter but this can be changed to an OutputStream by using a page directive.

req
request
The HttpServletRequest object or this request

Note: you can use the short word req or the larger word request to refer to the same object.

res
response
The HttpServletResponse object for this request.

Note: you can use the short word res or the larger word response to refer to the same object.

Since pages extend PageImpl, they also have access to inherited methods/variables from this superclass. Some of these superclass methods include those for:

See the javadocs for PageImpl for more information on these methods.

Translation

A page is translated ("compiled") into a java class that implements the Page interface. A PageServlet then invokes the render method of the generated class when the page is requested by the browser. This diagram shows this process graphically.

Processing

This diagram shows the sequence of events when a molly page is requested.