support for specifying appearance for select and select1 from the schema.

handling the case where create web content is called with no forms configured for the web project

some more progress on xf:switch

updated tests - including one from ken at berkeley who is trying to use forms to write grant applications.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4925 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-01-25 00:39:30 +00:00
parent bd25cfa86f
commit 1c966e9a71
10 changed files with 1227 additions and 614 deletions

View File

@@ -84,6 +84,7 @@ public class CreateWebContentWizard extends BaseContentWizard
protected String content = null; protected String content = null;
protected String formName; protected String formName;
protected transient List<SelectItem> createMimeTypes; protected transient List<SelectItem> createMimeTypes;
protected transient List<SelectItem> formChoices;
protected String createdPath = null; protected String createdPath = null;
protected List<Rendition> renditions = null; protected List<Rendition> renditions = null;
protected FormInstanceData formInstanceData = null; protected FormInstanceData formInstanceData = null;
@@ -171,6 +172,8 @@ public class CreateWebContentWizard extends BaseContentWizard
this.renditions = null; this.renditions = null;
this.startWorkflow = false; this.startWorkflow = false;
this.formSelectDisabled = false; this.formSelectDisabled = false;
this.createMimeTypes = null;
this.formChoices = null;
// check for a form ID being passed in as a parameter // check for a form ID being passed in as a parameter
if (this.parameters.get(UIUserSandboxes.PARAM_FORM_NAME) != null) if (this.parameters.get(UIUserSandboxes.PARAM_FORM_NAME) != null)
@@ -523,17 +526,20 @@ public class CreateWebContentWizard extends BaseContentWizard
*/ */
public List<SelectItem> getFormChoices() public List<SelectItem> getFormChoices()
{ {
final List<Form> forms = this.avmBrowseBean.getWebProject().getForms(); if (this.formChoices == null)
final List<SelectItem> items = new ArrayList<SelectItem>(forms.size());
for (final Form f : forms)
{ {
items.add(new SelectItem(f.getName(), f.getTitle())); final List<Form> forms = this.avmBrowseBean.getWebProject().getForms();
this.formChoices = new ArrayList<SelectItem>(forms.size());
for (final Form f : forms)
{
this.formChoices.add(new SelectItem(f.getName(), f.getTitle()));
}
final QuickSort sorter = new QuickSort(this.formChoices, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
} }
return this.formChoices;
final QuickSort sorter = new QuickSort(items, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
return items;
} }
/** /**
@@ -543,21 +549,21 @@ public class CreateWebContentWizard extends BaseContentWizard
{ {
if (this.createMimeTypes == null) if (this.createMimeTypes == null)
{ {
FacesContext context = FacesContext.getCurrentInstance(); final FacesContext context = FacesContext.getCurrentInstance();
// add the well known object type to start with // add the well known object type to start with
this.createMimeTypes = new ArrayList<SelectItem>(5); this.createMimeTypes = new ArrayList<SelectItem>(5);
// add the configured create mime types to the list // add the configured create mime types to the list
ConfigService svc = Application.getConfigService(context); final ConfigService svc = Application.getConfigService(context);
Config wizardCfg = svc.getConfig("Content Wizards"); final Config wizardCfg = svc.getConfig("Content Wizards");
if (wizardCfg == null) if (wizardCfg == null)
{ {
LOGGER.warn("Could not find 'Content Wizards' configuration section"); LOGGER.warn("Could not find 'Content Wizards' configuration section");
} }
else else
{ {
ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types"); final ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types");
if (typesCfg == null) if (typesCfg == null)
{ {
LOGGER.warn("Could not find 'create-mime-types' configuration element"); LOGGER.warn("Could not find 'create-mime-types' configuration element");
@@ -566,16 +572,20 @@ public class CreateWebContentWizard extends BaseContentWizard
{ {
for (ConfigElement child : typesCfg.getChildren()) for (ConfigElement child : typesCfg.getChildren())
{ {
String currentMimeType = child.getAttribute("name"); final String currentMimeType = child.getAttribute("name");
if (currentMimeType != null) if (currentMimeType == null ||
(MimetypeMap.MIMETYPE_XML.equals(currentMimeType) &&
this.getFormChoices().size() == 0))
{ {
String label = getSummaryMimeType(currentMimeType); continue;
this.createMimeTypes.add(new SelectItem(currentMimeType, label));
} }
final String label = this.getSummaryMimeType(currentMimeType);
this.createMimeTypes.add(new SelectItem(currentMimeType, label));
} }
// make sure the list is sorted by the label // make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); final QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort(); sorter.sort();
} }
} }

View File

@@ -34,6 +34,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@@ -175,4 +176,41 @@ public class XMLUtil
return null; return null;
} }
} }
/**
* Provides a NodeList of multiple nodelists
*/
public static NodeList combine(final NodeList... nls)
{
return new NodeList()
{
public Node item(final int index)
{
int offset = 0;
for (int i = 0; i < nls.length; i++)
{
if (index - offset < nls[i].getLength())
{
return nls[i].item(index - offset);
}
else
{
offset += nls[i].getLength();
}
}
return null;
}
public int getLength()
{
int result = 0;
for (int i = 0; i < nls.length; i++)
{
result += nls[i].getLength();
}
return result;
}
};
}
} }

View File

