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");
|
||||
|
||||
final SchemaFormBuilder builder =
|
||||
new BaseSchemaFormBuilder(tt.getName(),
|
||||
xmlContent,
|
||||
new BaseSchemaFormBuilder(xmlContent,
|
||||
"/ajax/invoke/XFormsBean.handleAction",
|
||||
SchemaFormBuilder.SUBMIT_METHOD_POST,
|
||||
new XHTMLWrapperElementsBuilder(),
|
||||
|
@@ -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();
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user