mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
get xforms instance data saved to the workspace.
get radios and comboboxes calling into setFormValue get editor working marginally better get edit to work git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3503 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -39,6 +40,7 @@ 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;
|
||||
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -48,9 +50,8 @@ public class XFormsBean
|
||||
private static final Log LOGGER = LogFactory.getLog(XFormsBean.class);
|
||||
|
||||
private TemplateType tt;
|
||||
private Document instanceData = null;
|
||||
private InstanceData instanceData = null;
|
||||
private ChibaBean chibaBean;
|
||||
private Map context = new HashMap();
|
||||
|
||||
public TemplateType getTemplateType()
|
||||
{
|
||||
@@ -62,7 +63,7 @@ public class XFormsBean
|
||||
this.tt = tt;
|
||||
}
|
||||
|
||||
public void setInstanceData(final Document instanceData)
|
||||
public void setInstanceData(final InstanceData instanceData)
|
||||
{
|
||||
this.instanceData = instanceData;
|
||||
}
|
||||
@@ -71,15 +72,18 @@ public class XFormsBean
|
||||
throws XFormsException
|
||||
{
|
||||
this.chibaBean = new ChibaBean();
|
||||
this.chibaBean.setContext(context);
|
||||
|
||||
final FacesContext facesContext = FacesContext.getCurrentInstance();
|
||||
final ExternalContext externalContext = facesContext.getExternalContext();
|
||||
final HttpServletRequest request = (HttpServletRequest)
|
||||
externalContext.getRequest();
|
||||
XFormsBean.storeCookies(request.getCookies(), this.chibaBean);
|
||||
try
|
||||
{
|
||||
LOGGER.debug("initializing " + this +
|
||||
" with tt " + tt.getName());
|
||||
final XFormsInputMethod tim = (XFormsInputMethod)
|
||||
tt.getInputMethods().get(0);
|
||||
final Document form = tim.getXForm(instanceData, tt);
|
||||
final Document form = tim.getXForm(instanceData.getContent(), tt);
|
||||
this.chibaBean.setXMLContainer(form);
|
||||
this.chibaBean.init();
|
||||
EventTarget et = (EventTarget)
|
||||
@@ -123,7 +127,7 @@ public class XFormsBean
|
||||
* @return the list of events that may result through this action
|
||||
*/
|
||||
public void setXFormsValue()
|
||||
throws XFormsException
|
||||
throws XFormsException, IOException
|
||||
{
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
|
||||
@@ -132,6 +136,9 @@ public class XFormsBean
|
||||
|
||||
LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")");
|
||||
this.chibaBean.updateControlValue(id, value);
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
out.write("<todo/>");
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +149,7 @@ public class XFormsBean
|
||||
* @return the list of events that may result through this action
|
||||
*/
|
||||
public void fireAction()
|
||||
throws XFormsException
|
||||
throws XFormsException, IOException
|
||||
{
|
||||
final FacesContext context = FacesContext.getCurrentInstance();
|
||||
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
|
||||
@@ -150,6 +157,9 @@ public class XFormsBean
|
||||
|
||||
LOGGER.debug(this + " fireAction(" + id + ")");
|
||||
this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE);
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
out.write("<todo/>");
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,23 +172,15 @@ public class XFormsBean
|
||||
public void handleAction()
|
||||
throws Exception
|
||||
{
|
||||
LOGGER.debug(this + " handleAction");
|
||||
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 TemplatingService ts = TemplatingService.getInstance();
|
||||
final Document result = ts.parseXML(request.getInputStream());
|
||||
this.instanceData.setContent(result);
|
||||
final ResponseWriter out = context.getResponseWriter();
|
||||
out.write(xml);
|
||||
ts.writeXML(result, out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
@@ -186,4 +188,31 @@ public class XFormsBean
|
||||
{
|
||||
LOGGER.debug("handleEvent " + e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private static void storeCookies(final javax.servlet.http.Cookie[] cookiesIn,
|
||||
final ChibaBean chibaBean){
|
||||
if (cookiesIn != null) {
|
||||
org.apache.commons.httpclient.Cookie[] commonsCookies =
|
||||
new org.apache.commons.httpclient.Cookie[cookiesIn.length];
|
||||
for (int i = 0; i < cookiesIn.length; i += 1) {
|
||||
commonsCookies[i] =
|
||||
new org.apache.commons.httpclient.Cookie(cookiesIn[i].getDomain(),
|
||||
cookiesIn[i].getName(),
|
||||
cookiesIn[i].getValue(),
|
||||
cookiesIn[i].getPath(),
|
||||
cookiesIn[i].getMaxAge(),
|
||||
cookiesIn[i].getSecure());
|
||||
}
|
||||
chibaBean.getContext().put(AbstractHTTPConnector.REQUEST_COOKIE,
|
||||
commonsCookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user