@@ -73,65 +73,7 @@ public class Schema2XForms
private final static Log LOGGER = LogFactory.getLog(Schema2XForms.class); private final static Log LOGGER = LogFactory.getLog(Schema2XForms.class);
private static final String PROPERTY_PREFIX = private final static int LONG_LIST_SIZE = 5;
"http://www.chiba.org/properties/schemaFormBuilder/";
/**
* Property to control the selection of UI control for a selectOne control.
* If a selectOne control has >= the number of values specified in this property,
* it is considered a <b>long</b> list, and the UI control specified by
* SELECTONE_UI_CONTROL_LONG_PROP is used. Otherwise, the value of SELECTONE_UI_CONTROL_SHORT_PROP
* is used.
*/
public static final String SELECTONE_LONG_LIST_SIZE_PROP =
PROPERTY_PREFIX + "select1@longListSize";
/**
* Property to specify the selectMany UI control to be used when there are releatively few items
* to choose from.
*/
public static final String SELECTONE_UI_CONTROL_SHORT_PROP =
PROPERTY_PREFIX + "select1@appearance/short";
/**
* Property to specify the selectMany UI control to be used when there are large numbers of items
* to choose from.
*/
public static final String SELECTONE_UI_CONTROL_LONG_PROP =
PROPERTY_PREFIX + "select1@appearance/long";
private static final String DEFAULT_SELECTONE_UI_CONTROL_SHORT_PROP =
"full";
private static final String DEFAULT_SELECTONE_UI_CONTROL_LONG_PROP =
"minimal";
/**
* Property to control the selection of UI control for a selectMany control.
* If a selectMany control has >= the number of values specified in this property,
* it is considered a <b>long</b> list, and the UI control specified by
* SELECTMANY_UI_CONTROL_LONG_PROP is used. Otherwise, the value of SELECTMANY_UI_CONTROL_SHORT_PROP
* is used.
*/
public static final String SELECTMANY_LONG_LIST_SIZE_PROP =
PROPERTY_PREFIX + "select@longListSize";
/**
* Property to specify the selectMany UI control to be used when there are releatively few items
* to choose from.
*/
public static final String SELECTMANY_UI_CONTROL_SHORT_PROP =
PROPERTY_PREFIX + "select@appearance/short";
/**
* Property to specify the selectMany UI control to be used when there are large numbers of items
* to choose from.
*/
public static final String SELECTMANY_UI_CONTROL_LONG_PROP =
PROPERTY_PREFIX + "select@appearance/long";
private static final String DEFAULT_SELECTMANY_UI_CONTROL_SHORT_PROP =
"full";
private static final String DEFAULT_SELECTMANY_UI_CONTROL_LONG_PROP =
"compact";
private static final String DEFAULT_LONG_LIST_MAX_SIZE = "6";
private final String action; private final String action;
private final SubmitMethod submitMethod; private final SubmitMethod submitMethod;
@@ -143,7 +85,6 @@ public class Schema2XForms
* values: "Long" representing the counter for this element * values: "Long" representing the counter for this element
*/ */
private final Map<String, Long> counter = new HashMap<String, Long>(); private final Map<String, Long> counter = new HashMap<String, Long>();
private final Properties properties = new Properties();
private String targetNamespace; private String targetNamespace;
private final Map namespacePrefixes = new HashMap(); private final Map namespacePrefixes = new HashMap();
@@ -174,50 +115,6 @@ public class Schema2XForms
this.base = base; this.base = base;
} }
/**
* Get the current set of properties used by implementations of Schema2XForms.
*
* @return The list of properties.
*/
public Properties getProperties()
{
return properties;
}
/**
* Sets the property to the specified value. If the property exists, its value is overwritten.
*
* @param key The implementation defined property key.
* @param value The value for the property.
*/
public void setProperty(String key, String value)
{
getProperties().setProperty(key, value);
}
/**
* Gets the value for the specified property.
*
* @param key The implementation defined property key.
* @return The property value if found, or null if the property cannot be located.
*/
public String getProperty(String key)
{
return getProperties().getProperty(key);
}
/**
* Gets the value for the specified property, with a default if the property cannot be located.
*
* @param key The implementation defined property key.
* @param defaultValue This value will be returned if the property does not exists.
* @return The property value if found, or defaultValue if the property cannot be located.
*/
public String getProperty(String key, String defaultValue)
{
return getProperties().getProperty(key, defaultValue);
}
/** /**
* Generate the XForm based on a user supplied XML Schema. * Generate the XForm based on a user supplied XML Schema.
* *
@@ -373,16 +270,6 @@ public class Schema2XForms
public void reset() public void reset()
{ {
this.counter.clear(); this.counter.clear();
setProperty(SELECTMANY_LONG_LIST_SIZE_PROP, DEFAULT_LONG_LIST_MAX_SIZE);
setProperty(SELECTMANY_UI_CONTROL_SHORT_PROP,
DEFAULT_SELECTMANY_UI_CONTROL_SHORT_PROP);
setProperty(SELECTMANY_UI_CONTROL_LONG_PROP,
DEFAULT_SELECTMANY_UI_CONTROL_LONG_PROP);
setProperty(SELECTONE_LONG_LIST_SIZE_PROP, DEFAULT_LONG_LIST_MAX_SIZE);
setProperty(SELECTONE_UI_CONTROL_SHORT_PROP,
DEFAULT_SELECTONE_UI_CONTROL_SHORT_PROP);
setProperty(SELECTONE_UI_CONTROL_LONG_PROP,
DEFAULT_SELECTONE_UI_CONTROL_LONG_PROP);
} }
private void insertPrototypeNodes(final Element instanceDocumentElement, private void insertPrototypeNodes(final Element instanceDocumentElement,
@@ -580,9 +467,10 @@ public class Schema2XForms
/** /**
*/ */
protected Map<String, Element> addChoicesForSelectSwitchControl(final Document xForm, protected Map<String, Element> addChoicesForSelectSwitchControl(final Document xformsDocument,
final Element choicesElement, final Element formSection,
final List<XSTypeDefinition> choiceValues) final List<XSTypeDefinition> choiceValues,
final String typeBindId)
{ {
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
{ {
@@ -613,37 +501,32 @@ public class Schema2XForms
} }
//build the case element //build the case element
final Element caseElement = xForm.createElementNS(NamespaceConstants.XFORMS_NS, final Element caseElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":case"); NamespaceConstants.XFORMS_PREFIX + ":case");
caseElement.appendChild(this.createLabel(xformsDocument, textValue));
final String caseId = this.setXFormsId(caseElement); final String caseId = this.setXFormsId(caseElement);
result.put(textValue, caseElement); result.put(textValue, caseElement);
final Element item = this.createXFormsItem(xForm, final Element toggle = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
this.createCaption(textValue), NamespaceConstants.XFORMS_PREFIX + ":toggle");
textValue);
choicesElement.appendChild(item);
/// action in the case
final Element action = xForm.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":action");
this.setXFormsId(action);
item.appendChild(action);
action.setAttributeNS(NamespaceConstants.XMLEVENTS_NS,
NamespaceConstants.XMLEVENTS_PREFIX + ":event",
"xforms-select");
final Element toggle = xForm.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":toggle");
this.setXFormsId(toggle); this.setXFormsId(toggle);
toggle.setAttributeNS(NamespaceConstants.XFORMS_NS, toggle.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":case", NamespaceConstants.XFORMS_PREFIX + ":case",
caseId); caseId);
//toggle.setAttributeNS(NamespaceConstants.XFORMS_NS, final Element setValue = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
//NamespaceConstants.XFORMS_PREFIX + ":case",bindIdPrefix + "_" + textValue +"_case"); NamespaceConstants.XFORMS_PREFIX + ":setvalue");
action.appendChild(toggle); setValue.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":bind",
typeBindId);
setValue.appendChild(xformsDocument.createTextNode(textValue));
formSection.appendChild(this.createTrigger(xformsDocument,
null,
typeBindId,
"toggle to case " + caseId,
toggle,
setValue));
} }
return result; return result;
} }
@@ -661,11 +544,15 @@ public class Schema2XForms
final NodeList d = doc.getElementsByTagNameNS(namespace, elementName); final NodeList d = doc.getElementsByTagNameNS(namespace, elementName);
if (d.getLength() == 0) if (d.getLength() == 0)
{
return null; return null;
}
if (d.getLength() > 1) if (d.getLength() > 1)
LOGGER.warn("expect exactly one value for " + namespace + {
LOGGER.warn("expected exactly one value for " + namespace +
":" + elementName + ":" + elementName +
". found " + d.getLength()); ". found " + d.getLength());
}
String result = DOMUtil.getTextNodeAsString(d.item(0)); String result = DOMUtil.getTextNodeAsString(d.item(0));
LOGGER.debug(namespace + ":" + elementName + " = " + result); LOGGER.debug(namespace + ":" + elementName + " = " + result);
if (result.startsWith("${") && result.endsWith("}") && resourceBundle != null) if (result.startsWith("${") && result.endsWith("}") && resourceBundle != null)
@@ -685,7 +572,7 @@ public class Schema2XForms
return result; return result;
} }
private Element addAnyType(final Document xForm, private Element addAnyType(final Document xformsDocument,
final Element modelSection, final Element modelSection,
final Element formSection, final Element formSection,
final XSModel schema, final XSModel schema,
@@ -694,7 +581,7 @@ public class Schema2XForms
final String pathToRoot, final String pathToRoot,
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
{ {
return this.addSimpleType(xForm, return this.addSimpleType(xformsDocument,
modelSection, modelSection,
formSection, formSection,
schema, schema,
@@ -706,7 +593,7 @@ public class Schema2XForms
resourceBundle); resourceBundle);
} }
private void addAttributeSet(final Document xForm, private void addAttributeSet(final Document xformsDocument,
final Element modelSection, final Element modelSection,
final Element defaultInstanceElement, final Element defaultInstanceElement,
final Element formSection, final Element formSection,
@@ -819,7 +706,7 @@ public class Schema2XForms
throw new FormBuilderException("error retrieving default value for attribute " + throw new FormBuilderException("error retrieving default value for attribute " +
attributeName + " at " + newPathToRoot, e); attributeName + " at " + newPathToRoot, e);
} }
this.addSimpleType(xForm, this.addSimpleType(xformsDocument,
modelSection, modelSection,
formSection, formSection,
schema, schema,
@@ -831,7 +718,7 @@ public class Schema2XForms
} }
} }
private Element addComplexType(final Document xForm, private Element addComplexType(final Document xformsDocument,
final Element modelSection, final Element modelSection,
final Element defaultInstanceElement, final Element defaultInstanceElement,
final Element formSection, final Element formSection,
@@ -861,13 +748,13 @@ public class Schema2XForms
} }
// add a group node and recurse // add a group node and recurse
final Element groupElement = this.createGroup(xForm, final Element groupElement = this.createGroup(xformsDocument,
modelSection, modelSection,
formSection, formSection,
owner, owner,
resourceBundle); resourceBundle);
final SchemaUtil.Occurance o = SchemaUtil.getOccurance(owner); final SchemaUtil.Occurance o = SchemaUtil.getOccurance(owner);
final Element repeatSection = this.addRepeatIfNecessary(xForm, final Element repeatSection = this.addRepeatIfNecessary(xformsDocument,
modelSection, modelSection,
groupElement, groupElement,
controlType, controlType,
@@ -883,7 +770,7 @@ public class Schema2XForms
relative = true; relative = true;
} }
this.addComplexTypeChildren(xForm, this.addComplexTypeChildren(xformsDocument,
modelSection, modelSection,
defaultInstanceElement, defaultInstanceElement,
repeatSection, repeatSection,
@@ -897,7 +784,7 @@ public class Schema2XForms
return groupElement; return groupElement;
} }
private void addComplexTypeChildren(final Document xForm, private void addComplexTypeChildren(final Document xformsDocument,
Element modelSection, Element modelSection,
final Element defaultInstanceElement, final Element defaultInstanceElement,
final Element formSection, final Element formSection,
@@ -937,7 +824,7 @@ public class Schema2XForms
{ {
if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
{ {
this.addSimpleType(xForm, this.addSimpleType(xformsDocument,
modelSection, modelSection,
formSection, formSection,
schema, schema,
@@ -973,7 +860,7 @@ public class Schema2XForms
} }
//attributes //attributes
this.addAttributeSet(xForm, this.addAttributeSet(xformsDocument,
modelSection, modelSection,
defaultInstanceElement, defaultInstanceElement,
formSection, formSection,
@@ -1001,7 +888,7 @@ public class Schema2XForms
if (term instanceof XSModelGroup) if (term instanceof XSModelGroup)
{ {
//call addGroup on this group //call addGroup on this group
this.addGroup(xForm, this.addGroup(xformsDocument,
modelSection, modelSection,
defaultInstanceElement, defaultInstanceElement,
formSection, formSection,
@@ -1065,7 +952,7 @@ public class Schema2XForms
modelSection, modelSection,
formSection, formSection,
schema, schema,
(XSComplexTypeDefinition) controlType, (XSComplexTypeDefinition)controlType,
elementDecl, elementDecl,
pathToRoot, pathToRoot,
resourceBundle); resourceBundle);
@@ -1078,13 +965,15 @@ public class Schema2XForms
} }
boolean relative = true; boolean relative = true;
String typeName = controlType.getName(); final String typeName = controlType.getName();
final boolean typeIsAbstract = ((XSComplexTypeDefinition)controlType).getAbstract();
final TreeSet<XSTypeDefinition> compatibleTypes = final TreeSet<XSTypeDefinition> compatibleTypes =
typeName != null ? this.typeTree.get(controlType.getName()) : null; typeName != null ? this.typeTree.get(typeName) : null;
if (compatibleTypes == null && typeName != null && LOGGER.isDebugEnabled()) if (compatibleTypes == null && typeName != null && LOGGER.isDebugEnabled())
{ {
LOGGER.debug("No compatible type found for " + typeName); LOGGER.debug("No compatible type found for " + typeName);
} }
if (typeName != null && compatibleTypes != null) if (typeName != null && compatibleTypes != null)
{ {
relative = false; relative = false;
@@ -1097,7 +986,7 @@ public class Schema2XForms
LOGGER.debug(" compatible type name=" + compType.getName()); LOGGER.debug(" compatible type name=" + compType.getName());
} }
} }
final boolean typeIsAbstract = ((XSComplexTypeDefinition)controlType).getAbstract();
if (!typeIsAbstract && compatibleTypes.size() == 0) if (!typeIsAbstract && compatibleTypes.size() == 0)
{ {
relative = true; relative = true;
@@ -1111,7 +1000,7 @@ public class Schema2XForms
} }
else if (typeIsAbstract && compatibleTypes.size() == 0) else if (typeIsAbstract && compatibleTypes.size() == 0)
{ {
//name not null but no compatibleType? // name not null but no compatibleType?
relative = false; relative = false;
} }
else else
@@ -1147,7 +1036,7 @@ public class Schema2XForms
// create the <xforms:bind> element and add it to the model. // create the <xforms:bind> element and add it to the model.
final Element bindElement = final Element bindElement =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":bind"); NamespaceConstants.XFORMS_PREFIX + ":bind");
final String bindId = this.setXFormsId(bindElement); final String bindId = this.setXFormsId(bindElement);
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":nodeset", NamespaceConstants.XFORMS_PREFIX + ":nodeset",
@@ -1175,7 +1064,6 @@ public class Schema2XForms
true, true,
false, false,
resourceBundle); resourceBundle);
} }
private Element addElementWithMultipleCompatibleTypes(final Document xformsDocument, private Element addElementWithMultipleCompatibleTypes(final Document xformsDocument,
@@ -1189,12 +1077,16 @@ public class Schema2XForms
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
throws FormBuilderException throws FormBuilderException
{ {
LOGGER.debug("&&&&&&&&&&&&&&& path to root = " + pathToRoot);
// look for compatible types // look for compatible types
final XSTypeDefinition controlType = elementDecl.getTypeDefinition(); final XSTypeDefinition controlType = elementDecl.getTypeDefinition();
defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS,
NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":type",
controlType.getName());
defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS,
NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil",
"true");
//get possible values //get possible values
final List<XSTypeDefinition> enumValues = new LinkedList<XSTypeDefinition>(); final List<XSTypeDefinition> enumValues = new LinkedList<XSTypeDefinition>();
//add the type (if not abstract) //add the type (if not abstract)
if (!((XSComplexTypeDefinition) controlType).getAbstract()) if (!((XSComplexTypeDefinition) controlType).getAbstract())
@@ -1205,17 +1097,7 @@ public class Schema2XForms
//add compatible types //add compatible types
enumValues.addAll(compatibleTypes); enumValues.addAll(compatibleTypes);
final Element control =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":select1");
final String select1Id = this.setXFormsId(control);
final Element choices =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":choices");
this.setXFormsId(choices, select1Id + "-choices");
final String caption = this.createCaption(elementDecl.getName() + " Type"); final String caption = this.createCaption(elementDecl.getName() + " Type");
control.appendChild(this.createLabel(xformsDocument, caption));
// multiple compatible types for this element exist // multiple compatible types for this element exist
// in the schema - allow the user to choose from // in the schema - allow the user to choose from
@@ -1229,109 +1111,47 @@ public class Schema2XForms
pathToRoot + "/@xsi:type"); pathToRoot + "/@xsi:type");
modelSection.appendChild(bindElement); modelSection.appendChild(bindElement);
control.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":bind",
bindId);
//add the "element" bind, in addition //add the "element" bind, in addition
Element bindElement2 = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element bindElement2 = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":bind"); NamespaceConstants.XFORMS_PREFIX + ":bind");
String bindId2 = this.setXFormsId(bindElement2); final String bindId2 = this.setXFormsId(bindElement2);
bindElement2.setAttributeNS(NamespaceConstants.XFORMS_NS, bindElement2.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":nodeset", NamespaceConstants.XFORMS_PREFIX + ":nodeset",
pathToRoot); pathToRoot);
modelSection.appendChild(bindElement2); modelSection.appendChild(bindElement2);
control.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
(enumValues.size() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))
? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)
: getProperty(SELECTONE_UI_CONTROL_LONG_PROP)));
if (enumValues.size() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)))
{
// add the "Please select..." instruction item for the combobox
// and set the isValid attribute on the bind element to check for the "Please select..."
// item to indicate that is not a valid value
//
final String pleaseSelect = "[Select1 " + caption + "]";
final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect);
choices.appendChild(item);
// not(purchaseOrder/state = '[Choose State]')
//String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset") + " = '" + pleaseSelect + "')";
// ->no, not(. = '[Choose State]')
final String isValidExpr = "not( . = '" + pleaseSelect + "')";
//check if there was a constraint
final String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint");
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":constraint",
(constraint != null && constraint.length() != 0
? constraint + " && " + isValidExpr
: isValidExpr));
}
control.appendChild(choices);
formSection.appendChild(control);
// add content to select1 // add content to select1
final Map<String, Element> caseTypes = final Map<String, Element> caseTypes =
this.addChoicesForSelectSwitchControl(xformsDocument, choices, enumValues); this.addChoicesForSelectSwitchControl(xformsDocument, formSection, enumValues, bindId);
//add a trigger for this control (is there a way to not need it ?)
final Element dispatchTrigger = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":dispatch");
dispatchTrigger.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":name",
"DOMActivate");
dispatchTrigger.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":target",
select1Id);
formSection.appendChild(this.createTrigger(xformsDocument,
null,
null,
"validate choice",
dispatchTrigger));
//add switch //add switch
final Element switchElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element switchElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":switch"); NamespaceConstants.XFORMS_PREFIX + ":switch");
this.setXFormsId(switchElement, select1Id + "-" + this.setXFormsId(switchElement)); final String switchId = this.setXFormsId(switchElement);
switchElement.setAttributeNS(NamespaceConstants.XFORMS_NS, switchElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":bind", NamespaceConstants.XFORMS_PREFIX + ":bind",
bindId); bindId);
formSection.appendChild(switchElement); formSection.appendChild(switchElement);
//formSection.appendChild(switchElement);
/////////////// add this type //////////////
final Element firstCaseElement = caseTypes.get(controlType.getName()); final Element firstCaseElement = caseTypes.get(controlType.getName());
switchElement.appendChild(firstCaseElement); switchElement.appendChild(firstCaseElement);
firstCaseElement.setAttributeNS(NamespaceConstants.XFORMS_NS, final Element firstGroupElement = this.addComplexType(xformsDocument,
NamespaceConstants.XFORMS_PREFIX + ":selected", modelSection,
"true"); defaultInstanceElement,
firstCaseElement,
defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, schema,
NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":type", (XSComplexTypeDefinition)controlType,
controlType.getName()); elementDecl,
defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, pathToRoot,
NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", true,
"true"); false,
LOGGER.debug("&&&&& die before " + XMLUtil.toString(defaultInstanceElement)); resourceBundle);
this.addComplexType(xformsDocument, firstGroupElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
modelSection, NamespaceConstants.XFORMS_PREFIX + ":appearance",
defaultInstanceElement, "");
firstCaseElement,
schema,
(XSComplexTypeDefinition)controlType,
elementDecl,
pathToRoot,
true,
false,
resourceBundle);
LOGGER.debug("&&&&& die after " + XMLUtil.toString(defaultInstanceElement));
/////////////// add sub types ////////////// /////////////// add sub types //////////////
// add each compatible type within // add each compatible type within
@@ -1352,27 +1172,23 @@ public class Schema2XForms
continue; continue;
} }
//Element caseElement = (Element) xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":case");
//caseElement.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":id",bindId + "_" + type.getName() +"_case");
//String case_id=this.setXFormsId(caseElement);
final Element caseElement = caseTypes.get(type.getName()); final Element caseElement = caseTypes.get(type.getName());
caseElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":selected",
"false");
switchElement.appendChild(caseElement); switchElement.appendChild(caseElement);
this.addComplexType(xformsDocument, final Element groupElement = this.addComplexType(xformsDocument,
modelSection, modelSection,
defaultInstanceElement, defaultInstanceElement,
caseElement, caseElement,
schema, schema,
(XSComplexTypeDefinition) type, (XSComplexTypeDefinition) type,
elementDecl, elementDecl,
pathToRoot, pathToRoot,
true, true,
true, true,
resourceBundle); resourceBundle);
groupElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance",
"");
// modify bind to add a "relevant" attribute that checks the value of @xsi:type // modify bind to add a "relevant" attribute that checks the value of @xsi:type
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
@@ -1383,8 +1199,8 @@ public class Schema2XForms
final NodeList binds = bindElement2.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); final NodeList binds = bindElement2.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
for (int i = 0; i < binds.getLength(); i++) for (int i = 0; i < binds.getLength(); i++)
{ {
Element subBind = (Element) binds.item(i); final Element subBind = (Element) binds.item(i);
String name = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); final String name = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
{ {
@@ -1427,7 +1243,7 @@ public class Schema2XForms
newRelevant); newRelevant);
} }
} }
return control; return switchElement;
} }
/** /**
@@ -1629,8 +1445,10 @@ public class Schema2XForms
} }
} }
else else
{ //XSWildcard -> ignore ? {
//LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); LOGGER.warn("Unhandled term " + term +
" found in group from " + owner.getName() +
" for pathToRoot = " + pathToRoot);
} }
} }
@@ -1665,7 +1483,7 @@ public class Schema2XForms
final Element repeatSection = final Element repeatSection =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":repeat"); NamespaceConstants.XFORMS_PREFIX + ":repeat");
//bind instead of repeat //bind instead of repeat
//repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":nodeset",pathToRoot); //repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":nodeset",pathToRoot);
@@ -1713,7 +1531,7 @@ public class Schema2XForms
//add a group inside the repeat? //add a group inside the repeat?
final Element group = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element group = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":group"); NamespaceConstants.XFORMS_PREFIX + ":group");
group.setAttributeNS(NamespaceConstants.XFORMS_NS, group.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance", NamespaceConstants.XFORMS_PREFIX + ":appearance",
"repeated"); "repeated");
@@ -1887,6 +1705,7 @@ public class Schema2XForms
{ {
formControl = this.createControlForListType(xformsDocument, formControl = this.createControlForListType(xformsDocument,
(XSSimpleTypeDefinition)controlType, (XSSimpleTypeDefinition)controlType,
owner,
caption, caption,
bindElement, bindElement,
resourceBundle); resourceBundle);
@@ -1896,6 +1715,7 @@ public class Schema2XForms
{ {
formControl = this.createControlForEnumerationType(xformsDocument, formControl = this.createControlForEnumerationType(xformsDocument,
(XSSimpleTypeDefinition)controlType, (XSSimpleTypeDefinition)controlType,
owner,
caption, caption,
bindElement, bindElement,
resourceBundle); resourceBundle);
@@ -2040,19 +1860,22 @@ public class Schema2XForms
} }
//model element //model element
Element modelElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element modelElement =
NamespaceConstants.XFORMS_PREFIX + ":model"); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":model");
this.setXFormsId(modelElement); this.setXFormsId(modelElement);
Element modelWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, final Element modelWrapper =
NamespaceConstants.XHTML_PREFIX + ":head"); xformsDocument.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":head");
modelWrapper.appendChild(modelElement); modelWrapper.appendChild(modelElement);
envelopeElement.appendChild(modelWrapper); envelopeElement.appendChild(modelWrapper);
//form control wrapper -> created by wrapper //form control wrapper -> created by wrapper
//Element formWrapper = xformsDocument.createElement("body"); //Element formWrapper = xformsDocument.createElement("body");
//envelopeElement.appendChild(formWrapper); //envelopeElement.appendChild(formWrapper);
Element formWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, final Element formWrapper =
NamespaceConstants.XHTML_PREFIX + ":body"); xformsDocument.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":body");
envelopeElement.appendChild(formWrapper); envelopeElement.appendChild(formWrapper);
return xformsDocument; return xformsDocument;
} }
@@ -2064,7 +1887,7 @@ public class Schema2XForms
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
{ {
// add a group node and recurse // add a group node and recurse
Element groupElement = final Element groupElement =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":group"); NamespaceConstants.XFORMS_PREFIX + ":group");
this.setXFormsId(groupElement); this.setXFormsId(groupElement);
@@ -2111,18 +1934,26 @@ public class Schema2XForms
{ {
// if the word is all upper case, then set to lower case and continue // if the word is all upper case, then set to lower case and continue
if (text.equals(text.toUpperCase())) if (text.equals(text.toUpperCase()))
{
text = text.toLowerCase(); text = text.toLowerCase();
}
final String[] s = text.split("[-_\\ ]"); final String[] s = text.split("[-_\\ ]");
final StringBuffer result = new StringBuffer(); final StringBuffer result = new StringBuffer();
for (int i = 0; i < s.length; i++) for (int i = 0; i < s.length; i++)
{ {
if (i != 0) if (i != 0)
{
result.append(' '); result.append(' ');
}
if (s[i].length() > 1) if (s[i].length() > 1)
{
result.append(Character.toUpperCase(s[i].charAt(0)) + result.append(Character.toUpperCase(s[i].charAt(0)) +
s[i].substring(1, s[i].length())); s[i].substring(1, s[i].length()));
}
else else
{
result.append(s[i]); result.append(s[i]);
}
} }
return result.toString(); return result.toString();
} }
@@ -2169,15 +2000,23 @@ public class Schema2XForms
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
{ {
if (element instanceof XSElementDeclaration) if (element instanceof XSElementDeclaration)
{
return this.createCaption((XSElementDeclaration)element, resourceBundle); return this.createCaption((XSElementDeclaration)element, resourceBundle);
}
if (element instanceof XSAttributeDeclaration) if (element instanceof XSAttributeDeclaration)
{
return this.createCaption((XSAttributeDeclaration)element, resourceBundle); return this.createCaption((XSAttributeDeclaration)element, resourceBundle);
}
if (element instanceof XSAttributeUse) if (element instanceof XSAttributeUse)
{
return this.createCaption((XSAttributeUse)element, resourceBundle); return this.createCaption((XSAttributeUse)element, resourceBundle);
}
LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: " else
+ element.getClass().getName()); {
return null; LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: "
+ element.getClass().getName());
return null;
}
} }
/** /**
@@ -2198,15 +2037,14 @@ public class Schema2XForms
final String caption, final String caption,
final XSTypeDefinition controlType) final XSTypeDefinition controlType)
{ {
Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":textarea"); NamespaceConstants.XFORMS_PREFIX + ":textarea");
this.setXFormsId(control); this.setXFormsId(control);
// control.setAttributeNS(Schema2XForms.CHIBA_NS, // control.setAttributeNS(Schema2XForms.CHIBA_NS,
// Schema2XForms.CHIBA_PREFIX + "height", // Schema2XForms.CHIBA_PREFIX + "height",
// "3"); // "3");
control.appendChild(this.createLabel(xformsDocument, caption)); control.appendChild(this.createLabel(xformsDocument, caption));
return control; return control;
} }
@@ -2310,6 +2148,7 @@ public class Schema2XForms
*/ */
public Element createControlForEnumerationType(final Document xformsDocument, public Element createControlForEnumerationType(final Document xformsDocument,
final XSSimpleTypeDefinition controlType, final XSSimpleTypeDefinition controlType,
final XSObject owner,
final String caption, final String caption,
final Element bindElement, final Element bindElement,
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
@@ -2326,20 +2165,23 @@ public class Schema2XForms
return null; return null;
} }
Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element control =
NamespaceConstants.XFORMS_PREFIX + ":select1"); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":select1");
this.setXFormsId(control); this.setXFormsId(control);
//label //label
control.appendChild(this.createLabel(xformsDocument, caption)); control.appendChild(this.createLabel(xformsDocument, caption));
Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":choices"); NamespaceConstants.XFORMS_PREFIX + ":choices");
this.setXFormsId(choices); this.setXFormsId(choices);
final XSObjectList mvFacets = controlType.getMultiValueFacets(); final XSObjectList mvFacets = controlType.getMultiValueFacets();
if (mvFacets.getLength() != 1) if (mvFacets.getLength() != 1)
{
throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType); throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType);
}
final XSObjectList annotations = final XSObjectList annotations =
((XSMultiValueFacet)mvFacets.item(0)).getAnnotations(); ((XSMultiValueFacet)mvFacets.item(0)).getAnnotations();
@@ -2354,43 +2196,43 @@ public class Schema2XForms
: null)); : null));
} }
String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI,
"appearance",
this.getAnnotation(owner),
resourceBundle);
if (appearance == null || appearance.length() == 0)
{
appearance = enumFacets.getLength() < Schema2XForms.LONG_LIST_SIZE ? "full" : "compact";
}
control.setAttributeNS(NamespaceConstants.XFORMS_NS, control.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance", NamespaceConstants.XFORMS_PREFIX + ":appearance",
(enumFacets.getLength() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)) appearance);
? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)
: getProperty(SELECTONE_UI_CONTROL_LONG_PROP)));
if (enumFacets.getLength() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) // add the "Please select..." instruction item for the combobox
{ // and set the isValid attribute on the bind element to check for the "Please select..."
// add the "Please select..." instruction item for the combobox // item to indicate that is not a valid value
// and set the isValid attribute on the bind element to check for the "Please select..." final String pleaseSelect = "[Select1 " + caption + "]";
// item to indicate that is not a valid value final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect);
// choices.appendChild(item);
final String pleaseSelect = "[Select1 " + caption + "]";
final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect); // not(purchaseOrder/state = '[Choose State]')
choices.appendChild(item); //String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')";
// ->no, not(. = '[Choose State]')
// not(purchaseOrder/state = '[Choose State]') final String isValidExpr = "not( . = '" + pleaseSelect + "')";
//String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')";
// ->no, not(. = '[Choose State]') //check if there was a constraint
final String isValidExpr = "not( . = '" + pleaseSelect + "')"; String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint");
//check if there was a constraint constraint = (constraint != null && constraint.length() != 0
String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint"); ? constraint + " and " + isValidExpr
: isValidExpr);
constraint = (constraint != null && constraint.length() != 0
? constraint + " and " + isValidExpr bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
: isValidExpr); NamespaceConstants.XFORMS_PREFIX + ":constraint",
constraint);
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":constraint",
constraint);
}
control.appendChild(choices); control.appendChild(choices);
this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle); this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle);
return control; return control;
} }
@@ -2415,6 +2257,7 @@ public class Schema2XForms
*/ */
public Element createControlForListType(final Document xformsDocument, public Element createControlForListType(final Document xformsDocument,
final XSSimpleTypeDefinition listType, final XSSimpleTypeDefinition listType,
final XSObject owner,
final String caption, final String caption,
final Element bindElement, final Element bindElement,
final ResourceBundle resourceBundle) final ResourceBundle resourceBundle)
@@ -2423,17 +2266,19 @@ public class Schema2XForms
final StringList enumFacets = controlType.getLexicalEnumeration(); final StringList enumFacets = controlType.getLexicalEnumeration();
if (enumFacets.getLength() <= 0) if (enumFacets.getLength() <= 0)
{
return null; return null;
}
Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":select"); NamespaceConstants.XFORMS_PREFIX + ":select");
this.setXFormsId(control); this.setXFormsId(control);
control.appendChild(this.createLabel(xformsDocument, caption)); control.appendChild(this.createLabel(xformsDocument, caption));
final XSObjectList mvFacets = controlType.getMultiValueFacets(); final XSObjectList mvFacets = controlType.getMultiValueFacets();
if (mvFacets.getLength() != 1) if (mvFacets.getLength() != 1)
{
throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType); throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType);
}
final XSObjectList annotations = final XSObjectList annotations =
((XSMultiValueFacet)mvFacets.item(0)).getAnnotations(); ((XSMultiValueFacet)mvFacets.item(0)).getAnnotations();
@@ -2453,19 +2298,23 @@ public class Schema2XForms
// Possibly look for special appInfo section in the schema and if not present default to checkBox... // Possibly look for special appInfo section in the schema and if not present default to checkBox...
// //
// For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control // For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control
// String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI,
"appearance",
this.getAnnotation(owner),
resourceBundle);
if (appearance == null || appearance.length() == 0)
{
appearance = enumValues.size() < Schema2XForms.LONG_LIST_SIZE ? "full" : "compact";
}
control.setAttributeNS(NamespaceConstants.XFORMS_NS, control.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":appearance", NamespaceConstants.XFORMS_PREFIX + ":appearance",
(enumValues.size() < Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP)) appearance);
? getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP) final Element choices =
: getProperty(SELECTMANY_UI_CONTROL_LONG_PROP))); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":choices");
NamespaceConstants.XFORMS_PREFIX + ":choices");
this.setXFormsId(choices); this.setXFormsId(choices);
control.appendChild(choices); control.appendChild(choices);
this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle); this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle);
return control; return control;
} }
@@ -2487,13 +2336,17 @@ public class Schema2XForms
{ {
final XSAnnotation annotation = this.getAnnotation(node); final XSAnnotation annotation = this.getAnnotation(node);
if (annotation == null) if (annotation == null)
{
return null; return null;
}
final String s = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI, final String s = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI,
"hint", "hint",
annotation, annotation,
resourceBundle); resourceBundle);
if (s == null) if (s == null)
{
return null; return null;
}
final Element hintElement = final Element hintElement =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":hint"); NamespaceConstants.XFORMS_PREFIX + ":hint");
@@ -2615,9 +2468,11 @@ public class Schema2XForms
? minConstraint ? minConstraint
: maxConstraint)); : maxConstraint));
if (constraint != null) if (constraint != null)
{
bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":constraint", NamespaceConstants.XFORMS_PREFIX + ":constraint",
constraint); constraint);
}
return bindElement; return bindElement;
} }
@@ -2873,13 +2728,11 @@ public class Schema2XForms
final Element rootGroup) final Element rootGroup)
{ {
Element submission = this.createSubmissionElement(xformsDocument, "submission-validate", true); Element submission =
this.createSubmissionElement(xformsDocument, "submission-validate", true);
modelSection.appendChild(submission); modelSection.appendChild(submission);
Element submit = this.createSubmitControl(xformsDocument, Element submit = this.createSubmitControl(xformsDocument, submission, "submit", "Submit");
submission,
"submit",
"Submit");
rootGroup.appendChild(submit); rootGroup.appendChild(submit);
submission = this.createSubmissionElement(xformsDocument, "submission-draft", false); submission = this.createSubmissionElement(xformsDocument, "submission-draft", false);
@@ -2896,13 +2749,15 @@ public class Schema2XForms
final String label, final String label,
final String value) final String value)
{ {
final Element item = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element item =
NamespaceConstants.XFORMS_PREFIX + ":item"); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":item");
this.setXFormsId(item); this.setXFormsId(item);
item.appendChild(this.createLabel(xformsDocument, label)); item.appendChild(this.createLabel(xformsDocument, label));
final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element e =
NamespaceConstants.XFORMS_PREFIX + ":value"); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":value");
this.setXFormsId(e); this.setXFormsId(e);
e.appendChild(xformsDocument.createTextNode(value)); e.appendChild(xformsDocument.createTextNode(value));
item.appendChild(e); item.appendChild(e);
@@ -2912,8 +2767,9 @@ public class Schema2XForms
private Element createLabel(final Document xformsDocument, private Element createLabel(final Document xformsDocument,
final String label) final String label)
{ {
final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, final Element e =
NamespaceConstants.XFORMS_PREFIX + ":label"); xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":label");
this.setXFormsId(e); this.setXFormsId(e);
e.appendChild(xformsDocument.createTextNode(label)); e.appendChild(xformsDocument.createTextNode(label));
return e; return e;

