Merged V2.1 to HEAD

6293: WCM fixes by Ariel (no details)
   6294: Fogotten file for above


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6717 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-09-10 12:26:25 +00:00
parent 03afc572b3
commit 10236f165a
47 changed files with 1596 additions and 718 deletions

View File

@@ -19,7 +19,8 @@
* 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;
import java.io.IOException;
@@ -82,7 +83,8 @@ public interface FormInstanceData
/////////////////////////////////////////////////////////////////////////////
/** the form generate this form instance data */
public Form getForm();
public Form getForm()
throws FormNotFoundException;
/** the name of this instance data */
public String getName();
@@ -104,7 +106,8 @@ public interface FormInstanceData
throws IOException, SAXException;
/** Regenerates all renditions of this form instance data */
public List<RegenerateResult> regenerateRenditions();
public List<RegenerateResult> regenerateRenditions()
throws FormNotFoundException;
/** returns all renditions of this form instance data */
public List<Rendition> getRenditions();

View File

@@ -101,12 +101,17 @@ public class FormInstanceDataImpl
}
public Form getForm()
throws FormNotFoundException
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final String parentFormName = (String)
nodeService.getProperty(this.nodeRef,
WCMAppModel.PROP_PARENT_FORM_NAME);
return FormsService.getInstance().getForm(parentFormName);
final String parentFormName = this.getParentFormName();
try
{
return FormsService.getInstance().getForm(parentFormName);
}
catch (FormNotFoundException fnfe)
{
throw new FormNotFoundException(parentFormName, this);
}
}
/** the node ref containing the contents of this rendition */
@@ -121,8 +126,8 @@ public class FormInstanceDataImpl
}
public List<FormInstanceData.RegenerateResult> regenerateRenditions()
throws FormNotFoundException
{
if (LOGGER.isDebugEnabled())
LOGGER.debug("regenerating renditions of " + this);
String originalParentAvmPath = (String)
@@ -211,12 +216,28 @@ public class FormInstanceDataImpl
public int hashCode()
{
return this.getPath().hashCode() ^ this.getForm().hashCode();
return this.getPath().hashCode();
}
public String toString()
{
return (this.getClass().getName() + "{path : " + this.getPath() +
", form : " + this.getForm().getName() + "}");
try
{
return (this.getClass().getName() + "{path : " + this.getPath() +
", form : " + this.getForm().getName() + "}");
}
catch (FormNotFoundException fnfe)
{
return (this.getClass().getName() + "{path : " + this.getPath() +
", form : " + this.getParentFormName() + " NOT_FOUND! }");
}
}
protected String getParentFormName()
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
return (String) nodeService.getProperty(this.nodeRef,
WCMAppModel.PROP_PARENT_FORM_NAME);
}
}

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* 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"
*/
package org.alfresco.web.forms;
import java.io.FileNotFoundException;
import java.text.MessageFormat;
import javax.faces.context.FacesContext;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.wcm.WebProject;
/**
* Error when a form cannot be resolved.
*
* @author Ariel Backenroth
*/
public class FormNotFoundException
extends FileNotFoundException
{
private final String formName;
private final WebProject webProject;
private final FormInstanceData fid;
public FormNotFoundException(final String formName)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_not_found"),
formName));
this.formName = formName;
this.webProject = null;
this.fid = null;
}
public FormNotFoundException(final String formName, final FormInstanceData fid)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_not_found_for_form_instance_data"),
formName,
fid.getPath()));
this.formName = formName;
this.fid = fid;
this.webProject = null;
}
public FormNotFoundException(final String formName, final WebProject webProject)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_not_found_in_web_project"),
formName,
webProject.getName()));
this.formName = formName;
this.webProject = webProject;
this.fid = null;
}
public FormNotFoundException(final String formName, final WebProject webProject, final FormInstanceData fid)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_not_found_for_form_instance_data_in_web_project"),
formName,
webProject.getName(),
fid.getPath()));
this.formName = formName;
this.webProject = webProject;
this.fid = fid;
}
public FormNotFoundException(final Form form, final WebProject webProject)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_not_configured_for_web_project"),
form.getName(),
webProject.getName()));
this.formName = form.getName();
this.webProject = webProject;
this.fid = null;
}
public FormNotFoundException(final Form form, final WebProject webProject, final FormInstanceData fid)
{
super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
"form_associated_with_form_instance_data_not_configured_for_web_project"),
form.getName(),
fid.getPath(),
webProject.getName()));
this.formName = form.getName();
this.webProject = webProject;
this.fid = fid;
}
}

