diff --git a/config/alfresco/web-client-config-wizards.xml b/config/alfresco/web-client-config-wizards.xml index 28bf559e4b..9299b4b55d 100644 --- a/config/alfresco/web-client-config-wizards.xml +++ b/config/alfresco/web-client-config-wizards.xml @@ -226,7 +226,7 @@ - diff --git a/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java similarity index 89% rename from source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java rename to source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java index cd269e5dd6..b178a0e525 100644 --- a/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java @@ -14,13 +14,14 @@ * language governing permissions and limitations under the * License. */ -package org.alfresco.web.bean.content; +package org.alfresco.web.bean.wcm; import java.io.File; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -31,6 +32,7 @@ import javax.faces.model.DataModel; import javax.faces.model.ListDataModel; import javax.faces.model.SelectItem; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMModel; import org.alfresco.service.cmr.model.FileInfo; @@ -41,17 +43,19 @@ import org.alfresco.service.namespace.QName; import org.alfresco.web.app.Application; import org.alfresco.web.bean.FileUploadBean; import org.alfresco.web.bean.wizard.BaseWizardBean; +import org.alfresco.web.templating.xforms.SchemaFormBuilder; import org.alfresco.web.templating.TemplatingService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import org.apache.xerces.xs.*; +import org.w3c.dom.Document; /** * Bean implementation for the "Create XML Form" dialog * * @author arielb */ -public class CreateXmlContentTypeWizard extends BaseWizardBean +public class CreateFormWizard extends BaseWizardBean { ///////////////////////////////////////////////////////////////////////////// @@ -103,7 +107,7 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean ///////////////////////////////////////////////////////////////////////////// private final static Log LOGGER = - LogFactory.getLog(CreateXmlContentTypeWizard.class); + LogFactory.getLog(CreateFormWizard.class); private String schemaRootTagName; private String templateName; @@ -262,6 +266,15 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean */ public void addSelectedTemplateOutputMethod(ActionEvent event) { + for (TemplateOutputMethodData tomd : this.templateOutputMethods) + { + if (tomd.getFileExtension().equals(this.fileExtension)) + { + throw new AlfrescoRuntimeException("template output method with extension " + this.fileExtension + + " already exists"); + } + } + final TemplateOutputMethodData data = new TemplateOutputMethodData(this.getTemplateOutputMethodFileName(), this.getTemplateOutputMethodFile(), @@ -419,15 +432,44 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean { this.schemaRootTagName = schemaRootTagName; } - + /** - * @return the root tag name to use when processing the schema. + * Returns the root tag name to use when processing the schema. */ public String getSchemaRootTagName() { - return (this.schemaRootTagName == null && this.getSchemaFileName() != null - ? this.getSchemaFileName().replaceAll("([^\\.])\\..+", "$1") - : this.schemaRootTagName); + return this.schemaRootTagName; + } + + /** + * @return the possible root tag names for use with the schema based on + * the element declarations it defines. + */ + public List getSchemaRootTagNameChoices() + { + final List result = new LinkedList(); + if (this.getSchemaFile() != null) + { + try + { + final TemplatingService ts = TemplatingService.getInstance(); + final Document d = ts.parseXML(this.getSchemaFile()); + final XSModel xsm = SchemaFormBuilder.loadSchema(d); + final XSNamedMap elementsMap = xsm.getComponents(XSConstants.ELEMENT_DECLARATION); + for (int i = 0; i < elementsMap.getLength(); i++) + { + final XSElementDeclaration e = (XSElementDeclaration)elementsMap.item(i); + result.add(new SelectItem(e.getName(), e.getName())); + } + } + catch (Exception e) + { + final String msg = "unable to parse " + this.getSchemaFileName(); + this.removeUploadedSchemaFile(); + throw new AlfrescoRuntimeException(msg, e); + } + } + return result; } /** diff --git a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java index 9ff1fced30..9da75967a1 100644 --- a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java +++ b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java @@ -2260,8 +2260,8 @@ public class SchemaFormBuilder bindElement.setAttributeNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", pathToRoot); - bindElement = (Element)modelSection.appendChild(bindElement); - bindElement = startBindElement(bindElement, schema, controlType, o); + modelSection.appendChild(bindElement); + bindElement = this.startBindElement(bindElement, schema, controlType, owner, o); // add a group if a repeat ! if (owner instanceof XSElementDeclaration && o.maximum != 1) @@ -3331,6 +3331,7 @@ public class SchemaFormBuilder public Element startBindElement(final Element bindElement, final XSModel schema, final XSTypeDefinition controlType, + final XSObject owner, final Occurs o) { // START WORKAROUND @@ -3350,11 +3351,23 @@ public class SchemaFormBuilder typeName); } + final short constraintType = + (owner instanceof XSElementDeclaration + ? ((XSElementDeclaration)owner).getConstraintType() + : (owner instanceof XSAttributeDeclaration + ? ((XSAttributeDeclaration)owner).getConstraintType() + : (owner instanceof XSAttributeUse + ? ((XSAttributeUse)owner).getConstraintType() + : XSConstants.VC_NONE))); + + bindElement.setAttributeNS(XFORMS_NS, + SchemaFormBuilder.XFORMS_NS_PREFIX + "readonly", + (constraintType == XSConstants.VC_FIXED) + "()"); + bindElement.setAttributeNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "required", - o.minimum == 0 ? "false()" : "true()"); + (o.minimum != 0) + "()"); - //no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1: //count(.) <= maxOccurs && count(.) >= minOccurs String minConstraint = null; @@ -3451,7 +3464,8 @@ public class SchemaFormBuilder return elementName; } - private XSModel loadSchema(final Document schemaDocument) + //XXXarielb factor out to a utility method... + public static XSModel loadSchema(final Document schemaDocument) throws FormBuilderException { try diff --git a/source/test-resources/xforms/demos/record/record.xsd b/source/test-resources/xforms/demos/record/record.xsd index 5c6356d488..355a9f985e 100644 --- a/source/test-resources/xforms/demos/record/record.xsd +++ b/source/test-resources/xforms/demos/record/record.xsd @@ -23,7 +23,7 @@ - + diff --git a/source/test-resources/xforms/unit-tests/attributes-test/attributes-test.xsd b/source/test-resources/xforms/unit-tests/attributes-test/attributes-test.xsd new file mode 100644 index 0000000000..457037f370 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/attributes-test/attributes-test.xsd @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/multi-form-schema/multi-form-schema.xsd b/source/test-resources/xforms/unit-tests/multi-form-schema/multi-form-schema.xsd new file mode 100644 index 0000000000..151a13edff --- /dev/null +++ b/source/test-resources/xforms/unit-tests/multi-form-schema/multi-form-schema.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/repeat-multi/repeat-multi.xsd b/source/test-resources/xforms/unit-tests/repeat-multi/repeat-multi.xsd new file mode 100644 index 0000000000..c3dc549763 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-multi/repeat-multi.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index e555b55768..ce2ef00d21 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2065,8 +2065,8 @@ The bean that backs up the Create XML Content Type Wizard - CreateXmlContentTypeWizard - org.alfresco.web.bean.content.CreateXmlContentTypeWizard + CreateFormWizard + org.alfresco.web.bean.wcm.CreateFormWizard session nodeService diff --git a/source/web/jsp/dialog/edit-xml-inline.jsp b/source/web/jsp/dialog/edit-xml-inline.jsp index 6b08ba6613..dbd52f7571 100644 --- a/source/web/jsp/dialog/edit-xml-inline.jsp +++ b/source/web/jsp/dialog/edit-xml-inline.jsp @@ -29,7 +29,6 @@ org.alfresco.web.templating.*" %> <%@ page import="java.io.*" %> <%@ page import="org.alfresco.web.app.Application" %> -<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %> <%@ page import="org.alfresco.web.templating.*" %> <%@ page import="org.w3c.dom.Document" %> <% @@ -219,4 +218,4 @@ dojo.addOnLoad(function() - \ No newline at end of file + diff --git a/source/web/jsp/wcm/create-form-wizard/details.jsp b/source/web/jsp/wcm/create-form-wizard/details.jsp index 39d5700294..058edb0e40 100644 --- a/source/web/jsp/wcm/create-form-wizard/details.jsp +++ b/source/web/jsp/wcm/create-form-wizard/details.jsp @@ -98,8 +98,10 @@ if (upload == null || upload.getFile() == null) - + + + -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> -<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> -<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> -<%@ page import="java.io.*" %> -<%@ page import="org.alfresco.web.app.Application" %> -<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %> -<%@ page import="org.alfresco.web.templating.*" %> -<%@ page import="org.w3c.dom.Document" %> -<% -CreateXmlContentTypeWizard wiz = (CreateXmlContentTypeWizard) - Application.getWizardManager().getBean(); -TemplateType tt = wiz.getTemplateType(); -TemplateInputMethod tim = tt.getInputMethods().get(0); -final InstanceData instanceData = new InstanceData() { - public Document getContent() { return null; } - public void setContent(Document d) { } -}; -tim.generate(instanceData, tt, out); -%> diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index 9e02a6250a..cc1f7ba25d 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -1,8 +1,6 @@ dojo.require("dojo.widget.DebugConsole"); dojo.require("dojo.widget.DatePicker"); dojo.require("dojo.widget.Button"); -dojo.require("dojo.widget.validate"); -dojo.require("dojo.widget.Spinner"); dojo.require("dojo.lfx.html"); dojo.hostenv.writeIncludes(); @@ -99,8 +97,12 @@ dojo.declare("alfresco.xforms.Widget", isRequired: function() { var binding = this._getBinding(); - var required = binding && binding.required == "true()"; - return required; + return binding && binding.required == "true()"; + }, + isReadonly: function() + { + var binding = this._getBinding(); + return binding && binding.readonly == "true()"; }, getInitialValue: function() { @@ -274,7 +276,15 @@ dojo.declare("alfresco.xforms.TextField", // value: initial_value // }, // this.domNode); - dojo.event.connect(this.widget, "onkeyup", this, this._widget_keyUpHandler); + if (this.isReadonly()) + { + this.widget.setAttribute("readonly", this.isReadonly()); + this.widget.setAttribute("disabled", this.isReadonly()); + } + else + { + dojo.event.connect(this.widget, "onkeyup", this, this._widget_keyUpHandler); + } }, getValue: function() { @@ -387,7 +397,7 @@ dojo.declare("alfresco.xforms.Select", if (initial_value.indexOf(values[i].value) != -1) { this._selectedValues.push(values[i].value); - checkbox.setAttribute("checked", "true"); + checkbox.checked = true; } dojo.event.connect(checkbox, "onclick", this, this._checkbox_clickHandler); this.widget.appendChild(checkbox); @@ -408,7 +418,7 @@ dojo.declare("alfresco.xforms.Select", if (initial_value.indexOf(values[i].value) != -1) { this._selectedValues.push(values[i].value); - option.setAttribute("selected", "true"); + option.selected = true; } this.widget.appendChild(option); } @@ -479,7 +489,7 @@ dojo.declare("alfresco.xforms.Select1", if (values[i].value == initial_value) { this._selectedValue = initial_value; - radio.setAttribute("checked", "true"); + radio.checked = true; } dojo.event.connect(radio, "onclick", this, this._radio_clickHandler); } @@ -499,7 +509,7 @@ dojo.declare("alfresco.xforms.Select1", if (values[i].value == initial_value) { this._selectedValue = initial_value; - option.setAttribute("selected", "true"); + option.selected = true; } } dojo.event.connect(this.widget, "onchange", this, this._combobox_changeHandler); @@ -1232,13 +1242,15 @@ dojo.declare("alfresco.xforms.XForm", { var id = bind.childNodes[i].getAttribute("id"); dojo.debug("loading binding " + id); - result[id] = { - id: bind.childNodes[i].getAttribute("id"), - required: bind.childNodes[i].getAttribute("xforms:required"), - nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"), - type: bind.childNodes[i].getAttribute("xforms:type"), - constraint: bind.childNodes[i].getAttribute("xforms:constraint"), - parent: parent + result[id] = + { + id: bind.childNodes[i].getAttribute("id"), + readonly: bind.childNodes[i].getAttribute("xforms:readonly"), + required: bind.childNodes[i].getAttribute("xforms:required"), + nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"), + type: bind.childNodes[i].getAttribute("xforms:type"), + constraint: bind.childNodes[i].getAttribute("xforms:constraint"), + parent: parent }; this._loadBindings(bind.childNodes[i], result[id], result); }