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,41 +196,13 @@ 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();
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);
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: " +
FormsService.getInstance().writeXMLToString(xformsDocument));
}
chibaBean.setXMLContainer(xformsDocument);
final EventTarget et = (EventTarget) final EventTarget et = (EventTarget)
chibaBean.getXMLContainer().getDocumentElement(); chibaBean.getXMLContainer().getDocumentElement();
@@ -228,44 +211,32 @@ public class XFormsBean
public void handleEvent(final Event e) public void handleEvent(final Event e)
{ {
XFormsBean.LOGGER.debug("received event " + e); XFormsBean.LOGGER.debug("received event " + e);
XFormsBean.this.xformsSession.eventLog.add((XFormsEvent)e); XFormsBean.this.xformsSession.eventLog.add((XMLEvent)e);
} }
}; };
// interaction events my occur during init so we have to register before // interaction events my occur during init so we have to register before
et.addEventListener(XFormsEventFactory.CHIBA_LOAD_URI, el, true); et.addEventListener(ChibaEventNames.LOAD_URI, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, el, true); et.addEventListener(ChibaEventNames.RENDER_MESSAGE, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, el, true); et.addEventListener(ChibaEventNames.REPLACE_ALL, el, true);
chibaBean.init(); chibaBean.init();
// register for notification events // register for notification events
et.addEventListener(XFormsEventFactory.SUBMIT_DONE, el, true); et.addEventListener(XFormsEventNames.SUBMIT, el, true);
et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, el, true); et.addEventListener(XFormsEventNames.SUBMIT_DONE, el, true);
et.addEventListener(XFormsEventFactory.REQUIRED, el, true); et.addEventListener(XFormsEventNames.SUBMIT_ERROR, el, true);
et.addEventListener(XFormsEventFactory.OPTIONAL, el, true); et.addEventListener(XFormsEventNames.REQUIRED, el, true);
et.addEventListener(XFormsEventFactory.VALID, el, true); et.addEventListener(XFormsEventNames.OPTIONAL, el, true);
et.addEventListener(XFormsEventFactory.INVALID, el, true); et.addEventListener(XFormsEventNames.VALID, el, true);
et.addEventListener(XFormsEventFactory.OUT_OF_RANGE, el, true); et.addEventListener(XFormsEventNames.INVALID, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_STATE_CHANGED, el, true); et.addEventListener(XFormsEventNames.OUT_OF_RANGE, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_PROTOTYPE_CLONED, el, true); et.addEventListener(ChibaEventNames.STATE_CHANGED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ID_GENERATED, el, true); et.addEventListener(ChibaEventNames.PROTOTYPE_CLONED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_INSERTED, el, true); et.addEventListener(ChibaEventNames.ID_GENERATED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_DELETED, el, true); et.addEventListener(ChibaEventNames.ITEM_INSERTED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_INDEX_CHANGED, el, true); et.addEventListener(ChibaEventNames.ITEM_DELETED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_SWITCH_TOGGLED, el, true); et.addEventListener(ChibaEventNames.INDEX_CHANGED, el, true);
} et.addEventListener(ChibaEventNames.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;
@@ -46,20 +44,12 @@ public class XFormsProcessor
final Form form, final Form form,
final Writer out) final Writer out)
throws FormProcessor.ProcessingException throws FormProcessor.ProcessingException
{
try
{ {
final Session result = final Session result =
XFormsBean.createSession(instanceDataDocument, form); XFormsBean.createSession(instanceDataDocument, form);
this.process(result, out); this.process(result, out);
return result; return result;
} }
catch (XFormsException xfe)
{
LOGGER.error(xfe);
throw new FormProcessor.ProcessingException(xfe);
}
}
/** /**
* Generates html text which bootstraps the JavaScript code that will * Generates html text which bootstraps the JavaScript code that will
@@ -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.*;
/** /**
@@ -70,10 +70,6 @@ public class XHTMLWrapperElementsBuilder
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private final static String XHTML_NS = "http://www.w3.org/1999/xhtml";
private final static String XHTML_PREFIX = "xhtml";
private String title; private String title;
private final Collection<Link> links = new LinkedList<Link>(); private final Collection<Link> links = new LinkedList<Link>();
private final Collection<Meta> meta = new LinkedList<Meta>(); private final Collection<Meta> meta = new LinkedList<Meta>();
@@ -147,18 +143,19 @@ public class XHTMLWrapperElementsBuilder
*/ */
public Element createEnvelope(Document doc) public Element createEnvelope(Document doc)
{ {
Element html = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":html"); final Element html = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":html");
//set namespace attribute //set namespace attribute
html.setAttributeNS(SchemaFormBuilder.XMLNS_NAMESPACE_URI, html.setAttributeNS(NamespaceConstants.XMLNS_NS,
"xmlns:" + XHTML_PREFIX, NamespaceConstants.XMLNS_PREFIX + ':' + NamespaceConstants.XHTML_PREFIX,
XHTMLWrapperElementsBuilder.XHTML_NS); NamespaceConstants.XHTML_NS);
doc.appendChild(html); doc.appendChild(html);
//other namespaces //other namespaces
for (String prefix : this.namespaces.keySet()) for (String prefix : this.namespaces.keySet())
{ {
html.setAttributeNS(SchemaFormBuilder.XMLNS_NAMESPACE_URI, html.setAttributeNS(NamespaceConstants.XMLNS_NS,
"xmlns:" + prefix, NamespaceConstants.XMLNS_PREFIX + ":" + prefix,
this.namespaces.get(prefix)); this.namespaces.get(prefix));
} }
@@ -185,7 +182,7 @@ public class XHTMLWrapperElementsBuilder
public Element createFormWrapper(Element enveloppeElement) public Element createFormWrapper(Element enveloppeElement)
{ {
Document doc = enveloppeElement.getOwnerDocument(); Document doc = enveloppeElement.getOwnerDocument();
Element body = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":body"); Element body = doc.createElementNS(NamespaceConstants.XHTML_NS, NamespaceConstants.XHTML_PREFIX + ":body");
//body.appendChild(formElement); //body.appendChild(formElement);
enveloppeElement.appendChild(body); enveloppeElement.appendChild(body);
return body; return body;
@@ -197,54 +194,81 @@ public class XHTMLWrapperElementsBuilder
* @param modelElement the xforms:model element * @param modelElement the xforms:model element
* @return the wrapper element, already containing the model * @return the wrapper element, already containing the model
*/ */
public Element createModelWrapper(Element modelElement) public Element createModelWrapper(final Element modelElement)
{ {
Document doc = modelElement.getOwnerDocument(); Document doc = modelElement.getOwnerDocument();
Element head = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":head"); Element head = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":head");
head.appendChild(modelElement); head.appendChild(modelElement);
//eventually add other info //eventually add other info
if (title != null && title.length() != 0) if (title != null && title.length() != 0)
{ {
Element title_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":title"); final Element title_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
Text title_text = doc.createTextNode(title); NamespaceConstants.XHTML_PREFIX + ":title");
title_el.appendChild(title_text); title_el.appendChild(doc.createTextNode(title));
head.appendChild(title_el); head.appendChild(title_el);
} }
for (Meta m : this.meta) for (Meta m : this.meta)
{ {
Element meta_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":META"); final Element meta_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":META");
head.appendChild(meta_el); 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", {
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":http-equiv",
m.httpEquiv); m.httpEquiv);
}
if (m.name != null && m.name.length() != 0) if (m.name != null && m.name.length() != 0)
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":name", m.name); {
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":name",
m.name);
}
if (m.content != null && m.content.length() != 0) if (m.content != null && m.content.length() != 0)
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":content", m.content); {
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":content",
m.content);
}
if (m.scheme != null && m.scheme.length() != 0) if (m.scheme != null && m.scheme.length() != 0)
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":scheme", m.scheme); {
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":scheme",
m.scheme);
}
} }
for (Link l : this.links) for (Link l : this.links)
{ {
Element link_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":LINK"); final Element link_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":LINK");
head.appendChild(link_el); head.appendChild(link_el);
//attributes //attributes
if (l.href != null && l.href.length() != 0) if (l.href != null && l.href.length() != 0)
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":href", l.href); {
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":href",
l.href);
}
if (l.type != null && l.type.length() != 0) if (l.type != null && l.type.length() != 0)
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":type", l.type); {
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":type",
l.type);
}
if (l.rel != null && l.rel.length() != 0) if (l.rel != null && l.rel.length() != 0)
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":rel", l.rel); {
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
NamespaceConstants.XHTML_PREFIX + ":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()
{ {
if (!finishButtonPressed)
return true; 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>
@@ -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,
CHIBA_NS_PREFIX,
"data");
if (chibaData.length == 0)
return null;
chibaData = chibaData[chibaData.length - 1]; var xpath = this._getXPathInInstanceDocument();
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 + "}";
};
} }
p = p.parent; 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)));
}
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));