org.alfresco.web.forms.xforms
Class Schema2XForms

java.lang.Object
  extended by org.alfresco.web.forms.xforms.Schema2XForms
All Implemented Interfaces:
java.io.Serializable

public class Schema2XForms
extends java.lang.Object
implements java.io.Serializable

An abstract implementation of the Schema2XForms interface allowing an XForm to be automatically generated for an XML Schema definition. This abstract class implements the buildForm and buildFormAsString methods and associated helper but relies on concrete subclasses to implement other required interface methods (createXXX, startXXX, and endXXX methods).

See Also:
Serialized Form

Nested Class Summary
static class Schema2XForms.SubmitMethod
           
 
Constructor Summary
Schema2XForms(java.lang.String action, Schema2XForms.SubmitMethod submitMethod, java.lang.String base, boolean formatCaption)
          Creates a new Schema2XForms object.
 
Method Summary
protected  void addChoicesForSelectControl(org.w3c.dom.Document xForm, org.w3c.dom.Element choicesElement, java.util.Map choiceValues, java.util.ResourceBundle resourceBundle)
          _UNDOCUMENTED_
protected  java.util.Map addChoicesForSelectSwitchControl(org.w3c.dom.Document xformsDocument, org.w3c.dom.Element formSection, java.util.List choiceValues, java.lang.String typeBindId)
           
 org.alfresco.util.Pair buildXForm(org.w3c.dom.Document instanceDocument, org.w3c.dom.Document schemaDocument, java.lang.String rootElementName, java.util.ResourceBundle resourceBundle)
          Generate the XForm based on a user supplied XML Schema.
 java.lang.String createCaption(java.lang.String text)
          Creates a caption for the provided text extracted from the XML Schema.
 java.lang.String createCaption(java.lang.String text, org.apache.xerces.xs.XSAnnotation annotation, java.util.ResourceBundle resourceBundle)
           
 java.lang.String createCaption(java.lang.String text, org.apache.xerces.xs.XSObject o, java.util.ResourceBundle resourceBundle)
           
 java.lang.String createCaption(org.apache.xerces.xs.XSAttributeDeclaration attribute, java.util.ResourceBundle resourceBundle)
          Creates a caption for the provided XML Schema attribute.
 java.lang.String createCaption(org.apache.xerces.xs.XSAttributeUse attribute, java.util.ResourceBundle resourceBundle)
           
 java.lang.String createCaption(org.apache.xerces.xs.XSElementDeclaration element, java.util.ResourceBundle resourceBundle)
          Creates a caption for the provided XML Schema element.
 java.lang.String createCaption(org.apache.xerces.xs.XSObject element, java.util.ResourceBundle resourceBundle)
           
 org.w3c.dom.Element createControlForAnyType(org.w3c.dom.Document xformsDocument, java.lang.String caption, org.apache.xerces.xs.XSTypeDefinition controlType)
          Creates a form control for an XML Schema any type.
 org.w3c.dom.Element createControlForAtomicType(org.w3c.dom.Document xformsDocument, org.apache.xerces.xs.XSSimpleTypeDefinition controlType, org.apache.xerces.xs.XSObject owner, java.lang.String caption, java.util.ResourceBundle resourceBundle)
          Creates a form control for an XML Schema simple atomic type.
 org.w3c.dom.Element createControlForEnumerationType(org.w3c.dom.Document xformsDocument, org.apache.xerces.xs.XSSimpleTypeDefinition controlType, org.apache.xerces.xs.XSObject owner, java.lang.String caption, org.w3c.dom.Element bindElement, java.util.ResourceBundle resourceBundle)
          Creates a form control for an XML Schema simple type restricted by an enumeration.
 org.w3c.dom.Element createControlForListType(org.w3c.dom.Document xformsDocument, org.apache.xerces.xs.XSSimpleTypeDefinition listType, org.apache.xerces.xs.XSObject owner, java.lang.String caption, org.w3c.dom.Element bindElement, java.util.ResourceBundle resourceBundle)
          Creates a form control for an XML Schema simple list type.
protected  java.lang.String getXFormsTypeName(org.w3c.dom.Document xformsDocument, org.apache.xerces.xs.XSModel schema, org.apache.xerces.xs.XSTypeDefinition controlType)
          used to get the type name that will be used in the XForms document
static void rebuildInstance(org.w3c.dom.Node prototypeNode, org.w3c.dom.Node oldInstanceNode, org.w3c.dom.Node newInstanceNode, java.util.HashMap schemaNamespaces)
           
static void removePrototypeNodes(org.w3c.dom.Node instanceDocumentElement)
           
 void reset()
          Reset the Schema2XForms to default values.
protected  java.lang.String setXFormsId(org.w3c.dom.Element el)
           
