mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
a bunch of refactoring of back end templating wizards. removing the chiba-web stuff as it is no longer used. more updates to dojo generator. adding in an XFormsBean to handle ajax requests from the form.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3500 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -454,7 +454,7 @@ public class Application
|
||||
{
|
||||
Locale locale = parseLocale(code);
|
||||
|
||||
session.putValue(LOCALE, locale);
|
||||
session.setAttribute(LOCALE, locale);
|
||||
session.removeAttribute(MESSAGE_BUNDLE);
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,10 @@ import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.FileUploadBean;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.RequestContext;
|
||||
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;
|
||||
|
||||
@@ -55,7 +57,8 @@ public class UploadFileServlet extends BaseServlet
|
||||
{
|
||||
String uploadId = null;
|
||||
String returnPage = null;
|
||||
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
||||
final RequestContext requestContext = new ServletRequestContext(request);
|
||||
boolean isMultipart = ServletFileUpload.isMultipartContent(requestContext);
|
||||
|
||||
try
|
||||
{
|
||||
|
@@ -28,10 +28,14 @@ public interface AjaxCommand
|
||||
*
|
||||
* @param facesContext FacesContext
|
||||
* @param expression The binding expression
|
||||
* <!-- @param responseMimeType The response mime-type -->
|
||||
* @param request The request
|
||||
* @param response The response
|
||||
*/
|
||||
public abstract void execute(FacesContext facesContext, String expression,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException;
|
||||
public abstract void execute(FacesContext facesContext,
|
||||
String expression,
|
||||
// String responseMimeType,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException;
|
||||
}
|
||||
|
189
source/java/org/alfresco/web/bean/ajax/XFormsBean.java
Normal file
189
source/java/org/alfresco/web/bean/ajax/XFormsBean.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.bean.ajax;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.alfresco.web.templating.*;
|
||||
import org.alfresco.web.templating.xforms.*;
|
||||
import org.alfresco.web.templating.xforms.schemabuilder.FormBuilderException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.chiba.xml.xforms.ChibaBean;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.chiba.xml.xforms.events.XFormsEventFactory;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.events.EventTarget;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class XFormsBean
|
||||
implements EventListener
|
||||
{
|
||||
private static final Log LOGGER = LogFactory.getLog(XFormsBean.class);
|
||||
|
||||
private TemplateType tt;
|
||||
private Document instanceData = null;
|
||||
private ChibaBean chibaBean;
|
||||
private Map context = new HashMap();
|
||||
|
||||
public TemplateType getTemplateType()
|
||||
{
|
||||
return this.tt;
|
||||
}
|
||||
|
||||
public void setTemplateType(final TemplateType tt)
|
||||
{
|
||||
this.tt = tt;
|
||||
}
|
||||
|
||||
public void setInstanceData(final Document instanceData)
|
||||
{
|
||||
this.instanceData = instanceData;
|
||||
}
|
||||
|
||||
public void init()
|
||||
throws XFormsException
|
||||
{
|
||||
this.chibaBean = new ChibaBean();
|
||||
this.chibaBean.setContext(context);
|
||||
|
||||
try
|
||||
{
|
||||
LOGGER.debug("initializing " + this +
|
||||
" with tt " + tt.getName());
|
||||
final XFormsInputMethod tim = (XFormsInputMethod)
|
||||
tt.getInputMethods().get(0);
|
||||
final Document form = tim.getXForm(instanceData, tt);
|
||||
this.chibaBean.setXMLContainer(form);
|
||||
this.chibaBean.init();
|
||||
EventTarget et = (EventTarget)
|
||||
this.chibaBean.getXMLContainer().getDocumentElement();
|
||||
et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, this, true);
|
||||
}
|
||||
catch (FormBuilderException fbe)
|
||||
{
|
||||
LOGGER.error(fbe);
|
||||
}
|
||||
}
|
||||
|
||||
public void getXForm()
|
||||
throws IOException,
|
||||
XFormsException
|
||||
{
|
||||
LOGGER.debug(this + " building xform");
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
|
||||
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
|
||||
// final String templateTypeName = (String)requestParameters.get("template_type_name");
|
||||
|
||||
LOGGER.debug("building xform for " + this.tt.getName()); //templateTypeName);
|
||||
|
||||
// final TemplatingService ts = TemplatingService.getInstance();
|
||||
// final TemplateType tt = ts.getTemplateType(templateTypeName);
|
||||
// final XFormsInputMethod tim = (XFormsInputMethod)
|
||||
// tt.getInputMethods().get(0);
|
||||
// final Document form = tim.getXForm(tt);
|
||||
final Node form = this.chibaBean.getXMLContainer();
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
ts.writeXML(form, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the value of a control in the processor.
|
||||
*
|
||||
* @param id the id of the control in the host document
|
||||
* @param value the new value
|
||||
* @return the list of events that may result through this action
|
||||
*/
|
||||
public void setXFormsValue()
|
||||
throws XFormsException
|
||||
{
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
|
||||
final String id = (String)requestParameters.get("id");
|
||||
final String value = (String)requestParameters.get("value");
|
||||
|
||||
LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")");
|
||||
this.chibaBean.updateControlValue(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the value of a control in the processor.
|
||||
*
|
||||
* @param id the id of the control in the host document
|
||||
* @param value the new value
|
||||
* @return the list of events that may result through this action
|
||||
*/
|
||||
public void fireAction()
|
||||
throws XFormsException
|
||||
{
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
|
||||
final String id = (String)requestParameters.get("id");
|
||||
|
||||
LOGGER.debug(this + " fireAction(" + id + ")");
|
||||
this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the value of a control in the processor.
|
||||
*
|
||||
* @param id the id of the control in the host document
|
||||
* @param value the new value
|
||||
* @return the list of events that may result through this action
|
||||
*/
|
||||
public void handleAction()
|
||||
throws Exception
|
||||
{
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final HttpServletRequest request = (HttpServletRequest)
|
||||
context.getExternalContext().getRequest();
|
||||
BufferedReader bufferedReader = request.getReader();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
do
|
||||
{
|
||||
String s = bufferedReader.readLine();
|
||||
if (s == null)
|
||||
break;
|
||||
sb.append(s).append('\n');
|
||||
}
|
||||
while (true);
|
||||
String xml = sb.toString();
|
||||
System.out.println("you submitting " + xml);
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
out.write(xml);
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void handleEvent(Event e)
|
||||
{
|
||||
LOGGER.debug("handleEvent " + e);
|
||||
}
|
||||
}
|
@@ -36,6 +36,7 @@ import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.data.IDataContainer;
|
||||
import org.alfresco.web.data.QuickSort;
|
||||
import org.alfresco.web.templating.*;
|
||||
import org.alfresco.web.bean.ajax.XFormsBean;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -44,6 +45,8 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import java.io.OutputStreamWriter;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
|
||||
/**
|
||||
* Bean implementation for the "Create Content Wizard" dialog
|
||||
@@ -53,7 +56,7 @@ import java.io.OutputStreamWriter;
|
||||
public class CreateContentWizard extends BaseContentWizard
|
||||
{
|
||||
protected String content = null;
|
||||
protected String templateType;
|
||||
protected String templateTypeName;
|
||||
protected List<SelectItem> createMimeTypes;
|
||||
|
||||
private static final Log LOGGER =
|
||||
@@ -71,12 +74,12 @@ public class CreateContentWizard extends BaseContentWizard
|
||||
{
|
||||
LOGGER.debug("saving file content to " + this.fileName);
|
||||
saveContent(null, this.content);
|
||||
if (this.templateType != null)
|
||||
if (this.templateTypeName != null)
|
||||
{
|
||||
LOGGER.debug("generating template output for " + this.templateType);
|
||||
this.nodeService.setProperty(this.createdNode, TT_QNAME, this.templateType);
|
||||
LOGGER.debug("generating template output for " + this.templateTypeName);
|
||||
this.nodeService.setProperty(this.createdNode, TT_QNAME, this.templateTypeName);
|
||||
TemplatingService ts = TemplatingService.getInstance();
|
||||
TemplateType tt = ts.getTemplateType(this.templateType);
|
||||
TemplateType tt = this.getTemplateType();
|
||||
if (tt.getOutputMethods().size() != 0)
|
||||
{
|
||||
try {
|
||||
@@ -104,7 +107,7 @@ public class CreateContentWizard extends BaseContentWizard
|
||||
new OutputStreamWriter(writer.getContentOutputStream());
|
||||
tom.generate(ts.parseXML(this.content), tt, out);
|
||||
out.close();
|
||||
this.nodeService.setProperty(fileNodeRef, TT_QNAME, this.templateType);
|
||||
this.nodeService.setProperty(fileNodeRef, TT_QNAME, this.templateTypeName);
|
||||
|
||||
LOGGER.debug("generated " + fileName + " using " + tom);
|
||||
}
|
||||
@@ -127,7 +130,7 @@ public class CreateContentWizard extends BaseContentWizard
|
||||
|
||||
this.content = null;
|
||||
this.inlineEdit = true;
|
||||
this.templateType = null;
|
||||
this.templateTypeName = null;
|
||||
this.mimeType = MimetypeMap.MIMETYPE_HTML;
|
||||
}
|
||||
|
||||
@@ -253,17 +256,23 @@ public class CreateContentWizard extends BaseContentWizard
|
||||
return this.createMimeTypes;
|
||||
}
|
||||
|
||||
public String getTemplateType()
|
||||
public String getTemplateTypeName()
|
||||
{
|
||||
return this.templateType;
|
||||
return this.templateTypeName;
|
||||
}
|
||||
|
||||
public TemplateType getTemplateType()
|
||||
{
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
return ts.getTemplateType(this.getTemplateTypeName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param templateType Sets the currently selected template type
|
||||
*/
|
||||
public void setTemplateType(String templateType)
|
||||
public void setTemplateTypeName(final String templateTypeName)
|
||||
{
|
||||
this.templateType = templateType;
|
||||
this.templateTypeName = templateTypeName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -49,6 +49,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
||||
/**
|
||||
* Bean implementation for the "Create Content Wizard" dialog
|
||||
*
|
||||
@@ -292,44 +293,10 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
|
||||
final TemplateType result = ts.newTemplateType(rootTagName, d);
|
||||
if (this.getPresentationTemplateFile() != null)
|
||||
{
|
||||
result .addOutputMethod(new XSLTOutputMethod(this.getPresentationTemplateFile()));
|
||||
result.addOutputMethod(new XSLTOutputMethod(this.getPresentationTemplateFile()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getFormURL()
|
||||
{
|
||||
try
|
||||
{
|
||||
final TemplateType tt = this.getTemplateType();
|
||||
final TemplateInputMethod tim = tt.getInputMethods().get(0);
|
||||
return tim.getInputURL(tt.getSampleXml(tt.getName()), tt);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// public String getSchemaFormURL()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// final TemplatingService ts = TemplatingService.getInstance();
|
||||
// final String rootTagName =
|
||||
// this.getSchemaFileName().replaceAll("([^\\.])\\..+", "$1");
|
||||
// final Document d = ts.parseXML(this.getSchemaFile());
|
||||
// this.tt = ts.newTemplateType(rootTagName, d);
|
||||
// final TemplateInputMethod tim = tt.getInputMethods()[0];
|
||||
// return tim.getSchemaInputURL(tt);
|
||||
// }
|
||||
// catch (Throwable t)
|
||||
// {
|
||||
// t.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return Returns a list of mime types to allow the user to select from
|
||||
|
@@ -17,11 +17,13 @@
|
||||
package org.alfresco.web.templating;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import java.io.Writer;
|
||||
|
||||
public interface TemplateInputMethod
|
||||
{
|
||||
public String getInputURL(final Document xmlContent,
|
||||
final TemplateType tt);
|
||||
public void generate(final Document xmlContent,
|
||||
final TemplateType tt,
|
||||
final Writer out);
|
||||
|
||||
// public String getSchemaInputURL(final TemplateType tt);
|
||||
}
|
||||
|
@@ -31,9 +31,12 @@ import org.alfresco.web.templating.xforms.*;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class TemplatingService
|
||||
{
|
||||
private static final Log LOGGER = LogFactory.getLog(TemplatingService.class);
|
||||
private final static TemplatingService INSTANCE = new TemplatingService();
|
||||
|
||||
private ArrayList<TemplateType> templateTypes =
|
||||
@@ -77,15 +80,29 @@ public class TemplatingService
|
||||
}
|
||||
|
||||
public Document newDocument()
|
||||
throws ParserConfigurationException,
|
||||
SAXException,
|
||||
IOException
|
||||
{
|
||||
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setValidating(false);
|
||||
final DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
return db.newDocument();
|
||||
try
|
||||
{
|
||||
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setValidating(false);
|
||||
final DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
return db.newDocument();
|
||||
}
|
||||
catch (ParserConfigurationException pce)
|
||||
{
|
||||
assert false : pce;
|
||||
LOGGER.error(pce);
|
||||
return null;
|
||||
}
|
||||
// catch (SAXException saxe)
|
||||
// {
|
||||
// LOGGER.error(saxe);
|
||||
// }
|
||||
// catch (IOException ioe)
|
||||
// {
|
||||
// LOGGER.error(ioe);
|
||||
// }
|
||||
}
|
||||
|
||||
public void writeXML(final Node n, final Writer output)
|
||||
|
@@ -63,6 +63,7 @@ public class DojoGenerator
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
request.setAttribute("xform", this.inputNode);
|
||||
final RequestDispatcher rd = request.getRequestDispatcher("/jsp/content/xforms/dojo-generator.jsp");
|
||||
rd.include(request, response);
|
||||
@@ -73,4 +74,3 @@ public class DojoGenerator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,17 +18,22 @@ package org.alfresco.web.templating.xforms;
|
||||
|
||||
import java.io.*;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.web.templating.*;
|
||||
import org.alfresco.web.templating.xforms.schemabuilder.*;
|
||||
import org.alfresco.web.bean.ajax.XFormsBean;
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
|
||||
public class XFormsInputMethod
|
||||
implements TemplateInputMethod
|
||||
@@ -39,47 +44,48 @@ public class XFormsInputMethod
|
||||
{
|
||||
}
|
||||
|
||||
public String getInputURL(final Document xmlContent, final TemplateType tt)
|
||||
public void generate(final Document xmlContent,
|
||||
final TemplateType tt,
|
||||
final Writer out)
|
||||
{
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
final XFormsBean xforms = (XFormsBean)
|
||||
FacesHelper.getManagedBean(fc, "XFormsBean");
|
||||
xforms.setInstanceData(xmlContent);
|
||||
xforms.setTemplateType(tt);
|
||||
try
|
||||
{
|
||||
final Document xform = this.getXForm(xmlContent, tt);
|
||||
final String id = getDocumentElementNameNoNS(xmlContent);
|
||||
// this.saveInChiba(id, xform);
|
||||
final File xformFile = TempFileProvider.createTempFile("alfresco", ".xform");
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
ts.writeXML(xform, xformFile);
|
||||
final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
final String cp =
|
||||
fc.getExternalContext().getRequestContextPath();
|
||||
return cp + "/XFormsServlet?form=" + xformFile.toURI().toString();
|
||||
{
|
||||
xforms.init();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
catch (XFormsException xfe)
|
||||
{
|
||||
LOGGER.error(xfe);
|
||||
}
|
||||
}
|
||||
|
||||
final String cp = fc.getExternalContext().getRequestContextPath();
|
||||
|
||||
public String getSchemaInputURL(final TemplateType tt)
|
||||
{
|
||||
try
|
||||
{
|
||||
// final Document xform = this.getXFormForSchema(tt);
|
||||
// final File xformFile = TempFileProvider.createTempFile("alfresco", ".xform");
|
||||
// final TemplatingService ts = TemplatingService.getInstance();
|
||||
// ts.writeXML(tt.getSchema(), xformFile);
|
||||
// final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
// final String cp =
|
||||
// fc.getExternalContext().getRequestContextPath();
|
||||
// return cp + "/XFormsServlet?form=" + xformFile.toURI().toString();
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
final Document result = ts.newDocument();
|
||||
final Element div = result.createElement("div");
|
||||
div.setAttribute("id", "alf-ui");
|
||||
div.setAttribute("style", "width: 100%; border: solid 1px orange;");
|
||||
result.appendChild(div);
|
||||
|
||||
Element e = result.createElement("script");
|
||||
e.appendChild(result.createTextNode("djConfig = { isDebug: true };\n" +
|
||||
"var WEBAPP_CONTEXT = \"" + cp + "\";\n"));
|
||||
div.appendChild(e);
|
||||
e = result.createElement("script");
|
||||
e.setAttribute("type", "text/javascript");
|
||||
e.setAttribute("src", cp + "/scripts/ajax/dojo.js");
|
||||
e.appendChild(result.createTextNode("\n"));
|
||||
div.appendChild(e);
|
||||
e = result.createElement("script");
|
||||
e.setAttribute("type", "text/javascript");
|
||||
e.setAttribute("src", cp + "/scripts/ajax/xforms.js");
|
||||
e.appendChild(result.createTextNode("\n"));
|
||||
div.appendChild(e);
|
||||
ts.writeXML(result, out);
|
||||
}
|
||||
|
||||
private static String getDocumentElementNameNoNS(final Document d)
|
||||
@@ -92,37 +98,12 @@ public class XFormsInputMethod
|
||||
// System.out.println("name " + name + " prefix " + prefix + " ns uri " + namespace);
|
||||
// return name.replaceAll(".+\\:", "");
|
||||
}
|
||||
|
||||
// public Document getXFormForSchema(final TemplateType tt)
|
||||
// throws FormBuilderException
|
||||
// {
|
||||
// final TemplatingService ts = TemplatingService.getInstance();
|
||||
//
|
||||
// final File schemaFile = TempFileProvider.createTempFile("alfresco", ".schema");
|
||||
// ts.writeXML(tt.getSchema(), schemaFile);
|
||||
// final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
// final String cp =
|
||||
// fc.getExternalContext().getRequestContextPath();
|
||||
//
|
||||
// final SchemaFormBuilder builder =
|
||||
// new BaseSchemaFormBuilder("schema",
|
||||
// schemaFile.toURI().toString(),
|
||||
// cp + "/jsp/content/xforms/form/debug-instance.jsp",
|
||||
// "post",
|
||||
// new XHTMLWrapperElementsBuilder(),
|
||||
// null,
|
||||
// null,
|
||||
// true);
|
||||
// System.out.println("building xform for schema " + schemaFile.getPath());
|
||||
// final Document result = builder.buildForm("/Users/arielb/Documents/alfresco/xsd/XMLSchema.xsd");
|
||||
// // xmlContentFile.delete();
|
||||
// // schemaFile.delete();
|
||||
// return result;
|
||||
// }
|
||||
|
||||
public Document getXForm(final Document xmlContent, final TemplateType tt)
|
||||
public Document getXForm(Document xmlContent, final TemplateType tt)
|
||||
throws FormBuilderException
|
||||
{
|
||||
if (xmlContent == null)
|
||||
xmlContent = tt.getSampleXml(tt.getName());
|
||||
final TemplatingService ts = TemplatingService.getInstance();
|
||||
final File schemaFile = TempFileProvider.createTempFile("alfresco", ".schema");
|
||||
try
|
||||
@@ -135,33 +116,26 @@ public class XFormsInputMethod
|
||||
LOGGER.error(ioe);
|
||||
}
|
||||
final FacesContext fc = FacesContext.getCurrentInstance();
|
||||
final String cp =
|
||||
fc.getExternalContext().getRequestContextPath();
|
||||
|
||||
final HttpServletRequest request = (HttpServletRequest)
|
||||
fc.getExternalContext().getRequest();
|
||||
final String baseUrl = (request.getScheme() + "://" +
|
||||
request.getServerName() + ':' +
|
||||
request.getServerPort());
|
||||
LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder");
|
||||
|
||||
final SchemaFormBuilder builder =
|
||||
new BaseSchemaFormBuilder(getDocumentElementNameNoNS(xmlContent),
|
||||
xmlContent,
|
||||
"http://localhost:8080" + cp + "/jsp/content/xforms/debug-instance.jsp",
|
||||
request.getContextPath() + "/ajax/invoke/XFormsBean.handleAction",
|
||||
"post",
|
||||
new XHTMLWrapperElementsBuilder(),
|
||||
null,
|
||||
null,
|
||||
baseUrl,
|
||||
true);
|
||||
System.out.println("building xform for schema " + schemaFile.getPath());
|
||||
LOGGER.debug("building xform for schema " + schemaFile.getPath());
|
||||
final Document result = builder.buildForm(schemaFile.getPath());
|
||||
// xmlContentFile.delete();
|
||||
// schemaFile.delete();
|
||||
return result;
|
||||
}
|
||||
|
||||
// private void saveInChiba(final String fileName, final Document d)
|
||||
// throws IOException
|
||||
// {
|
||||
// final ServletContext myContext = (ServletContext)
|
||||
// FacesContext.getCurrentInstance().getExternalContext().getContext();
|
||||
// final ServletContext chiba = myContext.getContext("/chiba");
|
||||
// final File outputFile = new File(new File(chiba.getRealPath("/forms")),
|
||||
// fileName + ".xhtml");
|
||||
// TemplatingService.getInstance().writeXML(d.getDocumentElement(), outputFile);
|
||||
// }
|
||||
}
|
||||
|
@@ -1,127 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.flux;
|
||||
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.chiba.xml.xforms.XFormsConstants;
|
||||
import org.chiba.xml.xforms.events.XFormsEvent;
|
||||
import org.chiba.xml.xforms.events.XFormsEventFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EventLog logs all events happening in XForms processor and build a DOM
|
||||
* document which represent those events.
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @version $Id: EventLog.java,v 1.6 2005/12/21 22:59:27 unl Exp $
|
||||
*/
|
||||
public class EventLog {
|
||||
private static List HELPER_ELEMENTS =
|
||||
Arrays.asList(new String[]
|
||||
{
|
||||
XFormsConstants.LABEL,
|
||||
XFormsConstants.HELP,
|
||||
XFormsConstants.HINT,
|
||||
XFormsConstants.ALERT,
|
||||
XFormsConstants.VALUE
|
||||
});
|
||||
|
||||
private static List SELECTOR_ELEMENTS =
|
||||
Arrays.asList(new String[]
|
||||
{
|
||||
XFormsConstants.SELECT1,
|
||||
XFormsConstants.SELECT
|
||||
});
|
||||
|
||||
private final Document doc;
|
||||
private final Element root;
|
||||
private Element selector;
|
||||
|
||||
public EventLog() {
|
||||
this.doc = DOMUtil.newDocument(false, false);
|
||||
this.root = this.doc.createElement("eventlog");
|
||||
this.root.setAttribute("id", "eventlog");
|
||||
this.doc.appendChild(this.root);
|
||||
}
|
||||
|
||||
public Element getLog() {
|
||||
return (Element) this.root.cloneNode(true);
|
||||
}
|
||||
|
||||
public void add(XFormsEvent event) {
|
||||
// get target properties
|
||||
String type = event.getType();
|
||||
Element target = (Element) event.getTarget();
|
||||
String targetId = target.getAttributeNS(null, "id");
|
||||
String targetName = target.getLocalName();
|
||||
|
||||
// create event element
|
||||
Element element;
|
||||
|
||||
if (XFormsEventFactory.CHIBA_STATE_CHANGED.equals(type) && SELECTOR_ELEMENTS.contains(targetName)) {
|
||||
// selector events are always appended to the end of the log
|
||||
// to ensure their items' labels and values are updated before
|
||||
element = insert(null, type, targetId, targetName);
|
||||
if (this.selector == null)
|
||||
this.selector = element;
|
||||
}
|
||||
else
|
||||
{
|
||||
// all other events are inserted before any selector events
|
||||
element = insert(this.selector, type, targetId, targetName);
|
||||
}
|
||||
|
||||
if (XFormsEventFactory.CHIBA_STATE_CHANGED.equals(type) && HELPER_ELEMENTS.contains(targetName))
|
||||
{
|
||||
// parent id is needed for updating all helper elements cause they
|
||||
// are identified by '<parentId>-label' etc. rather than their own id
|
||||
String parentId = ((Element) target.getParentNode()).getAttributeNS(null, "id");
|
||||
addProperty(element, "parentId", parentId);
|
||||
}
|
||||
|
||||
// add event params
|
||||
Iterator iterator = event.getPropertyNames().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
String name = (String) iterator.next();
|
||||
addProperty(element, name, event.getContextInfo(name).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public Element add(String type, String targetId, String targetName){
|
||||
return insert(this.selector, type, targetId, targetName);
|
||||
}
|
||||
|
||||
public Element addProperty(Element element, String name, String value) {
|
||||
Element property = this.doc.createElement("property");
|
||||
property.setAttribute("name", name);
|
||||
property.appendChild(this.doc.createTextNode(value));
|
||||
element.appendChild(property);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private Element insert(Element ref, String type, String targetId, String targetName)
|
||||
{
|
||||
// create event element
|
||||
Element element = this.doc.createElement("event");
|
||||
this.root.insertBefore(element, ref);
|
||||
|
||||
// add target properties
|
||||
element.setAttribute("type", type);
|
||||
element.setAttribute("targetId", targetId);
|
||||
element.setAttribute("targetName", targetName);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
// clean the log
|
||||
public void flush()
|
||||
{
|
||||
DOMUtil.removeAllChildren(this.root);
|
||||
this.selector = null;
|
||||
}
|
||||
}
|
@@ -1,265 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.flux;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.chiba.adapter.AbstractChibaAdapter;
|
||||
import org.chiba.adapter.ChibaEvent;
|
||||
import org.alfresco.web.templating.xforms.servlet.HttpRequestHandler;
|
||||
import org.alfresco.web.templating.xforms.servlet.ServletAdapter;
|
||||
import org.alfresco.web.templating.xforms.servlet.ChibaServlet;
|
||||
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.Repeat;
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.events.EventTarget;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Adapter for processing DWR calls and building appropriate responses. This
|
||||
* class is not exposed through DWR. Instead a Facadeclass 'FluxFacade' will be
|
||||
* exposed that only allows to use the dispatch method. All other methods will
|
||||
* be hidden for security.
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @version $Id: FluxAdapter.java,v 1.15 2005/12/21 22:59:27 unl Exp $
|
||||
*/
|
||||
public class FluxAdapter extends AbstractChibaAdapter implements EventListener {
|
||||
private static final Log LOGGER = LogFactory.getLog(FluxAdapter.class);
|
||||
|
||||
private final HttpSession session;
|
||||
private EventLog eventLog;
|
||||
private EventTarget root;
|
||||
|
||||
|
||||
public FluxAdapter(HttpSession session) {
|
||||
this.chibaBean = createXFormsProcessor();
|
||||
this.context = new HashMap();
|
||||
chibaBean.setContext(this.context);
|
||||
this.eventLog = new EventLog();
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the Adapter. This is necessary cause often the using
|
||||
* application will need to configure the Adapter before actually using it.
|
||||
*
|
||||
* @throws org.chiba.xml.xforms.exception.XFormsException
|
||||
*/
|
||||
public void init() throws XFormsException {
|
||||
try {
|
||||
// get docuent root as event target in order to capture all events
|
||||
this.root = (EventTarget) this.chibaBean.getXMLContainer().getDocumentElement();
|
||||
|
||||
// interaction events my occur during init so we have to register before
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_LOAD_URI, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, this, true);
|
||||
|
||||
// init processor
|
||||
this.chibaBean.init();
|
||||
|
||||
// todo: add getter for event log
|
||||
setContextParam("EVENT-LOG", this.eventLog);
|
||||
|
||||
// register for notification events
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_STATE_CHANGED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_PROTOTYPE_CLONED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_ID_GENERATED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_ITEM_INSERTED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_ITEM_DELETED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_INDEX_CHANGED, this, true);
|
||||
this.root.addEventListener(XFormsEventFactory.CHIBA_SWITCH_TOGGLED, this, true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new XFormsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a ChibaEvent to trigger some XForms processing such as updating
|
||||
* of values or execution of triggers.
|
||||
*
|
||||
* @param event an application specific event
|
||||
* @throws org.chiba.xml.xforms.exception.XFormsException
|
||||
* @see org.chiba.adapter.DefaultChibaEventImpl
|
||||
*/
|
||||
public void dispatch(ChibaEvent event) throws XFormsException {
|
||||
LOGGER.debug("dispatching " + event);
|
||||
this.eventLog.flush();
|
||||
String targetId = event.getId();
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Event " + event.getEventName() + " dispatched");
|
||||
LOGGER.debug("Event target: " + targetId);
|
||||
// try
|
||||
// {
|
||||
// DOMUtil.prettyPrintDOM(this.chibaBean.getXMLContainer(), System.out);
|
||||
// } catch (TransformerException e) {
|
||||
// throw new XFormsException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
if (event.getEventName().equals(FluxFacade.FLUX_ACTIVATE_EVENT))
|
||||
chibaBean.dispatch(targetId, XFormsEventFactory.DOM_ACTIVATE);
|
||||
else if (event.getEventName().equals("SETINDEX")) {
|
||||
int position = Integer.parseInt((String) event.getContextInfo());
|
||||
Repeat repeat = (Repeat) this.chibaBean.lookup(targetId);
|
||||
repeat.setIndex(position);
|
||||
}
|
||||
else if (event.getEventName().equals("SETVALUE")) {
|
||||
if (LOGGER.isDebugEnabled())
|
||||
LOGGER.debug("Event contextinfo: " + event.getContextInfo());
|
||||
this.chibaBean.updateControlValue(targetId, (String) event.getContextInfo());
|
||||
}
|
||||
else if (event.getEventName().equalsIgnoreCase("http-request")) {
|
||||
// todo: make request handler member of web adapter
|
||||
HttpRequestHandler httpRequestHandler = new HttpRequestHandler(this.chibaBean);
|
||||
httpRequestHandler.execute(event);
|
||||
}
|
||||
else {
|
||||
throw new XFormsException("Unknown or illegal event type");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* listen to processor and add a DefaultChibaEventImpl object to the
|
||||
* EventQueue.
|
||||
*
|
||||
* @param event the handled DOMEvent
|
||||
*/
|
||||
public void handleEvent(Event event)
|
||||
{
|
||||
LOGGER.debug("handleEvent(" + event + ")");
|
||||
try {
|
||||
if (event instanceof XFormsEvent)
|
||||
{
|
||||
XFormsEvent xformsEvent = (XFormsEvent) event;
|
||||
String type = xformsEvent.getType();
|
||||
if (XFormsEventFactory.CHIBA_REPLACE_ALL.equals(type))
|
||||
{
|
||||
// get event context and store it in session
|
||||
Map submissionResponse = new HashMap();
|
||||
submissionResponse.put("header", xformsEvent.getContextInfo("header"));
|
||||
submissionResponse.put("body", xformsEvent.getContextInfo("body"));
|
||||
this.session.setAttribute(ChibaServlet.CHIBA_SUBMISSION_RESPONSE, submissionResponse);
|
||||
|
||||
// get event properties
|
||||
Element target = (Element) event.getTarget();
|
||||
String targetId = target.getAttributeNS(null, "id");
|
||||
String targetName = target.getLocalName();
|
||||
|
||||
// add event properties to log
|
||||
this.eventLog.add(type, targetId, targetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add event to log
|
||||
this.eventLog.add(xformsEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("**** " + e.getMessage());
|
||||
LOGGER.debug("error " + e.getMessage() + " while handling event " + event);
|
||||
try {
|
||||
this.chibaBean.getContainer().handleEventException(e);
|
||||
}
|
||||
catch (XFormsException xfe) {
|
||||
xfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* terminates the XForms processing. right place to do cleanup of
|
||||
* resources.
|
||||
*
|
||||
* @throws org.chiba.xml.xforms.exception.XFormsException
|
||||
*/
|
||||
public void shutdown() throws XFormsException {
|
||||
try {
|
||||
// deregister for notification events
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_STATE_CHANGED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_PROTOTYPE_CLONED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_ID_GENERATED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_ITEM_INSERTED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_ITEM_DELETED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_INDEX_CHANGED, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_SWITCH_TOGGLED, this, true);
|
||||
|
||||
// shutdown processor
|
||||
this.chibaBean.shutdown();
|
||||
this.chibaBean = null;
|
||||
|
||||
// deregister for interaction events
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_LOAD_URI, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, this, true);
|
||||
this.root.removeEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, this, true);
|
||||
|
||||
this.root = null;
|
||||
|
||||
System.gc();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new XFormsException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the upload location. This string represents the destination
|
||||
* (data-sink) for uploads.
|
||||
*
|
||||
* @param destination a String representing the location where to store
|
||||
* uploaded files/data.
|
||||
*/
|
||||
public void setUploadDestination(String destination) {
|
||||
this.uploadDestination = destination;
|
||||
//todo: this should be moved to parent class. it's duplicated in both Adapters
|
||||
setContextParam(ServletAdapter.HTTP_UPLOAD_DIR, this.uploadDestination);
|
||||
}
|
||||
|
||||
protected String escape(String string) {
|
||||
if (string == null) {
|
||||
return string;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer(string.length());
|
||||
char c;
|
||||
for (int index = 0; index < string.length(); index++) {
|
||||
c = string.charAt(index);
|
||||
switch (c) {
|
||||
case '\n':
|
||||
buffer.append('\\').append('n');
|
||||
break;
|
||||
case '\r':
|
||||
buffer.append('\\').append('r');
|
||||
break;
|
||||
case '\t':
|
||||
buffer.append('\\').append('t');
|
||||
break;
|
||||
case '\'':
|
||||
buffer.append('\\').append('\'');
|
||||
break;
|
||||
case '\"':
|
||||
buffer.append('\\').append('\"');
|
||||
break;
|
||||
default:
|
||||
buffer.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
// end of class
|
@@ -1,23 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.flux;
|
||||
|
||||
/**
|
||||
* Used for signalling problems with Flux execution
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @version $Id: FluxException.java,v 1.1 2005/11/08 17:34:07 joernt Exp $
|
||||
*/
|
||||
public class FluxException extends Exception{
|
||||
|
||||
public FluxException() {
|
||||
}
|
||||
|
||||
public FluxException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
public FluxException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,144 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.flux;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.chiba.adapter.ChibaAdapter;
|
||||
import org.chiba.adapter.ChibaEvent;
|
||||
import org.chiba.adapter.DefaultChibaEventImpl;
|
||||
import org.alfresco.web.templating.xforms.servlet.ChibaServlet;
|
||||
import org.chiba.xml.util.DOMUtil;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.w3c.dom.Element;
|
||||
import uk.ltd.getahead.dwr.ExecutionContext;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
/**
|
||||
* AJAX Facade class to hide the full functionality from the web-client.
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @version $Id: FluxFacade.java,v 1.9 2005/12/21 19:06:55 unl Exp $
|
||||
*/
|
||||
public class FluxFacade
|
||||
{
|
||||
|
||||
//this is a custom event to activate a trigger in XForms.
|
||||
private static final Log LOGGER = LogFactory.getLog(FluxFacade.class);
|
||||
public static final String FLUX_ACTIVATE_EVENT = "flux-action-event";
|
||||
ChibaAdapter adapter = null;
|
||||
private HttpSession session;
|
||||
|
||||
|
||||
/**
|
||||
* grabs the actual adapter from the session.
|
||||
*/
|
||||
public FluxFacade() {
|
||||
session = ExecutionContext.get().getSession();
|
||||
adapter = (ChibaAdapter) session.getAttribute(ChibaServlet.CHIBA_ADAPTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* executes a trigger
|
||||
*
|
||||
* @param id the id of the trigger to execute
|
||||
* @return the list of events that may result through this action
|
||||
* @throws FluxException
|
||||
*/
|
||||
public Element fireAction(String id) throws FluxException {
|
||||
LOGGER.debug("fireAction " + id);
|
||||
ChibaEvent chibaActivateEvent = new DefaultChibaEventImpl();
|
||||
chibaActivateEvent.initEvent(FLUX_ACTIVATE_EVENT, id, null);
|
||||
return dispatch(chibaActivateEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the value of a control in the processor.
|
||||
*
|
||||
* @param id the id of the control in the host document
|
||||
* @param value the new value
|
||||
* @return the list of events that may result through this action
|
||||
* @throws FluxException
|
||||
*/
|
||||
public Element setXFormsValue(String id, String value) throws FluxException {
|
||||
LOGGER.debug("setXFormsValue(" + id + ", " + value + ")");
|
||||
ChibaEvent event = new DefaultChibaEventImpl();
|
||||
event.initEvent("SETVALUE", id, value);
|
||||
return dispatch(event);
|
||||
}
|
||||
|
||||
public Element setRepeatIndex(String id, String position) throws FluxException {
|
||||
LOGGER.debug("setRepeatPosition(" + id + ", " + position + ")");
|
||||
ChibaEvent event = new DefaultChibaEventImpl();
|
||||
event.initEvent("SETINDEX", id, position);
|
||||
return dispatch(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetches the progress of a running upload.
|
||||
*
|
||||
* @param id id of the upload control in use
|
||||
* @param filename filename for uploaded data
|
||||
* @return a array containing two elements for evaluation in browser. First
|
||||
* param is the upload control id and second will be the current
|
||||
* progress of the upload.
|
||||
*/
|
||||
public Element fetchProgress(String id, String filename) {
|
||||
String progress = "0";
|
||||
|
||||
if (session.getAttribute(filename) != null) {
|
||||
progress = ((Integer) session.getAttribute(filename)).toString();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Percent completed: " + progress);
|
||||
}
|
||||
}
|
||||
|
||||
EventLog eventLog = (EventLog) adapter.getContextParam("EVENT-LOG");
|
||||
if (eventLog == null) {
|
||||
eventLog = new EventLog();
|
||||
}
|
||||
Element eventlogElement = eventLog.getLog();
|
||||
eventLog.flush();
|
||||
|
||||
Element progressEvent = eventLog.add("upload-progress-event", id, "upload");
|
||||
eventLog.addProperty(progressEvent, "progress", progress);
|
||||
return eventlogElement;
|
||||
}
|
||||
|
||||
private Element dispatch(ChibaEvent event) throws FluxException {
|
||||
LOGGER.debug("dispatching " + event);
|
||||
if (adapter != null) {
|
||||
try {
|
||||
adapter.dispatch(event);
|
||||
}
|
||||
catch (XFormsException e) {
|
||||
throw new FluxException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//session expired or cookie got lost
|
||||
throw new FluxException("Session expired. Please start again.");
|
||||
}
|
||||
EventLog eventLog = (EventLog) adapter.getContextParam("EVENT-LOG");
|
||||
Element eventlogElement = eventLog.getLog();
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
try
|
||||
{
|
||||
DOMUtil.prettyPrintDOM(eventlogElement, System.out);
|
||||
}
|
||||
catch (TransformerException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return eventlogElement;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return "FluxFacade using " + adapter.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// end of class
|
@@ -225,26 +225,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
public static final String SUBMIT_METHOD_URLENCODED_POST =
|
||||
"urlencoded-post";
|
||||
|
||||
/**
|
||||
* possible instance modes
|
||||
*/
|
||||
public static final int INSTANCE_MODE_NONE = 0;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
public static final int INSTANCE_MODE_INCLUDED = 1;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
public static final int INSTANCE_MODE_HREF = 2;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
protected Source _instanceSource;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
@@ -255,11 +235,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
*/
|
||||
protected String _action;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
protected String _instanceHref;
|
||||
|
||||
/**
|
||||
* Properties choosed by the user
|
||||
*/
|
||||
@@ -285,11 +260,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
*/
|
||||
protected WrapperElementsBuilder _wrapper = new XHTMLWrapperElementsBuilder();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
protected int _instanceMode = 0;
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*/
|
||||
@@ -318,62 +288,9 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
// can be used as a substituted type using xsi:type
|
||||
// In order for it to be compatible, it cannot be abstract, and
|
||||
// it must be derived by extension.
|
||||
// The ArrayList does not contain its own type + has the other types only once
|
||||
//
|
||||
// The ArrayList does not contain its own type + has the other types only once
|
||||
private final TreeMap typeTree = new TreeMap();
|
||||
|
||||
/**
|
||||
* Creates a new instance of AbstractSchemaFormBuilder
|
||||
*/
|
||||
public AbstractSchemaFormBuilder(String rootTagName) {
|
||||
this._rootTagName = rootTagName;
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setValidating(false);
|
||||
documentBuilder = factory.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AbstractSchemaFormBuilder object.
|
||||
*
|
||||
* @param rootTagName __UNDOCUMENTED__
|
||||
* @param instanceSource __UNDOCUMENTED__
|
||||
* @param action __UNDOCUMENTED__
|
||||
* @param submitMethod __UNDOCUMENTED__
|
||||
* @param wrapper __UNDOCUMENTED__
|
||||
* @param stylesheet __UNDOCUMENTED__
|
||||
*/
|
||||
public AbstractSchemaFormBuilder(String rootTagName,
|
||||
Source instanceSource,
|
||||
String action,
|
||||
String submitMethod,
|
||||
WrapperElementsBuilder wrapper,
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
this(rootTagName);
|
||||
this._instanceSource = instanceSource;
|
||||
|
||||
if (instanceSource != null)
|
||||
this._instanceMode = AbstractSchemaFormBuilder.INSTANCE_MODE_INCLUDED;
|
||||
|
||||
this._action = action;
|
||||
this._stylesheet = stylesheet;
|
||||
this._base = base;
|
||||
this._useSchemaTypes = userSchemaTypes;
|
||||
|
||||
//control if it is one of the SUBMIT_METHOD attributes?
|
||||
this._submitMethod = submitMethod;
|
||||
this._wrapper = wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AbstractSchemaFormBuilder object.
|
||||
*
|
||||
@@ -392,12 +309,20 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
this(rootTagName);
|
||||
this._rootTagName = rootTagName;
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setValidating(false);
|
||||
documentBuilder = factory.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
|
||||
reset();
|
||||
this._instanceDocument = instanceDocument;
|
||||
|
||||
if (instanceDocument != null)
|
||||
this._instanceMode = AbstractSchemaFormBuilder.INSTANCE_MODE_INCLUDED;
|
||||
|
||||
this._action = action;
|
||||
this._stylesheet = stylesheet;
|
||||
this._base = base;
|
||||
@@ -408,41 +333,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
this._wrapper = wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AbstractSchemaFormBuilder object.
|
||||
*
|
||||
* @param rootTagName __UNDOCUMENTED__
|
||||
* @param instanceHref __UNDOCUMENTED__
|
||||
* @param action __UNDOCUMENTED__
|
||||
* @param submitMethod __UNDOCUMENTED__
|
||||
* @param wrapper __UNDOCUMENTED__
|
||||
* @param stylesheet __UNDOCUMENTED__
|
||||
*/
|
||||
public AbstractSchemaFormBuilder(String rootTagName,
|
||||
String instanceHref,
|
||||
String action,
|
||||
String submitMethod,
|
||||
WrapperElementsBuilder wrapper,
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
this(rootTagName);
|
||||
this._instanceHref = instanceHref;
|
||||
|
||||
if ((instanceHref != null) && !"".equals(instanceHref))
|
||||
this._instanceMode = AbstractSchemaFormBuilder.INSTANCE_MODE_HREF;
|
||||
|
||||
this._action = action;
|
||||
this._stylesheet = stylesheet;
|
||||
this._base = base;
|
||||
this._useSchemaTypes = userSchemaTypes;
|
||||
|
||||
//control if it is one of the SUBMIT_METHOD attributes?
|
||||
this._submitMethod = submitMethod;
|
||||
this._wrapper = wrapper;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
@@ -452,33 +342,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
return _action;
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public String getInstanceHref() {
|
||||
return _instanceHref;
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public int getInstanceMode() {
|
||||
return _instanceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public Source getInstanceSource() {
|
||||
return _instanceSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
@@ -589,18 +452,19 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
* @return __UNDOCUMENTED__
|
||||
* @throws FormBuilderException __UNDOCUMENTED__
|
||||
*/
|
||||
public Document buildForm(String inputFile) throws FormBuilderException {
|
||||
public Document buildForm(String inputFile)
|
||||
throws FormBuilderException {
|
||||
try {
|
||||
this.loadSchema(new File(inputFile).toURI().toString());
|
||||
buildTypeTree(schema);
|
||||
this.buildTypeTree(schema);
|
||||
|
||||
//refCounter = 0;
|
||||
counter = new HashMap();
|
||||
|
||||
Document xForm =
|
||||
createFormTemplate(_rootTagName,
|
||||
_rootTagName + " Form",
|
||||
getProperty(CSS_STYLE_PROP, DEFAULT_CSS_STYLE_PROP));
|
||||
Document xForm = createFormTemplate(_rootTagName,
|
||||
_rootTagName + " Form",
|
||||
getProperty(CSS_STYLE_PROP,
|
||||
DEFAULT_CSS_STYLE_PROP));
|
||||
|
||||
//this.buildInheritenceTree(schema);
|
||||
Element envelopeElement = xForm.getDocumentElement();
|
||||
@@ -682,83 +546,31 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
this.setXFormsId(instanceElement);
|
||||
|
||||
Element rootElement;
|
||||
|
||||
if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_NONE)
|
||||
if (_instanceDocument != null)
|
||||
{
|
||||
rootElement = (Element) instanceElement.appendChild(xForm.createElementNS(targetNamespace, getElementName(rootElementDecl, xForm)));
|
||||
|
||||
String prefix = xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1);
|
||||
rootElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:" + prefix, XMLSCHEMA_INSTANCE_NAMESPACE_URI);
|
||||
|
||||
}
|
||||
else if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_INCLUDED)
|
||||
{
|
||||
//get the instance element
|
||||
boolean ok = true;
|
||||
try
|
||||
{
|
||||
if (_instanceDocument == null)
|
||||
{
|
||||
DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance();
|
||||
docFact.setNamespaceAware(true);
|
||||
docFact.setValidating(false);
|
||||
DocumentBuilder parser = docFact.newDocumentBuilder();
|
||||
_instanceDocument = parser.parse(new InputSource(_instanceSource.getSystemId()));
|
||||
}
|
||||
//possibility abandonned for the moment:
|
||||
//modify the instance to add the correct "xsi:type" attributes wherever needed
|
||||
//Document instanceDoc=this.setXMLSchemaAndPSVILoad(inputURI, _instanceSource, targetNamespace);
|
||||
|
||||
if (_instanceDocument == null)
|
||||
{
|
||||
LOGGER.debug("instanceDocument is null");
|
||||
ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Element instanceInOtherDoc = _instanceDocument.getDocumentElement();
|
||||
if (!instanceInOtherDoc.getNodeName().equals(_rootTagName))
|
||||
throw new IllegalArgumentException("instance document root tag name invalid. " +
|
||||
"expected " + _rootTagName +
|
||||
", got " + instanceInOtherDoc.getNodeName());
|
||||
else
|
||||
{
|
||||
LOGGER.debug("importing rootElement from other document");
|
||||
rootElement = (Element)xForm.importNode(instanceInOtherDoc, true);
|
||||
instanceElement.appendChild(rootElement);
|
||||
|
||||
//add XMLSchema instance NS
|
||||
String prefix = xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1);
|
||||
if (!rootElement.hasAttributeNS(XMLNS_NAMESPACE_URI, prefix))
|
||||
rootElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:" + prefix, XMLSCHEMA_INSTANCE_NAMESPACE_URI);
|
||||
|
||||
//possibility abandonned for the moment:
|
||||
//modify the instance to add the correct "xsi:type" attributes wherever needed
|
||||
//this.addXSITypeAttributes(rootElement);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
//if there is an exception we put the empty root element
|
||||
ok = false;
|
||||
}
|
||||
|
||||
//if there was a problem
|
||||
if (!ok)
|
||||
{
|
||||
LOGGER.debug("using empty root for " + _rootTagName);
|
||||
rootElement = (Element)
|
||||
instanceElement.appendChild(xForm.createElement(_rootTagName));
|
||||
}
|
||||
}
|
||||
else if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_HREF)
|
||||
//add the xlink:href attribute
|
||||
{
|
||||
instanceElement.setAttributeNS(SchemaFormBuilder.XLINK_NS,
|
||||
this.getXLinkNSPrefix() + "href",
|
||||
_instanceHref);
|
||||
}
|
||||
Element instanceDocumentElement = _instanceDocument.getDocumentElement();
|
||||
if (!instanceDocumentElement.getNodeName().equals(_rootTagName))
|
||||
throw new IllegalArgumentException("instance document root tag name invalid. " +
|
||||
"expected " + _rootTagName +
|
||||
", got " + instanceDocumentElement.getNodeName());
|
||||
LOGGER.debug("importing rootElement from other document");
|
||||
rootElement = (Element)xForm.importNode(instanceDocumentElement, true);
|
||||
instanceElement.appendChild(rootElement);
|
||||
|
||||
//add XMLSchema instance NS
|
||||
String prefix = xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1);
|
||||
if (!rootElement.hasAttributeNS(XMLNS_NAMESPACE_URI, prefix))
|
||||
rootElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:" + prefix, XMLSCHEMA_INSTANCE_NAMESPACE_URI);
|
||||
|
||||
//possibility abandonned for the moment:
|
||||
//modify the instance to add the correct "xsi:type" attributes wherever needed
|
||||
//this.addXSITypeAttributes(rootElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootElement = (Element)
|
||||
instanceElement.appendChild(xForm.createElement(_rootTagName));
|
||||
}
|
||||
|
||||
Element formContentWrapper =
|
||||
_wrapper.createGroupContentWrapper(formSection);
|
||||
@@ -2518,12 +2330,12 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
|
||||
// add xforms:repeat section if this element re-occurs
|
||||
//
|
||||
if (maxOccurs != 1) {
|
||||
|
||||
if (maxOccurs != 1)
|
||||
{
|
||||
if (LOGGER.isDebugEnabled())
|
||||
LOGGER.debug("DEBUG: AddRepeatIfNecessary for multiple element for type "
|
||||
+ controlType.getName()
|
||||
+ ", maxOccurs=" + maxOccurs);
|
||||
+ controlType.getName()
|
||||
+ ", maxOccurs=" + maxOccurs);
|
||||
|
||||
//repeatSection = (Element) formSection.appendChild(xForm.createElementNS(XFORMS_NS,getXFormsNSPrefix() + "repeat"));
|
||||
repeatSection = xForm.createElementNS(XFORMS_NS,
|
||||
@@ -2535,24 +2347,23 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
Element bind = DOMUtil.getLastChildElement(modelSection);
|
||||
String bindId = null;
|
||||
|
||||
if ((bind != null)
|
||||
&& (bind.getLocalName() != null)
|
||||
&& bind.getLocalName().equals("bind")) {
|
||||
if (bind != null &&
|
||||
bind.getLocalName() != null &&
|
||||
"bind".equals(bind.getLocalName())) {
|
||||
bindId = bind.getAttributeNS(SchemaFormBuilder.XFORMS_NS, "id");
|
||||
} else {
|
||||
LOGGER.warn("addRepeatIfNecessary: bind not found: "
|
||||
+ bind
|
||||
+ " (model selection name="
|
||||
+ modelSection.getNodeName()
|
||||
+ ")");
|
||||
+ bind
|
||||
+ " (model selection name="
|
||||
+ modelSection.getNodeName()
|
||||
+ ")");
|
||||
|
||||
//if no bind is found -> modelSection is already a bind, get its parent last child
|
||||
bind =
|
||||
DOMUtil.getLastChildElement(modelSection.getParentNode());
|
||||
bind = DOMUtil.getLastChildElement(modelSection.getParentNode());
|
||||
|
||||
if ((bind != null) &&
|
||||
(bind.getLocalName() != null) &&
|
||||
bind.getLocalName().equals("bind")) {
|
||||
if (bind != null &&
|
||||
bind.getLocalName() != null &&
|
||||
"bind".equals(bind.getLocalName())) {
|
||||
bindId = bind.getAttributeNS(SchemaFormBuilder.XFORMS_NS, "id");
|
||||
} else {
|
||||
LOGGER.warn("addRepeatIfNecessary: bind really not found");
|
||||
@@ -3164,47 +2975,36 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
private Document createFormTemplate(String formId,
|
||||
String formName,
|
||||
String stylesheet)
|
||||
throws ParserConfigurationException {
|
||||
throws ParserConfigurationException {
|
||||
Document xForm = documentBuilder.newDocument();
|
||||
|
||||
Element envelopeElement = _wrapper.createEnvelope(xForm);
|
||||
|
||||
// set required namespace attributes
|
||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||
"xmlns:"
|
||||
+ getChibaNSPrefix().substring(0,
|
||||
getChibaNSPrefix().length() - 1),
|
||||
CHIBA_NS);
|
||||
"xmlns:" + getChibaNSPrefix().substring(0, getChibaNSPrefix().length() - 1),
|
||||
CHIBA_NS);
|
||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||
"xmlns:"
|
||||
+ getXFormsNSPrefix().substring(0,
|
||||
getXFormsNSPrefix().length() - 1),
|
||||
XFORMS_NS);
|
||||
"xmlns:" + getXFormsNSPrefix().substring(0, getXFormsNSPrefix().length() - 1),
|
||||
XFORMS_NS);
|
||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||
"xmlns:"
|
||||
+ getXLinkNSPrefix().substring(0,
|
||||
getXLinkNSPrefix().length() - 1),
|
||||
XLINK_NS);
|
||||
//XMLEvent
|
||||
"xmlns:" + getXLinkNSPrefix().substring(0, getXLinkNSPrefix().length() - 1),
|
||||
XLINK_NS);
|
||||
//XMLEvent
|
||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||
"xmlns:" +
|
||||
xmleventsNSPrefix.substring(0, xmleventsNSPrefix.length() - 1),
|
||||
XMLEVENTS_NS);
|
||||
//XML Schema Instance
|
||||
"xmlns:" + xmleventsNSPrefix.substring(0, xmleventsNSPrefix.length() - 1),
|
||||
XMLEVENTS_NS);
|
||||
//XML Schema Instance
|
||||
envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI,
|
||||
"xmlns:" +
|
||||
xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1),
|
||||
XMLSCHEMA_INSTANCE_NAMESPACE_URI);
|
||||
//base
|
||||
if (_base != null && !_base.equals("")) {
|
||||
envelopeElement.setAttributeNS(XML_NAMESPACE_URI,
|
||||
"xml:base",
|
||||
_base);
|
||||
}
|
||||
"xmlns:" + xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1),
|
||||
XMLSCHEMA_INSTANCE_NAMESPACE_URI);
|
||||
//base
|
||||
if (_base != null && _base.length() != 0)
|
||||
envelopeElement.setAttributeNS(XML_NAMESPACE_URI, "xml:base", _base);
|
||||
|
||||
//model element
|
||||
Element modelElement =
|
||||
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "model");
|
||||
Element modelElement = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "model");
|
||||
this.setXFormsId(modelElement);
|
||||
Element modelWrapper = _wrapper.createModelWrapper(modelElement);
|
||||
envelopeElement.appendChild(modelWrapper);
|
||||
|
@@ -42,42 +42,8 @@ import java.util.Vector;
|
||||
* @version $Id: BaseSchemaFormBuilder.java,v 1.19 2005/03/29 14:24:34 unl Exp $
|
||||
*/
|
||||
public class BaseSchemaFormBuilder
|
||||
extends AbstractSchemaFormBuilder
|
||||
implements SchemaFormBuilder {
|
||||
/**
|
||||
* Creates a new instance of BaseSchemaForBuilder
|
||||
*/
|
||||
public BaseSchemaFormBuilder(String rootTagName) {
|
||||
super(rootTagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BaseSchemaFormBuilder object.
|
||||
*
|
||||
* @param rootTagName __UNDOCUMENTED__
|
||||
* @param instanceSource __UNDOCUMENTED__
|
||||
* @param action __UNDOCUMENTED__
|
||||
* @param submitMethod __UNDOCUMENTED__
|
||||
* @param wrapper __UNDOCUMENTED__
|
||||
* @param stylesheet __UNDOCUMENTED__
|
||||
*/
|
||||
public BaseSchemaFormBuilder(String rootTagName,
|
||||
Source instanceSource,
|
||||
String action,
|
||||
String submitMethod,
|
||||
WrapperElementsBuilder wrapper,
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
super(rootTagName,
|
||||
instanceSource,
|
||||
action,
|
||||
submitMethod,
|
||||
wrapper,
|
||||
stylesheet,
|
||||
base,
|
||||
userSchemaTypes);
|
||||
}
|
||||
extends AbstractSchemaFormBuilder
|
||||
implements SchemaFormBuilder {
|
||||
|
||||
/**
|
||||
* Creates a new BaseSchemaFormBuilder object.
|
||||
@@ -107,34 +73,6 @@ public class BaseSchemaFormBuilder
|
||||
userSchemaTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BaseSchemaFormBuilder object.
|
||||
*
|
||||
* @param rootTagName __UNDOCUMENTED__
|
||||
* @param instanceHref __UNDOCUMENTED__
|
||||
* @param action __UNDOCUMENTED__
|
||||
* @param submitMethod __UNDOCUMENTED__
|
||||
* @param wrapper __UNDOCUMENTED__
|
||||
* @param stylesheet __UNDOCUMENTED__
|
||||
*/
|
||||
public BaseSchemaFormBuilder(String rootTagName,
|
||||
String instanceHref,
|
||||
String action,
|
||||
String submitMethod,
|
||||
WrapperElementsBuilder wrapper,
|
||||
String stylesheet,
|
||||
String base,
|
||||
boolean userSchemaTypes) {
|
||||
super(rootTagName,
|
||||
instanceHref,
|
||||
action,
|
||||
submitMethod,
|
||||
wrapper,
|
||||
stylesheet,
|
||||
base,
|
||||
userSchemaTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
@@ -212,15 +150,15 @@ public class BaseSchemaFormBuilder
|
||||
public Element createControlForAnyType(Document xForm,
|
||||
String caption,
|
||||
XSTypeDefinition controlType) {
|
||||
Element control =
|
||||
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "textarea");
|
||||
Element control = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "textarea");
|
||||
this.setXFormsId(control);
|
||||
control.setAttributeNS(CHIBA_NS, getChibaNSPrefix() + "height", "3");
|
||||
|
||||
//label
|
||||
Element captionElement =
|
||||
(Element) control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
Element captionElement = (Element)
|
||||
control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
this.setXFormsId(captionElement);
|
||||
captionElement.appendChild(xForm.createTextNode(caption));
|
||||
|
||||
@@ -323,96 +261,87 @@ public class BaseSchemaFormBuilder
|
||||
//
|
||||
StringList enumFacets = controlType.getLexicalEnumeration();
|
||||
int nbFacets = enumFacets.getLength();
|
||||
if (nbFacets > 0) {
|
||||
Vector enumValues = new Vector();
|
||||
if (nbFacets <= 0)
|
||||
return null;
|
||||
Vector enumValues = new Vector();
|
||||
|
||||
Element control =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "select1");
|
||||
this.setXFormsId(control);
|
||||
Element control = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "select1");
|
||||
this.setXFormsId(control);
|
||||
|
||||
//label
|
||||
Element captionElement1 =
|
||||
(Element) control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
this.setXFormsId(captionElement1);
|
||||
captionElement1.appendChild(xForm.createTextNode(caption));
|
||||
//label
|
||||
Element captionElement1 = (Element)
|
||||
control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
this.setXFormsId(captionElement1);
|
||||
captionElement1.appendChild(xForm.createTextNode(caption));
|
||||
|
||||
Element choices =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "choices");
|
||||
this.setXFormsId(choices);
|
||||
Element choices = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "choices");
|
||||
this.setXFormsId(choices);
|
||||
|
||||
for (int i = 0; i < nbFacets; i++) {
|
||||
String facet = enumFacets.item(i);
|
||||
enumValues.add(facet);
|
||||
}
|
||||
|
||||
if (nbFacets
|
||||
< Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTONE_UI_CONTROL_SHORT_PROP));
|
||||
} else {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTONE_UI_CONTROL_LONG_PROP));
|
||||
|
||||
// add the "Please select..." instruction item for the combobox
|
||||
// and set the isValid attribute on the bind element to check for the "Please select..."
|
||||
// item to indicate that is not a valid value
|
||||
//
|
||||
{
|
||||
String pleaseSelect = "[Select1 " + caption + "]";
|
||||
Element item =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "item");
|
||||
this.setXFormsId(item);
|
||||
choices.appendChild(item);
|
||||
|
||||
Element captionElement =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label");
|
||||
this.setXFormsId(captionElement);
|
||||
item.appendChild(captionElement);
|
||||
captionElement.appendChild(xForm.createTextNode(pleaseSelect));
|
||||
|
||||
Element value =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "value");
|
||||
this.setXFormsId(value);
|
||||
item.appendChild(value);
|
||||
value.appendChild(xForm.createTextNode(pleaseSelect));
|
||||
|
||||
// not(purchaseOrder/state = '[Choose State]')
|
||||
//String isValidExpr = "not(" + bindElement.getAttributeNS(XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')";
|
||||
// ->no, not(. = '[Choose State]')
|
||||
String isValidExpr = "not( . = '" + pleaseSelect + "')";
|
||||
|
||||
//check if there was a constraint
|
||||
String constraint =
|
||||
bindElement.getAttributeNS(XFORMS_NS, "constraint");
|
||||
|
||||
if ((constraint != null) && !constraint.equals("")) {
|
||||
constraint = constraint + " and " + isValidExpr;
|
||||
} else {
|
||||
constraint = isValidExpr;
|
||||
}
|
||||
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "constraint",
|
||||
constraint);
|
||||
}
|
||||
}
|
||||
|
||||
control.appendChild(choices);
|
||||
|
||||
addChoicesForSelectControl(xForm, choices, enumValues);
|
||||
|
||||
return control;
|
||||
} else {
|
||||
return null;
|
||||
for (int i = 0; i < nbFacets; i++) {
|
||||
String facet = enumFacets.item(i);
|
||||
enumValues.add(facet);
|
||||
}
|
||||
|
||||
if (nbFacets < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTONE_UI_CONTROL_SHORT_PROP));
|
||||
} else {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTONE_UI_CONTROL_LONG_PROP));
|
||||
|
||||
// add the "Please select..." instruction item for the combobox
|
||||
// and set the isValid attribute on the bind element to check for the "Please select..."
|
||||
// item to indicate that is not a valid value
|
||||
//
|
||||
{
|
||||
String pleaseSelect = "[Select1 " + caption + "]";
|
||||
Element item = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "item");
|
||||
this.setXFormsId(item);
|
||||
choices.appendChild(item);
|
||||
|
||||
Element captionElement =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label");
|
||||
this.setXFormsId(captionElement);
|
||||
item.appendChild(captionElement);
|
||||
captionElement.appendChild(xForm.createTextNode(pleaseSelect));
|
||||
|
||||
Element value =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "value");
|
||||
this.setXFormsId(value);
|
||||
item.appendChild(value);
|
||||
value.appendChild(xForm.createTextNode(pleaseSelect));
|
||||
|
||||
// not(purchaseOrder/state = '[Choose State]')
|
||||
//String isValidExpr = "not(" + bindElement.getAttributeNS(XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')";
|
||||
// ->no, not(. = '[Choose State]')
|
||||
String isValidExpr = "not( . = '" + pleaseSelect + "')";
|
||||
|
||||
//check if there was a constraint
|
||||
String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint");
|
||||
|
||||
constraint = ((constraint != null && constraint.length() != 0)
|
||||
? constraint + " and " + isValidExpr
|
||||
: isValidExpr);
|
||||
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "constraint",
|
||||
constraint);
|
||||
}
|
||||
}
|
||||
|
||||
control.appendChild(choices);
|
||||
|
||||
addChoicesForSelectControl(xForm, choices, enumValues);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,54 +361,50 @@ public class BaseSchemaFormBuilder
|
||||
|
||||
StringList enumFacets = controlType.getLexicalEnumeration();
|
||||
int nbFacets = enumFacets.getLength();
|
||||
if (nbFacets > 0) {
|
||||
Element control =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "select");
|
||||
this.setXFormsId(control);
|
||||
if (nbFacets <= 0)
|
||||
return null;
|
||||
Element control = xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "select");
|
||||
this.setXFormsId(control);
|
||||
|
||||
//label
|
||||
Element captionElement =
|
||||
(Element) control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
this.setXFormsId(captionElement);
|
||||
captionElement.appendChild(xForm.createTextNode(caption));
|
||||
//label
|
||||
Element captionElement = (Element)
|
||||
control.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "label"));
|
||||
this.setXFormsId(captionElement);
|
||||
captionElement.appendChild(xForm.createTextNode(caption));
|
||||
|
||||
Vector enumValues = new Vector();
|
||||
for (int i = 0; i < nbFacets; i++) {
|
||||
String facet = enumFacets.item(i);
|
||||
enumValues.add(facet);
|
||||
}
|
||||
|
||||
// TODO: Figure out an intelligent or user determined way to decide between
|
||||
// selectUI style (listbox, menu, combobox, radio) (radio and listbox best apply)
|
||||
// Possibly look for special appInfo section in the schema and if not present default to checkBox...
|
||||
//
|
||||
// For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control
|
||||
//
|
||||
if (enumValues.size()
|
||||
< Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP))) {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP));
|
||||
} else {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTMANY_UI_CONTROL_LONG_PROP));
|
||||
}
|
||||
|
||||
Element choices =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "choices");
|
||||
this.setXFormsId(choices);
|
||||
control.appendChild(choices);
|
||||
|
||||
addChoicesForSelectControl(xForm, choices, enumValues);
|
||||
|
||||
return control;
|
||||
} else {
|
||||
return null;
|
||||
Vector enumValues = new Vector();
|
||||
for (int i = 0; i < nbFacets; i++) {
|
||||
enumValues.add(enumFacets.item(i));
|
||||
}
|
||||
|
||||
// TODO: Figure out an intelligent or user determined way to decide between
|
||||
// selectUI style (listbox, menu, combobox, radio) (radio and listbox best apply)
|
||||
// Possibly look for special appInfo section in the schema and if not present default to checkBox...
|
||||
//
|
||||
// For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control
|
||||
//
|
||||
if (enumValues.size()
|
||||
< Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP))) {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP));
|
||||
} else {
|
||||
control.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "appearance",
|
||||
getProperty(SELECTMANY_UI_CONTROL_LONG_PROP));
|
||||
}
|
||||
|
||||
Element choices =
|
||||
xForm.createElementNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "choices");
|
||||
this.setXFormsId(choices);
|
||||
control.appendChild(choices);
|
||||
|
||||
addChoicesForSelectControl(xForm, choices, enumValues);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,24 +485,19 @@ public class BaseSchemaFormBuilder
|
||||
//
|
||||
// type.getName() may be 'null' for anonymous types, so compare against
|
||||
// static string (see bug #1172541 on sf.net)
|
||||
if (!("anyType").equals(controlType.getName())) {
|
||||
if (!"anyType".equals(controlType.getName())) {
|
||||
Element enveloppe = bindElement.getOwnerDocument().getDocumentElement();
|
||||
String typeName = this.getXFormsTypeName(enveloppe, controlType);
|
||||
if (typeName != null && !typeName.equals(""))
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "type",
|
||||
typeName);
|
||||
getXFormsNSPrefix() + "type",
|
||||
typeName);
|
||||
}
|
||||
|
||||
if (minOccurs == 0) {
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "required",
|
||||
"false()");
|
||||
} else {
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "required",
|
||||
"true()");
|
||||
}
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "required",
|
||||
minOccurs == 0 ? "false()" : "true()");
|
||||
|
||||
|
||||
//no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1:
|
||||
//count(.) <= maxOccurs && count(.) >= minOccurs
|
||||
@@ -604,18 +524,17 @@ public class BaseSchemaFormBuilder
|
||||
constraint = maxConstraint;
|
||||
}
|
||||
|
||||
if ((constraint != null) && !constraint.equals("")) {
|
||||
if (constraint != null && constraint.length() != 0)
|
||||
bindElement.setAttributeNS(XFORMS_NS,
|
||||
getXFormsNSPrefix() + "constraint",
|
||||
constraint);
|
||||
}
|
||||
getXFormsNSPrefix() + "constraint",
|
||||
constraint);
|
||||
|
||||
/*if (minOccurs != 1) {
|
||||
bindElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "minOccurs",String.valueOf(minOccurs));
|
||||
}
|
||||
if (maxOccurs != 1) {
|
||||
bindElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "maxOccurs",maxOccurs == -1 ? "unbounded" : String.valueOf((maxOccurs)));
|
||||
}*/
|
||||
//if (minOccurs != 1) {
|
||||
//bindElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "minOccurs",String.valueOf(minOccurs));
|
||||
//}
|
||||
//if (maxOccurs != 1) {
|
||||
//bindElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "maxOccurs",maxOccurs == -1 ? "unbounded" : String.valueOf((maxOccurs)));
|
||||
//}
|
||||
return bindElement;
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,8 @@ public interface SchemaFormBuilder {
|
||||
/**
|
||||
* XMLSchema Instance Namespace declaration
|
||||
*/
|
||||
public static final String XMLSCHEMA_INSTANCE_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance";
|
||||
public static final String XMLSCHEMA_INSTANCE_NAMESPACE_URI =
|
||||
"http://www.w3.org/2001/XMLSchema-instance";
|
||||
|
||||
/**
|
||||
* XMLNS Namespace declaration.
|
||||
@@ -107,27 +108,6 @@ public interface SchemaFormBuilder {
|
||||
*/
|
||||
public String getAction();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public String getInstanceHref();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public int getInstanceMode();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
* @return __UNDOCUMENTED__
|
||||
*/
|
||||
public Source getInstanceSource();
|
||||
|
||||
/**
|
||||
* __UNDOCUMENTED__
|
||||
*
|
||||
|
@@ -1,489 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.servlet;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.templating.xforms.DojoGenerator;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.httpclient.Cookie;
|
||||
import org.chiba.adapter.ChibaAdapter;
|
||||
import org.alfresco.web.templating.xforms.flux.FluxAdapter;
|
||||
import org.alfresco.web.templating.TemplatingService;
|
||||
import org.chiba.tools.xslt.StylesheetLoader;
|
||||
import org.chiba.tools.xslt.UIGenerator;
|
||||
import org.chiba.tools.xslt.XSLTGenerator;
|
||||
import org.chiba.xml.xforms.config.Config;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.*;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The ChibaServlet handles all interactions between client and
|
||||
* form-processor (ChibaBean) for the whole lifetime of a form-filling session.
|
||||
* <br>
|
||||
* The Processor will be started through a Get-request from the client
|
||||
* pointing to the desired form-container. The Processor instance will
|
||||
* be stored in a Session-object.<br>
|
||||
* <br>
|
||||
* All further interaction will be handled through Post-requests.
|
||||
* Incoming request params will be mapped to data and action-handlers.
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @author Ulrich Nicolas Lissé
|
||||
* @author William Boyd
|
||||
* @version $Id: ChibaServlet.java,v 1.14 2005/12/21 22:59:27 unl Exp $
|
||||
*/
|
||||
public class ChibaServlet extends HttpServlet {
|
||||
//init-params
|
||||
private static Log logger = LogFactory.getLog(ChibaServlet.class);
|
||||
|
||||
private static final String FORM_PARAM_NAME = "form";
|
||||
private static final String XSL_PARAM_NAME = "xslt";
|
||||
private static final String CSS_PARAM_NAME = "css";
|
||||
private static final String ACTIONURL_PARAM_NAME = "action_url";
|
||||
|
||||
public static final String CHIBA_ADAPTER = "chiba.adapter";
|
||||
public static final String CHIBA_UI_GENERATOR = "chiba.ui.generator";
|
||||
public static final String CHIBA_SUBMISSION_RESPONSE = "chiba.submission.response";
|
||||
|
||||
/*
|
||||
* It is not thread safe to modify these variables once the
|
||||
* init(ServletConfig) method has been called
|
||||
*/
|
||||
// the absolute path to the Chiba config-file
|
||||
protected String configPath = null;
|
||||
|
||||
// the rootdir of this app; forms + documents fill be searched under this root
|
||||
protected String contextRoot = null;
|
||||
|
||||
// where uploaded files are stored
|
||||
protected String uploadDir = null;
|
||||
|
||||
protected String stylesPath = null;
|
||||
|
||||
protected String agent;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a short description of the servlet.
|
||||
*
|
||||
* @return - Returns a short description of the servlet.
|
||||
*/
|
||||
public String getServletInfo() {
|
||||
return "Servlet Controller for Chiba XForms Processor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the servlet.
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the servlet.
|
||||
*
|
||||
* @param config - the ServletConfig object
|
||||
* @throws javax.servlet.ServletException
|
||||
*/
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
|
||||
logger.info("--------------- initing ChibaServlet... ---------------");
|
||||
//read some params from web-inf
|
||||
contextRoot = getServletConfig().getServletContext().getRealPath("");
|
||||
if (contextRoot == null)
|
||||
contextRoot = getServletConfig().getServletContext().getRealPath(".");
|
||||
|
||||
//get the relative path to the chiba config-file
|
||||
String path = getServletConfig().getInitParameter("chiba.config");
|
||||
|
||||
//get the real path for the config-file
|
||||
if (path != null) {
|
||||
configPath = getServletConfig().getServletContext().getRealPath(path);
|
||||
}
|
||||
|
||||
//get the path for the stylesheets
|
||||
path = getServletConfig().getServletContext().getInitParameter("chiba.xforms.stylesPath");
|
||||
|
||||
//get the real path for the stylesheets and configure a new StylesheetLoader with it
|
||||
if (path != null) {
|
||||
stylesPath = getServletConfig().getServletContext().getRealPath(path);
|
||||
logger.info("stylesPath: " + stylesPath);
|
||||
}
|
||||
|
||||
//uploadDir = contextRoot + "/" + getServletConfig().getServletContext().getInitParameter("chiba.upload");
|
||||
uploadDir = getServletConfig().getServletContext().getInitParameter("chiba.upload");
|
||||
|
||||
//Security constraint
|
||||
if (uploadDir != null) {
|
||||
if (uploadDir.toUpperCase().indexOf("WEB-INF") >= 0) {
|
||||
throw new ServletException("Chiba security constraint: uploadDir '" + uploadDir + "' not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
//user-agent mappings
|
||||
agent = getServletConfig().getServletContext().getInitParameter("chiba.useragent.ajax.path");
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new form-editing session.<br>
|
||||
* <p/>
|
||||
* The default value of a number of settings can be overridden as follows:
|
||||
* <p/>
|
||||
* 1. The uru of the xform to be displayed can be specified by using a param name of 'form' and a param value
|
||||
* of the location of the xform file as follows, which will attempt to load the current xforms file.
|
||||
* <p/>
|
||||
* http://localhost:8080/chiba-0.9.3/XFormsServlet?form=/forms/hello.xhtml
|
||||
* <p/>
|
||||
* 2. The uru of the CSS file used to style the form can be specified using a param name of 'css' as follows:
|
||||
* <p/>
|
||||
* http://localhost:8080/chiba-0.9.3/XFormsServlet?form=/forms/hello.xhtml&css=/chiba/my.css
|
||||
* <p/>
|
||||
* 3. The uri of the XSLT file used to generate the form can be specified using a param name of 'xslt' as follows:
|
||||
* <p/>
|
||||
* http://localhost:8080/chiba-0.9.3/XFormsServlet?form=/forms/hello.xhtml&xslt=/chiba/my.xslt
|
||||
* <p/>
|
||||
* 4. Besides these special params arbitrary other params can be passed via the GET-string and will be available
|
||||
* in the context map of ChibaBean. This means they can be used as instance data (with the help of ContextResolver)
|
||||
* or to set params for URI resolution.
|
||||
*
|
||||
* @param request servlet request
|
||||
* @param response servlet response
|
||||
* @throws javax.servlet.ServletException
|
||||
* @throws java.io.IOException
|
||||
* @see org.chiba.xml.xforms.connector.context.ContextResolver
|
||||
* @see org.chiba.xml.xforms.connector.ConnectorFactory
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
ChibaAdapter adapter = null;
|
||||
HttpSession session = request.getSession(true);
|
||||
try {
|
||||
if (request.getParameter("xxx") != null)
|
||||
{
|
||||
response.setContentType("text/xml");
|
||||
Writer out = response.getWriter();
|
||||
adapter = (ChibaAdapter)session.getAttribute(CHIBA_ADAPTER);
|
||||
TemplatingService.getInstance().writeXML(adapter.getXForms(), out);
|
||||
out.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("--------------- new XForms session ---------------");
|
||||
//kill everything that may have lived before
|
||||
session.removeAttribute(CHIBA_ADAPTER);
|
||||
session.removeAttribute(CHIBA_UI_GENERATOR);
|
||||
|
||||
// determine Form to load
|
||||
String formURI = /*getRequestURI(request) +*/ request.getParameter(FORM_PARAM_NAME);
|
||||
logger.info("formURI: " + formURI);
|
||||
String xslFile = request.getParameter(XSL_PARAM_NAME);
|
||||
String css = request.getParameter(CSS_PARAM_NAME);
|
||||
String actionURL = getActionURL(request, response,true);
|
||||
logger.info("setting up adapeter");
|
||||
|
||||
//setup Adapter
|
||||
adapter = setupAdapter(new FluxAdapter(session), session, formURI);
|
||||
setContextParams(request, adapter);
|
||||
storeCookies(request, adapter);
|
||||
adapter.init();
|
||||
|
||||
if (load(adapter, response)) return;
|
||||
if (replaceAll(adapter, response)) return;
|
||||
|
||||
// response.setContentType("text/html");
|
||||
// PrintWriter out = response.getWriter();
|
||||
|
||||
logger.info("generating ui");
|
||||
|
||||
UIGenerator uiGenerator = createUIGenerator(request,
|
||||
response,
|
||||
actionURL,
|
||||
xslFile,
|
||||
css);
|
||||
uiGenerator.setInputNode(adapter.getXForms());
|
||||
// uiGenerator.setOutput(out);
|
||||
uiGenerator.generate();
|
||||
|
||||
//store adapter in session
|
||||
session.setAttribute(CHIBA_ADAPTER, adapter);
|
||||
session.setAttribute(CHIBA_UI_GENERATOR,uiGenerator);
|
||||
|
||||
// out.close();
|
||||
logger.info("done!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
shutdown(adapter, session, e, response, request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* configures the an Adapter for interacting with the XForms processor (ChibaBean). The Adapter itself
|
||||
* will create the XFormsProcessor (ChibaBean) and configure it for processing.
|
||||
*
|
||||
* If you'd like to use a different source of XForms documents e.g. DOM you should extend this class and
|
||||
* overwrite this method. Please take care to also set the baseURI of the processor to a reasonable value
|
||||
* cause this will be the fundament for all URI resolutions taking place.
|
||||
*
|
||||
* @param adapter the ChibaAdapter implementation to setup
|
||||
* @param session - the Servlet session
|
||||
* @param formPath - the relative location where forms are stored
|
||||
* @return ServletAdapter
|
||||
*/
|
||||
protected ChibaAdapter setupAdapter(ChibaAdapter adapter,
|
||||
HttpSession session,
|
||||
String formPath)
|
||||
throws XFormsException, URISyntaxException {
|
||||
|
||||
adapter.createXFormsProcessor();
|
||||
|
||||
if ((configPath != null) && !(configPath.equals(""))) {
|
||||
adapter.setConfigPath(configPath);
|
||||
}
|
||||
adapter.setXForms(new URI(formPath));
|
||||
adapter.setBaseURI(formPath);
|
||||
adapter.setUploadDestination(uploadDir);
|
||||
|
||||
Map servletMap = new HashMap();
|
||||
servletMap.put(ChibaAdapter.SESSION_ID, session.getId());
|
||||
adapter.setContextParam(ChibaAdapter.SUBMISSION_RESPONSE, servletMap);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* stores cookies that may exist in request and passes them on to processor for usage in
|
||||
* HTTPConnectors. Instance loading and submission then uses these cookies. Important for
|
||||
* applications using auth.
|
||||
*
|
||||
* @param request the servlet request
|
||||
* @param adapter the Chiba adapter instance
|
||||
*/
|
||||
protected void storeCookies(HttpServletRequest request,ChibaAdapter adapter){
|
||||
javax.servlet.http.Cookie[] cookiesIn = request.getCookies();
|
||||
if (cookiesIn != null) {
|
||||
Cookie[] commonsCookies = new org.apache.commons.httpclient.Cookie[cookiesIn.length];
|
||||
for (int i = 0; i < cookiesIn.length; i += 1) {
|
||||
javax.servlet.http.Cookie c = cookiesIn[i];
|
||||
Cookie newCookie = new Cookie(c.getDomain(),
|
||||
c.getName(),
|
||||
c.getValue(),
|
||||
c.getPath(),
|
||||
c.getMaxAge(),
|
||||
c.getSecure());
|
||||
commonsCookies[i] = newCookie;
|
||||
}
|
||||
adapter.setContextParam(AbstractHTTPConnector.REQUEST_COOKIE,commonsCookies);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* creates and configures the UI generating component.
|
||||
* @param request
|
||||
* @param actionURL
|
||||
* @param xslFile
|
||||
* @param css
|
||||
* @return
|
||||
* @throws XFormsException
|
||||
*/
|
||||
protected UIGenerator createUIGenerator(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
String actionURL,
|
||||
String xslFile,
|
||||
String css)
|
||||
throws XFormsException {
|
||||
// StylesheetLoader stylesheetLoader = new StylesheetLoader(stylesPath);
|
||||
// if (xslFile != null){
|
||||
// stylesheetLoader.setStylesheetFile(xslFile);
|
||||
// }
|
||||
UIGenerator uiGenerator = new DojoGenerator(request, response);
|
||||
|
||||
//set parameters
|
||||
uiGenerator.setParameter("contextroot",request.getContextPath());
|
||||
uiGenerator.setParameter("action-url",actionURL);
|
||||
uiGenerator.setParameter("debug-enabled", String.valueOf(logger.isDebugEnabled()));
|
||||
String selectorPrefix =
|
||||
Config.getInstance().getProperty(HttpRequestHandler.SELECTOR_PREFIX_PROPERTY,
|
||||
HttpRequestHandler.SELECTOR_PREFIX_DEFAULT);
|
||||
uiGenerator.setParameter("selector-prefix", selectorPrefix);
|
||||
String removeUploadPrefix =
|
||||
Config.getInstance().getProperty(HttpRequestHandler.REMOVE_UPLOAD_PREFIX_PROPERTY,
|
||||
HttpRequestHandler.REMOVE_UPLOAD_PREFIX_DEFAULT);
|
||||
uiGenerator.setParameter("remove-upload-prefix", removeUploadPrefix);
|
||||
if (css != null)
|
||||
uiGenerator.setParameter("css-file", css);
|
||||
String dataPrefix = Config.getInstance().getProperty("chiba.web.dataPrefix");
|
||||
uiGenerator.setParameter("data-prefix", dataPrefix);
|
||||
|
||||
String triggerPrefix = Config.getInstance().getProperty("chiba.web.triggerPrefix");
|
||||
uiGenerator.setParameter("trigger-prefix", triggerPrefix);
|
||||
|
||||
uiGenerator.setParameter("user-agent", request.getHeader("User-Agent"));
|
||||
|
||||
// uiGenerator.setParameter("scripted","true");
|
||||
|
||||
return uiGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is responsible for passing all context information needed by the Adapter and Processor from
|
||||
* ServletRequest to ChibaContext. Will be called only once when the form-session is inited (GET).
|
||||
*
|
||||
* @param request the ServletRequest
|
||||
* @param chibaAdapter the ChibaAdapter to use
|
||||
*/
|
||||
protected void setContextParams(HttpServletRequest request, ChibaAdapter chibaAdapter) {
|
||||
|
||||
//[1] pass user-agent to Adapter for UI-building
|
||||
chibaAdapter.setContextParam(ServletAdapter.USERAGENT, request.getHeader("User-Agent"));
|
||||
|
||||
//[2] read any request params that are *not* Chiba params and pass them into the context map
|
||||
Enumeration params = request.getParameterNames();
|
||||
while (params.hasMoreElements()) {
|
||||
String s = (String) params.nextElement();
|
||||
//store all request-params we don't use in the context map of ChibaBean
|
||||
if (!(s.equals(FORM_PARAM_NAME) ||
|
||||
s.equals(XSL_PARAM_NAME) ||
|
||||
s.equals(CSS_PARAM_NAME) ||
|
||||
s.equals(ACTIONURL_PARAM_NAME))) {
|
||||
String value = request.getParameter(s);
|
||||
//servletAdapter.setContextProperty(s, value);
|
||||
chibaAdapter.setContextParam(s, value);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("added request param '" + s + "' added to context");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated should be re-implemented using chiba events on adapter
|
||||
*/
|
||||
protected boolean load(ChibaAdapter adapter, HttpServletResponse response) throws XFormsException, IOException {
|
||||
if (adapter.getContextParam(ChibaAdapter.LOAD_URI) != null) {
|
||||
String redirectTo = (String) adapter.removeContextParam(ChibaAdapter.LOAD_URI);
|
||||
adapter.shutdown();
|
||||
response.sendRedirect(response.encodeRedirectURL(redirectTo));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated should be re-implemented using chiba events on adapter
|
||||
*/
|
||||
protected boolean replaceAll(ChibaAdapter chibaAdapter, HttpServletResponse response)
|
||||
throws XFormsException, IOException {
|
||||
if (chibaAdapter.getContextParam(ChibaAdapter.SUBMISSION_RESPONSE) != null) {
|
||||
Map forwardMap = (Map) chibaAdapter.removeContextParam(ChibaAdapter.SUBMISSION_RESPONSE);
|
||||
if (forwardMap.containsKey(ChibaAdapter.SUBMISSION_RESPONSE_STREAM)) {
|
||||
forwardResponse(forwardMap, response);
|
||||
chibaAdapter.shutdown();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getActionURL(HttpServletRequest request, HttpServletResponse response, boolean scripted) {
|
||||
String defaultActionURL = getRequestURI(request) + agent;
|
||||
String encodedDefaultActionURL = response.encodeURL(defaultActionURL);
|
||||
int sessIdx = encodedDefaultActionURL.indexOf(";jsession");
|
||||
String sessionId = null;
|
||||
if (sessIdx > -1) {
|
||||
sessionId = encodedDefaultActionURL.substring(sessIdx);
|
||||
}
|
||||
String actionURL = request.getParameter(ACTIONURL_PARAM_NAME);
|
||||
if (null == actionURL) {
|
||||
actionURL = encodedDefaultActionURL;
|
||||
} else if (null != sessionId) {
|
||||
actionURL += sessionId;
|
||||
}
|
||||
|
||||
logger.info("actionURL: " + actionURL);
|
||||
// encode the URL to allow for session id rewriting
|
||||
return response.encodeURL(actionURL);
|
||||
}
|
||||
|
||||
private String getRequestURI(HttpServletRequest request){
|
||||
StringBuffer buffer = new StringBuffer(request.getScheme());
|
||||
buffer.append("://");
|
||||
buffer.append(request.getServerName());
|
||||
buffer.append(":");
|
||||
buffer.append(request.getServerPort()) ;
|
||||
buffer.append(request.getContextPath());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void forwardResponse(Map forwardMap, HttpServletResponse response) throws IOException {
|
||||
// fetch response stream
|
||||
InputStream responseStream = (InputStream) forwardMap.remove(ChibaAdapter.SUBMISSION_RESPONSE_STREAM);
|
||||
|
||||
// copy header information
|
||||
Iterator iterator = forwardMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
String name = (String) iterator.next();
|
||||
|
||||
if ("Transfer-Encoding".equalsIgnoreCase(name)) {
|
||||
// Some servers (e.g. WebSphere) may set a "Transfer-Encoding"
|
||||
// with the value "chunked". This may confuse the client since
|
||||
// ChibaServlet output is not encoded as "chunked", so this
|
||||
// header is ignored.
|
||||
continue;
|
||||
}
|
||||
String value = (String) forwardMap.get(name);
|
||||
response.setHeader(name, value);
|
||||
}
|
||||
|
||||
// copy stream content
|
||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
for (int b = responseStream.read();
|
||||
b > -1;
|
||||
b = responseStream.read()) {
|
||||
outputStream.write(b);
|
||||
}
|
||||
|
||||
// close streams
|
||||
responseStream.close();
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
protected void shutdown(ChibaAdapter chibaAdapter,
|
||||
HttpSession session,
|
||||
Exception e,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request)
|
||||
throws IOException,
|
||||
ServletException {
|
||||
// attempt to shutdown processor
|
||||
if (chibaAdapter != null) {
|
||||
try {
|
||||
chibaAdapter.shutdown();
|
||||
} catch (XFormsException xfe) {
|
||||
xfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
Application.handleServletError(this.getServletContext(),
|
||||
request,
|
||||
response,
|
||||
e,
|
||||
logger,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
// end of class
|
@@ -1,101 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.servlet;
|
||||
|
||||
import org.apache.commons.fileupload.FileUpload;
|
||||
import org.apache.log4j.Category;
|
||||
import org.chiba.adapter.ChibaAdapter;
|
||||
import org.chiba.adapter.ChibaEvent;
|
||||
import org.chiba.adapter.DefaultChibaEventImpl;
|
||||
import org.chiba.xml.xforms.config.Config;
|
||||
import org.chiba.tools.xslt.UIGenerator;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Provides extra functionality that's not easily handled with AJAX. This helper servlet will only be triggered in
|
||||
* in one of two situations:<br>
|
||||
* 1. an upload<br>
|
||||
* for an file upload to happen the browser has to submit the file as multipart-request. In this case the browser
|
||||
* form must be submitted cause there's no way to get the file content from javascript to send an AJAX request.<br><br>
|
||||
* 2. for a submission replace="all"<br>
|
||||
* This mode requires that the response will be directly streamed back to the client, replacing the existing viewport.
|
||||
* To maintain the correct location of that response in the location bar of the browser there seems no way but to
|
||||
* also let the browser do the request/response handling itself by the use of a normal form submit.
|
||||
*
|
||||
* @author Joern Turner
|
||||
* @version $Version: $
|
||||
*/
|
||||
public class FluxHelperServlet extends ChibaServlet {
|
||||
//init-params
|
||||
private static Category cat = Category.getInstance(FluxHelperServlet.class);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a short description of the servlet.
|
||||
*
|
||||
* @return - Returns a short description of the servlet.
|
||||
*/
|
||||
public String getServletInfo() {
|
||||
return "Ajax Servlet Controller for Chiba XForms Processor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the servlet.
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* handles all interaction with the user during a form-session.
|
||||
*
|
||||
* Note: this method is only triggered if the
|
||||
* browser has javascript turned off.
|
||||
*
|
||||
* @param request servlet request
|
||||
* @param response servlet response
|
||||
* @throws javax.servlet.ServletException
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
protected void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
HttpSession session = request.getSession(true);
|
||||
ChibaAdapter chibaAdapter =null;
|
||||
|
||||
response.setContentType("text/html");
|
||||
|
||||
try {
|
||||
chibaAdapter = (ChibaAdapter) session.getAttribute(CHIBA_ADAPTER);
|
||||
if (chibaAdapter == null) {
|
||||
throw new ServletException(Config.getInstance().getErrorMessage("session-invalid"));
|
||||
}
|
||||
ChibaEvent chibaEvent = new DefaultChibaEventImpl();
|
||||
chibaEvent.initEvent("http-request",null,request);
|
||||
chibaAdapter.dispatch(chibaEvent);
|
||||
|
||||
boolean isUpload = FileUpload.isMultipartContent(request);
|
||||
|
||||
if(isUpload){
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html><head><title>status</title></head><body><div id='upload-status-ok' style='width:10px;height:10px;background:green'> </div></body></html>");
|
||||
out.close();
|
||||
}else{
|
||||
if(!replaceAll(chibaAdapter, response)){
|
||||
UIGenerator uiGenerator = (UIGenerator) session.getAttribute(CHIBA_UI_GENERATOR);
|
||||
uiGenerator.setInputNode(chibaAdapter.getXForms());
|
||||
uiGenerator.setOutput(response.getWriter());
|
||||
uiGenerator.generate();
|
||||
response.getWriter().close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
shutdown(chibaAdapter, session, e, response, request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// end of class
|
@@ -1,439 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.servlet;
|
||||
|
||||
import org.apache.commons.fileupload.DiskFileUpload;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUpload;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.log4j.Category;
|
||||
import org.chiba.xml.xforms.ChibaBean;
|
||||
import org.chiba.xml.xforms.config.Config;
|
||||
import org.chiba.xml.xforms.events.XFormsEventFactory;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.chiba.xml.xforms.ui.Repeat;
|
||||
import org.chiba.adapter.ChibaEvent;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Default implementation for handling http servlet requests.
|
||||
*
|
||||
* @author joern turner
|
||||
* @version $Id: HttpRequestHandler.java,v 1.7 2005/10/27 23:10:31 joernt Exp $
|
||||
*/
|
||||
public class HttpRequestHandler {
|
||||
private static final Category LOGGER = Category.getInstance(HttpRequestHandler.class);
|
||||
public static final String DATA_PREFIX_PROPERTY = "chiba.web.dataPrefix";
|
||||
public static final String TRIGGER_PREFIX_PROPERTY = "chiba.web.triggerPrefix";
|
||||
public static final String SELECTOR_PREFIX_PROPERTY = "chiba.web.selectorPrefix";
|
||||
public static final String REMOVE_UPLOAD_PREFIX_PROPERTY = "chiba.web.removeUploadPrefix";
|
||||
public static final String DATA_PREFIX_DEFAULT = "d_";
|
||||
public static final String TRIGGER_PREFIX_DEFAULT = "t_";
|
||||
public static final String SELECTOR_PREFIX_DEFAULT = "s_";
|
||||
public static final String REMOVE_UPLOAD_PREFIX_DEFAULT = "ru_";
|
||||
|
||||
private ChibaBean chibaBean;
|
||||
|
||||
private String dataPrefix;
|
||||
private String selectorPrefix;
|
||||
private String triggerPrefix;
|
||||
private String removeUploadPrefix;
|
||||
private String uploadRoot;
|
||||
|
||||
|
||||
public HttpRequestHandler(ChibaBean chibaBean) {
|
||||
this.chibaBean = chibaBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* executes this handler.
|
||||
*
|
||||
* @throws XFormsException
|
||||
*/
|
||||
public void execute(ChibaEvent event) throws XFormsException {
|
||||
//HttpServletRequest request = (HttpServletRequest) this.chibaBean.getContext().get(ServletAdapter.HTTP_SERVLET_REQUEST);
|
||||
HttpServletRequest request= (HttpServletRequest) event.getContextInfo();
|
||||
|
||||
String contextRoot = request.getSession().getServletContext().getRealPath("");
|
||||
if (contextRoot == null) {
|
||||
contextRoot = request.getSession().getServletContext().getRealPath(".");
|
||||
}
|
||||
|
||||
String uploadDir = (String) this.chibaBean.getContext().get(ServletAdapter.HTTP_UPLOAD_DIR);
|
||||
this.uploadRoot = new File(contextRoot, uploadDir).getAbsolutePath();
|
||||
|
||||
handleRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether we have multipart or urlencoded request and processes it accordingly. After updating
|
||||
* the data, a reacalculate, revalidate refresh sequence is fired and the found trigger is executed.
|
||||
*
|
||||
* @param request Servlet request
|
||||
* @throws org.chiba.xml.xforms.exception.XFormsException
|
||||
* todo: implement action block behaviour
|
||||
*/
|
||||
protected void handleRequest(HttpServletRequest request) throws XFormsException {
|
||||
String trigger = null;
|
||||
|
||||
// Check that we have a file upload request
|
||||
boolean isMultipart = FileUpload.isMultipartContent(request);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("request isMultipart: " + isMultipart);
|
||||
LOGGER.debug("base URI: " + this.chibaBean.getBaseURI());
|
||||
LOGGER.debug("user agent: " + request.getHeader("User-Agent"));
|
||||
}
|
||||
|
||||
if (isMultipart) {
|
||||
trigger = processMultiPartRequest(request, trigger);
|
||||
} else {
|
||||
trigger = processUrlencodedRequest(request, trigger);
|
||||
}
|
||||
|
||||
// finally activate trigger if any
|
||||
if (trigger != null) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("trigger '" + trigger + "'");
|
||||
}
|
||||
|
||||
this.chibaBean.dispatch(trigger, XFormsEventFactory.DOM_ACTIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param request Servlet request
|
||||
* @param trigger Trigger control
|
||||
* @return the calculated trigger
|
||||
* @throws XFormsException If an error occurs
|
||||
*/
|
||||
protected String processMultiPartRequest(HttpServletRequest request, String trigger) throws XFormsException {
|
||||
DiskFileUpload upload = new DiskFileUpload();
|
||||
|
||||
String encoding = request.getCharacterEncoding();
|
||||
if (encoding == null) {
|
||||
encoding = "ISO-8859-1";
|
||||
}
|
||||
|
||||
upload.setRepositoryPath(this.uploadRoot);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("root dir for uploads: " + this.uploadRoot);
|
||||
}
|
||||
|
||||
List items;
|
||||
try {
|
||||
items = upload.parseRequest(request);
|
||||
} catch (FileUploadException fue) {
|
||||
throw new XFormsException(fue);
|
||||
}
|
||||
|
||||
Map formFields = new HashMap();
|
||||
Iterator iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
FileItem item = (FileItem) iter.next();
|
||||
String itemName = item.getName();
|
||||
String fieldName = item.getFieldName();
|
||||
String id = fieldName.substring(Config.getInstance().getProperty("chiba.web.dataPrefix").length());
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Multipart item name is: " + itemName
|
||||
+ " and fieldname is: " + fieldName
|
||||
+ " and id is: " + id);
|
||||
LOGGER.debug("Is formfield: " + item.isFormField());
|
||||
}
|
||||
|
||||
if (item.isFormField()) {
|
||||
|
||||
// check for upload-remove action
|
||||
if (fieldName.startsWith(getRemoveUploadPrefix())) {
|
||||
id = fieldName.substring(getRemoveUploadPrefix().length());
|
||||
// if data is null, file will be removed ...
|
||||
// TODO: remove the file from the disk as well
|
||||
chibaBean.updateControlValue(id, "", "", null);
|
||||
continue;
|
||||
}
|
||||
|
||||
// It's a field name, it means that we got a non-file
|
||||
// form field. Upload is not required. We must treat it as we
|
||||
// do in processUrlencodedRequest()
|
||||
processMultipartParam(formFields, fieldName, item, encoding);
|
||||
} else {
|
||||
|
||||
String uniqueFilename = new File(getUniqueParameterName("file"),
|
||||
new File(itemName).getName()).getPath();
|
||||
|
||||
File savedFile = new File(this.uploadRoot, uniqueFilename);
|
||||
|
||||
byte[] data = null;
|
||||
|
||||
data = processMultiPartFile(item, id, savedFile, encoding, data);
|
||||
|
||||
// if data is null, file will be removed ...
|
||||
// TODO: remove the file from the disk as well
|
||||
chibaBean.updateControlValue(id, item.getContentType(),
|
||||
itemName, data);
|
||||
}
|
||||
|
||||
// handle regular fields
|
||||
if (formFields.size() > 0) {
|
||||
|
||||
Iterator it = formFields.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
fieldName = (String) it.next();
|
||||
String[] values = (String[]) formFields.get(fieldName);
|
||||
|
||||
// [1] handle data
|
||||
handleData(fieldName, values);
|
||||
|
||||
// [2] handle selector
|
||||
handleSelector(fieldName, values[0]);
|
||||
|
||||
// [3] handle trigger
|
||||
trigger = handleTrigger(trigger, fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trigger;
|
||||
}
|
||||
|
||||
protected String processUrlencodedRequest(HttpServletRequest request, String trigger) throws XFormsException {
|
||||
// iterate request parameters
|
||||
Enumeration names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String paramName = names.nextElement().toString();
|
||||
String[] values = request.getParameterValues(paramName);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(this + " parameter-name: " + paramName);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
LOGGER.debug(this + " value: " + values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// [1] handle data
|
||||
handleData(paramName, values);
|
||||
|
||||
// [2] handle selector
|
||||
handleSelector(paramName, values[0]);
|
||||
|
||||
// [3] handle trigger
|
||||
trigger = handleTrigger(trigger, paramName);
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @throws XFormsException
|
||||
*/
|
||||
protected void handleData(String name, String[] values)
|
||||
throws XFormsException {
|
||||
if (name.startsWith(getDataPrefix())) {
|
||||
String id = name.substring(getDataPrefix().length());
|
||||
|
||||
// assemble new control value
|
||||
String newValue;
|
||||
|
||||
if (values.length > 1) {
|
||||
StringBuffer buffer = new StringBuffer(values[0]);
|
||||
|
||||
for (int i = 1; i < values.length; i++) {
|
||||
buffer.append(" ").append(values[i]);
|
||||
}
|
||||
|
||||
newValue = trim( buffer.toString() );
|
||||
} else {
|
||||
newValue = trim( values[0] );
|
||||
}
|
||||
|
||||
this.chibaBean.updateControlValue(id, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* patch to handle linefeed duplication in textareas with some browsers.
|
||||
*
|
||||
* @param value the value where linebreaks will be trimmed
|
||||
* @return returns a cleaned up version of the value
|
||||
*/
|
||||
|
||||
protected String trim(String value) {
|
||||
if (value != null && value.length() > 0) {
|
||||
value = value.replaceAll("\r\n", "\r");
|
||||
value = value.trim();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @throws XFormsException
|
||||
*/
|
||||
protected void handleSelector(String name, String value) throws XFormsException {
|
||||
if (name.startsWith(getSelectorPrefix())) {
|
||||
int separator = value.lastIndexOf(':');
|
||||
|
||||
String id = value.substring(0, separator);
|
||||
int index = Integer.valueOf(value.substring(separator + 1)).intValue();
|
||||
|
||||
Repeat repeat = (Repeat) this.chibaBean.lookup(id);
|
||||
repeat.setIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
protected String handleTrigger(String trigger, String name) {
|
||||
if ((trigger == null) && name.startsWith(getTriggerPrefix())) {
|
||||
String parameter = name;
|
||||
int x = parameter.lastIndexOf(".x");
|
||||
int y = parameter.lastIndexOf(".y");
|
||||
|
||||
if (x > -1) {
|
||||
parameter = parameter.substring(0, x);
|
||||
}
|
||||
|
||||
if (y > -1) {
|
||||
parameter = parameter.substring(0, y);
|
||||
}
|
||||
|
||||
// keep trigger id
|
||||
trigger = name.substring(getTriggerPrefix().length());
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
|
||||
private byte[] processMultiPartFile(FileItem item, String id, File savedFile, String encoding, byte[] data)
|
||||
throws XFormsException {
|
||||
// some data uploaded ...
|
||||
if (item.getSize() > 0) {
|
||||
|
||||
if (chibaBean.storesExternalData(id)) {
|
||||
|
||||
// store data to file and create URI
|
||||
try {
|
||||
savedFile.getParentFile().mkdir();
|
||||
item.write(savedFile);
|
||||
} catch (Exception e) {
|
||||
throw new XFormsException(e);
|
||||
}
|
||||
// content is URI in this case
|
||||
try {
|
||||
data = savedFile.toURI().toString().getBytes(encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new XFormsException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
// content is the data
|
||||
data = item.get();
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private void processMultipartParam(Map formFields, String fieldName, FileItem item, String encoding) throws XFormsException {
|
||||
String values[] = (String[]) formFields.get(fieldName);
|
||||
String formFieldValue = null;
|
||||
try {
|
||||
formFieldValue = item.getString(encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new XFormsException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (values == null) {
|
||||
formFields.put(fieldName, new String[]{formFieldValue});
|
||||
} else {
|
||||
// not very effective, but not many duplicate values
|
||||
// expected either ...
|
||||
String[] tmp = new String[values.length + 1];
|
||||
System.arraycopy(values, 0, tmp, 0, values.length);
|
||||
tmp[values.length] = formFieldValue;
|
||||
formFields.put(fieldName, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the prefix which is used to identify trigger parameters.
|
||||
*
|
||||
* @return the prefix which is used to identify trigger parameters
|
||||
*/
|
||||
protected final String getTriggerPrefix() {
|
||||
if (this.triggerPrefix == null) {
|
||||
try {
|
||||
this.triggerPrefix =
|
||||
Config.getInstance().getProperty(TRIGGER_PREFIX_PROPERTY, TRIGGER_PREFIX_DEFAULT);
|
||||
} catch (Exception e) {
|
||||
this.triggerPrefix = TRIGGER_PREFIX_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return this.triggerPrefix;
|
||||
}
|
||||
|
||||
protected final String getDataPrefix() {
|
||||
if (this.dataPrefix == null) {
|
||||
try {
|
||||
this.dataPrefix = Config.getInstance().getProperty(DATA_PREFIX_PROPERTY, DATA_PREFIX_DEFAULT);
|
||||
} catch (Exception e) {
|
||||
this.dataPrefix = DATA_PREFIX_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return this.dataPrefix;
|
||||
}
|
||||
|
||||
protected final String getRemoveUploadPrefix() {
|
||||
if (this.removeUploadPrefix == null) {
|
||||
try {
|
||||
this.removeUploadPrefix = Config.getInstance().getProperty(REMOVE_UPLOAD_PREFIX_PROPERTY, REMOVE_UPLOAD_PREFIX_DEFAULT);
|
||||
} catch (Exception e) {
|
||||
this.removeUploadPrefix = REMOVE_UPLOAD_PREFIX_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return this.removeUploadPrefix;
|
||||
}
|
||||
|
||||
|
||||
private String getUniqueParameterName(String prefix) {
|
||||
return prefix + Integer.toHexString((int) (Math.random() * 10000));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the configured prefix which identifies 'selector' parameters. These are used to transport
|
||||
* the state of repeat indices via http.
|
||||
*
|
||||
* @return the prefix for selector parameters from the configuration
|
||||
*/
|
||||
public final String getSelectorPrefix() {
|
||||
if (this.selectorPrefix == null) {
|
||||
try {
|
||||
this.selectorPrefix =
|
||||
Config.getInstance().getProperty(SELECTOR_PREFIX_PROPERTY,
|
||||
SELECTOR_PREFIX_DEFAULT);
|
||||
} catch (Exception e) {
|
||||
this.selectorPrefix = SELECTOR_PREFIX_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return this.selectorPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of chibaBean.
|
||||
*
|
||||
* @return the value of chibaBean
|
||||
*/
|
||||
public ChibaBean getChibaBean() {
|
||||
return this.chibaBean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// end of class
|
||||
|
||||
|
@@ -1,167 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.servlet;
|
||||
|
||||
import org.apache.log4j.Category;
|
||||
import org.chiba.adapter.AbstractChibaAdapter;
|
||||
import org.chiba.adapter.ChibaEvent;
|
||||
import org.chiba.xml.xforms.events.XFormsEvent;
|
||||
import org.chiba.xml.xforms.events.XFormsEventFactory;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* integrates XForms Processor into Web-applications and handles request
|
||||
* processing. This is the default implementation of ChibaAdapter and besides
|
||||
* handling the interaction it also manages a UIGenerator to build the rendered
|
||||
* output for the browser.
|
||||
*
|
||||
* @author joern turner
|
||||
* @version $Id: ServletAdapter.java,v 1.8 2005/12/15 11:45:38 unl Exp $
|
||||
*/
|
||||
public class ServletAdapter extends AbstractChibaAdapter implements EventListener {
|
||||
|
||||
private static final Category LOGGER = Category.getInstance(ServletAdapter.class);
|
||||
public static final String HTTP_SERVLET_REQUEST = "chiba.web.request";
|
||||
//public static final String HTTP_SESSION_OBJECT = "chiba.web.session";
|
||||
public static final String HTTP_UPLOAD_DIR = "chiba.web.uploadDir";
|
||||
|
||||
//private ChibaBean chibaBean = null;
|
||||
//private String formURI = null;
|
||||
//private String actionUrl = null;
|
||||
//private String CSSFile = null;
|
||||
//private String stylesheet = null;
|
||||
//private UIGenerator generator = null;
|
||||
//private String stylesheetPath = null;
|
||||
//private HashMap context = null;
|
||||
public static final String USERAGENT = "chiba.useragent";
|
||||
private HttpRequestHandler handler;
|
||||
public static final Object XSLT_PATH = "xslt-path";
|
||||
|
||||
/**
|
||||
* Creates a new ServletAdapter object.
|
||||
*/
|
||||
public ServletAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* place to put application-specific params or configurations before
|
||||
* actually starting off the XFormsProcessor. It's the responsibility of
|
||||
* this method to call chibaBean.init() to finish up the processor setup.
|
||||
*
|
||||
* @throws XFormsException If an error occurs
|
||||
*/
|
||||
public void init() throws XFormsException {
|
||||
this.chibaBean.init();
|
||||
this.handler = getNewInteractionHandler();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ServletAdapter knows and executes only one ChibaEvent: 'http-request'
|
||||
* which will contain the HttpServletRequest as contextInfo.
|
||||
*
|
||||
* @param event only events of type 'http-request' will be handled
|
||||
* @throws XFormsException
|
||||
*/
|
||||
public void dispatch(ChibaEvent event) throws XFormsException {
|
||||
if (event.getEventName().equals("http-request")) {
|
||||
this.handler.execute(event);
|
||||
}
|
||||
else {
|
||||
LOGGER.warn("unknown event: '" + event.getEventName() + "' - ignoring");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* terminates the XForms processing. right place to do cleanup of
|
||||
* resources.
|
||||
*
|
||||
* @throws org.chiba.xml.xforms.exception.XFormsException
|
||||
*/
|
||||
public void shutdown() throws XFormsException {
|
||||
this.chibaBean.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the application environment to forward the given response.
|
||||
*
|
||||
* @param response a map containing at least a response stream and optional
|
||||
* header information.
|
||||
*/
|
||||
public void forward(Map response) {
|
||||
this.chibaBean.getContext().put(SUBMISSION_RESPONSE, response);
|
||||
}
|
||||
|
||||
// todo: should be set by servlet
|
||||
|
||||
/**
|
||||
* return a new InteractionHandler.
|
||||
* <p/>
|
||||
* This method returns a new HttpRequestHandler.
|
||||
*
|
||||
* @return returns a new
|
||||
*/
|
||||
protected HttpRequestHandler getNewInteractionHandler()
|
||||
throws XFormsException {
|
||||
return new HttpRequestHandler(this.chibaBean);
|
||||
}
|
||||
|
||||
public void setUploadDestination(String uploadDir) {
|
||||
super.setUploadDestination(uploadDir);
|
||||
//HttpRequestHandler uses this
|
||||
// todo: should be a member of request handler and set directly
|
||||
setContextParam(HTTP_UPLOAD_DIR, uploadDir);
|
||||
}
|
||||
|
||||
// event handling
|
||||
// todo: should be moved up to base class
|
||||
|
||||
/**
|
||||
* This method is called whenever an event occurs of the type for which the
|
||||
* <code> EventListener</code> interface was registered.
|
||||
*
|
||||
* @param event The <code>Event</code> contains contextual information about
|
||||
* the event. It also contains the <code>stopPropagation</code> and
|
||||
* <code>preventDefault</code> methods which are used in determining the
|
||||
* event's flow and default action.
|
||||
*/
|
||||
public void handleEvent(Event event) {
|
||||
String type = event.getType();
|
||||
String targetId = ((Element) event.getTarget()).getAttributeNS(null, "id");
|
||||
XFormsEvent xformsEvent = (XFormsEvent) event;
|
||||
|
||||
if (XFormsEventFactory.CHIBA_LOAD_URI.equals(type)) {
|
||||
handleLoadURI(targetId, (String) xformsEvent.getContextInfo("uri"), (String) xformsEvent.getContextInfo("show"));
|
||||
return;
|
||||
}
|
||||
if (XFormsEventFactory.CHIBA_RENDER_MESSAGE.equals(type)) {
|
||||
handleMessage(targetId, (String) xformsEvent.getContextInfo("message"), (String) xformsEvent.getContextInfo("level"));
|
||||
return;
|
||||
}
|
||||
if (XFormsEventFactory.CHIBA_REPLACE_ALL.equals(type)) {
|
||||
handleReplaceAll(targetId, (Map) xformsEvent.getContextInfo("header"), xformsEvent.getContextInfo("body"));
|
||||
return;
|
||||
}
|
||||
|
||||
// unknown event ignored
|
||||
}
|
||||
|
||||
// todo: *either* move up these three methods as abstract template methods *or* use event log ?
|
||||
public void handleLoadURI(String targetId, String uri, String show) {
|
||||
// todo
|
||||
}
|
||||
|
||||
public void handleMessage(String targetId, String message, String level) {
|
||||
// todo
|
||||
}
|
||||
|
||||
public void handleReplaceAll(String targetId, Map header, Object body) {
|
||||
// todo
|
||||
}
|
||||
}
|
||||
|
||||
// end of class
|
@@ -1,84 +0,0 @@
|
||||
package org.alfresco.web.templating.xforms.servlet;
|
||||
|
||||
import org.chiba.adapter.ChibaAdapter;
|
||||
import org.chiba.xml.xforms.exception.XFormsException;
|
||||
import org.apache.log4j.Category;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Returns a submission response exactly once.
|
||||
*
|
||||
* @author Ulrich Nicolas Lissé
|
||||
* @version $Id: SubmissionResponseServlet.java,v 1.1 2005/12/21 22:59:27 unl Exp $
|
||||
*/
|
||||
public class SubmissionResponseServlet extends HttpServlet {
|
||||
private static Category LOGGER = Category.getInstance(SubmissionResponseServlet.class);
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
// lookup session
|
||||
HttpSession session = request.getSession(false);
|
||||
if (session != null) {
|
||||
// lookup attribute containing submission response map
|
||||
Map submissionResponse = (Map) session.getAttribute(ChibaServlet.CHIBA_SUBMISSION_RESPONSE);
|
||||
if (submissionResponse != null) {
|
||||
// shutdown form session
|
||||
ChibaAdapter adapter = (ChibaAdapter) session.getAttribute(ChibaServlet.CHIBA_ADAPTER);
|
||||
if (adapter != null) {
|
||||
try {
|
||||
adapter.shutdown();
|
||||
}
|
||||
catch (XFormsException e) {
|
||||
LOGGER.error("xforms shutdown failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
// remove session attributes
|
||||
session.removeAttribute(ChibaServlet.CHIBA_ADAPTER);
|
||||
session.removeAttribute(ChibaServlet.CHIBA_SUBMISSION_RESPONSE);
|
||||
|
||||
// copy header fields
|
||||
Map headerMap = (Map) submissionResponse.get("header");
|
||||
Iterator iterator = headerMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final String name = (String) iterator.next();
|
||||
if (name.equalsIgnoreCase("Transfer-Encoding")) {
|
||||
// Some servers (e.g. WebSphere) may set a "Transfer-Encoding"
|
||||
// with the value "chunked". This may confuse the client since
|
||||
// ChibaServlet output is not encoded as "chunked", so this
|
||||
// header is ignored.
|
||||
continue;
|
||||
}
|
||||
|
||||
final String value = (String) headerMap.get(name);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("added header: " + name + "=" + value);
|
||||
}
|
||||
|
||||
response.setHeader(name, value);
|
||||
}
|
||||
|
||||
// copy body stream
|
||||
InputStream bodyStream = (InputStream) submissionResponse.get("body");
|
||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
for (int b = bodyStream.read(); b > -1; b = bodyStream.read()) {
|
||||
outputStream.write(b);
|
||||
}
|
||||
|
||||
// close streams
|
||||
bodyStream.close();
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
// response.sendError(HttpServletResponse.SC_FORBIDDEN, "no submission response available");
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
# Tokens
|
||||
chiba-version=1.0.0
|
||||
baseurl.host=localhost
|
||||
baseurl.port=8080
|
||||
|
@@ -1 +0,0 @@
|
||||
@version.major@ [build @version.build@]
|
Reference in New Issue
Block a user