upgrading to chiba-1.3.0. there are several significant bug fixes that customers will notice - and several that make my life easier so i figure might as well go for it. things seem reasonably stable at this point so i'm comfortable with taking the hit sooner rather than later.

- adding chiba-1.3.0.jar in lib rather than chiba dir (removing chiba dir since we really only use one jar from them at this point)
- need to generate xform with unprefixed id attributes
- using a bunch of constants now defined within chiba.
- generating my own xpaths in js using binding nodesets since chiba remove the once useful chiba:xpath attribute.
- better error handling for breakage when processing schema and xform

fixing bug in create form details screen where form-name and form-title weren't being prefilled after uploading the schema.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4625 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-12-16 20:02:38 +00:00
parent 68a5004c3e
commit d318fea7a9
12 changed files with 764 additions and 781 deletions

View File

@@ -42,7 +42,6 @@
<fileset dir="${dir.common.lib}/treecache" includes="*.jar" /> <fileset dir="${dir.common.lib}/treecache" includes="*.jar" />
<fileset dir="${dir.common.lib}/swarmcache" includes="*.jar" /> <fileset dir="${dir.common.lib}/swarmcache" includes="*.jar" />
<fileset dir="${dir.common.lib}/jbpm" includes="*.jar" /> <fileset dir="${dir.common.lib}/jbpm" includes="*.jar" />
<fileset dir="${dir.common.lib}/chiba" includes="*.jar" />
<fileset dir="${dir.common.lib}/fop" includes="*.jar"/> <fileset dir="${dir.common.lib}/fop" includes="*.jar"/>
<fileset dir="${dir.project.core}/build/dist" includes="${dir.name.core}.jar" /> <fileset dir="${dir.project.core}/build/dist" includes="${dir.name.core}.jar" />
<fileset dir="${dir.project.repository}/build/dist" includes="${dir.name.repository}.jar" /> <fileset dir="${dir.project.repository}/build/dist" includes="${dir.name.repository}.jar" />

View File

