pkg://webmacro-1.1-1jpp.src.rpm:344073/webmacro-src-1.1final.tgz
info downloads
webmacro-src-1.1final/examples/ 40755 0 0 0 7605651403 13607 5 ustar 0 0 webmacro-src-1.1final/examples/advanced/ 40755 0 0 0 7605651403 15354 5 ustar 0 0 webmacro-src-1.1final/examples/WEB-INF/ 40755 0 0 0 7605651403 14636 5 ustar 0 0 webmacro-src-1.1final/examples/WEB-INF/classes/ 40755 0 0 0 7605651403 16273 5 ustar 0 0 webmacro-src-1.1final/examples/WEB-INF/lib/ 40755 0 0 0 7605651403 15404 5 ustar 0 0 webmacro-src-1.1final/lib/ 40755 0 0 0 7605651403 12537 5 ustar 0 0 webmacro-src-1.1final/macros/ 40755 0 0 0 7605651403 13255 5 ustar 0 0 webmacro-src-1.1final/macros/ecomm/ 40755 0 0 0 7605651403 14355 5 ustar 0 0 webmacro-src-1.1final/macros/html/ 40755 0 0 0 7605651403 14221 5 ustar 0 0 webmacro-src-1.1final/src/ 40755 0 0 0 7605651403 12560 5 ustar 0 0 webmacro-src-1.1final/src/org/ 40755 0 0 0 7605651403 13347 5 ustar 0 0 webmacro-src-1.1final/src/org/opendoors/ 40755 0 0 0 7605651403 15357 5 ustar 0 0 webmacro-src-1.1final/src/org/opendoors/cache/ 40755 0 0 0 7605651403 16422 5 ustar 0 0 webmacro-src-1.1final/src/org/opendoors/cache/immutable/ 40755 0 0 0 7605651403 20401 5 ustar 0 0 webmacro-src-1.1final/src/org/opendoors/util/ 40755 0 0 0 7605651403 16334 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/ 40755 0 0 0 7605651403 15146 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/broker/ 40755 0 0 0 7605651403 16432 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/directive/ 40755 0 0 0 7605651403 17124 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/engine/ 40755 0 0 0 7605651403 16413 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/parser/ 40755 0 0 0 7605651403 16442 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/profile/ 40755 0 0 0 7605651403 16606 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/resource/ 40755 0 0 0 7605651403 16775 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/servlet/ 40755 0 0 0 7605651403 16632 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/servlet/Templates/ 40755 0 0 0 7605651403 20570 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/tools/ 40755 0 0 0 7605651403 16306 5 ustar 0 0 webmacro-src-1.1final/src/org/webmacro/util/ 40755 0 0 0 7605651403 16123 5 ustar 0 0 webmacro-src-1.1final/test/ 40755 0 0 0 7605651403 12750 5 ustar 0 0 webmacro-src-1.1final/test/perf/ 40755 0 0 0 7605651403 13704 5 ustar 0 0 webmacro-src-1.1final/test/unit/ 40755 0 0 0 7605651403 13727 5 ustar 0 0 webmacro-src-1.1final/tutorial/ 40755 0 0 0 7605651403 13634 5 ustar 0 0 webmacro-src-1.1final/build.xml 100644 0 0 25727 7605651403 13744 0 ustar 0 0 <!--
In order to compile WebMacro, you may need to set these environment variables
JAVACC_HOME: your JavaCC installation
-->
<!--
Note, you will need ANT 1.5.x, available from:
http://jakarta.apache.org/ant
-->
<project name="WebMacro" default="usage" basedir=".">
<target name="usage">
<echo><![CDATA[
Usage:
ant TARGET [-Dproperty1=value -DpropertyN=value]
Common targets:
clean
Remove all temporary files created during build process
compile
Compile all source files
jar
Create "webmacro.jar"
javadoc
Generate javadocs
test
Execute entire test suite against current sources
test -Dtest=TestSomething
Execute a specific test. No need to specify full classname.
Useful to quickly test a specific aspect of WebMacro
all
do it all, baby!
Administrative targets:
dist-binary
Build a binary distro of WebMacro
dist-source
Build a source distro of WebMacro
release
Build both binary and source distros and .zip and .tgz 'em both
]]></echo>
</target>
<property name="version" value="1.1final" />
<property name="app.name" value="webmacro" />
<property name="tmpdir" value="tmp" />
<property name="classes" value="classes"/>
<property name="macros" value="macros"/>
<property name="dist.binary" value="webmacro-bin-${version}"/>
<property name="dist.source" value="webmacro-src-${version}"/>
<property name="javadoc" value="javadoc"/>
<property name="examples" value="examples"/>
<property name="jar" value="${app.name}.jar"/>
<property name="src.jar" value="${app.name}-src.jar"/>
<property environment="ENV" />
<property name="javacc.home" value="${ENV.JAVACC_HOME}" />
<taskdef name="javacc"
classname="org.apache.tools.ant.taskdefs.optional.javacc.JavaCC" />
<path id="class.path">
<fileset dir="lib">
<include name="*.jar" />
<include name="*.zip" />
</fileset>
<pathelement location="${classes}" />
<pathelement location="${macros}" />
<pathelement path="${java.class.path}" />
</path>
<property name="classpath.resolved" refid="class.path"/>
<target name="prepare">
<tstamp />
<mkdir dir="${classes}"/>
<mkdir dir="${javadoc}"/>
<mkdir dir="${dist.binary}"/>
<mkdir dir="${examples}/WEB-INF"/>
<mkdir dir="${examples}/WEB-INF/classes"/>
<mkdir dir="${examples}/WEB-INF/lib"/>
<mkdir dir="${dist.binary}"/>
<mkdir dir="${dist.source}"/>
<available property="javacc.present" classname="COM.sun.labs.javacc.Main"
classpath="${javacc.home}/JavaCC.zip" />
</target>
<target name="clean" depends="test-clean">
<delete dir="${classes}"/>
<delete dir="${javadoc}"/>
<delete dir="${dist.binary}"/>
<delete file="${dist.binary}.tgz"/>
<delete file="${dist.binary}.zip"/>
<delete dir="${dist.source}"/>
<delete file="${dist.source}.tgz"/>
<delete file="${dist.source}.zip"/>
<delete file="${jar}"/>
<delete file="${src.jar}"/>
<delete dir="${tmpdir}"/>
<delete dir="${examples}/WEB-INF"/>
<delete dir="${tmpdir}"/>
<ant antfile="test/build.xml" target="unit-clean" />
</target>
<target name="precompile" depends="prepare" if="javacc.present">
<javacc target="src/org/webmacro/parser/WMParser_impl.jj"
javacchome="${javacc.home}" />
</target>
<target name="compile" depends="prepare, precompile">
<filter token="VERSION" value="${version}" />
<filter token="BUILD_DATE" value="${TODAY}" />
<copy todir="${tmpdir}" filtering="true">
<fileset dir="src" />
</copy>
<javac srcdir="${tmpdir}" destdir="${classes}"
debug="on" optimize="off" deprecation="off">
<classpath refid="class.path" />
</javac>
<copy todir="${classes}">
<fileset dir="${tmpdir}" includes="**/*.properties" />
<fileset dir="." includes="WebMacro.defaults"/>
</copy>
<touch file="${classes}/WM-VERSION-${version}" />
</target>
<target name="compile-examples" depends="compile">
<filter token="VERSION" value="${version}" />
<filter token="BUILD_DATE" value="${TODAY}" />
<javac srcdir="${examples}" destdir="${examples}/WEB-INF/classes"
excludes="**/advanced/*.java"
debug="on" optimize="off" deprecation="off">
<classpath refid="class.path" />
</javac>
</target>
<target name="javadoc" depends="prepare">
<javadoc sourcepath="src" destdir="${javadoc}"
packagenames="org.*" author="true" version="true"
use="true">
<classpath refid="class.path" />
</javadoc>
</target>
<target name="jar" depends="prepare,compile">
<jar jarfile="${jar}" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="org.webmacro.WM" />
<attribute name="Build-Date" value="${TODAY}" />
</manifest>
</jar>
</target>
<target name="dist-binary" depends="prepare,compile,compile-examples,jar,javadoc">
<delete dir='${dist.binary}' />
<mkdir dir='${dist.binary}' />
<copy todir="${dist.binary}" file="${jar}"/>
<copy todir="${dist.binary}">
<fileset dir="distroot" />
</copy>
<mkdir dir="${dist.binary}/tutorial" />
<copy todir="${dist.binary}/tutorial">
<fileset dir="tutorial"/>
</copy>
<mkdir dir="${dist.binary}/api" />
<copy todir="${dist.binary}/api">
<fileset dir="${javadoc}"/>
</copy>
<mkdir dir="${dist.binary}/examples" />
<copy todir="${dist.binary}/examples">
<fileset dir="examples" />
</copy>
<mkdir dir="${dist.binary}/macros" />
<copy todir="${dist.binary}/macros">
<fileset dir="${macros}" />
</copy>
<touch file="${dist.binary}/WM-VERSION-${version}"/>
</target>
<target name="dist-source" depends="prepare">
<delete dir='${dist.source}' />
<mkdir dir='${dist.source}' />
<copy todir="${dist.source}">
<fileset dir="distroot" />
</copy>
<copy file='WebMacro.defaults' todir='${dist.source}' />
<copy file='build.xml' todir='${dist.source}' />
<mkdir dir="${dist.source}/src" />
<copy todir="${dist.source}/src">
<fileset dir="src" />
</copy>
<mkdir dir="${dist.source}/test" />
<copy todir="${dist.source}/test">
<fileset dir="test" includes='perf,unit' />
</copy>
<mkdir dir="${dist.source}/lib" />
<copy todir="${dist.source}/lib">
<fileset dir="lib" includes="**/*.txt" />
</copy>
<mkdir dir="${dist.source}/tutorial" />
<copy todir="${dist.source}/tutorial">
<fileset dir="tutorial"/>
</copy>
<mkdir dir="${dist.source}/examples" />
<copy todir="${dist.source}/examples">
<fileset dir="examples" />
</copy>
<mkdir dir="${dist.source}/macros" />
<copy todir="${dist.source}/macros">
<fileset dir="${macros}" />
</copy>
<touch file="${dist.source}/WM-VERSION-${version}"/>
</target>
<target name='zip.and.tar' depends='dist-binary,dist-source'>
<zip destfile='${dist.binary}.zip' basedir='.' includes='${dist.binary}/**/*' />
<zip destfile='${dist.source}.zip' basedir='.' includes='${dist.source}/**/*' />
<tar destfile='${dist.binary}.tgz' longfile='gnu' compression='gzip' basedir='.' includes='${dist.binary}/**/*' />
<tar destfile='${dist.source}.tgz' longfile='gnu' compression='gzip' basedir='.' includes='${dist.source}/**/*' />
</target>
<target name='release' depends='clean,test,dist-binary,dist-source,zip.and.tar' />
<!--
<target name="contrib" depends="compile" >
<ant antfile="contrib/build.xml" target="all" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
-->
<target name="test" depends="compile" >
<ant antfile="test/build.xml" target="all" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-unit" depends="compile" >
<ant antfile="test/build.xml" target="unit" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-validate" depends="compile" >
<ant antfile="test/build.xml" target="validate" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-templates" depends="compile" >
<ant antfile="test/build.xml" target="templates" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-tst" depends="compile" >
<ant antfile="test/build.xml" target="TST" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-macro" depends="compile" >
<ant antfile="test/build.xml" target="macros" >
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-clean" >
<ant antfile="test/build.xml" target="clean">
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="test-compile" >
<ant antfile="test/build.xml" target="unit-compile">
<property name="java.class.path" value="${classpath.resolved}"/>
</ant>
</target>
<target name="all" depends="clean,prepare,compile,javadoc,dist-source,dist-binary,test-unit"/>
<!--
Note: there are two tasks:
(1) Parsing a template which checks the grammar syntax
(2) Evaluating a template which evaluates a template using a context
provided by the template or some bean
MOTE: the tasks are independent. (1) and/or (2) can be run completely
independent of the other!
<taskdef name="wmtemplates"
classname="org.webmacro.tools.WMTemplateAntTask" >
<classpath refid="class.path" />
</taskdef>
<taskdef name="wmevaltemplates"
classname="org.webmacro.tools.TemplateEvalAntTask" >
<classpath refid="class.path" />
</taskdef>
<target name="templates">
<wmtemplates>
<fileset dir="." includes="**/*.wm"/>
<classpath refid="class.path" />
</wmtemplates>
<wmevaltemplates>
<fileset dir="templates" includes="**/*.wm"/>
<classpath refid="class.path" />
</wmevaltemplates>
</target>
-->
</project>
webmacro-src-1.1final/CONFIGURING-EXAMPLES 100644 0 0 10441 7605651403 15017 0 ustar 0 0 *INSTALLING THE WEBMACRO EXAMPLES*
This document describes how to install and configure the examples packaged
with WebMacro using Tomcat and Resin, two popular Java servlet containers.
Other JSDK 2.2+ compliant servlet containers should work very similarly.
The sources were compiled using Sun's JDK1.3. Unix/Linux configuration
should be virtually identical (except for the slashes
and drive letters in the paths). All paths given such as
release/examples/ are relative to "release" which will be a
specific version, eg, "webmacro-1.0rc1"
to the
*TOMCAT CONFIGURATION (v3.2.1)*
Copy the files from release/examples to a webapps directory named wm/.
For example, if your TOMCAT_HOME is E:\tomcat then copy the examples files to
E:\tomcat\webapps\wm. This will result in a directory with the
following files:
HTML and text:
e:\tomcat\webapps\wm\index.html
e:\tomcat\webapps\wm\README
WebMacro configuration file:
e:\tomcat\webapps\wm\WebMacro.properties
Sample batch file for compiling sources:
e:\tomcat\webapps\wm\build.bat
Templates:
e:\tomcat\webapps\wm\allguest.wm
e:\tomcat\webapps\wm\callgraph.wm
e:\tomcat\webapps\wm\error.wm
e:\tomcat\webapps\wm\form.wm
e:\tomcat\webapps\wm\helloWorld.wm
e:\tomcat\webapps\wm\noservlet.wm
e:\tomcat\webapps\wm\profile.wm
e:\tomcat\webapps\wm\sandbox.wm
e:\tomcat\webapps\wm\verify.wm
e:\tomcat\webapps\wm\WEB-INF\classes\standalone.wm
Java sources:
e:\tomcat\webapps\wm\GuestBook.java
e:\tomcat\webapps\wm\HelloWorld.java
e:\tomcat\webapps\wm\NoServlet.java
e:\tomcat\webapps\wm\Profile.java
e:\tomcat\webapps\wm\SandBox.java
e:\tomcat\webapps\wm\Standalone.java
Class files:
e:\tomcat\webapps\wm\WEB-INF\classes\GuestBook$GuestEntry.class
e:\tomcat\webapps\wm\WEB-INF\classes\GuestBook.class
e:\tomcat\webapps\wm\WEB-INF\classes\HelloWorld.class
e:\tomcat\webapps\wm\WEB-INF\classes\NoServlet.class
e:\tomcat\webapps\wm\WEB-INF\classes\Profile.class
e:\tomcat\webapps\wm\WEB-INF\classes\SandBox.class
e:\tomcat\webapps\wm\WEB-INF\classes\Standalone.class
WebMacro jar:
e:\tomcat\webapps\wm\WEB-INF\lib\webmacro.jar
*RESIN CONFIGURATION (1.2.5)*
Extract the files as above to the <resin_home>/doc directory. Add the
following lines to the resin.conf file (usually in <resin_home>/conf)
within the <host> tag (just above the </host> tag):
<web-app id='wm'>
<servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
<welcome-file-list>index.html</welcome-file-list>
</web-app>
*ALTERNATIVE CONFIGURATION FOR RESIN*
This technique avoids moving directories all over the place.
Assume that you have installed webmacro/ in /usr/local/web
and /usr/local/web is an application root directory for http://localhost
1) Copy webmacro.jar to <resin_home>/lib
2) Add the following to your resin.conf within the application host section:
<web-app id='wm' app-dir='webmacro/examples'>
<servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
<welcome-file-list>index.html</welcome-file-list>
</web-app>
http://localhost/wm should serve up the index.html page and the links in the page
should serve up the servlets.
*NOTE ON TEMPLATE PATHS*
Notice that all the templates are located in the applications root directory
except for standalone.wm. The "Standalone" example instantiates WM directly
and does not extend WMServlet. Because of this its broker does not have
access to the ServletContext. The other examples all extend WMServlet and
thus are able to get their resources (templates) through the ServletContext.
This feature is only available with JSDK2.2+ compatable servlet containers.
By putting the template in the classes directory, the Standalone servlet is
able to locate it through the classpath.
The alternative would have been to add a TemplatePath to the
webmacro.properties file. For example, you could put all of the templates
in e:\tomcat\webapps\wm\WEB-INF\templates and add:
TemplatePath: e:\tomcat\webapps\wm\WEB-INF\templates
to the WebMacro.properties file. This technique should work with all
servlet containers. The major drawback is that it requires a manual
configuration step (since we can't know what directory you will use) which
is a frequent cause of configuration problems. The other methods will work
out of the box, even without a WebMacro.properties file.
webmacro-src-1.1final/CREDITS 100644 0 0 3264 7605651403 13113 0 ustar 0 0
(c) 1998, 1999, 2000, 2001, 2002 by Semiotek Inc. and its contributors.
WebMacro was primarily designed and developed by Justin Wells,
and originally implemented by Justin Wells and Yuen-Ping Leung.
WebMacro is an opensource community development effort. The
current team is:
Justin Wells Original Developer
Brian Goetz Current Lead Software Engineer
Fergus Gallagher Core Developer
Marcel Huijkman Core Developer
Tim Joyce Core Developer
Sebastian Kanthak Core Developer
Keats Kirsch Core Developer
Paul Kmiec Core Developer
Aldona Majorek Core Developer
Marc Palmer Core Developer
Eric Ridge Core Developer
Lane Sharman Core Developer
Petr Toman Core Developer
Zeljko Trogrlic Core Developer
Frank Carver Contributor
Jeff Gee Contributor
Chris Hoover Contributor
Jason Hunter Contributor
Stefan Mainz Contributor
Dr. S. G. Shering Contributor
Michelle Yeh Contributor
Doug Young Contributor
Many people beyond this list contribute to WebMacro.
THANK YOU TO EACH AND EVERYONE OF YOU.
If you wish to make a software contribution, please visit
the WebMacro wiki site to learn how to join the mailing list,
make a software contribution, or to rant or rave on the interactive
wiki site.
Webmacro is a community development effort that would not have been
possible without folks like you.
Again, new contributors are always welcome!
webmacro-src-1.1final/examples/advanced/CommitActionHandler.java 100644 0 0 2625 7605651403 22205 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import org.opendoors.store.*;
import org.opendoors.util.Console;
import com.acctiva.bo.*;
import com.acctiva.intf.ExceptionReporting;
/**
* All commit acction handers should derive from this class which does no
* processing.
*/
public class CommitActionHandler extends ViewActionHandler {
/**
* Every action handler must have a locale senstive label.
*/
public CommitActionHandler(ActionVerb verb, AbstractViewAgent handledView) {
super(verb, handledView);
}
/**
* The commit handler should must implement this process handler.
*/
protected View processAction(HttpServletRequest request){
try {
commitAction();
}
catch (Exception e) {
Console.error("CommitHandler. Unable to commit", this, e);
}
handledView.actionTaken = this.verb;
return handledView;
}
/** Subclasses should implement this adapter method. */
protected void commitAction() throws Exception {}
}
webmacro-src-1.1final/examples/advanced/GeneralCommitView.java 100644 0 0 4375 7605651403 21706 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import org.opendoors.util.Console;
import org.opendoors.adt.OrderedSet;
import org.opendoors.store.*;
import com.acctiva.views.*;
import com.acctiva.schema.Fields;
import com.acctiva.bo.*;
/**
* A General Commit View is a subclass of General View with
* a commit phase at the end allowing the user to review
* the changes. This is a much harder class to implement subclass
* and therefore you should first consider subclassing GeneralView.
*/
abstract public class GeneralCommitView extends GeneralView {
/** A repeating set of notes on the person. */
public GeneralCommitView() { super(); }
/**
* What is the commit handler.
*/
abstract public CommitActionHandler getCommitHandler(CommitView v);
/**
* The attributes to lay out the commit with.
*/
abstract public Attributes getCommitAttributes();
/** The commit title. */
abstract public String getCommitTitle();
protected OrderedSet createViews(HttpServletRequest request, String contextLink) throws Exception {
OrderedSet relatedViews = super.createViews(request, contextLink);
// the commit view:
CommitView c = new CommitView(null, getCommitAttributes(), relatedViews);
c.initView(null, getCommitTitle(), ActionVerb.NULL, contextLink);
CommitActionHandler cah = getCommitHandler(c);
ViewActionHandler[] c1 = null;
if (cah == null) {
c1 = new ViewActionHandler[]
{new CancelActionHandler(ActionVerb.CANCEL, c),
new ViewActionHandler(ActionVerb.PREVIOUS, c) };
}
else {
c1 = new ViewActionHandler[]
{new CancelActionHandler(ActionVerb.CANCEL, c),
new ViewActionHandler(ActionVerb.PREVIOUS, c), cah};
}
c.addActionHandler(c1);
c.commitView = true;
return relatedViews;
}
public String toString() {return "GeneralCommitView";}
}
webmacro-src-1.1final/examples/advanced/GeneralView.java 100644 0 0 10755 7605651403 20554 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import org.opendoors.util.Console;
import org.opendoors.adt.OrderedSet;
import org.opendoors.store.*;
import com.acctiva.views.*;
import com.acctiva.schema.Fields;
import com.acctiva.bo.*;
/**
* A General View is a subclass of this view which uses
* headless views but no commit view. The headless views can
* be multi-element views. Action handlers can be supplied to
* provide persistence on the accept action if desired.
* <p>
* Note: The last view created is not identified as a commit
* view. If the last view is to be a commit view, the client subclass
* must make it so.
* @see GeneralCommitView
*/
abstract public class GeneralView extends MultipleViewFactory implements Fields {
/** A repeating set of notes on the person. */
public GeneralView() { super(); }
/** Subclasses must provide the value panels for each view. */
abstract public FieldData[][] getDataPanels();
/**
* Subclasses indicate if the view is a multi-view by setting the
* the value to true.
*/
abstract public boolean[] isMultiView();
/**
* When a view has multiple views, the layout of the
* the rows is dictated by the a row meta panel.
*/
abstract public MetaField[][] getMultiLayout();
/**
* When a view is a multi-view, there can be existing values
* and they should be in the form of an array of attributes.
* <p>
* This can be blank in many cases.
*/
abstract public Attributes[][] getMultiValues();
/** Subclass provides the panel titles. */
abstract public String[] getPanelTitles();
protected OrderedSet createViews(HttpServletRequest request, String contextLink) throws Exception {
OrderedSet relatedViews = new OrderedSet();
FieldData[][] panel = getDataPanels();
boolean[] multiView = isMultiView();
Attributes[][] multiValues = getMultiValues();
MetaField[][] listLayout = getMultiLayout();
String[] title = getPanelTitles();
for (int index = 0; index < panel.length; index++) {
Attributes attributes = new Attributes();
// Creates the property elements.
HeadlessView p = new HeadlessView(null, attributes, relatedViews,
multiView[index], listLayout[index]);
p.initView(panel[index], title[index], ActionVerb.NULL, contextLink);
if (multiView[index] && multiValues[index] != null) {
p.appendMultiValue(multiValues[index]);
}
// if count == 1, add below else add next
ViewActionHandler[] actions = null;
if (panel.length == 1) {
ViewActionHandler[] vah = {new CancelActionHandler(ActionVerb.CANCEL, p),
new FinishActionHandler(ActionVerb.FINISH, p)};
actions = vah;
}
else {
if (index == 0) {
ViewActionHandler[] vah = {new CancelActionHandler(ActionVerb.CANCEL, p),
new ViewActionHandler(ActionVerb.NEXT, p)};
actions = vah;
}
else {
if (index < (panel.length-1)) {
ViewActionHandler[] vah = {new CancelActionHandler(ActionVerb.CANCEL, p),
new ViewActionHandler(ActionVerb.PREVIOUS, p),
new ViewActionHandler(ActionVerb.NEXT, p)};
actions = vah;
}
else { // the last view in the panel list
ViewActionHandler[] vah = {new CancelActionHandler(ActionVerb.CANCEL, p),
new ViewActionHandler(ActionVerb.PREVIOUS, p),
new FinishActionHandler(ActionVerb.FINISH, p)};
actions = vah;
}
}
}
p.addActionHandler( actions );
if (multiView[index]) {
ViewActionHandler[] create = {new AddItemActionHandler(ActionVerb.ADDITEM, p)};
ViewActionHandler[] edit = {new SaveItemActionHandler(ActionVerb.SAVEITEM, p),
new CancelModifyItemActionHandler(ActionVerb.CANCELMODIFICATION, p)};
ViewActionHandler[] rlist = {new RemoveItemActionHandler(ActionVerb.REMOVEITEM, p),
new ModifyItemActionHandler(ActionVerb.MODIFYITEM, p)};
p.setMultiActionList( rlist, edit, create, create ); // sets all values, initial state
}
p.contextLink = contextLink;
}
return relatedViews;
}
public String toString() {return "GeneralView";}
}
webmacro-src-1.1final/examples/advanced/index.html 100644 0 0 10174 7605651403 17471 0 ustar 0 0 <html>
<center>
Templates, Java Class Files, Further Reference
<br>Last Updated 2-July-2001
</center>
<p>
<a href=list.tml>list.tml</a> Lists can be powerfully handled by getting to know the List
Context Tool and its methods. Here is a simple example of transforming default arrays to more powerful
lists implementing the java.util.List interface and thus being uniformly managed by the List Tool.
<p>
<a href=wizard.tml>wizard.tml</a> An example of how to render a form relying exclusively on introspection
obtain the "View", the labels, the controls, the values. Labels are rendered in a locale sensitive manner:
<pre>
$field.MetaField.getLabel($User.Locale):
</pre>
achieves label localization in the WM script.
<p>
<a href=wizardform.tml>wizardform.tml</a> An example of to interact with server state variables
and then how to evaluate conditions and parse in the correct template.
<p>
<a href=wizardform.tml>wizardform.tml</a> An example of to interact with server state variables
and then how to evaluate conditions and parse in the correct template.
<p>
<a href=view.tml>view.tml</a> An example of a complete object report showing the "peers" of a logical
view. In most web apps, views will be linked together as logical pages.
<p>
<hr size=1 width=50%>
<p>
<a href=View.java>View.java</a> An interface definition which
represents the server-side equivalent of a webmacro "skin".
During template evaluation, an instance implementing this interface provides the core
lifecylce and state management methods. A convenient and globally unique identifier
can be passed around as an http get and post parameter. Views are often chained
together to produce wizards and multi-phased input models. State is always maintained
inside the View implementation members.
<p>
<a href=ViewFactory.java>ViewFactory.java</a> Views are instantiated by factories which return an instance implementing the View interface.
<p>
<a href=GeneralView.java>GeneralView.java</a> A view factory which supports multiple panels in a view.
<p>
<a href=GeneralCommitView.java>GeneralCommitView.java</a> A view factory which adds a commit view panel as the last view.
<p>
<a href=ReferralView.java>ReferralView.java</a> A concrete view containing two panels. The first allows for the panel
to create and manage a vector of elements. The second panel is for a single element.
The last panel is for a commit/confirmation of the views. This is an excellent example of how the subclass
has been relieved of all complexity in the view management. It is focused on the application elements
of the referred parties and the referring party.
<p>
<a href=ViewActionHandler.java>ViewActionHandler.java</a> You must add to a view one or more action handlers. The general case.
<p>
<a href=CommitActionHandler.java>CommitActionHandler.java</a> The base handler for the proverbial "OK. Do something with this input!"
<p>
<a href=InsertInterimBOHandler.java>InsertInterimBOHandler.java</a> A commit handler which
assembles the view elements and creates a persistent business object, an InterimBusinessObject. These
objects are persisted as elements in a <a href=http://engineering.acctiva.org>Very Large Hashtable</a>.
<p>
<hr size=1 width=50%>
<p>
These are specimens contributed by Lane Sharman. Others are more than welcome to add to this file
which is maintained as index.html in cvs under the examples directory.
<p>
The examples are best viewed with a text editor, not a browser.
<p>
<hr size=1 width=50%>
<p>
Other example resources:
<p>
<a href=http://wiki.webmacro.org/WebMacroScriptLanguage>Scripting</a> tutorial
under development by Keats Kirsch.
<p>
<a href=http://wiki.webmacro.org/SiteMap>Map</a> of the WM wiki site with many good development links.
Be sure to check the date on the bottom of the page for when it was last edited. Some pages
are out of date.
<p>
Many have generously contributed ideas and approaches in the current
distribution. Check these out for ideas on how to solve a particular
problem using WebMacro.
<p>
<a href=http://engineering.acctiva.org/jldap>jldap</a>
Practice at Open Doors Software for creating a java language for data acquistion and presentment for
web applications we write.
</html>
webmacro-src-1.1final/examples/advanced/InsertInterimBOHandler.java 100644 0 0 4721 7605651403 22633 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.opendoors.store.*;
import org.opendoors.util.Console;
import com.acctiva.bo.*;
import com.acctiva.intf.ExceptionReporting;
/**
* All commit acction handers should derive from this class which does no
* processing.
*/
public class InsertInterimBOHandler extends CommitActionHandler {
private String name, value;
/**
* Every action handler must have a locale senstive label.
*/
public InsertInterimBOHandler(ActionVerb verb, AbstractViewAgent handledView) {
super(verb, handledView);
}
/** Sets the name and value properties required. */
public void setProperties(String name, String value) {
this.name = name;
this.value = value;
}
/**
* The logic for processing the insert of
* a interim business object in a background thread.
*/
protected void commitAction() throws Exception {
(new Thread() {
public void run() {
InterimBusinessObject ibo = createIBO();
ibo.init();
ibo.setProperty(name, value);
insertActions(ibo);
Map m = ibo.getMap();
Enumeration e = handledView.getViewElements();
while (e.hasMoreElements()) {
AbstractViewAgent v = (AbstractViewAgent) e.nextElement();
v.mapAttributeData(m);
}
try {
ibo.create();
iboCreated(ibo); // lifecycle
System.out.println("Commit Complete of IBO in background thread=" + this + " " + ibo);
}
catch(Exception ex) {
Console.error("Unable to create interim bo", ibo, ex);
}
}
}).start();
}
/** Subclasses provide insert actions by implementing the adapter method. */
protected void insertActions(InterimBusinessObject obj) {}
/** Subclasses provide a subclass of an interim business object. */
protected InterimBusinessObject createIBO() {
return new InterimBusinessObject();
}
/** Subclasses can override once an interim business object has been created. */
protected void iboCreated(InterimBusinessObject ibo) {}
}
webmacro-src-1.1final/examples/advanced/list.tml 100644 0 0 1145 7605651403 17143 0 ustar 0 0 <!-- helptoc.tml -->
## Provides the control for listing help files in a separate window
## Requires $org.webmacro.servlet.ListTool to be in the context
## as List.
## create arrays and then create more powerful list structures
## available for manipulation by the list tool:
#set $hrefs = ["AboutAcctiva.lbi", "HowDo.lbi"]
#set $refsList = $List.toList($hrefs)
#set $titles = ["About Acctiva", "How Do I..."]
#set $titlesList = $List.toList($titles)
<html>
#foreach $href in $hrefs indexing $index from 0 {
<a href="$List.getItem($refsList, $index)">$List.getItem($titlesList, $index)</a><br>
}
</html>
webmacro-src-1.1final/examples/advanced/ReferralView.java 100644 0 0 5453 7605651403 20720 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views.directory;
import javax.servlet.http.HttpServletRequest;
import org.opendoors.util.Console;
import org.opendoors.adt.OrderedSet;
import org.opendoors.store.*;
import com.acctiva.views.*;
import com.acctiva.schema.directory.CommonDirectory;
import com.acctiva.schema.directory.Refer;
/**
* A two panel view of a user.
* <p>
* Panel 1: Information on referred party.
* Panel 2: Voluntary information from party making referral.
*/
public class ReferralView extends GeneralCommitView implements Refer {
static final FieldData[] panel1 = {
new EmailData(REFERRED_EMAIL),
new StringData(REFERRED_NAME_FIRST),
new StringData(REFERRED_NAME_LAST),
new StringData(REFERRED_ORG_NAME)
};
static final FieldData[] panel2 = {
new StringData(REFERRAL_NOTE),
new StringData(REFERRERS_NAME),
new BooleanData(REFERRAL_NOTE_PUBLIC)
};
static final FieldData[][] panels = {panel1, panel2};
static final MetaField[][] layout = { {REFERRED_EMAIL,
REFERRED_NAME_FIRST,
REFERRED_NAME_LAST,
REFERRED_ORG_NAME},
null};
static final boolean[] multi = {true, false};
static final String[] titles = {"Directory.ReferredName",
"Directory.ReferringNameAndNote"};
public ReferralView() {}
public FieldData[][] getDataPanels() {
return panels;
}
public boolean lastIsCommit() { return true; }
public boolean[] isMultiView() {
return multi;
}
public Attributes[][] getMultiValues() {
// need to do a look up here if the
// request has a seqnbr value
Attributes[][] v = new Attributes[2][];
return v;
}
public MetaField[][] getMultiLayout() {
return layout;
}
public String[] getPanelTitles() { return titles; }
public String toString() { return "ReferralView"; }
public CommitActionHandler getCommitHandler(CommitView v) {
InsertInterimBOHandler i = new InsertInterimBOHandler(ActionVerb.COMMIT, v);
i.setProperties("ReferralView", "Directory.ReferredName" + " " +
"Directory.ReferringNameAndNote");
return i;
}
public Attributes getCommitAttributes() {return null;}
public String getCommitTitle() {return null;}
}
webmacro-src-1.1final/examples/advanced/View.java 100644 0 0 2612 7605651403 17227 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import javax.servlet.http.HttpServletRequest;
import org.opendoors.store.*;
import com.acctiva.bo.BusinessObject;
/**
* All views extend from this base class.
*/
public interface View {
/**
* Every view must be initialized with its fields.
*/
public void initView(FieldData[] templateFields, String localeLabel,
ActionVerb initialAction, String contextLink) throws Exception;
/**
* Every view has a unique sequence number identifying it.
*/
public SeqNbr getViewIdentifier();
/**
* A view has a set of viewable fields to be rendered, processed.
* <p>
* These are the viewable fields as meta fields.
* @return An array of the viewable fields.
*/
public FieldData[] getViewableFields();
/**
* Current attributes at any time in lifecycle of view.
*/
public Attributes getViewableAttributes();
/**
* Handle an http request on the current view.
*/
public View dispatchAction(HttpServletRequest request);
}
webmacro-src-1.1final/examples/advanced/view.tml 100644 0 0 1066 7605651403 17144 0 ustar 0 0 <html>
#include "$ViewServerSupport.resourceDir/templates/Copyright.tml"
<head>
<title>The Current View: $View</title>
#include "$ViewServerSupport.resourceDir/templates/Acctiva.style"
</head>
<body>
#foreach $view in $View.peers.set {
View Identifier: $view.ViewIdentifier.Value</a><br>
<br>Locale Sensitive Name: $Term.lookup($View.viewLabel, $User.Locale)
<p>
#foreach $field in $view.ViewableFields {
$field.MetaField.LocaleKey: $field.MetaField.OutputControl.render($FastWriter, $field)<br>
}
<br>
}
</body>
</html>
webmacro-src-1.1final/examples/advanced/ViewFactory.java 100644 0 0 1461 7605651403 20560 0 ustar 0 0 /*
* Copyright Acctiva Corporation, 2000.
*
* Software is governed and protected under the patent,
* copyright and trademark laws of governing countries
* and this code and embodiment herein has been registered in the
* the United States with the Patent and Trademark Office.
*
* Right to use is strictly licensed by Acctiva corporation.
*
* Direct all questions and comments to support@acctiva.com.
*/
package com.acctiva.views;
import javax.servlet.http.HttpServletRequest;
import org.opendoors.store.*;
/**
* The base class for all classes which can be requested to create
* a view.
*/
abstract public class ViewFactory {
/** Create the view associated with the implementation. */
abstract public View createView(HttpServletRequest request,
String contextLink) throws Exception;
}
webmacro-src-1.1final/examples/advanced/wizard.tml 100644 0 0 2305 7605651403 17467 0 ustar 0 0 <!--
wizard.tml
-->
## wizard.tml Standard processing according to the layout provided.
<table $Skin.InputTableStyle>
<tr bgcolor=$Skin.GridHeaderColor><td COLSPAN="2" align=right><font color=$Skin.TextColorLight>$Term.lookup($View.viewLabel, $User.Locale)</font></td></tr>
<form action="/wizardform.tml" method=GET target="_top">
<input type=hidden name="vid" value="$View.ViewIdentifier.Value">
#alternate $color through [ $Skin.GridOddColor, $Skin.GridEvenColor ]
#foreach $field in $View.ViewableFields {
<tr bgcolor="$color">
<td align=right>
$field.MetaField.getLabel($User.Locale):
</td>
<td #if ($field.inputError) { bgcolor="red" }>
$field.MetaField.InputControl.render($FastWriter, $field, $User.Locale)
</td>
</tr>
}
<tr>
<td colspan=2 align=right valign=center bgcolor="$Skin.FormActionColor">
#foreach $action in $View.Actions {
<input
#if ($View.inWindow && ($action.verb.name == "cancel")) { onClick="window.close()" }
#if ($View.inWindow && ($action.verb.name == "close")) { onClick="window.close()" }
type=submit name=$action.verb.name value=$Term.lookup($action.verb.localeLabel, $User.Locale)>
}
</td>
</tr>
</form>
</table>
webmacro-src-1.1final/examples/advanced/wizardform.tml 100644 0 0 2632 7605651403 20356 0 ustar 0 0 <!--
wizardform.tml
-->
##
## wizardform.tml
##
<!--
wizardform.tml
Copyright 2001. Acctiva Corporation.
-->
## Top Level Script for handling wizard forms
#set $vid = $Request.getParameter("vid")
#if ($vid) {
<!-- Processing $vid from Request. -->
#set $SubmittedView = $Storage.get($vid)
#set $View = $SubmittedView.dispatchAction($Request)
#set $vid = $View.ViewIdentifier.Value.toString()
#if ($Storage.put($vid, $View)) {}
}
#else {
<!-- Evaluating $SubmittedView as current input -->
#set $View = $SubmittedView
#set $vid = $View.ViewIdentifier.Value.toString()
#if ($Storage.put($vid, $View)) {}
}
<!--
View.actionTaken.name=$View.actionTaken.name
View.inWindow=$View.inWindow
View.contextLink=$View.contextLink
locale=$User.Locale
-->
#if ($View.actionTaken.name == "cancel" || $View.actionTaken.name == "close") {
## action has been taken to exit this wizard context
##parse "$View.contextLink"
$Response.sendRedirect($View.contextLink)
}
#elseif ($View.actionTaken.name == "search") {
#parse "$View.performAction"
}
#elseif ((! $View.inWindow) && $View.actionTaken.name == "commit") {
##parse "$View.contextLink"
$Response.sendRedirect($View.contextLink)
}
#elseif ($View.commitView) {
#parse "commitaction.tml"
}
#elseif ($View.multiValueView) {
#parse "frameform.tml"
}
#elseif ($View.searchView) {
#parse "framesearch.tml"
}
#else {
#parse "header.tml"
#parse "wizard.tml"
#parse "footer.tml"
}
webmacro-src-1.1final/examples/allguest.wm 100644 0 0 1126 7605651403 16071 0 ustar 0 0 <html><head><title>View GuestBook!</title></head>
#set $Response.ContentType = "text/html"
<body bgcolor="white">
<h1><font color="green">View GuestBook</font></h1>
<p>Guest List</p>
<TABLE ALIGN="CENTER" width="600" border="1">
<TR>
<TD font color="red" align="center">NAME</TD>
<TD font color="red" align="center">E-MAIL</TD>
<TD font color="red" align="center">COMMENT</TD>
</TR>
#foreach $guest in $registry {
<TR>
<TD>$guest.Name</TD>
<TD>$guest.Email</TD>
<TD>$guest.Comment</TD>
</TR>
}
</TABLE>
<a href="GuestBook?loadFile=allguest">
See Guests</a>
</body></html>
webmacro-src-1.1final/examples/callgraph.wm 100644 0 0 422 7605651403 16164 0 ustar 0 0
#set $tmpl = "callgraph.wm"
<li>$callgraph.Time: $callgraph.Name ($callgraph.Calls)
#set $children = $callgraph.Children
#if ($children) {
<ul>
#foreach $node in $children {
#set $callgraph = $node
#parse "$tmpl"
}
</ul>
} #else {
No kids.
}
webmacro-src-1.1final/examples/CheckConfig.java 100644 0 0 12672 7605651403 16742 0 ustar 0 0 import org.webmacro.servlet.*;
import org.webmacro.*;
import java.util.*;
import java.io.StringWriter;
import java.io.PrintWriter;
import javax.servlet.http.*;
import javax.servlet.ServletException;
/**
*
* @author Keats Kirsch
* @version 1.0
* @since 11-Sep-01
*/
public class CheckConfig extends WMServlet {
final static public boolean DEBUG = true;
final static public String DEFAULT_TEMPLATE = "default.wm";
private Log _log = null;
public Template handle(WebContext context) throws HandlerException {
HttpSession sess = null;
try {
//TODO:
/* Get template path
* Get env info (OS, JVM, classpath, ...)
*
*/
// get WM properties, put sorted entry set into context
Properties wmProps = getBroker().getSettings().getAsProperties();
TreeMap settings = new TreeMap(wmProps);
context.put("Settings", settings.entrySet());
// get system properties, put sorted entry set into context
Properties sysProps = System.getProperties();
TreeMap sysPropMap = new TreeMap(sysProps);
context.put("SysProps", sysPropMap.entrySet());
javax.servlet.ServletConfig sconf = getServletConfig();
TreeMap servletParms = new TreeMap();
Enumeration e = sconf.getInitParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
servletParms.put(key, sconf.getInitParameter(key));
servletParms.put(key, getInitParameter(key));
}
context.put("ServletParms", servletParms.entrySet());
javax.servlet.ServletContext sc = this.getServletContext();
TreeMap scAttribs = new TreeMap();
Enumeration e2 = sc.getAttributeNames();
while (e2.hasMoreElements()){
String key = (String)e2.nextElement();
scAttribs.put(key, sc.getAttribute(key));
}
context.put("ServletContextAttributes", scAttribs.entrySet());
String jsdkVer = "2.0";
try {
jsdkVer = sc.getMajorVersion() + "." + sc.getMinorVersion();
}
catch (NoSuchMethodError nsme) {
}
context.put("JSDK_Version", jsdkVer);
java.net.URL url = getBroker().getResource(Broker.WEBMACRO_DEFAULTS);
context.put("WEBMACRO_DEFAULTS", url.toExternalForm());
// find the WebMacro.properties file if any
url = null;
if (!"2.0".equals(jsdkVer)){
url = getBroker().getResource("WEB-INF/" + Broker.WEBMACRO_PROPERTIES);
}
if (url == null){
url = getBroker().getResource(Broker.WEBMACRO_PROPERTIES);
}
if (url != null){
context.put("WEBMACRO_PROPERTIES", url.toExternalForm());
}
else {
context.put("WEBMACRO_PROPERTIES", "[none]");
}
Template t = getTemplate("CheckConfig.wm");
return t;
}
catch (Exception e){
context.put("stackTrace", getStackTrace(e));
throw new HandlerException(e.getMessage());
}
}
/**
* This is called when the servlet environment initializes
* the servlet for use via the init() method.
* @exception ServletException to indicate initialization failed
*/
protected void start() throws ServletException {
// get the log
//_log = org.webmacro.util.LogSystem.getInstance().getLog("WMTest", "WMTest log");
_log = org.webmacro.util.LogSystem.getInstance().getLog(null);
_log.info(this.getClass().getName() + ".start() invoked.");
} // start()
/**
* This is called when the servlet environment shuts down the servlet
* via the shutdown() method. The default implementation does nothing.
*/
protected void stop() {
}
/** debugging utility - dumps list of request headers from a WebContext */
static public void printRequestHeaders(WebContext context){
HttpServletRequest req = context.getRequest();
java.util.Enumeration hdrs = req.getHeaderNames();
int hdrCnt = 0;
while (hdrs.hasMoreElements()){
hdrCnt++;
String hdr = (String)hdrs.nextElement();
String val = (String)req.getHeader(hdr);
System.out.println("Req header " + hdrCnt + ", " + hdr + "=" + val);
}
}
/** write the stack trace from an exception into a string */
static public String getStackTrace(Throwable e){
if (e == null) return null;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
public class KeyValuePair implements java.lang.Comparable {
public String key = null;
public String value = null;
public KeyValuePair(String key, String value){
this.key = key;
this.value = value;
}
public String getKey(){ return key; }
public String getValue(){ return value; }
public int compareTo(java.lang.Object obj) {
return key.compareTo(((KeyValuePair)obj).getKey());
}
}
} // class CheckConfig
webmacro-src-1.1final/examples/CheckConfig.wm 100644 0 0 3251 7605651403 16415 0 ustar 0 0 <html>
<head>
<TITLE>WebMacro Configuration</TITLE>
</HEAD>
<body bgcolor='#ffffcc'>
<h2>WebMacro Configuration</h2>
<h3>Current Settings</h3>
JSDK Version: $JSDK_Version<br>
ContextPath: $Request.ContextPath<br>
<h4>Configuration File Locations</h4>
WebMacro.defaults: $WEBMACRO_DEFAULTS<br>
WebMacro.properties: $WEBMACRO_PROPERTIES<br>
#alternate $color through ["#ffcc66", "#ffffcc"]
<br>
<table border='1'>
#foreach $Setting in $Settings indexing $i from 1
<tr bgcolor='$color'>
<td>$i</td>
<td>$Setting.Key</td>
<td>$Setting.Value </td>
</tr>
#end
</table>
<h3>Request Headers</h3>
<table border='1'>
#foreach $hdr in $Request.HeaderNames indexing $i from 1
<tr bgcolor='$color'>
<td>$i</td>
<td>$hdr</td>
<td>$Request.getHeader($hdr) </td>
</tr>
#end
</table>
<h3>System Settings</h3>
<table border='1'>
#foreach $Prop in $SysProps indexing $i from 1
<tr bgcolor='$color'>
<td>$i</td>
<td>$Prop.Key</td>
<td>$Prop.Value </td>
</tr>
#end
</table>
<h3>Servlet Initialization Parameters</h3>
#if ($ServletParms.size()==0)
None
#else
<table border='1'>
#foreach $Prop in $ServletParms indexing $i from 1
<tr bgcolor='$color'>
<td>$i</td>
<td>$Prop.Key</td>
<td>$Prop.Value </td>
</tr>
#end
</table>
#end
<h3>Servlet Context Attributes</h3>
#if ($ServletContextAttributes.size()==0)
None
#else
<table border='1'>
#foreach $Prop in $ServletContextAttributes indexing $i from 1
<tr bgcolor='$color'>
<td>$i</td>
<td>$Prop.Key</td>
<td>$Prop.Value </td>
</tr>
#end
</table>
#end
</body>
</html>
webmacro-src-1.1final/examples/error.wm 100644 0 0 255 7605651403 15364 0 ustar 0 0 <html><head><title>ERROR!</title></head>
#set $Response.ContentType = "text/html"
<body bgcolor="white">
<h1><font color="green">ERROR!</font></h1>
$error
</body></html>
webmacro-src-1.1final/examples/form.wm 100644 0 0 1724 7605651403 15220 0 ustar 0 0 <html><head><title>GuestBook Example</title></head>
#set $Response.ContentType = "text/html"
<body bgcolor="white">
<h1><font color="green">GuestBook Example</font></h1>
<p> This sample webmacro script will collect form data and then interpret
the form data and return the information in a table.
<FORM METHOD="POST" ACTION="GuestBook">
<TABLE ALIGN="CENTER" width="600">
<INPUT TYPE="HIDDEN" NAME="loadFile" VALUE="verify">
<TR><TD font color="red">Your Name:</TD><TD font color="green"><INPUT TYPE="TEXT" NAME="name" VALUE=""></TD></TR>
<TR><TD font color="red">e-Mail:</TD><TD font color="green"><INPUT TYPE="TEXT" NAME="email" VALUE=""></TD></TR>
<TR><TD font color="red">Comment:</TD><TD font color="green"><TEXTAREA NAME="comment" COLS="60" ROWS="25" WRAP="HARD"></TEXTAREA></TD></TR>
<TR><TD ALIGN="CENTER" COLSPAN="2"><INPUT TYPE="SUBMIT" NAME="ACTION" VALUE="SUBMIT"></TD></TR>
</TABLE>
</FORM>
<a href="GuestBook?loadFile=allguest">
See Guests</a>
</body></html>
webmacro-src-1.1final/examples/GuestBook.java 100644 0 0 7351 7605651403 16457 0 ustar 0 0
/*
* Copyright (c) 1998, 1999 Semiotek Inc. All Rights Reserved.
*
* This software is the confidential intellectual property of
* of Semiotek Inc.; it is copyrighted and licensed, not sold.
* You may use it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation. If you
* do not want to use the GPL, you may still use the software after
* purchasing a proprietary developers license from Semiotek Inc.
*
* This software is provided "as is", with NO WARRANTY, not even the
* implied warranties of fitness to purpose, or merchantability. You
* assume all risks and liabilities associated with its use.
*
* See the attached License.html file for details, or contact us
* by e-mail at info@semiotek.com to get a copy.
*/
import java.util.*;
import org.webmacro.servlet.*;
import org.webmacro.*;
import org.webmacro.util.*;
/**
* This is the "Guest Book" WebMacro example. To get it working, put this
* class (which has no package) in your servlet directory. Make
* sure WebMacro.jar is in your CLASSPATH and that you have edited
* WebMacro.properties appropriately.
*
* Start your servletrunner, connect to the port, and request the URL:
*
* http://...servletrunner.../servlet/GuestBook/
*
* You guestbook should now work.
*/
public class GuestBook extends WMServlet
{
ArrayList book = new ArrayList();
String name;
String email;
String comment;
GuestEntry myGuestEntry;
final static private boolean debug = false;
public Template handle(WebContext context)
throws HandlerException
{
context.getResponse().setContentType("text/html");
Object output = new Object();
String templateName;
// get the form variables
output = (String) context.getForm("loadFile");
name = (String) context.getForm("name");
email = (String) context.getForm("email");
comment = (String) context.getForm("comment");
if (output == null) {
output = "form.wm";
templateName = "form.wm";
}
if (name == null) {
name = "<!-- form variable 'name' not defined -->";
}
if (email == null) {
email = "<!-- form variable 'email' not defined -->";
}
if (comment == null) {
comment = "<!-- form variable 'comment' not defined -->";
}
// verifying for submissions
if (output.equals("verify")) {
myGuestEntry = new GuestEntry(name, email, comment);
book.add(myGuestEntry);
context.put("registry", book);
templateName = "verify.wm";
// for guest book view
} else if (output.equals("allguest")) {
context.put("registry",book);
templateName = "allguest.wm";
// default
} else {
templateName = "form.wm";
}
// return the appropriate template
try {
Template t = getTemplate(templateName);
return t;
} catch (Exception e) {
throw new HandlerException("Could not load template: "
+ templateName
+ ".<br><br>The system reported the following error:<br>" + e.getMessage());
}
}
public final class GuestEntry
{
final private String name;
final private String email;
final private String comment;
GuestEntry(String inName, String inEmail, String inComment)
{
name = inName;
email = inEmail;
comment = inComment;
}
final public String getName()
{
return name;
}
final public String getEmail()
{
return email;
}
final public String getComment()
{
return comment;
}
}
}
webmacro-src-1.1final/examples/HelloWorld.java 100644 0 0 7753 7605651403 16636 0 ustar 0 0
// import the WebMacro core interfaces
import org.webmacro.*;
// import the WebMacro servlet classes
import org.webmacro.servlet.*;
/**
* HelloWorld -- the simplest possible WebMacro servlet.
* The easiest way to create a WebMacro servlet is to
* subclass from org.webmacro.servlet.WMServlet
*
* Before trying to run this example, be sure to do
* all of the following:
*
* 1. Add webmacro.jar to your CLASSPATH
*
* 2. Compile this servlet and install it in your servlet directory
*
* 3. Add webmacro.jar to your servlet runner's classpath
*
* 4. Put your template (helloWorld.wm) in your "application directory"
* if using Servlet 2.2. Or in your servlet container CLASSPATH otherwise.
*
* 5. Start your servlet runner
*
*/
public class HelloWorld extends WMServlet
{
/**
* WebMacro creates a WebContext and passes it to your servlet.
* The WebContext contains all the information you'll need to
* handle the request. It is also the only object you share
* with the template. If you add objects to the WebContext via
* its put(key,value)method,they become available in the
* template as variables named after the key.
*/
public Template handle(WebContext context) throws HandlerException
{
// Put whatever data you like into the context. In
// this example we just put in a simple string
context.put("Hello", "Hello, brave new world!");
// Select a template. You could choose the template based
// on any criteria you like: user preference, current
// action, different templates for different results, etc.
// We need to acquire a template somehow
Template view;
try {
// The following line asks WebMacro's resource broker to
// find the "helloWorld.wm" template, cache it, and return a
// parsed copy to us.
view = getTemplate("helloWorld.wm");
} catch (ResourceException e) {
// If this happens you have not set WebMacro up correctly:
// either WebMacro isn't up and running well enough to be able
// to locate any template, or else we asked for a template which
// doesn't exist. However, the HelloWorld.wm example should exist
// if you have everything set up properly!
throw new HandlerException(
"HelloWorld loaded and executed OK, but was unable to load \n"
+ "a template. There are a couple of things that could be wrong \n"
+ "here. First, you may have put webmacro.properties somewhere \n"
+ "outside your servlet classpath. Try putting it in the same \n"
+ "place as you put webmacro.jar. Second, you may have set the \n"
+ "TemplateRoot directory incorectly. The file helloWorld.wm \n"
+ "must be in one of the directories listed in that option in \n"
+ "the webmacro.properties file. You should check the server \n"
+ "logs or output (or WebMacro's log if it's set and being used \n"
+ "for helpful messages which may indicate what the problem is. \n"
+ "Since your servlet runner may have d fewifferent classpath \n"
+ "settings, check that webmacro.properties is in the same \n"
+ "classpath that was used to load webmacro.jar. \n"
+ "\n", e);
}
// Now that we have done all our processing, it's time to produce
// some output. We return the template we have created. WebMacro
// will automatically execute it for us. If you don't want this
// to happen, you can return "null" instead and WebMacro will
// do nothing--leaving you responsible for what is returned to
// the user. You could execute the template yourself if wanted,
// giving you a chance to do some post execution cleanup--in
// that case you would do a view.execute(context) here, followed
// by whatever you wanted to do, followed by a return null.
return view;
}
}
webmacro-src-1.1final/examples/helloWorld.wm 100644 0 0 1457 7605651403 16373 0 ustar 0 0 <html><head><title>Hello, World!</title></head>
## You have to set the content type. You could do this from
## the servlet instead--but this way your page designer can
## change it if XML was wanted. What the line below does is
## use WebMacro's introspection to find and use the method:
##
## WebContext.getResponse().setContentType("text/html")
#set $Response.ContentType = "text/html"
## Now the rest of your HTML, including a few example WebMacro
## statements, just for fun. Note the use of the $Hello variable
## which is defined in the HelloWorld servlet.
<h1>WebMacro is working!</h1>
<ul>
#set $go = "<font color=red size=+1><b>$Hello</b></font>"
#foreach $count in [ "five", "four", "three", "two", "one", "$go" ] {
<li>$count
}
</ul>
Thanks for looking into WebMacro!
</body></html>
webmacro-src-1.1final/examples/index.html 100644 0 0 605 7605651403 15662 0 ustar 0 0 <html>
<body>
<H1>WebMacro Examples</H1>
<ol>
<li><a href="servlet/HelloWorld">Hello World</a>
<li><a href="servlet/GuestBook">Guest Book</a>
<li><a href="servlet/Profile">Profile</a>
<li><a href="servlet/Standalone">Standalone</a>
<li><a href="servlet/SandBox">Sand Box</a>
</ol>
</body>
</html>
webmacro-src-1.1final/examples/NoServlet.java 100644 0 0 3002 7605651403 16463 0 ustar 0 0
/*
* Copyright (c) 1998, 1999, 2000 Semiotek Inc. All Rights Reserved.
*
* This software is the confidential intellectual property of
* of Semiotek Inc.; it is copyrighted and licensed, not sold.
* You may use it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation. If you
* do not want to use the GPL, you may still use the software after
* purchasing a proprietary developers license from Semiotek Inc.
*
* This software is provided "as is", with NO WARRANTY, not even the
* implied warranties of fitness to purpose, or merchantability. You
* assume all risks and liabilities associated with its use.
*
* See the attached License.html file for details, or contact us
* by e-mail at info@semiotek.com to get a copy.
*/
import org.webmacro.*;
import java.util.Date;
/**
* This example demonstrates using WebMacro outside the context of a servlet.
*/
public class NoServlet
{
public static void main(String[] args) throws Exception {
WM wm = new WM();
Context c = new Context(wm.getBroker());
// fill up the context with our data
c.put("Today", new Date());
c.put("Number", new Long(23));
c.put("hello", "Hello there!");
// get the template we intend to execute
Template t = wm.getTemplate("noservlet.wm");
// Create FastWriter for fast output encoding
FastWriter fw = wm.getFastWriter (System.out, "UTF8");
// write the template to the output, using our context
t.write(fw, c);
fw.close();
}
}
webmacro-src-1.1final/examples/noservlet.wm 100644 0 0 124 7605651403 16247 0 ustar 0 0 WebMacro "NoServlet" example!
Hello is $hello
Today is $Today
Number is $Number
webmacro-src-1.1final/examples/Profile.java 100644 0 0 5453 7605651403 16156 0 ustar 0 0
// import the WebMacro core interfaces
import org.webmacro.*;
// import the WebMacro servlet classes
import org.webmacro.servlet.*;
import org.webmacro.util.*;
import org.webmacro.profile.*;
/**
* Profile servlet checks to see if profiling has been enabled
* and if it has prints out some statistics about how WebMacro
* has been performing. Note that to enable profiling you need
* to do two things: enable it in org.webmacro.Flags and also
* in the WebMacro.properties file.<p>
*
*
* ******NOTICE*****
* To use this example, *you* must enable the #profile directive
* by adding the following lines to your local WebMacro.properties file.
*
* Directives.profile: org.webmacro.directive.ProfileDirective
* Profile.rate: 0
*
* If you don't have a WebMacro.properties file, simply make one
* and place it in the CLASSPATH of your JDK, servlet container, or
* web-app.
*
*/
public class Profile extends WMServlet
{
/**
* WebMacro creates a WebContext and passes it to your servlet.
* The WebContext contains all the information you'll need to
* handle the request. It is also the only object you share
* with the template. If you add objects to the WebContext via
* its put(key,value)method,they become available in the
* template as variables named after the key.
*/
public Template handle(WebContext context) throws HandlerException
{
try {
ProfileSystem ps = ProfileSystem.getInstance();
context.startTiming("getProfileCategories");
ProfileCategory[] pc = ps.getProfileCategories();
context.stopTiming();
context.put("cats", pc);
context.put("compiled", Flags.PROFILE ? Boolean.TRUE : Boolean.FALSE);
context.startTiming("CallGraph.init");
if (pc != null) {
CallGraph[] cg = new CallGraph[ pc.length ];
for (int i = 0; i < pc.length; i++) {
cg[i] = new CallGraph(pc[i]);
}
context.put("stats", cg);
context.put("status", "All OK");
} else {
context.put("status", "No profiling information");
}
context.stopTiming();
} catch (Exception e) {
context.put("status", e);
e.printStackTrace();
}
Template view;
context.startTiming("getTemplate");
try {
view = getTemplate("profile.wm");
} catch (ResourceException e) {
throw new HandlerException(
"Profiler was unable to load the template profile.wm: your"
+ " WebMacro system is not set up properly. Please get "
+ " WebMacro working before trying out the Profiler\n\n"
+ "Here is the actual exception that was raised:\n" + e);
}
context.stopTiming();
return view;
}
}
webmacro-src-1.1final/examples/profile.wm 100644 0 0 3646 7605651403 15722 0 ustar 0 0 #comment {
******NOTICE*****
To use this example, *you* must enable the #profile directive
by adding the following lines to your local WebMacro.properties file.
Directives.profile: org.webmacro.directive.ProfileDirective
Profile.rate: 0
If you don't have a WebMacro.properties file, simply make one
and place it in the CLASSPATH of your JDK, servlet container, or
web-app.
}
<html><head><title>WebMacro Profile</title></head>
#set $Response.ContentType = "text/html"
<h1>WebMacro Profile Statistics</h1>
<b>Profiling Status: <pre>$status</pre></b>
<p>
#if (!$compiled) {
<b>PROFILING WAS NOT ENABLED IN org.webmacro.Flags</b>
}
<p>
#profile "TemplateStats" {
Profile categories:
<ul>
#profile "categories" {
#foreach $cat in $cats {
<li>$cat
</ul>
}
<p>
}
Profile Stats:
<ul>
#profile "callgraph" {
#foreach $node in $stats {
#profile "node" {
#set $callgraph = $node
#parse "callgraph.wm"
}
}
}
</ul>
}
#profile "StaticText" {
This profiling servlet displays results that are created by WebMacro
when profiling is enabled. There are three requirements for the
collection of profiling data:
<ul>
<li>org.webmacro.Flags.PROFILE = true (and all code compiled that way)
<li>In WebMacro.properties Profile.rate = 1 (some positive value)
<li>In WebMacro.properties Profile.time = 120000 (some positive value)
</ul>
The next question is how you get profile data. WebMacro automatically
collects some data on its own if you use WMServlet and the Context.
If you use WebMacro in standalone mode you have to instrument the
code yourself by calling context.startTiming() and context.stopTiming()
in your code.
<p>
In addition to that there is a \#profile directive which you can
use to block off sections of your templates for specific timing.
}
</body></html>
webmacro-src-1.1final/examples/README 100644 0 0 7047 7605651403 14574 0 ustar 0 0
WebMacro Examples
=================
These trivial examples are intended to help you get started with
WebMacro. We suggest you try the HelloWorld example first, as it
is the easiest to get going.
[NOTE: For information on getting the examples configured on your system see
the document CONFIGURING-EXAMPLES in the webroot directory of this
distribution or the Wiki page at http://www.webmacro.org/ConfiguringExamples]
In each case you will find comments inside the .java file explaining
what the example is, and how to get it working.
Previous versions of WebMacro *required* you to customize the WebMacro.properties
file, espically the "TemplatePath" value. This is no longer required! In fact,
in most cases you don't even need a WebMacro.properties file!
Included in the webmacro.jar file is a file named "WebMacro.defaults". This
file contains all the default configuration settings for WebMacro. Should
you need to change a key/value, DO NOT change it in the WebMacro.defaults.
Create a new file, "WebMacro.properties", and put in it *only* the keys/values
you wish to change. WebMacro first loads it's .defaults, then if it exists
loads WebMacro.properties overriding any values set by .defaults.
Also, you no longer need to specify a TemplatePath. WebMacro, depending on your
execution environment, will automagically find your templates:
1) WM in standalone mode (ie, not in a servlet):
If using the "new WM();" constructor, WebMacro will search for templates in
your system CLASSPATH
2) WM in a Servlet 2.0 environment (ie, Apache/JServ):
WebMacro will search for templates in your servlet container CLASSPATH
3) WM in a Servlet >2.0 environment (ie, Turbine or Resin):
WebMacro will search for templates in your "application directory". This
means different things for different servlet runners, but will include either
your "htdocs" directory or your WEB-INF/ directory/.war file.
Below is an overview of the examples included with this release:
HelloWorld
----------
A servlet. Demonstrates the basic workings of WebMacro, with lots
of comments explainig each step. Try installing this one first.
GuestBook
---------
A servlet. Intended to give you an application with several
different templates, so you can experiment with customizing it.
Also shows WebMacro using and introspecting some ordinary objects.
Profile
-------
A servlet that illustrates how to use the #profile directive to time
various operations in a WebMacro application.
To use this example, you must enable the #profile directive. See the
comments in profile.wm or Profile.java for more information.
Standalone
----------
An advanced HelloWorld servlet that does *not* subclass WMServlet. This
example, although a servlet, manages it's own WebMacro instance internally.
It also demonstrates how to create FastWriters, Contexts, and how to write
Templates. If you're trying to fit WebMacro into an existing servlet
application, this example will be of the most benefit for you.
Sandbox
-------
A servlet. This is basically another version of the HelloWorld servlet.
It is provided as a place where you can start playing with WebMacro by
just editing the template -- sandbox.wm -- and the servlet Sandbox.java.
Have fun exploring.
NoServlet
---------
A standalone command-line program which demonstrates how to create
a WebMacro instance and a Context along with getting and writing
a template. If you plan on using WebMacro outside of a servlet
environment, look here first!
webmacro-src-1.1final/examples/SandBox.java 100644 0 0 2700 7605651403 16104 0 ustar 0 0 import org.webmacro.*;
import org.webmacro.servlet.*;
/**
* SandBox - where to play
*/
public class SandBox extends WMServlet
{
public Template handle(WebContext context) throws HandlerException
{
// Put whatever data you like into the context. In
// this example we just put in a simple string
context.put("Hello", "Hello, brave new world!");
// Select a template. You could choose the template based
// on any criteria you like: user preference, current
// action, different templates for different results, etc.
// We need to acquire a template somehow
Template view;
try {
// The following line asks WebMacro's resource broker to
// find the "helloWorld.wm" template, cache it, and return a
// parsed copy to us.
view = getTemplate("sandbox.wm");
} catch (ResourceException e) {
// If this happens you have not set WebMacro up correctly:
// either WebMacro isn't up and running well enough to be able
// to locate any template, or else we asked for a template which
// doesn't exist. However, the HelloWorld.wm example should exist
// if you have everything set up properly!
throw new HandlerException(
"SandBox was unable to load \n"
+ "a template. \n\n"
+ "Here is the actual exception that was raised:\n" + e);
}
return view;
}
}
webmacro-src-1.1final/examples/sandbox.wm 100644 0 0 100 7605651403 15656 0 ustar 0 0 <html>
<body>
<h1>Sand Box</h1>
</body>
</html>
webmacro-src-1.1final/examples/Standalone.java 100644 0 0 15323 7605651403 16663 0 ustar 0 0
/*
* Copyright (c) 1998, 1999, 2000 Semiotek Inc. All Rights Reserved.
*
* This software is the confidential intellectual property of
* of Semiotek Inc.; it is copyrighted and licensed, not sold.
* You may use it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation. If you
* do not want to use the GPL, you may still use the software after
* purchasing a proprietary developers license from Semiotek Inc.
*
* This software is provided "as is", with NO WARRANTY, not even the
* implied warranties of fitness to purpose, or merchantability. You
* assume all risks and liabilities associated with its use.
*
* See the attached License.html file for details, or contact us
* by e-mail at info@semiotek.com to get a copy.
*/
import org.webmacro.*;
import org.webmacro.servlet.WebContext;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
/**
* This example demonstrates using WebMacro in "standalone" mode. Instead
* of subclassing from WMServlet you create and maintain your own WebMacro
* object, and you are free to subclass from another servlet. Also, this
* technique can be used outside the servlet context.
* <p>
* The WebMacro master object is initialized when the servlet is initialized
* and destroyed when the servlet is destroyed. There is some overhead
* involved in creating the interface so you should prefer not to create one
* on every request.
* <p>
* This servlet can be compiled and installed as an ordinary servlet. You
* need to ensure that your WebMacro.defaults (and possible WebMacro.properties)
* file is properly configured and available on your CLASSPATH.
* <p>
* When setting up WebMacro.properties make sure that the TemplatePath is
* correctly set and that the template used by this servlet, "standalone.wm",
* is available on that path.
* <p>
* If you do not create a custom WebMacro.properties, WebMacro will attempt
* to load templates from the CLASSPATH.
*/
public class Standalone extends HttpServlet
{
/**
* This is the core WebMacro interface which we use to create Contexts,
* load Templates, and begin other WebMacro operations.
*/
private WebMacro _wm = null;
/**
* The init() method will be called by your servlet runner whenever
* it wants to instantiate a new copy of your servlet. We initialize
* WebMacro here so as to avoid the expense of initializing it on
* every request.
*/
public void init(ServletConfig sc) throws ServletException {
try {
if (_wm == null) {
_wm = new WM();
}
} catch (InitException e) {
throw new ServletException("Could not initialize WebMacro: " + e);
}
}
/**
* It's not strictly necessary to destroy the WebMacro object when
* you're done with it--garbage collection will eventually get it--but
* it makes sure the resources get freed. You really ought to do this,
* since it might be a lot of resources.
*/
public void destroy() {
if (_wm != null) {
_wm.destroy();
_wm = null;
}
}
/**
* We only implement the GET method in this servlet.
* <p>
* We create a WebContext object, populate it with some data, select
* a template, and write the output of that template to the output
* stream. Note that you need to pass the WebContext object to the
* template in order to write it, you also need an output stream, in
* this case the HttpServletResponse output stream is used.
* <p>
* If you were using WebMacro outside a servlet context you would not
* be able to construct a WebContext object, since you would not have
* the HttpServletRequest and HttpServletResponse objects which you
* need in order to do that. WebContext is a subclass of Context, so
* outside of a servlet just construct a Context object. You will
* obviously lose the ability to talk about servlet specific things
* in your templates (such as "Cookies") but otherwise it's the same.
* <p>
* There are a few exceptions you have to deal with. First, WebMacro
* may not be able to locate the template you've requested in which
* case it'll throw a NotFoundException. Second, the template will
* expect to find certain information in the Context, and if you fail
* to provide that information a ContextException will be thrown. Aside
* than WebMacro, in a servlet environment you also have to deal with
* the IOException that can be thrown if something goes wrong with
* the network connection back to the client.
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
try {
try {
// create a context for the current request
WebContext c = _wm.getWebContext(req,resp);
// fill up the context with our data
c.put("Today", new Date());
c.put("Number", new Long(23));
// WebContext provides some utilities as well
String other = c.getForm("other");
if (other == null) {
c.put("hello","hello again!"); // put this into the hash
} else {
c.put("hello",other); // else put this in
}
// get the template we intend to execute
Template t = _wm.getTemplate("standalone.wm");
// Create FastWriter for fast output encoding
FastWriter fw = _wm.getFastWriter(resp.getOutputStream(),
resp.getCharacterEncoding());
// write the template to the output, using our context
t.write(fw, c);
fw.close();
} catch (org.webmacro.ResourceException e) {
FastWriter out = _wm.getFastWriter(resp.getOutputStream(),
resp.getCharacterEncoding());
out.write("ERROR! Could not locate template standalone.wm, check that your template path is set properly in WebMacro.properties");
out.close();
} catch (org.webmacro.ContextException e) {
FastWriter out = _wm.getFastWriter(resp.getOutputStream(),
resp.getCharacterEncoding());
out.write("ERROR! Could not locate required data in the Context.");
out.close();
}
} catch (java.io.IOException e) {
// what else can we do?
System.out.println("ERROR: IOException while writing to servlet output stream.");
}
}
} webmacro-src-1.1final/examples/standalone.wm 100644 0 0 2352 7605651403 16403 0 ustar 0 0