View File

@@ -211,6 +211,7 @@ public final class FormsService
* @return the form by name or <tt>null</tt> if not found
*/
public Form getForm(final String name)
throws FormNotFoundException
{
final SearchParameters sp = new SearchParameters();
sp.addStore(Repository.getStoreRef());
@@ -230,9 +231,11 @@ public final class FormsService
break;
}
}
if (result == null && LOGGER.isDebugEnabled())
LOGGER.debug("unable to find template type " + name);
return result != null ? this.getForm(result) : null;
if (result == null)
{
throw new FormNotFoundException(name);
}
return this.getForm(result);
}
/**
@@ -244,11 +247,13 @@ public final class FormsService
*/
public Form getForm(final NodeRef nodeRef)
{
if (LOGGER.isDebugEnabled())
LOGGER.debug("loading form for " + nodeRef);
if (!this.nodeService.hasAspect(nodeRef, WCMAppModel.ASPECT_FORM))
{
throw new IllegalArgumentException("node " + nodeRef + " is not a form");
}
final Form result = new FormImpl(nodeRef);
if (LOGGER.isDebugEnabled())
LOGGER.debug("loaded form " + result);
LOGGER.debug("loaded form " + result + " for noderef " + nodeRef);
return result;
}
}

View File

@@ -46,13 +46,14 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.wcm.AVMUtil;
import org.alfresco.web.forms.XMLUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xalan.extensions.ExpressionContext;
import org.apache.xpath.objects.XObject;
import org.apache.xml.dtm.ref.DTMNodeProxy;
import org.apache.xml.utils.Constants;
import org.springframework.util.StringUtils;
//import org.apache.xml.utils.QName;
import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeFilter;
@@ -318,7 +319,7 @@ public class XSLTRenderingEngine
compEl.appendChild(scriptEl);
}
docEl.setAttribute("exclude-result-prefixes",
StringUtils.arrayToDelimitedString(excludePrefixes.toArray(new String[excludePrefixes.size()]), " "));
StringUtils.join(excludePrefixes.toArray(new String[excludePrefixes.size()]), " "));
return result;
}

View File