@@ -18,13 +18,7 @@ package org.alfresco.web.bean.wcm;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent; import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent; import javax.faces.event.ValueChangeEvent;
@@ -76,6 +70,7 @@ public class CreateFormWizard
* Simple wrapper class to represent a form data renderer * Simple wrapper class to represent a form data renderer
*/ */
public class RenderingEngineTemplateData public class RenderingEngineTemplateData
implements Serializable
{ {
private final String fileName; private final String fileName;
private final File file; private final File file;
@@ -171,12 +166,13 @@ public class CreateFormWizard
protected ContentService contentService; protected ContentService contentService;
protected MimetypeService mimetypeService; protected MimetypeService mimetypeService;
protected WorkflowService workflowService; protected WorkflowService workflowService;
private DataModel renderingEngineTemplatesDataModel; private transient DataModel renderingEngineTemplatesDataModel;
private List<RenderingEngineTemplateData> renderingEngineTemplates = null; private List<RenderingEngineTemplateData> renderingEngineTemplates = null;
private String outputPathPatternForFormInstanceData = null; private String outputPathPatternForFormInstanceData = null;
private String outputPathPatternForRendition = null; private String outputPathPatternForRendition = null;
private String mimetypeForRendition = null; private String mimetypeForRendition = null;
private List<SelectItem> mimetypeChoices = null; private transient List<SelectItem> mimetypeChoices = null;
private transient List<SelectItem> schemaRootElementNameChoices = null;
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Wizard implementation // Wizard implementation
@@ -305,6 +301,7 @@ public class CreateFormWizard
this.removeUploadedSchemaFile(); this.removeUploadedSchemaFile();
this.removeUploadedRenderingEngineTemplateFile(); this.removeUploadedRenderingEngineTemplateFile();
this.schemaRootElementName = null; this.schemaRootElementName = null;
this.schemaRootElementNameChoices = null;
this.formName = null; this.formName = null;
this.formTitle = null; this.formTitle = null;
this.formDescription = null; this.formDescription = null;
@@ -472,6 +469,7 @@ public class CreateFormWizard
public String removeUploadedSchemaFile() public String removeUploadedSchemaFile()
{ {
clearUpload(FILE_SCHEMA); clearUpload(FILE_SCHEMA);
this.schemaRootElementNameChoices = null;
// refresh the current page // refresh the current page
return null; return null;
@@ -488,7 +486,10 @@ public class CreateFormWizard
return null; return null;
} }
public String validateSchema() /**
* Action handler called when the schema has been uploaded.
*/
public String schemaFileValueChanged(final ValueChangeEvent vce)
{ {
if (this.getSchemaFile() != null) if (this.getSchemaFile() != null)
{ {
@@ -692,9 +693,13 @@ public class CreateFormWizard
*/ */
public List<SelectItem> getSchemaRootElementNameChoices() public List<SelectItem> getSchemaRootElementNameChoices()
{ {
final List<SelectItem> result = new LinkedList<SelectItem>(); if (this.getSchemaFile() == null)
if (this.getSchemaFile() != null)
{ {
return Collections.EMPTY_LIST;
}
if (this.schemaRootElementNameChoices == null)
{
this.schemaRootElementNameChoices = new LinkedList<SelectItem>();
final FormsService ts = FormsService.getInstance(); final FormsService ts = FormsService.getInstance();
try try
{ {
@@ -704,7 +709,7 @@ public class CreateFormWizard
for (int i = 0; i < elementsMap.getLength(); i++) for (int i = 0; i < elementsMap.getLength(); i++)
{ {
final XSElementDeclaration e = (XSElementDeclaration)elementsMap.item(i); final XSElementDeclaration e = (XSElementDeclaration)elementsMap.item(i);
result.add(new SelectItem(e.getName(), e.getName())); this.schemaRootElementNameChoices.add(new SelectItem(e.getName(), e.getName()));
} }
} }
catch (Exception e) catch (Exception e)
@@ -714,7 +719,7 @@ public class CreateFormWizard
Utils.addErrorMessage(msg, e); Utils.addErrorMessage(msg, e);
} }
} }
return result; return this.schemaRootElementNameChoices;
} }
/** /**
@@ -722,7 +727,7 @@ public class CreateFormWizard
*/ */
public void setFormName(final String formName) public void setFormName(final String formName)
{ {
this.formName = formName; this.formName = formName != null && formName.length() != 0 ? formName : null;
} }
/** /**
@@ -759,7 +764,7 @@ public class CreateFormWizard
*/ */
public void setFormTitle(final String formTitle) public void setFormTitle(final String formTitle)
{ {
this.formTitle = formTitle; this.formTitle = formTitle != null && formTitle.length() != 0 ? formTitle : null;
} }
/** /**

View File

@@ -80,7 +80,7 @@ public class CreateWebContentWizard extends BaseContentWizard
protected String content = null; protected String content = null;
protected String formName; protected String formName;
protected List<SelectItem> createMimeTypes; protected transient List<SelectItem> createMimeTypes;
protected String createdPath = null; protected String createdPath = null;
protected List<Rendition> renditions = null; protected List<Rendition> renditions = null;
protected FormInstanceData formInstanceData = null; protected FormInstanceData formInstanceData = null;

View File

@@ -32,7 +32,6 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.bean.wcm.AVMConstants; import org.alfresco.web.bean.wcm.AVMConstants;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.chiba.xml.util.DOMUtil;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;

View File

@@ -18,10 +18,14 @@ package org.alfresco.web.forms.xforms;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import javax.faces.context.ExternalContext; import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter; import javax.faces.context.ResponseWriter;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
@@ -40,23 +44,29 @@ import org.alfresco.web.bean.wcm.AVMBrowseBean;
import org.alfresco.web.bean.wcm.AVMConstants; import org.alfresco.web.bean.wcm.AVMConstants;
import org.alfresco.web.forms.*; import org.alfresco.web.forms.*;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.servlet.ServletRequestContext; import org.apache.commons.fileupload.servlet.ServletRequestContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.chiba.xml.events.ChibaEventNames;
import org.chiba.xml.events.DOMEventNames;
import org.chiba.xml.events.XFormsEventNames;
import org.chiba.xml.events.XMLEvent;
import org.chiba.xml.xforms.ChibaBean; import org.chiba.xml.xforms.ChibaBean;
import org.chiba.xml.xforms.Instance;
import org.chiba.xml.xforms.XFormsElement; import org.chiba.xml.xforms.XFormsElement;
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector; import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
import org.chiba.xml.xforms.core.Instance;
import org.chiba.xml.xforms.core.ModelItem; import org.chiba.xml.xforms.core.ModelItem;
import org.chiba.xml.xforms.events.XFormsEvent;
import org.chiba.xml.xforms.events.XFormsEventFactory;
import org.chiba.xml.xforms.exception.XFormsException; import org.chiba.xml.xforms.exception.XFormsException;
import org.chiba.xml.xforms.ui.BoundElement; import org.chiba.xml.xforms.ui.BoundElement;
import org.chiba.xml.xforms.ui.Upload; import org.chiba.xml.xforms.ui.Upload;
import org.chiba.xml.ns.NamespaceConstants;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.w3c.dom.*; import org.w3c.dom.*;
import org.w3c.dom.bootstrap.DOMImplementationRegistry; import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.events.Event; import org.w3c.dom.events.Event;
@@ -85,7 +95,7 @@ public class XFormsBean
private ChibaBean chibaBean; private ChibaBean chibaBean;
private final SchemaFormBuilder schemaFormBuilder; private final SchemaFormBuilder schemaFormBuilder;
private final HashMap<String, NodeRef> uploads = new HashMap<String, NodeRef>(); private final HashMap<String, NodeRef> uploads = new HashMap<String, NodeRef>();
private final List<XFormsEvent> eventLog = new LinkedList<XFormsEvent>(); private final List<XMLEvent> eventLog = new LinkedList<XMLEvent>();
public XFormsSession(final Document formInstanceData, public XFormsSession(final Document formInstanceData,
final Form form, final Form form,
@@ -95,7 +105,7 @@ public class XFormsBean
this.form = form; this.form = form;
this.schemaFormBuilder = this.schemaFormBuilder =
new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction", new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction",
SchemaFormBuilder.SUBMIT_METHOD_POST, SchemaFormBuilder.SubmitMethod.POST,
new XHTMLWrapperElementsBuilder(), new XHTMLWrapperElementsBuilder(),
baseUrl); baseUrl);
} }
@@ -177,7 +187,8 @@ public class XFormsBean
/** @param xformsSession the current session */ /** @param xformsSession the current session */
public void setXFormsSession(final XFormsSession xformsSession) public void setXFormsSession(final XFormsSession xformsSession)
throws XFormsException throws FormBuilderException,
XFormsException
{ {
this.xformsSession = xformsSession; this.xformsSession = xformsSession;
@@ -185,87 +196,47 @@ public class XFormsBean
final ExternalContext externalContext = facesContext.getExternalContext(); final ExternalContext externalContext = facesContext.getExternalContext();
final HttpServletRequest request = (HttpServletRequest) final HttpServletRequest request = (HttpServletRequest)
externalContext.getRequest(); externalContext.getRequest();
final ServletContext servletContext = (ServletContext)
externalContext.getContext();
final ChibaBean chibaBean = new ChibaBean(); 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 String cwdAVMPath = this.avmBrowseBean.getCurrentPath(); final EventTarget et = (EventTarget)
chibaBean.getXMLContainer().getDocumentElement();
if (LOGGER.isDebugEnabled()) final EventListener el = new EventListener()
{ {
LOGGER.debug("building xform for schema " + this.xformsSession.form.getName() + public void handleEvent(final Event e)
" root element " + this.xformsSession.form.getSchemaRootElementName() +
" avm cwd " + cwdAVMPath);
}
final Locale locale = Application.getLanguage(facesContext);
final ResourceBundle resourceBundle =
this.schema2XFormsProperties.getResourceBundle(this.xformsSession.form,
locale);
try
{
final Document schemaDocument = this.xformsSession.form.getSchema();
XFormsBean.rewriteInlineURIs(schemaDocument, cwdAVMPath);
final Document xformsDocument =
this.xformsSession.schemaFormBuilder.buildXForm(this.xformsSession.formInstanceData,
schemaDocument,
this.xformsSession.form.getSchemaRootElementName(),
resourceBundle);
if (LOGGER.isDebugEnabled())
{ {
LOGGER.debug("generated xform: " + XFormsBean.LOGGER.debug("received event " + e);
FormsService.getInstance().writeXMLToString(xformsDocument)); XFormsBean.this.xformsSession.eventLog.add((XMLEvent)e);
} }
};
// interaction events my occur during init so we have to register before
et.addEventListener(ChibaEventNames.LOAD_URI, el, true);
et.addEventListener(ChibaEventNames.RENDER_MESSAGE, el, true);
et.addEventListener(ChibaEventNames.REPLACE_ALL, el, true);
chibaBean.setXMLContainer(xformsDocument); chibaBean.init();
final EventTarget et = (EventTarget) // register for notification events
chibaBean.getXMLContainer().getDocumentElement(); et.addEventListener(XFormsEventNames.SUBMIT, el, true);
final EventListener el = new EventListener() et.addEventListener(XFormsEventNames.SUBMIT_DONE, el, true);
{ et.addEventListener(XFormsEventNames.SUBMIT_ERROR, el, true);
public void handleEvent(final Event e) et.addEventListener(XFormsEventNames.REQUIRED, el, true);
{ et.addEventListener(XFormsEventNames.OPTIONAL, el, true);
XFormsBean.LOGGER.debug("received event " + e); et.addEventListener(XFormsEventNames.VALID, el, true);
XFormsBean.this.xformsSession.eventLog.add((XFormsEvent)e); et.addEventListener(XFormsEventNames.INVALID, el, true);
} et.addEventListener(XFormsEventNames.OUT_OF_RANGE, el, true);
}; et.addEventListener(ChibaEventNames.STATE_CHANGED, el, true);
// interaction events my occur during init so we have to register before et.addEventListener(ChibaEventNames.PROTOTYPE_CLONED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_LOAD_URI, el, true); et.addEventListener(ChibaEventNames.ID_GENERATED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, el, true); et.addEventListener(ChibaEventNames.ITEM_INSERTED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, el, true); et.addEventListener(ChibaEventNames.ITEM_DELETED, el, true);
et.addEventListener(ChibaEventNames.INDEX_CHANGED, el, true);
chibaBean.init(); et.addEventListener(ChibaEventNames.SWITCH_TOGGLED, el, true);
// register for notification events
et.addEventListener(XFormsEventFactory.SUBMIT_DONE, el, true);
et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, el, true);
et.addEventListener(XFormsEventFactory.REQUIRED, el, true);
et.addEventListener(XFormsEventFactory.OPTIONAL, el, true);
et.addEventListener(XFormsEventFactory.VALID, el, true);
et.addEventListener(XFormsEventFactory.INVALID, el, true);
et.addEventListener(XFormsEventFactory.OUT_OF_RANGE, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_STATE_CHANGED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_PROTOTYPE_CLONED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ID_GENERATED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_INSERTED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_DELETED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_INDEX_CHANGED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_SWITCH_TOGGLED, el, true);
}
catch (FormBuilderException fbe)
{
LOGGER.error(fbe);
}
catch (IOException ioe)
{
LOGGER.error(ioe);
}
catch (SAXException saxe)
{
LOGGER.error(saxe);
}
this.xformsSession.chibaBean = chibaBean; this.xformsSession.chibaBean = chibaBean;
} }
@@ -275,7 +246,6 @@ public class XFormsBean
*/ */
public static XFormsSession createSession(final Document formInstanceData, public static XFormsSession createSession(final Document formInstanceData,
final Form form) final Form form)
throws XFormsException
{ {
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
{ {
@@ -328,7 +298,7 @@ public class XFormsBean
LOGGER.debug(this + ".setXFormsValue(" + id + ", " + value + ")"); LOGGER.debug(this + ".setXFormsValue(" + id + ", " + value + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean; final ChibaBean chibaBean = this.xformsSession.chibaBean;
if (chibaBean.lookup(id) instanceof Upload) if (chibaBean.getContainer().lookup(id) instanceof Upload)
{ {
chibaBean.updateControlValue(id, null, value, value.getBytes()); chibaBean.updateControlValue(id, null, value, value.getBytes());
} }
@@ -380,7 +350,7 @@ public class XFormsBean
LOGGER.debug(this + ".fireAction(" + id + ")"); LOGGER.debug(this + ".fireAction(" + id + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean; final ChibaBean chibaBean = this.xformsSession.chibaBean;
chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE); chibaBean.dispatch(id, DOMEventNames.ACTIVATE);
final ResponseWriter out = context.getResponseWriter(); final ResponseWriter out = context.getResponseWriter();
FormsService.getInstance().writeXML(this.getEventLog(), out); FormsService.getInstance().writeXML(this.getEventLog(), out);
@@ -435,8 +405,8 @@ public class XFormsBean
final String toItemId = (String)requestParameters.get("toItemId"); final String toItemId = (String)requestParameters.get("toItemId");
LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")"); LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean; final ChibaBean chibaBean = this.xformsSession.chibaBean;
this.swapRepeatItems(chibaBean.lookup(fromItemId), this.swapRepeatItems(chibaBean.getContainer().lookup(fromItemId),
chibaBean.lookup(toItemId)); chibaBean.getContainer().lookup(toItemId));
final ResponseWriter out = context.getResponseWriter(); final ResponseWriter out = context.getResponseWriter();
FormsService.getInstance().writeXML(this.getEventLog(), out); FormsService.getInstance().writeXML(this.getEventLog(), out);
@@ -648,7 +618,7 @@ public class XFormsBean
final String cwdAvmPath) final String cwdAvmPath)
{ {
final NodeList includes = final NodeList includes =
schemaDocument.getElementsByTagNameNS(SchemaFormBuilder.XMLSCHEMA_NS, "include"); schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include");
LOGGER.debug("rewriting " + includes.getLength() + " includes"); LOGGER.debug("rewriting " + includes.getLength() + " includes");
for (int i = 0; i < includes.getLength(); i++) for (int i = 0; i < includes.getLength(); i++)
{ {
@@ -672,7 +642,7 @@ public class XFormsBean
final Document result = formsService.newDocument(); final Document result = formsService.newDocument();
final Element eventsElement = result.createElement("events"); final Element eventsElement = result.createElement("events");
result.appendChild(eventsElement); result.appendChild(eventsElement);
for (XFormsEvent xfe : this.xformsSession.eventLog) for (XMLEvent xfe : this.xformsSession.eventLog)
{ {
final String type = xfe.getType(); final String type = xfe.getType();
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
@@ -740,4 +710,48 @@ public class XFormsBean
commonsCookies); commonsCookies);
} }
} }
private Document getXFormsDocument()
throws FormBuilderException
{
final String cwdAVMPath = this.avmBrowseBean.getCurrentPath();
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("building xform for schema " + this.xformsSession.form.getName() +
" root element " + this.xformsSession.form.getSchemaRootElementName() +
" avm cwd " + cwdAVMPath);
}
final Locale locale =
Application.getLanguage(FacesContext.getCurrentInstance());
final ResourceBundle resourceBundle =
this.schema2XFormsProperties.getResourceBundle(this.xformsSession.form,
locale);
try
{
final Document schemaDocument = this.xformsSession.form.getSchema();
XFormsBean.rewriteInlineURIs(schemaDocument, cwdAVMPath);
final String rootElementName = this.xformsSession.form.getSchemaRootElementName();
final Document result =
this.xformsSession.schemaFormBuilder.buildXForm(this.xformsSession.formInstanceData,
schemaDocument,
rootElementName,
resourceBundle);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("generated xform: " +
FormsService.getInstance().writeXMLToString(result));
}
return result;
}
catch (IOException ioe)
{
throw new FormBuilderException(ioe);
}
catch (SAXException saxe)
{
throw new FormBuilderException(saxe);
}
}
} }

View File

@@ -19,10 +19,8 @@ package org.alfresco.web.forms.xforms;
import java.io.*; import java.io.*;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletContext;
import org.alfresco.web.forms.*; import org.alfresco.web.forms.*;
import org.chiba.xml.util.DOMUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -47,18 +45,10 @@ public class XFormsProcessor
final Writer out) final Writer out)
throws FormProcessor.ProcessingException throws FormProcessor.ProcessingException
{ {
try final Session result =
{ XFormsBean.createSession(instanceDataDocument, form);
final Session result = this.process(result, out);
XFormsBean.createSession(instanceDataDocument, form); return result;
this.process(result, out);
return result;
}
catch (XFormsException xfe)
{
LOGGER.error(xfe);
throw new FormProcessor.ProcessingException(xfe);
}
} }
/** /**
@@ -77,6 +67,11 @@ public class XFormsProcessor
{ {
xforms.setXFormsSession((XFormsBean.XFormsSession)session); xforms.setXFormsSession((XFormsBean.XFormsSession)session);
} }
catch (FormBuilderException fbe)
{
LOGGER.error(fbe);
throw new ProcessingException(fbe);
}
catch (XFormsException xfe) catch (XFormsException xfe)
{ {
LOGGER.error(xfe); LOGGER.error(xfe);

View File

@@ -19,7 +19,7 @@ package org.alfresco.web.forms.xforms;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import org.chiba.xml.ns.NamespaceConstants;
import java.util.*; import java.util.*;
/** /**
@@ -28,224 +28,248 @@ import java.util.*;
* @author Sophie Ramel * @author Sophie Ramel
*/ */
public class XHTMLWrapperElementsBuilder public class XHTMLWrapperElementsBuilder
implements WrapperElementsBuilder implements WrapperElementsBuilder
{ {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private static class Link private static class Link
{ {
public final String href; public final String href;
public final String type; public final String type;
public final String rel; public final String rel;
public Link(final String href, final String type, final String rel) public Link(final String href, final String type, final String rel)
{ {
this.href = href; this.href = href;
this.type = type; this.type = type;
this.rel = rel; this.rel = rel;
} }
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private static class Meta private static class Meta
{ {
public final String httpEquiv; public final String httpEquiv;
public final String name; public final String name;
public final String content; public final String content;
public final String scheme; public final String scheme;
public Meta(final String httpEquiv, public Meta(final String httpEquiv,
final String name, final String name,
final String content, final String content,
final String scheme) final String scheme)
{ {
this.httpEquiv = httpEquiv; this.httpEquiv = httpEquiv;
this.name = name; this.name = name;
this.content = content; this.content = content;
this.scheme = scheme; this.scheme = scheme;
} }
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private final static String XHTML_NS = "http://www.w3.org/1999/xhtml"; private String title;
private final static String XHTML_PREFIX = "xhtml"; private final Collection<Link> links = new LinkedList<Link>();
private final Collection<Meta> meta = new LinkedList<Meta>();
private final HashMap<String, String> namespaces =
new HashMap<String, String>();
/**
* Creates a new instance of XHTMLWrapperElementsBuilder
*/
public XHTMLWrapperElementsBuilder() { }
private String title; /**
private final Collection<Link> links = new LinkedList<Link>(); * add a tag "title" in the header of the HTML document
private final Collection<Meta> meta = new LinkedList<Meta>(); */
private final HashMap<String, String> namespaces = public void setTitle(String title)
new HashMap<String, String>(); {
this.title = title;
}
/** /**
* Creates a new instance of XHTMLWrapperElementsBuilder * add a tag "link" in the header of the HTML document
*/ *
public XHTMLWrapperElementsBuilder() { } * @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 "title" in the header of the HTML document * add a tag "meta" in the header of the HTML document
*/ *
public void setTitle(String title) * @param http_equiv the "http-equiv" parameter of the "META" tag
{ * @param name the "name" parameter of the "META" tag
this.title = title; * @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,
* add a tag "link" in the header of the HTML document final String url)
* {
* @param href the "href" parameter of the "link" tag namespaces.put(prefix, url);
* @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 * create the wrapper element of the different controls
* *
* @param http_equiv the "http-equiv" parameter of the "META" tag * @param controlElement the control element (input, select, repeat, group, ...)
* @param name the "name" parameter of the "META" tag * @return the wrapper element, already containing the control element
* @param content the "content" parameter of the "META" tag */
* @param scheme the "scheme" parameter of the "META" tag public Element createControlsWrapper(final Element controlElement)
*/ {
public void addMeta(final String httpEquiv, return controlElement;
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) * creates the global enveloppe of the resulting document, and puts it in the document
{ *
namespaces.put(prefix, url); * @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
* create the wrapper element of the different controls for (String prefix : this.namespaces.keySet())
* {
* @param controlElement the control element (input, select, repeat, group, ...) html.setAttributeNS(NamespaceConstants.XMLNS_NS,
* @return the wrapper element, already containing the control element NamespaceConstants.XMLNS_PREFIX + ":" + prefix,
*/ this.namespaces.get(prefix));
public Element createControlsWrapper(final Element controlElement)
{
return controlElement;
}
/** }
* creates the global enveloppe of the resulting document, and puts it in the document return html;
* }
* @return the enveloppe
*/
public Element createEnvelope(Document doc)
{
Element html = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":html");
//set namespace attribute
html.setAttributeNS(SchemaFormBuilder.XMLNS_NAMESPACE_URI,
"xmlns:" + XHTML_PREFIX,
XHTMLWrapperElementsBuilder.XHTML_NS);
doc.appendChild(html);
//other namespaces /**
for (String prefix : this.namespaces.keySet()) * create the element that will contain the content of the group (or repeat) element
{ *
html.setAttributeNS(SchemaFormBuilder.XMLNS_NAMESPACE_URI, * @param groupElement the group or repeat element
"xmlns:" + prefix, * @return the wrapper element
this.namespaces.get(prefix)); */
public Element createGroupContentWrapper(Element groupElement)
{
return groupElement;
}
} /**
return html; * 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 element that will contain the content of the group (or repeat) element * create the wrapper element of the xforms:model element
* *
* @param groupElement the group or repeat element * @param modelElement the xforms:model element
* @return the wrapper element * @return the wrapper element, already containing the model
*/ */
public Element createGroupContentWrapper(Element groupElement) public Element createModelWrapper(final Element modelElement)
{ {
return groupElement; Document doc = modelElement.getOwnerDocument();
} Element head = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":head");
head.appendChild(modelElement);
/** //eventually add other info
* create the wrapper element of the form if (title != null && title.length() != 0)
* {
* @param enveloppeElement the form element (chiba:form or other) final Element title_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
* @return the wrapper element NamespaceConstants.XHTML_PREFIX + ":title");
*/ title_el.appendChild(doc.createTextNode(title));
public Element createFormWrapper(Element enveloppeElement) head.appendChild(title_el);
{ }
Document doc = enveloppeElement.getOwnerDocument();
Element body = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":body");
//body.appendChild(formElement);
enveloppeElement.appendChild(body);
return body;
}
/** for (Meta m : this.meta)
* create the wrapper element of the xforms:model element {
* final Element meta_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
* @param modelElement the xforms:model element NamespaceConstants.XHTML_PREFIX + ":META");
* @return the wrapper element, already containing the model head.appendChild(meta_el);
*/
public Element createModelWrapper(Element modelElement)
{
Document doc = modelElement.getOwnerDocument();
Element head = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":head");
head.appendChild(modelElement);
//eventually add other info
if (title != null && title.length() != 0)
{
Element title_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":title");
Text title_text = doc.createTextNode(title);
title_el.appendChild(title_text);
head.appendChild(title_el);
}
for (Meta m : this.meta)
{
Element meta_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":META");
head.appendChild(meta_el);
//attributes //attributes
if (m.httpEquiv != null && m.httpEquiv.length() != 0) if (m.httpEquiv != null && m.httpEquiv.length() != 0)
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":http-equiv", {
m.httpEquiv); meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
if (m.name != null && m.name.length() != 0) NamespaceConstants.XHTML_PREFIX + ":http-equiv",
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":name", m.name); 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);
}
}
if (m.content != null && m.content.length() != 0) for (Link l : this.links)
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":content", m.content); {
final Element link_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":LINK");
head.appendChild(link_el);
if (m.scheme != null && m.scheme.length() != 0) //attributes
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":scheme", m.scheme); if (l.href != null && l.href.length() != 0)
} {
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
for (Link l : this.links) NamespaceConstants.XHTML_PREFIX + ":href",
{ l.href);
Element link_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":LINK"); }
head.appendChild(link_el); if (l.type != null && l.type.length() != 0)
{
//attributes link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
if (l.href != null && l.href.length() != 0) NamespaceConstants.XHTML_PREFIX + ":type",
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":href", l.href); l.type);
}
if (l.type != null && l.type.length() != 0) if (l.rel != null && l.rel.length() != 0)
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":type", l.type); {
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
if (l.rel != null && l.rel.length() != 0) NamespaceConstants.XHTML_PREFIX + ":rel",
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":rel", l.rel); l.rel);
}
return head; }
} }
return head;
}
} }

