bruno 2004/06/01 03:51:28
Modified: src/blocks/forms/java/org/apache/cocoon/forms
FormManager.java DefaultFormManager.java
src/blocks/forms/java/org/apache/cocoon/forms/binding
BindingManager.java JXPathBindingManager.java
Log:
added methods to FormManager and BindingManager that take a URI (String) as
argument instead of a Source object.
Revision Changes Path
1.3 +23 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/FormManager.java
Index: FormManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/FormManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormManager.java 18 Mar 2004 13:56:09 -0000 1.2
+++ FormManager.java 1 Jun 2004 10:51:28 -0000 1.3
@@ -33,12 +33,24 @@
* Creates a form instance based on the XML form definition
* that can be read from the specified source.
*
+ * <p>To avoid having to resolve the Source object yourself,
+ * use the [EMAIL PROTECTED] #createForm(java.lang.String)} method.
+ *
* <p>The form definition will be cached, so that future form instances
* can be creted quickly.
*/
Form createForm(Source source) throws Exception;
/**
+ * Creates a form instance based on the XML form definition
+ * that can be retrieved from the specified URI.
+ *
+ * <p>The form definition will be cached, so that future form instances
+ * can be creted quickly.
+ */
+ Form createForm(String uri) throws Exception;
+
+ /**
* Creates a form instance based on the XML form definition that is
* supplied as a DOM tree.
*
@@ -57,4 +69,14 @@
* <p>The Form Definition will not be cached.
*/
FormDefinition createFormDefinition(Element formElement) throws
Exception;
+
+ /**
+ * Creates a form definition based on the XML form definition
+ * that can be retrieved from the specified URI.
+ *
+ * <p>The specified element must be a fd:form element.
+
+ * <p>The Form Definition will not be cached.
+ */
+ FormDefinition createFormDefinition(String uri) throws Exception;
}
1.5 +49 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/DefaultFormManager.java
Index: DefaultFormManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/DefaultFormManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultFormManager.java 18 Mar 2004 13:56:09 -0000 1.4
+++ DefaultFormManager.java 1 Jun 2004 10:51:28 -0000 1.5
@@ -34,6 +34,7 @@
import org.apache.cocoon.forms.util.DomHelper;
import org.apache.cocoon.forms.util.SimpleServiceSelector;
import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -97,6 +98,24 @@
return (Form)formDefinition.createInstance();
}
+ public Form createForm(String uri) throws Exception {
+ SourceResolver sourceResolver = null;
+ Source source = null;
+
+ try {
+ sourceResolver =
(SourceResolver)manager.lookup(SourceResolver.ROLE);
+
+ source = sourceResolver.resolveURI(uri);
+ Form form = createForm(source);
+ return form;
+ } finally {
+ if (source != null)
+ sourceResolver.release(source);
+ if (sourceResolver != null)
+ manager.release(sourceResolver);
+ }
+ }
+
public Form createForm(Element formElement) throws Exception {
return (Form)getFormDefinition(formElement).createInstance();
}
@@ -132,6 +151,35 @@
FormDefinitionBuilder formDefinitionBuilder =
(FormDefinitionBuilder)widgetDefinitionBuilderSelector.select("form");
return
(FormDefinition)formDefinitionBuilder.buildWidgetDefinition(formElement);
+ }
+
+ public FormDefinition createFormDefinition(String uri) throws Exception {
+ SourceResolver sourceResolver = null;
+ Source source = null;
+ Document formDocument = null;
+
+ try {
+ sourceResolver =
(SourceResolver)manager.lookup(SourceResolver.ROLE);
+ source = sourceResolver.resolveURI(uri);
+
+ try {
+ InputSource inputSource = new
InputSource(source.getInputStream());
+ inputSource.setSystemId(source.getURI());
+ formDocument = DomHelper.parse(inputSource);
+ }
+ catch (Exception exc) {
+ throw new CascadingException("Could not parse form
definition from " + source.getURI(), exc);
+ }
+
+ } finally {
+ if (source != null)
+ sourceResolver.release(source);
+ if (sourceResolver != null)
+ manager.release(sourceResolver);
+ }
+
+ Element formElement = formDocument.getDocumentElement();
+ return getFormDefinition(formElement);
}
/**
1.2 +7 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/BindingManager.java
Index: BindingManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/BindingManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BindingManager.java 9 Mar 2004 10:33:55 -0000 1.1
+++ BindingManager.java 1 Jun 2004 10:51:28 -0000 1.2
@@ -35,7 +35,13 @@
/**
* Creates a binding from the XML config found at source parameter.
+ * The binding will be cached.
*/
Binding createBinding(Source bindingFile) throws BindingException;
+ /**
+ * Creates a binding from the XML config found at bindingURI parameter.
+ * The binding will be cached.
+ */
+ Binding createBinding(String bindingURI) throws BindingException;
}
1.3 +22 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java
Index: JXPathBindingManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JXPathBindingManager.java 11 Mar 2004 02:56:32 -0000 1.2
+++ JXPathBindingManager.java 1 Jun 2004 10:51:28 -0000 1.3
@@ -30,6 +30,7 @@
import org.apache.cocoon.forms.util.DomHelper;
import org.apache.cocoon.forms.util.SimpleServiceSelector;
import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -110,6 +111,26 @@
}
}
return binding;
+ }
+
+ public Binding createBinding(String bindingURI) throws BindingException {
+ SourceResolver sourceResolver = null;
+ Source source = null;
+
+ try {
+ try {
+ sourceResolver =
(SourceResolver)serviceManager.lookup(SourceResolver.ROLE);
+ source = sourceResolver.resolveURI(bindingURI);
+ } catch (Exception e) {
+ throw new BindingException("Error resolving binding source:
" + bindingURI);
+ }
+ return createBinding(source);
+ } finally {
+ if (source != null)
+ sourceResolver.release(source);
+ if (sourceResolver != null)
+ serviceManager.release(sourceResolver);
+ }
}
private Assistant getBuilderAssistant() {