WebMacro is a free Java development package that allows you to keep HTML and presentational issues out of your Java servlet code--while providing web designers with a simple template language capable of displaying any Java object. In stand alone mode, it is a powerful language generation platform for java.
Some basic guidelines for set-up:
These classes are servlets. Compile them and install them in your servlet directory. Note that there are multiple .class files for GuestBook, so be sure to copy all of them.
Then follow the instructions below to configure your classpath. If the templates are in your classpath, you will not need to create and then specify a path to your template file.
CLASSPATH=$JAVA_HOME/lib/classes.zip:$HOME/webmacro/webmacro.jar:$HOME/WebMacro/examples:$JSDK_HOMEYou have unpacked WebMacro in your home directory in this example. $JSDK_HOME contains the "javax" directory in which you have your JSDK base classes, and JAVA_HOME/lib/classes.zip contains the standard library.
Note that the examples are not pre-compiled, you must compile them.
HelloWorld and GuestBook use the WMServlet approach, so put all their .class files in your servlet directory.
TestWM uses the Reactor method. So register Reactor as the
servlet with TestWM as its script name (last part of the
URL).
How to Compile WebMacro
WebMacro ships with a webmacro.jar file compiled for JDK 1.2/1.3.
To recompile WM, you will need to go to the CVS archive where you
can find the ant build script and all the supporting libraries
referenced during compilation. You must "check out" the sources and
supporting files to compile and test WM.
Overview of the WebMacro System:
WebMacro is similar in many ways to JSP/ASP and other projects in many
ways, but differs from those according to our biases:
WebMacro presents two separate interfaces:
Alternately you might be a programmer working with a web designer: By providing the web designer with a list of variables which they can substitute into a page, you keep the designer at some distance from your sensitive program codes. At the same time, the designer is free to take those variables and lay them out any which way they please.
This separation of program code and content is the fundamental idea behind the WebMacro system.
Lastly, WM is a powerful language for code generation, mail merging
and rule development. A WebMacro template can contain simple
business logic. When a template is evaluated, the simple logic can interact
with more complex java and state processing. This makes for a formidable
framework for language generation. WebMacro is a language platform.
How it works:
WebMacro relies heavily on introspection to glue your template to your
back-end. On your back end you stick ordinary Java objects into your
Context. WebMacro will then introspect these objects and make them
available as properties in the template.
Introspection is fairly expensive so WebMacro avoids doing this at execution time. The first time a class is introspected WebMacro caches the knowledge it gains about the class for efficient use in the future. Templates are also compiled into a form suitable for rapid-execution on first use. (Note that you have to turn on the Template caching in your WebMacro.properties file to see this behavior.)
The overall design of WebMacro is that the state for each request is contained in this Context object: you need to instantiate a new Context for every request (you can create a prototype Context and then clone it for efficiency--this is automatically done for you most of the time.)
Since the state for each request is entirely contained within the Context, templates can be shared between multiple requests. Since templates have no state, they don't need to be synchronized. Since Contexts are accessed by only one thread ("thread per request") they don't need to be synchronized either. Thus you get very good performance out of WebMacro since most of the code can avoid the overhead of synchronization locks.
Finally, WebMacro is a framework. Most of its behavior is loaded dynamically based on the configuration file, WebMacro.defaults and if present, WebMacro.properties. The effect of this is that you can radically alter the behavior of WebMacro by replacing the classes named in WebMacro.properties with your own. There are a large number of "plug points" in the design to allow an advanced user to customize WebMacro extensively.
For an ordinary user, though, it's good enough to rely on the default configuration. All you have to do is create contexts and load templates using the provided WebMacro interfaces. See the examples provided in the examples directory for more information.