WebMacro is a framework for developing servlets . The framework implements the Model-View-Controller design template, providing a clean separation of responsibilities, namely WebMacro, provides a clean separation of the project source code from the presentation HTML code.
| Webmacro | |
|---|---|
| Type of | Template Engine |
| Developer | Sourceforge |
| Written on | Java |
| operating system | Cross Platform Software |
| Latest version | 2.2 ( February 25, 2010 ) |
| License | BSD |
| Website | webmacro.sourceforge.net |
WebMacro - Distributed as an open source project.
WebMacro was originally created and developed by Justin Wells of Semiotek Inc., in mid-2000, the project was accepted by the team at SourceForge .
In addition, WebMacro can be used to generate arbitrary text output based on a template (one of the methods of such use is automated code generation).
The template language is very similar to the language used in Apache Velocity , and there is also an automated script that performs migration.
Code Example
An example of using a template, and a simple Java application. The source code of the template named search.view
< html > < head > < title > Search Results </ title > </ head >
< body >
< h1 > Here are the results for $ query: </ h1 >
< table >
#foreach $ result in $ results {
< tr > < td > $ result.Number </ td >
< td > <a href = "$ result.Link"> $ result.Name </ a > </ td > </ tr >
}
</ table >
</ body > </ html >
The “$” symbol indicates that it is followed by a variable name in the template.
A shortened example of Java code using WebMacro:
WebMacro wm = new WM (); // likely to be created only once in your servlet
FastWriter out = wm . getFastWriter ( outStream , "UTF8" ); // FastWriter is created with UTF8 encoding
Context c = wm . getContext (); // produced in each request
c . put ( "query" , queryString ); // place a regular Java object, in this case a string
Result [] res = ...; // some data intended for output: search results are possible.
c . put ( "results" , res ); // place the object in context
Template t = wm . getTemplate ( "search.view" );
t . write ( out , c );
out . flush ();
See also
- Apache velocity
- Freemarker
- xmlc
- Jsp