- adding support for alerts

- allowing overriding of label and specification of alert using xs:appinfo and inner alfresco:label, alfresco:alert tags. 



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4027 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-05 05:55:22 +00:00
parent 54ac87ef6b
commit e8643d2003
5 changed files with 3219 additions and 3139 deletions

View File

@@ -182,6 +182,17 @@ public class SchemaFormBuilder
*/ */
public static final String XFORMS_NS_PREFIX = "xforms:"; public static final String XFORMS_NS_PREFIX = "xforms:";
/**
* Alfresco namespace declaration.
*/
public static final String ALFRESCO_NS =
"http://www.alfresco.org/alfresco";
/**
* Alfresco prefix
*/
public static final String ALFRESCO_NS_PREFIX = "alfresco:";
/** /**
* Chiba namespace declaration. * Chiba namespace declaration.
*/ */
@@ -914,30 +925,9 @@ public class SchemaFormBuilder
return result; return result;
} }
/** private String extractPropertyFromAnnotation(final String namespace,
* __UNDOCUMENTED__ final String elementName,
*
* @param xForm __UNDOCUMENTED__
* @param annotation __UNDOCUMENTED__
* @return __UNDOCUMENTED__
*/
protected Element addHintFromDocumentation(final Document xForm,
final XSAnnotation annotation) final XSAnnotation annotation)
{
if (annotation == null)
return null;
final Text text = this.extractDocumentation(annotation);
if (text == null)
return null;
final Element hintElement =
xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "hint");
this.setXFormsId(hintElement);
hintElement.appendChild(xForm.importNode(text, true));
return hintElement;
}
private Text extractDocumentation(final XSAnnotation annotation)
{ {
if (annotation == null) if (annotation == null)
return null; return null;
@@ -945,22 +935,15 @@ public class SchemaFormBuilder
final Document doc = DOMUtil.newDocument(true, false); final Document doc = DOMUtil.newDocument(true, false);
annotation.writeAnnotation(doc, XSAnnotation.W3C_DOM_DOCUMENT); annotation.writeAnnotation(doc, XSAnnotation.W3C_DOM_DOCUMENT);
final NodeList d = doc.getElementsByTagNameNS(SchemaFormBuilder.XMLSCHEMA_NS, final NodeList d = doc.getElementsByTagNameNS(namespace, elementName);
"documentation");
if (d.getLength() == 0) if (d.getLength() == 0)
return null; return null;
if (d.getLength() > 1)
final Text result = doc.createTextNode(""); LOGGER.warn("expect exactly one value for " + namespace +
":" + elementName +
for (int i = 0; i < d.getLength(); i++) ". found " + d.getLength());
{ final String result = DOMUtil.getTextNodeAsString(d.item(0));
//get text value LOGGER.debug(namespace + ":" + elementName + " = " + result);
final String text = DOMUtil.getTextNodeAsString((Element)d.item(i));
result.appendData(text);
if (i < d.getLength() - 1)
result.appendData(" ");
}
return result; return result;
} }
@@ -2267,6 +2250,9 @@ public class SchemaFormBuilder
LOGGER.debug("addSimpleType for " + controlType.getName() + LOGGER.debug("addSimpleType for " + controlType.getName() +
" (owningElementName=" + owningElementName + ")"); " (owningElementName=" + owningElementName + ")");
if (owner != null)
LOGGER.debug("*************** owner is " + owner.getClass() +
" name is " + owner.getName() + " ****************");
// create the <xforms:bind> element and add it to the model. // create the <xforms:bind> element and add it to the model.
Element bindElement = xForm.createElementNS(XFORMS_NS, Element bindElement = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); SchemaFormBuilder.XFORMS_NS_PREFIX + "bind");
@@ -2322,10 +2308,12 @@ public class SchemaFormBuilder
bindId = bindId2; bindId = bindId2;
} }
String caption = createCaption(owningElementName); final String caption = owner != null ? createCaption(owner) : createCaption(owningElementName);
Element formControl = this.createFormControl(xForm, Element formControl = this.createFormControl(xForm,
schema,
caption, caption,
controlType, controlType,
owner,
bindId, bindId,
bindElement, bindElement,
o); o);
@@ -2638,8 +2626,10 @@ public class SchemaFormBuilder
} }
private Element createFormControl(final Document xForm, private Element createFormControl(final Document xForm,
final XSModel schema,
final String caption, final String caption,
final XSTypeDefinition controlType, final XSTypeDefinition controlType,
final XSObject owner,
final String bindId, final String bindId,
final Element bindElement, final Element bindElement,
final Occurs o) final Occurs o)
@@ -2703,20 +2693,22 @@ public class SchemaFormBuilder
// //
// e.g. Please provide a valid value for 'Address'. 'Address' is a mandatory decimal field. // e.g. Please provide a valid value for 'Address'. 'Address' is a mandatory decimal field.
// //
// Element alertElement = (Element) final Element alertElement = xForm.createElementNS(XFORMS_NS,
// formControl.appendChild(xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "alert");
// SchemaFormBuilder.XFORMS_NS_PREFIX + "alert")); formControl.appendChild(alertElement);
// this.setXFormsId(alertElement); this.setXFormsId(alertElement);
//
// StringBuffer alert = final Element envelope = xForm.getDocumentElement();
// new StringBuffer("Please provide a valid value for '" + caption + "'."); String alert = this.extractPropertyFromAnnotation(ALFRESCO_NS,
// "alert",
// Element enveloppe = xForm.getDocumentElement(); this.getAnnotation(owner));
// alert.append(" '" + caption + if (alert == null)
// "' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" + alert = ("Please provide a valid value for '" + caption + "'." +
// createCaption(this.getXFormsTypeName(enveloppe, controlType)) + " '" + caption +
// "' value."); "' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" +
// alertElement.appendChild(xForm.createTextNode(alert.toString())); createCaption(this.getXFormsTypeName(envelope, schema, controlType)) +
"' value.");
alertElement.appendChild(xForm.createTextNode(alert));
return formControl; return formControl;
} }
@@ -2781,8 +2773,7 @@ public class SchemaFormBuilder
namespaces.put(SchemaFormBuilder.XFORMS_NS_PREFIX, SchemaFormBuilder.XFORMS_NS); namespaces.put(SchemaFormBuilder.XFORMS_NS_PREFIX, SchemaFormBuilder.XFORMS_NS);
namespaces.put(SchemaFormBuilder.XLINK_NS_PREFIX, SchemaFormBuilder.XLINK_NS); namespaces.put(SchemaFormBuilder.XLINK_NS_PREFIX, SchemaFormBuilder.XLINK_NS);
namespaces.put(SchemaFormBuilder.XMLEVENTS_NS_PREFIX, SchemaFormBuilder.XMLEVENTS_NS); namespaces.put(SchemaFormBuilder.XMLEVENTS_NS_PREFIX, SchemaFormBuilder.XMLEVENTS_NS);
namespaces.put(SchemaFormBuilder.XMLSCHEMA_INSTANCE_NS_PREFIX, namespaces.put(SchemaFormBuilder.XMLSCHEMA_INSTANCE_NS_PREFIX, SchemaFormBuilder.XMLSCHEMA_INSTANCE_NS);
SchemaFormBuilder.XMLSCHEMA_INSTANCE_NS);
for (String nsPrefix : namespaces.keySet()) for (String nsPrefix : namespaces.keySet())
{ {
this.addNamespace(envelopeElement, nsPrefix, namespaces.get(nsPrefix)); this.addNamespace(envelopeElement, nsPrefix, namespaces.get(nsPrefix));
@@ -2838,11 +2829,17 @@ public class SchemaFormBuilder
return groupElement; return groupElement;
} }
public String createCaption(final String text,
final XSObject o)
{
return this.createCaption(text, this.getAnnotation(o));
}
public String createCaption(final String text, public String createCaption(final String text,
final XSAnnotation annotation) final XSAnnotation annotation)
{ {
final Text t = this.extractDocumentation(annotation); final String s = this.extractPropertyFromAnnotation(ALFRESCO_NS, "label", annotation);
return (t != null ? t.getNodeValue() : text); return s != null ? s : this.createCaption(text);
} }
/** /**
@@ -2890,7 +2887,7 @@ public class SchemaFormBuilder
// TODO: Improve i18n/l10n of caption - may have to use // TODO: Improve i18n/l10n of caption - may have to use
// a custom <appinfo> element in the XML Schema to do this. // a custom <appinfo> element in the XML Schema to do this.
// //
return createCaption(attribute.getName()); return createCaption(attribute.getName(), attribute);
} }
public String createCaption(XSAttributeUse attribute) public String createCaption(XSAttributeUse attribute)
@@ -2898,7 +2895,7 @@ public class SchemaFormBuilder
// TODO: Improve i18n/l10n of caption - may have to use // TODO: Improve i18n/l10n of caption - may have to use
// a custom <appinfo> element in the XML Schema to do this. // a custom <appinfo> element in the XML Schema to do this.
// //
return createCaption(attribute.getAttrDeclaration().getName()); return createCaption(attribute.getAttrDeclaration().getName(), attribute);
} }
/** /**
@@ -2916,7 +2913,7 @@ public class SchemaFormBuilder
// TODO: Improve i18n/l10n of caption - may have to use // TODO: Improve i18n/l10n of caption - may have to use
// a custom <appinfo> element in the XML Schema to do this. // a custom <appinfo> element in the XML Schema to do this.
// //
return createCaption(element.getName()); return createCaption(element.getName(), element);
} }
/** /**
@@ -2930,16 +2927,15 @@ public class SchemaFormBuilder
// TODO: Improve i18n/l10n of caption - may have to use // TODO: Improve i18n/l10n of caption - may have to use
// a custom <appinfo> element in the XML Schema to do this. // a custom <appinfo> element in the XML Schema to do this.
// //
if (element instanceof XSElementDeclaration) { if (element instanceof XSElementDeclaration)
return createCaption(((XSElementDeclaration) element).getName()); return createCaption((XSElementDeclaration)element);
} else if (element instanceof XSAttributeDeclaration) { if (element instanceof XSAttributeDeclaration)
return createCaption(((XSAttributeDeclaration) element).getName()); return createCaption((XSAttributeDeclaration)element);
} else if (element instanceof XSAttributeUse) { if (element instanceof XSAttributeUse)
return createCaption(((XSAttributeUse) element).getAttrDeclaration().getName()); return createCaption((XSAttributeUse)element);
} else
LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: " LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: "
+ element.getClass().getName()); + element.getClass().getName());
return null; return null;
} }
@@ -3255,17 +3251,29 @@ public class SchemaFormBuilder
*/ */
public Element createHint(Document xForm, XSObject node) public Element createHint(Document xForm, XSObject node)
{ {
XSAnnotation annotation = null; final XSAnnotation annotation = this.getAnnotation(node);
if (node instanceof XSElementDeclaration) if (annotation == null)
annotation = ((XSElementDeclaration)node).getAnnotation(); return null;
else if (node instanceof XSAttributeDeclaration) final String s = this.extractPropertyFromAnnotation(ALFRESCO_NS, "hint", annotation);
annotation = ((XSAttributeDeclaration)node).getAnnotation(); if (s == null)
else if (node instanceof XSAttributeUse) return null;
annotation = ((XSAttributeUse)node).getAttrDeclaration().getAnnotation(); final Element hintElement =
xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "hint");
this.setXFormsId(hintElement);
hintElement.appendChild(xForm.createTextNode(s));
return hintElement;
}
return (annotation != null private XSAnnotation getAnnotation(final XSObject o)
? addHintFromDocumentation(xForm, annotation) {
: null); return (o instanceof XSElementDeclaration
? ((XSElementDeclaration)o).getAnnotation()
: (o instanceof XSAttributeDeclaration
? ((XSAttributeDeclaration)o).getAnnotation()
: (o instanceof XSAttributeUse
? ((XSAttributeUse)o).getAttrDeclaration().getAnnotation()
: null)));
} }
/** /**
@@ -3465,11 +3473,17 @@ public class SchemaFormBuilder
registry.getDOMImplementation("XS-Loader"); registry.getDOMImplementation("XS-Loader");
final XSLoader schemaLoader = xsImpl.createXSLoader(null); final XSLoader schemaLoader = xsImpl.createXSLoader(null);
return schemaLoader.load(in); return schemaLoader.load(in);
} catch (ClassNotFoundException x) { }
catch (ClassNotFoundException x)
{
throw new FormBuilderException(x); throw new FormBuilderException(x);
} catch (InstantiationException x) { }
catch (InstantiationException x)
{
throw new FormBuilderException(x); throw new FormBuilderException(x);
} catch (IllegalAccessException x) { }
catch (IllegalAccessException x)
{
throw new FormBuilderException(x); throw new FormBuilderException(x);
} }
} }

View File

@@ -1,5 +1,6 @@
<jsp:root version="1.2" <jsp:root version="1.2"
xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:alfresco="http://www.alfresco.org/alfresco"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:pr="http://www.alfresco.org/pr"> xmlns:pr="http://www.alfresco.org/pr">
<jsp:directive.page language="java" contentType="text/html; charset=UTF-8"/> <jsp:directive.page language="java" contentType="text/html; charset=UTF-8"/>
@@ -13,7 +14,9 @@
<jsp:attribute name="value"><c:out value="${companyFooter.href}"/></jsp:attribute> <jsp:attribute name="value"><c:out value="${companyFooter.href}"/></jsp:attribute>
<jsp:body> <jsp:body>
<xs:annotation> <xs:annotation>
<xs:documentation><c:out value="${companyFooter.name}"/></xs:documentation> <xs:appinfo>
<alfresco:label><c:out value="${companyFooter.name}"/></alfresco:label>
</xs:appinfo>
</xs:annotation> </xs:annotation>
</jsp:body> </jsp:body>
</jsp:element> </jsp:element>

View File

@@ -1,13 +1,44 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alfresco="http://www.alfresco.org/alfresco"
elementFormDefault="qualified"> elementFormDefault="qualified">
<xs:simpleType name="five_string_values"> <xs:simpleType name="five_string_values">
<xs:restriction base="xs:string"> <xs:restriction base="xs:string">
<xs:enumeration value="one"/> <xs:enumeration value="one">
<xs:enumeration value="two"/> <xs:annotation>
<xs:enumeration value="three"/> <xs:appinfo>
<xs:enumeration value="four"/> <alfresco:label>1 - eno</alfresco:label>
<xs:enumeration value="five"/> </xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="two">
<xs:annotation>
<xs:appinfo>
<alfresco:label>2 - owt</alfresco:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="three">
<xs:annotation>
<xs:appinfo>
<alfresco:label>3 - eerht</alfresco:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="four">
<xs:annotation>
<xs:appinfo>
<alfresco:label>4 - ruof</alfresco:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="five">
<xs:annotation>
<xs:appinfo>
<alfresco:label>5 - evif</alfresco:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="ten_string_values"> <xs:simpleType name="ten_string_values">
@@ -38,7 +69,14 @@
<xs:element name="components"> <xs:element name="components">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="required_textfield" type="xs:string" minOccurs="1" maxOccurs="1"/> <xs:element name="required_textfield" type="xs:string" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<alfresco:label>A Required String</alfresco:label>
<alfresco:alert>Please enter a non zero length string</alfresco:alert>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="optional_textfield" type="xs:string" minOccurs="0" maxOccurs="1"/> <xs:element name="optional_textfield" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="prefilled_textfield" type="xs:string" minOccurs="0" maxOccurs="1" default="i am the default value"/> <xs:element name="prefilled_textfield" type="xs:string" minOccurs="0" maxOccurs="1" default="i am the default value"/>
<xs:element name="integer" type="xs:integer"/> <xs:element name="integer" type="xs:integer"/>
@@ -49,7 +87,14 @@
<xs:element name="combobox" type="ten_string_values"/> <xs:element name="combobox" type="ten_string_values"/>
<xs:element name="list_of_five" type="five_number_list"/> <xs:element name="list_of_five" type="five_number_list"/>
<xs:element name="list_of_ten" type="ten_number_list"/> <xs:element name="list_of_ten" type="ten_number_list"/>
<xs:element name="list_of_ten_select_three" type="ten_number_list_select_three"/> <xs:element name="list_of_ten_select_three" type="ten_number_list_select_three">
<xs:annotation>
<xs:appinfo>
<alfresco:label>10 select 3</alfresco:label>
<alfresco:alert>Please select at least 3 items from the list.</alfresco:alert>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="textarea" type="xs:anyType"/> <xs:element name="textarea" type="xs:anyType"/>
<xs:element name="checkbox_default_true" type="xs:boolean" default="true"/> <xs:element name="checkbox_default_true" type="xs:boolean" default="true"/>
<xs:element name="checkbox_default_false" type="xs:boolean" default="false"/> <xs:element name="checkbox_default_false" type="xs:boolean" default="false"/>

View File

@@ -15,6 +15,7 @@
<xs:element name="one-to-inf" type="xs:string" minOccurs="1" maxOccurs="unbounded"/> <xs:element name="one-to-inf" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="zero-to-inf" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="zero-to-inf" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="one-to-five" type="xs:string" minOccurs="1" maxOccurs="5"/> <xs:element name="one-to-five" type="xs:string" minOccurs="1" maxOccurs="5"/>
<xs:element name="three-to-five" type="xs:string" minOccurs="3" maxOccurs="5"/>
<xs:element name="zero-to-five" type="xs:string" minOccurs="0" maxOccurs="5"/> <xs:element name="zero-to-five" type="xs:string" minOccurs="0" maxOccurs="5"/>
<xs:element name="one-to-five-multi" type="multi-input" minOccurs="1" maxOccurs="5"/> <xs:element name="one-to-five-multi" type="multi-input" minOccurs="1" maxOccurs="5"/>
<xs:element name="zero-to-five-multi" type="multi-input" minOccurs="0" maxOccurs="5"/> <xs:element name="zero-to-five-multi" type="multi-input" minOccurs="0" maxOccurs="5"/>

View File

@@ -122,11 +122,28 @@ dojo.declare("alfresco.xforms.Widget",
} }
return null; return null;
}, },
_getAlertNode: function()
{
var labels = this.node.getElementsByTagName("alert");
for (var i = 0; i < labels.length; i++)
{
dojo.debug("parent " + labels[i].parentNode.nodeName +
" o " + this.node.nodeName);
if (labels[i].parentNode == this.node)
return labels[i];
}
return null;
},
getLabel: function() getLabel: function()
{ {
var node = this._getLabelNode(); var node = this._getLabelNode();
return node ? dojo.dom.textContent(node) : ""; return node ? dojo.dom.textContent(node) : "";
}, },
getAlert: function()
{
var node = this._getAlertNode();
return node ? dojo.dom.textContent(node) : "";
},
_updateDisplay: function() _updateDisplay: function()
{ {
// this.domContainer.style.backgroundColor = // this.domContainer.style.backgroundColor =
@@ -1206,7 +1223,7 @@ dojo.declare("alfresco.xforms.XForm",
msg += "<br/><ul>"; msg += "<br/><ul>";
for (var j = 0; j < invalid.length; j++) for (var j = 0; j < invalid.length; j++)
{ {
msg += "<li>" + invalid[j].getLabel() + "</li>"; msg += "<li>" + invalid[j].getAlert() + "</li>";
} }
msg += "</ul>"; msg += "</ul>";
_show_error(msg); _show_error(msg);