View File

@@ -109,9 +109,10 @@ public class UIFormProcessor extends SelfRenderingComponent
out)); out));
} }
} }
catch (FormProcessor.ProcessingException fppe) catch (Throwable t)
{ {
Utils.addErrorMessage(fppe.getMessage(), fppe); Utils.addErrorMessage(t.getMessage(), t);
out.write(t.toString());
} }
} }

View File

@@ -1,71 +1,15 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: default.xml,v 1.2 2005/12/15 09:27:01 unl Exp $ --> <!-- $Id: default.xml,v 1.40 2006/08/02 20:37:26 unl Exp $ -->
<!-- Copyright 2005 Chibacon --> <!-- Copyright 2005 Chibacon -->
<chiba-config> <chiba-config>
<!-- PLEASE COMMENT YOUR ENTRIES --> <!-- PLEASE COMMENT YOUR ENTRIES -->
<properties> <properties>
<!-- <!-- generate default alert elements if none present. -->
Language is not a config-property any more as soon as
Chiba starts to support user-agents. Language may vary from
instance to instance or even from request to request
-->
<property name="language" value="de"/>
<!--
This property allows to switch the stylesheet compilation on.
Because of the significant performance gain this option is turned on by default.
Note: If you extend stylesheets and use custom xpath extensions, compilation can become
a problem cause XSLTC has limitations in this area.
-->
<property name="chiba.stylesheets.compiled" value="true"/>
<!-- ********* web adapter properties ********* -->
<!--
Normally there should be no reason to change the following prefixes unless they're
in conflict with your application that uses Chiba.
-->
<!-- prefix used in http request param names to denote a data (value) parameter. -->
<property name="chiba.web.dataPrefix" value="d_"/>
<!-- prefix used in http request param names to denote the id of an action to be fired. -->
<property name="chiba.web.triggerPrefix" value="t_"/>
<!-- prefix used in http request param names to denote a selector parameter (used for repeats). -->
<property name="chiba.web.selectorPrefix" value="s_"/>
<!-- ********* ui handler properties ********* -->
<!--
This option allows to steer the processor behaviour regarding the initialization of
<case> elements which are not visible currently (unselected). If setting this option
to false, only the current <case> will be initialized.
The default is to initialize all <case> elements.
-->
<property name="chiba.ui.initializeDeselectedCases" value="true"/>
<!-- generate default alert Elements for UI controls. default is false -->
<property name="chiba.ui.generateDefaultAlerts" value="false"/> <property name="chiba.ui.generateDefaultAlerts" value="false"/>
<!-- define the default text for automatically generated alert elements. -->
<!--
allows the define the default error-message for automatically generated alert elements.
-->
<property name="chiba.ui.defaultAlertText" value="The specified value is invalid"/> <property name="chiba.ui.defaultAlertText" value="The specified value is invalid"/>
</properties> </properties>
<error-messages>
<message id="session-invalid" value="Invalid session - You probably used the back button to visit an already finished form."/>
</error-messages>
<stylesheets>
<!--
Maps internal names to external file-names.
The internal name is used by the framework to identify
entities and resolve these to the associated filenames.
-->
<!-- Standard stylesheet used for simple HTML 3.2 compatible Browsers without Javascript support -->
<stylesheet name="html-default" value="html4.xsl"/>
</stylesheets>
<connectors> <connectors>
<!-- <!--
For each of the connector types you can specifiy one connector to handle one URI scheme. For each of the connector types you can specifiy one connector to handle one URI scheme.
@@ -75,36 +19,25 @@
<uri-resolver scheme="class" class="org.chiba.util.ClassResourceLoader"/> <uri-resolver scheme="class" class="org.chiba.util.ClassResourceLoader"/>
<uri-resolver scheme="xmlrpc" class="org.chiba.connectors.xmlrpc.XMLRPCURIResolver"/> <uri-resolver scheme="xmlrpc" class="org.chiba.connectors.xmlrpc.XMLRPCURIResolver"/>
<uri-resolver scheme="context" class="org.chiba.xml.xforms.connector.context.ContextResolver"/> <uri-resolver scheme="context" class="org.chiba.xml.xforms.connector.context.ContextResolver"/>
<uri-resolver scheme="contextobject" class="org.chiba.xml.xforms.connector.context.ContextObjectResolver"/>
<submission-handler scheme="context" class="org.chiba.xml.xforms.connector.context.ContextSubmissionHandler"/>
<submission-handler scheme="file" class="org.chiba.xml.xforms.connector.file.FileSubmissionHandler"/> <submission-handler scheme="file" class="org.chiba.xml.xforms.connector.file.FileSubmissionHandler"/>
<submission-handler scheme="http" class="org.chiba.xml.xforms.connector.http.HTTPSubmissionHandler"/> <submission-handler scheme="http" class="org.chiba.xml.xforms.connector.http.HTTPSubmissionHandler"/>
<submission-handler scheme="mailto" class="org.chiba.connectors.smtp.SMTPSubmissionHandler"/> <submission-handler scheme="mailto" class="org.chiba.connectors.smtp.SMTPSubmissionHandler"/>
<submission-handler scheme="xmlrpc" class="org.chiba.connectors.xmlrpc.XMLRPCSubmissionHandler"/> <submission-handler scheme="xmlrpc" class="org.chiba.connectors.xmlrpc.XMLRPCSubmissionHandler"/>
<!-- <submission-handler scheme="jms" class="org.chiba.connectors.jms.JMSSubmissionHandler"/>--> <submission-handler scheme="echo" class="org.chiba.xml.xforms.connector.echo.EchoSubmissionHandler"/>
<!--
These connector types are deprecated. Their usage is strongly discouraged,
since they may disappear without notice. Use custom extension functions instead.
-->
<!-- <modelitem-calculator scheme="http" class="org.chiba.xml.xforms.connector.http.HTTPModelItemCalculator"/>-->
<!-- <modelitem-validator scheme="http" class="org.chiba.xml.xforms.connector.http.HTTPModelItemValidator"/>-->
</connectors> </connectors>
<extension-functions> <extension-functions>
<!-- <!--
Specifies external functions to be used in the XForms' XPath expressions. If the 'java-name' attribute Specifies external functions to be used in the XForms' XPath expressions. If the 'java-name' attribute
is ommitted, the Java function name is considered to be the same as that of the XPath function. is ommitted, the Java function name is considered to be the same as that of the XPath function.
--> -->
<function namespace="http://chiba.sourceforge.net/xforms" name="declare" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/> <function namespace="http://chiba.sourceforge.net/xforms" name="context" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions" />
<function namespace="http://chiba.sourceforge.net/xforms" name="undeclare" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<!--<function namespace="http://exslt.org/regular-expressions" prefix="regexp" name="test" class="org.galasoft.util.xml.servlet.xforms.exslt.Regexp" java-name="test"/>--> <!--<function namespace="http://exslt.org/regular-expressions" prefix="regexp" name="test" class="org.galasoft.util.xml.servlet.xforms.exslt.Regexp" java-name="test"/>-->
<function namespace="http://exslt.org/regular-expressions" name="test" class="org.galasoft.util.xml.servlet.xforms.exslt.Regexp" java-name="test"/> <function namespace="http://exslt.org/regular-expressions" name="test" class="org.galasoft.util.xml.servlet.xforms.exslt.Regexp" java-name="test"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="formatDateString" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="fileDate" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/> <function namespace="http://chiba.sourceforge.net/xforms" name="fileDate" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="fileSize" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/> <function namespace="http://chiba.sourceforge.net/xforms" name="fileSize" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="match" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/> <function namespace="http://chiba.sourceforge.net/xforms" name="match" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="validate" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
<function namespace="http://chiba.sourceforge.net/xforms" name="calculate" class="org.chiba.xml.xforms.xpath.ChibaExtensionFunctions"/>
</extension-functions> </extension-functions>
<custom-elements> <custom-elements>

