mpo 2004/04/09 04:03:28
Modified: src/blocks/forms/samples welcome.xml
Added: src/blocks/forms/java/org/apache/cocoon/forms/samples/bindings
DateWrapper.java
src/blocks/forms/samples/forms/binding 03aggregate-def.xml
03aggregate-template.xml 03aggregate-data.xml
03aggregate-bind.xml
Log:
Adding binding sample 03 'aggregate'.
Revision Changes Path
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/samples/bindings/DateWrapper.java
Index: DateWrapper.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.forms.samples.bindings;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
/**
* DateWrapper is a specific sample test-class to demo the aggregate-binding.
* This class must loook quite awkward, but is specially designed to look
* similar to the XML structure used in the same sample.
*
* That is also why all field types here are simply kept to String
* This will cause the binding-conversion to be applied.
*/
public class DateWrapper {
private Map split = new HashMap();
public DateWrapper(String day, String month, String year) {
setDay(day);
setMonth(month);
setYear(year);
}
public String getCombined() {
return "" + getDay() +"/" + getMonth() + "/" + getYear();
}
public void setCombined(String fullDate) {
StringTokenizer st = new StringTokenizer(fullDate, "/");
setDay(st.nextToken());
setMonth(st.nextToken());
setYear(st.nextToken());
}
public Map getSplit() {
return this.split;
}
/**
* @return Returns the day.
*/
public String getDay() {
return split.get("day").toString();
}
/**
* @param day The day to set.
*/
public void setDay(String day) {
split.put("day", day);
}
/**
* @return Returns the month.
*/
public String getMonth() {
return split.get("month").toString();
}
/**
* @param month The month to set.
*/
public void setMonth(String month) {
split.put("month", month);
}
/**
* @return Returns the year.
*/
public String getYear() {
return split.get("year").toString();
}
/**
* @param year The year to set.
*/
public void setYear(String year) {
split.put("year", year);
}
/**
* @return
*/
public String toString() {
return "Wrapped Date as combined='" + getCombined() + "' as split=["
+ getDay() + ", " + getMonth() + ", " + getYear() + "]";
}
}
1.1
cocoon-2.1/src/blocks/forms/samples/forms/binding/03aggregate-def.xml
Index: 03aggregate-def.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.
-->
<fd:form
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
<fd:widgets>
<fd:aggregatefield id="date-combined" required="true">
<fd:label>
Enter Date
<br/><small>(Format is: dd/MM/yyyy)
<br/>Year should be between 1990 and 2010. Day should be between 1 to
15</small>
</fd:label>
<fd:datatype base="date">
<fd:convertor>
<fd:patterns>
<fd:pattern>dd/MM/yyyy</fd:pattern>
</fd:patterns>
</fd:convertor>
<fd:validation>
<fd:range min="Date(1990, 1, 1)" max="Date(2010, 12, 31)">
<fd:failmessage>Enter date in 1990 to 2010 year</fd:failmessage>
</fd:range>
</fd:validation>
</fd:datatype>
<fd:split pattern="([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})">
<fd:map group="1" field="day"/>
<fd:map group="2" field="month"/>
<fd:map group="3" field="year"/>
<fd:failmessage>Not a valid date.</fd:failmessage>
</fd:split>
<fd:combine expression='Date(year, month, day)'/>
<fd:widgets>
<fd:field id="day" required="true">
<fd:datatype base="integer"/>
<fd:label>
Enter Day
<br/><small>(Day should be between 1 to 15)</small>
</fd:label>
<fd:validation>
<fd:range min="1" max="15">
<fd:failmessage>Enter date between 1st and 15th day of the
month.</fd:failmessage>
</fd:range>
</fd:validation>
</fd:field>
<fd:field id="month" required="true">
<fd:label>
Enter Month
<br/><small>(Month should be between 1 to 12)</small>
</fd:label>
<fd:datatype base="integer"/>
<fd:selection-list>
<fd:item value="">
<fd:label>Select Month</fd:label>
</fd:item>
<fd:item value="1">
<fd:label>January</fd:label>
</fd:item>
<fd:item value="2">
<fd:label>February</fd:label>
</fd:item>
<fd:item value="3">
<fd:label>March</fd:label>
</fd:item>
<fd:item value="4">
<fd:label>April</fd:label>
</fd:item>
<fd:item value="5">
<fd:label>May</fd:label>
</fd:item>
<fd:item value="6">
<fd:label>June</fd:label>
</fd:item>
<fd:item value="7">
<fd:label>July</fd:label>
</fd:item>
<fd:item value="8">
<fd:label>August</fd:label>
</fd:item>
<fd:item value="9">
<fd:label>September</fd:label>
</fd:item>
<fd:item value="10">
<fd:label>October</fd:label>
</fd:item>
<fd:item value="11">
<fd:label>November</fd:label>
</fd:item>
<fd:item value="12">
<fd:label>December</fd:label>
</fd:item>
</fd:selection-list>
</fd:field>
<fd:field id="year" required="true">
<fd:label>
Enter Year
<br/><small>(Year should be between 1990 to 2010)</small>
</fd:label>
<fd:datatype base="integer"/>
</fd:field>
</fd:widgets>
</fd:aggregatefield>
<!-- if ever we were looking for a good reason to introduce
the @define and @extends for widget-reuse,
here is the same thing again with just a different id: -->
<fd:aggregatefield id="date-split" required="true">
<fd:label>
Enter Date
<br/><small>(Format is: dd/MM/yyyy)
<br/>Year should be between 1990 and 2010. Day should be between 1 to
15</small>
</fd:label>
<fd:datatype base="date">
<fd:convertor>
<fd:patterns>
<fd:pattern>dd/MM/yyyy</fd:pattern>
</fd:patterns>
</fd:convertor>
<fd:validation>
<fd:range min="Date(1990, 1, 1)" max="Date(2010, 12, 31)">
<fd:failmessage>Enter date in 1990 to 2010 year</fd:failmessage>
</fd:range>
</fd:validation>
</fd:datatype>
<fd:split pattern="([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})">
<fd:map group="1" field="day"/>
<fd:map group="2" field="month"/>
<fd:map group="3" field="year"/>
<fd:failmessage>Not a valid date.</fd:failmessage>
</fd:split>
<fd:combine expression='Date(year, month, day)'/>
<fd:widgets>
<fd:field id="day" required="true">
<fd:datatype base="integer"/>
<fd:label>
Enter Day
<br/><small>(Day should be between 1 to 15)</small>
</fd:label>
<fd:validation>
<fd:range min="1" max="15">
<fd:failmessage>Enter date between 1st and 15th day of the
month.</fd:failmessage>
</fd:range>
</fd:validation>
</fd:field>
<fd:field id="month" required="true">
<fd:label>
Enter Month
<br/><small>(Month should be between 1 to 12)</small>
</fd:label>
<fd:datatype base="integer"/>
<fd:selection-list>
<fd:item value="">
<fd:label>Select Month</fd:label>
</fd:item>
<fd:item value="1">
<fd:label>January</fd:label>
</fd:item>
<fd:item value="2">
<fd:label>February</fd:label>
</fd:item>
<fd:item value="3">
<fd:label>March</fd:label>
</fd:item>
<fd:item value="4">
<fd:label>April</fd:label>
</fd:item>
<fd:item value="5">
<fd:label>May</fd:label>
</fd:item>
<fd:item value="6">
<fd:label>June</fd:label>
</fd:item>
<fd:item value="7">
<fd:label>July</fd:label>
</fd:item>
<fd:item value="8">
<fd:label>August</fd:label>
</fd:item>
<fd:item value="9">
<fd:label>September</fd:label>
</fd:item>
<fd:item value="10">
<fd:label>October</fd:label>
</fd:item>
<fd:item value="11">
<fd:label>November</fd:label>
</fd:item>
<fd:item value="12">
<fd:label>December</fd:label>
</fd:item>
</fd:selection-list>
</fd:field>
<fd:field id="year" required="true">
<fd:label>
Enter Year
<br/><small>(Year should be between 1990 to 2010)</small>
</fd:label>
<fd:datatype base="integer"/>
</fd:field>
</fd:widgets>
</fd:aggregatefield>
</fd:widgets>
</fd:form>
1.1
cocoon-2.1/src/blocks/forms/samples/forms/binding/03aggregate-template.xml
Index: 03aggregate-template.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.
-->
<!--+
| CForms aggregate sample binding. Represent values of two aggregate
| fields as single input fields.
|
| CVS $Id: 03aggregate-template.xml,v 1.1 2004/04/09 11:03:27 mpo Exp $
+-->
<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<title>Aggregate Field Binding</title>
<content>
<p>
On this form, you can enter a date, either split over it's parts or as
one entry.
</p>
<ft:form-template>
<fi:group>
<fi:styling layout="columns" />
<fi:items>
<ft:widget id="date-combined"/>
<ft:aggregate-widget id="date-split">
<ft:widget id="day"/>
<ft:widget id="month"/>
<ft:widget id="year"/>
</ft:aggregate-widget>
</fi:items>
</fi:group>
<input type="submit" value="Submit"/>
</ft:form-template>
</content>
</page>
1.1
cocoon-2.1/src/blocks/forms/samples/forms/binding/03aggregate-data.xml
Index: 03aggregate-data.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.
-->
<root>
<match-combined>
<combined/>
<split>
<day>07</day>
<month>04</month>
<year>2004</year>
</split>
</match-combined>
<match-split>
<combined>07/04/2004</combined>
<split/>
</match-split>
</root>
1.1
cocoon-2.1/src/blocks/forms/samples/forms/binding/03aggregate-bind.xml
Index: 03aggregate-bind.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.
-->
<fb:context
xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
path="/" >
<fb:context path="match-combined">
<fb:aggregate id="date-combined" path="split">
<fb:value id="day" path="day">
<fd:convertor datatype="integer" />
</fb:value>
<fb:value id="month" path="month">
<fd:convertor datatype="integer" />
</fb:value>
<fb:value id="year" path="year">
<fd:convertor datatype="integer" />
</fb:value>
</fb:aggregate>
<fb:value id="date-combined" path="combined" direction="save">
<fd:convertor datatype="date" >
<fd:patterns>
<fd:pattern>dd/MM/yyyy</fd:pattern>
</fd:patterns>
</fd:convertor>
</fb:value>
</fb:context>
<fb:context path="match-split">
<fb:aggregate id="date-split" path="split" direction="save">
<fb:value id="day" path="day">
<fb:convertor datatype="integer" />
</fb:value>
<fb:value id="month" path="month">
<fb:convertor datatype="integer" />
</fb:value>
<fb:value id="year" path="year">
<fb:convertor datatype="integer" />
</fb:value>
</fb:aggregate>
<fb:value id="date-split" path="combined" >
<fd:convertor datatype="date" >
<fd:patterns>
<fd:pattern>dd/MM/yyyy</fd:pattern>
</fd:patterns>
</fd:convertor>
</fb:value>
</fb:context>
</fb:context>
1.6 +4 -3 cocoon-2.1/src/blocks/forms/samples/welcome.xml
Index: welcome.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/samples/welcome.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- welcome.xml 6 Apr 2004 08:52:52 -0000 1.5
+++ welcome.xml 9 Apr 2004 11:03:27 -0000 1.6
@@ -54,9 +54,10 @@
</note>
<sample name="1. Binding Simple Values"
href="binding-01value.flow">fb:*/@direction and fb:value/*</sample>
<sample name="2. Lenient Binding"
href="binding-02lenient.flow">fb:*/@lenient</sample>
- <!-- TODO: provide more tutorial samples like these:
<sample name="3. Aggregate Binding"
href="binding-03aggregate.flow">fb:aggregate</sample>
- <sample name="4. Repeater Binding"
href="binding-04repeater.flow">fb:repeater</sample>
+ <!-- TODO: provide more tutorial samples like these:
+ <sample name="4a. MultiValue/Repeater Binding"
href="binding-03multi.flow">fb:multi-value</sample>
+ <sample name="4b. Repeater Binding"
href="binding-06repeater.flow">fb:repeater</sample>
-->
<sample name="5. Custom Bindings using Java or Javascript"
href="binding-05custom.flow">fb:javascript and fb:custom</sample>
</group>