mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -18,13 +18,7 @@ package org.alfresco.web.bean.wcm;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.event.ValueChangeEvent;
|
||||
@@ -76,6 +70,7 @@ public class CreateFormWizard
|
||||
* Simple wrapper class to represent a form data renderer
|
||||
*/
|
||||
public class RenderingEngineTemplateData
|
||||
implements Serializable
|
||||
{
|
||||
private final String fileName;
|
||||
private final File file;
|
||||
@@ -171,12 +166,13 @@ public class CreateFormWizard
|
||||
protected ContentService contentService;
|
||||
protected MimetypeService mimetypeService;
|
||||
protected WorkflowService workflowService;
|
||||
private DataModel renderingEngineTemplatesDataModel;
|
||||
private transient DataModel renderingEngineTemplatesDataModel;
|
||||
private List<RenderingEngineTemplateData> renderingEngineTemplates = null;
|
||||
private String outputPathPatternForFormInstanceData = null;
|
||||
private String outputPathPatternForRendition = null;
|
||||
private String mimetypeForRendition = null;
|
||||
private List<SelectItem> mimetypeChoices = null;
|
||||
private transient List<SelectItem> mimetypeChoices = null;
|
||||
private transient List<SelectItem> schemaRootElementNameChoices = null;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Wizard implementation
|
||||
@@ -305,6 +301,7 @@ public class CreateFormWizard
|
||||
this.removeUploadedSchemaFile();
|
||||
this.removeUploadedRenderingEngineTemplateFile();
|
||||
this.schemaRootElementName = null;
|
||||
this.schemaRootElementNameChoices = null;
|
||||
this.formName = null;
|
||||
this.formTitle = null;
|
||||
this.formDescription = null;
|
||||
@@ -472,6 +469,7 @@ public class CreateFormWizard
|
||||
public String removeUploadedSchemaFile()
|
||||
{
|
||||
clearUpload(FILE_SCHEMA);
|
||||
this.schemaRootElementNameChoices = null;
|
||||
|
||||
// refresh the current page
|
||||
return null;
|
||||
@@ -488,7 +486,10 @@ public class CreateFormWizard
|
||||
return null;
|
||||
}
|
||||
|
||||
public String validateSchema()
|
||||
/**
|
||||
* Action handler called when the schema has been uploaded.
|
||||
*/
|
||||
public String schemaFileValueChanged(final ValueChangeEvent vce)
|
||||
{
|
||||
if (this.getSchemaFile() != null)
|
||||
{
|
||||
@@ -692,9 +693,13 @@ public class CreateFormWizard
|
||||
*/
|
||||
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();
|
||||
try
|
||||
{
|
||||
@@ -704,7 +709,7 @@ public class CreateFormWizard
|
||||
for (int i = 0; i < elementsMap.getLength(); 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)
|
||||
@@ -714,7 +719,7 @@ public class CreateFormWizard
|
||||
Utils.addErrorMessage(msg, e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return this.schemaRootElementNameChoices;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -722,7 +727,7 @@ public class CreateFormWizard
|
||||
*/
|
||||
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)
|
||||
{
|
||||
this.formTitle = formTitle;
|
||||
this.formTitle = formTitle != null && formTitle.length() != 0 ? formTitle : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -80,7 +80,7 @@ public class CreateWebContentWizard extends BaseContentWizard
|
||||
|
||||
protected String content = null;
|
||||
protected String formName;
|
||||
protected List<SelectItem> createMimeTypes;
|
||||
protected transient List<SelectItem> createMimeTypes;
|
||||
protected String createdPath = null;
|
||||
protected List<Rendition> renditions = null;
|
||||
protected FormInstanceData formInstanceData = null;
|
||||
|
@@ -32,7 +32,6 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.web.bean.wcm.AVMConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,10 +18,14 @@ package org.alfresco.web.forms.xforms;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
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.forms.*;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.fileupload.servlet.ServletRequestContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
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.Instance;
|
||||
import org.chiba.xml.xforms.XFormsElement;
|
||||
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.events.XFormsEvent;
|
||||
import org.chiba.xml.xforms.events.XFormsEventFactory;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.chiba.xml.xforms.ui.BoundElement;
|
||||
import org.chiba.xml.xforms.ui.Upload;
|
||||
import org.chiba.xml.ns.NamespaceConstants;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import org.w3c.dom.*;
|
||||
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
|
||||
import org.w3c.dom.events.Event;
|
||||
@@ -85,7 +95,7 @@ public class XFormsBean
|
||||
private ChibaBean chibaBean;
|
||||
private final SchemaFormBuilder schemaFormBuilder;
|
||||
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,
|
||||
final Form form,
|
||||
@@ -95,7 +105,7 @@ public class XFormsBean
|
||||
this.form = form;
|
||||
this.schemaFormBuilder =
|
||||
new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction",
|
||||
SchemaFormBuilder.SUBMIT_METHOD_POST,
|
||||
SchemaFormBuilder.SubmitMethod.POST,
|
||||
new XHTMLWrapperElementsBuilder(),
|
||||
baseUrl);
|
||||
}
|
||||
@@ -177,7 +187,8 @@ public class XFormsBean
|
||||
|
||||
/** @param xformsSession the current session */
|
||||
public void setXFormsSession(final XFormsSession xformsSession)
|
||||
throws XFormsException
|
||||
throws FormBuilderException,
|
||||
XFormsException
|
||||
{
|
||||
this.xformsSession = xformsSession;
|
||||
|
||||
@@ -185,87 +196,47 @@ public class XFormsBean
|
||||
final ExternalContext externalContext = facesContext.getExternalContext();
|
||||
final HttpServletRequest request = (HttpServletRequest)
|
||||
externalContext.getRequest();
|
||||
|
||||
final ServletContext servletContext = (ServletContext)
|
||||
externalContext.getContext();
|
||||
|
||||
final ChibaBean chibaBean = new ChibaBean();
|
||||
chibaBean.setConfig(servletContext.getRealPath("/WEB-INF/chiba.xml"));
|
||||
XFormsBean.storeCookies(request.getCookies(), chibaBean);
|
||||
chibaBean.setXMLContainer(this.getXFormsDocument());
|
||||
|
||||
final String cwdAVMPath = this.avmBrowseBean.getCurrentPath();
|
||||
|
||||
if (LOGGER.isDebugEnabled())
|
||||
final EventTarget et = (EventTarget)
|
||||
chibaBean.getXMLContainer().getDocumentElement();
|
||||
final EventListener el = new EventListener()
|
||||
{
|
||||
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())
|
||||
public void handleEvent(final Event e)
|
||||
{
|
||||
LOGGER.debug("generated xform: " +
|
||||
FormsService.getInstance().writeXMLToString(xformsDocument));
|
||||
XFormsBean.LOGGER.debug("received event " + e);
|
||||
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)
|
||||
chibaBean.getXMLContainer().getDocumentElement();
|
||||
final EventListener el = new EventListener()
|
||||
{
|
||||
public void handleEvent(final Event e)
|
||||
{
|
||||
XFormsBean.LOGGER.debug("received event " + e);
|
||||
XFormsBean.this.xformsSession.eventLog.add((XFormsEvent)e);
|
||||
}
|
||||
};
|
||||
// interaction events my occur during init so we have to register before
|
||||
et.addEventListener(XFormsEventFactory.CHIBA_LOAD_URI, el, true);
|
||||
et.addEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, el, true);
|
||||
et.addEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, el, true);
|
||||
|
||||
chibaBean.init();
|
||||
|
||||
// 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);
|
||||
}
|
||||
// register for notification events
|
||||
et.addEventListener(XFormsEventNames.SUBMIT, el, true);
|
||||
et.addEventListener(XFormsEventNames.SUBMIT_DONE, el, true);
|
||||
et.addEventListener(XFormsEventNames.SUBMIT_ERROR, el, true);
|
||||
et.addEventListener(XFormsEventNames.REQUIRED, el, true);
|
||||
et.addEventListener(XFormsEventNames.OPTIONAL, el, true);
|
||||
et.addEventListener(XFormsEventNames.VALID, el, true);
|
||||
et.addEventListener(XFormsEventNames.INVALID, el, true);
|
||||
et.addEventListener(XFormsEventNames.OUT_OF_RANGE, el, true);
|
||||
et.addEventListener(ChibaEventNames.STATE_CHANGED, el, true);
|
||||
et.addEventListener(ChibaEventNames.PROTOTYPE_CLONED, el, true);
|
||||
et.addEventListener(ChibaEventNames.ID_GENERATED, el, true);
|
||||
et.addEventListener(ChibaEventNames.ITEM_INSERTED, el, true);
|
||||
et.addEventListener(ChibaEventNames.ITEM_DELETED, el, true);
|
||||
et.addEventListener(ChibaEventNames.INDEX_CHANGED, el, true);
|
||||
et.addEventListener(ChibaEventNames.SWITCH_TOGGLED, el, true);
|
||||
this.xformsSession.chibaBean = chibaBean;
|
||||
}
|
||||
|
||||
@@ -275,7 +246,6 @@ public class XFormsBean
|
||||
*/
|
||||
public static XFormsSession createSession(final Document formInstanceData,
|
||||
final Form form)
|
||||
throws XFormsException
|
||||
{
|
||||
if (LOGGER.isDebugEnabled())
|
||||
{
|
||||
@@ -328,7 +298,7 @@ public class XFormsBean
|
||||
|
||||
LOGGER.debug(this + ".setXFormsValue(" + id + ", " + value + ")");
|
||||
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());
|
||||
}
|
||||
@@ -380,7 +350,7 @@ public class XFormsBean
|
||||
|
||||
LOGGER.debug(this + ".fireAction(" + id + ")");
|
||||
final ChibaBean chibaBean = this.xformsSession.chibaBean;
|
||||
chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE);
|
||||
chibaBean.dispatch(id, DOMEventNames.ACTIVATE);
|
||||
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
FormsService.getInstance().writeXML(this.getEventLog(), out);
|
||||
@@ -435,8 +405,8 @@ public class XFormsBean
|
||||
final String toItemId = (String)requestParameters.get("toItemId");
|
||||
LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")");
|
||||
final ChibaBean chibaBean = this.xformsSession.chibaBean;
|
||||
this.swapRepeatItems(chibaBean.lookup(fromItemId),
|
||||
chibaBean.lookup(toItemId));
|
||||
this.swapRepeatItems(chibaBean.getContainer().lookup(fromItemId),
|
||||
chibaBean.getContainer().lookup(toItemId));
|
||||
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
FormsService.getInstance().writeXML(this.getEventLog(), out);
|
||||
@@ -648,7 +618,7 @@ public class XFormsBean
|
||||
final String cwdAvmPath)
|
||||
{
|
||||
final NodeList includes =
|
||||
schemaDocument.getElementsByTagNameNS(SchemaFormBuilder.XMLSCHEMA_NS, "include");
|
||||
schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include");
|
||||
LOGGER.debug("rewriting " + includes.getLength() + " includes");
|
||||
for (int i = 0; i < includes.getLength(); i++)
|
||||
{
|
||||
@@ -672,7 +642,7 @@ public class XFormsBean
|
||||
final Document result = formsService.newDocument();
|
||||
final Element eventsElement = result.createElement("events");
|
||||
result.appendChild(eventsElement);
|
||||
for (XFormsEvent xfe : this.xformsSession.eventLog)
|
||||
for (XMLEvent xfe : this.xformsSession.eventLog)
|
||||
{
|
||||
final String type = xfe.getType();
|
||||
if (LOGGER.isDebugEnabled())
|
||||
@@ -740,4 +710,48 @@ public class XFormsBean
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,10 +19,8 @@ package org.alfresco.web.forms.xforms;
|
||||
import java.io.*;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.alfresco.web.forms.*;
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -47,18 +45,10 @@ public class XFormsProcessor
|
||||
final Writer out)
|
||||
throws FormProcessor.ProcessingException
|
||||
{
|
||||
try
|
||||
{
|
||||
final Session result =
|
||||
XFormsBean.createSession(instanceDataDocument, form);
|
||||
this.process(result, out);
|
||||
return result;
|
||||
}
|
||||
catch (XFormsException xfe)
|
||||
{
|
||||
LOGGER.error(xfe);
|
||||
throw new FormProcessor.ProcessingException(xfe);
|
||||
}
|
||||
final Session result =
|
||||
XFormsBean.createSession(instanceDataDocument, form);
|
||||
this.process(result, out);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +67,11 @@ public class XFormsProcessor
|
||||
{
|
||||
xforms.setXFormsSession((XFormsBean.XFormsSession)session);
|
||||
}
|
||||
catch (FormBuilderException fbe)
|
||||
{
|
||||
LOGGER.error(fbe);
|
||||
throw new ProcessingException(fbe);
|
||||
}
|
||||
catch (XFormsException xfe)
|
||||
{
|
||||
LOGGER.error(xfe);
|
||||
|
@@ -19,7 +19,7 @@ package org.alfresco.web.forms.xforms;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import org.chiba.xml.ns.NamespaceConstants;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -28,224 +28,248 @@ import java.util.*;
|
||||
* @author Sophie Ramel
|
||||
*/
|
||||
public class XHTMLWrapperElementsBuilder
|
||||
implements WrapperElementsBuilder
|
||||
implements WrapperElementsBuilder
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static class Link
|
||||
{
|
||||
public final String href;
|
||||
public final String type;
|
||||
public final String rel;
|
||||
private static class Link
|
||||
{
|
||||
public final String href;
|
||||
public final String type;
|
||||
public final String rel;
|
||||
|
||||
public Link(final String href, final String type, final String rel)
|
||||
{
|
||||
this.href = href;
|
||||
this.type = type;
|
||||
this.rel = rel;
|
||||
}
|
||||
}
|
||||
public Link(final String href, final String type, final String rel)
|
||||
{
|
||||
this.href = href;
|
||||
this.type = type;
|
||||
this.rel = rel;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static class Meta
|
||||
{
|
||||
public final String httpEquiv;
|
||||
public final String name;
|
||||
public final String content;
|
||||
public final String scheme;
|
||||
private static class Meta
|
||||
{
|
||||
public final String httpEquiv;
|
||||
public final String name;
|
||||
public final String content;
|
||||
public final String scheme;
|
||||
|
||||
public Meta(final String httpEquiv,
|
||||
final String name,
|
||||
final String content,
|
||||
final String scheme)
|
||||
{
|
||||
this.httpEquiv = httpEquiv;
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
this.scheme = scheme;
|
||||
}
|
||||
}
|
||||
public Meta(final String httpEquiv,
|
||||
final String name,
|
||||
final String content,
|
||||
final String scheme)
|
||||
{
|
||||
this.httpEquiv = httpEquiv;
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
this.scheme = scheme;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final static String XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
private final static String XHTML_PREFIX = "xhtml";
|
||||
private String title;
|
||||
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>();
|
||||
private final Collection<Meta> meta = new LinkedList<Meta>();
|
||||
private final HashMap<String, String> namespaces =
|
||||
new HashMap<String, String>();
|
||||
/**
|
||||
* add a tag "title" in the header of the HTML document
|
||||
*/
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of XHTMLWrapperElementsBuilder
|
||||
*/
|
||||
public XHTMLWrapperElementsBuilder() { }
|
||||
/**
|
||||
* add a tag "link" in the header of the HTML document
|
||||
*
|
||||
* @param href the "href" parameter of the "link" tag
|
||||
* @param type the "type" parameter of the "link" tag
|
||||
* @param rel the "rel" parameter of the "link" tag
|
||||
*/
|
||||
public void addLink(final String href,
|
||||
final String type,
|
||||
final String rel)
|
||||
{
|
||||
links.add(new Link(href, type, rel));
|
||||
}
|
||||
|
||||
/**
|
||||
* add a tag "title" in the header of the HTML document
|
||||
*/
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
/**
|
||||
* add a tag "meta" in the header of the HTML document
|
||||
*
|
||||
* @param http_equiv the "http-equiv" parameter of the "META" tag
|
||||
* @param name the "name" parameter of the "META" tag
|
||||
* @param content the "content" parameter of the "META" tag
|
||||
* @param scheme the "scheme" parameter of the "META" tag
|
||||
*/
|
||||
public void addMeta(final String httpEquiv,
|
||||
final String name,
|
||||
final String content,
|
||||
final String scheme)
|
||||
{
|
||||
meta.add(new Meta(httpEquiv, name, content, scheme));
|
||||
}
|
||||
|
||||
/**
|
||||
* add a tag "link" in the header of the HTML document
|
||||
*
|
||||
* @param href the "href" parameter of the "link" tag
|
||||
* @param type the "type" parameter of the "link" tag
|
||||
* @param rel the "rel" parameter of the "link" tag
|
||||
*/
|
||||
public void addLink(final String href,
|
||||
final String type,
|
||||
final String rel)
|
||||
{
|
||||
links.add(new Link(href, type, rel));
|
||||
}
|
||||
public void addNamespaceDeclaration(final String prefix,
|
||||
final String url)
|
||||
{
|
||||
namespaces.put(prefix, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a tag "meta" in the header of the HTML document
|
||||
*
|
||||
* @param http_equiv the "http-equiv" parameter of the "META" tag
|
||||
* @param name the "name" parameter of the "META" tag
|
||||
* @param content the "content" parameter of the "META" tag
|
||||
* @param scheme the "scheme" parameter of the "META" tag
|
||||
*/
|
||||
public void addMeta(final String httpEquiv,
|
||||
final String name,
|
||||
final String content,
|
||||
final String scheme)
|
||||
{
|
||||
meta.add(new Meta(httpEquiv, name, content, scheme));
|
||||
}
|
||||
/**
|
||||
* create the wrapper element of the different controls
|
||||
*
|
||||
* @param controlElement the control element (input, select, repeat, group, ...)
|
||||
* @return the wrapper element, already containing the control element
|
||||
*/
|
||||
public Element createControlsWrapper(final Element controlElement)
|
||||
{
|
||||
return controlElement;
|
||||
}
|
||||
|
||||
public void addNamespaceDeclaration(final String prefix,
|
||||
final String url)
|
||||
{
|
||||
namespaces.put(prefix, url);
|
||||
}
|
||||
/**
|
||||
* creates the global enveloppe of the resulting document, and puts it in the document
|
||||
*
|
||||
* @return the enveloppe
|
||||
*/
|
||||
public Element createEnvelope(Document doc)
|
||||
{
|
||||
final Element html = doc.createElementNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":html");
|
||||
//set namespace attribute
|
||||
html.setAttributeNS(NamespaceConstants.XMLNS_NS,
|
||||
NamespaceConstants.XMLNS_PREFIX + ':' + NamespaceConstants.XHTML_PREFIX,
|
||||
NamespaceConstants.XHTML_NS);
|
||||
doc.appendChild(html);
|
||||
|
||||
/**
|
||||
* create the wrapper element of the different controls
|
||||
*
|
||||
* @param controlElement the control element (input, select, repeat, group, ...)
|
||||
* @return the wrapper element, already containing the control element
|
||||
*/
|
||||
public Element createControlsWrapper(final Element controlElement)
|
||||
{
|
||||
return controlElement;
|
||||
}
|
||||
//other namespaces
|
||||
for (String prefix : this.namespaces.keySet())
|
||||
{
|
||||
html.setAttributeNS(NamespaceConstants.XMLNS_NS,
|
||||
NamespaceConstants.XMLNS_PREFIX + ":" + prefix,
|
||||
this.namespaces.get(prefix));
|
||||
|
||||
/**
|
||||
* creates the global enveloppe of the resulting document, and puts it in the document
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
//other namespaces
|
||||
for (String prefix : this.namespaces.keySet())
|
||||
{
|
||||
html.setAttributeNS(SchemaFormBuilder.XMLNS_NAMESPACE_URI,
|
||||
"xmlns:" + prefix,
|
||||
this.namespaces.get(prefix));
|
||||
/**
|
||||
* create the element that will contain the content of the group (or repeat) element
|
||||
*
|
||||
* @param groupElement the group or repeat element
|
||||
* @return the wrapper element
|
||||
*/
|
||||
public Element createGroupContentWrapper(Element groupElement)
|
||||
{
|
||||
return groupElement;
|
||||
}
|
||||
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param groupElement the group or repeat element
|
||||
* @return the wrapper element
|
||||
*/
|
||||
public Element createGroupContentWrapper(Element groupElement)
|
||||
{
|
||||
return groupElement;
|
||||
}
|
||||
/**
|
||||
* create the wrapper element of the xforms:model element
|
||||
*
|
||||
* @param modelElement the xforms:model element
|
||||
* @return the wrapper element, already containing the model
|
||||
*/
|
||||
public Element createModelWrapper(final Element modelElement)
|
||||
{
|
||||
Document doc = modelElement.getOwnerDocument();
|
||||
Element head = doc.createElementNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":head");
|
||||
head.appendChild(modelElement);
|
||||
|
||||
/**
|
||||
* 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(XHTML_NS, XHTML_PREFIX + ":body");
|
||||
//body.appendChild(formElement);
|
||||
enveloppeElement.appendChild(body);
|
||||
return body;
|
||||
}
|
||||
//eventually add other info
|
||||
if (title != null && title.length() != 0)
|
||||
{
|
||||
final Element title_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":title");
|
||||
title_el.appendChild(doc.createTextNode(title));
|
||||
head.appendChild(title_el);
|
||||
}
|
||||
|
||||
/**
|
||||
* create the wrapper element of the xforms:model element
|
||||
*
|
||||
* @param modelElement the xforms:model element
|
||||
* @return the wrapper element, already containing the model
|
||||
*/
|
||||
public Element createModelWrapper(Element modelElement)
|
||||
{
|
||||
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);
|
||||
for (Meta m : this.meta)
|
||||
{
|
||||
final Element meta_el = doc.createElementNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":META");
|
||||
head.appendChild(meta_el);
|
||||
|
||||
//attributes
|
||||
if (m.httpEquiv != null && m.httpEquiv.length() != 0)
|
||||
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":http-equiv",
|
||||
m.httpEquiv);
|
||||
if (m.name != null && m.name.length() != 0)
|
||||
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":name", m.name);
|
||||
//attributes
|
||||
if (m.httpEquiv != null && m.httpEquiv.length() != 0)
|
||||
{
|
||||
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":http-equiv",
|
||||
m.httpEquiv);
|
||||
}
|
||||
if (m.name != null && m.name.length() != 0)
|
||||
{
|
||||
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":name",
|
||||
m.name);
|
||||
}
|
||||
if (m.content != null && m.content.length() != 0)
|
||||
{
|
||||
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":content",
|
||||
m.content);
|
||||
}
|
||||
if (m.scheme != null && m.scheme.length() != 0)
|
||||
{
|
||||
meta_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":scheme",
|
||||
m.scheme);
|
||||
}
|
||||
}
|
||||
|
||||
if (m.content != null && m.content.length() != 0)
|
||||
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":content", m.content);
|
||||
for (Link l : this.links)
|
||||
{
|
||||
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)
|
||||
meta_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":scheme", m.scheme);
|
||||
}
|
||||
|
||||
for (Link l : this.links)
|
||||
{
|
||||
Element link_el = doc.createElementNS(XHTML_NS, XHTML_PREFIX + ":LINK");
|
||||
head.appendChild(link_el);
|
||||
|
||||
//attributes
|
||||
if (l.href != null && l.href.length() != 0)
|
||||
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":href", l.href);
|
||||
|
||||
if (l.type != null && l.type.length() != 0)
|
||||
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":type", l.type);
|
||||
|
||||
if (l.rel != null && l.rel.length() != 0)
|
||||
link_el.setAttributeNS(XHTML_NS, XHTML_PREFIX + ":rel", l.rel);
|
||||
}
|
||||
return head;
|
||||
}
|
||||
//attributes
|
||||
if (l.href != null && l.href.length() != 0)
|
||||
{
|
||||
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":href",
|
||||
l.href);
|
||||
}
|
||||
if (l.type != null && l.type.length() != 0)
|
||||
{
|
||||
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":type",
|
||||
l.type);
|
||||
}
|
||||
if (l.rel != null && l.rel.length() != 0)
|
||||
{
|
||||
link_el.setAttributeNS(NamespaceConstants.XHTML_NS,
|
||||
NamespaceConstants.XHTML_PREFIX + ":rel",
|
||||
l.rel);
|
||||
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
}
|
||||
|
@@ -109,9 +109,10 @@ public class UIFormProcessor extends SelfRenderingComponent
|
||||
out));
|
||||
}
|
||||
}
|
||||
catch (FormProcessor.ProcessingException fppe)
|
||||
catch (Throwable t)
|
||||
{
|
||||
Utils.addErrorMessage(fppe.getMessage(), fppe);
|
||||
Utils.addErrorMessage(t.getMessage(), t);
|
||||
out.write(t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user