View File

@@ -34,7 +34,10 @@
function pageLoaded() function pageLoaded()
{ {
document.getElementById("wizard:wizard-body:file-input").focus(); if (document.getElementById("wizard:wizard-body:file-input"))
document.getElementById("wizard:wizard-body:file-input").focus()
else
document.getElementById("wizard:wizard-body:form-name").focus();
document.getElementById("wizard").onsubmit = validate; document.getElementById("wizard").onsubmit = validate;
document.getElementById("wizard:next-button").onclick = function() {finishButtonPressed = true; clear_wizard();} document.getElementById("wizard:next-button").onclick = function() {finishButtonPressed = true; clear_wizard();}
document.getElementById("wizard:finish-button").onclick = function() {finishButtonPressed = true; clear_wizard();} document.getElementById("wizard:finish-button").onclick = function() {finishButtonPressed = true; clear_wizard();}
@@ -42,7 +45,14 @@
function validate() function validate()
{ {
return true; if (!finishButtonPressed)
return true;
finishButtonPressed = false;
var formName = document.getElementById("wizard:wizard-body:form-name");
return validateMandatory(formName) &&
validateName(formName,
'</f:verbatim><a:outputText value="#{msg.validation_invalid_character}" /><f:verbatim>',
true)
} }
function handle_upload(target) function handle_upload(target)
@@ -55,9 +65,10 @@
function upload_complete(id, path) function upload_complete(id, path)
{ {
var validate_button = var schema_file_input =
document.getElementById("wizard:wizard-body:command_button_validate_schema"); document.getElementById("wizard:wizard-body:schema-file");
validate_button.click(); schema_file_input.value = path;
schema_file_input.form.submit();
} }
</script> </script>
</f:verbatim> </f:verbatim>
@@ -81,7 +92,7 @@
<h:graphicImage id="graphic_image_schema" <h:graphicImage id="graphic_image_schema"
value="/images/icons/required_field.gif" alt="Required Field" /> value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="output_text_schema" <h:outputText id="output_text_schema"
value="#{msg.schema}:"/> value="#{msg.schema}:"/>
<h:column id="column_schema"> <h:column id="column_schema">
<% <%
FileUploadBean upload = (FileUploadBean) FileUploadBean upload = (FileUploadBean)
@@ -96,12 +107,11 @@ if (upload == null || upload.getFile() == null)
name="alfFileInput" name="alfFileInput"
onchange="javascript:handle_upload(this)"/> onchange="javascript:handle_upload(this)"/>
</f:verbatim> </f:verbatim>
<h:commandButton id="command_button_validate_schema" <h:inputText id="schema-file"
value="" value="#{WizardManager.bean.schemaFileName}"
immediate="true" rendered="#{empty WizardManager.bean.schemaFileName}"
style="display: none" style="display: none"
action="#{WizardManager.bean.validateSchema}"/> valueChangeListener="#{WizardManager.bean.schemaFileValueChanged}"/>
<% <%
} else { } else {
%> %>
@@ -146,21 +156,21 @@ if (upload == null || upload.getFile() == null)
value="/images/icons/required_field.gif" value="/images/icons/required_field.gif"
alt="Required Field" /> alt="Required Field" />
<h:outputText id="output_text_name" value="#{msg.name}:"/> <h:outputText id="output_text_name" value="#{msg.name}:"/>
<h:inputText id="file-name" <h:inputText id="form-name"
value="#{WizardManager.bean.formName}" value="#{WizardManager.bean.formName}"
maxlength="1024" maxlength="1024"
size="35"/> size="35"/>
<h:outputText id="no_graphic_image_title" value=""/> <h:outputText id="no_graphic_image_title" value=""/>
<h:outputText id="output_text_title" value="#{msg.title}:"/> <h:outputText id="output_text_title" value="#{msg.title}:"/>
<h:inputText id="title" <h:inputText id="form-title"
value="#{WizardManager.bean.formTitle}" value="#{WizardManager.bean.formTitle}"
maxlength="1024" maxlength="1024"
size="35"/> size="35"/>
<h:outputText id="no_graphic_image_description" value=""/> <h:outputText id="no_graphic_image_description" value=""/>
<h:outputText id="output_text_description" value="#{msg.description}:"/> <h:outputText id="output_text_description" value="#{msg.description}:"/>
<h:inputText id="description" <h:inputText id="form-description"
value="#{WizardManager.bean.formDescription}" value="#{WizardManager.bean.formDescription}"
maxlength="1024" maxlength="1024"
style="width:100%"/> style="width:100%"/>

View File

@@ -5,7 +5,7 @@ dojo.require("dojo.lfx.html");
dojo.hostenv.writeIncludes(); dojo.hostenv.writeIncludes();
var XFORMS_NS = "http://www.w3.org/2002/xforms"; var XFORMS_NS = "http://www.w3.org/2002/xforms";
var XFORMS_NS_PREFIX = "xforms"; var XFORMS_PREFIX = "xf";
var XHTML_NS = "http://www.w3.org/1999/xhtml"; var XHTML_NS = "http://www.w3.org/1999/xhtml";
var XHTML_NS_PREFIX = "xhtml"; var XHTML_NS_PREFIX = "xhtml";
var CHIBA_NS = "http://chiba.sourceforge.net/xforms"; var CHIBA_NS = "http://chiba.sourceforge.net/xforms";
@@ -134,20 +134,11 @@ dojo.declare("alfresco.xforms.Widget",
{ {
if (typeof this.initialValue != "undefined") if (typeof this.initialValue != "undefined")
return this.initialValue; return this.initialValue;
var chibaData = _getElementsByTagNameNS(this.xformsNode,
CHIBA_NS, var xpath = this._getXPathInInstanceDocument();
CHIBA_NS_PREFIX,
"data");
if (chibaData.length == 0)
return null;
chibaData = chibaData[chibaData.length - 1];
var xpath = chibaData.getAttribute(CHIBA_NS_PREFIX + ":xpath");
var d = this.xformsNode.ownerDocument; var d = this.xformsNode.ownerDocument;
var contextNode = this.xform.getInstance(); var contextNode = this.xform.getInstance();
dojo.debug("locating " + xpath + dojo.debug("locating " + xpath + " in " + contextNode.nodeName);
" from " + chibaData.nodeName +
" in " + contextNode.nodeName);
var result = _evaluateXPath("/" + xpath, var result = _evaluateXPath("/" + xpath,
this.xform.getInstance(), this.xform.getInstance(),
XPathResult.FIRST_ORDERED_NODE_TYPE); XPathResult.FIRST_ORDERED_NODE_TYPE);
@@ -159,9 +150,29 @@ dojo.declare("alfresco.xforms.Widget",
dojo.debug("resolved xpath " + xpath + " to " + result); dojo.debug("resolved xpath " + xpath + " to " + result);
return result; return result;
}, },
_getXPathInInstanceDocument: function()
{
var binding = this.xform.getBinding(this.xformsNode);
var xpath = '';
do
{
var s = binding.nodeset;
if (binding.nodeset == '.')
{
binding = binding.parent;
var repeatIndices = this.getRepeatIndices();
s = binding.nodeset.replace(/([^\[]+)\[.*/, "$1");
s += '[' + (repeatIndices.pop().index + 1) + ']';
}
xpath = s + (xpath.length != 0 ? '/' + xpath : "");
binding = binding.parent;
}
while (binding);
return xpath;
},
_getLabelNode: function() _getLabelNode: function()
{ {
var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "label"); var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_PREFIX, "label");
for (var i = 0; i < labels.length; i++) for (var i = 0; i < labels.length; i++)
{ {
if (labels[i].parentNode == this.xformsNode) if (labels[i].parentNode == this.xformsNode)
@@ -171,7 +182,7 @@ dojo.declare("alfresco.xforms.Widget",
}, },
_getAlertNode: function() _getAlertNode: function()
{ {
var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "alert"); var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_PREFIX, "alert");
for (var i = 0; i < labels.length; i++) for (var i = 0; i < labels.length; i++)
{ {
if (labels[i].parentNode == this.xformsNode) if (labels[i].parentNode == this.xformsNode)
@@ -212,17 +223,27 @@ dojo.declare("alfresco.xforms.Widget",
{ {
dojo.debug("destroying " + this.id); dojo.debug("destroying " + this.id);
}, },
getParentRepeats: function() getRepeatIndices: function()
{ {
var result = []; function RepeatIndexData(repeat, index)
var p = this.parent;
while (p)
{ {
if (p instanceof alfresco.xforms.Repeat) this.repeat = repeat;
this.index = index;
this.toString = function()
{ {
result.push(p); return "{" + this.repeat.id + " = " + this.index + "}";
};
}
var result = [];
var w = this;
while (w.parent)
{
if (w.parent instanceof alfresco.xforms.Repeat)
{
result.push(new RepeatIndexData(w.parent,
w.parent.getChildIndex(w)));
} }
p = p.parent; w = w.parent;
} }
return result; return result;
} }
@@ -449,12 +470,12 @@ dojo.declare("alfresco.xforms.AbstractSelectWidget",
getValues: function() getValues: function()
{ {
var binding = this.xform.getBinding(this.xformsNode); var binding = this.xform.getBinding(this.xformsNode);
var values = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "item"); var values = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_PREFIX, "item");
var result = []; var result = [];
for (var v = 0; v < values.length; v++) for (var v = 0; v < values.length; v++)
{ {
var label = _getElementsByTagNameNS(values[v], XFORMS_NS, XFORMS_NS_PREFIX, "label")[0]; var label = _getElementsByTagNameNS(values[v], XFORMS_NS, XFORMS_PREFIX, "label")[0];
var value = _getElementsByTagNameNS(values[v], XFORMS_NS, XFORMS_NS_PREFIX, "value")[0]; var value = _getElementsByTagNameNS(values[v], XFORMS_NS, XFORMS_PREFIX, "value")[0];
var valid = true; var valid = true;
if (binding.constraint) if (binding.constraint)
{ {
@@ -1220,7 +1241,7 @@ dojo.declare("alfresco.xforms.Repeat",
this.domNode = this.inherited("render", [ attach_point ]); this.domNode = this.inherited("render", [ attach_point ]);
this.domNode.style.border = "1px solid black"; this.domNode.style.border = "1px solid black";
var parentRepeats = this.getParentRepeats(); var parentRepeats = this.getRepeatIndices();
this.domNode.style.marginLeft = (parentRepeats.length * 10) + "px"; this.domNode.style.marginLeft = (parentRepeats.length * 10) + "px";
this.domNode.style.marginRight = (parseInt(this.domNode.style.marginLeft) / 2) + "px"; this.domNode.style.marginRight = (parseInt(this.domNode.style.marginLeft) / 2) + "px";
this.domNode.style.width = (this.domNode.offsetParent.offsetWidth - this.domNode.style.width = (this.domNode.offsetParent.offsetWidth -
@@ -1344,8 +1365,8 @@ dojo.declare("alfresco.xforms.Trigger",
var c = this.xformsNode.childNodes[i]; var c = this.xformsNode.childNodes[i];
if (c.nodeType != dojo.dom.ELEMENT_NODE) if (c.nodeType != dojo.dom.ELEMENT_NODE)
continue; continue;
if (c.nodeName == XFORMS_NS_PREFIX + ":label" || if (c.nodeName == XFORMS_PREFIX + ":label" ||
c.nodeName == XFORMS_NS_PREFIX + ":alert") c.nodeName == XFORMS_PREFIX + ":alert")
continue; continue;
return new alfresco.xforms.XFormsAction(this.xform, c); return new alfresco.xforms.XFormsAction(this.xform, c);
} }
@@ -1413,16 +1434,16 @@ dojo.declare("alfresco.xforms.XFormsAction",
for (var i = 0; i < this.xformsNode.attributes.length; i++) for (var i = 0; i < this.xformsNode.attributes.length; i++)
{ {
var attr = this.xformsNode.attributes[i]; var attr = this.xformsNode.attributes[i];
if (attr.nodeName.match(/^xforms:/)) if (attr.nodeName.match(new RegExp("^" + XFORMS_PREFIX + ":")))
{ {
this.properties[attr.nodeName.substring((XFORMS_NS_PREFIX + ":").length)] = this.properties[attr.nodeName.substring((XFORMS_PREFIX + ":").length)] =
attr.nodeValue; attr.nodeValue;
} }
} }
}, },
getType: function() getType: function()
{ {
return this.xformsNode.nodeName.substring((XFORMS_NS_PREFIX + ":").length); return this.xformsNode.nodeName.substring((XFORMS_PREFIX + ":").length);
}, },
}); });
@@ -1490,15 +1511,15 @@ dojo.declare("alfresco.xforms.XForm",
dojo.debug("creating node for " + node.nodeName.toLowerCase()); dojo.debug("creating node for " + node.nodeName.toLowerCase());
switch (node.nodeName.toLowerCase()) switch (node.nodeName.toLowerCase())
{ {
case XFORMS_NS_PREFIX + ":group": case XFORMS_PREFIX + ":group":
return new alfresco.xforms.Group(this, node); return new alfresco.xforms.Group(this, node);
case XFORMS_NS_PREFIX + ":repeat": case XFORMS_PREFIX + ":repeat":
return new alfresco.xforms.Repeat(this, node); return new alfresco.xforms.Repeat(this, node);
case XFORMS_NS_PREFIX + ":textarea": case XFORMS_PREFIX + ":textarea":
return new alfresco.xforms.TextArea(this, node); return new alfresco.xforms.TextArea(this, node);
case XFORMS_NS_PREFIX + ":upload": case XFORMS_PREFIX + ":upload":
return new alfresco.xforms.FilePicker(this, node); return new alfresco.xforms.FilePicker(this, node);
case XFORMS_NS_PREFIX + ":input": case XFORMS_PREFIX + ":input":
var type = this.getType(node); var type = this.getType(node);
switch (type) switch (type)
{ {
@@ -1523,19 +1544,19 @@ dojo.declare("alfresco.xforms.XForm",
default: default:
return new alfresco.xforms.TextField(this, node); return new alfresco.xforms.TextField(this, node);
} }
case XFORMS_NS_PREFIX + ":select": case XFORMS_PREFIX + ":select":
return new alfresco.xforms.Select(this, node); return new alfresco.xforms.Select(this, node);
case XFORMS_NS_PREFIX + ":select1": case XFORMS_PREFIX + ":select1":
return (this.getType(node) == "boolean" return (this.getType(node) == "boolean"
? new alfresco.xforms.Checkbox(this, node) ? new alfresco.xforms.Checkbox(this, node)
: new alfresco.xforms.Select1(this, node)); : new alfresco.xforms.Select1(this, node));
case XFORMS_NS_PREFIX + ":submit": case XFORMS_PREFIX + ":submit":
return new alfresco.xforms.Submit(this, node); return new alfresco.xforms.Submit(this, node);
case XFORMS_NS_PREFIX + ":trigger": case XFORMS_PREFIX + ":trigger":
return new alfresco.xforms.Trigger(this, node); return new alfresco.xforms.Trigger(this, node);
case CHIBA_NS_PREFIX + ":data": case CHIBA_NS_PREFIX + ":data":
case XFORMS_NS_PREFIX + ":label": case XFORMS_PREFIX + ":label":
case XFORMS_NS_PREFIX + ":alert": case XFORMS_PREFIX + ":alert":
dojo.debug("ignoring " + node.nodeName); dojo.debug("ignoring " + node.nodeName);
return null; return null;
default: default:
@@ -1571,7 +1592,7 @@ dojo.declare("alfresco.xforms.XForm",
{ {
return _getElementsByTagNameNS(this.xformsNode, return _getElementsByTagNameNS(this.xformsNode,
XFORMS_NS, XFORMS_NS,
XFORMS_NS_PREFIX, XFORMS_PREFIX,
"model")[0]; "model")[0];
}, },
getInstance: function() getInstance: function()
@@ -1579,7 +1600,7 @@ dojo.declare("alfresco.xforms.XForm",
var model = this.getModel(); var model = this.getModel();
return _getElementsByTagNameNS(model, return _getElementsByTagNameNS(model,
XFORMS_NS, XFORMS_NS,
XFORMS_NS_PREFIX, XFORMS_PREFIX,
"instance")[0]; "instance")[0];
}, },
getBody: function() getBody: function()
@@ -1596,7 +1617,7 @@ dojo.declare("alfresco.xforms.XForm",
}, },
getBinding: function(node) getBinding: function(node)
{ {
return this._bindings[node.getAttribute(XFORMS_NS_PREFIX + ":bind")]; return this._bindings[node.getAttribute(XFORMS_PREFIX + ":bind")];
}, },
getBindings: function() getBindings: function()
{ {
@@ -1608,18 +1629,18 @@ dojo.declare("alfresco.xforms.XForm",
dojo.debug("loading bindings for " + bind.nodeName); dojo.debug("loading bindings for " + bind.nodeName);
for (var i = 0; i < bind.childNodes.length; i++) for (var i = 0; i < bind.childNodes.length; i++)
{ {
if (bind.childNodes[i].nodeName.toLowerCase() == XFORMS_NS_PREFIX + ":bind") if (bind.childNodes[i].nodeName.toLowerCase() == XFORMS_PREFIX + ":bind")
{ {
var id = bind.childNodes[i].getAttribute("id"); var id = bind.childNodes[i].getAttribute("id");
dojo.debug("loading binding " + id); dojo.debug("loading binding " + id);
result[id] = result[id] =
{ {
id: bind.childNodes[i].getAttribute("id"), id: bind.childNodes[i].getAttribute("id"),
readonly: bind.childNodes[i].getAttribute(XFORMS_NS_PREFIX + ":readonly"), readonly: bind.childNodes[i].getAttribute(XFORMS_PREFIX + ":readonly"),
required: bind.childNodes[i].getAttribute(XFORMS_NS_PREFIX + ":required"), required: bind.childNodes[i].getAttribute(XFORMS_PREFIX + ":required"),
nodeset: bind.childNodes[i].getAttribute(XFORMS_NS_PREFIX + ":nodeset"), nodeset: bind.childNodes[i].getAttribute(XFORMS_PREFIX + ":nodeset"),
type: bind.childNodes[i].getAttribute(XFORMS_NS_PREFIX + ":type"), type: bind.childNodes[i].getAttribute(XFORMS_PREFIX + ":type"),
constraint: bind.childNodes[i].getAttribute(XFORMS_NS_PREFIX + ":constraint"), constraint: bind.childNodes[i].getAttribute(XFORMS_PREFIX + ":constraint"),
maximum: parseInt(bind.childNodes[i].getAttribute(ALFRESCO_NS_PREFIX + ":maximum")), maximum: parseInt(bind.childNodes[i].getAttribute(ALFRESCO_NS_PREFIX + ":maximum")),
minimum: parseInt(bind.childNodes[i].getAttribute(ALFRESCO_NS_PREFIX + ":minimum")), minimum: parseInt(bind.childNodes[i].getAttribute(ALFRESCO_NS_PREFIX + ":minimum")),
parent: parent, parent: parent,
@@ -1728,8 +1749,8 @@ dojo.declare("alfresco.xforms.XForm",
dojo.debug("cloning prototype " + originalId); dojo.debug("cloning prototype " + originalId);
var prototypeNode = _findElementById(this.xformsNode, originalId); var prototypeNode = _findElementById(this.xformsNode, originalId);
clone = prototypeNode.cloneNode(true); clone = prototypeNode.cloneNode(true);
var clone = prototypeNode.ownerDocument.createElement("xforms:group"); var clone = prototypeNode.ownerDocument.createElement(XFORMS_PREFIX + ":group");
clone.setAttribute("xforms:appearance", "repeated"); clone.setAttribute(XFORMS_PREFIX + ":appearance", "repeated");
for (var j = 0; j < prototypeNode.childNodes.length; j++) for (var j = 0; j < prototypeNode.childNodes.length; j++)
{ {
clone.appendChild(prototypeNode.childNodes[j].cloneNode(true)); clone.appendChild(prototypeNode.childNodes[j].cloneNode(true));