protected  java.lang.String setXFormsId(org.w3c.dom.Element el, java.lang.String id)
           
 org.w3c.dom.Element startBindElement(org.w3c.dom.Element bindElement, org.apache.xerces.xs.XSModel schema, org.apache.xerces.xs.XSTypeDefinition controlType, org.apache.xerces.xs.XSObject owner, SchemaUtil.Occurrence o)
          This method is invoked after an xforms:bind element is created for the specified SimpleType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Schema2XForms

public Schema2XForms(java.lang.String action,
                     Schema2XForms.SubmitMethod submitMethod,
                     java.lang.String base,
                     boolean formatCaption)
Creates a new Schema2XForms object.

Parameters:
action - _UNDOCUMENTED_
submitMethod - _UNDOCUMENTED_
formatCaption -
Method Detail

buildXForm

public org.alfresco.util.Pair buildXForm(org.w3c.dom.Document instanceDocument,
                                         org.w3c.dom.Document schemaDocument,
                                         java.lang.String rootElementName,
                                         java.util.ResourceBundle resourceBundle)
                                  throws FormBuilderException
Generate the XForm based on a user supplied XML Schema.

Parameters:
instanceDocument - The document source for the XML Schema.
schemaDocument - Schema document
rootElementName - Name of the root element
resourceBundle - Strings to use
Returns:
The Document containing the XForm.
Throws:
org.chiba.tools.schemabuilder.FormBuilderException - If an error occurs building the XForm.
FormBuilderException

reset

public void reset()
Reset the Schema2XForms to default values.


rebuildInstance

public static void rebuildInstance(org.w3c.dom.Node prototypeNode,
                                   org.w3c.dom.Node oldInstanceNode,
                                   org.w3c.dom.Node newInstanceNode,
                                   java.util.HashMap schemaNamespaces)

removePrototypeNodes

public static void removePrototypeNodes(org.w3c.dom.Node instanceDocumentElement)

setXFormsId

protected java.lang.String setXFormsId(org.w3c.dom.Element el)

setXFormsId

protected java.lang.String setXFormsId(org.w3c.dom.Element el,
                                       java.lang.String id)

addChoicesForSelectControl

protected void addChoicesForSelectControl(org.w3c.dom.Document xForm,
                                          org.w3c.dom.Element choicesElement,
                                          java.util.Map choiceValues,
                                          java.util.ResourceBundle resourceBundle)
_UNDOCUMENTED_

Parameters:
xForm - _UNDOCUMENTED_
choicesElement - _UNDOCUMENTED_
choiceValues - _UNDOCUMENTED_

addChoicesForSelectSwitchControl

protected java.util.Map addChoicesForSelectSwitchControl(org.w3c.dom.Document xformsDocument,
                                                         org.w3c.dom.Element formSection,
                                                         java.util.List choiceValues,
                                                         java.lang.String typeBindId)

getXFormsTypeName

protected java.lang.String getXFormsTypeName(org.w3c.dom.Document xformsDocument,
                                             org.apache.xerces.xs.XSModel schema,
                                             org.apache.xerces.xs.XSTypeDefinition controlType)
used to get the type name that will be used in the XForms document

Parameters:
xformsDocument -
schema -
controlType - the type from which we want the name
Returns:
the complete type name (with namespace prefix) of the type in the XForms doc

createCaption

public java.lang.String createCaption(java.lang.String text,
                                      org.apache.xerces.xs.XSObject o,
                                      java.util.ResourceBundle resourceBundle)

createCaption

public java.lang.String createCaption(java.lang.String text,
                                      org.apache.xerces.xs.XSAnnotation annotation,
                                      java.util.ResourceBundle resourceBundle)

createCaption

public java.lang.String createCaption(java.lang.String text)
Creates a caption for the provided text extracted from the XML Schema. The implementation is responsible for reformatting the provided string to make it suitable to be displayed to users of the XForm. This typically includes translating XML tag name style identifiers (e.g. customerStreetAddress) into more reader friendly captions (e.g. Customer Street Address).

Parameters:
text - The string value to be reformatted for use as a caption.
Returns:
The caption.

createCaption

public java.lang.String createCaption(org.apache.xerces.xs.XSAttributeDeclaration attribute,
                                      java.util.ResourceBundle resourceBundle)
Creates a caption for the provided XML Schema attribute. The implementation is responsible for providing an appropriate caption suitable to be displayed to users of the XForm. This typically includes translating XML tag name style identifiers (e.g. customerStreetAddress) into more reader friendly captions (e.g. Customer Street Address).

Parameters:
attribute - The XML schema attribute for which a caption is required.
Returns:
The caption.

createCaption

public java.lang.String createCaption(org.apache.xerces.xs.XSAttributeUse attribute,
                                      java.util.ResourceBundle resourceBundle)

createCaption

public java.lang.String createCaption(org.apache.xerces.xs.XSElementDeclaration element,
                                      java.util.ResourceBundle resourceBundle)
Creates a caption for the provided XML Schema element. The implementation is responsible for providing an appropriate caption suitable to be displayed to users of the XForm. This typically includes translating XML tag name style identifiers (e.g. customerStreetAddress) into more reader friendly captions (e.g. Customer Street Address).

