diff --git a/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java b/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java index e1158a8bca..6e812a3c39 100644 --- a/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java +++ b/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java @@ -80,7 +80,7 @@ public final class AuthenticationHelper /** public service bean IDs **/ private static final String AUTHENTICATION_SERVICE = "AuthenticationService"; - private static final String UNPROTECTED_AUTH_SERVICE = "authenticationServiceImpl"; + private static final String UNPROTECTED_AUTH_SERVICE = "authenticationService"; private static final String PERSON_SERVICE = "personService"; /** cookie names */ diff --git a/source/java/org/alfresco/web/bean/DocumentDetailsBean.java b/source/java/org/alfresco/web/bean/DocumentDetailsBean.java index ccbef56163..847b91d4b9 100644 --- a/source/java/org/alfresco/web/bean/DocumentDetailsBean.java +++ b/source/java/org/alfresco/web/bean/DocumentDetailsBean.java @@ -35,6 +35,7 @@ import java.util.Locale; import java.util.Map; import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; @@ -690,12 +691,13 @@ public class DocumentDetailsBean extends BaseDetailsBean { try { - RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance()); + FacesContext context = FacesContext.getCurrentInstance(); + RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context); RetryingTransactionCallback callback = new RetryingTransactionCallback() { public Object execute() throws Throwable { - // add the versionable aspect to the node + // add the versionable aspect to the node nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null); return null; } @@ -704,6 +706,13 @@ public class DocumentDetailsBean extends BaseDetailsBean // reset the state of the current document getDocument().reset(); + + // get hold of the main property sheet on the page and remove the children to force a refresh + UIComponent comp = context.getViewRoot().findComponent("document-details:document-props"); + if (comp != null) + { + comp.getChildren().clear(); + } } catch (Throwable e) { diff --git a/source/java/org/alfresco/web/bean/SearchContext.java b/source/java/org/alfresco/web/bean/SearchContext.java index bfd59c38cf..8ee5e11f53 100644 --- a/source/java/org/alfresco/web/bean/SearchContext.java +++ b/source/java/org/alfresco/web/bean/SearchContext.java @@ -424,7 +424,7 @@ public final class SearchContext implements Serializable case SearchContext.SEARCH_ALL: query = '(' + fileTypeQuery + " AND " + '(' + nameAttrQuery + ' ' + additionalAttrsQuery + ' ' + fullTextQuery + ')' + ')' + " OR " + - '(' + folderTypeQuery + " AND " + nameAttrQuery + ' ' + additionalAttrsQuery + ')'; + '(' + folderTypeQuery + " AND " + '(' + nameAttrQuery + ' ' + additionalAttrsQuery + "))"; break; case SearchContext.SEARCH_FILE_NAMES: diff --git a/source/java/org/alfresco/web/bean/wizard/WizardManager.java b/source/java/org/alfresco/web/bean/wizard/WizardManager.java index d3e846a710..97abc96d04 100644 --- a/source/java/org/alfresco/web/bean/wizard/WizardManager.java +++ b/source/java/org/alfresco/web/bean/wizard/WizardManager.java @@ -479,7 +479,16 @@ public final class WizardManager { // calculate next step number and update wizard state int currentStep = this.currentWizardState.getCurrentStep(); + int noSteps = this.currentWizardState.getSteps().size(); currentStep++; + + // check we haven't gone past the end (this can happen if the next + // button is pressed too many times) + if (currentStep > noSteps) + { + currentStep = noSteps; + } + this.currentWizardState.setCurrentStep(currentStep); if (logger.isDebugEnabled()) @@ -499,6 +508,14 @@ public final class WizardManager // calculate next step number and update wizard state int currentStep = this.currentWizardState.getCurrentStep(); currentStep--; + + // check we haven't gone past the beginning (this can + // happen if the back button is pressed too many times) + if (currentStep < 1) + { + currentStep = 1; + } + this.currentWizardState.setCurrentStep(currentStep); if (logger.isDebugEnabled()) diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java index d0df764605..248d0c118f 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java @@ -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 = diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java b/source/java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java index b57729629d..ef268b37d2 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java @@ -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("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")) diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java index 0da62730c6..2e97d9ebcf 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java @@ -358,8 +358,7 @@ public class SchemaUtil public static TreeMap> buildTypeTree(final XSModel schema) { - final TreeMap> result = new - TreeMap>(); + final TreeMap> result = new TreeMap>(); 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(TYPE_EXTENSION_SORTER), - result); + new TreeSet(TYPE_EXTENSION_SORTER), + result); } } diff --git a/source/test-resources/xforms/unit-tests/automated/derived-type-test.xsd b/source/test-resources/xforms/unit-tests/automated/derived-type-test.xsd new file mode 100644 index 0000000000..0b4ade56e4 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/automated/derived-type-test.xsd @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/web/scripts/ajax/common.js b/source/web/scripts/ajax/common.js index b7f50df824..637369f723 100644 --- a/source/web/scripts/ajax/common.js +++ b/source/web/scripts/ajax/common.js @@ -27,7 +27,7 @@ function handleCaughtError(err) msg = err; } - alert("An error occurred: " + msg); + alert("An error occurred:\n" + msg); } /** diff --git a/source/web/scripts/ajax/opensearch.js b/source/web/scripts/ajax/opensearch.js index 5d277d8bb8..fd11a478c8 100644 --- a/source/web/scripts/ajax/opensearch.js +++ b/source/web/scripts/ajax/opensearch.js @@ -206,17 +206,15 @@ Alfresco.OpenSearchClient.prototype = var count = document.getElementById(this.id + _PAGE_SIZE_FIELD_ID).value; // default the count if its invalid - if (count.length == 0 || isNaN(count)) + if (count.length == 0 || isNaN(count) || count < 1) { count = 5; + document.getElementById(this.id + _PAGE_SIZE_FIELD_ID).value = count; } // issue the queries if there is enough search criteria if (this.searchInProgress == false && term != null && term.length > 1) { - // show that we are executing a search - this.searchInProgress = true; - // remove previous results (if necessary) var resultsPanel = document.getElementById(this.id + _RESULTS_DIV_ID_SUFFIX); if (resultsPanel != null) @@ -235,6 +233,8 @@ Alfresco.OpenSearchClient.prototype = var engCheckbox = document.getElementById(this.id + "-" + ose.id + _ENGINE_ENABLED_FIELD_ID); if (engCheckbox != null && engCheckbox.checked) { + // we found at least one engine - show that we are executing a search + this.searchInProgress = true; this.issueSearchRequest(ose, term, count); } } @@ -265,7 +265,7 @@ Alfresco.OpenSearchClient.prototype = { // replace the token with the engine label var errorMsg = this.msgFailedGenerateUrl.replace("{0}", ose.label); - handleErrorYahoo(errorMsg); + handleCaughtError(errorMsg); } }, @@ -786,5 +786,8 @@ Alfresco.OpenSearchEngine.handleSearchError = function(ajaxResponse) var engineLabel = clientInstance.enginesById[engineId].label; var errorMsg = clientInstance.msgFailedSearch.replace("{0}", engineLabel); - handleErrorYahoo(errorMsg + ": " + ajaxResponse.status + " " + ajaxResponse.statusText); + handleCaughtError(errorMsg + ": " + ajaxResponse.status + " " + ajaxResponse.statusText); + + // reset the search in progress flag + clientInstance.searchInProgress = false; } diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index 4be9ada61e..47519895fa 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -3931,6 +3931,10 @@ dojo.declare("alfresco.xforms.Binding", (_hasAttribute(this.xformsNode, alfresco.xforms.constants.XFORMS_PREFIX + ":type") ? this.xformsNode.getAttribute(alfresco.xforms.constants.XFORMS_PREFIX + ":type") : null); + this._builtInType = + (_hasAttribute(this.xformsNode, alfresco.xforms.constants.ALFRESCO_PREFIX + ":builtInType") + ? this.xformsNode.getAttribute(alfresco.xforms.constants.ALFRESCO_PREFIX + ":builtInType") + : null); this.constraint = (_hasAttribute(this.xformsNode, alfresco.xforms.constants.XFORMS_PREFIX + ":constraint") ? this.xformsNode.getAttribute(alfresco.xforms.constants.XFORMS_PREFIX + ":constraint") @@ -3950,6 +3954,14 @@ dojo.declare("alfresco.xforms.Binding", : (this.parent != null ? this.parent.getType() : null)); }, + /** Returns the expected built in schema type for this binding. */ + getBuiltInType: function() + { + return (this._builtInType != null + ? this._builtInType + : (this.parent != null ? this.parent.getBuiltInType() : null)); + }, + /** Returns true if a node bound by this binding has a readonly value */ isReadonly: function() { @@ -3968,6 +3980,7 @@ dojo.declare("alfresco.xforms.Binding", { return ("{id: " + this.id + ",type: " + this.getType() + + ",builtInType: " + this.getBuiltInType() + ",required: " + this.isRequired() + ",readonly: " + this.isReadonly() + ",nodeset: " + this.nodeset + "}"); @@ -4026,17 +4039,19 @@ dojo.declare("alfresco.xforms.XForm", var xformsType = xformsNode.nodeName.toLowerCase(); var binding = this.getBinding(xformsNode); - var schemaType = binding ? binding.getType() : "*"; + var schemaType = binding ? binding.getType() : null; + var builtInSchemaType = binding ? binding.getBuiltInType() : null; dojo.debug("creating widget for xforms type " + xformsType + " schema type " + schemaType + + " built in schema type " + builtInSchemaType + " with appearance " + appearance); var x = alfresco.xforms.widgetConfig[xformsType]; if (!x) { throw new Error("unknown type " + xformsNode.nodeName); } - x = schemaType in x ? x[schemaType] : x["*"]; + x = schemaType in x ? x[schemaType] : builtInSchemaType in x ? x[builtInSchemaType] : x["*"]; x = appearance in x ? x[appearance] : x["*"]; // dojo.debug(xformsType + ":" + schemaType + ":" + appearance + " =>" + x); if (x === undefined)