@@ -19,7 +19,8 @@
* 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.File;
@@ -273,23 +274,27 @@ public class Schema2XForms
schema,
rootElementDecl,
"/" + this.getElementName(rootElementDecl, xformsDocument),
new SchemaUtil.Occurance(1, 1),
new SchemaUtil.Occurrence(1, 1),
resourceBundle);
if (rootGroup.getNodeName() != NamespaceConstants.XFORMS_PREFIX + ":group")
{
throw new FormBuilderException("Expected root form element to be a group. Generated a " +
rootGroup.getNodeName() + " instead");
throw new FormBuilderException("Expected root form element to be a " + NamespaceConstants.XFORMS_PREFIX +
":group, not a " + rootGroup.getNodeName() +
". Ensure that " + this.getElementName(rootElementDecl, xformsDocument) +
" is a concrete type that has no extensions. " +
"Types with extensions are not supported for " +
"the root element of a form.");
}
this.setXFormsId(rootGroup, "alfresco-xforms-root-group");
if (importedInstanceDocumentElement != null)
{
this.insertUpdatedNodes(importedInstanceDocumentElement,
defaultInstanceDocumentElement,
schemaNamespacesMap);
this.insertPrototypeNodes(importedInstanceDocumentElement,
defaultInstanceDocumentElement,
schemaNamespacesMap);
Schema2XForms.insertUpdatedNodes(importedInstanceDocumentElement,
defaultInstanceDocumentElement,
schemaNamespacesMap);
Schema2XForms.insertPrototypeNodes(importedInstanceDocumentElement,
defaultInstanceDocumentElement,
schemaNamespacesMap);
}
@@ -324,9 +329,9 @@ public class Schema2XForms
* @param schemaNamespaces the namespaces used by the instance document needed for
* initializing the xpath context.
*/
private void insertUpdatedNodes(final Element instanceDocumentElement,
final Element prototypeDocumentElement,
final HashMap<String, String> schemaNamespaces)
public static void insertUpdatedNodes(final Element instanceDocumentElement,
final Element prototypeDocumentElement,
final HashMap<String, String> schemaNamespaces)
{
LOGGER.debug("updating imported instance document");
final JXPathContext prototypeContext =
@@ -434,9 +439,9 @@ public class Schema2XForms
* @param schemaNamespaces the namespaces used by the instance document needed for
* initializing the xpath context.
*/
private void insertPrototypeNodes(final Element instanceDocumentElement,
final Element prototypeDocumentElement,
final HashMap<String, String> schemaNamespaces)
public static void insertPrototypeNodes(final Element instanceDocumentElement,
final Element prototypeDocumentElement,
final HashMap<String, String> schemaNamespaces)
{
final JXPathContext prototypeContext =
JXPathContext.newContext(prototypeDocumentElement);
@@ -605,7 +610,7 @@ public class Schema2XForms
}
}
public void removePrototypeNodes(final Element instanceDocumentElement)
public static void removePrototypeNodes(final Node instanceDocumentElement)
{
final Map<String, LinkedList<Element>> prototypes =
new HashMap<String, LinkedList<Element>>();
@@ -641,7 +646,7 @@ public class Schema2XForms
}
if (e.getParentNode() != null)
{
this.removePrototypeNodes(e);
Schema2XForms.removePrototypeNodes(e);
}
}
}
@@ -953,7 +958,7 @@ public class Schema2XForms
final XSComplexTypeDefinition controlType,
final XSElementDeclaration owner,
String pathToRoot,
final SchemaUtil.Occurance occurs,
final SchemaUtil.Occurrence occurs,
boolean relative,
final boolean checkIfExtension,
final ResourceBundle resourceBundle)
@@ -981,7 +986,7 @@ public class Schema2XForms
formSection,
owner,
resourceBundle);
// final SchemaUtil.Occurance o = SchemaUtil.getOccurance(owner);
// final SchemaUtil.Occurrence o = SchemaUtil.getOccurrence(owner);
final Element repeatSection = this.addRepeatIfNecessary(xformsDocument,
modelSection,
groupElement,
@@ -1000,7 +1005,7 @@ public class Schema2XForms
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("addComplexTypeChildren for " + controlType.getName() +
LOGGER.debug("addComplexType for " + controlType.getName() + "(" + pathToRoot + ")" +
" owner = " + (owner == null ? "null" : owner.getName()));
}
@@ -1081,6 +1086,26 @@ public class Schema2XForms
if (term instanceof XSModelGroup)
{
switch (((XSModelGroup)term).getCompositor())
{
case XSModelGroup.COMPOSITOR_CHOICE:
LOGGER.warn("term " + term.getName() + " of particle " + particle.getName() +
" of type " + controlType.getName() + " in " + owner.getName() +
" describes a " + NamespaceConstants.XMLSCHEMA_PREFIX +
":choice which is not yet supported, adding it as a " +
NamespaceConstants.XMLSCHEMA_PREFIX + ":sequence");
break;
case XSModelGroup.COMPOSITOR_ALL:
LOGGER.warn("term " + term.getName() + " of particle " + particle.getName() +
" of type " + controlType.getName() + " in " + owner.getName() +
" describes a " + NamespaceConstants.XMLSCHEMA_PREFIX +
":all which is not yet supported, adding it as a " +
NamespaceConstants.XMLSCHEMA_PREFIX + ":sequence");
break;
case XSModelGroup.COMPOSITOR_SEQUENCE:
break;
}
//call addGroup on this group
this.addGroup(xformsDocument,
modelSection,
@@ -1091,7 +1116,7 @@ public class Schema2XForms
controlType,
owner,
pathToRoot,
new SchemaUtil.Occurance(particle),
new SchemaUtil.Occurrence(particle),
checkIfExtension,
resourceBundle);
}
@@ -1115,7 +1140,7 @@ public class Schema2XForms
final XSModel schema,
final XSElementDeclaration elementDecl,
final String pathToRoot,
final SchemaUtil.Occurance occurs,
final SchemaUtil.Occurrence occurs,
final ResourceBundle resourceBundle)
throws FormBuilderException
{
@@ -1229,7 +1254,7 @@ public class Schema2XForms
}
else
{
// final SchemaUtil.Occurance occurs = SchemaUtil.getOccurance(elementDecl);
// final SchemaUtil.Occurrence occurs = SchemaUtil.getOccurrence(elementDecl);
//create the bind in case it is a repeat
LOGGER.debug("Adding empty bind for control " + controlType +
" type " + typeName +
@@ -1331,7 +1356,7 @@ public class Schema2XForms
(XSComplexTypeDefinition)controlType,
elementDecl,
pathToRoot,
SchemaUtil.getOccurance(elementDecl),
SchemaUtil.getOccurrence(elementDecl),
true,
false,
resourceBundle);
@@ -1379,7 +1404,7 @@ public class Schema2XForms
(XSComplexTypeDefinition) type,
elementDecl,
pathToRoot,
SchemaUtil.getOccurance(elementDecl),
SchemaUtil.getOccurrence(elementDecl),
true,
true,
resourceBundle);
@@ -1454,7 +1479,7 @@ public class Schema2XForms
final XSComplexTypeDefinition controlType,
final XSElementDeclaration owner,
final String pathToRoot,
final SchemaUtil.Occurance occurs,
final SchemaUtil.Occurrence occurs,
final boolean checkIfExtension,
final ResourceBundle resourceBundle)
throws FormBuilderException
@@ -1482,7 +1507,7 @@ public class Schema2XForms
{
final XSParticle currentNode = (XSParticle)particles.item(counter);
XSTerm term = currentNode.getTerm();
final SchemaUtil.Occurance childOccurs = new SchemaUtil.Occurance(currentNode);
final SchemaUtil.Occurrence childOccurs = new SchemaUtil.Occurrence(currentNode);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug(" : next term = " + term.getName() +
@@ -1625,16 +1650,16 @@ public class Schema2XForms
final XSModel schema,
final XSElementDeclaration element,
final String pathToRoot,
final SchemaUtil.Occurance occurs,
final SchemaUtil.Occurrence occurs,
final ResourceBundle resourceBundle)
throws FormBuilderException
{
LOGGER.debug("addElement to group " + element + " at " + pathToRoot);
//add it normally
final String elementName = this.getElementName(element, xformsDocument);
final String path = (pathToRoot.length() == 0
? elementName
: pathToRoot + "/" + elementName);
LOGGER.debug("addElement to group " + elementName + " at " + path);
final Element newDefaultInstanceElement = xformsDocument.createElement(elementName);
if (element.getConstraintType() != XSConstants.VC_NONE)
@@ -1653,7 +1678,7 @@ public class Schema2XForms
occurs,
resourceBundle);
// final SchemaUtil.Occurance occurs = SchemaUtil.getOccurance(element);
// final SchemaUtil.Occurrence occurs = SchemaUtil.getOccurrence(element);
LOGGER.debug("adding " + (occurs.maximum == 1
? 1
: occurs.minimum + 1) +
@@ -1699,7 +1724,7 @@ public class Schema2XForms
final Element formSection,
final XSTypeDefinition controlType,
final String pathToRoot,
final SchemaUtil.Occurance o)
final SchemaUtil.Occurrence o)
{
// add xforms:repeat section if this element re-occurs
@@ -1783,7 +1808,7 @@ public class Schema2XForms
final String owningElementName,
final XSObject owner,
final String pathToRoot,
final SchemaUtil.Occurance occurs,
final SchemaUtil.Occurrence occurs,
final ResourceBundle resourceBundle)
{
if (LOGGER.isDebugEnabled())
@@ -1887,7 +1912,7 @@ public class Schema2XForms
owningAttribute.getAttrDeclaration().getName(),
owningAttribute,
pathToRoot,
new SchemaUtil.Occurance(owningAttribute.getRequired() ? 1 : 0, 1),
new SchemaUtil.Occurrence(owningAttribute.getRequired() ? 1 : 0, 1),
resourceBundle);
}
@@ -1898,7 +1923,7 @@ public class Schema2XForms
final XSObject owner,
final String bindId,
final Element bindElement,
final SchemaUtil.Occurance o,
final SchemaUtil.Occurrence o,
final ResourceBundle resourceBundle)
{
Element formControl = null;
@@ -2123,6 +2148,10 @@ public class Schema2XForms
formSection.appendChild(result);
result.appendChild(this.createLabel(xformsDocument,
this.createCaption(owner, resourceBundle)));
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("created group " + XMLUtil.toString(result));
}
return result;
}
@@ -2718,7 +2747,7 @@ public class Schema2XForms
final XSModel schema,
final XSTypeDefinition controlType,
final XSObject owner,
final SchemaUtil.Occurance o)
final SchemaUtil.Occurrence o)
{
// START WORKAROUND
// Due to a Chiba bug, anyType is not a recognized type name.

View File

@@ -35,7 +35,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.forms.Form;
import org.springframework.util.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -198,7 +198,8 @@ public class Schema2XFormsProperties
public String toString()
{
return (this.getClass().getName() + "{" +
StringUtils.arrayToCommaDelimitedString(this.locations) +
StringUtils.join(this.locations, ",") +
"}");
}
}
}

