coliver 2003/07/19 13:18:51
Modified: src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/flow/javascript JXForm.java src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/xmlform Form.java src/blocks/jxforms/samples/view confirm.xml end.xml Log: Fixed sample, updated to use latest FOM Java API, and fixed bug with jxpath coercions Revision Changes Path 1.3 +18 -29 cocoon-2.1/src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/flow/javascript/JXForm.java Index: JXForm.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/flow/javascript/JXForm.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JXForm.java 13 Jul 2003 03:36:12 -0000 1.2 +++ JXForm.java 19 Jul 2003 20:18:49 -0000 1.3 @@ -52,14 +52,13 @@ import org.apache.cocoon.components.jxforms.validation.*; import org.apache.cocoon.components.jxforms.xmlform.*; import org.mozilla.javascript.*; +import org.mozilla.javascript.continuations.Continuation; import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon; -import org.apache.cocoon.components.flow.ContinuationsManager; -import org.apache.cocoon.components.flow.WebContinuation; -import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.FOM_WebContinuation; +import org.apache.cocoon.components.flow.javascript.fom.FOM_WebContinuation; import org.apache.commons.jxpath.JXPathContext; -import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.components.source.SourceUtil; +import org.apache.excalibur.source.SourceResolver; import org.apache.excalibur.source.Source; +import org.apache.cocoon.components.source.SourceUtil; import org.xml.sax.InputSource; import java.util.Set; import java.util.List; @@ -121,8 +120,8 @@ context = JXPathContext.newContext(model); form.setAutoValidate(false); if (validatorNamespace != null && validatorDocument != null) { - SourceResolver resolver = - getCocoon().getEnvironment(); + SourceResolver resolver = (SourceResolver) + getCocoon().getComponentManager().lookup(SourceResolver.ROLE); Source schemaSrc = resolver.resolveURI(validatorDocument); InputSource is = SourceUtil.getInputSource(schemaSrc); SchemaFactory schf = SchemaFactory.lookup(validatorNamespace); @@ -150,14 +149,10 @@ FOM_Cocoon cocoon = getCocoon(); FOM_WebContinuation fom_wk = (FOM_WebContinuation)unwrap(continuation); - String redUri = "cocoon://" + - cocoon.getEnvironment().getURIPrefix() + uri; - cocoon.getInterpreter().forwardTo(getTopLevelScope(cocoon), - cocoon, - redUri, - unwrap(bizData), - fom_wk == null ? null: fom_wk.getWebContinuation(), - cocoon.getEnvironment()); + cocoon.forwardTo(uri, + unwrap(bizData), + fom_wk); + } public void jsFunction_addViolation(String xpath, String message) @@ -183,8 +178,7 @@ Object cocoon_) throws Exception { FOM_Cocoon cocoon = (FOM_Cocoon)unwrap(cocoon_); - cocoon.getInterpreter().handleContinuation(kontId, null, - cocoon.getEnvironment()); + cocoon.handleContinuation(kontId, null); } public Object jsFunction_iterate(String expr) { @@ -195,17 +189,11 @@ Object lastContinuation, int ttl) throws Exception { - FOM_Cocoon cocoon = getCocoon(); - WebContinuation wk; - ContinuationsManager contMgr; - contMgr = (ContinuationsManager) - cocoon.getComponentManager().lookup(ContinuationsManager.ROLE); + Continuation kont = (Continuation)unwrap(k); FOM_WebContinuation fom_wk = (FOM_WebContinuation)unwrap(lastContinuation); - wk = contMgr.createWebContinuation(unwrap(k), - (WebContinuation)(fom_wk == null ? null : fom_wk.getWebContinuation()), - ttl); - return cocoon.makeWebContinuation(wk); + FOM_Cocoon cocoon = getCocoon(); + return cocoon.makeWebContinuation(kont, fom_wk, ttl); } // unwrap Wrapper's and convert undefined to null @@ -220,18 +208,19 @@ public void jsFunction_removeForm() { FOM_Cocoon cocoon = getCocoon(); - Form.remove(cocoon.getEnvironment().getObjectModel(), id); + + Form.remove(cocoon.getObjectModel(), id); cocoon.getRequest().removeAttribute(this.id); } public void jsFunction_saveForm() { FOM_Cocoon cocoon = getCocoon(); - form.save(cocoon.getEnvironment().getObjectModel(), "request"); + form.save(cocoon.getObjectModel(), "request"); } public void jsFunction_populateForm() { FOM_Cocoon cocoon = getCocoon(); - form.populate(cocoon.getEnvironment().getObjectModel()); + form.populate(cocoon.getObjectModel()); } public void jsFunction_validateForm(String view) { 1.3 +11 -2 cocoon-2.1/src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/xmlform/Form.java Index: Form.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jxforms/java/org/apache/cocoon/components/jxforms/xmlform/Form.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Form.java 14 Jul 2003 21:05:48 -0000 1.2 +++ Form.java 19 Jul 2003 20:18:49 -0000 1.3 @@ -172,6 +172,15 @@ if (model_==null) { throw new IllegalStateException("Form model not set"); } + // Convert empty string to null, before passing to jxpath + // so proper xpath coercions occur for number and boolean + if (value instanceof String && + ((String)value).length() == 0) { + Object node = jxcontext_.getPointer(xpath).getNode(); + if (!(node instanceof String)) { + value = null; + } + } jxcontext_.setValue(xpath, value); } @@ -243,7 +252,7 @@ Context.exit(); } } else { - jxcontext_.setValue(xpath, values[0]); + setValue(xpath, values[0]); } } 1.2 +1 -1 cocoon-2.1/src/blocks/jxforms/samples/view/confirm.xml Index: confirm.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jxforms/samples/view/confirm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- confirm.xml 12 Jul 2003 19:22:31 -0000 1.1 +++ confirm.xml 19 Jul 2003 20:18:50 -0000 1.2 @@ -1,6 +1,6 @@ <?xml version="1.0"?> <document xmlns:xf="http://apache.org/cocoon/jxforms/1.0"> - <xf:form id="form-feedback" view="confirm" action="" method="GET"> + <xf:form id="form-feedback" view="confirm"> <xf:label>Confirm Input</xf:label> <!-- from page1 --> <xf:output ref="firstName"> 1.2 +1 -1 cocoon-2.1/src/blocks/jxforms/samples/view/end.xml Index: end.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/jxforms/samples/view/end.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- end.xml 12 Jul 2003 19:22:31 -0000 1.1 +++ end.xml 19 Jul 2003 20:18:50 -0000 1.2 @@ -21,7 +21,7 @@ <tr> <td align="center"> <h3> - <a href="../scratchpad">Go to home page.</a> + <a href="../">Go to home page.</a> </h3> </td> </tr>