bdelacretaz 2004/06/04 02:22:17
Modified: . status.xml
src/blocks/tour/samples/flow sitemap.xmap
src/blocks/tour/samples/intro/docs toc.xml
Added: src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes
Circle.java Rectangular.java Shape.java Square.java
src/blocks/tour/samples/flow/docs java-shapes.xml
src/blocks/tour/samples/flow/java-shapes circle.xml
java-shapes.js rectangular.xml results.xml
select.xml square.xml
Log:
tour block: java shapes sample added
Revision Changes Path
1.350 +4 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.349
retrieving revision 1.350
diff -u -r1.349 -r1.350
--- status.xml 4 Jun 2004 08:59:20 -0000 1.349
+++ status.xml 4 Jun 2004 09:22:16 -0000 1.350
@@ -205,6 +205,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="BD" type="add" due-to="Stavros Kounis" fixes-bug="28834">
+ tour block: added Java shapes sample, with thanks to Stavros!
+ </action>
<action dev="AG" type="update">
updated Groovy to 1.0-beta5, qdox to 1.4 an util.concurrent to 1.3.4
</action>
1.1
cocoon-2.1/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java
Index: Circle.java
===================================================================
/*
* 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.cocoon.samples.tour.shapes;
/**
* Circle Shape for tour block java-shapes sample
*/
public class Circle implements Shape{
double _r;
public String getName() {
return "Circle";
}
/** Creates a new instance of Circle */
public Circle(double r) {
_r = r;
}
public double area() {
return 3.14 * _r * _r;
}
public double perimeter() {
return 2 * 3.14 * _r;
}
}
1.1
cocoon-2.1/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java
Index: Rectangular.java
===================================================================
/*
* 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.cocoon.samples.tour.shapes;
/**
* Rectangular Shape for tour block java-shapes sample
*/
public class Rectangular implements Shape{
double _h;
double _b;
/** Creates a new instance of StrCount */
public Rectangular(double h, double b) {
_h = h;
_b = b;
}
public String getName() {
return "Rectangular";
}
public double area(){
return _h * _b;
}
public double perimeter(){
return (_h + _b) * 2;
}
}
1.1
cocoon-2.1/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java
Index: Shape.java
===================================================================
/*
* 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.cocoon.samples.tour.shapes;
/**
* Shape interface for tour block java-shapes sample
*/
public interface Shape {
String getName();
abstract double area();
abstract double perimeter();
}
1.1
cocoon-2.1/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java
Index: Square.java
===================================================================
/*
* 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.cocoon.samples.tour.shapes;
/**
* Square Shape for tour block java-shapes sample
*/
public class Square implements Shape {
float _b;
/** Creates a new instance of Square */
public Square(float b) {
_b = b;
}
public String getName() {
return "Square";
}
public double area() {
return _b*_b;
}
public double perimeter() {
return 4*_b;
}
}
1.2 +1 -0 cocoon-2.1/src/blocks/tour/samples/flow/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/tour/samples/flow/sitemap.xmap,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sitemap.xmap 11 May 2004 06:52:30 -0000 1.1
+++ sitemap.xmap 4 Jun 2004 09:22:16 -0000 1.2
@@ -31,6 +31,7 @@
<map:flow id="flow" language="javascript">
<map:script src="number-guess/guess-number.js"/>
<map:script src="multi-page/multi-page.js"/>
+ <map:script src="java-shapes/java-shapes.js"/>
</map:flow>
<!-- reusable parts of pipelines -->
1.1
cocoon-2.1/src/blocks/tour/samples/flow/docs/java-shapes.xml
Index: java-shapes.xml
===================================================================
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
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.
-->
<page
xmlns:cinclude="http://apache.org/cocoon/include/1.0"
>
<content>
<p>
In this example, java classes are used to calculate the area and
perimeter of shapes.
Various Java classes are instantiated and used from Flow.
</p>
<p>
Start the example <a href="../java-shapes/startShape">here</a>.
</p>
<h2>The sitemap</h2>
<p>
There's nothing new in the sitemap, our use of
variables allows the exact same sitemap to be reused for
both our Flow examples.
</p>
<p>
The only specific thing is the importing of the java-shapes.js
flowscript, but this was already present for the previous
example:
<cinclude:include element="xml-code"
src="cocoon:/xml-element/flow/sitemap.xmap/flow"/>
</p>
<h2>Java code</h2>
<p>
The java code (interface Shape, classes Rectangular, Square,
Circle) is fairly trivial,
and the computations could easily be done in javascript for such
a simple case.
</p>
<p>
However, our goal is to show interactions between Flow and java
classes, so you shouldn't pay
too much attention to the java code, except to note that it has
no knowledge of Avalon - our java
objects are just POJOs: Plain Old Java Objects.
</p>
<h2>Flowscript code</h2>
<p>
Here's the Flowscript which has three steps.
<ol>
<li>Get the selected shape from user and prepare the next
page.</li>
<li>Get shape's informations (width, height or radius) and
instantiate the correct java class for the selected shape.</li>
<li>Use java class to calculate area and perimeter and display
the results</li>
</ol>
<cinclude:include element="flowscript-code"
src="cocoon:/text-file/flow/java-shapes/java-shapes.js"/>
</p>
<h2>JXTemplate view</h2>
<p>
Shape selection
</p>
<cinclude:include element="xml-code"
src="cocoon:/xml-element/flow/java-shapes/select.xml/page"/>
<p>
Here the user can select a shape.
</p>
</content>
</page>
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/circle.xml
Index: circle.xml
===================================================================
<?xml version="1.0"?>
<!--
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.
-->
<!--
Shape's area and perimeter calculation example.
Use JXTemplateTransformer to generate an HTML form
showing values set by Flowscript
-->
<page id="page" xmlns:c="http://apache.org/cocoon/templates/jx/1.0">
<title>Flow example: Circle shape (id=${shapeId})</title>
<content>
<h2>Please enter circle radius</h2>
<form method="post" action="${continuation.id}.continue">
r:<input type="text" name="r"/>
<br/>
<br/>
<input type="submit"/>
</form>
<p class="footer">
<a href="../docs/index.html">Flow examples</a>
</p>
</content>
</page>
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/java-shapes.js
Index: java-shapes.js
===================================================================
/*
* 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.
*/
// Shape's area and perimeter calculation example.
var calculator = Packages.org.apache.cocoon.samples.supersonic.shapes.Shape;
function public_startShape() {
var hint = "Calculate shape's area and perimeter using logic in java. ";
// let user select shape
cocoon.sendPageAndWait("java-shapes/views/select", {"hint" : hint});
var shapeId = cocoon.request.get("shape");
// send shape-specific view
cocoon.sendPageAndWait("java-shapes/views/" + shapeId, {"shapeId" :
shapeId});
// instantiate appropriate calculator
switch (shapeId){
case "square":
var b = parseInt( cocoon.request.get("b") );
calculator = new
Packages.org.apache.cocoon.samples.tour.shapes.Square(b);
break;
case "rectangular":
var h = parseInt( cocoon.request.get("h") );
var b = parseInt( cocoon.request.get("b") );
calculator = new
Packages.org.apache.cocoon.samples.tour.shapes.Rectangular(b,h);
break;
case "circle":
var r = parseInt( cocoon.request.get("r") );
calculator = new
Packages.org.apache.cocoon.samples.tour.shapes.Circle(r);
break;
}
// compute results
var a = calculator.area();
var p = calculator.perimeter();
cocoon.sendPage("java-shapes/views/results", {"area" : a, "perimeter" :
p, "shape" : shapeId} );
}
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/rectangular.xml
Index: rectangular.xml
===================================================================
<?xml version="1.0"?>
<!--
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.
-->
<!--
Shape's area and perimeter calculation example.
Use JXTemplateTransformer to generate an HTML form
showing values set by Flowscript
-->
<page id="page" xmlns:c="http://apache.org/cocoon/templates/jx/1.0">
<title>Flow example: Rectangular shape (id=${shapeId})</title>
<content>
<h2>Please enter rectangle dimensions</h2>
<form method="post" action="${continuation.id}.continue">
width:<input type="text" name="b"/>
<br/>
height:<input type="text" name="h"/>
<br/>
<br/>
<input type="submit"/>
</form>
<p class="footer">
<a href="../docs/index.html">Flow examples</a>
</p>
</content>
</page>
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/results.xml
Index: results.xml
===================================================================
<?xml version="1.0"?>
<!--
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.
-->
<!--
Shape's area and perimeter calculation example.
Use JXTemplateTransformer to generate an HTML form
showing values set by Flowscript
-->
<page xmlns:c="http://apache.org/cocoon/templates/jx/1.0">
<title>Flow example: Shapes</title>
<content>
<h2>Results!</h2>
<p>
Area and perimeter of selected shape: <b>${shape}</b></p>
<p>
area: <b>${area}</b> <br/>
perimeter: <b>${perimeter}</b><br/>
</p>
<p class="footer">
<a href="startShape">Restart with a new shape</a>
<br/>
<a href="../docs/index.html">Flow examples</a>
</p>
</content>
</page>
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/select.xml
Index: select.xml
===================================================================
<?xml version="1.0"?>
<!--
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.
-->
<!--
Shape's area and perimeter calculation example.
Use JXTemplateTransformer to generate an HTML form
showing values set by Flowscript
-->
<page id="page" xmlns:c="http://apache.org/cocoon/templates/jx/1.0">
<title>Flow example: Shapes</title>
<content>
<h2>${hint}</h2>
<form method="post" action="${continuation.id}.continue">
<p>Select shape</p>
<select name="shape">
<optgroup label="Select shape">
<option value="square">Square</option>
<option
value="rectangular">Rectangular</option>
<option value="circle">Circle</option>
</optgroup>
</select>
<input type="submit"/>
</form>
<p class="footer">
<a href="../docs/index.html">Flow examples</a>
</p>
</content>
</page>
1.1
cocoon-2.1/src/blocks/tour/samples/flow/java-shapes/square.xml
Index: square.xml
===================================================================
<?xml version="1.0"?>
<!--
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.
-->
<!--
Shape's area and perimeter calculation example.
Use JXTemplateTransformer to generate an HTML form
showing values set by Flowscript
-->
<page id="page" xmlns:c="http://apache.org/cocoon/templates/jx/1.0">
<title>Flow example: Square shape (id=${shapeId})</title>
<content>
<h2>Please enter the side-length of the square</h2>
<form method="post" action="${continuation.id}.continue">
side-length:<input type="text" name="b"/>
<br/>
<br/>
<input type="submit"/>
</form>
<p class="footer">
<a href="../docs/index.html">Flow examples</a>
</p>
</content>
</page>
1.3 +1 -0 cocoon-2.1/src/blocks/tour/samples/intro/docs/toc.xml
Index: toc.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/tour/samples/intro/docs/toc.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- toc.xml 26 May 2004 21:27:41 -0000 1.2
+++ toc.xml 4 Jun 2004 09:22:17 -0000 1.3
@@ -48,6 +48,7 @@
<toc-item name="Flow examples" href="flow/docs/index"/>
<toc-item name="Number guessing game" href="flow/docs/number-guess"/>
<toc-item name="Multi-page form" href="flow/docs/multi-page"/>
+ <toc-item name="Java shapes: using Java objects from Flow"
href="flow/docs/java-shapes"/>
</toc-section>
<toc-section name="Cocoon Forms sample application">