You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2006/10/02 12:33:13 UTC
svn commit: r451957 - in /cocoon: branches/BRANCH_2_1_X/
trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/
trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/
Author: vgritsenko
Date: Mon Oct 2 03:33:13 2006
New Revision: 451957
URL: http://svn.apache.org/viewvc?view=rev&rev=451957
Log:
<action dev="VG" type="fix" fixes-bug="COCOON-1906" due-to="Lars Trieloff" due-to-email="lars@trieloff.net">
CForms: Apply patch to disambiguate toSAX method call.
</action>
Modified:
cocoon/branches/BRANCH_2_1_X/status.xml
cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/XMLAdapter.java
cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/Form.js
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=451957&r1=451956&r2=451957
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Oct 2 03:33:13 2006
@@ -184,6 +184,9 @@
<release version="@version@" date="@date@">
-->
<release version="2.1.10" date="TBD">
+ <action dev="VG" type="fix" fixes-bug="COCOON-1906" due-to="Lars Trieloff" due-to-email="lars@trieloff.net">
+ CForms: Apply patch to disambiguate toSAX method call.
+ </action>
<action dev="VG" type="update">
Core: Move BackgroundEnvironment from Cron block into the Core.
</action>
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/XMLAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/XMLAdapter.java?view=diff&rev=451957&r1=451956&r2=451957
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/XMLAdapter.java (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/XMLAdapter.java Mon Oct 2 03:33:13 2006
@@ -5,9 +5,9 @@
* The ASF licenses this file to You 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.
@@ -41,8 +41,8 @@
* Adapter class that wraps a <code>Form</code> object and makes it
* possible to populate a widget hierarchy from XML in form of SAX
* events and serialize the content of the widget hierarchy as XML.
- *
- * The XML format is such that there is one XML element for each
+ *
+ * <p>The XML format is such that there is one XML element for each
* widget and the element get the widgets id as name. Exceptions from
* this is that the elements in a repeater gets the name
* <code>item</code> and a attribute <code>position</code> with the
@@ -50,12 +50,12 @@
* not allowed as element name). Childs of a
* <code>MultiValueField</code> are also embeded within a
* <code>item</code> element. If the <code>Form</code> widget does
- * not have an id it get the name <code>uknown</code>.
+ * not have an id it get the name <code>uknown</code>.</p>
*
- * An <code>AggregateField</code> can both be interpreted as one value
+ * <p>An <code>AggregateField</code> can both be interpreted as one value
* and as several widgets. This ambiguity is resolved by chosing to emit
* the single value rather than the fields as XML. For population of the
- * form both forms are however allowed.
+ * form both forms are however allowed.</p>
*
* @version $Id$
*/
@@ -71,23 +71,23 @@
private final static String PREFIX = "";
/** The namespace URI of this component. */
private final static String URI = "";
+
/** The <code>ContentHandler</code> receiving SAX events. */
private ContentHandler contentHandler;
/** The <code>Widget</code> to read and write XML to. */
private Widget widget;
/** The <code>Widget</code> that we are currently writing to. */
- private Widget currentWidget = null;
+ private Widget currentWidget;
/** The <code>Locale</code> that decides how to convert widget values to strings */
private Locale locale;
/** Is a <code>MultiValueField</code> handled? */
- private boolean isMultiValueItem = false;
+ private boolean isMultiValueItem;
/** The buffer used to receive character events */
private StringBuffer textBuffer;
/**
* Wrap a <code>Form</code> with an <code>XMLAdapter</code>
- *
*/
public XMLAdapter(Widget widget) {
this.widget = widget;
@@ -137,35 +137,38 @@
public void startElement(String uri, String loc, String raw, Attributes a)
throws SAXException {
handleText();
+
if (this.currentWidget == null) {
// The name of the root element is ignored
this.currentWidget = this.widget;
- return;
+
} else if (this.currentWidget instanceof ContainerWidget) {
Widget child = ((ContainerWidget)this.currentWidget).getChild(loc);
- if (child != null)
- this.currentWidget = child;
- else
+ if (child == null) {
throw new SAXException("There is no widget with id: " + loc +
" as child to: " + this.currentWidget.getId());
+ }
+ this.currentWidget = child;
+
} else if (this.currentWidget instanceof Repeater) {
// In a repeater the XML elements are added in the order
// they are recieved, the position attribute is not used
- if (ITEM.equals(loc)) {
- Repeater repeater = (Repeater)currentWidget;
- currentWidget = repeater.addRow();
- } else
+ if (!ITEM.equals(loc)) {
throw new SAXException("The element: " + loc +
" is not allowed as a direct child of a Repeater");
+ }
+ Repeater repeater = (Repeater) currentWidget;
+ this.currentWidget = repeater.addRow();
+
} else if (this.currentWidget instanceof MultiValueField) {
this.isMultiValueItem = true;
- if (!ITEM.equals(loc))
+ if (!ITEM.equals(loc)) {
throw new SAXException("The element: " + loc +
" is not allowed as a direct child of a MultiValueField");
+ }
}
}
-
/**
* Receive notification of the end of an element.
*
@@ -216,51 +219,50 @@
// Buffer text, as a single text node can be sent in several chunks.
if (this.textBuffer == null) {
this.textBuffer = new StringBuffer();
- }
+ }
this.textBuffer.append(ch, start, len);
}
-
+
/**
* Handle text nodes, if any. Called on every potential text node boundary,
* i.e. start and end element events.
- *
+ *
* @throws SAXException
*/
private void handleText() throws SAXException {
if (this.textBuffer == null)
return;
-
+
String input = this.textBuffer.toString().trim();
this.textBuffer = null; // clear buffer
if (input.length() == 0)
return;
if (this.currentWidget instanceof MultiValueField && isMultiValueItem) {
- MultiValueField field = (MultiValueField)this.currentWidget;
+ MultiValueField field = (MultiValueField) this.currentWidget;
Datatype type = field.getDatatype();
- ConversionResult conv =
- type.convertFromString(input, this.locale);
- if (conv.isSuccessful()) {
- Object[] values = (Object[])field.getValue();
- int valLen = values == null ? 0 : values.length;
- Object[] newValues = new Object[valLen + 1];
- for (int i = 0; i < valLen; i++)
- newValues[i] = values[i];
- newValues[valLen] = conv.getResult();
- field.setValues(newValues);
- } else
+ ConversionResult conv = type.convertFromString(input, this.locale);
+ if (!conv.isSuccessful()) {
throw new SAXException("Could not convert: " + input +
" to " + type.getTypeClass());
+ }
+ Object[] values = (Object[]) field.getValue();
+ int valLen = values == null ? 0 : values.length;
+ Object[] newValues = new Object[valLen + 1];
+ for (int i = 0; i < valLen; i++) {
+ newValues[i] = values[i];
+ }
+ newValues[valLen] = conv.getResult();
+ field.setValues(newValues);
} else if (this.currentWidget instanceof DataWidget) {
- DataWidget data = (DataWidget)this.currentWidget;
+ DataWidget data = (DataWidget) this.currentWidget;
Datatype type = data.getDatatype();
- ConversionResult conv =
- type.convertFromString(input, this.locale);
- if (conv.isSuccessful()) {
- data.setValue(conv.getResult());
- } else
+ ConversionResult conv = type.convertFromString(input, this.locale);
+ if (!conv.isSuccessful()) {
throw new SAXException("Could not convert: " + input +
" to " + type.getTypeClass());
+ }
+ data.setValue(conv.getResult());
} else if (this.currentWidget instanceof BooleanField) {
// FIXME: BooleanField should implement DataWidget, which
// would make this case unnecessary
@@ -274,7 +276,6 @@
throw new SAXException("Unknown widget type: " + this.currentWidget);
}
}
-
/* ================ Widget -> SAX ================ */
Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/Form.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/Form.js?view=diff&rev=451957&r1=451956&r2=451957
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/Form.js (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/flow/javascript/Form.js Mon Oct 2 03:33:13 2006
@@ -58,9 +58,8 @@
return this.formWidget;
}
-
/**
- * Get the actual Form-Widget (the Java object)
+ * Get the actual form widget (the Java object)
*/
Form.prototype.getWidget = function(name) {
if (name != undefined) {
@@ -160,11 +159,11 @@
var formContext = new Packages.org.apache.cocoon.forms.FormContext(cocoon.request, this.locale);
- // Prematurely add the viewdata as in the object model so that event listeners can use it
- // (the same is done by cocoon.sendPage())
- // FIXME : hack needed because FOM doesn't provide access to the object model
- var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
- org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, viewdata);
+ // Prematurely add the viewdata as in the object model so that event listeners can use it
+ // (the same is done by cocoon.sendPage())
+ // FIXME : hack needed because FOM doesn't provide access to the object model
+ var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
+ org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, viewdata);
finished = this.form.process(formContext);
@@ -178,7 +177,7 @@
// Ask the client to issue a new request reloading the whole page.
// As we have nothing special to send back, so a header should be just what we need...
// e.g. cocoon.response.setHeader("X-Cocoon-Ajax", "continue");
- // cocoon.sendStatus(200);
+ // cocoon.sendStatus(200);
// ...but Safari doesn't consider empty responses (with content-length = 0) as
// valid ones. So send a continue response by using directly the HttpResponse's
// output stream. Avoiding this hack would require to put an additional pipeline
@@ -244,16 +243,18 @@
}
Form.prototype.load = function(object) {
- if (this.binding == null)
+ if (this.binding == null) {
throw new Error("Binding not configured for this form.");
+ }
this.form.informStartLoadingModel();
this.binding.loadFormFromModel(this.form, object);
this.form.informEndLoadingModel();
}
Form.prototype.save = function(object) {
- if (this.binding == null)
+ if (this.binding == null) {
throw new Error("Binding not configured for this form.");
+ }
this.form.informStartSavingModel();
this.binding.saveFormToModel(this.form, object);
this.form.informEndSavingModel();
@@ -285,11 +286,12 @@
try {
resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
- Packages.org.apache.cocoon.components.source.SourceUtil.toSAX(source, this.getXML());
+ // Disambiguate toSAX method: Pick the one with Sosurce argument.
+ Packages.org.apache.cocoon.components.source.SourceUtil["toSAX(org.apache.excalibur.source.Source,org.xml.sax.ContentHandler)"](source, this.getXML())
} finally {
- if (source != null)
+ if (source != null) {
resolver.release(source);
-
+ }
cocoon.releaseComponent(resolver);
}
}
@@ -319,9 +321,9 @@
}
} finally {
- if (source != null)
+ if (source != null) {
resolver.release(source);
-
+ }
cocoon.releaseComponent(resolver);
if (outputStream != null) {
@@ -375,11 +377,11 @@
var formContext = new Packages.org.apache.cocoon.forms.FormContext(cocoon.request, this.locale);
- // Prematurely add the viewdata as in the object model so that event listeners can use it
- // (the same is done by cocoon.sendPage())
- // FIXME : hack needed because FOM doesn't provide access to the object model
- var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
- org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, viewdata);
+ // Prematurely add the viewdata as in the object model so that event listeners can use it
+ // (the same is done by cocoon.sendPage())
+ // FIXME : hack needed because FOM doesn't provide access to the object model
+ var objectModel = org.apache.cocoon.components.ContextHelper.getObjectModel(this.avalonContext);
+ org.apache.cocoon.components.flow.FlowHelper.setContextObject(objectModel, viewdata);
if (this.restoreHook) {
this.restoreHook(this);