Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 40111 invoked by uid 500); 27 Mar 2003 18:59:25 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 40100 invoked by uid 500); 27 Mar 2003 18:59:25 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 40091 invoked from network); 27 Mar 2003 18:59:25 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 27 Mar 2003 18:59:25 -0000 Received: (qmail 97997 invoked by uid 1544); 27 Mar 2003 18:59:24 -0000 Date: 27 Mar 2003 18:59:24 -0000 Message-ID: <20030327185924.97996.qmail@icarus.apache.org> From: coliver@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/templates IncludeTop.vm X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N coliver 2003/03/27 10:59:24 Modified: src/scratchpad/src/org/apache/cocoon/transformation JXPathTransformer.java src/scratchpad/webapp/samples/petstore sitemap.xmap src/scratchpad/webapp/samples/petstore/flow petstore.js src/scratchpad/webapp/samples/petstore/stylesheets site2html.xsl src/scratchpad/webapp/samples/petstore/view/templates IncludeTop.vm Added: src/scratchpad/lib commons-jexl-1.0-beta-1.jar velocity-1.4-dev-20030301.jar src/scratchpad/webapp/samples/petstore/view/jexl Cart.xml Category.xml Checkout.xml ConfirmOrder.xml Item.xml NewAccountForm.xml NewOrderForm.xml Product.xml SearchProducts.xml ShippingForm.xml SignonForm.xml ViewOrder.xml index.xml src/scratchpad/webapp/samples/petstore/view/jxpath Cart.xml Category.xml Checkout.xml ConfirmOrder.xml Item.xml NewAccountForm.xml NewOrderForm.xml Product.xml SearchProducts.xml ShippingForm.xml SignonForm.xml ViewOrder.xml index.xml Log: added examples of JXPath and Jexl views to petstore Revision Changes Path 1.1 cocoon-2.1/src/scratchpad/lib/commons-jexl-1.0-beta-1.jar <> 1.1 cocoon-2.1/src/scratchpad/lib/velocity-1.4-dev-20030301.jar <> 1.2 +82 -12 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/transformation/JXPathTransformer.java Index: JXPathTransformer.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/transformation/JXPathTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JXPathTransformer.java 26 Mar 2003 05:28:08 -0000 1.1 +++ JXPathTransformer.java 27 Mar 2003 18:59:22 -0000 1.2 @@ -52,6 +52,7 @@ import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.generation.Generator; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.flow.WebContinuation; import org.apache.cocoon.environment.Environment; @@ -59,12 +60,17 @@ import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.Pointer; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.apache.cocoon.xml.dom.DOMStreamer; import org.w3c.dom.DocumentFragment; import org.apache.avalon.framework.CascadingRuntimeException; +import org.apache.cocoon.components.source.SourceUtil; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.source.SourceValidity; import java.io.IOException; import java.io.Reader; @@ -76,7 +82,7 @@ import java.util.Stack; import java.util.Iterator; /** - * JXPath Transformer. + * JXPath Transformer * *

* Transformer implementation using Apache JXPath @@ -91,7 +97,7 @@ * @author Christopher Oliver */ public class JXPathTransformer -extends AbstractSAXTransformer implements Initializable { +extends AbstractSAXTransformer implements Initializable, Generator { public static final String JXPATH_NAMESPACE_URI = "http://cocoon.apache.org/transformation/jxpath/1.0"; @@ -140,6 +146,31 @@ private Stack ifStack; + // Run as a generator for debugging: to get line numbers in error messages + + private Source inputSource; + + public void generate() + throws IOException, SAXException, ProcessingException { + try { + this.resolver.toSAX(this.inputSource, this); + } catch (SAXException e) { + final Exception cause = e.getException(); + if( cause != null ) { + if ( cause instanceof ProcessingException ) + throw (ProcessingException)cause; + if ( cause instanceof IOException ) + throw (IOException)cause; + if ( cause instanceof SAXException ) + throw (SAXException)cause; + throw new ProcessingException("Could not read resource " + + this.inputSource.getURI(), cause); + } + throw e; + } + } + + /** * Initialize this transformer. * @@ -166,7 +197,13 @@ throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, parameters); - + if (src != null) { + try { + this.inputSource = resolver.resolveURI(src); + } catch (SourceException se) { + throw SourceUtil.handle("Error during resolving of '" + src + "'.", se); + } + } // setup the jxpath transformer for this thread // FIX ME: When we decide proper way to pass "bean" and "kont" Object bean = ((Environment)resolver).getAttribute("bean-dict"); @@ -180,6 +217,42 @@ } /** + * Hack? Accept JXPath expr with or without enclosing {} + */ + + String getExpr(String inStr) { + try { + inStr = inStr.trim(); + if (inStr.length() == 0 || inStr.charAt(0) != '{') { + return inStr; + } + StringReader in = new StringReader(inStr); + int ch; + StringBuffer expr = new StringBuffer(); + in.read(); // '{' + while ((ch = in.read()) != -1) { + char c = (char)ch; + if (c == '}') { + break; + } else if (c == '\\') { + ch = in.read(); + if (ch == -1) { + expr.append('\\'); + } else { + expr.append((char)ch); + } + } else { + expr.append(c); + } + } + return expr.toString(); + } catch (IOException ignored) { + ignored.printStackTrace(); + } + return inStr; + } + + /** * Substitute the values of XPath expr's (contained in {}) within attribute values * TBD: how should escaping of {} be done? (uses backslash at the moment) */ @@ -247,8 +320,7 @@ try { substitute(reader, writer); } catch (Exception exc) { - throw new CascadingRuntimeException(exc.getMessage(), - exc); + throw new SAXException(exc.getMessage(), exc); } impl.setValue(i, writer.toString()); } @@ -338,17 +410,15 @@ finishIf(); } else if (JXPATH_CHOOSE.equals(name)) { finishChoose(); + inChoose = false; } else if (JXPATH_WHEN.equals(name)) { finishWhen(); inChoose = true; - return; } else if (JXPATH_OTHERWISE.equals(name)) { finishOtherwise(); inChoose = true; - return; } } - inChoose = false; } private JXPathContext getContext() { @@ -415,7 +485,7 @@ final String select = a.getValue(JXPATH_VALUEOF_SELECT); if (null != select) { - Object value = getValue(select); + Object value = getValue(getExpr(select)); if (value == null) { value = ""; } @@ -466,7 +536,7 @@ String test = a.getValue(JXPATH_IF_TEST); final Object value = - (test == null) ? Boolean.FALSE : getValue("boolean("+test+")"); + (test == null) ? Boolean.FALSE : getValue("boolean("+getExpr(test)+")"); final boolean isTrueBoolean = value instanceof Boolean && ((Boolean)value).booleanValue() == true; ifStack.push(isTrueBoolean ? Boolean.TRUE : Boolean.FALSE); @@ -496,7 +566,7 @@ if (ignoreEventsCount == 0) { startRecording(); // get the test variable - String variable = a.getValue(JXPATH_VALUEOF_SELECT); + String variable = getExpr(a.getValue(JXPATH_VALUEOF_SELECT)); Iterator iter = JXPathContext.compile(variable).iteratePointers(getContext()); foreachStack.push(variable); @@ -539,7 +609,7 @@ // get the test variable String test = a.getValue(JXPATH_WHEN_TEST); final Object value = - (test == null) ? Boolean.FALSE : getValue("boolean("+test+")"); + (test == null) ? Boolean.FALSE : getValue("boolean("+getExpr(test)+")"); final boolean isTrueBoolean = value instanceof Boolean && ((Boolean)value).booleanValue() == true; if (isTrueBoolean) { 1.11 +16 -2 cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- sitemap.xmap 25 Mar 2003 20:55:09 -0000 1.10 +++ sitemap.xmap 27 Mar 2003 18:59:22 -0000 1.11 @@ -5,9 +5,11 @@ + + - + @@ -104,8 +106,20 @@ + + + + + + + + + + + + - + 1.10 +4 -0 cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js Index: petstore.js =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- petstore.js 25 Mar 2003 20:55:09 -0000 1.9 +++ petstore.js 27 Mar 2003 18:59:22 -0000 1.10 @@ -102,6 +102,10 @@ EXT = ".vm"; } else if (VIEW == "Xsp") { EXT = ".xsp"; + } else if (VIEW == "Jexl") { + EXT = ".jexl"; + } else if (VIEW == "JXPath") { + EXT = ".jxpath"; } print("EXT="+EXT); } 1.7 +19 -1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/stylesheets/site2html.xsl Index: site2html.xsl =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/stylesheets/site2html.xsl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- site2html.xsl 25 Mar 2003 20:55:09 -0000 1.6 +++ site2html.xsl 27 Mar 2003 18:59:22 -0000 1.7 @@ -21,9 +21,27 @@

- + + + + + + + + + + + + + + + + + +
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/Cart.xml Index: Cart.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/Category.xml Index: Category.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/Checkout.xml Index: Checkout.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/ConfirmOrder.xml Index: ConfirmOrder.xml =================================================================== Please confirm the information below and then press continue... 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/Item.xml Index: Item.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/NewAccountForm.xml Index: NewAccountForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/NewOrderForm.xml Index: NewOrderForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/Product.xml Index: Product.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/SearchProducts.xml Index: SearchProducts.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/ShippingForm.xml Index: ShippingForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/SignonForm.xml Index: SignonForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/ViewOrder.xml Index: ViewOrder.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jexl/index.xml Index: index.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/Cart.xml Index: Cart.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/Category.xml Index: Category.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/Checkout.xml Index: Checkout.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/ConfirmOrder.xml Index: ConfirmOrder.xml =================================================================== Please confirm the information below and then press continue... 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/Item.xml Index: Item.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/NewAccountForm.xml Index: NewAccountForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/NewOrderForm.xml Index: NewOrderForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/Product.xml Index: Product.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/SearchProducts.xml Index: SearchProducts.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/ShippingForm.xml Index: ShippingForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/SignonForm.xml Index: SignonForm.xml ===================================================================
1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/ViewOrder.xml Index: ViewOrder.xml =================================================================== 1.1 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/jxpath/index.xml Index: index.xml =================================================================== 1.5 +2 -0 cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/templates/IncludeTop.vm Index: IncludeTop.vm =================================================================== RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/view/templates/IncludeTop.vm,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- IncludeTop.vm 25 Mar 2003 20:55:10 -0000 1.4 +++ IncludeTop.vm 27 Mar 2003 18:59:24 -0000 1.5 @@ -17,6 +17,8 @@