Parameters:
element - The XML schema element for which a caption is required.
Returns:
The caption.

createCaption

public java.lang.String createCaption(org.apache.xerces.xs.XSObject element,
                                      java.util.ResourceBundle resourceBundle)

createControlForAnyType

public org.w3c.dom.Element createControlForAnyType(org.w3c.dom.Document xformsDocument,
                                                   java.lang.String caption,
                                                   org.apache.xerces.xs.XSTypeDefinition controlType)
Creates a form control for an XML Schema any type.
This method is called when the form builder determines a form control is required for an any type. The implementation of this method is responsible for creating an XML element of the appropriate type to receive a value for controlType. The caller is responsible for adding the returned element to the form and setting caption, bind, and other standard elements and attributes.

Parameters:
xformsDocument - The XForm document.
controlType - The XML Schema type for which the form control is to be created.
Returns:
The element for the form control.

createControlForAtomicType

public org.w3c.dom.Element createControlForAtomicType(org.w3c.dom.Document xformsDocument,
                                                      org.apache.xerces.xs.XSSimpleTypeDefinition controlType,
                                                      org.apache.xerces.xs.XSObject owner,
                                                      java.lang.String caption,
                                                      java.util.ResourceBundle resourceBundle)
Creates a form control for an XML Schema simple atomic type.

This method is called when the form builder determines a form control is required for an atomic type. The implementation of this method is responsible for creating an XML element of the appropriate type to receive a value for controlType. The caller is responsible for adding the returned element to the form and setting caption, bind, and other standard elements and attributes.

Parameters:
xformsDocument - The XForm document.
controlType - The XML Schema type for which the form control is to be created.
Returns:
The element for the form control.

createControlForEnumerationType

public org.w3c.dom.Element createControlForEnumerationType(org.w3c.dom.Document xformsDocument,
                                                           org.apache.xerces.xs.XSSimpleTypeDefinition controlType,
                                                           org.apache.xerces.xs.XSObject owner,
                                                           java.lang.String caption,
                                                           org.w3c.dom.Element bindElement,
                                                           java.util.ResourceBundle resourceBundle)
Creates a form control for an XML Schema simple type restricted by an enumeration. This method is called when the form builder determines a form control is required for an enumerated type. The implementation of this method is responsible for creating an XML element of the appropriate type to receive a value for controlType. The caller is responsible for adding the returned element to the form and setting caption, bind, and other standard elements and attributes.

Parameters:
xformsDocument - The XForm document.
controlType - The XML Schema type for which the form control is to be created.
caption - The caption for the form control. The caller The purpose of providing the caption is to permit the implementation to add a [Select1 .... ] message that involves the caption.
bindElement - The bind element for this control. The purpose of providing the bind element is to permit the implementation to add a isValid attribute to the bind element that prevents the [Select1 .... ] item from being selected.
Returns:
The element for the form control.

createControlForListType

public org.w3c.dom.Element createControlForListType(org.w3c.dom.Document xformsDocument,
                                                    org.apache.xerces.xs.XSSimpleTypeDefinition listType,
                                                    org.apache.xerces.xs.XSObject owner,
                                                    java.lang.String caption,
                                                    org.w3c.dom.Element bindElement,
                                                    java.util.ResourceBundle resourceBundle)
Creates a form control for an XML Schema simple list type.

This method is called when the form builder determines a form control is required for a list type. The implementation of this method is responsible for creating an XML element of the appropriate type to receive a value for controlType. The caller is responsible for adding the returned element to the form and setting caption, bind, and other standard elements and attributes.

Parameters:
xformsDocument - The XForm document.
listType - The XML Schema list type for which the form control is to be created.
owner -
caption - The caption for the form control. The caller The purpose of providing the caption is to permit the implementation to add a [Select1 .... ] message that involves the caption.
bindElement - The bind element for this control. The purpose of providing the bind element is to permit the implementation to add a isValid attribute to the bind element that prevents the [Select1 .... ] item from being selected.
resourceBundle -
Returns:
The element for the form control.

startBindElement

public org.w3c.dom.Element startBindElement(org.w3c.dom.Element bindElement,
                                            org.apache.xerces.xs.XSModel schema,
                                            org.apache.xerces.xs.XSTypeDefinition controlType,
                                            org.apache.xerces.xs.XSObject owner,
                                            SchemaUtil.Occurrence o)
This method is invoked after an xforms:bind element is created for the specified SimpleType. The implementation is responsible for setting setting any/all bind attributes except for id and ref - these have been automatically set by the caller (and should not be touched by implementation of startBindElement) prior to invoking startBindElement. The caller automatically adds the returned element to the model section of the form.

Parameters:
bindElement - The bindElement being processed.
schema - XML Schema type of the element/attribute this bind is for.
controlType -
owner -
o -
Returns:
The bind Element to use in the XForm - bindElement or a replacement.


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.