mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
fixing support for using xml namespaces within forms.
enabling using attributes within forms. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3911 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -130,8 +130,7 @@ public class XFormsInputMethod
|
|||||||
LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder");
|
LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder");
|
||||||
|
|
||||||
final SchemaFormBuilder builder =
|
final SchemaFormBuilder builder =
|
||||||
new BaseSchemaFormBuilder(tt.getName(),
|
new BaseSchemaFormBuilder(xmlContent,
|
||||||
xmlContent,
|
|
||||||
"/ajax/invoke/XFormsBean.handleAction",
|
"/ajax/invoke/XFormsBean.handleAction",
|
||||||
SchemaFormBuilder.SUBMIT_METHOD_POST,
|
SchemaFormBuilder.SUBMIT_METHOD_POST,
|
||||||
new XHTMLWrapperElementsBuilder(),
|
new XHTMLWrapperElementsBuilder(),
|
||||||
|
@@ -171,11 +171,6 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
*/
|
*/
|
||||||
protected String _action;
|
protected String _action;
|
||||||
|
|
||||||
/**
|
|
||||||
* Properties choosed by the user
|
|
||||||
*/
|
|
||||||
protected String _rootElementName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __UNDOCUMENTED__
|
* __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
@@ -222,15 +217,12 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
* @param submitMethod __UNDOCUMENTED__
|
* @param submitMethod __UNDOCUMENTED__
|
||||||
* @param wrapper __UNDOCUMENTED__
|
* @param wrapper __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public AbstractSchemaFormBuilder(final String rootElementName,
|
public AbstractSchemaFormBuilder(final Document instanceDocument,
|
||||||
final Document instanceDocument,
|
|
||||||
final String action,
|
final String action,
|
||||||
final String submitMethod,
|
final String submitMethod,
|
||||||
final WrapperElementsBuilder wrapper,
|
final WrapperElementsBuilder wrapper,
|
||||||
final String base)
|
final String base)
|
||||||
{
|
{
|
||||||
this._rootElementName = rootElementName;
|
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
this._instanceDocument = instanceDocument;
|
this._instanceDocument = instanceDocument;
|
||||||
|
|
||||||
@@ -247,7 +239,8 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
*
|
*
|
||||||
* @return __UNDOCUMENTED__
|
* @return __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public Properties getProperties() {
|
public Properties getProperties()
|
||||||
|
{
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +250,8 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
* @param key __UNDOCUMENTED__
|
* @param key __UNDOCUMENTED__
|
||||||
* @param value __UNDOCUMENTED__
|
* @param value __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, String value) {
|
public void setProperty(String key, String value)
|
||||||
|
{
|
||||||
getProperties().setProperty(key, value);
|
getProperties().setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +261,8 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
* @param key __UNDOCUMENTED__
|
* @param key __UNDOCUMENTED__
|
||||||
* @return __UNDOCUMENTED__
|
* @return __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public String getProperty(String key) {
|
public String getProperty(String key)
|
||||||
|
{
|
||||||
return getProperties().getProperty(key);
|
return getProperties().getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +273,8 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
* @param defaultValue __UNDOCUMENTED__
|
* @param defaultValue __UNDOCUMENTED__
|
||||||
* @return __UNDOCUMENTED__
|
* @return __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public String getProperty(String key, String defaultValue) {
|
public String getProperty(String key, String defaultValue)
|
||||||
|
{
|
||||||
return getProperties().getProperty(key, defaultValue);
|
return getProperties().getProperty(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,13 +288,14 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
public Document buildForm(final TemplateType tt)
|
public Document buildForm(final TemplateType tt)
|
||||||
throws FormBuilderException
|
throws FormBuilderException
|
||||||
{
|
{
|
||||||
|
String rootElementName = tt.getName();
|
||||||
final XSModel schema = this.loadSchema(tt);
|
final XSModel schema = this.loadSchema(tt);
|
||||||
this.buildTypeTree(schema);
|
this.buildTypeTree(schema);
|
||||||
|
|
||||||
//refCounter = 0;
|
//refCounter = 0;
|
||||||
this.counter = new HashMap();
|
this.counter = new HashMap();
|
||||||
|
|
||||||
final Document xForm = createFormTemplate(_rootElementName);
|
final Document xForm = createFormTemplate(rootElementName);
|
||||||
final Element envelopeElement = xForm.getDocumentElement();
|
final Element envelopeElement = xForm.getDocumentElement();
|
||||||
|
|
||||||
//Element formSection = (Element) envelopeElement.getElementsByTagNameNS(CHIBA_NS, "form").item(0);
|
//Element formSection = (Element) envelopeElement.getElementsByTagNameNS(CHIBA_NS, "form").item(0);
|
||||||
@@ -325,73 +322,66 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
//check if target namespace
|
//check if target namespace
|
||||||
//no way to do this with XS API ? load DOM document ?
|
//no way to do this with XS API ? load DOM document ?
|
||||||
//TODO: find a better way to find the targetNamespace
|
//TODO: find a better way to find the targetNamespace
|
||||||
try
|
final StringList targetNamespaces = schema.getNamespaces();
|
||||||
|
if (targetNamespaces.getLength() != 0)
|
||||||
{
|
{
|
||||||
final Document domDoc = tt.getSchema();
|
// will return null if no target namespace was specified
|
||||||
if (domDoc != null)
|
this.targetNamespace = targetNamespaces.item(0);
|
||||||
{
|
|
||||||
Element root = domDoc.getDocumentElement();
|
|
||||||
this.targetNamespace = root.getAttribute("targetNamespace");
|
|
||||||
if (this.targetNamespace != null && this.targetNamespace.length() == 0)
|
|
||||||
this.targetNamespace = null;
|
|
||||||
}
|
}
|
||||||
LOGGER.debug("using targetNamespace " + this.targetNamespace);
|
LOGGER.debug("using targetNamespace " + this.targetNamespace);
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error("Schema not loaded as DOM document: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
//if target namespace & we use the schema types: add it to form ns declarations
|
//if target namespace & we use the schema types: add it to form ns declarations
|
||||||
if (this.targetNamespace != null && this.targetNamespace.length() != 0)
|
// if (this.targetNamespace != null && this.targetNamespace.length() != 0)
|
||||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
// envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||||
"xmlns:schema",
|
// "xmlns:schema",
|
||||||
this.targetNamespace);
|
// this.targetNamespace);
|
||||||
|
|
||||||
|
|
||||||
final Comment comment =
|
final Comment comment =
|
||||||
xForm.createComment("This XForm was automatically generated by " + this.getClass().getName() +
|
xForm.createComment("This XForm was automatically generated by " + this.getClass().getName() +
|
||||||
" on " + (new Date()) + " from the '" + this._rootElementName +
|
" on " + (new Date()) + " from the '" + rootElementName +
|
||||||
"' element of the '" + this.targetNamespace +
|
"' element of the '" + this.targetNamespace + "' XML Schema.");
|
||||||
"' XML Schema.");
|
|
||||||
xForm.insertBefore(comment, envelopeElement);
|
xForm.insertBefore(comment, envelopeElement);
|
||||||
|
|
||||||
//TODO: WARNING: in Xerces 2.6.1, parameters are switched !!! (name, namespace)
|
//TODO: WARNING: in Xerces 2.6.1, parameters are switched !!! (name, namespace)
|
||||||
//XSElementDeclaration rootElementDecl =schema.getElementDeclaration(this.targetNamespace, _rootElementName);
|
//XSElementDeclaration rootElementDecl =schema.getElementDeclaration(this.targetNamespace, _rootElementName);
|
||||||
XSElementDeclaration rootElementDecl =
|
XSElementDeclaration rootElementDecl =
|
||||||
schema.getElementDeclaration(this._rootElementName, this.targetNamespace);
|
schema.getElementDeclaration(rootElementName, this.targetNamespace);
|
||||||
|
|
||||||
if (rootElementDecl == null)
|
if (rootElementDecl == null)
|
||||||
{
|
{
|
||||||
//Debug
|
//Debug
|
||||||
rootElementDecl = schema.getElementDeclaration(this.targetNamespace,
|
rootElementDecl = schema.getElementDeclaration(this.targetNamespace,
|
||||||
this._rootElementName);
|
rootElementName);
|
||||||
if (rootElementDecl != null && LOGGER.isDebugEnabled())
|
if (rootElementDecl != null && LOGGER.isDebugEnabled())
|
||||||
LOGGER.debug("getElementDeclaration: inversed parameters OK !!!");
|
LOGGER.debug("getElementDeclaration: inversed parameters OK !!!");
|
||||||
|
|
||||||
throw new FormBuilderException("Invalid root element tag name ["
|
throw new FormBuilderException("Invalid root element tag name ["
|
||||||
+ this._rootElementName
|
+ rootElementName
|
||||||
+ ", targetNamespace="
|
+ ", targetNamespace="
|
||||||
+ this.targetNamespace
|
+ this.targetNamespace
|
||||||
+ "]");
|
+ "]");
|
||||||
}
|
}
|
||||||
|
rootElementName = this.getElementName(rootElementDecl, xForm);
|
||||||
final Element instanceElement =
|
final Element instanceElement =
|
||||||
xForm.createElementNS(XFORMS_NS,
|
xForm.createElementNS(XFORMS_NS,
|
||||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "instance");
|
SchemaFormBuilder.XFORMS_NS_PREFIX + "instance");
|
||||||
modelSection.appendChild(instanceElement);
|
modelSection.appendChild(instanceElement);
|
||||||
this.setXFormsId(instanceElement);
|
this.setXFormsId(instanceElement);
|
||||||
|
|
||||||
final Element defaultInstanceRootElement = (Element)
|
final Element defaultInstanceRootElement = xForm.createElement(rootElementName);
|
||||||
xForm.createElement(this._rootElementName);
|
|
||||||
this.addNamespace(defaultInstanceRootElement,
|
this.addNamespace(defaultInstanceRootElement,
|
||||||
XMLSCHEMA_INSTANCE_NS_PREFIX,
|
XMLSCHEMA_INSTANCE_NS_PREFIX,
|
||||||
XMLSCHEMA_INSTANCE_NS);
|
XMLSCHEMA_INSTANCE_NS);
|
||||||
instanceElement.appendChild(defaultInstanceRootElement);
|
|
||||||
|
|
||||||
if (this._instanceDocument != null)
|
if (this._instanceDocument == null)
|
||||||
|
instanceElement.appendChild(defaultInstanceRootElement);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Element instanceDocumentElement = this._instanceDocument.getDocumentElement();
|
Element instanceDocumentElement = this._instanceDocument.getDocumentElement();
|
||||||
if (!instanceDocumentElement.getNodeName().equals(this._rootElementName))
|
if (!instanceDocumentElement.getNodeName().equals(rootElementName))
|
||||||
throw new IllegalArgumentException("instance document root tag name invalid. " +
|
throw new IllegalArgumentException("instance document root tag name invalid. " +
|
||||||
"expected " + this._rootElementName +
|
"expected " + rootElementName +
|
||||||
", got " + instanceDocumentElement.getNodeName());
|
", got " + instanceDocumentElement.getNodeName());
|
||||||
LOGGER.debug("importing rootElement from other document");
|
LOGGER.debug("importing rootElement from other document");
|
||||||
final Element importedInstanceRootElement = (Element)
|
final Element importedInstanceRootElement = (Element)
|
||||||
@@ -424,7 +414,7 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
//action
|
//action
|
||||||
submitInfoElement.setAttributeNS(XFORMS_NS,
|
submitInfoElement.setAttributeNS(XFORMS_NS,
|
||||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "action",
|
SchemaFormBuilder.XFORMS_NS_PREFIX + "action",
|
||||||
_action == null ? "" : _action);
|
_action == null ? "" : this._base + _action);
|
||||||
|
|
||||||
//method
|
//method
|
||||||
submitInfoElement.setAttributeNS(XFORMS_NS,
|
submitInfoElement.setAttributeNS(XFORMS_NS,
|
||||||
@@ -944,6 +934,7 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
|
|
||||||
private void addAttributeSet(final Document xForm,
|
private void addAttributeSet(final Document xForm,
|
||||||
final Element modelSection,
|
final Element modelSection,
|
||||||
|
final Element defaultInstanceElement,
|
||||||
final Element formSection,
|
final Element formSection,
|
||||||
final XSModel schema,
|
final XSModel schema,
|
||||||
final XSComplexTypeDefinition controlType,
|
final XSComplexTypeDefinition controlType,
|
||||||
@@ -957,10 +948,14 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
return;
|
return;
|
||||||
for (int i = 0; i < attrUses.getLength(); i++)
|
for (int i = 0; i < attrUses.getLength(); i++)
|
||||||
{
|
{
|
||||||
XSAttributeUse currentAttributeUse = (XSAttributeUse)attrUses.item(i);
|
final XSAttributeUse currentAttributeUse = (XSAttributeUse)attrUses.item(i);
|
||||||
XSAttributeDeclaration currentAttribute =
|
final XSAttributeDeclaration currentAttribute =
|
||||||
currentAttributeUse.getAttrDeclaration();
|
currentAttributeUse.getAttrDeclaration();
|
||||||
|
|
||||||
|
String attributeName = currentAttributeUse.getName();
|
||||||
|
if (attributeName == null || attributeName.length() == 0)
|
||||||
|
attributeName = currentAttributeUse.getAttrDeclaration().getName();
|
||||||
|
|
||||||
//test if extended !
|
//test if extended !
|
||||||
if (checkIfExtension &&
|
if (checkIfExtension &&
|
||||||
this.doesAttributeComeFromExtension(currentAttributeUse, controlType))
|
this.doesAttributeComeFromExtension(currentAttributeUse, controlType))
|
||||||
@@ -971,13 +966,9 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
DOMUtil.prettyPrintDOM(modelSection);
|
DOMUtil.prettyPrintDOM(modelSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
String attributeName = currentAttributeUse.getName();
|
|
||||||
if (attributeName == null || attributeName.length() == 0)
|
|
||||||
attributeName = currentAttributeUse.getAttrDeclaration().getName();
|
|
||||||
|
|
||||||
//find the existing bind Id
|
//find the existing bind Id
|
||||||
//(modelSection is the enclosing bind of the element)
|
//(modelSection is the enclosing bind of the element)
|
||||||
NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind");
|
final NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind");
|
||||||
String bindId = null;
|
String bindId = null;
|
||||||
for (int j = 0; j < binds.getLength() && bindId == null; j++) {
|
for (int j = 0; j < binds.getLength() && bindId == null; j++) {
|
||||||
Element bind = (Element) binds.item(j);
|
Element bind = (Element) binds.item(j);
|
||||||
@@ -1021,6 +1012,12 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
defaultInstanceElement.setAttributeNS(this.targetNamespace,
|
||||||
|
// XXXarielb - i probably need the prefix here i.e. "alf:" + attributeName
|
||||||
|
attributeName,
|
||||||
|
(currentAttributeUse.getConstraintType() == XSConstants.VC_NONE
|
||||||
|
? null
|
||||||
|
: currentAttributeUse.getConstraintValue()));
|
||||||
final String newPathToRoot =
|
final String newPathToRoot =
|
||||||
(pathToRoot == null || pathToRoot.length() == 0
|
(pathToRoot == null || pathToRoot.length() == 0
|
||||||
? "@" + currentAttribute.getName()
|
? "@" + currentAttribute.getName()
|
||||||
@@ -1176,8 +1173,9 @@ public abstract class AbstractSchemaFormBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
//attributes
|
//attributes
|
||||||
addAttributeSet(xForm,
|
this.addAttributeSet(xForm,
|
||||||
modelSection,
|
modelSection,
|
||||||
|
defaultInstanceElement,
|
||||||
formSection,
|
formSection,
|
||||||
schema,
|
schema,
|
||||||
controlType,
|
controlType,
|
||||||
|
@@ -46,21 +46,18 @@ public class BaseSchemaFormBuilder
|
|||||||
/**
|
/**
|
||||||
* Creates a new BaseSchemaFormBuilder object.
|
* Creates a new BaseSchemaFormBuilder object.
|
||||||
*
|
*
|
||||||
* @param rootTagName __UNDOCUMENTED__
|
|
||||||
* @param instanceSource __UNDOCUMENTED__
|
* @param instanceSource __UNDOCUMENTED__
|
||||||
* @param action __UNDOCUMENTED__
|
* @param action __UNDOCUMENTED__
|
||||||
* @param submitMethod __UNDOCUMENTED__
|
* @param submitMethod __UNDOCUMENTED__
|
||||||
* @param wrapper __UNDOCUMENTED__
|
* @param wrapper __UNDOCUMENTED__
|
||||||
*/
|
*/
|
||||||
public BaseSchemaFormBuilder(final String rootTagName,
|
public BaseSchemaFormBuilder(final Document instanceDocument,
|
||||||
final Document instanceDocument,
|
|
||||||
final String action,
|
final String action,
|
||||||
final String submitMethod,
|
final String submitMethod,
|
||||||
final WrapperElementsBuilder wrapper,
|
final WrapperElementsBuilder wrapper,
|
||||||
final String base)
|
final String base)
|
||||||
{
|
{
|
||||||
super(rootTagName,
|
super(instanceDocument,
|
||||||
instanceDocument,
|
|
||||||
action,
|
action,
|
||||||
submitMethod,
|
submitMethod,
|
||||||
wrapper,
|
wrapper,
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:alf="http://www.alfresco.org/alf"
|
||||||
|
elementFormDefault="qualified"
|
||||||
|
targetNamespace="http://www.alfresco.org/alf">
|
||||||
|
<xs:complexType name="multi">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="multi1" type="xs:string"/>
|
||||||
|
<xs:element name="multi2" type="xs:string"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:element name="xml-namespaces-test">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="string_with_default" type="xs:string" default="default string value"/>
|
||||||
|
<xs:element name="string_no_default" type="xs:string"/>
|
||||||
|
<xs:element name="multi" type="alf:multi" minOccurs="2" maxOccurs="3"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="string_attribute_with_default" type="xs:string" default="default string value"/>
|
||||||
|
<xs:attribute name="string_attribute_no_default" type="xs:string"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xsl:stylesheet version="1.0"
|
||||||
|
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
exclude-result-prefixes="xhtml">
|
||||||
|
|
||||||
|
<xsl:output method="html" version="4.01" encoding="UTF-8" indent="yes"
|
||||||
|
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
|
doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
|
||||||
|
<xsl:preserve-space elements="*"/>
|
||||||
|
|
||||||
|
<xsl:template match="/">
|
||||||
|
</xsl:template>
|
||||||
|
</xsl:stylesheet>
|
@@ -67,7 +67,7 @@ dojo.declare("alfresco.xforms.Widget",
|
|||||||
chibaData = chibaData[chibaData.length - 1];
|
chibaData = chibaData[chibaData.length - 1];
|
||||||
var xpath = "/" + chibaData.getAttribute("chiba:xpath");
|
var xpath = "/" + chibaData.getAttribute("chiba:xpath");
|
||||||
var d = this.node.ownerDocument;
|
var d = this.node.ownerDocument;
|
||||||
var nsResolver = d.createNSResolver(d);
|
var nsResolver = d.createNSResolver(d.documentElement);
|
||||||
var contextNode = this.xform.getInstance();
|
var contextNode = this.xform.getInstance();
|
||||||
dojo.debug("locating " + xpath +
|
dojo.debug("locating " + xpath +
|
||||||
" from " + chibaData.nodeName +
|
" from " + chibaData.nodeName +
|
||||||
@@ -289,7 +289,7 @@ dojo.declare("alfresco.xforms.Select1",
|
|||||||
var d = this.node.ownerDocument;
|
var d = this.node.ownerDocument;
|
||||||
valid = d.evaluate(binding.constraint,
|
valid = d.evaluate(binding.constraint,
|
||||||
value,
|
value,
|
||||||
d.createNSResolver(d),
|
d.createNSResolver(d.documentElement),
|
||||||
XPathResult.ANY_TYPE,
|
XPathResult.ANY_TYPE,
|
||||||
null);
|
null);
|
||||||
dojo.debug("valid " + dojo.dom.textContent(value) + "? " + valid);
|
dojo.debug("valid " + dojo.dom.textContent(value) + "? " + valid);
|
||||||
|
Reference in New Issue
Block a user