cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms FormManager.java DefaultFormManager.java
Date Thu, 18 Mar 2004 13:56:09 GMT
bruno       2004/03/18 05:56:09

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms
                        FormManager.java DefaultFormManager.java
  Log:
  Added methods to create a form instance or definition based on a DOM tree
  instead of a Source.
  
  Revision  Changes    Path
  1.2       +30 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormManager.java	9 Mar 2004 10:34:12 -0000	1.1
  +++ FormManager.java	18 Mar 2004 13:56:09 -0000	1.2
  @@ -16,7 +16,9 @@
   package org.apache.cocoon.forms;
   
   import org.apache.cocoon.forms.formmodel.Form;
  +import org.apache.cocoon.forms.formmodel.FormDefinition;
   import org.apache.excalibur.source.Source;
  +import org.w3c.dom.Element;
   
   /**
    * Work interface for the component that can create {@link Form}s.
  @@ -27,5 +29,32 @@
       
       String ROLE = FormManager.class.getName();
   
  +    /**
  +     * Creates a form instance based on the XML form definition
  +     * that can be read from the specified source.
  +     *
  +     * <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 is
  +     * supplied as a DOM tree.
  +     *
  +     * <p>The specified element must be a fd:form element.
  +     *
  +     * <p>The Form Definition will not be cached.
  +     */
  +    Form createForm(Element formElement) throws Exception;
  +
  +    /**
  +     * Creates a form definition based on the XML form definition that is
  +     * supplied as a DOM tree.
  +     *
  +     * <p>The specified element must be a fd:form element.
  +
  +     * <p>The Form Definition will not be cached.
  +     */
  +    FormDefinition createFormDefinition(Element formElement) throws Exception;
   }
  
  
  
  1.4       +19 -8     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultFormManager.java	11 Mar 2004 02:56:33 -0000	1.3
  +++ DefaultFormManager.java	18 Mar 2004 13:56:09 -0000	1.4
  @@ -97,6 +97,14 @@
           return (Form)formDefinition.createInstance();
       }
   
  +    public Form createForm(Element formElement) throws Exception {
  +        return (Form)getFormDefinition(formElement).createInstance();
  +    }
  +
  +    public FormDefinition createFormDefinition(Element formElement) throws Exception {
  +        return getFormDefinition(formElement);
  +    }
  +
       public FormDefinition getFormDefinition(Source source) throws Exception {
           FormDefinition formDefinition = (FormDefinition)this.cacheManager.get(source, PREFIX);
           if (formDefinition == null) {
  @@ -111,16 +119,19 @@
               }
   
               Element formElement = formDocument.getDocumentElement();
  -
  -            // check that the root element is a fd:form element
  -            if (!(formElement.getLocalName().equals("form") || Constants.DEFINITION_NS.equals(formElement.getNamespaceURI())))
  -                throw new Exception("Expected a Cocoon Forms form element at " + DomHelper.getLocation(formElement));
  -
  -            FormDefinitionBuilder formDefinitionBuilder = (FormDefinitionBuilder)widgetDefinitionBuilderSelector.select("form");
  -            formDefinition = (FormDefinition)formDefinitionBuilder.buildWidgetDefinition(formElement);
  +            formDefinition = getFormDefinition(formElement);
               this.cacheManager.set(formDefinition, source, PREFIX);
           }
           return formDefinition;
  +    }
  +
  +    public FormDefinition getFormDefinition(Element formElement) throws Exception {
  +        // check that the root element is a fd:form element
  +        if (!(formElement.getLocalName().equals("form") || Constants.DEFINITION_NS.equals(formElement.getNamespaceURI())))
  +            throw new Exception("Expected a Cocoon Forms form element at " + DomHelper.getLocation(formElement));
  +
  +        FormDefinitionBuilder formDefinitionBuilder = (FormDefinitionBuilder)widgetDefinitionBuilderSelector.select("form");
  +        return (FormDefinition)formDefinitionBuilder.buildWidgetDefinition(formElement);
       }
   
       /**
  
  
  

Mime
View raw message