mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.1 to HEAD
6466: Xml metadata. Support for pulling collections of values from XML 6470: Fix for AWC-1321 - Using zero as items per page gives error for Alfresco repos in OpenSearch 6471: Fix for AWC-1496 - OpenSearch dashlet can get in a state where search queries are not executed 6472: Fix for AWC-1495. Searching additional attributes now working correctly for folders. 6473: Fix for AR-1251 (Version error when saving new content via CIFS) 6474: Updated bundles and installers - added missing files back into Linux bundle 6475: LDAP and chainging authentication Resolved conflicted state of 'root\projects\repository\source\java\org\alfresco\repo\security\authentication\AuthenticationUtil.java' 6477: XForms WCM-696. 6478: Fix for WCM-567 (IndexOutOfBoundsException when stepping through wizard rapidly) 6480: Fix to issue when removing locks on directories. 6481: Updated installer and config wizard to fix download option and config behaviour when called from installer. 6482: Fix for WCM-1229 (properties sheet does not refresh) 6483: Fix for AR-1511 6484: Fix for AR-1351 6485: Missed a unit test update git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6737 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2358,39 +2358,7 @@ public class Schema2XForms
|
||||
this.getAnnotation(owner),
|
||||
resourceBundle);
|
||||
Element result = null;
|
||||
if ("boolean".equals(controlType.getName()))
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":select1");
|
||||
final String[] values = { "true", "false" };
|
||||
for (String v : values)
|
||||
{
|
||||
final Element item = this.createXFormsItem(xformsDocument, v, v);
|
||||
result.appendChild(item);
|
||||
}
|
||||
}
|
||||
else if ("string".equals(controlType.getName()))
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":textarea");
|
||||
if (appearance == null || appearance.length() == 0)
|
||||
{
|
||||
appearance = "compact";
|
||||
}
|
||||
}
|
||||
else if ("anyURI".equals(controlType.getName()))
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":upload");
|
||||
final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":filename");
|
||||
this.setXFormsId(e);
|
||||
result.appendChild(e);
|
||||
e.setAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":ref",
|
||||
".");
|
||||
}
|
||||
else if (controlType.getNumeric())
|
||||
if (controlType.getNumeric())
|
||||
{
|
||||
if (controlType.getBounded() &&
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE) != null &&
|
||||
@@ -2437,91 +2405,132 @@ public class Schema2XForms
|
||||
}
|
||||
else
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
if ((appearance == null || appearance.length() == 0) &&
|
||||
SchemaUtil.getBuiltInType(controlType) == XSConstants.NORMALIZEDSTRING_DT)
|
||||
switch (SchemaUtil.getBuiltInType(controlType))
|
||||
{
|
||||
appearance = "full";
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_LENGTH))
|
||||
case XSConstants.BOOLEAN_DT:
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":length",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_LENGTH));
|
||||
}
|
||||
else if(controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH) ||
|
||||
controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH))
|
||||
{
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH))
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":select1");
|
||||
final String[] values = { "true", "false" };
|
||||
for (String v : values)
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":minlength",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINLENGTH));
|
||||
final Element item = this.createXFormsItem(xformsDocument, v, v);
|
||||
result.appendChild(item);
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH))
|
||||
break;
|
||||
}
|
||||
case XSConstants.STRING_DT:
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":textarea");
|
||||
if (appearance == null || appearance.length() == 0)
|
||||
{
|
||||
appearance = "compact";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XSConstants.ANYURI_DT:
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":upload");
|
||||
final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":filename");
|
||||
this.setXFormsId(e);
|
||||
result.appendChild(e);
|
||||
e.setAttributeNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":ref",
|
||||
".");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
if ((appearance == null || appearance.length() == 0) &&
|
||||
SchemaUtil.getBuiltInType(controlType) == XSConstants.NORMALIZEDSTRING_DT)
|
||||
{
|
||||
appearance = "full";
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_LENGTH))
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":maxlength",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXLENGTH));
|
||||
NamespaceService.ALFRESCO_PREFIX + ":length",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_LENGTH));
|
||||
}
|
||||
else if(controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH) ||
|
||||
controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH))
|
||||
{
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH))
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":minlength",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINLENGTH));
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH))
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":maxlength",
|
||||
controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXLENGTH));
|
||||
}
|
||||
}
|
||||
if (SchemaUtil.getBuiltInType(controlType) == XSConstants.DATE_DT)
|
||||
{
|
||||
String minInclusive = null;
|
||||
String maxInclusive = null;
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE))
|
||||
{
|
||||
minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE);
|
||||
try
|
||||
{
|
||||
final Date d = sdf.parse(minInclusive);
|
||||
calendar.setTime(d);
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
LOGGER.error(pe);
|
||||
}
|
||||
calendar.roll(Calendar.DATE, true);
|
||||
minInclusive = sdf.format(calendar.getTime());
|
||||
}
|
||||
else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE))
|
||||
{
|
||||
minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE);
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE))
|
||||
{
|
||||
maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE);
|
||||
try
|
||||
{
|
||||
final Date d = sdf.parse(maxInclusive);
|
||||
calendar.setTime(d);
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
LOGGER.error(pe);
|
||||
}
|
||||
calendar.roll(Calendar.DATE, false);
|
||||
maxInclusive = sdf.format(calendar.getTime());
|
||||
}
|
||||
else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE))
|
||||
{
|
||||
maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE);
|
||||
}
|
||||
if (minInclusive != null)
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":minInclusive",
|
||||
minInclusive);
|
||||
}
|
||||
if (maxInclusive != null)
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":maxInclusive",
|
||||
maxInclusive);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SchemaUtil.getBuiltInType(controlType) == XSConstants.DATE_DT)
|
||||
{
|
||||
String minInclusive = null;
|
||||
String maxInclusive = null;
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE))
|
||||
{
|
||||
minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE);
|
||||
try
|
||||
{
|
||||
final Date d = sdf.parse(minInclusive);
|
||||
calendar.setTime(d);
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
LOGGER.error(pe);
|
||||
}
|
||||
calendar.roll(Calendar.DATE, true);
|
||||
minInclusive = sdf.format(calendar.getTime());
|
||||
}
|
||||
else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE))
|
||||
{
|
||||
minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE);
|
||||
}
|
||||
if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE))
|
||||
{
|
||||
maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE);
|
||||
try
|
||||
{
|
||||
final Date d = sdf.parse(maxInclusive);
|
||||
calendar.setTime(d);
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
LOGGER.error(pe);
|
||||
}
|
||||
calendar.roll(Calendar.DATE, false);
|
||||
maxInclusive = sdf.format(calendar.getTime());
|
||||
}
|
||||
else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE))
|
||||
{
|
||||
maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE);
|
||||
}
|
||||
if (minInclusive != null)
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":minInclusive",
|
||||
minInclusive);
|
||||
}
|
||||
if (maxInclusive != null)
|
||||
{
|
||||
result.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":maxInclusive",
|
||||
maxInclusive);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setXFormsId(result);
|
||||
@@ -2769,8 +2778,8 @@ public class Schema2XForms
|
||||
// type.getName() may be 'null' for anonymous types, so compare against
|
||||
// static string (see bug #1172541 on sf.net)
|
||||
|
||||
if (!"anyType".equals(controlType.getName()) &&
|
||||
controlType instanceof XSSimpleTypeDefinition)
|
||||
if (controlType instanceof XSSimpleTypeDefinition &&
|
||||
((XSSimpleTypeDefinition)controlType).getBuiltInKind() != XSConstants.ANYSIMPLETYPE_DT)
|
||||
{
|
||||
String typeName = this.getXFormsTypeName(bindElement.getOwnerDocument(),
|
||||
schema,
|
||||
@@ -2781,6 +2790,14 @@ public class Schema2XForms
|
||||
NamespaceConstants.XFORMS_PREFIX + ":type",
|
||||
typeName);
|
||||
}
|
||||
|
||||
typeName = SchemaUtil.getBuiltInTypeName(controlType);
|
||||
if (typeName != null && typeName.length() != 0)
|
||||
{
|
||||
bindElement.setAttributeNS(NamespaceService.ALFRESCO_URI,
|
||||
NamespaceService.ALFRESCO_PREFIX + ":builtInType",
|
||||
typeName);
|
||||
}
|
||||
}
|
||||
|
||||
final short constraintType =
|
||||
|
@@ -20,13 +20,13 @@
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
* http://www.alfresco.com/legal/licensing
|
||||
*/
|
||||
package org.alfresco.web.forms.xforms;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.web.forms.XMLUtil;
|
||||
import org.alfresco.util.BaseTest;
|
||||
@@ -53,7 +53,7 @@ public class Schema2XFormsTest
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/one-string-test.xsd");
|
||||
final Document xformsDocument = this.buildXForm(null, schemaDocument, "one-string-test");
|
||||
final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "one-string-test");
|
||||
final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument);
|
||||
Pointer pointer = xpathContext.getPointer("//*[@id='input_0']");
|
||||
assertNotNull(pointer);
|
||||
@@ -72,7 +72,7 @@ public class Schema2XFormsTest
|
||||
{
|
||||
final Document instanceDocument = XMLUtil.parse("<one-string-test><string>test</string></one-string-test>");
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/one-string-test.xsd");
|
||||
final Document xformsDocument = this.buildXForm(instanceDocument, schemaDocument, "one-string-test");
|
||||
final Document xformsDocument = Schema2XFormsTest.buildXForm(instanceDocument, schemaDocument, "one-string-test");
|
||||
final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument);
|
||||
Pointer pointer = xpathContext.getPointer("//*[@id='input_0']");
|
||||
assertNotNull(pointer);
|
||||
@@ -89,73 +89,73 @@ public class Schema2XFormsTest
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/repeat-constraints-test.xsd");
|
||||
final Document xformsDocument = this.buildXForm(null, schemaDocument, "repeat-constraints-test");
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/one-to-five",
|
||||
new SchemaUtil.Occurrence(1, 5));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/three-to-five",
|
||||
new SchemaUtil.Occurrence(3, 5));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/zero-to-five",
|
||||
new SchemaUtil.Occurrence(0, 5));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/referenced-string",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five",
|
||||
new SchemaUtil.Occurrence(3, 5));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf",
|
||||
new SchemaUtil.Occurrence(3, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf",
|
||||
new SchemaUtil.Occurrence(5, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
this.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf/nested-inner-inner-seven-to-inf",
|
||||
new SchemaUtil.Occurrence(7, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "repeat-constraints-test");
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/one-to-five",
|
||||
new SchemaUtil.Occurrence(1, 5));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/three-to-five",
|
||||
new SchemaUtil.Occurrence(3, 5));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/zero-to-five",
|
||||
new SchemaUtil.Occurrence(0, 5));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/referenced-string",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five",
|
||||
new SchemaUtil.Occurrence(3, 5));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-zero-to-inf",
|
||||
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-one-to-inf",
|
||||
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf",
|
||||
new SchemaUtil.Occurrence(3, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf",
|
||||
new SchemaUtil.Occurrence(5, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
Schema2XFormsTest.assertRepeatProperties(xformsDocument,
|
||||
"/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf/nested-inner-inner-seven-to-inf",
|
||||
new SchemaUtil.Occurrence(7, SchemaUtil.Occurrence.UNBOUNDED));
|
||||
}
|
||||
|
||||
public void testRootElementWithExtension()
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/root-element-with-extension-test.xsd");
|
||||
Document xformsDocument = this.buildXForm(null, schemaDocument, "without-extension-test");
|
||||
Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "without-extension-test");
|
||||
assertEquals(3, xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "input").getLength());
|
||||
|
||||
try
|
||||
{
|
||||
xformsDocument = this.buildXForm(null, schemaDocument, "with-extension-test");
|
||||
xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "with-extension-test");
|
||||
fail("expected failure creating xform with root element with-extension-test in schema " + XMLUtil.toString(schemaDocument));
|
||||
}
|
||||
catch (FormBuilderException fbe)
|
||||
@@ -168,13 +168,13 @@ public class Schema2XFormsTest
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/switch-test.xsd");
|
||||
final Document xformsDocument = this.buildXForm(null, schemaDocument, "switch-test");
|
||||
final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "switch-test");
|
||||
LOGGER.debug("generated xforms " + XMLUtil.toString(xformsDocument));
|
||||
// assertEquals(3, xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "input").getLength());
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// xformsDocument = this.buildXForm(null, schemaDocument, "with-extension-test");
|
||||
// xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "with-extension-test");
|
||||
// fail("expected failure creating xform with root element with-extension-test in schema " + XMLUtil.toString(schemaDocument));
|
||||
// }
|
||||
// catch (FormBuilderException fbe)
|
||||
@@ -182,14 +182,133 @@ public class Schema2XFormsTest
|
||||
// }
|
||||
}
|
||||
|
||||
public void testDerivedType()
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/derived-type-test.xsd");
|
||||
final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "derived-type-test");
|
||||
LOGGER.debug("generated xforms " + XMLUtil.toString(xformsDocument));
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-normalized-string",
|
||||
"normalizedString",
|
||||
"normalizedString");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-normalized-string",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-normalized-string",
|
||||
"non-empty-normalized-string-type",
|
||||
"normalizedString");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-normalized-string",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-string",
|
||||
"string",
|
||||
"string");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-string",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":textarea");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-string",
|
||||
"non-empty-string-type",
|
||||
"string");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-string",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":textarea");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-any-uri",
|
||||
"anyURI",
|
||||
"anyURI");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-any-uri",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":upload");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-any-uri",
|
||||
"non-empty-any-uri-type",
|
||||
"anyURI");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/non-empty-any-uri",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":upload");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-decimal",
|
||||
"decimal",
|
||||
"decimal");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-decimal",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
try
|
||||
{
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/non-zero-decimal",
|
||||
"non-zero-decimal-type",
|
||||
"decimal");
|
||||
fail("expected union type non-zero-decimal to fail");
|
||||
}
|
||||
catch (AssertionFailedError ignore)
|
||||
{
|
||||
}
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/non-zero-decimal",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-positive-integer",
|
||||
"positiveInteger",
|
||||
"positiveInteger");
|
||||
Element control = assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-positive-integer",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":input");
|
||||
assertEquals(0, Integer.parseInt(control.getAttributeNS(NamespaceService.ALFRESCO_URI, "fractionDigits")));
|
||||
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/one-to-ten-positive-integer",
|
||||
"one-to-ten-positive-integer-type",
|
||||
"positiveInteger");
|
||||
control = assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/one-to-ten-positive-integer",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":range");
|
||||
assertEquals(1, Integer.parseInt(control.getAttributeNS(NamespaceConstants.XFORMS_NS, "start")));
|
||||
assertEquals(10, Integer.parseInt(control.getAttributeNS(NamespaceConstants.XFORMS_NS, "end")));
|
||||
assertEquals(0, Integer.parseInt(control.getAttributeNS(NamespaceService.ALFRESCO_URI, "fractionDigits")));
|
||||
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-boolean",
|
||||
"boolean",
|
||||
"boolean");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-boolean",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":select1");
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/always-true-boolean",
|
||||
"always-true-boolean-type",
|
||||
"boolean");
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/always-true-boolean",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":select1");
|
||||
try
|
||||
{
|
||||
assertBindProperties(xformsDocument,
|
||||
"/derived-type-test/raw-any-type",
|
||||
"anyType",
|
||||
"anyType");
|
||||
fail("expected unexpected behavior for anyType");
|
||||
}
|
||||
catch (AssertionFailedError ignore)
|
||||
{
|
||||
}
|
||||
assertControlProperties(xformsDocument,
|
||||
"/derived-type-test/raw-any-type",
|
||||
NamespaceConstants.XFORMS_PREFIX + ":textarea");
|
||||
}
|
||||
|
||||
public void testRecursive()
|
||||
throws Exception
|
||||
{
|
||||
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/recursive-test.xsd");
|
||||
Document xformsDocument = this.buildXForm(null, schemaDocument, "non-recursive-test");
|
||||
Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "non-recursive-test");
|
||||
try
|
||||
{
|
||||
xformsDocument = this.buildXForm(null, schemaDocument, "recursive-test");
|
||||
xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "recursive-test");
|
||||
fail("expected failure creating xform with recursive element definition root element recursive-test in schema " + XMLUtil.toString(schemaDocument));
|
||||
}
|
||||
catch (FormBuilderException fbe)
|
||||
@@ -198,7 +317,7 @@ public class Schema2XFormsTest
|
||||
}
|
||||
try
|
||||
{
|
||||
xformsDocument = this.buildXForm(null, schemaDocument, "nested-recursive-test");
|
||||
xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "nested-recursive-test");
|
||||
fail("expected failure creating xform with recursive element definition root element nested-recursive-test in schema " + XMLUtil.toString(schemaDocument));
|
||||
}
|
||||
catch (FormBuilderException fbe)
|
||||
@@ -207,9 +326,11 @@ public class Schema2XFormsTest
|
||||
}
|
||||
}
|
||||
|
||||
private void assertRepeatProperties(final Document xformsDocument, final String nodeset, final SchemaUtil.Occurrence o)
|
||||
private static void assertRepeatProperties(final Document xformsDocument,
|
||||
final String nodeset,
|
||||
final SchemaUtil.Occurrence o)
|
||||
{
|
||||
final Element[] bindElements = this.resolveBind(xformsDocument, nodeset);
|
||||
final Element[] bindElements = Schema2XFormsTest.resolveBind(xformsDocument, nodeset);
|
||||
assertNotNull("unable to resolve bind for nodeset " + nodeset, bindElements);
|
||||
assertFalse("unable to resolve bind for nodeset " + nodeset, 0 == bindElements.length);
|
||||
final Element nodesetBindElement = bindElements[bindElements.length - 1];
|
||||
@@ -247,7 +368,7 @@ public class Schema2XFormsTest
|
||||
int nestingFactor = 1;
|
||||
for (int i = 0; i < bindElements.length - 1; i++)
|
||||
{
|
||||
final SchemaUtil.Occurrence parentO = this.occuranceFromBind(bindElements[i]);
|
||||
final SchemaUtil.Occurrence parentO = Schema2XFormsTest.occuranceFromBind(bindElements[i]);
|
||||
if (parentO.isRepeated())
|
||||
{
|
||||
nestingFactor = nestingFactor * (1 + parentO.minimum);
|
||||
@@ -267,10 +388,36 @@ public class Schema2XFormsTest
|
||||
xpathContext.selectNodes(xpath).size());
|
||||
}
|
||||
|
||||
private static Element assertBindProperties(final Document xformsDocument,
|
||||
final String nodeset,
|
||||
final String schemaType,
|
||||
final String builtInType)
|
||||
{
|
||||
final Element[] binds = Schema2XFormsTest.resolveBind(xformsDocument, nodeset);
|
||||
assertEquals("unexpected type for nodeset " + nodeset,
|
||||
schemaType,
|
||||
binds[binds.length - 1].getAttributeNS(NamespaceConstants.XFORMS_NS, "type"));
|
||||
assertEquals("unexpected built in type for nodeset " + nodeset,
|
||||
builtInType,
|
||||
binds[binds.length - 1].getAttributeNS(NamespaceService.ALFRESCO_URI, "builtInType"));
|
||||
return binds[binds.length - 1];
|
||||
}
|
||||
|
||||
private static Element assertControlProperties(final Document xformsDocument,
|
||||
final String nodeset,
|
||||
final String controlType)
|
||||
{
|
||||
final Element[] controls = Schema2XFormsTest.resolveXFormsControl(xformsDocument, nodeset);
|
||||
assertEquals("unexpected xforms control for " + nodeset,
|
||||
controlType,
|
||||
controls[controls.length - 1].getNodeName());
|
||||
return controls[controls.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resolved bind and all parents binds for the nodeset.
|
||||
*/
|
||||
private Element[] resolveBind(final Document xformsDocument, final String nodeset)
|
||||
private static Element[] resolveBind(final Document xformsDocument, final String nodeset)
|
||||
{
|
||||
JXPathContext xpathContext = JXPathContext.newContext(xformsDocument);
|
||||
assertNotNull(nodeset);
|
||||
@@ -307,6 +454,19 @@ public class Schema2XFormsTest
|
||||
return (Element[])result.toArray(new Element[result.size()]);
|
||||
}
|
||||
|
||||
private static Element[] resolveXFormsControl(final Document xformsDocument,
|
||||
final String nodeset)
|
||||
{
|
||||
final Element[] binds = Schema2XFormsTest.resolveBind(xformsDocument, nodeset);
|
||||
assertNotNull(binds);
|
||||
assertFalse(binds.length == 0);
|
||||
final String bindId = binds[binds.length - 1].getAttribute("id");
|
||||
|
||||
final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument);
|
||||
String xpath = "//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']";
|
||||
return (Element[])xpathContext.selectNodes(xpath).toArray(new Element[0]);
|
||||
}
|
||||
|
||||
private Document loadTestResourceDocument(final String path)
|
||||
throws IOException, SAXException
|
||||
{
|
||||
@@ -318,9 +478,9 @@ public class Schema2XFormsTest
|
||||
return XMLUtil.parse(f);
|
||||
}
|
||||
|
||||
private Document buildXForm(final Document instanceDocument,
|
||||
final Document schemaDocument,
|
||||
final String rootElementName)
|
||||
private static Document buildXForm(final Document instanceDocument,
|
||||
final Document schemaDocument,
|
||||
final String rootElementName)
|
||||
throws FormBuilderException
|
||||
{
|
||||
final Schema2XForms s2xf = new Schema2XForms("/test_action",
|
||||
@@ -347,8 +507,7 @@ public class Schema2XFormsTest
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private SchemaUtil.Occurrence occuranceFromBind(final Element bindElement)
|
||||
private static SchemaUtil.Occurrence occuranceFromBind(final Element bindElement)
|
||||
{
|
||||
return new SchemaUtil.Occurrence(bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs")
|
||||
? Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs"))
|
||||
|
@@ -358,8 +358,7 @@ public class SchemaUtil
|
||||
public static TreeMap<String, TreeSet<XSTypeDefinition>>
|
||||
buildTypeTree(final XSModel schema)
|
||||
{
|
||||
final TreeMap<String, TreeSet<XSTypeDefinition>> result = new
|
||||
TreeMap<String, TreeSet<XSTypeDefinition>>();
|
||||
final TreeMap<String, TreeSet<XSTypeDefinition>> result = new TreeMap<String, TreeSet<XSTypeDefinition>>();
|
||||
if (LOGGER.isDebugEnabled())
|
||||
LOGGER.debug("buildTypeTree " + schema);
|
||||
// build the type tree for complex types
|
||||
@@ -371,8 +370,8 @@ public class SchemaUtil
|
||||
{
|
||||
final XSComplexTypeDefinition type = (XSComplexTypeDefinition)t;
|
||||
SchemaUtil.buildTypeTree(type,
|
||||
new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER),
|
||||
result);
|
||||
new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER),
|
||||
result);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user