You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by co...@apache.org on 2003/02/28 20:12:13 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript system.js

coliver     2003/02/28 11:12:13

  Modified:    src/java/org/apache/cocoon/components/flow/javascript
                        system.js
  Log:
  Removed tabs, added getValue() and iterate() methods to XForm and removed xpath() method
  
  Revision  Changes    Path
  1.9       +114 -96   xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/system.js
  
  Index: system.js
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/system.js,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- system.js	26 Feb 2003 17:15:41 -0000	1.8
  +++ system.js	28 Feb 2003 19:12:13 -0000	1.9
  @@ -159,11 +159,13 @@
    */
   XForm.prototype.setModel = function(model) {
       this.form = 
  -	new Packages.org.apache.cocoon.components.xmlform.Form(this.id, 
  -							       model);
  +       new Packages.org.apache.cocoon.components.xmlform.Form(this.id, 
  +                                                               model);
  +    this.context = 
  +       Packages.org.apache.commons.jxpath.JXPathContext.newContext(model);
       this.form.setAutoValidate(false);
       if (this.validatorNS != undefined && this.validatorDoc != undefined) {
  -	this._setValidator(this.validatorNS, this.validatorDoc);
  +        this._setValidator(this.validatorNS, this.validatorDoc);
       }
   }
   
  @@ -176,7 +178,7 @@
   XForm.prototype.start = function(lastCont, timeToLive) {
       var k = new Continuation();
       var kont = new WebContinuation(cocoon, k, 
  -				   lastCont, timeToLive);
  +                                   lastCont, timeToLive);
       return kont;
   } 
   
  @@ -193,12 +195,12 @@
       var list = new java.util.LinkedList();
       list.add(violation);
       try {
  -	this.form.addViolations(list);
  +        this.form.addViolations(list);
       } catch (e) {
  -	print(e);
  -	if (e instanceof java.lang.Throwable) {
  -	    e.printStackTrace();
  -	}
  +        print(e);
  +        if (e instanceof java.lang.Throwable) {
  +            e.printStackTrace();
  +        }
       }
   }
   
  @@ -207,9 +209,18 @@
    * @param expr xpath expression
    * @return result of computing <code>expr</code>
    */
  -XForm.prototype.xpath = function(expr) {
  -    var ctx = new Packages.org.apache.commons.jxpath.JXPathContext.newContext(this.form.getModel());
  -    return ctx.getValue(expr);
  +XForm.prototype.getValue = function(expr) {
  +    return this.context.getValue(expr);
  +}
  +
  +/**
  + * Returns an iterator over a nodeset value of an xpath expression evaluated 
  + * against the model of this form
  + * @param expr xpath expression
  + * @return java.util.Iterator representing a nodeset 
  + */
  +XForm.prototype.iterate = function(expr) {
  +    return this.context.iterate(expr);
   }
   
   XForm.prototype._sendView = function(uri, lastCont, timeToLive) {
  @@ -228,7 +239,7 @@
   /**
    * Sends view to presentation pipeline and waits for subsequent submission.
    * Automatically resends view if validation fails.
  - * Creates two continuations: one immediately before the page submission
  + * Creates two continuations: one immediately before the page is sent 
    * and one immediately after. These are used to implement automated support
    * for back/forward navigation in the form. When you move forward in the
    * form the second continuation is invoked. When you move back from the
  @@ -242,41 +253,47 @@
       this.form.clearViolations();
       var view = this.form.getFormView(cocoon.environment.objectModel);
       while (true) {
  -	var k = this.start(lastCont);
  -	if (cocoon.request == null) {
  -	    // this continuation has been invalidated
  -	    this.dead = true;
  -	    handleInvalidContinuation();
  -	    suicide();
  -	}
  -	cocoon.request.setAttribute("view", view);
  -	try {
  -	    this.form.save(cocoon.environment.objectModel, "request");
  -	} catch (e if (e instanceof java.lang.IllegalStateException)) {
  -	    if (cocoon.session.getAttribute(this.id) != null) {
  -		// someone else has taken my session
  -		this.dead = true;
  -		cocoon.removeSession();
  -		handleInvalidContinuation();
  -		suicide();
  -	    }
  -	    throw e;
  -	}
  -	this._sendView(uri, k);
  -	if (this.dead || cocoon.request == null) {
  -	    // this continuation has been invalidated
  -	    handleInvalidContinuation();
  -	    suicide();
  -	}
  -	this.form.populate(cocoon.environment.objectModel);
  -	if (validator != undefined) {
  -	    validator(this);
  -	}
  -	this.form.validate(phase);
  -	if (this.form.violationsAsSortedSet == null ||
  -	    this.form.violationsAsSortedSet.size() == 0) {
  -	    break;
  -	}
  +        // create a continuation, the invocation of which will resend
  +        // the page: this is used to implement <xf:submit continuation="back">
  +        var k = this.start(lastCont);
  +        if (cocoon.request == null) {
  +            // this continuation has been invalidated
  +            this.dead = true;
  +            handleInvalidContinuation();
  +            suicide();
  +        }
  +        // reset the view in case this is a re-invocation of a continuation
  +        cocoon.request.setAttribute("view", view);
  +        try {
  +            this.form.save(cocoon.environment.objectModel, "request");
  +        } catch (e if (e instanceof java.lang.IllegalStateException)) {
  +            if (cocoon.session.getAttribute(this.id) != null) {
  +                // someone else has taken my session
  +                this.dead = true;
  +                cocoon.removeSession();
  +                handleInvalidContinuation();
  +                suicide();
  +            }
  +            throw e;
  +        }
  +        this._sendView(uri, k);
  +        // _sendView creates a continuation, the invocation of which
  +        // will return right here: it is used to implement 
  +        // <xf:submit continuation="forward">
  +        if (this.dead || cocoon.request == null) {
  +            // this continuation has been invalidated
  +            handleInvalidContinuation();
  +            suicide();
  +        }
  +        this.form.populate(cocoon.environment.objectModel);
  +        if (validator != undefined) {
  +            validator(this);
  +        }
  +        this.form.validate(phase);
  +        if (this.form.violationsAsSortedSet == null ||
  +            this.form.violationsAsSortedSet.size() == 0) {
  +            break;
  +        }
       }
   }
   
  @@ -287,12 +304,12 @@
       var resolver = cocoon.environment;
       var schemaSrc = resolver.resolveURI( schDoc );
       try {
  -	var is = Packages.org.apache.cocoon.components.source.SourceUtil.getInputSource(schemaSrc);
  -	var schf = Packages.org.apache.cocoon.components.validation.SchemaFactory.lookup ( schNS );
  -	var sch = schf.compileSchema ( is );
  -	this.form.setValidator(sch.newValidator());
  +        var is = Packages.org.apache.cocoon.components.source.SourceUtil.getInputSource(schemaSrc);
  +        var schf = Packages.org.apache.cocoon.components.validation.SchemaFactory.lookup ( schNS );
  +        var sch = schf.compileSchema ( is );
  +        this.form.setValidator(sch.newValidator());
       } finally {
  -	resolver.release(schemaSrc);
  +        resolver.release(schemaSrc);
       }
   }
   
  @@ -304,25 +321,25 @@
   
   XForm.prototype.finish = function(view, uri) {
       try {
  -	this.form.save(cocoon.environment.objectModel, "request");
  +        this.form.save(cocoon.environment.objectModel, "request");
       } catch (e if (e instanceof java.lang.IllegalStateException)) {
  -	if (cocoon.session.getAttribute(this.id) != null) {
  -	    // someone else has taken my session
  -	    this.dead = true;
  -	    cocoon.removeSession();
  -	    handleInvalidContinuation();
  -	    suicide();
  -	}
  -	throw e;
  +        if (cocoon.session.getAttribute(this.id) != null) {
  +            // someone else has taken my session
  +            this.dead = true;
  +            cocoon.removeSession();
  +            handleInvalidContinuation();
  +            suicide();
  +        }
  +        throw e;
       }
       cocoon.forwardTo("cocoon://" + cocoon.environment.getURIPrefix() + uri,
  -		     this.form.getModel(), null);
  +                     this.form.getModel(), null);
       delete XForm.forms[this.id]; // delete myself
       this.dead = true;
       cocoon.removeSession();
       if (this.lastContinuation != null) {
  -	this.lastContinuation.invalidate();
  -	this.lastContinuation = null;
  +        this.lastContinuation.invalidate();
  +        this.lastContinuation = null;
       }
       
   }
  @@ -337,41 +354,42 @@
    */
   
   function xmlForm(application, id, validator_ns, validator_doc) {
  +    if (cocoon.request == null) {
  +        handleInvalidContinuation("");
  +        return;
  +    }
       function getCommand() {
  -	if (cocoon.request == null) {
  -	    return undefined;
  -	}
  -	var enum_ = cocoon.request.parameterNames;
  -	var command = undefined;
  -	while (enum_.hasMoreElements()) {
  -	    var paramName = enum_.nextElement();
  -	    // search for the command
  -	    if (paramName.startsWith(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX)) {
  -		command =
  -		    paramName.substring(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX.length(), paramName.length());
  -		break;
  -	    }
  -	}
  -	// command encodes the continuation id for "back" or "next" actions
  -	return command;
  +        var enum_ = cocoon.request.parameterNames;
  +        var command = undefined;
  +        while (enum_.hasMoreElements()) {
  +            var paramName = enum_.nextElement();
  +            // search for the command
  +            if (paramName.startsWith(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX)) {
  +                command =
  +                    paramName.substring(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX.length(), paramName.length());
  +                break;
  +            }
  +        }
  +        // command encodes the continuation id for "back" or "next" actions
  +        return command;
       }
       var command = getCommand();
       if (command != undefined) {
  -	var xform = XForm.forms[id];
  -	if (xform != undefined) {
  -	    // invoke a continuation 
  -	    var continuationsMgr =
  -		cocoon.componentManager.lookup(Packages.org.apache.cocoon.components.flow.ContinuationsManager.ROLE);
  -	    var wk = continuationsMgr.lookupWebContinuation(command);
  -	    cocoon.componentManager.release(continuationsMgr);
  -	    if (wk != null) {
  -		var jswk = wk.userObject;
  -		xform.form.clearViolations();
  -		jswk.continuation(jswk);
  -	    } else {
  -		handleInvalidContinuation(command);
  -	    }
  -	}
  +        var xform = XForm.forms[id];
  +        if (xform != undefined) {
  +            // invoke a continuation 
  +            var continuationsMgr =
  +                cocoon.componentManager.lookup(Packages.org.apache.cocoon.components.flow.ContinuationsManager.ROLE);
  +            var wk = continuationsMgr.lookupWebContinuation(command);
  +            cocoon.componentManager.release(continuationsMgr);
  +            if (wk != null) {
  +                var jswk = wk.userObject;
  +                xform.form.clearViolations();
  +                jswk.continuation(jswk);
  +            }
  +        }
  +        handleInvalidContinuation(command);
  +        return;
       } 
       // Just start a new instance of the application
       cocoon.session.removeAttribute(id);