diff --git a/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java b/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java
index d31b1d286f..b3826b3903 100644
--- a/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java
+++ b/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java
@@ -130,8 +130,7 @@ public class XFormsInputMethod
LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder");
final SchemaFormBuilder builder =
- new BaseSchemaFormBuilder(tt.getName(),
- xmlContent,
+ new BaseSchemaFormBuilder(xmlContent,
"/ajax/invoke/XFormsBean.handleAction",
SchemaFormBuilder.SUBMIT_METHOD_POST,
new XHTMLWrapperElementsBuilder(),
diff --git a/source/java/org/alfresco/web/templating/xforms/schemabuilder/AbstractSchemaFormBuilder.java b/source/java/org/alfresco/web/templating/xforms/schemabuilder/AbstractSchemaFormBuilder.java
index 54cd5137c8..08b2c084dc 100644
--- a/source/java/org/alfresco/web/templating/xforms/schemabuilder/AbstractSchemaFormBuilder.java
+++ b/source/java/org/alfresco/web/templating/xforms/schemabuilder/AbstractSchemaFormBuilder.java
@@ -171,11 +171,6 @@ public abstract class AbstractSchemaFormBuilder
*/
protected String _action;
- /**
- * Properties choosed by the user
- */
- protected String _rootElementName;
-
/**
* __UNDOCUMENTED__
*/
@@ -222,15 +217,12 @@ public abstract class AbstractSchemaFormBuilder
* @param submitMethod __UNDOCUMENTED__
* @param wrapper __UNDOCUMENTED__
*/
- public AbstractSchemaFormBuilder(final String rootElementName,
- final Document instanceDocument,
+ public AbstractSchemaFormBuilder(final Document instanceDocument,
final String action,
final String submitMethod,
final WrapperElementsBuilder wrapper,
final String base)
{
- this._rootElementName = rootElementName;
-
reset();
this._instanceDocument = instanceDocument;
@@ -247,7 +239,8 @@ public abstract class AbstractSchemaFormBuilder
*
* @return __UNDOCUMENTED__
*/
- public Properties getProperties() {
+ public Properties getProperties()
+ {
return properties;
}
@@ -257,7 +250,8 @@ public abstract class AbstractSchemaFormBuilder
* @param key __UNDOCUMENTED__
* @param value __UNDOCUMENTED__
*/
- public void setProperty(String key, String value) {
+ public void setProperty(String key, String value)
+ {
getProperties().setProperty(key, value);
}
@@ -267,7 +261,8 @@ public abstract class AbstractSchemaFormBuilder
* @param key __UNDOCUMENTED__
* @return __UNDOCUMENTED__
*/
- public String getProperty(String key) {
+ public String getProperty(String key)
+ {
return getProperties().getProperty(key);
}
@@ -278,7 +273,8 @@ public abstract class AbstractSchemaFormBuilder
* @param defaultValue __UNDOCUMENTED__
* @return __UNDOCUMENTED__
*/
- public String getProperty(String key, String defaultValue) {
+ public String getProperty(String key, String defaultValue)
+ {
return getProperties().getProperty(key, defaultValue);
}
@@ -292,13 +288,14 @@ public abstract class AbstractSchemaFormBuilder
public Document buildForm(final TemplateType tt)
throws FormBuilderException
{
+ String rootElementName = tt.getName();
final XSModel schema = this.loadSchema(tt);
this.buildTypeTree(schema);
//refCounter = 0;
this.counter = new HashMap();
- final Document xForm = createFormTemplate(_rootElementName);
+ final Document xForm = createFormTemplate(rootElementName);
final Element envelopeElement = xForm.getDocumentElement();
//Element formSection = (Element) envelopeElement.getElementsByTagNameNS(CHIBA_NS, "form").item(0);
@@ -325,73 +322,66 @@ public abstract class AbstractSchemaFormBuilder
//check if target namespace
//no way to do this with XS API ? load DOM document ?
//TODO: find a better way to find the targetNamespace
- try
+ final StringList targetNamespaces = schema.getNamespaces();
+ if (targetNamespaces.getLength() != 0)
{
- final Document domDoc = tt.getSchema();
- if (domDoc != null)
- {
- 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);
- } catch (Exception ex) {
- LOGGER.error("Schema not loaded as DOM document: " + ex.getMessage());
+ // will return null if no target namespace was specified
+ this.targetNamespace = targetNamespaces.item(0);
}
+ LOGGER.debug("using targetNamespace " + this.targetNamespace);
//if target namespace & we use the schema types: add it to form ns declarations
- if (this.targetNamespace != null && this.targetNamespace.length() != 0)
- envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
- "xmlns:schema",
- this.targetNamespace);
-
+// if (this.targetNamespace != null && this.targetNamespace.length() != 0)
+// envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
+// "xmlns:schema",
+// this.targetNamespace);
+
+
final Comment comment =
xForm.createComment("This XForm was automatically generated by " + this.getClass().getName() +
- " on " + (new Date()) + " from the '" + this._rootElementName +
- "' element of the '" + this.targetNamespace +
- "' XML Schema.");
+ " on " + (new Date()) + " from the '" + rootElementName +
+ "' element of the '" + this.targetNamespace + "' XML Schema.");
xForm.insertBefore(comment, envelopeElement);
//TODO: WARNING: in Xerces 2.6.1, parameters are switched !!! (name, namespace)
//XSElementDeclaration rootElementDecl =schema.getElementDeclaration(this.targetNamespace, _rootElementName);
XSElementDeclaration rootElementDecl =
- schema.getElementDeclaration(this._rootElementName, this.targetNamespace);
+ schema.getElementDeclaration(rootElementName, this.targetNamespace);
if (rootElementDecl == null)
{
//Debug
rootElementDecl = schema.getElementDeclaration(this.targetNamespace,
- this._rootElementName);
+ rootElementName);
if (rootElementDecl != null && LOGGER.isDebugEnabled())
LOGGER.debug("getElementDeclaration: inversed parameters OK !!!");
throw new FormBuilderException("Invalid root element tag name ["
- + this._rootElementName
+ + rootElementName
+ ", targetNamespace="
+ this.targetNamespace
+ "]");
}
-
+ rootElementName = this.getElementName(rootElementDecl, xForm);
final Element instanceElement =
xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "instance");
modelSection.appendChild(instanceElement);
this.setXFormsId(instanceElement);
- final Element defaultInstanceRootElement = (Element)
- xForm.createElement(this._rootElementName);
+ final Element defaultInstanceRootElement = xForm.createElement(rootElementName);
this.addNamespace(defaultInstanceRootElement,
XMLSCHEMA_INSTANCE_NS_PREFIX,
XMLSCHEMA_INSTANCE_NS);
- instanceElement.appendChild(defaultInstanceRootElement);
- if (this._instanceDocument != null)
+ if (this._instanceDocument == null)
+ instanceElement.appendChild(defaultInstanceRootElement);
+ else
{
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. " +
- "expected " + this._rootElementName +
+ "expected " + rootElementName +
", got " + instanceDocumentElement.getNodeName());
LOGGER.debug("importing rootElement from other document");
final Element importedInstanceRootElement = (Element)
@@ -424,7 +414,7 @@ public abstract class AbstractSchemaFormBuilder
//action
submitInfoElement.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "action",
- _action == null ? "" : _action);
+ _action == null ? "" : this._base + _action);
//method
submitInfoElement.setAttributeNS(XFORMS_NS,
@@ -944,6 +934,7 @@ public abstract class AbstractSchemaFormBuilder
private void addAttributeSet(final Document xForm,
final Element modelSection,
+ final Element defaultInstanceElement,
final Element formSection,
final XSModel schema,
final XSComplexTypeDefinition controlType,
@@ -957,9 +948,13 @@ public abstract class AbstractSchemaFormBuilder
return;
for (int i = 0; i < attrUses.getLength(); i++)
{
- XSAttributeUse currentAttributeUse = (XSAttributeUse)attrUses.item(i);
- XSAttributeDeclaration currentAttribute =
+ final XSAttributeUse currentAttributeUse = (XSAttributeUse)attrUses.item(i);
+ final XSAttributeDeclaration currentAttribute =
currentAttributeUse.getAttrDeclaration();
+
+ String attributeName = currentAttributeUse.getName();
+ if (attributeName == null || attributeName.length() == 0)
+ attributeName = currentAttributeUse.getAttrDeclaration().getName();
//test if extended !
if (checkIfExtension &&
@@ -971,13 +966,9 @@ public abstract class AbstractSchemaFormBuilder
DOMUtil.prettyPrintDOM(modelSection);
}
- String attributeName = currentAttributeUse.getName();
- if (attributeName == null || attributeName.length() == 0)
- attributeName = currentAttributeUse.getAttrDeclaration().getName();
-
//find the existing bind Id
//(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;
for (int j = 0; j < binds.getLength() && bindId == null; j++) {
Element bind = (Element) binds.item(j);
@@ -1021,6 +1012,12 @@ public abstract class AbstractSchemaFormBuilder
}
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 =
(pathToRoot == null || pathToRoot.length() == 0
? "@" + currentAttribute.getName()
@@ -1176,14 +1173,15 @@ public abstract class AbstractSchemaFormBuilder
}
//attributes
- addAttributeSet(xForm,
- modelSection,
- formSection,
- schema,
- controlType,
- owner,
- pathToRoot,
- checkIfExtension);
+ this.addAttributeSet(xForm,
+ modelSection,
+ defaultInstanceElement,
+ formSection,
+ schema,
+ controlType,
+ owner,
+ pathToRoot,
+ checkIfExtension);
//process group
final XSParticle particle = controlType.getParticle();
diff --git a/source/java/org/alfresco/web/templating/xforms/schemabuilder/BaseSchemaFormBuilder.java b/source/java/org/alfresco/web/templating/xforms/schemabuilder/BaseSchemaFormBuilder.java
index 278f049201..6aa3d8dfba 100644
--- a/source/java/org/alfresco/web/templating/xforms/schemabuilder/BaseSchemaFormBuilder.java
+++ b/source/java/org/alfresco/web/templating/xforms/schemabuilder/BaseSchemaFormBuilder.java
@@ -46,21 +46,18 @@ public class BaseSchemaFormBuilder
/**
* Creates a new BaseSchemaFormBuilder object.
*
- * @param rootTagName __UNDOCUMENTED__
* @param instanceSource __UNDOCUMENTED__
* @param action __UNDOCUMENTED__
* @param submitMethod __UNDOCUMENTED__
* @param wrapper __UNDOCUMENTED__
*/
- public BaseSchemaFormBuilder(final String rootTagName,
- final Document instanceDocument,
+ public BaseSchemaFormBuilder(final Document instanceDocument,
final String action,
final String submitMethod,
final WrapperElementsBuilder wrapper,
final String base)
{
- super(rootTagName,
- instanceDocument,
+ super(instanceDocument,
action,
submitMethod,
wrapper,
diff --git a/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsd b/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsd
new file mode 100644
index 0000000000..a6cc93b480
--- /dev/null
+++ b/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsd
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsl b/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsl
new file mode 100644
index 0000000000..da14742ce0
--- /dev/null
+++ b/source/test-resources/xforms/unit-tests/xml-namespaces-test/xml-namespaces-test.xsl
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js
index 9c346ba601..6e0119ad7c 100644
--- a/source/web/scripts/ajax/xforms.js
+++ b/source/web/scripts/ajax/xforms.js
@@ -67,7 +67,7 @@ dojo.declare("alfresco.xforms.Widget",
chibaData = chibaData[chibaData.length - 1];
var xpath = "/" + chibaData.getAttribute("chiba:xpath");
var d = this.node.ownerDocument;
- var nsResolver = d.createNSResolver(d);
+ var nsResolver = d.createNSResolver(d.documentElement);
var contextNode = this.xform.getInstance();
dojo.debug("locating " + xpath +
" from " + chibaData.nodeName +
@@ -289,7 +289,7 @@ dojo.declare("alfresco.xforms.Select1",
var d = this.node.ownerDocument;
valid = d.evaluate(binding.constraint,
value,
- d.createNSResolver(d),
+ d.createNSResolver(d.documentElement),
XPathResult.ANY_TYPE,
null);
dojo.debug("valid " + dojo.dom.textContent(value) + "? " + valid);