View File

@@ -660,12 +660,13 @@ public class XFormsBean
private static void rewriteInlineURIs(final Document schemaDocument, private static void rewriteInlineURIs(final Document schemaDocument,
final String cwdAvmPath) final String cwdAvmPath)
{ {
final NodeList includes = final NodeList nl =
schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include"); XMLUtil.combine(schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include"),
LOGGER.debug("rewriting " + includes.getLength() + " includes"); schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "import"));
for (int i = 0; i < includes.getLength(); i++) LOGGER.debug("rewriting " + nl.getLength() + " includes");
for (int i = 0; i < nl.getLength(); i++)
{ {
final Element includeEl = (Element)includes.item(i); final Element includeEl = (Element)nl.item(i);
if (includeEl.hasAttribute("schemaLocation")) if (includeEl.hasAttribute("schemaLocation"))
{ {
String uri = includeEl.getAttribute("schemaLocation"); String uri = includeEl.getAttribute("schemaLocation");

View File

@@ -0,0 +1,294 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1.5 $ -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:glob="http://apply.grants.gov/system/Global-V1.0" xmlns:att="http://apply.grants.gov/system/Attachments-V1.0" xmlns:globLib="http://apply.grants.gov/system/GlobalLibrary-V2.0" xmlns:RR_SF424="http://apply.grants.gov/forms/RR_SF424-V1.1" targetNamespace="http://apply.grants.gov/forms/RR_SF424-V1.1" elementFormDefault="qualified" attributeFormDefault="qualified" version="1.1">
<xs:import namespace="http://apply.grants.gov/system/GlobalLibrary-V2.0" schemaLocation="http://apply.grants.gov/system/schemas/GlobalLibrary-V2.0.xsd"/>
<xs:import namespace="http://apply.grants.gov/system/Global-V1.0" schemaLocation="http://apply.grants.gov/system/schemas/Global-V1.0.xsd"/>
<xs:import namespace="http://apply.grants.gov/system/Attachments-V1.0" schemaLocation="http://apply.grants.gov/system/schemas/Attachments-V1.0.xsd"/>
<xs:element name="RR_SF424">
<xs:complexType>
<xs:sequence>
<xs:element name="SubmissionTypeCode" type="RR_SF424:SubmissionTypeDataType"/>
<xs:element name="SubmittedDate" type="xs:date" minOccurs="0"/>
<xs:element name="ApplicantID" type="globLib:ApplicantIDDataType" minOccurs="0"/>
<xs:element name="StateReceivedDate" type="xs:date" minOccurs="0"/>
<xs:element name="StateID" type="globLib:StateIDDataType" minOccurs="0"/>
<xs:element name="FederalID" type="globLib:FederalIDDataType" minOccurs="0"/>
<xs:element name="ApplicantInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="OrganizationInfo" type="globLib:OrganizationDataType"/>
<xs:element name="ContactPersonInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="globLib:HumanNameDataType"/>
<xs:element name="Phone" type="globLib:TelephoneNumberDataType"/>
<xs:element name="Fax" type="globLib:TelephoneNumberDataType" minOccurs="0"/>
<xs:element name="Email" type="globLib:EmailDataType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployerID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="9"/>
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ApplicantType">
<xs:complexType>
<xs:sequence>
<xs:element name="ApplicantTypeCode" type="globLib:ApplicantTypeCodeDataType"/>
<xs:element name="ApplicantTypeCodeOtherExplanation" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="SmallBusinessOrganizationType" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="isWomenOwned" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="globLib:YesNoDataType"/>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="isSociallyEconomicallyDisadvantaged" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="globLib:YesNoDataType"/>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ApplicationType">
<xs:complexType>
<xs:sequence>
<xs:element name="ApplicationTypeCode" type="RR_SF424:ApplicationTypeCodeDataType"/>
<xs:element name="RevisionCode" type="RR_SF424:RevisionTypeCodeDataType" minOccurs="0"/>
<xs:element name="RevisionCodeOtherExplanation" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="45"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="isOtherAgencySubmission" type="globLib:YesNoDataType"/>
<xs:element name="OtherAgencySubmissionExplanation" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="FederalAgencyName" type="globLib:AgencyNameDataType"/>
<xs:element name="CFDANumber" type="globLib:CFDANumberDataType" minOccurs="0"/>
<xs:element name="ActivityTitle" type="globLib:ProgramActivityTitleDataType" minOccurs="0"/>
<xs:element name="ProjectTitle" type="globLib:ProjectTitleDataType"/>
<xs:element name="Location">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="45"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ProposedProjectPeriod">
<xs:complexType>
<xs:sequence>
<xs:element name="ProposedStartDate" type="xs:date"/>
<xs:element name="ProposedEndDate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CongressionalDistrict">
<xs:complexType>
<xs:sequence>
<xs:element name="ApplicantCongressionalDistrict" type="globLib:CongressionalDistrictDataType"/>
<xs:element name="ProjectCongressionalDistrict" type="globLib:CongressionalDistrictDataType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PDPIContactInfo" type="RR_SF424:OrganizationContactPersonDataType"/>
<xs:element name="EstimatedProjectFunding">
<xs:complexType>
<xs:sequence>
<xs:element name="TotalEstimatedAmount" type="globLib:BudgetTotalAmountDataType"/>
<xs:element name="TotalfedNonfedrequested" type="globLib:BudgetTotalAmountDataType"/>
<xs:element name="EstimatedProgramIncome" type="globLib:BudgetTotalAmountDataType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="StateReview">
<xs:complexType>
<xs:sequence>
<xs:element name="StateReviewCodeType" type="RR_SF424:StateReviewCodeTypeDataType"/>
<xs:element name="StateReviewDate" type="xs:date" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TrustAgree" type="globLib:YesNoDataType"/>
<xs:element name="AORInfo" type="RR_SF424:AORInfoType"/>
<xs:element name="PreApplicationAttachment" type="att:AttachedFileDataType" minOccurs="0"/>
<xs:element name="AdditionalCongressionalDistricts" type="att:AttachedFileDataType" minOccurs="0"/>
<xs:element name="AOR_Signature" type="globLib:SignatureDataType"/>
<xs:element name="AOR_SignedDate" type="xs:date"/>
</xs:sequence>
<xs:attribute name="FormVersion" type="globLib:FormVersionDataType" use="required" fixed="1.1"/>
</xs:complexType>
<!--
<xs:key name="ApplicantTypeCodeKey">
<xs:selector xpath="./RR_SF424:ApplicantType"/>
<xs:field xpath="RR_SF424:ApplicantTypeCode"/>
</xs:key>
<xs:keyref name="ApplicantTypeCodeOtherKeyRef" refer="RR_SF424:ApplicantTypeCodeKey">
<xs:selector xpath="./RR_SF424:ApplicantType/RR_SF424:ApplicantTypeCodeOtherExplanation"/>
<xs:field xpath="@ApplicantTypeCode"/>
</xs:keyref>
<xs:keyref name="ApplicantTypeCodeSmallBusinessKeyRef" refer="RR_SF424:ApplicantTypeCodeKey">
<xs:selector xpath="./RR_SF424:ApplicantType/RR_SF424:SmallBusinessOrganizationType"/>
<xs:field xpath="@ApplicantTypeCode"/>
</xs:keyref>
<xs:key name="ApplicationTypeCodeKey">
<xs:selector xpath="./RR_SF424:ApplicationType"/>
<xs:field xpath="RR_SF424:ApplicationTypeCode"/>
</xs:key>
<xs:keyref name="ApplicationTypeCodeKeyRef" refer="RR_SF424:ApplicationTypeCodeKey">
<xs:selector xpath="./RR_SF424:ApplicationType/RR_SF424:RevisionCode"/>
<xs:field xpath="@ApplicationTypeCode"/>
</xs:keyref>
<xs:key name="isOtherAgencySubmissionKey">
<xs:selector xpath="./RR_SF424:ApplicationType"/>
<xs:field xpath="RR_SF424:isOtherAgencySubmission"/>
</xs:key>
<xs:keyref name="isOtherAgencySubmissionKeyRef" refer="RR_SF424:isOtherAgencySubmissionKey">
<xs:selector xpath="./RR_SF424:ApplicationType/RR_SF424:OtherAgencySubmissionExplanation"/>
<xs:field xpath="@isOtherAgencySubmission"/>
</xs:keyref>
<xs:key name="StateReviewCodeTypeKey">
<xs:selector xpath="./RR_SF424:StateReview"/>
<xs:field xpath="RR_SF424:StateReviewCodeType"/>
</xs:key>
<xs:keyref name="StateReviewCodeTypeKeyRef" refer="RR_SF424:StateReviewCodeTypeKey">
<xs:selector xpath="./RR_SF424:StateReview/RR_SF424:StateReview"/>
<xs:field xpath="@StateReviewCodeType"/>
</xs:keyref>
-->
</xs:element>
<xs:simpleType name="SubmissionTypeDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="Preapplication"/>
<xs:enumeration value="Application"/>
<xs:enumeration value="Change/Corrected Application"/>
</xs:restriction>
</xs:simpleType>
<!--
<xs:simpleType name="ApplicantTypeCodeDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="A: State Government"/>
<xs:enumeration value="B: County Government"/>
<xs:enumeration value="C: City or Township Government"/>
<xs:enumeration value="D: Special District Governments"/>
<xs:enumeration value="E: Independent School District"/>
<xs:enumeration value="F: State-Controlled Institution of Higher Education"/>
<xs:enumeration value="G: Native American Tribal Government (Federally Recognized)"/>
<xs:enumeration value="H: Public/Indian Housing Authority"/>
<xs:enumeration value="I: Native American Tribal Organization (other than Federally recognized)"/>
<xs:enumeration value="J: Nonprofit with 501C3 IRS status (other than Institution of Higher Education)"/>
<xs:enumeration value="K: Nonprofit without 501C3 IRS status (other than Institution of Higher Education)"/>
<xs:enumeration value="L: Private Institution of Higher Education"/>
<xs:enumeration value="M: Individual"/>
<xs:enumeration value="N: For-profit Organization (other than small business)"/>
<xs:enumeration value="O: Small Business"/>
<xs:enumeration value="P: Other (specify)"/>
</xs:restriction>
</xs:simpleType>-->
<xs:simpleType name="ApplicationTypeCodeDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="New"/>
<xs:enumeration value="Resubmission"/>
<xs:enumeration value="Renewal"/>
<xs:enumeration value="Continuation"/>
<xs:enumeration value="Revision"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="RevisionTypeCodeDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
<xs:enumeration value="E"/>
<xs:enumeration value="AC"/>
<xs:enumeration value="AD"/>
<xs:enumeration value="BC"/>
<xs:enumeration value="BD"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="StateReviewCodeTypeDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="Y: Yes"/>
<xs:enumeration value="Program is not covered by E.O. 12372"/>
<xs:enumeration value="Program has not been selected by state for review"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="OrganizationContactPersonDataType">
<xs:sequence>
<xs:element name="Name" type="globLib:HumanNameDataType"/>
<xs:element name="Title" type="globLib:HumanTitleDataType" minOccurs="0"/>
<xs:element name="Address" type="globLib:AddressDataType"/>
<xs:element name="Phone" type="globLib:TelephoneNumberDataType"/>
<xs:element name="Fax" type="globLib:TelephoneNumberDataType" minOccurs="0"/>
<xs:element name="Email" type="globLib:EmailDataType"/>
<xs:element name="OrganizationName" type="globLib:OrganizationNameDataType"/>
<xs:element name="DepartmentName" type="globLib:DepartmentNameDataType" minOccurs="0"/>
<xs:element name="DivisionName" type="globLib:DivisionNameDataType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<!-- ================================================ -->
<!-- AORInfoType -->
<!-- The AORInfoType is a re-definition of the global -->
<!-- library's ContactPersonDataType. Restriction -->
<!-- based inheritence could not be used since each -->
<!-- element in the restricted derivation would have -->
<!-- a different namespace from the base type, making -->
<!-- it an entirely different element that cannot be -->
<!-- mapped back to its base particle. This violates -->
<!-- the schema specification for "Particle Derivation-->
<!-- OK (All:All,Sequence:Sequence - Recurse)" line -->
<!-- 2.1, for more information see the following link:-->
<!-- http://www.w3.org/TR/xmlschema-1/#rcase-Recurse -->
<!-- ================================================ -->
<xs:complexType name="AORInfoType">
<xs:sequence>
<xs:element name="Name" type="globLib:HumanNameDataType"/>
<xs:element name="Title" type="globLib:HumanTitleDataType"/>
<xs:element name="Address" type="globLib:AddressDataType"/>
<xs:element name="Phone" type="globLib:TelephoneNumberDataType"/>
<xs:element name="Fax" type="globLib:TelephoneNumberDataType" minOccurs="0"/>
<xs:element name="Email" type="globLib:EmailDataType"/>
<xs:element name="OrganizationName" type="globLib:OrganizationNameDataType"/>
<xs:element name="DepartmentName" type="globLib:DepartmentNameDataType" minOccurs="0"/>
<xs:element name="DivisionName" type="globLib:DivisionNameDataType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@@ -0,0 +1,214 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alf="http://www.alfresco.org"
elementFormDefault="qualified">
<xs:simpleType name="four_presidents">
<xs:restriction base="xs:string">
<xs:enumeration value="washington"/>
<xs:enumeration value="jefferson"/>
<xs:enumeration value="lincoln"/>
<xs:enumeration value="roosevelt1">
<xs:annotation>
<xs:appinfo><alf:label>Teddy Roosevelt</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="four_presidents_list">
<xs:list itemType="four_presidents"/>
</xs:simpleType>
<xs:simpleType name="thirteen_colonies">
<xs:restriction base="xs:string">
<xs:enumeration value="massachusetts"/>
<xs:enumeration value="NH">
<xs:annotation>
<xs:appinfo><alf:label>new hampshire</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="NY">
<xs:annotation>
<xs:appinfo><alf:label>new york</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="connecticut"/>
<xs:enumeration value="RI">
<xs:annotation>
<xs:appinfo><alf:label>rhode island</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="NJ">
<xs:annotation>
<xs:appinfo><alf:label>new jersey</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="delaware"/>
<xs:enumeration value="maryland"/>
<xs:enumeration value="pennsylvania"/>
<xs:enumeration value="virginia"/>
<xs:enumeration value="NC">
<xs:annotation>
<xs:appinfo><alf:label>north carolina</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="SC">
<xs:annotation>
<xs:appinfo><alf:label>south carolina</alf:label></xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="georgia"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="thirteen_colonies_list">
<xs:list itemType="thirteen_colonies"/>
</xs:simpleType>
<xs:element name="list-test">
<xs:complexType>
<xs:sequence>
<xs:element name="select1">
<xs:complexType>
<xs:sequence>
<xs:element name="four_items">
<xs:complexType>
<xs:sequence>
<xs:element name="full"
type="four_presidents"
default="jefferson"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>full</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="compact"
type="four_presidents"
default="roosevelt1"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>compact</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="default"
type="four_presidents"
default="jefferson"
minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ten_items">
<xs:complexType>
<xs:sequence>
<xs:element name="full"
type="thirteen_colonies"
minOccurs="1"
default="NY"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>full</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="compact"
type="thirteen_colonies"
default="NJ"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>compact</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="default"
type="thirteen_colonies"
default="NJ"
minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="select">
<xs:complexType>
<xs:sequence>
<xs:element name="four_items">
<xs:complexType>
<xs:sequence>
<xs:element name="full"
type="four_presidents_list"
default="jefferson"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>full</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="compact"
type="four_presidents_list"
default="jefferson"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>compact</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="default"
type="four_presidents_list"
default="jefferson"
minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ten_items">
<xs:complexType>
<xs:sequence>
<xs:element name="full"
type="thirteen_colonies_list"
minOccurs="1"
default="NJ"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>full</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="compact"
type="thirteen_colonies_list"
default="massachusetts"
minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alf:appearance>compact</alf:appearance>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="default"
type="thirteen_colonies_list"
default="maryland"
minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:othernsprefix="http://other.org/othernsuri"
elementFormDefault="qualified"
attributeFormDefault="qualified"
targetNamespace="http://other.org/othernsuri">
<xs:simpleType name="type1">
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mynsprefix="http://mine.org/mynsuri"
xmlns:othernsprefix="http://other.org/othernsuri"
elementFormDefault="qualified"
attributeFormDefault="qualified"
targetNamespace="http://mine.org/mynsuri">
<xs:import namespace="http://other.org/othernsuri" schemaLocation="/multi-namespace-test-other.xsd"/>
<xs:element name="multi-namespace-test">
<xs:complexType>
<xs:sequence>
<xs:element name="element_type_1" type="othernsprefix:type1"/>
</xs:sequence>
<xs:attribute name="attribute_type_1" type="othernsprefix:type1" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -94,7 +94,12 @@
<h:outputText value=""/> <h:outputText value=""/>
<h:outputText value="#{msg.form}:"/> <h:outputText value="#{msg.form}:"/>
<h:selectOneMenu value="#{WizardManager.bean.formName}" disabled="#{WizardManager.bean.formSelectDisabled}"> <h:selectOneMenu value="#{WizardManager.bean.formName}"
disabled="#{WizardManager.bean.formSelectDisabled}"
rendered="#{!empty WizardManager.bean.formChoices}">
<f:selectItems value="#{WizardManager.bean.formChoices}" /> <f:selectItems value="#{WizardManager.bean.formChoices}" />
</h:selectOneMenu> </h:selectOneMenu>
<h:outputText value="#{msg.sandbox_no_web_forms}"
style="font-style: italic"
rendered="#{empty WizardManager.bean.formChoices}"/>
</h:panelGrid> </h:panelGrid>

View File

@@ -457,6 +457,14 @@ dojo.declare("alfresco.xforms.Widget",
} }
}, },
/** Returns the value of the appearance attribute for widget */
getAppearance: function()
{
var result = (this.xformsNode.getAttribute("appearance") ||
this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":appearance"));
return result == null || result.length == 0 ? null : result;
},
/** Updates the display of the widget. This is intended to be overridden. */ /** Updates the display of the widget. This is intended to be overridden. */
_updateDisplay: function() _updateDisplay: function()
{ {
@@ -520,10 +528,10 @@ dojo.declare("alfresco.xforms.Widget",
/** The file picker widget which handles xforms widget xf:upload. */ /** The file picker widget which handles xforms widget xf:upload. */
dojo.declare("alfresco.xforms.FilePicker", dojo.declare("alfresco.xforms.FilePicker",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -583,10 +591,10 @@ dojo.declare("alfresco.xforms.FilePicker",
/** The textfield widget which handle xforms widget xf:input with any string or numerical type */ /** The textfield widget which handle xforms widget xf:input with any string or numerical type */
dojo.declare("alfresco.xforms.TextField", dojo.declare("alfresco.xforms.TextField",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -737,11 +745,11 @@ dojo.declare("alfresco.xforms.NumericalRange",
/** The textfield widget which handle xforms widget xf:textarea. */ /** The textfield widget which handle xforms widget xf:textarea. */
dojo.declare("alfresco.xforms.TextArea", dojo.declare("alfresco.xforms.TextArea",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
this.focused = false;
},
{ {
initializer: function(xform, xformsNode)
{
this.focused = false;
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// methods // methods
@@ -952,7 +960,7 @@ dojo.declare("alfresco.xforms.Select",
var initial_value = this.getInitialValue(); var initial_value = this.getInitialValue();
initial_value = initial_value ? initial_value.split(' ') : []; initial_value = initial_value ? initial_value.split(' ') : [];
this._selectedValues = []; this._selectedValues = [];
if (values.length <= 5) if (this.getAppearance() == "full")
{ {
this.widget = document.createElement("div"); this.widget = document.createElement("div");
this.widget.style.width = "100%"; this.widget.style.width = "100%";
@@ -1051,7 +1059,7 @@ dojo.declare("alfresco.xforms.Select",
{ {
if (event.target.options[i].selected) if (event.target.options[i].selected)
{ {
this._selectedValues.push(event.target.options[i].value); this._selectedValues.push(event.target.options[i].getAttribute("value"));
} }
} }
this._commitValueChange(); this._commitValueChange();
@@ -1060,12 +1068,12 @@ dojo.declare("alfresco.xforms.Select",
_checkbox_clickHandler: function(event) _checkbox_clickHandler: function(event)
{ {
this._selectedValues = []; this._selectedValues = [];
for (var i = 0; i < 5; i++) var all_checkboxes = this.widget.getElementsByTagName("input");
for (var i = 0; i < all_checkboxes.length; i++)
{ {
var checkbox = document.getElementById(this.id + "_" + i + "-widget"); if (all_checkboxes[i] && all_checkboxes[i].checked)
if (checkbox && checkbox.checked)
{ {
this._selectedValues.push(checkbox.value); this._selectedValues.push(all_checkboxes[i].getAttribute("value"));
} }
} }
this._commitValueChange(); this._commitValueChange();
@@ -1090,13 +1098,19 @@ dojo.declare("alfresco.xforms.Select1",
{ {
var values = this._getItemValues(); var values = this._getItemValues();
var initial_value = this.getInitialValue(); var initial_value = this.getInitialValue();
if (values.length <= 5) if (this.getAppearance() == "full")
{ {
this.widget = document.createElement("div"); this.widget = document.createElement("div");
this.widget.style.width = "100%"; this.widget.style.width = "100%";
attach_point.appendChild(this.widget); attach_point.appendChild(this.widget);
for (var i = 0; i < values.length; i++) for (var i = 0; i < values.length; i++)
{ {
if (!values[i].valid)
{
// always skip the invalid values for radios
continue;
}
var radio_div = document.createElement("div"); var radio_div = document.createElement("div");
radio_div.style.lineHeight = "16px"; radio_div.style.lineHeight = "16px";
this.widget.appendChild(radio_div); this.widget.appendChild(radio_div);
@@ -1273,10 +1287,10 @@ dojo.declare("alfresco.xforms.Checkbox",
/** The date picker widget which handles xforms widget xf:input with type xf:date */ /** The date picker widget which handles xforms widget xf:input with type xf:date */
dojo.declare("alfresco.xforms.DatePicker", dojo.declare("alfresco.xforms.DatePicker",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1363,10 +1377,10 @@ dojo.declare("alfresco.xforms.DatePicker",
/** The date picker widget which handles xforms widget xf:input with type xf:date */ /** The date picker widget which handles xforms widget xf:input with type xf:date */
dojo.declare("alfresco.xforms.TimePicker", dojo.declare("alfresco.xforms.TimePicker",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1438,10 +1452,10 @@ dojo.declare("alfresco.xforms.TimePicker",
/** The year picker handles xforms widget xf:input with a gYear type */ /** The year picker handles xforms widget xf:input with a gYear type */
dojo.declare("alfresco.xforms.YearPicker", dojo.declare("alfresco.xforms.YearPicker",
alfresco.xforms.TextField, alfresco.xforms.TextField,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1479,10 +1493,10 @@ dojo.declare("alfresco.xforms.YearPicker",
/** The day picker widget which handles xforms widget xf:input with type xf:gDay */ /** The day picker widget which handles xforms widget xf:input with type xf:gDay */
dojo.declare("alfresco.xforms.DayPicker", dojo.declare("alfresco.xforms.DayPicker",
alfresco.xforms.Select1, alfresco.xforms.Select1,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1506,10 +1520,10 @@ dojo.declare("alfresco.xforms.DayPicker",
/** The month picker widget which handles xforms widget xf:input with type xf:gMonth */ /** The month picker widget which handles xforms widget xf:input with type xf:gMonth */
dojo.declare("alfresco.xforms.MonthPicker", dojo.declare("alfresco.xforms.MonthPicker",
alfresco.xforms.Select1, alfresco.xforms.Select1,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1535,15 +1549,15 @@ dojo.declare("alfresco.xforms.MonthPicker",
/** The month day picker widget which handles xforms widget xf:input with type xf:gMonthDay */ /** The month day picker widget which handles xforms widget xf:input with type xf:gMonthDay */
dojo.declare("alfresco.xforms.MonthDayPicker", dojo.declare("alfresco.xforms.MonthDayPicker",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode);
this.monthPicker._compositeParent = this;
this.dayPicker = new alfresco.xforms.DayPicker(xform, xformsNode);
this.dayPicker._compositeParent = this;
},
{ {
initializer: function(xform, xformsNode)
{
this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode);
this.monthPicker._compositeParent = this;
this.dayPicker = new alfresco.xforms.DayPicker(xform, xformsNode);
this.dayPicker._compositeParent = this;
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1575,15 +1589,15 @@ dojo.declare("alfresco.xforms.MonthDayPicker",
/** The year month picker widget which handles xforms widget xf:input with type xf:gYearMonth */ /** The year month picker widget which handles xforms widget xf:input with type xf:gYearMonth */
dojo.declare("alfresco.xforms.YearMonthPicker", dojo.declare("alfresco.xforms.YearMonthPicker",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
this.yearPicker = new alfresco.xforms.YearPicker(xform, xformsNode);
this.yearPicker._compositeParent = this;
this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode);
this.monthPicker._compositeParent = this;
},
{ {
initializer: function(xform, xformsNode)
{
this.yearPicker = new alfresco.xforms.YearPicker(xform, xformsNode);
this.yearPicker._compositeParent = this;
this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode);
this.monthPicker._compositeParent = this;
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
@@ -1625,23 +1639,17 @@ dojo.declare("alfresco.xforms.YearMonthPicker",
*/ */
dojo.declare("alfresco.xforms.Group", dojo.declare("alfresco.xforms.Group",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
this._children = [];
dojo.html.removeClass(this.domNode, "xformsItem");
},
{ {
initializer: function(xform, xformsNode)
{
this._children = [];
dojo.html.removeClass(this.domNode, "xformsItem");
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// methods & properties // methods & properties
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/** Returns the value of the appearance attribute for widget */ _groupHeaderNode: null,
getAppearance: function()
{
return (this.xformsNode.getAttribute("appearance") ||
this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":appearance"));
},
/** Returns the child at the specified index or null if the index is out of range. */ /** Returns the child at the specified index or null if the index is out of range. */
getChildAt: function(index) getChildAt: function(index)
@@ -1704,11 +1712,38 @@ dojo.declare("alfresco.xforms.Group",
this._children.splice(position, 0, child); this._children.splice(position, 0, child);
} }
if (this.getAppearance() == "full" && function shouldInsertDivider(group, child, position)
!(this instanceof alfresco.xforms.Repeat) && {
child.isVisible() && if (group.getAppearance() != "full")
((child instanceof alfresco.xforms.Group && position != 0) || {
this._children[position - 1] instanceof alfresco.xforms.Group)) return false;
}
if (group instanceof alfresco.xforms.Repeat)
{
return false;
}
if (!child.isVisible())
{
return false;
}
if (group._children[position - 1] instanceof alfresco.xforms.Group)
{
return true;
}
if (child instanceof alfresco.xforms.Group)
{
for (var i = position - 1; i > 0; i--)
{
if (group._children[i].isVisible())
{
return true;
}
}
}
return false;
}
if (shouldInsertDivider(this, child, position))
{ {
var divider = document.createElement("div"); var divider = document.createElement("div");
dojo.html.setClass(divider, "xformsGroupDivider"); dojo.html.setClass(divider, "xformsGroupDivider");
@@ -1898,13 +1933,13 @@ dojo.declare("alfresco.xforms.Group",
attach_point.offsetWidth)) * 100 + "%"; attach_point.offsetWidth)) * 100 + "%";
} }
this.groupHeaderNode = document.createElement("div"); this._groupHeaderNode = document.createElement("div");
this.groupHeaderNode.id = this.id + "-groupHeaderNode"; this._groupHeaderNode.setAttribute("id", this.id + "-groupHeaderNode");
dojo.html.setClass(this.groupHeaderNode, "xformsGroupHeader"); dojo.html.setClass(this._groupHeaderNode, "xformsGroupHeader");
this.domNode.appendChild(this.groupHeaderNode); this.domNode.appendChild(this._groupHeaderNode);
this.toggleExpandedImage = document.createElement("img"); this.toggleExpandedImage = document.createElement("img");
this.groupHeaderNode.appendChild(this.toggleExpandedImage); this._groupHeaderNode.appendChild(this.toggleExpandedImage);
this.toggleExpandedImage.setAttribute("src", alfresco_xforms_constants.EXPANDED_IMAGE.src); this.toggleExpandedImage.setAttribute("src", alfresco_xforms_constants.EXPANDED_IMAGE.src);
this.toggleExpandedImage.align = "absmiddle"; this.toggleExpandedImage.align = "absmiddle";
this.toggleExpandedImage.style.marginLeft = "5px"; this.toggleExpandedImage.style.marginLeft = "5px";
@@ -1915,7 +1950,7 @@ dojo.declare("alfresco.xforms.Group",
this, this,
this._toggleExpanded_clickHandler); this._toggleExpanded_clickHandler);
this.groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); this._groupHeaderNode.appendChild(document.createTextNode(this.getLabel()));
} }
attach_point.appendChild(this.domNode); attach_point.appendChild(this.domNode);
@@ -2037,17 +2072,86 @@ dojo.declare("alfresco.xforms.SwitchGroup",
alfresco.xforms.Group, alfresco.xforms.Group,
function(xform, xformsNode) function(xform, xformsNode)
{ {
this.selectedCaseId = null; if (this.getInitialValue())
var widgets = this.xform.getBinding(this.xformsNode).widgets;
for (var i in widgets)
{ {
if (widgets[i] instanceof alfresco.xforms.Select1) var initialValueTrigger = this._getCaseToggleTriggerByTypeValue(this.getInitialValue());
{ this._selectedCaseId = initialValueTrigger.getActions()["toggle"].properties["case"];
widgets[i].setValue(this.getInitialValue(), "true");
}
} }
}, },
{ {
/////////////////////////////////////////////////////////////////
// methods & properties
/////////////////////////////////////////////////////////////////
_getCaseToggleTriggers: function()
{
var bw = this.xform.getBinding(this.xformsNode).widgets;
var result = [];
for (var i in bw)
{
if (! (bw[i] instanceof alfresco.xforms.Trigger))
{
continue;
}
var action = bw[i].getActions()["toggle"];
if (action)
{
result.push(bw[i]);
}
}
return result;
},
_getCaseToggleTriggerByCaseId: function(caseId)
{
var bw = this.xform.getBinding(this.xformsNode).widgets;
for (var i in bw)
{
if (! (bw[i] instanceof alfresco.xforms.Trigger))
{
continue;
}
var action = bw[i].getActions()["toggle"];
if (!action)
{
continue;
}
if (action.properties["case"] == caseId)
{
return bw[i];
}
}
throw new Error("unable to find trigger " + type +
", properties " + properties +
" for " + this.id);
},
_getCaseToggleTriggerByTypeValue: function(typeValue)
{
var bw = this.xform.getBinding(this.xformsNode).widgets;
for (var i in bw)
{
if (! (bw[i] instanceof alfresco.xforms.Trigger))
{
continue;
}
var action = bw[i].getActions()["setvalue"];
if (!action)
{
continue;
}
if (action.properties["value"] == typeValue)
{
return bw[i];
}
}
throw new Error("unable to find toggle trigger for type value " + typeValue +
" for " + this.id);
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods & properties // overridden methods & properties
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -2057,15 +2161,43 @@ dojo.declare("alfresco.xforms.SwitchGroup",
{ {
var childDomContainer = var childDomContainer =
alfresco.xforms.SwitchGroup.superclass._insertChildAt.call(this, child, position); alfresco.xforms.SwitchGroup.superclass._insertChildAt.call(this, child, position);
this.selectedCaseId = this.selectedCaseId || child.id; if (child.id == this._selectedCaseId)
if (this.selectedCaseId != child.id) {
this._getCaseToggleTriggerByCaseId(this._selectedCaseId).fire();
}
else
{ {
childDomContainer.style.display = "none"; childDomContainer.style.display = "none";
} }
return childDomContainer; return childDomContainer;
}, },
render: function(attach_point)
{
alfresco.xforms.SwitchGroup.superclass.render.call(this, attach_point);
this._groupHeaderNode = document.createElement("div");
this._groupHeaderNode.setAttribute("id", this.id + "-groupHeaderNode");
this.domNode.appendChild(this._groupHeaderNode);
this._groupHeaderNode.style.backgroundColor = "orange";
var cases = this._getCaseToggleTriggers();
for (var i = 0; i < cases.length; i++)
{
var d = document.createElement("div");
this._groupHeaderNode.appendChild(d);
var link = document.createElement("a");
link.setAttribute("id", cases[i].id);
link.trigger = cases[i];
link.appendChild(document.createTextNode(cases[i].getLabel()));
d.appendChild(link);
dojo.event.browser.addListener(link,
"onclick",
function(event)
{
event.target.trigger.fire();
});
}
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// XForms event handlers // XForms event handlers
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -2091,6 +2223,15 @@ dojo.declare("alfresco.xforms.SwitchGroup",
} }
}); });
/** */
dojo.declare("alfresco.xforms.CaseGroup",
alfresco.xforms.Group,
function(xform, xformsNode)
{
},
{
});
/** /**
* Handles xforms widget xf:group for the root group. Does some special rendering * Handles xforms widget xf:group for the root group. Does some special rendering
* to present a title rather than a group header. * to present a title rather than a group header.
@@ -2109,18 +2250,18 @@ dojo.declare("alfresco.xforms.ViewRoot",
this.domNode.style.width = "100%"; this.domNode.style.width = "100%";
dojo.html.setClass(this.domNode, "xformsViewRoot"); dojo.html.setClass(this.domNode, "xformsViewRoot");
this.groupHeaderNode = document.createElement("div"); this._groupHeaderNode = document.createElement("div");
this.groupHeaderNode.id = this.id + "-groupHeaderNode"; this._groupHeaderNode.id = this.id + "-groupHeaderNode";
dojo.html.setClass(this.groupHeaderNode, "xformsViewRootHeader"); dojo.html.setClass(this._groupHeaderNode, "xformsViewRootHeader");
this.domNode.appendChild(this.groupHeaderNode); this.domNode.appendChild(this._groupHeaderNode);
var icon = document.createElement("img"); var icon = document.createElement("img");
this.groupHeaderNode.appendChild(icon); this._groupHeaderNode.appendChild(icon);
icon.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/file_large.gif"); icon.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/file_large.gif");
icon.align = "absmiddle"; icon.align = "absmiddle";
icon.style.marginLeft = "5px"; icon.style.marginLeft = "5px";
icon.style.marginRight = "5px"; icon.style.marginRight = "5px";
this.groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); this._groupHeaderNode.appendChild(document.createTextNode(this.getLabel()));
attach_point.appendChild(this.domNode); attach_point.appendChild(this.domNode);
this.domNode.childContainerNode = document.createElement("div"); this.domNode.childContainerNode = document.createElement("div");
@@ -2211,8 +2352,8 @@ dojo.declare("alfresco.xforms.Repeat",
continue; continue;
} }
var action = bw[i].getAction(); var action = bw[i].getActions()[type];
if (action.getType() != type) if (!action)
{ {
continue; continue;
} }
@@ -2432,10 +2573,10 @@ dojo.declare("alfresco.xforms.Repeat",
// clear the border bottom for the group header since we'll be getting it // clear the border bottom for the group header since we'll be getting it
// from the repeat item border // from the repeat item border
this.groupHeaderNode.style.borderBottomWidth = "0px"; this._groupHeaderNode.style.borderBottomWidth = "0px";
this.groupHeaderNode.repeat = this; this._groupHeaderNode.repeat = this;
dojo.event.connect(this.groupHeaderNode, "onclick", function(event) dojo.event.connect(this._groupHeaderNode, "onclick", function(event)
{ {
if (event.target == event.currentTarget) if (event.target == event.currentTarget)
{ {
@@ -2445,7 +2586,7 @@ dojo.declare("alfresco.xforms.Repeat",
this.headerInsertRepeatItemImage = document.createElement("img"); this.headerInsertRepeatItemImage = document.createElement("img");
this.headerInsertRepeatItemImage.repeat = this; this.headerInsertRepeatItemImage.repeat = this;
this.groupHeaderNode.appendChild(this.headerInsertRepeatItemImage); this._groupHeaderNode.appendChild(this.headerInsertRepeatItemImage);
this.headerInsertRepeatItemImage.setAttribute("src", this.headerInsertRepeatItemImage.setAttribute("src",
alfresco_xforms_constants.WEBAPP_CONTEXT + alfresco_xforms_constants.WEBAPP_CONTEXT +
"/images/icons/plus.gif"); "/images/icons/plus.gif");
@@ -2469,14 +2610,14 @@ dojo.declare("alfresco.xforms.Repeat",
(this.getViewRoot().focusedRepeat == this || (this.getViewRoot().focusedRepeat == this ||
this.getViewRoot().focusedRepeat.isAncestorOf(this))) this.getViewRoot().focusedRepeat.isAncestorOf(this)))
{ {
if (!dojo.html.hasClass(this.groupHeaderNode, "xformsRepeatFocusedHeader")) if (!dojo.html.hasClass(this._groupHeaderNode, "xformsRepeatFocusedHeader"))
{ {
dojo.html.addClass(this.groupHeaderNode, "xformsRepeatFocusedHeader"); dojo.html.addClass(this._groupHeaderNode, "xformsRepeatFocusedHeader");
} }
} }
else if (dojo.html.hasClass(this.groupHeaderNode, "xformsRepeatFocusedHeader")) else if (dojo.html.hasClass(this._groupHeaderNode, "xformsRepeatFocusedHeader"))
{ {
dojo.html.removeClass(this.groupHeaderNode, "xformsRepeatFocusedHeader"); dojo.html.removeClass(this._groupHeaderNode, "xformsRepeatFocusedHeader");
} }
for (var i = 0; i < this._children.length; i++) for (var i = 0; i < this._children.length; i++)
@@ -2533,7 +2674,7 @@ dojo.declare("alfresco.xforms.Repeat",
var repeatItem = repeat.getChildAt(index); var repeatItem = repeat.getChildAt(index);
this.setFocusedChild(repeatItem); this.setFocusedChild(repeatItem);
var trigger = this._getRepeatItemTrigger("insert", { position: "after" }); var trigger = this._getRepeatItemTrigger("insert", { position: "after" });
this.xform.fireAction(trigger.id); trigger.fire();
} }
}, },
@@ -2551,7 +2692,7 @@ dojo.declare("alfresco.xforms.Repeat",
{ {
this.setFocusedChild(null); this.setFocusedChild(null);
var trigger = this._getRepeatItemTrigger("insert", { position: "before" }); var trigger = this._getRepeatItemTrigger("insert", { position: "before" });
this.xform.fireAction(trigger.id); trigger.fire();
} }
} }
}, },
@@ -2570,7 +2711,7 @@ dojo.declare("alfresco.xforms.Repeat",
var repeatItem = repeat.getChildAt(index); var repeatItem = repeat.getChildAt(index);
this.setFocusedChild(repeatItem); this.setFocusedChild(repeatItem);
var trigger = this._getRepeatItemTrigger("delete", {}); var trigger = this._getRepeatItemTrigger("delete", {});
this.xform.fireAction(trigger.id); trigger.fire();
} }
}, },
@@ -2666,24 +2807,44 @@ dojo.declare("alfresco.xforms.Repeat",
*/ */
dojo.declare("alfresco.xforms.Trigger", dojo.declare("alfresco.xforms.Trigger",
alfresco.xforms.Widget, alfresco.xforms.Widget,
function(xform, xformsNode)
{
},
{ {
initializer: function(xform, xformsNode)
{
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// methods & properties // methods & properties
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/** TODO: DOCUMENT */ /** TODO: DOCUMENT */
getAction: function() getActions: function()
{ {
var action = _getElementsByTagNameNS(this.xformsNode, if (typeof this._actions == "undefined")
alfresco_xforms_constants.XFORMS_NS, {
alfresco_xforms_constants.XFORMS_PREFIX, var actionNode = _getElementsByTagNameNS(this.xformsNode,
"action")[0]; alfresco_xforms_constants.XFORMS_NS,
return new alfresco.xforms.XFormsAction(this.xform, dojo.dom.firstElement(action)); alfresco_xforms_constants.XFORMS_PREFIX,
}, "action")[0];
this._actions = {};
for (var i = 0; i < actionNode.childNodes.length; i++)
{
if (actionNode.childNodes[i].nodeType != dojo.dom.ELEMENT_NODE)
{
continue;
}
var a = new alfresco.xforms.XFormsAction(this.xform, actionNode.childNodes[i]);
this._actions[a.getType()] = a;
}
}
return this._actions;
},
/** fires the xforms action associated with the trigger */
fire: function()
{
this.xform.fireAction(this.id);
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// overridden methods // overridden methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -2717,7 +2878,7 @@ dojo.declare("alfresco.xforms.Trigger",
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
_clickHandler: function(event) _clickHandler: function(event)
{ {
this.xform.fireAction(this.id); this.fire();
} }
}); });
@@ -2726,53 +2887,53 @@ dojo.declare("alfresco.xforms.Trigger",
*/ */
dojo.declare("alfresco.xforms.Submit", dojo.declare("alfresco.xforms.Submit",
alfresco.xforms.Trigger, alfresco.xforms.Trigger,
function(xform, xformsNode)
{ {
initializer: function(xform, xformsNode) var submit_buttons = (this.id == "submit"
? _xforms_getSubmitButtons()
: (this.id == "save-draft"
? _xforms_getSaveDraftButtons()
: null));
if (submit_buttons == null)
{ {
var submit_buttons = (this.id == "submit" throw new Error("unknown submit button " + this.id);
? _xforms_getSubmitButtons() }
: (this.id == "save-draft" for (var i = 0; i < submit_buttons.length; i++)
? _xforms_getSaveDraftButtons() {
: null)); dojo.debug("adding submit handler for " + submit_buttons[i].getAttribute('id'));
if (submit_buttons == null) submit_buttons[i].widget = this;
{ dojo.event.browser.addListener(submit_buttons[i],
throw new Error("unknown submit button " + this.id); "onclick",
} function(event)
for (var i = 0; i < submit_buttons.length; i++) {
{ if (!event.target.widget)
dojo.debug("adding submit handler for " + submit_buttons[i].getAttribute('id'));
submit_buttons[i].widget = this;
dojo.event.browser.addListener(submit_buttons[i],
"onclick",
function(event)
{ {
if (!event.target.widget) return true;
{ }
return true;
} var xform = event.target.widget.xform;
if (xform.submitWidget && xform.submitWidget.done)
var xform = event.target.widget.xform; {
if (xform.submitWidget && xform.submitWidget.done) dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id);
{ xform.submitWidget.currentButton = null;
dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id); xform.submitWidget = null;
xform.submitWidget.currentButton = null; return true;
xform.submitWidget = null; }
return true; else
} {
else dojo.debug("triggering submit from handler " + event.target.id);
{ dojo.event.browser.stopEvent(event);
dojo.debug("triggering submit from handler " + event.target.id); _hide_errors();
dojo.event.browser.stopEvent(event); xform.submitWidget = event.target.widget;
_hide_errors(); xform.submitWidget.currentButton = event.target;
xform.submitWidget = event.target.widget; xform.submitWidget.widget.buttonClick();
xform.submitWidget.currentButton = event.target; return false;
xform.submitWidget.widget.buttonClick(); }
return false; },
} false);
}, }
false); },
} {
},
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// DOM event handlers // DOM event handlers
@@ -2782,7 +2943,7 @@ dojo.declare("alfresco.xforms.Submit",
{ {
this.done = false; this.done = false;
_hide_errors(); _hide_errors();
this.xform.fireAction(this.id); this.fire();
} }
}); });
@@ -2791,24 +2952,27 @@ dojo.declare("alfresco.xforms.Submit",
*/ */
dojo.declare("alfresco.xforms.XFormsAction", dojo.declare("alfresco.xforms.XFormsAction",
null, null,
function(xform, xformsNode)
{ {
initializer: function(xform, xformsNode) this.xform = xform;
this.xformsNode = xformsNode;
/** All properties of the action as map of key value pairs */
this.properties = [];
for (var i = 0; i < this.xformsNode.attributes.length; i++)
{ {
this.xform = xform; var attr = this.xformsNode.attributes[i];
this.xformsNode = xformsNode; if (attr.nodeName.match(new RegExp("^" + alfresco_xforms_constants.XFORMS_PREFIX + ":")))
/** All properties of the action as map of key value pairs */
this.properties = [];
for (var i = 0; i < this.xformsNode.attributes.length; i++)
{ {
var attr = this.xformsNode.attributes[i]; this.properties[attr.nodeName.substring((alfresco_xforms_constants.XFORMS_PREFIX + ":").length)] =
if (attr.nodeName.match(new RegExp("^" + alfresco_xforms_constants.XFORMS_PREFIX + ":"))) attr.nodeValue;
{
this.properties[attr.nodeName.substring((alfresco_xforms_constants.XFORMS_PREFIX + ":").length)] =
attr.nodeValue;
}
} }
}, }
if (this.getType() == "setvalue" && !this.properties["value"])
{
this.properties["value"] = this.xformsNode.firstChild.nodeValue;
}
},
{
/** Returns the action type. */ /** Returns the action type. */
getType: function() getType: function()
{ {
@@ -2826,20 +2990,22 @@ dojo.declare("alfresco.xforms.XFormsAction",
*/ */
dojo.declare("alfresco.xforms.XFormsEvent", dojo.declare("alfresco.xforms.XFormsEvent",
null, null,
function(node)
{ {
initializer: function(node) this.type = node.nodeName;
this.targetId = node.getAttribute("targetId");
this.targetName = node.getAttribute("targetName");
this.properties = {};
for (var i = 0; i < node.childNodes.length; i++)
{ {
this.type = node.nodeName; if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
this.targetId = node.getAttribute("targetId");
this.targetName = node.getAttribute("targetName");
this.properties = {};
for (var i = 0; i < node.childNodes.length; i++)
{ {
if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) this.properties[node.childNodes[i].getAttribute("name")] =
this.properties[node.childNodes[i].getAttribute("name")] = node.childNodes[i].getAttribute("value");
node.childNodes[i].getAttribute("value");
} }
}, }
},
{
/** Returns the widget managing the specified target id. */ /** Returns the widget managing the specified target id. */
getTarget: function() getTarget: function()
{ {
@@ -2857,35 +3023,34 @@ dojo.declare("alfresco.xforms.XFormsEvent",
*/ */
dojo.declare("alfresco.xforms.Binding", dojo.declare("alfresco.xforms.Binding",
null, null,
function(xformsNode, parent)
{
this.xformsNode = xformsNode;
this.id = this.xformsNode.getAttribute("id");
this.nodeset = this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":nodeset");
this._readonly =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":readonly")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") == "true()"
: null);
this._required =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":required")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":required") == "true()"
: null);
this._type =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":type")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":type")
: null);
this.constraint =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":constraint")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":constraint")
: null);
this.maximum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":maximum"));
this.minimum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":minimum"));
this.parent = parent;
this.widgets = {};
},
{ {
initializer: function(xformsNode, parent)
{
this.xformsNode = xformsNode;
this.id = this.xformsNode.getAttribute("id");
this.nodeset = this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":nodeset");
this._readonly =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":readonly")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") == "true()"
: null);
this._required =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":required")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":required") == "true()"
: null);
this._type =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":type")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":type")
: null);
this.constraint =
(_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":constraint")
? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":constraint")
: null);
this.maximum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":maximum"));
this.minimum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":minimum"));
this.parent = parent;
this.widgets = {};
},
/** Returns the expected schema type for this binding. */ /** Returns the expected schema type for this binding. */
getType: function() getType: function()
{ {
@@ -2923,24 +3088,23 @@ dojo.declare("alfresco.xforms.Binding",
*/ */
dojo.declare("alfresco.xforms.XForm", dojo.declare("alfresco.xforms.XForm",
null, null,
/** Makes a request to the XFormsBean to load the xforms document. */
function()
{
var req = AjaxHelper.createRequest(this,
"getXForm",
{},
function(type, data, evt)
{
this.target._loadHandler(data);
});
AjaxHelper.sendRequest(req);
},
{ {
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Initialization // Initialization
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/** Makes a request to the XFormsBean to load the xforms document. */
initializer: function()
{
var req = AjaxHelper.createRequest(this,
"getXForm",
{},
function(type, data, evt)
{
this.target._loadHandler(data);
});
AjaxHelper.sendRequest(req);
},
/** Parses the xforms document and produces the widget tree. */ /** Parses the xforms document and produces the widget tree. */
_loadHandler: function(xformDocument) _loadHandler: function(xformDocument)
{ {
@@ -3074,8 +3238,7 @@ dojo.declare("alfresco.xforms.XForm",
case alfresco_xforms_constants.XFORMS_PREFIX + ":switch": case alfresco_xforms_constants.XFORMS_PREFIX + ":switch":
return new alfresco.xforms.SwitchGroup(this, xformsNode); return new alfresco.xforms.SwitchGroup(this, xformsNode);
case alfresco_xforms_constants.XFORMS_PREFIX + ":case": case alfresco_xforms_constants.XFORMS_PREFIX + ":case":
return new alfresco.xforms.Group(this, xformsNode); return new alfresco.xforms.CaseGroup(this, xformsNode);
default: default:
throw new Error("unknown type " + xformsNode.nodeName); throw new Error("unknown type " + xformsNode.nodeName);
} }
@@ -3086,26 +3249,27 @@ dojo.declare("alfresco.xforms.XForm",
{ {
for (var i = 0; i < xformsNode.childNodes.length; i++) for (var i = 0; i < xformsNode.childNodes.length; i++)
{ {
if (xformsNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) if (xformsNode.childNodes[i].nodeType != dojo.dom.ELEMENT_NODE)
{ {
dojo.debug("loading " + xformsNode.childNodes[i].nodeName + continue;
" into " + parentWidget.id); }
if (xformsNode.childNodes[i].getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + dojo.debug("loading " + xformsNode.childNodes[i].nodeName +
":prototype") == "true") " into " + parentWidget.id);
if (xformsNode.childNodes[i].getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX +
":prototype") == "true")
{
dojo.debug(xformsNode.childNodes[i].getAttribute("id") +
" is a prototype, ignoring");
continue;
}
var w = this.createWidget(xformsNode.childNodes[i]);
if (w != null)
{
dojo.debug("created " + w.id + " for " + xformsNode.childNodes[i].nodeName);
parentWidget.addChild(w);
if (w instanceof alfresco.xforms.Group)
{ {
dojo.debug(xformsNode.childNodes[i].getAttribute("id") + this.loadWidgets(xformsNode.childNodes[i], w);
" is a prototype, ignoring");
continue;
}
var w = this.createWidget(xformsNode.childNodes[i]);
if (w != null)
{
dojo.debug("created " + w.id + " for " + xformsNode.childNodes[i].nodeName);
parentWidget.addChild(w);
if (w instanceof alfresco.xforms.Group)
{
this.loadWidgets(xformsNode.childNodes[i], w);
}
} }
} }
} }