tcurdt 2002/10/29 11:53:11 Modified: src/blocks/precept/java/org/apache/cocoon/precept/acting AbstractMethodAction.java src/blocks/precept/samples sitemap.xmap src/blocks/precept/samples/example1 view1.xsl view2.xsl src/blocks/precept/samples/example2 i2html.xsl view1.xml view2.xml view3.xml view4.xml Log: some simplifications, examples under /coocoon/samples/precept/welcome (if included via properties.xml) Revision Changes Path 1.2 +71 -66 xml-cocoon2/src/blocks/precept/java/org/apache/cocoon/precept/acting/AbstractMethodAction.java Index: AbstractMethodAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/java/org/apache/cocoon/precept/acting/AbstractMethodAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractMethodAction.java 29 Oct 2002 15:48:33 -0000 1.1 +++ AbstractMethodAction.java 29 Oct 2002 19:53:10 -0000 1.2 @@ -99,11 +99,9 @@ */ - package org.apache.cocoon.precept.acting; - import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -121,17 +119,14 @@ import org.apache.cocoon.acting.ConfigurableComposerAction; - import java.util.HashMap; import java.util.Map; +import java.util.Enumeration; import java.lang.reflect.Method; - - - /* * @version: Feb 25, 2002 @@ -143,130 +138,140 @@ public abstract class AbstractMethodAction extends ConfigurableComposerAction { + private static final String ACTION_METHOD_PREFIX = "do"; - private static final String ACTION_METHOD_PREFIX = "do"; - - private static final String ACTION_METHOD_PARAMETER = "method"; - + private static final String ACTION_METHOD_PARAMETER = "method"; + private static final String ACTION_METHOD_REQUEST_PARAMETER_PREFIX = "cocoon-method-"; - private HashMap methodIndex = null; + private HashMap methodIndex = null; - - public void configure(Configuration conf) throws ConfigurationException { - - super.configure(conf); + public static final String extractMethod( Request request ) { + Enumeration parameterNames = request.getParameterNames(); + while (parameterNames.hasMoreElements()) { + String parameterName = (String) parameterNames.nextElement(); + if (parameterName.startsWith(ACTION_METHOD_REQUEST_PARAMETER_PREFIX)) { + return(parameterName.substring(ACTION_METHOD_REQUEST_PARAMETER_PREFIX.length())); + } + } + return(null); + } + public void configure(Configuration conf) throws ConfigurationException { - if (methodIndex == null) { + super.configure(conf); - try { - Method[] methods = this.getClass().getMethods(); + if (methodIndex == null) { - methodIndex = new HashMap(); + try { + Method[] methods = this.getClass().getMethods(); + methodIndex = new HashMap(); - int prefixLen = ACTION_METHOD_PREFIX.length(); - for (int i = 0; i < methods.length; i++) { + int prefixLen = ACTION_METHOD_PREFIX.length(); - String methodName = methods[i].getName(); + for (int i = 0; i < methods.length; i++) { - if (methodName.startsWith(ACTION_METHOD_PREFIX)) { + String methodName = methods[i].getName(); - String actionName = methodName.substring(prefixLen, prefixLen + 1).toLowerCase() + + if (methodName.startsWith(ACTION_METHOD_PREFIX)) { - methodName.substring(prefixLen + 1); + String actionName = methodName.substring(prefixLen, prefixLen + 1).toLowerCase() + - methodIndex.put(actionName, methods[i]); + methodName.substring(prefixLen + 1); - if (getLogger().isDebugEnabled()) { + methodIndex.put(actionName, methods[i]); - getLogger().debug("registered method \"" + methodName + "\" as action \"" + actionName + "\""); + if (getLogger().isDebugEnabled()) { - } + getLogger().debug("registered method \"" + methodName + "\" as action \"" + actionName + "\""); - } + } - } + } - } + } - catch (Exception e) { + } - throw new ConfigurationException("cannot get methods by reflection", e); + catch (Exception e) { - } + throw new ConfigurationException("cannot get methods by reflection", e); - } + } - } + } + } - public Map introspection( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { + public Map introspection(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { - return(EMPTY_MAP); + return (EMPTY_MAP); - } + } + public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { - public Map act( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { + String actionMethod = parameters.getParameter(ACTION_METHOD_PARAMETER, null); - String actionMethod = parameters.getParameter(ACTION_METHOD_PARAMETER,null); + if (actionMethod == null) { + actionMethod = extractMethod(ObjectModelHelper.getRequest(objectModel)); + getLogger().debug("no method specified as parameter, found in request: " + String.valueOf(actionMethod)); + } - if (actionMethod != null) { + if (actionMethod != null) { - Method method = (Method) methodIndex.get(actionMethod); + Method method = (Method) methodIndex.get(actionMethod); - if (method != null) { + if (method != null) { - getLogger().debug("calling method ["+ String.valueOf(actionMethod) + "]"); + getLogger().debug("calling method [" + String.valueOf(actionMethod) + "]"); - return((Map) method.invoke(this, new Object[]{ redirector,resolver,objectModel,source,parameters })); + return ((Map) method.invoke(this, new Object[]{redirector, resolver, objectModel, source, parameters})); - } + } - else { + else { - throw new Exception("action has no method \"" + actionMethod + "\""); + throw new Exception("action has no method \"" + actionMethod + "\""); - } + } - } + } - else { + else { - Request request = ObjectModelHelper.getRequest(objectModel); + Request request = ObjectModelHelper.getRequest(objectModel); + if (request != null && "GET".equalsIgnoreCase(request.getMethod())) { - if (request != null && "GET".equalsIgnoreCase(request.getMethod())) { + // just the first view of the page - // just the first view of the page + // call introspection - // call introspection + getLogger().debug("calling introspection"); - getLogger().debug("calling introspection"); + return (introspection(redirector, resolver, objectModel, source, parameters)); - return(introspection(redirector,resolver,objectModel,source,parameters )); + } - } + else { - else { + getLogger().debug("already in flow - no introspection"); - getLogger().debug("already in flow - no introspection"); + return (EMPTY_MAP); - return(EMPTY_MAP); + } - } + } } - - } } 1.2 +62 -82 xml-cocoon2/src/blocks/precept/samples/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/sitemap.xmap,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- sitemap.xmap 29 Oct 2002 15:48:35 -0000 1.1 +++ sitemap.xmap 29 Oct 2002 19:53:10 -0000 1.2 @@ -1,82 +1,62 @@ -<?xml version="1.0"?> - -<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> - - <map:components> - <map:generators default="file"/> - <map:transformers default="xslt"> - <map:transformer name="instance" src="org.apache.cocoon.precept.InstanceTransformer" logger="webapp.validation"/> - </map:transformers> - <map:readers default="resource"/> - <map:serializers default="html"/> - <map:matchers default="wildcard"/> - <map:selectors default="browser"/> - <map:actions> - <map:action name="demoflow" src="org.apache.cocoon.precept.acting.PreceptorDemoAction" logger="webapp.validation"/> - </map:actions> - </map:components> - - <map:action-sets> - <map:action-set name="demo"> - <map:act type="demoflow"/> - <map:act type="demoflow" action="prev1"> - <map:parameter name="method" value="prev1"/> - </map:act> - <map:act type="demoflow" action="prev2"> - <map:parameter name="method" value="prev2"/> - </map:act> - <map:act type="demoflow" action="prev3"> - <map:parameter name="method" value="prev3"/> - </map:act> - <map:act type="demoflow" action="prev4"> - <map:parameter name="method" value="prev4"/> - </map:act> - <map:act type="demoflow" action="next2"> - <map:parameter name="method" value="next2"/> - </map:act> - <map:act type="demoflow" action="next3"> - <map:parameter name="method" value="next3"/> - </map:act> - <map:act type="demoflow" action="next4"> - <map:parameter name="method" value="next4"/> - </map:act> - <map:act type="demoflow" action="submit"> - <map:parameter name="method" value="submit"/> - </map:act> - </map:action-set> - </map:action-sets> - - <map:pipelines> - <map:pipeline> - - <map:match pattern="**.html"> - <map:act type="request"> - - <map:match pattern="app/**"> - <map:match pattern="**/example1.*"> - <map:act set="demo"> - <map:generate src="example1/{page}.xml"/> - <map:transform type="instance"/> - <map:transform src="example1/{page}.xsl"/> - <map:serialize/> - </map:act> - </map:match> - </map:match> - - <map:match pattern="app/**"> - <map:match pattern="**/example2.*"> - <map:act set="demo"> - <map:generate src="example2/{page}.xml"/> - <map:transform type="instance"/> - <map:transform src="example2/i2html.xsl"/> - <map:serialize/> - </map:act> - </map:match> - </map:match> - - </map:act> - </map:match> - </map:pipeline> - - </map:pipelines> -</map:sitemap> +<?xml version="1.0"?> + +<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> + + <map:components> + <map:generators default="file"/> + <map:transformers default="xslt"> + <map:transformer name="instance" src="org.apache.cocoon.precept.InstanceTransformer" logger="webapp.validation"/> + </map:transformers> + <map:readers default="resource"/> + <map:serializers default="html"/> + <map:matchers default="wildcard"/> + <map:selectors default="browser"/> + <map:actions> + <map:action name="demo" src="org.apache.cocoon.precept.acting.PreceptorDemoAction" logger="webapp.validation"/> + </map:actions> + </map:components> + + <map:pipelines> + <map:pipeline> + + <map:match pattern=""> + <map:redirect-to uri="welcome"/> + </map:match> + + <map:match pattern="welcome"> + <map:generate src="index.xml"/> + <map:transform src="context://samples/common/style/xsl/html/simple-samples2html.xsl"/> + <map:serialize/> + </map:match> + + <map:match pattern="**.html"> + <map:act type="request"> + + <map:match pattern="app/**"> + <map:match pattern="**/example1.*"> + <map:act type="demo"> + <map:generate src="example1/{page}.xml"/> + <map:transform type="instance"/> + <map:transform src="example1/{page}.xsl"/> + <map:serialize/> + </map:act> + </map:match> + </map:match> + + <map:match pattern="app/**"> + <map:match pattern="**/example2.*"> + <map:act type="demo"> + <map:generate src="example2/{page}.xml"/> + <map:transform type="instance"/> + <map:transform src="example2/i2html.xsl"/> + <map:serialize/> + </map:act> + </map:match> + </map:match> + + </map:act> + </map:match> + </map:pipeline> + + </map:pipelines> +</map:sitemap> 1.2 +1 -1 xml-cocoon2/src/blocks/precept/samples/example1/view1.xsl Index: view1.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example1/view1.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view1.xsl 29 Oct 2002 15:48:35 -0000 1.1 +++ view1.xsl 29 Oct 2002 19:53:10 -0000 1.2 @@ -30,7 +30,7 @@ <td><xsl:apply-templates select="user/age/constraint"/></td> </tr> </table> - <input type="submit" name="cocoon-action-next2" value="Next Page"/> + <input type="submit" name="cocoon-method-next2" value="Next Page"/> </xsl:template> <xsl:template match="/|*"> 1.2 +2 -2 xml-cocoon2/src/blocks/precept/samples/example1/view2.xsl Index: view2.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example1/view2.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view2.xsl 29 Oct 2002 15:48:35 -0000 1.1 +++ view2.xsl 29 Oct 2002 19:53:10 -0000 1.2 @@ -27,8 +27,8 @@ </td> </tr> </table> - <input type="submit" name="cocoon-action-prev1" value="Prev Page"/> - <input type="submit" name="cocoon-action-next3" value="Next Page"/> + <input type="submit" name="cocoon-method-prev1" value="Prev Page"/> + <input type="submit" name="cocoon-method-next3" value="Next Page"/> </xsl:template> <xsl:template match="/|*"> 1.2 +11 -1 xml-cocoon2/src/blocks/precept/samples/example2/i2html.xsl Index: i2html.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example2/i2html.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- i2html.xsl 29 Oct 2002 15:48:36 -0000 1.1 +++ i2html.xsl 29 Oct 2002 19:53:11 -0000 1.2 @@ -10,6 +10,16 @@ </html> </xsl:template> + <xsl:template match="rows"> + <table border="1"> + <xsl:apply-templates/> + </table> + </xsl:template> + + <xsl:template match="row"> + <tr><td><xsl:apply-templates select="label"/></td><td><xsl:apply-templates select="i:*"/></td></tr> + </xsl:template> + <xsl:template match="i:output"> [<xsl:value-of select="i:value/text()"/>] </xsl:template> @@ -48,7 +58,7 @@ </xsl:template> <xsl:template match="i:button"> - <input name="cocoon-action-{@method}" type="submit" value="{i:caption/text()}" /> + <input name="cocoon-method-{@method}" type="submit" value="{i:caption/text()}" /> </xsl:template> <xsl:template match="*"> 1.2 +8 -7 xml-cocoon2/src/blocks/precept/samples/example2/view1.xml Index: view1.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example2/view1.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view1.xml 29 Oct 2002 15:48:36 -0000 1.1 +++ view1.xml 29 Oct 2002 19:53:11 -0000 1.2 @@ -4,14 +4,15 @@ <i:insert-violations/> </errors> - <i:instance id="form-feedback"> - <i:label>Firstname</i:label><i:textbox ref="cocoon-installation/user/firstname"/> - <i:label>Lastname</i:label><i:textbox ref="cocoon-installation/user/lastname"/> - <i:label>Email</i:label><i:textbox ref="cocoon-installation/user/email"/> - </i:instance> + <rows> + <i:instance id="form-feedback"> + <row><label>Firstname</label><i:textbox ref="cocoon-installation/user/firstname"/></row> + <row><label>Lastname</label><i:textbox ref="cocoon-installation/user/lastname"/></row> + <row><label>Email</label><i:textbox ref="cocoon-installation/user/email"/></row> + </i:instance> - <i:label>Age</i:label><i:textbox ref="cocoon-installation/user/age" instance="form-feedback"/> - + <row><label>Age</label><i:textbox ref="cocoon-installation/user/age" instance="form-feedback"/></row> + </rows> <i:button method="next2"> <i:caption>Next</i:caption> 1.2 +7 -5 xml-cocoon2/src/blocks/precept/samples/example2/view2.xml Index: view2.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example2/view2.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view2.xml 29 Oct 2002 15:48:36 -0000 1.1 +++ view2.xml 29 Oct 2002 19:53:11 -0000 1.2 @@ -4,11 +4,13 @@ <i:insert-violations/> </errors> - <i:instance id="form-feedback"> - <i:label>Number of installations</i:label><i:textbox ref="cocoon-installation/number"/> - <i:label>Live URL</i:label><i:textbox ref="cocoon-installation/live-url"/> - <i:label>Publish</i:label><i:selectBoolean ref="cocoon-installation/publish"/> - </i:instance> + <rows> + <i:instance id="form-feedback"> + <row><label>Number of installations</label><i:textbox ref="cocoon-installation/number"/></row> + <row><label>Live URL</label><i:textbox ref="cocoon-installation/live-url"/></row> + <row><label>Publish</label><i:selectBoolean ref="cocoon-installation/publish"/></row> + </i:instance> + </rows> <i:button method="prev1"> <i:caption>Prev</i:caption> 1.2 +9 -7 xml-cocoon2/src/blocks/precept/samples/example2/view3.xml Index: view3.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example2/view3.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view3.xml 29 Oct 2002 15:48:36 -0000 1.1 +++ view3.xml 29 Oct 2002 19:53:11 -0000 1.2 @@ -4,13 +4,15 @@ <i:insert-violations/> </errors> - <i:instance id="form-feedback"> - <i:label>OS</i:label><i:selectOne ref="cocoon-installation/system/os"/> - <i:label>Processor</i:label><i:selectOne ref="cocoon-installation/system/processor"/> - <i:label>RAM</i:label><i:textbox ref="cocoon-installation/system/ram"/> - <i:label>Servlet Engine</i:label><i:selectOne ref="cocoon-installation/system/servlet-engine"/> - <i:label>Java Version</i:label><i:selectOne ref="cocoon-installation/system/java-version"/> - </i:instance> + <rows> + <i:instance id="form-feedback"> + <row><label>OS</label><i:selectOne ref="cocoon-installation/system/os"/></row> + <row><label>Processor</label><i:selectOne ref="cocoon-installation/system/processor"/></row> + <row><label>RAM</label><i:textbox ref="cocoon-installation/system/ram"/></row> + <row><label>Servlet Engine</label><i:selectOne ref="cocoon-installation/system/servlet-engine"/></row> + <row><label>Java Version</label><i:selectOne ref="cocoon-installation/system/java-version"/></row> + </i:instance> + </rows> <i:button method="prev2"> <i:caption>Prev</i:caption> 1.2 +15 -14 xml-cocoon2/src/blocks/precept/samples/example2/view4.xml Index: view4.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/src/blocks/precept/samples/example2/view4.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view4.xml 29 Oct 2002 15:48:36 -0000 1.1 +++ view4.xml 29 Oct 2002 19:53:11 -0000 1.2 @@ -4,22 +4,23 @@ <i:insert-violations/> </errors> - <i:instance id="form-feedback"> - <i:label>Firstname</i:label><i:output ref="cocoon-installation/user/firstname"/> - <i:label>Lastname</i:label><i:output ref="cocoon-installation/user/lastname"/> - <i:label>Email</i:label><i:output ref="cocoon-installation/user/email"/> + <rows> + <i:instance id="form-feedback"> + <row><label>Firstname</label><i:output ref="cocoon-installation/user/firstname"/></row> + <row><label>Lastname</label><i:output ref="cocoon-installation/user/lastname"/></row> + <row><label>Email</label><i:output ref="cocoon-installation/user/email"/></row> - <i:label>Number of installations</i:label><i:output ref="cocoon-installation/number"/> - <i:label>Live URL</i:label><i:output ref="cocoon-installation/live-url"/> - <i:label>Publish</i:label><i:output ref="cocoon-installation/publish"/> - - <i:label>OS</i:label><i:output ref="cocoon-installation/system/os"/> - <i:label>Processor</i:label><i:output ref="cocoon-installation/system/processor"/> - <i:label>RAM</i:label><i:output ref="cocoon-installation/system/ram"/> - <i:label>Servlet Engine</i:label><i:output ref="cocoon-installation/system/servlet-engine"/> - <i:label>Java Version</i:label><i:output ref="cocoon-installation/system/java-version"/> - </i:instance> + <row><label>Number of installations</label><i:output ref="cocoon-installation/number"/></row> + <row><label>Live URL</label><i:output ref="cocoon-installation/live-url"/></row> + <row><label>Publish</label><i:output ref="cocoon-installation/publish"/></row> + <row><label>OS</label><i:output ref="cocoon-installation/system/os"/></row> + <row><label>Processor</label><i:output ref="cocoon-installation/system/processor"/></row> + <row><label>RAM</label><i:output ref="cocoon-installation/system/ram"/></row> + <row><label>Servlet Engine</label><i:output ref="cocoon-installation/system/servlet-engine"/></row> + <row><label>Java Version</label><i:output ref="cocoon-installation/system/java-version"/></row> + </i:instance> + </rows> <i:button method="prev3"> <i:caption>Prev</i:caption> </i:button>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]