diff --git a/source/java/org/alfresco/web/forms/FormImpl.java b/source/java/org/alfresco/web/forms/FormImpl.java index 124e91f7c4..28b58b5d20 100644 --- a/source/java/org/alfresco/web/forms/FormImpl.java +++ b/source/java/org/alfresco/web/forms/FormImpl.java @@ -224,6 +224,15 @@ public class FormImpl "}"); } + public boolean equals(final Object other) + { + if (other == null || !(other instanceof FormImpl)) + { + return false; + } + return this.getNodeRef().equals(((FormImpl)other).getNodeRef()); + } + protected ServiceRegistry getServiceRegistry() { final FacesContext fc = FacesContext.getCurrentInstance(); diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java index a8d075fbc4..5dd3479aab 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java @@ -142,7 +142,6 @@ public class SchemaFormBuilder private final String action; private final SubmitMethod submitMethod; private final String base; - protected WrapperElementsBuilder wrapper = new XHTMLWrapperElementsBuilder(); /** * generic counter -> replaced by an hashMap with: @@ -167,22 +166,17 @@ public class SchemaFormBuilder /** * Creates a new SchemaFormBuilder object. * - * @param rootElementName _UNDOCUMENTED_ - * @param instanceSource _UNDOCUMENTED_ * @param action _UNDOCUMENTED_ * @param submitMethod _UNDOCUMENTED_ - * @param wrapper _UNDOCUMENTED_ */ public SchemaFormBuilder(final String action, final SubmitMethod submitMethod, - final WrapperElementsBuilder wrapper, final String base) { reset(); this.action = action; this.submitMethod = submitMethod; - this.wrapper = wrapper; this.base = base; } @@ -250,18 +244,19 @@ public class SchemaFormBuilder //refCounter = 0; this.counter.clear(); - final Document xForm = this.createFormTemplate(rootElementName); + final Document xformsDocument = this.createFormTemplate(rootElementName); //find form element: last element created final Element formSection = (Element) - xForm.getDocumentElement().getLastChild(); + xformsDocument.getDocumentElement().getLastChild(); final Element modelSection = (Element) - xForm.getDocumentElement().getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "model").item(0); + xformsDocument.getDocumentElement().getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, + "model").item(0); //add XMLSchema if we use schema types modelSection.setAttributeNS(NamespaceConstants.XFORMS_NS, "schema", "#schema-1"); final Element importedSchemaDocumentElement = (Element) - xForm.importNode(schemaDocument.getDocumentElement(), true); + xformsDocument.importNode(schemaDocument.getDocumentElement(), true); importedSchemaDocumentElement.setAttributeNS(null, "id", "schema-1"); modelSection.appendChild(importedSchemaDocumentElement); @@ -282,50 +277,55 @@ public class SchemaFormBuilder // this.targetNamespace); - //TODO: WARNING: in Xerces 2.6.1, parameters are switched !!! (name, namespace) - //XSElementDeclaration rootElementDecl =schema.getElementDeclaration(this.targetNamespace, _rootElementName); - XSElementDeclaration rootElementDecl = + final XSElementDeclaration rootElementDecl = schema.getElementDeclaration(rootElementName, this.targetNamespace); - if (rootElementDecl == null) { - //Debug - rootElementDecl = schema.getElementDeclaration(this.targetNamespace, - rootElementName); - if (rootElementDecl != null && LOGGER.isDebugEnabled()) - LOGGER.debug("getElementDeclaration: inversed parameters OK !!!"); - throw new FormBuilderException("Invalid root element tag name [" + rootElementName + ", targetNamespace=" + this.targetNamespace + "]"); } - rootElementName = this.getElementName(rootElementDecl, xForm); + + rootElementName = this.getElementName(rootElementDecl, xformsDocument); final Element instanceElement = - xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":instance"); + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":instance"); modelSection.appendChild(instanceElement); this.setXFormsId(instanceElement); - final Element defaultInstanceDocumentElement = xForm.createElement(rootElementName); + final Element defaultInstanceDocumentElement = xformsDocument.createElement(rootElementName); this.addNamespace(defaultInstanceDocumentElement, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, NamespaceConstants.XMLSCHEMA_INSTANCE_NS); - + if (this.targetNamespace != null) + { + this.addNamespace(defaultInstanceDocumentElement, + schemaDocument.lookupPrefix(this.targetNamespace), + this.targetNamespace); + this.addNamespace(xformsDocument.getDocumentElement(), + schemaDocument.lookupPrefix(this.targetNamespace), + this.targetNamespace); + } + Element importedInstanceDocumentElement = null; if (instanceDocument == null || instanceDocument.getDocumentElement() == null) + { instanceElement.appendChild(defaultInstanceDocumentElement); + } else { Element instanceDocumentElement = instanceDocument.getDocumentElement(); if (!instanceDocumentElement.getNodeName().equals(rootElementName)) + { throw new IllegalArgumentException("instance document root tag name invalid. " + "expected " + rootElementName + ", got " + instanceDocumentElement.getNodeName()); + } LOGGER.debug("importing rootElement from other document"); importedInstanceDocumentElement = (Element) - xForm.importNode(instanceDocumentElement, true); + xformsDocument.importNode(instanceDocumentElement, true); //add XMLSchema instance NS this.addNamespace(importedInstanceDocumentElement, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, @@ -333,21 +333,21 @@ public class SchemaFormBuilder instanceElement.appendChild(importedInstanceDocumentElement); final Element prototypeInstanceElement = - xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":instance"); + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":instance"); modelSection.appendChild(prototypeInstanceElement); this.setXFormsId(prototypeInstanceElement, "instance_prototype"); prototypeInstanceElement.appendChild(defaultInstanceDocumentElement); } - Element formContentWrapper = this.wrapper.createGroupContentWrapper(formSection); - this.addElement(xForm, + Element formContentWrapper = formSection; + this.addElement(xformsDocument, modelSection, defaultInstanceDocumentElement, formContentWrapper, schema, rootElementDecl, - "/" + getElementName(rootElementDecl, xForm), + "/" + getElementName(rootElementDecl, xformsDocument), resourceBundle); if (importedInstanceDocumentElement != null) { @@ -355,50 +355,16 @@ public class SchemaFormBuilder defaultInstanceDocumentElement); } - Element submitInfoElement = - xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":submission"); - modelSection.appendChild(submitInfoElement); - - //submitInfoElement.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":id","save"); - String submissionId = this.setXFormsId(submitInfoElement); - - //action - submitInfoElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":action", - this.action == null ? "" : this.base + this.action); - - //method - submitInfoElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":method", - (this.submitMethod != null - ? this.submitMethod - : SchemaFormBuilder.SubmitMethod.POST).toString()); - - final Element submitButton = - xForm.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":submit"); - final Element submitControlWrapper = this.wrapper.createControlsWrapper(submitButton); - formContentWrapper.appendChild(submitControlWrapper); - submitButton.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":submission", - submissionId); - this.setXFormsId(submitButton); - - final Element submitButtonCaption = - xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":label"); - submitButton.appendChild(submitButtonCaption); - submitButtonCaption.appendChild(xForm.createTextNode("Submit")); - this.setXFormsId(submitButtonCaption); - this.createTriggersForRepeats(xForm); + this.createSubmitElements(xformsDocument, modelSection, formContentWrapper); + this.createTriggersForRepeats(xformsDocument); final Comment comment = - xForm.createComment("This XForm was generated by " + this.getClass().getName() + - " on " + (new Date()) + " from the '" + rootElementName + - "' element of the '" + this.targetNamespace + "' XML Schema."); - xForm.getDocumentElement().insertBefore(comment, - xForm.getDocumentElement().getFirstChild()); - return xForm; + xformsDocument.createComment("This XForm was generated by " + this.getClass().getName() + + " on " + (new Date()) + " from the '" + rootElementName + + "' element of the '" + this.targetNamespace + "' XML Schema."); + xformsDocument.getDocumentElement().insertBefore(comment, + xformsDocument.getDocumentElement().getFirstChild()); + return xformsDocument; } /** @@ -888,8 +854,9 @@ public class SchemaFormBuilder Element groupWrapper = groupElement; if (groupElement != modelSection) - groupWrapper = this.wrapper.createGroupContentWrapper(groupElement); - + { + groupWrapper = groupElement; + } final SchemaUtil.Occurance o = SchemaUtil.getOccurance(owner); final Element repeatSection = this.addRepeatIfNecessary(xForm, modelSection, @@ -902,7 +869,7 @@ public class SchemaFormBuilder if (repeatSection != groupWrapper) { // we have a repeat - repeatContentWrapper = this.wrapper.createGroupContentWrapper(repeatSection); + repeatContentWrapper = repeatSection; relative = true; } @@ -1278,11 +1245,8 @@ public class SchemaFormBuilder constraint); } - Element choicesControlWrapper = this.wrapper.createControlsWrapper(choices); - control.appendChild(choicesControlWrapper); - - Element controlWrapper = this.wrapper.createControlsWrapper(control); - formSection.appendChild(controlWrapper); + control.appendChild(choices); + formSection.appendChild(control); ///////////////// /////////////// // add content to select1 @@ -1322,9 +1286,7 @@ public class SchemaFormBuilder NamespaceConstants.XFORMS_PREFIX + ":switch"); this.setXFormsId(switchElement); - Element switchControlWrapper = - this.wrapper.createControlsWrapper(switchElement); - formSection.appendChild(switchControlWrapper); + formSection.appendChild(switchElement); //formSection.appendChild(switchElement); /////////////// add this type ////////////// @@ -1539,8 +1501,7 @@ public class SchemaFormBuilder //selector -> no more needed? //this.addSelector(xForm, repeatSection); //group wrapper - repeatContentWrapper = - this.wrapper.createGroupContentWrapper(repeatSection); + repeatContentWrapper = repeatSection; } if (LOGGER.isDebugEnabled()) @@ -1758,9 +1719,7 @@ public class SchemaFormBuilder NamespaceConstants.XFORMS_PREFIX + ":appearance", "full"); - final Element controlWrapper = - this.wrapper.createControlsWrapper(repeatSection); - formSection.appendChild(controlWrapper); + formSection.appendChild(repeatSection); //add a group inside the repeat? final Element group = xForm.createElementNS(NamespaceConstants.XFORMS_NS, @@ -1812,9 +1771,7 @@ public class SchemaFormBuilder (XSElementDeclaration)owner, resourceBundle); //set content - formSection = (groupElement == modelSection - ? groupElement - : this.wrapper.createGroupContentWrapper(groupElement)); + formSection = groupElement; } //eventual repeat @@ -1832,7 +1789,7 @@ public class SchemaFormBuilder if (repeatSection != formSection) { //content of repeat - contentWrapper = this.wrapper.createGroupContentWrapper(repeatSection); + contentWrapper = repeatSection; //if there is a repeat -> create another bind with "." Element bindElement2 = @@ -1860,7 +1817,7 @@ public class SchemaFormBuilder bindElement, o, resourceBundle); - contentWrapper.appendChild(this.wrapper.createControlsWrapper(formControl)); + contentWrapper.appendChild(formControl); // if this is a repeatable then set ref to point to current element // not sure if this is a workaround or this is just the way XForms works... @@ -1878,9 +1835,6 @@ public class SchemaFormBuilder //if (repeatSection != formSection) //this.addSelector(xForm, (Element) formControl.getParentNode()); // - // TODO: Generate help message based on datatype and restrictions - this.endFormControl(formControl, controlType, o); - this.endBindElement(bindElement); } private void addSimpleType(final Document xForm, @@ -1966,7 +1920,6 @@ public class SchemaFormBuilder (XSSimpleTypeDefinition)controlType); } - this.startFormControl(formControl, controlType); formControl.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":bind", bindId); @@ -2063,7 +2016,14 @@ public class SchemaFormBuilder { final Document xformsDocument = XMLUtil.newDocument(); - final Element envelopeElement = this.wrapper.createEnvelope(xformsDocument); + final Element envelopeElement = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, + NamespaceConstants.XHTML_PREFIX + ":html"); + xformsDocument.appendChild(envelopeElement); + + //set namespace attribute + this.addNamespace(envelopeElement, + NamespaceConstants.XHTML_PREFIX, + NamespaceConstants.XHTML_NS); this.addNamespace(envelopeElement, NamespaceConstants.XFORMS_PREFIX, NamespaceConstants.XFORMS_NS); @@ -2079,22 +2039,27 @@ public class SchemaFormBuilder //base if (this.base != null && this.base.length() != 0) + { envelopeElement.setAttributeNS(NamespaceConstants.XML_NS, NamespaceConstants.XML_PREFIX + ":base", this.base); + } //model element Element modelElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":model"); this.setXFormsId(modelElement); - Element modelWrapper = this.wrapper.createModelWrapper(modelElement); + Element modelWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, + NamespaceConstants.XHTML_PREFIX + ":head"); + modelWrapper.appendChild(modelElement); envelopeElement.appendChild(modelWrapper); //form control wrapper -> created by wrapper //Element formWrapper = xformsDocument.createElement("body"); //envelopeElement.appendChild(formWrapper); - Element formWrapper = this.wrapper.createFormWrapper(envelopeElement); - + Element formWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, + NamespaceConstants.XHTML_PREFIX + ":body"); + envelopeElement.appendChild(formWrapper); return xformsDocument; } @@ -2108,26 +2073,17 @@ public class SchemaFormBuilder Element groupElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":group"); - groupElement = startFormGroup(groupElement, owner); - - if (groupElement == null) - groupElement = modelSection; - else - { - this.setXFormsId(groupElement); - - Element controlsWrapper = this.wrapper.createControlsWrapper(groupElement); - - //groupElement = (Element) formSection.appendChild(groupElement); - formSection.appendChild(controlsWrapper); - - Element captionElement = - xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":label"); - groupElement.appendChild(captionElement); - this.setXFormsId(captionElement); - captionElement.appendChild(xformsDocument.createTextNode(this.createCaption(owner, resourceBundle))); - } + this.setXFormsId(groupElement); + + //groupElement = (Element) formSection.appendChild(groupElement); + formSection.appendChild(groupElement); + + Element captionElement = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":label"); + groupElement.appendChild(captionElement); + this.setXFormsId(captionElement); + captionElement.appendChild(xformsDocument.createTextNode(this.createCaption(owner, resourceBundle))); return groupElement; } @@ -2557,31 +2513,6 @@ public class SchemaFormBuilder : null))); } - /** - * This method is invoked after the form builder is finished creating and processing - * a bind element. Implementations may choose to use this method to add/inspect/modify - * the bindElement prior to the builder moving onto the next bind element. - * - * @param bindElement The bind element being processed. - */ - public void endBindElement(Element bindElement) - { - } - - /** - * This method is invoked after the form builder is finished creating and processing - * a form control. Implementations may choose to use this method to add/inspect/modify - * the controlElement prior to the builder moving onto the next control. - * - * @param controlElement The form control element that was created. - * @param controlType The XML Schema type for which controlElement was created. - */ - public void endFormControl(Element controlElement, - XSTypeDefinition controlType, - SchemaUtil.Occurance occurs) - { - } - /** * This method is invoked after an xforms:bind element is created for the specified SimpleType. * The implementation is responsible for setting setting any/all bind attributes @@ -2690,43 +2621,6 @@ public class SchemaFormBuilder return bindElement; } - /** - * This method is invoked after the form builder creates a form control - * via a createControlForXXX() method but prior to decorating the form control - * with common attributes such as a caption, hint, help text elements, - * bind attributes, etc. - * The returned element is used in the XForm in place of controlElement. - * Implementations may choose to use this method to substitute controlElement - * with a different element, or perform any other processing on controlElement - * prior to it being added to the form. - * - * @param controlElement The form control element that was created. - * @param controlType The XML Schema type for which controlElement was created. - * @return The Element to use in the XForm - controlElement or a replacement. - */ - public Element startFormControl(Element controlElement, - XSTypeDefinition controlType) - { - return controlElement; - } - - /** - * This method is invoked after an xforms:group element is created for the specified - * ElementDecl. A group is created whenever an element is encountered in the XML Schema - * that contains other elements and attributes (complex types or mixed content types). - * The caller automatically adds the returned element to the XForm. - * - * @param groupElement The groupElement being processed. - * @param schemaElement The schemaElement for the group. - * @return The group Element to use in the XForm - groupElement or a replacement. If a null - * value is returned, the group is not created. - */ - public Element startFormGroup(Element groupElement, - XSElementDeclaration schemaElement) - { - return groupElement; - } - /** * Get a fully qualified name for this element, and eventually declares a new prefix for the namespace if * it was not declared before @@ -2766,10 +2660,14 @@ public class SchemaFormBuilder final String nsPrefix, final String ns) { + if (!e.hasAttributeNS(NamespaceConstants.XMLNS_NS, nsPrefix)) + { + LOGGER.debug("adding namespace " + ns + " to " + e.getNodeType() + "(" + e.getNodeName() + ")"); e.setAttributeNS(NamespaceConstants.XMLNS_NS, NamespaceConstants.XMLNS_PREFIX + ':' + nsPrefix, ns); + } } private void createTriggersForRepeats(final Document xformsDocument) @@ -2929,27 +2827,79 @@ public class SchemaFormBuilder final Element formSection = (Element)xformsDocument.getDocumentElement().getLastChild(); //add the triggers - final Element wrapper_triggers = - this.wrapper.createControlsWrapper(trigger_insert_before); + formSection.appendChild(trigger_insert_before); + formSection.appendChild(trigger_insert_after); + formSection.appendChild(trigger_delete); + } - if (wrapper_triggers == trigger_insert_before) - { - //no wrapper - formSection.appendChild(trigger_insert_before); - formSection.appendChild(trigger_insert_after); - formSection.appendChild(trigger_delete); - } - else - { - formSection.appendChild(wrapper_triggers); - final Element insert_parent = (Element)trigger_insert_before.getParentNode(); + private Element createSubmissionElement(final Document xformDocument, + final String id, + final boolean validate) + { + final Element result = xformDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":submission"); + + this.setXFormsId(result, id); - if (insert_parent != null) - { - insert_parent.appendChild(trigger_insert_after); - insert_parent.appendChild(trigger_delete); - } - } + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":validate", + validate ? "true" : "false"); + + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":action", + this.action == null ? "" : this.base + this.action); + + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":method", + (this.submitMethod != null + ? this.submitMethod + : SchemaFormBuilder.SubmitMethod.POST).toString()); + return result; + } + + private Element createSubmitControl(final Document xformsDocument, + final Element submission, + final String id, + final String label) + { + final Element result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":submit"); + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":submission", + submission.getAttributeNS(null, "id")); + this.setXFormsId(result, id); + + final Element caption = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":label"); + result.appendChild(caption); + caption.appendChild(xformsDocument.createTextNode(label)); + this.setXFormsId(caption); + return result; + } + + private void createSubmitElements(final Document xformsDocument, + final Element modelSection, + final Element formSection) + { + + Element submission = this.createSubmissionElement(xformsDocument, "submission-validate", true); + modelSection.appendChild(submission); + + Element submit = this.createSubmitControl(xformsDocument, + submission, + "submit", + "Submit"); + formSection.appendChild(submit); + + submission = this.createSubmissionElement(xformsDocument, "submission-draft", false); + modelSection.appendChild(submission); + + submit = this.createSubmitControl(xformsDocument, + submission, + "save-draft", + "Save Draft"); + formSection.appendChild(submit); } private Element createXFormsItem(final Document xformsDocument, diff --git a/source/java/org/alfresco/web/forms/xforms/WrapperElementsBuilder.java b/source/java/org/alfresco/web/forms/xforms/WrapperElementsBuilder.java deleted file mode 100644 index 37b3b7b013..0000000000 --- a/source/java/org/alfresco/web/forms/xforms/WrapperElementsBuilder.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2005 Alfresco, Inc. - * - * Licensed under the Mozilla Public License version 1.1 - * with a permitted attribution clause. You may obtain a - * copy of the License at - * - * http://www.alfresco.org/legal/license.txt - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific - * language governing permissions and limitations under the - * License. - */ -package org.alfresco.web.forms.xforms; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * This interface provides methods to create the "wrappers" elements that will contain the XForms document. - * These elements can be: - * - the first "enveloppe" element - * - other elements specific to a destination language or platform (ex: XHTML tags) - * - * @author Sophie Ramel - */ -public interface WrapperElementsBuilder -{ - - /** - * create the wrapper element of the form (exemple_ "body" for HTML) - * - * @param enveloppeElement the containing enveloppe - * @return the wrapper element, already added in the enveloppe - */ - public Element createFormWrapper(Element enveloppeElement); - - /** - * create the wrapper element of the different controls - * - * @param controlElement the control element (input, select, repeat, group, ...) - * @return the wrapper element, already containing the control element - */ - public Element createControlsWrapper(Element controlElement); - - /** - * creates the global enveloppe of the resulting document, and puts it in the document - * - * @return the enveloppe - */ - public Element createEnvelope(Document xForm); - - /** - * create the element that will contain the content of the group (or repeat) element - * - * @param groupElement the group or repeat element - * @return - the wrapper element, already containing the content of the group element - */ - public Element createGroupContentWrapper(Element groupElement); - - /** - * create the wrapper element of the xforms:model element - * - * @param modelElement the xforms:model element - * @return - the wrapper element, already containing the model - */ - public Element createModelWrapper(Element modelElement); -} diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index a2054173ac..a77b068539 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -112,7 +112,6 @@ public class XFormsBean this.schemaFormBuilder = new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction", SchemaFormBuilder.SubmitMethod.POST, - new XHTMLWrapperElementsBuilder(), baseUrl); } diff --git a/source/java/org/alfresco/web/forms/xforms/XHTMLWrapperElementsBuilder.java b/source/java/org/alfresco/web/forms/xforms/XHTMLWrapperElementsBuilder.java deleted file mode 100644 index 55feb05b34..0000000000 --- a/source/java/org/alfresco/web/forms/xforms/XHTMLWrapperElementsBuilder.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2005 Alfresco, Inc. - * - * Licensed under the Mozilla Public License version 1.1 - * with a permitted attribution clause. You may obtain a - * copy of the License at - * - * http://www.alfresco.org/legal/license.txt - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific - * language governing permissions and limitations under the - * License. - */ -package org.alfresco.web.forms.xforms; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; -import org.chiba.xml.ns.NamespaceConstants; -import java.util.*; - -/** - * XHTML implementation of WrapperElementsBuilder: allows to wrap the XForm document in XHTML tags. - * - * @author Sophie Ramel - */ -public class XHTMLWrapperElementsBuilder - implements WrapperElementsBuilder -{ - - //////////////////////////////////////////////////////////////////////////// - - private static class Link - { - public final String href; - public final String type; - public final String rel; - - public Link(final String href, final String type, final String rel) - { - this.href = href; - this.type = type; - this.rel = rel; - } - } - - //////////////////////////////////////////////////////////////////////////// - - private static class Meta - { - public final String httpEquiv; - public final String name; - public final String content; - public final String scheme; - - public Meta(final String httpEquiv, - final String name, - final String content, - final String scheme) - { - this.httpEquiv = httpEquiv; - this.name = name; - this.content = content; - this.scheme = scheme; - } - } - - //////////////////////////////////////////////////////////////////////////// - - private String title; - private final Collection links = new LinkedList(); - private final Collection meta = new LinkedList(); - private final HashMap namespaces = - new HashMap(); - - /** - * Creates a new instance of XHTMLWrapperElementsBuilder - */ - public XHTMLWrapperElementsBuilder() { } - - /** - * add a tag "title" in the header of the HTML document - */ - public void setTitle(String title) - { - this.title = title; - } - - /** - * add a tag "link" in the header of the HTML document - * - * @param href the "href" parameter of the "link" tag - * @param type the "type" parameter of the "link" tag - * @param rel the "rel" parameter of the "link" tag - */ - public void addLink(final String href, - final String type, - final String rel) - { - links.add(new Link(href, type, rel)); - } - - /** - * add a tag "meta" in the header of the HTML document - * - * @param http_equiv the "http-equiv" parameter of the "META" tag - * @param name the "name" parameter of the "META" tag - * @param content the "content" parameter of the "META" tag - * @param scheme the "scheme" parameter of the "META" tag - */ - public void addMeta(final String httpEquiv, - final String name, - final String content, - final String scheme) - { - meta.add(new Meta(httpEquiv, name, content, scheme)); - } - - public void addNamespaceDeclaration(final String prefix, - final String url) - { - namespaces.put(prefix, url); - } - - /** - * create the wrapper element of the different controls - * - * @param controlElement the control element (input, select, repeat, group, ...) - * @return the wrapper element, already containing the control element - */ - public Element createControlsWrapper(final Element controlElement) - { - return controlElement; - } - - /** - * creates the global enveloppe of the resulting document, and puts it in the document - * - * @return the enveloppe - */ - public Element createEnvelope(Document doc) - { - final Element html = doc.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":html"); - //set namespace attribute - html.setAttributeNS(NamespaceConstants.XMLNS_NS, - NamespaceConstants.XMLNS_PREFIX + ':' + NamespaceConstants.XHTML_PREFIX, - NamespaceConstants.XHTML_NS); - doc.appendChild(html); - - //other namespaces - for (String prefix : this.namespaces.keySet()) - { - html.setAttributeNS(NamespaceConstants.XMLNS_NS, - NamespaceConstants.XMLNS_PREFIX + ":" + prefix, - this.namespaces.get(prefix)); - - } - return html; - } - - /** - * create the element that will contain the content of the group (or repeat) element - * - * @param groupElement the group or repeat element - * @return the wrapper element - */ - public Element createGroupContentWrapper(Element groupElement) - { - return groupElement; - } - - /** - * create the wrapper element of the form - * - * @param enveloppeElement the form element (chiba:form or other) - * @return the wrapper element - */ - public Element createFormWrapper(Element enveloppeElement) - { - Document doc = enveloppeElement.getOwnerDocument(); - Element body = doc.createElementNS(NamespaceConstants.XHTML_NS, NamespaceConstants.XHTML_PREFIX + ":body"); - //body.appendChild(formElement); - enveloppeElement.appendChild(body); - return body; - } - - /** - * create the wrapper element of the xforms:model element - * - * @param modelElement the xforms:model element - * @return the wrapper element, already containing the model - */ - public Element createModelWrapper(final Element modelElement) - { - Document doc = modelElement.getOwnerDocument(); - Element head = doc.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":head"); - head.appendChild(modelElement); - - //eventually add other info - if (title != null && title.length() != 0) - { - final Element title_el = doc.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":title"); - title_el.appendChild(doc.createTextNode(title)); - head.appendChild(title_el); - } - - for (Meta m : this.meta) - { - final Element meta_el = doc.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":META"); - head.appendChild(meta_el); - - //attributes - if (m.httpEquiv != null && m.httpEquiv.length() != 0) - { - meta_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":http-equiv", - m.httpEquiv); - } - if (m.name != null && m.name.length() != 0) - { - meta_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":name", - m.name); - } - if (m.content != null && m.content.length() != 0) - { - meta_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":content", - m.content); - } - if (m.scheme != null && m.scheme.length() != 0) - { - meta_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":scheme", - m.scheme); - } - } - - for (Link l : this.links) - { - final Element link_el = doc.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":LINK"); - head.appendChild(link_el); - - //attributes - if (l.href != null && l.href.length() != 0) - { - link_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":href", - l.href); - } - if (l.type != null && l.type.length() != 0) - { - link_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":type", - l.type); - } - if (l.rel != null && l.rel.length() != 0) - { - link_el.setAttributeNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":rel", - l.rel); - - } - } - return head; - } -} diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java b/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java index ef10d31f38..a192d1c527 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIFormProcessor.java @@ -91,9 +91,12 @@ public class UIFormProcessor final FormProcessor fp = form.getFormProcessors().get(0); final FormProcessor.Session fps = this.getFormProcessorSession(); final Document fid = this.getFormInstanceData(); + try { - if (fps != null && fps.getFormInstanceData().equals(fid)) + if (fps != null && + fps.getForm().equals(form) && + fps.getFormInstanceData().equals(fid)) { LOGGER.debug("reusing form processor session " + fps); fp.process(this.formProcessorSession, out); @@ -103,6 +106,8 @@ public class UIFormProcessor if (fps != null) { this.setFormProcessorSession(null); + LOGGER.debug("clearing form instance data " + fid); + fid.removeChild(fid.getDocumentElement()); } LOGGER.debug("creating a new session for " + fid); this.setFormProcessorSession(fp.process(fid, @@ -196,6 +201,7 @@ public class UIFormProcessor { if (formProcessorSession == null && this.formProcessorSession != null) { + LOGGER.debug("destroying old session " + this.formProcessorSession); this.formProcessorSession.destroy(); } this.formProcessorSession = formProcessorSession; diff --git a/source/test-resources/xforms/customer-tests/eyestreet-footer.xsd b/source/test-resources/xforms/customer-tests/eyestreet-footer.xsd index 1cefc3a016..1d8a8a8f9e 100644 --- a/source/test-resources/xforms/customer-tests/eyestreet-footer.xsd +++ b/source/test-resources/xforms/customer-tests/eyestreet-footer.xsd @@ -1,13 +1,13 @@ - + diff --git a/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp b/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp index c83e1f30e4..e163ec4827 100644 --- a/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp +++ b/source/web/jsp/wcm/create-web-content-wizard/create-xml.jsp @@ -26,6 +26,10 @@ function _xforms_getSubmitButtons() return [ document.getElementById("wizard:next-button"), document.getElementById("wizard:finish-button") ]; } +function _xforms_getSaveDraftButtons() +{ + return [ document.getElementById("wizard:back-button") ]; +} diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index 15b9dc51ff..3dc9d60924 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -1487,31 +1487,41 @@ dojo.declare("alfresco.xforms.Submit", { initializer: function(xform, xformsNode) { - var submit_buttons = _xforms_getSubmitButtons(); + var submit_buttons = (this.id == "submit" + ? _xforms_getSubmitButtons() + : (this.id == "save-draft" + ? _xforms_getSaveDraftButtons() + : null)); + if (submit_buttons == null) + { + throw new Error("unknown submit button " + this.id); + } for (var i = 0; i < submit_buttons.length; i++) { dojo.debug("adding submit handler for " + submit_buttons[i].getAttribute('id')); - submit_buttons[i].xform = this.xform; + submit_buttons[i].widget = this; dojo.event.browser.addListener(submit_buttons[i], "onclick", function(event) { - var xform = event.target.xform; - if (!xform.submitWidget.done) + var xform = event.target.widget.xform; + if (xform.submitWidget && xform.submitWidget.done) + { + dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id); + xform.submitWidget.currentButton = null; + xform.submitWidget = null; + return true; + } + else { dojo.debug("triggering submit from handler " + event.target.id); dojo.event.browser.stopEvent(event); _hide_errors(); + xform.submitWidget = event.target.widget; xform.submitWidget.currentButton = event.target; xform.submitWidget.widget.buttonClick(); return false; } - else - { - dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id); - xform.submitWidget.currentButton = null; - return true; - } }, false); } @@ -1519,7 +1529,6 @@ dojo.declare("alfresco.xforms.Submit", render: function(attach_point) { this.inherited("render", [ attach_point ]); - this.xform.submitWidget = this; }, _clickHandler: function(event) { @@ -1975,6 +1984,7 @@ dojo.declare("alfresco.xforms.XForm", } case "xforms-submit-error": { + this.submitWidget = null; var invalid = this.rootWidget.getWidgetsInvalidForSubmit(); _show_error(document.createTextNode("Please provide values for all required fields.")); var error_list = document.createElement("ul"); @@ -2156,8 +2166,8 @@ function _evaluateXPath(xpath, contextNode, result_type) if (xmlDocument.evaluate) { var nsResolver = (xmlDocument.createNSResolver - ? xmlDocument.createNSResolver(xmlDocument.documentElement) : - null); + ? xmlDocument.createNSResolver(xmlDocument.documentElement) + : null); result = xmlDocument.evaluate(xpath, contextNode, nsResolver,