You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/11/27 08:10:27 UTC
svn commit: r349187 [1/6] - in /struts/flow/trunk: ./ src/examples/WEB-INF/
src/examples/WEB-INF/guess/ src/examples/WEB-INF/portlet/
src/examples/WEB-INF/remote/ src/examples/remote/ src/java/
src/java/org/apache/struts/flow/ src/java/org/apache/strut...
Author: mrdon
Date: Sat Nov 26 23:10:08 2005
New Revision: 349187
URL: http://svn.apache.org/viewcvs?rev=349187&view=rev
Log:
== Merged flow with Cocoon, new portlet example ==
* Merged Cocoon trunk with flow implementation. New features:
* Per session continuation trees
* Page local variables stored with continuation
* Cocoon's Flow Object Model
* Interpreter abstracts to allow Java possibly impl later
* Monitoring classes to allow external monitoring like JMX
* A bunch of bug fixes and other features
* Added commons-lang as new dependency due to the Cocoon code using it.
Might try to rewrite those parts later.
* Brought in Excalibur's source component to make transition easier
* Brought in Cocoon's Location classes. Might prune later.
* Migrated guess and remote examples to new flow
* Changed ajax rpc mode to not use continuations ids, security to come
* Added startings of new portlet example
Added:
struts/flow/trunk/src/examples/WEB-INF/portlet/
struts/flow/trunk/src/examples/WEB-INF/portlet.xml
struts/flow/trunk/src/examples/WEB-INF/portlet/frontPage.jt
struts/flow/trunk/src/examples/WEB-INF/portlet/guess.jsp
struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js
struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js.template
struts/flow/trunk/src/examples/WEB-INF/portlet/portlet.js
struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp
struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp.ajax
struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jt
struts/flow/trunk/src/examples/WEB-INF/portlet/success.jsp
struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jsp
struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jt
struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/FlowHelper.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/Interpreter.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/WebContinuationDataBean.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/ConversionHelper.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/JSErrorReporter.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/LocationTrackingDebugger.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/FOMResourceNotFoundException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/FOM_Flow.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/FOM_JavaScriptInterpreter.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/FOM_WebContinuation.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/PageLocal.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/PageLocalImpl.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/PageLocalScope.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/PageLocalScopeHolder.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/PageLocalScopeImpl.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/javascript/fom/fom_system.js (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/Locatable.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocatableException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocatedException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocatedRuntimeException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/Location.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocationAttributes.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocationImpl.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/LocationUtils.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/MultiLocatable.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/location/package.html
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/ModifiableSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/ModifiableTraversableSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/MoveableSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/Source.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceFactory.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceNotFoundException.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceParameters.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceResolver.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceUtil.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/SourceValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/TraversableSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/URIAbsolutizer.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/AbstractSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/AbstractSourceResolver.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/ChainSourceResolver.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/FileSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/FileSourceFactory.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/ResourceSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/ResourceSourceFactory.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/URLSource.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/URLSourceFactory.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/AbstractAggregatedValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/AggregatedValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/DeferredAggregatedValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/DeferredValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/ExpiresValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/FileTimeStampValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/NOPValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/core/source/impl/validity/TimeStampValidity.java (with props)
struts/flow/trunk/src/java/org/apache/struts/flow/portlet/Portlet.java (with props)
Removed:
struts/flow/trunk/src/java/org/apache/struts/flow/core/JSErrorReporter.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/JSFlow.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/JSGlobal.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/JSLog.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/JSWebContinuation.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/JavaScriptInterpreter.java
struts/flow/trunk/src/java/system.js
Modified:
struts/flow/trunk/build.xml
struts/flow/trunk/project.xml
struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js
struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp
struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js
struts/flow/trunk/src/examples/WEB-INF/web.xml
struts/flow/trunk/src/examples/remote/clientFlow.js
struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java
struts/flow/trunk/src/java/org/apache/struts/flow/FlowPlugIn.java
struts/flow/trunk/src/java/org/apache/struts/flow/Struts.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/CompilingInterpreter.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsDisposer.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManager.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManagerImpl.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/DefaultCallVariableRegistrar.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/DefaultStaticVariableRegistrar.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/Factory.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/FlowException.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/InvalidContinuationException.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/Logger.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/VariableRegistrar.java
struts/flow/trunk/src/java/org/apache/struts/flow/core/WebContinuation.java
struts/flow/trunk/src/java/org/apache/struts/flow/ibatis/SqlMap.java
struts/flow/trunk/src/java/org/apache/struts/flow/portlet/FlowPortlet.java
Modified: struts/flow/trunk/build.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/build.xml?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/build.xml (original)
+++ struts/flow/trunk/build.xml Sat Nov 26 23:10:08 2005
@@ -89,12 +89,16 @@
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-collections/jars/commons-collections-2.1.1.jar"/>
-->
+ <get dest="${lib.build}/portlet-api-1.0.jar" usetimestamp="true"
+ ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/portlet-api/jars/portlet-api-1.0.jar"/>
+
<mkdir dir="${lib.core}" />
- <get dest="${lib.core}/struts-1.2.7.jar" usetimestamp="true"
+ <get dest="${lib.core}/struts-1.2.8.jar" usetimestamp="true"
ignoreerrors="true"
- src="http://www.ibiblio.org/maven/struts/jars/struts-1.2.7.jar"/>
+ src="http://www.ibiblio.org/maven/struts/jars/struts-1.2.8.jar"/>
<get dest="${lib.core}/js-1.6R1.jar" usetimestamp="true"
ignoreerrors="true"
@@ -104,6 +108,10 @@
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-chain/jars/commons-chain-1.0.jar"/>
+ <get dest="${lib.core}/commons-lang-2.1.jar" usetimestamp="true"
+ ignoreerrors="true"
+ src="http://www.ibiblio.org/maven/commons-lang/jars/commons-lang-2.1.jar"/>
+
<get dest="${lib.core}/jakarta-oro-2.0.7.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/oro/jars/oro-2.0.7.jar"/>
@@ -132,10 +140,6 @@
<get dest="${lib.core}/commons-digester.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-digester/jars/commons-digester-1.7.jar"/>
-
- <get dest="${lib.core}/portlet-api-1.0.jar" usetimestamp="true"
- ignoreerrors="true"
- src="http://www.ibiblio.org/maven/portlet-api/jars/portlet-api-1.0.jar"/>
<mkdir dir="${lib.examples}" />
<get dest="${lib.examples}/hsqldb.jar" usetimestamp="true"
Modified: struts/flow/trunk/project.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/project.xml?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/project.xml (original)
+++ struts/flow/trunk/project.xml Sat Nov 26 23:10:08 2005
@@ -54,7 +54,7 @@
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
- <version>1.2.7</version>
+ <version>1.2.8</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
@@ -84,6 +84,16 @@
<url>http://www.mozilla.org/rhino/</url>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ <url>http://jakarta.apache.org/commons/lang/</url>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency>
+
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
Modified: struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js (original)
+++ struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js Sat Nov 26 23:10:08 2005
@@ -7,7 +7,7 @@
while (true) {
// send guess page to user and wait for response
- forwardAndWait("failure",
+ flow.forwardAndWait("failure",
{ "random" : random,
"hint" : hint,
"guesses" : guesses} );
@@ -30,7 +30,7 @@
}
// send success page to user
- forwardAndWait("success",
+ flow.forwardAndWait("success",
{"random" : random,
"guess" : guess,
"guesses" : guesses} );
Added: struts/flow/trunk/src/examples/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet.xml?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet.xml (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet.xml Sat Nov 26 23:10:08 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
+ <portlet>
+ <description>Struts Flow Examples</description>
+ <portlet-name>FlowPortlet</portlet-name>
+ <display-name>Struts Flow Examples</display-name>
+
+ <portlet-class>org.apache.struts.flow.portlet.FlowPortlet</portlet-class>
+
+ <init-param>
+ <name>path</name>
+ <value>/WEB-INF/portlet/numberguess.js</value>
+ </init-param>
+
+ <expiration-cache>-1</expiration-cache>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>HELP</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>Struts Flow Examples</title>
+ <short-title>Struts Flow Examples</short-title>
+ <keywords>Examples</keywords>
+ </portlet-info>
+ </portlet>
+</portlet-app>
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/frontPage.jt
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/frontPage.jt?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/frontPage.jt (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/frontPage.jt Sat Nov 26 23:10:08 2005
@@ -0,0 +1,11 @@
+ <h1>Find Asset</h1>
+
+<ul>
+{for r in xml..rule}
+ <li>${r.@condensedImpact} - ${r.@fullImpact}</li>
+{/for}
+</ul>
+
+${xml.request.param.(@name=="debug").value}
+
+<br />
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/guess.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/guess.jsp?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/guess.jsp (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/guess.jsp Sat Nov 26 23:10:08 2005
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
+<portlet:defineObjects/>
+
+ <h1>Guess the Number Between 1 and 10</h1>
+
+ <h2><%= request.getAttribute("hint") %></h2>
+
+ <h3>You've guessed <%= request.getAttribute("guesses") %> times.</h3>
+
+<portlet:renderURL var="submitUrl">
+ <portlet:param name="contid" value="<%= String.valueOf(request.getAttribute("contid")) %>"/>
+</portlet:renderURL>
+
+<form action="<%=submitUrl%>">
+ <input type="text" name="guess"/>
+ <input type="submit"/>
+ </form>
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js Sat Nov 26 23:10:08 2005
@@ -0,0 +1,81 @@
+flow.load("/templates/template.js");
+
+function doView() {
+
+ var random = Math.round( Math.random() * 9 ) + 1;
+ var hint = "No hint for you!"
+ var guesses = 0;
+
+ while (true) {
+
+ // send guess page to user and wait for response
+ forwardAndWait("/WEB-INF/guess/guess.jsp",
+ { "random" : random,
+ "hint" : hint,
+ "guesses" : guesses} );
+
+ // process user's guess
+ var guess = parseInt( flow.context.param.guess );
+ guesses++;
+ if (guess) {
+ if (guess > random) {
+ hint = "Nope, lower!"
+ }
+ else if (guess < random) {
+ hint = "Nope, higher!"
+ }
+ else {
+ // correct guess
+ break;
+ }
+ }
+ }
+
+ // send success page to user
+ renderTemplate("/WEB-INF/guess/success.jsp",
+ {"random" : random,
+ "guess" : guess,
+ "guesses" : guesses} );
+}
+
+
+function renderTemplate(page, bizdata) {
+ res = flow.context.response;
+ stream = flow.context.context.getResourceAsStream("/WEB-INF/guess/"+page+".jt");
+ if (stream != null) {
+ text = new String(stream.getText());
+ html = text.process(bizdata);
+ res.contentType = "text/html";
+ res.writer.print(html);
+ res.writer.close();
+ } else {
+ res.sendError(res.SC_INTERNAL_SERVER_ERROR, "Unable to find page "+page);
+ }
+
+ suicide();
+ }
+}
+
+// This function intercepts the forward back to Struts and renders the content
+// directly using Javascript Templates
+function _renderTemplateAndWait(page, bizdata) {
+ // if rpc call, use old forward, otherwise use template
+ if (page == "n/a") {
+ return _oldForwardAndWait(page, bizdata);
+ } else {
+ var k = new Continuation();
+
+ // Use default ttl value from continuation manager
+ var timeToLive = 0;
+ var kont = new WebContinuation(flow, k, lastContinuation, timeToLive);
+
+ bizdata.contid = kont.id;
+ renderTemplate(page, bizdata);
+ return kont;
+ }
+}
+
+// Replace old forward method with ours, but keep a reference to it so we can
+// call it for remote flow responses
+this._oldForwardAndWait = _forwardAndWait;
+this._forwardAndWait = _renderTemplateAndWait;
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js.template
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js.template?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js.template (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/numberguess.js.template Sat Nov 26 23:10:08 2005
@@ -0,0 +1,90 @@
+flow.load("/templates/template.js");
+
+importClass(Packages.org.apache.commons.httpclient.HttpClient);
+importClass(Packages.org.apache.commons.httpclient.MultiThreadedHttpConnectionManager);
+importClass(Packages.org.apache.commons.httpclient.methods.GetMethod);
+importPackage(java.io);
+function doView() {
+
+ get = new GetMethod("http://mirage:8090/rp1/public/frontPage.do?debug=true&__accept_disclaimer__=true");
+
+ client = new HttpClient();
+ iGetResultCode = client.executeMethod(get);
+ body = get.getResponseBodyAsString();
+ xml = new XML(body);
+
+ forwardAndWait("frontPage",{"xml":xml});
+}
+
+/*
+ var random = Math.round( Math.random() * 9 ) + 1;
+ var hint = "No hint for you!"
+ var guesses = 0;
+
+ while (true) {
+
+ // send guess page to user and wait for response
+ forwardAndWait("/WEB-INF/guess/guess.jsp",
+ { "random" : random,
+ "hint" : hint,
+ "guesses" : guesses} );
+
+ // process user's guess
+ var guess = parseInt( flow.context.param.guess );
+ guesses++;
+ if (guess) {
+ if (guess > random) {
+ hint = "Nope, lower!"
+ }
+ else if (guess < random) {
+ hint = "Nope, higher!"
+ }
+ else {
+ // correct guess
+ break;
+ }
+ }
+ }
+
+ // send success page to user
+ forwardAndWait("/WEB-INF/guess/success.jsp",
+ {"random" : random,
+ "guess" : guess,
+ "guesses" : guesses} );
+*/
+
+// This function intercepts the forward back to Struts and renders the content
+// directly using Javascript Templates
+function renderTemplate(page, bizdata) {
+ // if rpc call, use old forward, otherwise use template
+ if (page == "n/a") {
+ return _oldForwardAndWait(page, bizdata);
+ } else {
+ var k = new Continuation();
+
+ // Use default ttl value from continuation manager
+ var timeToLive = 0;
+ var kont = new WebContinuation(flow, k, lastContinuation, timeToLive);
+
+ bizdata.contid = kont.id;
+ res = flow.context.response;
+ stream = flow.context.context.getResourceAsStream("/WEB-INF/guess/"+page+".jt");
+ if (stream != null) {
+ text = new String(stream.getText());
+ html = text.process(bizdata);
+ res.contentType = "text/html";
+ res.writer.print(html);
+ res.writer.close();
+ } else {
+ res.sendError(res.SC_INTERNAL_SERVER_ERROR, "Unable to find page "+page);
+ }
+
+ suicide();
+ return kont;
+ }
+}
+
+// Replace old forward method with ours, but keep a reference to it so we can
+// call it for remote flow responses
+this._oldForwardAndWait = _forwardAndWait;
+this._forwardAndWait = renderTemplate;
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/portlet.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/portlet.js?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/portlet.js (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/portlet.js Sat Nov 26 23:10:08 2005
@@ -0,0 +1,64 @@
+flow.load("/templates/template.js");
+
+importClass(Packages.javax.portlet.PortletURL);
+
+// This function intercepts the forward back to Struts and renders the content
+// directly using Javascript Templates
+function processTemplateAndWait(page, bizdata) {
+ // if rpc call, use old forward, otherwise use template
+ if (page == "n/a") {
+ return _oldForwardAndWait(page, bizdata);
+ } else {
+ var k = new Continuation();
+
+ // Use default ttl value from continuation manager
+ var timeToLive = 0;
+ var kont = new WebContinuation(flow, k, lastContinuation, timeToLive);
+
+ bizdata.contid = kont.id;
+ processTemplate(page, bizdata);
+ suicide();
+ return kont;
+ }
+}
+
+function processTemplate(page, bizdata) {
+ res = flow.context.response;
+ stream = flow.context.context.getResourceAsStream(page);
+ if (stream != null) {
+ text = new String(stream.getText());
+ html = text.process(bizdata);
+ res.contentType = "text/html";
+ res.writer.print(html);
+ res.flushBuffer();
+ res.writer.close();
+ } else {
+ res.sendError(res.SC_INTERNAL_SERVER_ERROR, "Unable to find page "+page);
+ }
+}
+
+function renderUrl(params) {
+ url = flow.context.response.createRenderURL();
+ if (params && params.params) {
+ for (x in params.params) {
+ url.setParameter(x, params.params[x]);
+ }
+ }
+ return url.toString();
+}
+
+function actionUrl(params) {
+ url = flow.context.response.createActionURL();
+ if (params && params.params) {
+ for (x in params.params) {
+ url.setParameter(x, params.params[x]);
+ }
+ }
+ return url.toString();
+}
+
+
+// Replace old forward method with ours, but keep a reference to it so we can
+// call it for remote flow responses
+this._oldForwardAndWait = _forwardAndWait;
+this._forwardAndWait = processTemplateAndWait;
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp Sat Nov 26 23:10:08 2005
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
+<portlet:defineObjects/>
+
+ <h1>Select Asset</h1>
+
+ <table cellspacing="2" cellpadding="3">
+ <tr>
+ <td class="property">
+ Asset search
+ </td>
+ <td>
+ <portlet:renderURL var="submitUrl">
+ <portlet:param name="contid" value="<%= String.valueOf(request.getAttribute("contid")) %>"/>
+ </portlet:renderURL>
+
+ <form method="GET" action="<%=submitUrl%>">
+ <input name="name" type="text" size="15" /> 
+ <input type="submit" value="Search" />
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td class="property">
+ Choose an asset
+ </td>
+ <td>
+ <form method="GET" action="<%=submitUrl%>" >
+ <select name="SystemKey">
+
+ <%
+ java.util.Map map = (java.util.Map)request.getAttribute("assets");
+ boolean any = false;
+ if (map != null) {
+ for (java.util.Iterator i = map.keySet().iterator(); i.hasNext(); any=true) {
+ String key = (String)i.next();
+ %>
+ <option value="<%=map.get(key)%>"><%=key%></option>
+ <%}
+ }
+ if (!any) {%>
+ <option value="">---- Assets ------</option>
+ <%}%>
+ </select> 
+ <input type="submit" value="View" />
+ </form>
+ </td>
+ </tr>
+ </table>
+
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp.ajax
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp.ajax?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp.ajax (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jsp.ajax Sat Nov 26 23:10:08 2005
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
+<portlet:defineObjects/>
+
+ <h1>Select Asset</h1>
+
+ <script src="<%=request.getContextPath()+response.encodeURL("/js/vcXMLRPC.js")%>" />
+ <script src="<%=request.getContextPath()+response.encodeURL("/js/finders.js")%>" />
+ <table cellspacing="2" cellpadding="3">
+ <tr>
+ <td class="property">
+ Asset search
+ </td>
+ <td>
+ <form name="find">
+ <input name="name" type="text" size="15" /> 
+ <input type="button" value="Search" onclick="findNames(form.name.value, document.forms['list'].SystemKey, 'asset', true, []);" />
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td class="property">
+ Choose an asset
+ </td>
+ <td>
+ <form name="list" >
+ <select name="SystemKey">
+ <option value="">---- Assets ------</option>
+ </select> 
+ <input type="submit" value="View" />
+ </form>
+ </td>
+ </tr>
+ </table>
+
+ <h2><%= request.getAttribute("hint") %></h2>
+
+ <h3>You've guessed <%= request.getAttribute("guesses") %> times.</h3>
+
+<portlet:renderURL var="submitUrl">
+ <portlet:param name="contid" value="<%= String.valueOf(request.getAttribute("contid")) %>"/>
+</portlet:renderURL>
+
+<form action="<%=submitUrl%>">
+ <input type="text" name="guess"/>
+ <input type="submit"/>
+ </form>
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jt
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jt?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jt (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/selectAsset.jt Sat Nov 26 23:10:08 2005
@@ -0,0 +1,37 @@
+
+ <h2>Select Asset</h2>
+
+ <table cellspacing="2" cellpadding="3">
+ <tr>
+ <td class="property">
+ Asset search
+ </td>
+ <td>
+ <form method="GET" action="${%renderUrl({params:{contid:contid}})%}">
+ <input name="name" type="text" size="15" /> 
+ <input type="submit" value="Search" />
+ </form>
+ </td>
+ </tr>
+ {if this["assets"]}
+ <tr>
+ <td class="property">
+ Choose an asset
+ </td>
+ <td>
+ <form method="GET" action="${%renderUrl({params:{contid:contid}})%}" >
+ <select name="SystemKey">
+
+ {for x in assets}
+ <option value="${x}">${x_index}</option>
+ {forelse}
+ <option value="">---- No assets found ------</option>
+ {/for}
+ </select> 
+ <input type="submit" value="View" />
+ </form>
+ </td>
+ </tr>
+ {/if}
+ </table>
+
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/success.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/success.jsp?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/success.jsp (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/success.jsp Sat Nov 26 23:10:08 2005
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
+ <h1>Success!</h1>
+
+ <h2>The number was: <%= request.getAttribute("random") %></h2>
+
+ <h3>It took you <%= request.getAttribute("guesses") %> tries.</h3>
+
+ <portlet:renderURL var="url" />
+ <p><a href="<%=url%>">Play again</a></p>
+
+
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jsp?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jsp (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jsp Sat Nov 26 23:10:08 2005
@@ -0,0 +1,2 @@
+<%=request.getAttribute("body")%>
+
Added: struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jt
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jt?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jt (added)
+++ struts/flow/trunk/src/examples/WEB-INF/portlet/viewAsset.jt Sat Nov 26 23:10:08 2005
@@ -0,0 +1,31 @@
+<h2>${xml.system.@nomenclature} ${xml.system.@name}</h2>
+
+<p>${xml.system.@description}</p>
+
+<h3>METOC Thresholds</h3>
+<table>
+ <tr>
+ <th>ID</th>
+ <th>Impact</th>
+ <th>Severity</th>
+ <th>Threshold</th>
+ </tr>
+ {for rule in xml..rule}
+ <tr>
+ <td>${rule.@key}</td>
+ <td>${rule.@condensedImpact}</td>
+ <td>{if parseInt(rule.@weight)==1}
+ Severe
+ {else}
+ Marginal
+ {/if}
+ </td>
+ <td>${rule.limit[0].@metocParameter} ${rule.limit[0].@operator} ${rule.limit[0].@value}</td>
+ </tr>
+ {/for}
+</table>
+
+<p>
+<a href="${renderUrl()}">Back</a>
+</p>
+
Modified: struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp (original)
+++ struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp Sat Nov 26 23:10:08 2005
@@ -5,13 +5,11 @@
<script type="text/javascript">
<!--
function init() {
- this.contid = "<%=request.getAttribute("contid")%>";
this.client = new ClientFlow("guess.do");
}
function cheat() {
- result = client.call("cheat", contid);
+ result = client.call("cheat");
alert("The secret number is "+result.secret+". After applying a penalty, you have guessed "+result.guesses+" times");
- contid = result.contid;
}
-->
</script>
Modified: struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js (original)
+++ struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js Sat Nov 26 23:10:08 2005
@@ -11,7 +11,7 @@
// send guess page to user and wait for response. Specify only cheat()
// can be called remotely.
- forwardAndWait("failure",
+ flow.forwardAndWait("failure",
{ "hint" : hint,
"guesses" : guesses},
["cheat"]);
@@ -35,7 +35,7 @@
}
// send success page to user
- forwardAndWait("success",
+ flow.forwardAndWait("success",
{"random" : random,
"guess" : guess,
"guesses" : guesses} );
Modified: struts/flow/trunk/src/examples/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/web.xml?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/web.xml (original)
+++ struts/flow/trunk/src/examples/WEB-INF/web.xml Sat Nov 26 23:10:08 2005
@@ -28,6 +28,25 @@
<load-on-startup>1</load-on-startup>
</servlet>
+ <servlet>
+ <servlet-name>FlowPortlet</servlet-name>
+ <display-name>FlowPortlet Wrapper</display-name>
+ <description>Automated generated Portlet Wrapper</description>
+ <servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
+ <init-param>
+ <param-name>portlet-guid</param-name>
+ <param-value>examples.FlowPortlet</param-value>
+ </init-param>
+ <init-param>
+ <param-name>portlet-class</param-name>
+ <param-value>org.apache.struts.flow.portlet.FlowPortlet</param-value>
+ </init-param>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>FlowPortlet</servlet-name>
+ <url-pattern>/FlowPortlet/*</url-pattern>
+ </servlet-mapping>
<!-- Action Servlet Mapping -->
<servlet-mapping>
Modified: struts/flow/trunk/src/examples/remote/clientFlow.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/remote/clientFlow.js?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/remote/clientFlow.js (original)
+++ struts/flow/trunk/src/examples/remote/clientFlow.js Sat Nov 26 23:10:08 2005
@@ -3,9 +3,9 @@
this.urlBase = url;
}
-ClientFlow.prototype.call = function(func, contid, data) {
+ClientFlow.prototype.call = function(func, data) {
if (!data) data = [];
- url = this.urlBase + "?contid="+contid+"&FlowCall="+func;
+ url = this.urlBase + "?FlowCall="+func;
req = this.xmlHTTPRequestObject();
if (req) {
req.open (this.method, url, false);
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java Sat Nov 26 23:10:08 2005
@@ -35,8 +35,8 @@
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
-import org.apache.struts.flow.core.JSFlow;
-import org.apache.struts.flow.core.JavaScriptInterpreter;
+import org.apache.struts.flow.core.javascript.ConversionHelper;
+import org.apache.struts.flow.core.Interpreter;
import org.apache.struts.flow.json.JSONArray;
import org.apache.struts.flow.json.JSONSerializer;
import org.mozilla.javascript.Scriptable;
@@ -51,8 +51,8 @@
*
*@return The interpreter value
*/
- protected JavaScriptInterpreter getInterpreter(String prefix) {
- return (JavaScriptInterpreter) servlet.getServletContext().getAttribute(FlowPlugIn.INTERPRETER_KEY+"/"+prefix);
+ protected Interpreter getInterpreter(String prefix) {
+ return (Interpreter) servlet.getServletContext().getAttribute(FlowPlugIn.INTERPRETER_KEY+"/"+prefix);
}
/**
@@ -61,9 +61,9 @@
*@param script The script to load the interpeter for
*@return The interpreter value
*/
- protected JavaScriptInterpreter getInterpreter(String prefix, String script) {
+ protected Interpreter getInterpreter(String prefix, String script) {
Map map = (Map)servlet.getServletContext().getAttribute(FlowPlugIn.INTERPRETERS_KEY+"/"+prefix);
- return (JavaScriptInterpreter) map.get(script);
+ return (Interpreter) map.get(script);
}
@@ -112,7 +112,7 @@
String contid = request.getParameter("contid");
- JavaScriptInterpreter interp = null;
+ Interpreter interp = null;
if (flowMapping.getScript() == null) {
interp = getInterpreter(flowMapping.getModuleConfig().getPrefix());
} else {
@@ -142,18 +142,49 @@
if (func == null || func.length() == 0) {
throw new ServletException("You must specify a function name to call");
} else {
+
+ // validate JSON in the body of a flowcall
+ if (isFlowCall) {
+ StringBuffer sb = new StringBuffer();
+ char[] buffer = new char[1024];
+ int len = 0;
+ BufferedReader reader = request.getReader();
+ while ((len = reader.read(buffer)) > 0 ) {
+ sb.append(buffer, 0, len);
+ }
+ String json = sb.toString();
+ System.out.println("processing json:"+json);
+ if (isValidJSON(json)) {
+ context.put("json", json);
+ System.out.println("setting json:"+json);
+ }
+
+ }
+
// call control script function
- interp.callFunction(func, args, context);
+ Object ret = interp.callFunction(func, args, context);
// retrieve page, continuation ID, and attributes from chain context
- String page = (String) JSFlow.jsobjectToObject(context.get(Constants.FORWARD_NAME_KEY));
+ String page = (String) ConversionHelper.jsobjectToObject(context.get(Constants.FORWARD_NAME_KEY));
contid = (String) context.get(Constants.CONTINUATION_ID_KEY);
Scriptable bizdata = (Scriptable) context.get(Constants.BIZ_DATA_KEY);
Map atts = null;
if (bizdata != null) {
- atts = JSFlow.jsobjectToMap(bizdata);
- }
- return dispatchToPage(request, response, mapping, page, contid, atts);
+ atts = ConversionHelper.jsobjectToMap(bizdata);
+ } else if (ret != null && ret instanceof Scriptable) {
+ atts = ConversionHelper.jsobjectToMap((Scriptable) ret);
+ }
+
+ // if a flowcall, return pure json
+ if (isFlowCall) {
+ String json = new JSONSerializer().serialize(atts);
+ response.getWriter().write(json);
+ response.getWriter().flush();
+ response.getWriter().close();
+ return null;
+ } else {
+ return dispatchToPage(request, response, mapping, page, contid, atts);
+ }
}
} else {
// --- continue an existing flow
@@ -161,25 +192,6 @@
// kick off continuation
context.put("id", "5");
- // validate JSON in the body of a flowcall
- if (isFlowCall) {
- StringBuffer sb = new StringBuffer();
- char[] buffer = new char[1024];
- int len = 0;
- BufferedReader reader = request.getReader();
- while ((len = reader.read(buffer)) > 0 ) {
- sb.append(buffer, 0, len);
- }
- String json = sb.toString();
- System.out.println("processing json:"+json);
- if (isValidJSON(json)) {
- context.put("json", json);
- context.put("func", func);
- System.out.println("setting json:"+json+" func:"+func);
- }
-
- }
-
interp.handleContinuation(
request.getParameter("contid"), new LinkedList(), context);
@@ -189,20 +201,9 @@
Scriptable bizdata = (Scriptable) context.get(Constants.BIZ_DATA_KEY);
Map atts = null;
if (bizdata != null) {
- atts = JSFlow.jsobjectToMap(bizdata);
+ atts = ConversionHelper.jsobjectToMap(bizdata);
}
-
- // if a flowcall, return pure json
- if (isFlowCall) {
- atts.put("contid", contid);
- String json = new JSONSerializer().serialize(atts);
- response.getWriter().write(json);
- response.getWriter().flush();
- response.getWriter().close();
- return null;
- } else {
- return dispatchToPage(request, response, mapping, page, contid, atts);
- }
+ return dispatchToPage(request, response, mapping, page, contid, atts);
}
}
@@ -234,7 +235,7 @@
Iterator attkeys = atts.keySet().iterator();
while (attkeys.hasNext()) {
String attkey = (String) attkeys.next();
- request.setAttribute(attkey, JSFlow.jsobjectToObject(atts.get(attkey)));
+ request.setAttribute(attkey, ConversionHelper.jsobjectToObject(atts.get(attkey)));
}
}
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/FlowPlugIn.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/FlowPlugIn.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/FlowPlugIn.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/FlowPlugIn.java Sat Nov 26 23:10:08 2005
@@ -27,10 +27,14 @@
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.flow.core.Factory;
-import org.apache.struts.flow.core.JavaScriptInterpreter;
+import org.apache.struts.flow.core.CompilingInterpreter;
+import org.apache.struts.flow.core.javascript.fom.FOM_JavaScriptInterpreter;
import org.apache.struts.flow.core.DefaultCallVariableRegistrar;
import org.apache.struts.flow.sugar.SugarWrapFactory;
import org.apache.struts.flow.ibatis.SqlMap;
+import org.apache.struts.flow.core.source.impl.ChainSourceResolver;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.*;
@@ -197,7 +201,7 @@
Factory.getContinuationsManager().setDefaultTimeToLive(ttl);
if (scripts != null && scripts.length() > 0) {
- JavaScriptInterpreter interp = createInterpreter();
+ CompilingInterpreter interp = createInterpreter(config.getPrefix());
context.setAttribute(key, interp);
String path = null;
String paths = scripts;
@@ -228,12 +232,12 @@
Map map =
new HashMap() {
public Object get(Object key) {
- JavaScriptInterpreter interp = (JavaScriptInterpreter) super.get(key);
+ CompilingInterpreter interp = (CompilingInterpreter) super.get(key);
if (interp == null) {
if (log.isDebugEnabled()) {
log.debug("Creating interpreter for " + key);
}
- interp = createInterpreter();
+ interp = createInterpreter(key.toString());
interp.register(scriptBase + key);
put(key, interp);
}
@@ -245,14 +249,16 @@
}
- private JavaScriptInterpreter createInterpreter() {
- JavaScriptInterpreter interp = new JavaScriptInterpreter();
+ private CompilingInterpreter createInterpreter(String id) {
+ FOM_JavaScriptInterpreter interp = new FOM_JavaScriptInterpreter();
+ interp.setInterpreterID(id);
+ interp.setSourceResolver(new ChainSourceResolver(new ServletWebContext(context, null, null)));
interp.setDebugger(debugger);
interp.setCheckTime(checkTime);
interp.setReloadScripts(reloadScripts);
interp.setWrapFactory(new SugarWrapFactory());
interp.initialize(classesToRegister);
- interp.register("/system.js");
+ interp.register("/org/apache/struts/flow/core/javascript/fom/fom_system.js");
interp.addVariableRegistrar(new DefaultCallVariableRegistrar(Struts.class, "struts"));
interp.addVariableRegistrar(new DefaultCallVariableRegistrar(SqlMap.class, "sqlMap"));
return interp;
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/Struts.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/Struts.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/Struts.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/Struts.java Sat Nov 26 23:10:08 2005
@@ -20,7 +20,7 @@
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessages;
import javax.servlet.*;
-import org.apache.commons.chain.Context;
+import org.apache.commons.chain.web.WebContext;
import org.apache.commons.chain.web.servlet.ServletWebContext;
import org.apache.struts.util.MessageResources;
@@ -42,7 +42,7 @@
/** Constructor for the JSLog object */
- public Struts(Context ctx) {
+ public Struts(WebContext ctx) {
if (ctx instanceof ServletWebContext) {
this.ctx = (ServletWebContext)ctx;
} else {
Added: struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java?rev=349187&view=auto
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java (added)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java Sat Nov 26 23:10:08 2005
@@ -0,0 +1,141 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts.flow.core;
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Map;
+
+/**
+ * Abstract superclass for various scripting languages used by Cocoon
+ * for flow control. Defines some useful behavior like the ability to
+ * reload script files if they get modified (useful when doing
+ * development), and passing the control to Cocoon's sitemap for
+ * result page generation.
+ * <p>
+ * Flow intrepreters belonging to different sitemaps should be isolated. To achieve this,
+ * class implements the {@link org.apache.avalon.framework.thread.SingleThreaded}. Since
+ * the sitemap engine looks up the flow intepreter once at sitemap build time, this ensures
+ * that each sitemap will use a different instance of this class. But that instance will
+ * handle all flow calls for a given sitemap, and must therefore be thread safe.
+ *
+ * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
+ * @since March 15, 2002
+ * @version CVS $Id: AbstractInterpreter.java 123711 2004-12-30 10:23:03Z cziegeler $
+ */
+public abstract class AbstractInterpreter implements Interpreter {
+
+ // The instance ID of this interpreter, used to identify user scopes
+ private String instanceID;
+
+ /**
+ * List of source locations that need to be resolved.
+ */
+ protected ArrayList needResolve = new ArrayList();
+
+ protected ContinuationsManager continuationsMgr;
+
+ /**
+ * Whether reloading of scripts should be done. Specified through
+ * the "reload-scripts" attribute in <code>flow.xmap</code>.
+ */
+ protected boolean reloadScripts;
+
+ /**
+ * Interval between two checks for modified script files. Specified
+ * through the "check-time" XML attribute in <code>flow.xmap</code>.
+ */
+ protected long checkTime;
+
+ public AbstractInterpreter() {
+ try {
+ continuationsMgr = Factory.getContinuationsManager();
+ } catch (Exception e) {
+ Factory.getLogger().error(e);
+ }
+ }
+
+ /**
+ * Set the unique ID for this interpreter, which can be used to distinguish user value scopes
+ * attached to the session.
+ */
+ public void setInterpreterID(String interpreterID) {
+ this.instanceID = interpreterID;
+ }
+
+ /**
+ * Get the unique ID for this interpreter, which can be used to distinguish user value scopes
+ * attached to the session.
+ *
+ * @return a unique ID for this interpreter
+ */
+ public String getInterpreterID() {
+ return this.instanceID;
+ }
+
+ /**
+ * Sets the interval between when the script should be looked at to see if
+ * it needs to be reloaded
+ *
+ *@param time The interval time in milliseconds
+ */
+ public void setCheckTime(long time) {
+ checkTime = time;
+ }
+
+
+ /**
+ * Sets whether to try to reload modified scripts or not
+ *
+ *@param val True to reload
+ */
+ public void setReloadScripts(boolean val) {
+ reloadScripts = val;
+ }
+
+ /**
+ * Registers a source file with the interpreter. Using this method
+ * an implementation keeps track of all the script files which are
+ * compiled. This allows them to reload the script files which get
+ * modified on the file system.
+ *
+ * <p>The parsing/compilation of a script file by an interpreter
+ * happens in two phases. In the first phase the file's location is
+ * registered in the <code>needResolve</code> array.
+ *
+ * <p>The second is possible only when a Cocoon
+ * <code>Environment</code> is passed to the Interpreter. This
+ * allows the file location to be resolved using Cocoon's
+ * <code>SourceFactory</code> class.
+ *
+ * <p>Once a file's location can be resolved, it is removed from the
+ * <code>needResolve</code> array and placed in the
+ * <code>scripts</code> hash table. The key in this hash table is
+ * the file location string, and the value is a
+ * DelayedRefreshSourceWrapper instance which keeps track of when
+ * the file needs to re-read.
+ *
+ * @param source the location of the script
+ *
+ * @see org.apache.cocoon.environment.Environment
+ * @see org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper
+ */
+ public void register(String source) {
+ synchronized (this) {
+ needResolve.add(source);
+ }
+ }
+}
Propchange: struts/flow/trunk/src/java/org/apache/struts/flow/core/AbstractInterpreter.java
------------------------------------------------------------------------------
svn:executable = *
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/core/CompilingInterpreter.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/core/CompilingInterpreter.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/core/CompilingInterpreter.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/core/CompilingInterpreter.java Sat Nov 26 23:10:08 2005
@@ -1,137 +1,115 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2004 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.struts.flow.core;
-import java.io.*;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import org.apache.struts.flow.core.source.Source;
+import org.apache.struts.flow.core.source.SourceResolver;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
/**
- * This is a base class for all interpreters compiling the scripts
+ * This is a base class for all interpreters compiling the scripts
*
- *@author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
- *@author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
- *@author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- *@version CVS $Id: CompilingInterpreter.java,v 1.2 2004/06/02 21:56:54 mrdon
- * Exp $
+ * @author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
+ * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: CompilingInterpreter.java 55850 2004-10-28 13:43:12Z vgritsenko $
*/
-public abstract class CompilingInterpreter {
+public abstract class CompilingInterpreter
+ extends AbstractInterpreter {
/**
- * Mapping of String objects (absolute script paths) to ScriptSourceEntry's
+ * A source resolver
*/
- protected Map compiledScripts = new HashMap();
-
+ protected SourceResolver sourceresolver;
/**
- * TODO - This is a little bit strange, the interpreter calls get Script on
- * the ScriptSourceEntry which in turn calls reallyCompileScript on the
- * interpreter. I think we need more refactoring here.
- *
- *@param context The script context
- *@param source The script file
- *@return A compiled script object
- *@exception IOException If anything goes wrong
+ * Mapping of String objects (source uri's) to ScriptSourceEntry's
*/
- protected abstract Script compileScript(Context context,
- File source) throws IOException;
+ protected Map compiledScripts = new HashMap();
+
+ public CompilingInterpreter() {
+ super();
+ }
+
+ public void setSourceResolver(SourceResolver r) {
+ this.sourceresolver = r;
+ }
- /**
- * Compiles the script
- *
- *@param context The script context
- *@param source The script file
- *@return The compiled script object
- *@exception IOException If anything goes wrong
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
- protected abstract Script reallyCompileScript(Context context,
- File source) throws IOException;
-
+ public void dispose() {
+ if (this.compiledScripts != null) {
+ Iterator i = this.compiledScripts.values().iterator();
+ while (i.hasNext()) {
+ ScriptSourceEntry current = (ScriptSourceEntry)i.next();
+ this.sourceresolver.release(current.getSource());
+ }
+ this.compiledScripts = null;
+ }
+ this.sourceresolver = null;
+ }
/**
- * An association between the script source and the compiled Script. This
- * class also calles the parent class to perform compilation lazily
+ * TODO - This is a little bit strange, the interpreter calls
+ * get Script on the ScriptSourceEntry which in turn
+ * calls compileScript on the interpreter. I think we
+ * need more refactoring here.
*/
+ protected abstract Script compileScript(Context context,
+ Scriptable scope,
+ Source source) throws Exception;
+
protected class ScriptSourceEntry {
- private final File source;
+ final private Source source;
private Script script;
private long compileTime;
-
- /**
- * Constructor for the ScriptSourceEntry object
- *
- *@param source Script source file
- */
- public ScriptSourceEntry(File source) {
+ public ScriptSourceEntry(Source source) {
this.source = source;
}
-
- /**
- * Constructor for the ScriptSourceEntry object
- *
- *@param source Script source file
- *@param script Compiled script
- *@param t Compile time in milliseconds
- */
- public ScriptSourceEntry(File source, Script script, long t) {
+ public ScriptSourceEntry(Source source, Script script, long t) {
this.source = source;
this.script = script;
this.compileTime = t;
}
-
- /**
- * Gets the script source
- *
- *@return The source value
- */
- public File getSource() {
+ public Source getSource() {
return source;
}
-
- /**
- * Gets the compiled script. The source is compiled if it hasn't been
- * already.
- *
- *@param context The script context
- *@param scope The script scope
- *@param refresh Whether to check to see if script needs to be
- * reloaded by looking at the lastModified property
- *@param interpreter The compiling interpreter
- *@return The script value
- *@exception IOException If anything goes wrong
- */
public Script getScript(Context context, Scriptable scope,
- boolean refresh, CompilingInterpreter interpreter)
- throws IOException {
- if (script == null || (compileTime < source.lastModified() && refresh)) {
- script = interpreter.reallyCompileScript(context, source);
- compileTime = source.lastModified();
+ boolean refresh, CompilingInterpreter interpreter)
+ throws Exception {
+ if (refresh) {
+ source.refresh();
+ }
+ if (script == null || compileTime < source.getLastModified()) {
+ script = interpreter.compileScript(context, scope, source);
+ compileTime = source.getLastModified();
}
return script;
}
}
-
}
-
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsDisposer.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsDisposer.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsDisposer.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsDisposer.java Sat Nov 26 23:10:08 2005
@@ -19,7 +19,7 @@
* ContinuationsDisposer declares the contract for the clean-up of specfic
* continuations.
* <p>
- * Typically an Interpreter implementation that produces continuation
+ * Typically a {@link Interpreter} implementation that produces continuation
* objects which require proper clean up will implement this interface to get
* a call-back in the event of the ContinuationsManager deciding to invalidate
* a WebContinuation.
Modified: struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManager.java
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManager.java?rev=349187&r1=349186&r2=349187&view=diff
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManager.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/core/ContinuationsManager.java Sat Nov 26 23:10:08 2005
@@ -1,96 +1,112 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.struts.flow.core;
+import java.util.List;
+import org.apache.commons.chain.web.WebContext;
+
/**
- * The interface of the Continuations manager. The continuation manager
- * maintains a forrest of {@link WebContinuation} trees. Each tree defines the
- * flow of control for a user within the application. A <code>WebContinuation</code>
- * is created for a continuation object from the scripting language used. A
- * continuation object in the implementation of the scripting language is an
- * opaque object here. It is only stored inside the <code>WebContinuation</code>
- * , without being interpreted in any way.
+ * The interface of the Continuations manager.
+ *
+ * The continuation manager maintains a forrest of {@link
+ * WebContinuation} trees. Each tree defines the flow of control for a
+ * user within the application.
*
- *@author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
- *@since March 19, 2002
- *@see WebContinuation
- *@version CVS $Id: ContinuationsManager.java,v 1.3 2004/06/02 21:56:54 mrdon
- * Exp $
+ * A <code>WebContinuation</code> is created for a continuation object
+ * from the scripting language used. A continuation object in the
+ * implementation of the scripting language is an opaque object
+ * here. It is only stored inside the <code>WebContinuation</code>,
+ * without being interpreted in any way.
+ *
+ * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
+ * @since March 19, 2002
+ * @see WebContinuation
+ * @version CVS $Id: ContinuationsManager.java 164239 2005-04-22 13:54:29Z reinhard $
*/
public interface ContinuationsManager {
/**
- * Create a <code>WebContinuation</code> object given a native continuation
- * object and its parent. If the parent continuation is null, the <code>WebContinuation</code>
- * returned becomes the root of a tree in the forrest.
+ * Create a <code>WebContinuation</code> object given a native
+ * continuation object and its parent. If the parent continuation is
+ * null, the <code>WebContinuation</code> returned becomes the root
+ * of a tree in the forrest.
*
- *@param kont an <code>Object</code> value
- *@param parentKont a <code>WebContinuation</code> value
- *@param timeToLive an <code>int</code> value indicating how long in
- * seconds this continuation will live in the server if not accessed
- *@param disposer a <code>ContinuationsDisposer</code> instance to
- * called when the continuation gets cleaned up.
- *@return a <code>WebContinuation</code> value
- *@see WebContinuation
+ * @param kont an <code>Object</code> value
+ * @param parentKont a <code>WebContinuation</code> value
+ * @param timeToLive an <code>int</code> value indicating how long
+ * in seconds this continuation will live in the server if not
+ * accessed
+ * @param interpreterId id of interpreter invoking continuation creation
+ * @param disposer a <code>ContinuationsDisposer</code> instance to called when
+ * the continuation gets cleaned up.
+ * @return a <code>WebContinuation</code> value
+ * @see WebContinuation
*/
public WebContinuation createWebContinuation(Object kont,
- WebContinuation parentKont,
- int timeToLive,
- ContinuationsDisposer disposer);
-
+ WebContinuation parentKont,
+ int timeToLive,
+ String interpreterId,
+ ContinuationsDisposer disposer,
+ WebContext webctx);
/**
- * Invalidates a <code>WebContinuation</code>. This effectively means that
- * the continuation object associated with it will no longer be accessible
- * from Web pages. Invalidating a <code>WebContinuation</code> invalidates
- * all the <code>WebContinuation</code>s which are children of it.
+ * Invalidates a <code>WebContinuation</code>. This effectively
+ * means that the continuation object associated with it will no
+ * longer be accessible from Web pages. Invalidating a
+ * <code>WebContinuation</code> invalidates all the
+ * <code>WebContinuation</code>s which are children of it.
*
- *@param k a <code>WebContinuation</code> value
+ * @param k a <code>WebContinuation</code> value
*/
- public void invalidateWebContinuation(WebContinuation k);
-
+ public void invalidateWebContinuation(WebContinuation k, WebContext webctx);
/**
- * Given a <code>WebContinuation</code> id, retrieve the associated <code>WebContinuation</code>
- * object.
+ * Given a <code>WebContinuation</code> id, retrieve the associated
+ * <code>WebContinuation</code> object.
+ * @param id a <code>String</code> value
+ * @param interpreterId Id of an interpreter that queries for
+ * the continuation
*
- *@param id a <code>String</code> value
- *@return a <code>WebContinuation</code> object, or null if no such
- * <code>WebContinuation</code> could be found.
+ * @return a <code>WebContinuation</code> object, null if no such
+ * <code>WebContinuation</code> could be found. Also null if
+ * <code>WebContinuation</code> was found but interpreter id does
+ * not match the one that the continuation was initialy created for.
*/
- public WebContinuation lookupWebContinuation(String id);
-
+ public WebContinuation lookupWebContinuation(String id, String interpreterId, WebContext webctx);
/**
- * Prints debug information about all web continuations into the log file.
- *
- *@see WebContinuation#display()
+ * Prints debug information about all web continuations into the log file.
+ * @see WebContinuation#display()
*/
public void displayAllContinuations();
-
-
+
+ /**
+ * Get a list of all continuations as <code>WebContinuationDataBean</code> objects.
+ */
+ public List getWebContinuationsDataBeanList();
+
/**
* Set the default time to live value
*
*@param ttl The time-to-live in milliseconds
*/
public void setDefaultTimeToLive(int ttl);
-
-
+
+ public void setExpirationPeriod(long period);
+
/** Destroys all continuations and any other resident objects */
public void destroy();
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org