View File

@@ -35,6 +35,8 @@ import org.apache.commons.jxpath.Pointer;
import org.chiba.xml.ns.NamespaceConstants;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* JUnit tests to exercise the the schema to xforms converter
@@ -45,6 +47,8 @@ public class Schema2XFormsTest
extends BaseTest
{
private final static Log LOGGER = LogFactory.getLog(Schema2XFormsTest.class);
public void testOneStringTestWithEmptyInstanceDocument()
throws Exception
{
@@ -88,61 +92,96 @@ public class Schema2XFormsTest
final Document xformsDocument = this.buildXForm(null, schemaDocument, "repeat-constraints-test");
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/one-to-inf",
new SchemaUtil.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/zero-to-inf",
new SchemaUtil.Occurance(0, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/one-to-five",
new SchemaUtil.Occurance(1, 5));
new SchemaUtil.Occurrence(1, 5));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/three-to-five",
new SchemaUtil.Occurance(3, 5));
new SchemaUtil.Occurrence(3, 5));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/zero-to-five",
new SchemaUtil.Occurance(0, 5));
new SchemaUtil.Occurrence(0, 5));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/referenced-string",
new SchemaUtil.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/nested-outer-zero-to-inf",
new SchemaUtil.Occurance(0, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(0, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/nested-outer-one-to-inf",
new SchemaUtil.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(0, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/nested-outer-three-to-five",
new SchemaUtil.Occurance(3, 5));
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.Occurance(0, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(1, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED));
this.assertRepeatProperties(xformsDocument,
"/repeat-constraints-test/nested-outer-outer-three-to-inf",
new SchemaUtil.Occurance(3, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(5, SchemaUtil.Occurance.UNBOUNDED));
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.Occurance(7, SchemaUtil.Occurance.UNBOUNDED));
new SchemaUtil.Occurrence(7, SchemaUtil.Occurrence.UNBOUNDED));
}
private void assertRepeatProperties(final Document xformsDocument, final String nodeset, final SchemaUtil.Occurance o)
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");
assertEquals(3, xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "input").getLength());
try
{
xformsDocument = this.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)
{
}
}
public void testSwitch()
throws Exception
{
final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/automated/switch-test.xsd");
final Document xformsDocument = this.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");
// fail("expected failure creating xform with root element with-extension-test in schema " + XMLUtil.toString(schemaDocument));
// }
// catch (FormBuilderException fbe)
// {
// }
}
private void assertRepeatProperties(final Document xformsDocument, final String nodeset, final SchemaUtil.Occurrence o)
{
final Element[] bindElements = this.resolveBind(xformsDocument, nodeset);
assertNotNull("unable to resolve bind for nodeset " + nodeset, bindElements);
@@ -182,7 +221,7 @@ public class Schema2XFormsTest
int nestingFactor = 1;
for (int i = 0; i < bindElements.length - 1; i++)
{
final SchemaUtil.Occurance parentO = this.occuranceFromBind(bindElements[i]);
final SchemaUtil.Occurrence parentO = this.occuranceFromBind(bindElements[i]);
if (parentO.isRepeated())
{
nestingFactor = nestingFactor * (1 + parentO.minimum);
@@ -283,15 +322,15 @@ public class Schema2XFormsTest
}
private SchemaUtil.Occurance occuranceFromBind(final Element bindElement)
private SchemaUtil.Occurrence occuranceFromBind(final Element bindElement)
{
return new SchemaUtil.Occurance(bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs")
? Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs"))
: 1,
bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")
? ("unbounded".equals(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs"))
? SchemaUtil.Occurance.UNBOUNDED
: Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")))
: 1);
return new SchemaUtil.Occurrence(bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs")
? Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs"))
: 1,
bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")
? ("unbounded".equals(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs"))
? SchemaUtil.Occurrence.UNBOUNDED
: Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")))
: 1);
}
}

View File

@@ -42,26 +42,26 @@ public class SchemaUtil
////////////////////////////////////////////////////////////////////////////
public static class Occurance
public static class Occurrence
{
public final static int UNBOUNDED = -1;
public final int minimum;
public final int maximum;
public Occurance(final XSParticle particle)
public Occurrence(final XSParticle particle)
{
this(particle.getMinOccurs(), (particle.getMaxOccursUnbounded()
? Occurance.UNBOUNDED
? Occurrence.UNBOUNDED
: particle.getMaxOccurs()));
}
public Occurance(final int minimum)
public Occurrence(final int minimum)
{
this(minimum, Occurance.UNBOUNDED);
this(minimum, Occurrence.UNBOUNDED);
}
public Occurance(final int minimum, final int maximum)
public Occurrence(final int minimum, final int maximum)
{
this.minimum = minimum;
this.maximum = maximum;
@@ -723,15 +723,15 @@ public class SchemaUtil
*
* @return a table containing minOccurs and MaxOccurs
*/
public static Occurance getOccurance(final XSElementDeclaration elDecl)
public static Occurrence getOccurrence(final XSElementDeclaration elDecl)
{
//get occurance on encosing element declaration
final XSParticle particle =
SchemaUtil.findCorrespondingParticleInComplexType(elDecl);
final Occurance result = particle == null ? new Occurance(1, 1) : new Occurance(particle);
final Occurrence result = particle == null ? new Occurrence(1, 1) : new Occurrence(particle);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("getOccurance for " + elDecl.getName() +
LOGGER.debug("getOccurrence for " + elDecl.getName() +
", " + result);
}
return result;

View File

@@ -69,10 +69,12 @@ import org.chiba.xml.events.XFormsEventNames;
import org.chiba.xml.events.XMLEvent;
import org.chiba.xml.xforms.ChibaBean;
import org.chiba.xml.xforms.XFormsElement;
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
import org.chiba.xml.xforms.connector.SubmissionHandler;
import org.chiba.xml.xforms.connector.AbstractConnector;
import org.chiba.xml.xforms.core.Instance;
import org.chiba.xml.xforms.core.ModelItem;
import org.chiba.xml.xforms.core.Model;
import org.chiba.xml.xforms.core.Submission;
import org.chiba.xml.xforms.core.UpdateHandler;
import org.chiba.xml.xforms.core.impl.DefaultValidatorMode;
import org.chiba.xml.xforms.exception.XFormsException;
@@ -96,6 +98,30 @@ import org.xml.sax.SAXException;
public class XFormsBean
{
/////////////////////////////////////////////////////////////////////////////
public static class AlfrescoSubmissionHandler
extends AbstractConnector
implements SubmissionHandler
{
public Map submit(final Submission submission,
final Node instance)
throws XFormsException
{
if (XFormsBean.LOGGER.isDebugEnabled())
{
XFormsBean.LOGGER.debug(this.getClass().getName() +
" recieved submission " + XMLUtil.toString(instance, true));
}
final FacesContext fc = FacesContext.getCurrentInstance();
//make the XFormsBean available for this session
final XFormsBean xforms = (XFormsBean)FacesHelper.getManagedBean(fc, "XFormsBean");
xforms.handleSubmit(instance);
return Collections.EMPTY_MAP;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
@@ -120,9 +146,9 @@ public class XFormsBean
this.formInstanceData = formInstanceData;
this.formInstanceDataName = formInstanceDataName;
this.form = form;
this.schema2XForms = new Schema2XForms("/ajax/invoke/XFormsBean.handleAction",
this.schema2XForms = new Schema2XForms(/* "/ajax/invoke/XFormsBean.handleAction" */ null,
Schema2XForms.SubmitMethod.POST,
baseUrl);
/* baseUrl */ "alfresco:" + XFormsBean.class.getName());
}
public void destroy()
@@ -206,7 +232,7 @@ public class XFormsBean
final ChibaBean chibaBean = new ChibaBean();
chibaBean.setConfig(servletContext.getRealPath("/WEB-INF/chiba.xml"));
XFormsBean.storeCookies(request.getCookies(), chibaBean);
// XFormsBean.storeCookies(request.getCookies(), chibaBean);
chibaBean.setXMLContainer(this.getXFormsDocument());
final EventTarget et = (EventTarget)
@@ -380,18 +406,8 @@ public class XFormsBean
final HttpServletRequest request = (HttpServletRequest)
context.getExternalContext().getRequest();
final Document result = XMLUtil.parse(request.getInputStream());
this.handleSubmit(result);
final Document instanceData = this.xformsSession.getFormInstanceData();
Element documentElement = instanceData.getDocumentElement();
if (documentElement != null)
{
instanceData.removeChild(documentElement);
}
documentElement = result.getDocumentElement();
this.xformsSession.schema2XForms.removePrototypeNodes(documentElement);
documentElement = (Element)instanceData.importNode(documentElement, true);
instanceData.appendChild(documentElement);
instanceData.normalizeDocument();
final ResponseWriter out = context.getResponseWriter();
XMLUtil.print(instanceData, out, false);
out.close();
@@ -402,6 +418,24 @@ public class XFormsBean
}
}
public void handleSubmit(Node result)
{
final Document instanceData = this.xformsSession.getFormInstanceData();
Element documentElement = instanceData.getDocumentElement();
if (documentElement != null)
{
instanceData.removeChild(documentElement);
}
if (result instanceof Document)
{
result = ((Document)result).getDocumentElement();
}
documentElement = (Element)instanceData.importNode(result.cloneNode(true), true);
Schema2XForms.removePrototypeNodes(documentElement);
instanceData.appendChild(documentElement);
instanceData.normalizeDocument();
}
/**
* Swaps model nodes to implement reordering within repeats.
*/
@@ -608,25 +642,25 @@ public class XFormsBean
* HTTPConnectors. Instance loading and submission then uses these cookies. Important for
* applications using auth.
*/
@SuppressWarnings("unchecked")
private static void storeCookies(final javax.servlet.http.Cookie[] cookiesIn,
final ChibaBean chibaBean){
if (cookiesIn != null) {
org.apache.commons.httpclient.Cookie[] commonsCookies =
new org.apache.commons.httpclient.Cookie[cookiesIn.length];
for (int i = 0; i < cookiesIn.length; i += 1) {
commonsCookies[i] =
new org.apache.commons.httpclient.Cookie(cookiesIn[i].getDomain(),
cookiesIn[i].getName(),
cookiesIn[i].getValue(),
cookiesIn[i].getPath(),
cookiesIn[i].getMaxAge(),
cookiesIn[i].getSecure());
}
chibaBean.getContext().put(AbstractHTTPConnector.REQUEST_COOKIE,
commonsCookies);
}
}
// @SuppressWarnings("unchecked")
// private static void storeCookies(final javax.servlet.http.Cookie[] cookiesIn,
// final ChibaBean chibaBean){
// if (cookiesIn != null) {
// org.apache.commons.httpclient.Cookie[] commonsCookies =
// new org.apache.commons.httpclient.Cookie[cookiesIn.length];
// for (int i = 0; i < cookiesIn.length; i += 1) {
// commonsCookies[i] =
// new org.apache.commons.httpclient.Cookie(cookiesIn[i].getDomain(),
// cookiesIn[i].getName(),
// cookiesIn[i].getValue(),
// cookiesIn[i].getPath(),
// cookiesIn[i].getMaxAge(),
// cookiesIn[i].getSecure());
// }
// chibaBean.getContext().put(AbstractHTTPConnector.REQUEST_COOKIE,
// commonsCookies);
// }
// }
private Document getXFormsDocument()
throws FormBuilderException