You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2003/07/03 11:03:20 UTC
cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation WidgetReplacingPipe.java
bruno 2003/07/03 02:03:20
Modified: src/blocks/woody/java/org/apache/cocoon/woody/formmodel
AbstractWidget.java AggregateField.java
ExpressionContextImpl.java Form.java Repeater.java
Widget.java
src/blocks/woody/java/org/apache/cocoon/woody/transformation
WidgetReplacingPipe.java
Removed: src/blocks/woody/java/org/apache/cocoon/woody/formmodel
ContainerWidget.java
Log:
Dropped ContainerWidget interface and moved getWidget method to Widget interface.
Revision Changes Path
1.2 +7 -3 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidget.java
Index: AbstractWidget.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidget.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractWidget.java 22 Apr 2003 12:04:19 -0000 1.1
+++ AbstractWidget.java 3 Jul 2003 09:03:19 -0000 1.2
@@ -55,13 +55,13 @@
* common to many widgets.
*/
public abstract class AbstractWidget implements Widget {
- private ContainerWidget parent;
+ private Widget parent;
- public ContainerWidget getParent() {
+ public Widget getParent() {
return parent;
}
- public void setParent(ContainerWidget widget) {
+ public void setParent(Widget widget) {
this.parent = widget;
}
@@ -87,5 +87,9 @@
public boolean isRequired() {
return false;
+ }
+
+ public Widget getWidget(String id) {
+ return null;
}
}
1.4 +1 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateField.java
Index: AggregateField.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AggregateField.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AggregateField.java 30 Jun 2003 14:16:02 -0000 1.3
+++ AggregateField.java 3 Jul 2003 09:03:19 -0000 1.4
@@ -83,7 +83,7 @@
* <p>Currently the child widgets should always be field widgets whose datatype is string.
*
*/
-public class AggregateField extends AbstractWidget implements ContainerWidget {
+public class AggregateField extends AbstractWidget {
private AggregateFieldDefinition definition;
private String enteredValue;
private List fields = new ArrayList();
1.3 +2 -2 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ExpressionContextImpl.java
Index: ExpressionContextImpl.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ExpressionContextImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExpressionContextImpl.java 26 Jun 2003 09:14:33 -0000 1.2
+++ ExpressionContextImpl.java 3 Jul 2003 09:03:19 -0000 1.3
@@ -71,7 +71,7 @@
* @param referenceChildren if true, variables will be resolved among the children of the given
* container widget, rather than among the siblings of the widget.
*/
- public ExpressionContextImpl(ContainerWidget widget, boolean referenceChildren) {
+ public ExpressionContextImpl(Widget widget, boolean referenceChildren) {
this.widget = widget;
this.referenceChildren = referenceChildren;
}
@@ -100,7 +100,7 @@
if (!referenceChildren)
widget = this.widget.getParent().getWidget(name);
else
- widget = ((ContainerWidget)this.widget).getWidget(name);
+ widget = this.widget.getWidget(name);
if (widget != null) {
Object value = widget.getValue();
1.5 +1 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Form.java
Index: Form.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Form.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Form.java 30 Jun 2003 13:25:28 -0000 1.4
+++ Form.java 3 Jul 2003 09:03:19 -0000 1.5
@@ -63,7 +63,7 @@
* A widget that serves as a container for other widgets, the top-level widget in
* a form description file.
*/
-public class Form extends AbstractWidget implements ContainerWidget {
+public class Form extends AbstractWidget {
private List widgets;
private Map widgetsById;
private FormDefinition definition;
1.6 +4 -4 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Repeater.java
Index: Repeater.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Repeater.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Repeater.java 26 Jun 2003 13:40:28 -0000 1.5
+++ Repeater.java 3 Jul 2003 09:03:19 -0000 1.6
@@ -69,7 +69,7 @@
* <p>Using the methods {@link #getSize} and {@link #getWidget(int, java.lang.String)}
* you can access all of the repeated widget instances.
*/
-public class Repeater extends AbstractWidget implements ContainerWidget {
+public class Repeater extends AbstractWidget {
private RepeaterDefinition definition;
private List rows = new ArrayList();
@@ -225,7 +225,7 @@
contentHandler.endElement(Constants.WI_NS, REPEATER_SIZE_EL, Constants.WI_PREFIX_COLON + REPEATER_SIZE_EL);
}
- public class RepeaterRow implements ContainerWidget {
+ public class RepeaterRow implements Widget {
private List widgets;
private Map widgetsById;
@@ -249,7 +249,7 @@
return String.valueOf(rows.indexOf(this));
}
- public ContainerWidget getParent() {
+ public Widget getParent() {
return Repeater.this;
}
@@ -261,7 +261,7 @@
return getParent().getNamespace() + "." + getId();
}
- public void setParent(ContainerWidget widget) {
+ public void setParent(Widget widget) {
throw new RuntimeException("Parent of RepeaterRow is fixed, and cannot be set.");
}
1.3 +33 -8 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Widget.java
Index: Widget.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Widget.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Widget.java 14 May 2003 11:33:38 -0000 1.2
+++ Widget.java 3 Jul 2003 09:03:19 -0000 1.3
@@ -58,15 +58,35 @@
/**
* Interface to be implemented by Widgets. In Woody, a form consists of a number
- * of widgets. Each widget can hold a (possibly strongly-typed) value, can validate
- * itself, can generate an XML representation of itself, can read its value
- * from the Request object, and so on.
+ * of widgets. Each widget:
+ *
+ * <ul>
+ * <li>has an id, unique within its parent context widget. See {@link #getId}.</li>
+ * <li>can have children (see {@link #getWidget}, and can have a parent (see {@link #getParent}.</li>
+ * <li>can hold a value (which can be any kind of object). See {@link #getValue}.</li>
+ * <li>can read its value from a request object (and convert it from a string to its native type).
+ * See {@link #readFromRequest}.</li>
+ * <li>can validate itself. See {@link #validate}.</li>
+ * <li>can generate an XML representation of itself.</li>
+ * </ul>
+ *
+ * <p>Because widgets can have children, the widgets form a widget tree, with its root
+ * being the {@link Form} widget.</p>
+ *
+ * <p>A widget can have only a value, or only child widgets, or can have both a value and child
+ * widgets, or can have neither. This all depends on the widget implementation.</p>
+ *
+ * <p>When a request is submitted, first the {@link #readFromRequest} method of all widgets
+ * will be called so that they can read their value(s). Next, the {@link #validate} method will
+ * be called. Doing this in two steps allows the validation to compare values between widgets.
+ * See also the method {@link Form#process}.</p>
*
* <p>A Widget is created by calling the createInstance method on the a
* {@link WidgetDefinition}. A Widget holds all the data that is specific for
* a certain use of the widget (its value, validationerrors, ...), while the
* WidgetDefinition holds the data that is static accross all widgets. This
- * keeps the Widgets small and light to create.
+ * keeps the Widgets small and light to create. This mechanism is similar to
+ * classes and objects in Java.
*/
public interface Widget {
/**
@@ -78,14 +98,14 @@
* Gets the parent of this widget. If this widget is the root widget,
* this method returns null.
*/
- public ContainerWidget getParent();
+ public Widget getParent();
/**
* This method is called on a widget when it is added to a container.
- * Unless you're implementing a {@link ContainerWidget}, you should not use
- * this method.
+ * You shouldn't call this method unless youre implementing a widget yourself (in
+ * which case it should be called when a widget is added as child of your widget).
*/
- public void setParent(ContainerWidget widget);
+ public void setParent(Widget widget);
/**
* Gets the namespace of this widget. The combination of a widget's namespace
@@ -139,4 +159,9 @@
* widgets this may not make sense, those should return false here.
*/
public boolean isRequired();
+
+ /**
+ * Gets the child widget of this widget with the given id, or null if there isn't such a child.
+ */
+ public Widget getWidget(String id);
}
1.2 +2 -3 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java
Index: WidgetReplacingPipe.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WidgetReplacingPipe.java 22 Apr 2003 12:04:21 -0000 1.1
+++ WidgetReplacingPipe.java 3 Jul 2003 09:03:20 -0000 1.2
@@ -51,7 +51,6 @@
package org.apache.cocoon.woody.transformation;
import org.apache.cocoon.xml.AbstractXMLPipe;
-import org.apache.cocoon.woody.formmodel.ContainerWidget;
import org.apache.cocoon.woody.formmodel.Widget;
import org.apache.cocoon.woody.formmodel.Repeater;
import org.apache.cocoon.woody.Constants;
@@ -92,7 +91,7 @@
* <p>Woody ships with an XSL that can style all the widgets that are provided by the core Woody framework.
*/
public class WidgetReplacingPipe extends AbstractXMLPipe {
- private ContainerWidget contextWidget;
+ private Widget contextWidget;
/** Indicates whether we're currently in a widget element. */
private boolean inWidgetElement;
/** Compiler used to record the XML inside wi:widget elements. */
@@ -115,7 +114,7 @@
private static final String STYLING_EL = "styling";
- public void init(ContainerWidget contextWidget) {
+ public void init(Widget contextWidget) {
this.contextWidget = contextWidget;
inWidgetElement = false;
elementNestingCounter = 0;