Author: tim
Date: Wed Nov 17 09:41:23 2004
New Revision: 76152
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBindingBuilder.java
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinition.java
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java
Modified:
cocoon/trunk/src/blocks/forms/conf/forms-binding.xconf
cocoon/trunk/src/blocks/forms/conf/forms-form.xconf
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Log:
CForms: Rename "struct"->"group" in model, binding, template,
and jx-macros, following the stabilization plan for CForms.
For deprecation, the support for "struct" is left in place
for now, but can be removed easily when we decide to do so.
Note: Unless you "build clean" first, you must manually
update cocoon.xconf to add these two configuration lines:
(In <forms-binding logger="forms.binding"><bindings>:)
<binding name="group"
src="org.apache.cocoon.forms.binding.GroupJXPathBindingBuilder"/>
(In <forms-formmanager><widgets>:)
<widget name="group"
src="org.apache.cocoon.forms.formmodel.GroupDefinitionBuilder"/>
Modified: cocoon/trunk/src/blocks/forms/conf/forms-binding.xconf
==============================================================================
--- cocoon/trunk/src/blocks/forms/conf/forms-binding.xconf (original)
+++ cocoon/trunk/src/blocks/forms/conf/forms-binding.xconf Wed Nov 17
09:41:23 2004
@@ -19,6 +19,7 @@
<forms-binding logger="forms.binding">
<bindings>
+ <binding name="group"
src="org.apache.cocoon.forms.binding.GroupJXPathBindingBuilder"/>
<binding name="value"
src="org.apache.cocoon.forms.binding.ValueJXPathBindingBuilder"/>
<binding name="multi-value"
src="org.apache.cocoon.forms.binding.MultiValueJXPathBindingBuilder"/>
<binding name="context"
src="org.apache.cocoon.forms.binding.ContextJXPathBindingBuilder"/>
Modified: cocoon/trunk/src/blocks/forms/conf/forms-form.xconf
==============================================================================
--- cocoon/trunk/src/blocks/forms/conf/forms-form.xconf (original)
+++ cocoon/trunk/src/blocks/forms/conf/forms-form.xconf Wed Nov 17 09:41:23 2004
@@ -24,6 +24,7 @@
<widgets>
<widget name="form"
src="org.apache.cocoon.forms.formmodel.FormDefinitionBuilder"/>
<widget name="field"
src="org.apache.cocoon.forms.formmodel.FieldDefinitionBuilder"/>
+ <widget name="group"
src="org.apache.cocoon.forms.formmodel.GroupDefinitionBuilder"/>
<widget name="repeater"
src="org.apache.cocoon.forms.formmodel.RepeaterDefinitionBuilder"/>
<widget name="booleanfield"
src="org.apache.cocoon.forms.formmodel.BooleanFieldDefinitionBuilder"/>
<widget name="multivaluefield"
src="org.apache.cocoon.forms.formmodel.MultiValueFieldDefinitionBuilder"/>
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java
==============================================================================
--- (empty file)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBinding.java
Wed Nov 17 09:41:23 2004
@@ -0,0 +1,82 @@
+/*
+ * 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.binding;
+
+import org.apache.cocoon.forms.formmodel.Group;
+import org.apache.cocoon.forms.formmodel.Widget;
+import org.apache.commons.jxpath.JXPathContext;
+
+/**
+ * GroupJXPathBinding provides an implementation of a [EMAIL PROTECTED]
Binding}
+ * that narrows the context towards provided childbindings.
+ * <p>
+ * NOTES: <ol>
+ * <li>This Binding assumes that the provided widget-id points to a widget
+ * that contains other widgets.</li>
+ * </ol>
+ *
+ * @version CVS $Id: GroupJXPathBinding.java 56582 2004-11-04 10:16:22Z
sylvain $
+ */
+public class GroupJXPathBinding extends ComposedJXPathBindingBase {
+
+ private final String xpath;
+
+ private final String widgetId;
+
+ /**
+ * Constructs GroupJXPathBinding
+ * @param widgetId
+ * @param xpath
+ * @param childBindings
+ */
+ public GroupJXPathBinding(JXPathBindingBuilderBase.CommonAttributes
commonAtts, String widgetId, String xpath, JXPathBindingBase[] childBindings) {
+ super(commonAtts, childBindings);
+ this.widgetId = widgetId;
+ this.xpath = xpath;
+ }
+
+ /**
+ * Narrows the scope on the form-model to the member widget-field, and
+ * narrows the scope on the object-model to the member xpath-context
+ * before continuing the binding over the child-bindings.
+ */
+ public void doLoad(Widget frmModel, JXPathContext jxpc) throws
BindingException {
+ Group groupWidget = (Group)selectWidget(frmModel, this.widgetId);
+ JXPathContext subContext =
jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+ super.doLoad(groupWidget, subContext);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("done loading " + toString());
+ }
+ }
+
+ /**
+ * Narrows the scope on the form-model to the member widget-field, and
+ * narrows the scope on the object-model to the member xpath-context
+ * before continuing the binding over the child-bindings.
+ */
+ public void doSave(Widget frmModel, JXPathContext jxpc) throws
BindingException {
+ Group groupWidget = (Group)selectWidget(frmModel, this.widgetId);
+ JXPathContext subContext =
jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
+ super.doSave(groupWidget, subContext);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("done saving " + toString());
+ }
+ }
+
+ public String toString() {
+ return "GroupJXPathBinding [widget=" + this.widgetId + ", xpath=" +
this.xpath + "]";
+ }
+}
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBindingBuilder.java
==============================================================================
--- (empty file)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/binding/GroupJXPathBindingBuilder.java
Wed Nov 17 09:41:23 2004
@@ -0,0 +1,56 @@
+/*
+ * 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.binding;
+
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+/**
+ * GroupJXPathBindingBuilder provides a helper class for the Factory
+ * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps construct
the
+ * actual [EMAIL PROTECTED] GroupJXPathBinding} out of the configuration in the
+ * provided configElement which looks like:
+ * <pre><code>
+ * <fb:group id="<i>widget-id</i>" path="<i>xpath-expression</i>"
+ * direction="<i>load|save</i>" lenient="<i>true|false</i>" >
+ * <fb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
+ * </fb:group>
+ * </code></pre>
+ *
+ * @version CVS $Id: GroupJXPathBindingBuilder.java 56582 2004-11-04 10:16:22Z
sylvain $
+ */
+public class GroupJXPathBindingBuilder
+ extends JXPathBindingBuilderBase {
+
+ public JXPathBindingBase buildBinding(Element bindingElm,
JXPathBindingManager.Assistant assistant)
+ throws BindingException {
+ try {
+ String widgetId = DomHelper.getAttribute(bindingElm, "id");
+ CommonAttributes commonAtts =
JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
+ String xpath = DomHelper.getAttribute(bindingElm, "path");
+
+ JXPathBindingBase[] childBindings =
assistant.makeChildBindings(bindingElm);
+
+ GroupJXPathBinding groupBinding =
+ new GroupJXPathBinding(commonAtts, widgetId, xpath,
childBindings);
+ return groupBinding;
+ } catch (BindingException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new BindingException("Error building group binding defined
at " + DomHelper.getLocation(bindingElm), e);
+ }
+ }
+}
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java
==============================================================================
--- (empty file)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Group.java
Wed Nov 17 09:41:23 2004
@@ -0,0 +1,45 @@
+/*
+ * 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.formmodel;
+
+
+/**
+ * A container [EMAIL PROTECTED] Widget} which can hold zero or more child
widgets.
+ *
+ * @version $Id: Group.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class Group extends AbstractContainerWidget {
+ private static final String GROUP_EL = "group";
+
+ private final GroupDefinition definition;
+
+ public Group(GroupDefinition definition) {
+ super(definition);
+ this.definition = definition;
+ }
+
+ protected WidgetDefinition getDefinition() {
+ return this.definition;
+ }
+
+ /**
+ * @return "group"
+ */
+ public String getXMLElementName() {
+ return GROUP_EL;
+ }
+
+}
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinition.java
==============================================================================
--- (empty file)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinition.java
Wed Nov 17 09:41:23 2004
@@ -0,0 +1,30 @@
+/*
+ * 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.formmodel;
+
+/**
+ * The [EMAIL PROTECTED] WidgetDefinition} corresponding to a [EMAIL
PROTECTED] Group} widget.
+ *
+ * @version $Id: GroupDefinition.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class GroupDefinition extends AbstractContainerDefinition {
+
+ public Widget createInstance() {
+ Group groupWidget = new Group(this);
+ createWidgets(groupWidget);
+ return groupWidget;
+ }
+}
Added:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java
==============================================================================
--- (empty file)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/GroupDefinitionBuilder.java
Wed Nov 17 09:41:23 2004
@@ -0,0 +1,46 @@
+/*
+ * 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.formmodel;
+
+import org.w3c.dom.Element;
+import org.apache.cocoon.forms.Constants;
+import org.apache.cocoon.forms.util.DomHelper;
+
+/**
+ * Builds {GroupDefinition}s.
+ *
+ * @version $Id: GroupDefinitionBuilder.java 47104 2004-09-23 14:16:39Z
sylvain $
+ */
+public class GroupDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
+
+ public WidgetDefinition buildWidgetDefinition(Element element) throws
Exception {
+ GroupDefinition definition = new GroupDefinition();
+ setCommonProperties(element, definition);
+ setDisplayData(element, definition);
+ setValidators(element, definition);
+
+ Element widgetsElement = DomHelper.getChildElement(element,
Constants.DEFINITION_NS, "widgets", true);
+ // All child elements of the widgets element are widgets
+ Element[] widgetElements = DomHelper.getChildElements(widgetsElement,
Constants.DEFINITION_NS);
+ for (int i = 0; i < widgetElements.length; i++) {
+ Element widgetElement = widgetElements[i];
+ WidgetDefinition widgetDefinition =
buildAnotherWidgetDefinition(widgetElement);
+ definition.addWidgetDefinition(widgetDefinition);
+ }
+
+ return definition;
+ }
+}
Modified:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
==============================================================================
---
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
(original)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
Wed Nov 17 09:41:23 2004
@@ -93,6 +93,20 @@
</jx:macro>
<!--
+ ft:group : just increase the nesting level
+ -->
+ <jx:macro name="group"
targetNamespace="http://apache.org/cocoon/forms/1.0#template">
+ <jx:parameter name="id"/>
+
+ <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/>
+ <jx:if test="${cformsHelper.isVisible(widget)}">
+ <fi:group id="${widget.getRequestParameterName()}">
+ <jx:evalBody/>
+ </fi:group>
+ </jx:if>
+ </jx:macro>
+
+ <!--
ft:new
-->
<jx:macro name="new"
targetNamespace="http://apache.org/cocoon/forms/1.0#template">
Modified:
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
==============================================================================
---
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
(original)
+++
cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Wed Nov 17 09:41:23 2004
@@ -20,6 +20,7 @@
import org.apache.cocoon.forms.formmodel.AggregateField;
import org.apache.cocoon.forms.formmodel.ContainerWidget;
import org.apache.cocoon.forms.formmodel.DataWidget;
+import org.apache.cocoon.forms.formmodel.Group;
import org.apache.cocoon.forms.formmodel.Repeater;
import org.apache.cocoon.forms.formmodel.Struct;
import org.apache.cocoon.forms.formmodel.Union;
@@ -76,6 +77,7 @@
private static final String CLASS = "class";
private static final String CONTINUATION_ID = "continuation-id";
private static final String FORM_TEMPLATE_EL = "form-template";
+ private static final String GROUP = "group";
private static final String NEW = "new";
private static final String REPEATER_SIZE = "repeater-size";
private static final String REPEATER_WIDGET = "repeater-widget";
@@ -101,6 +103,7 @@
private final ContinuationIdHandler continuationIdHandler = new
ContinuationIdHandler();
private final DocHandler docHandler = new
DocHandler();
private final FormHandler formHandler = new
FormHandler();
+ private final GroupHandler groupHandler = new
GroupHandler();
private final NestedHandler nestedHandler = new
NestedHandler();
private final NewHandler newHandler = new
NewHandler();
private final RepeaterSizeHandler repeaterSizeHandler = new
RepeaterSizeHandler();
@@ -139,6 +142,7 @@
templates.put(CHOOSE, chooseHandler);
templates.put(CLASS, classHandler);
templates.put(CONTINUATION_ID, continuationIdHandler);
+ templates.put(GROUP, groupHandler);
templates.put(NEW, newHandler);
templates.put(REPEATER_SIZE, repeaterSizeHandler);
templates.put(REPEATER_WIDGET, repeaterWidgetHandler);
@@ -535,6 +539,34 @@
throwWrongWidgetType("AggregateWidgetHandler", input.loc,
"aggregate");
}
+ if (isVisible(widget)) {
+ contextWidgets.addFirst(contextWidget);
+ contextWidget = widget;
+ return this;
+ } else {
+ return nullHandler;
+ }
+ case EVENT_ELEMENT:
+ return nestedTemplate();
+ case EVENT_END_ELEMENT:
+ contextWidget = (Widget)contextWidgets.removeFirst();
+ return this;
+ default:
+ out.copy();
+ return this;
+ }
+ }
+ }
+
+ protected class GroupHandler extends Handler {
+ public Handler process() throws SAXException {
+ switch(event) {
+ case EVENT_START_ELEMENT:
+ widgetPath = getWidgetId(input.attrs);
+ widget = getWidget(widgetPath);
+ if (!(widget instanceof Group)) {
+ throwWrongWidgetType("GroupHandler", input.loc, "group");
+ }
if (isVisible(widget)) {
contextWidgets.addFirst(contextWidget);
contextWidget = widget;