Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 4911 invoked from network); 17 Nov 2004 17:41:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 Nov 2004 17:41:32 -0000 Received: (qmail 11989 invoked by uid 500); 17 Nov 2004 17:41:28 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 11914 invoked by uid 500); 17 Nov 2004 17:41:27 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 11903 invoked by uid 99); 17 Nov 2004 17:41:27 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 17 Nov 2004 09:41:26 -0800 Received: (qmail 4778 invoked by uid 65534); 17 Nov 2004 17:41:25 -0000 Date: 17 Nov 2004 17:41:25 -0000 Message-ID: <20041117174125.4770.qmail@minotaur.apache.org> From: tim@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 76152 - in cocoon/trunk/src/blocks/forms: conf java/org/apache/cocoon/forms/binding java/org/apache/cocoon/forms/formmodel java/org/apache/cocoon/forms/generation java/org/apache/cocoon/forms/transformation X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 :) (In :) 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 @@ + 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 @@ + 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 {@link Binding} + * that narrows the context towards provided childbindings. + *

+ * NOTES:

    + *
  1. This Binding assumes that the provided widget-id points to a widget + * that contains other widgets.
  2. + *
+ * + * @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 {@link JXPathBindingManager} that helps construct the + * actual {@link GroupJXPathBinding} out of the configuration in the + * provided configElement which looks like: + *

+ * <fb:group id="widget-id" path="xpath-expression"
+ *     direction="load|save" lenient="true|false" >
+ *   <fb:field id="sub-widget-id" path="relative-xpath" />
+ * </fb:group>
+ * 
+ * + * @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 {@link 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 {@link WidgetDefinition} corresponding to a {@link 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 @@ + + + + + + + + + + + + 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;