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:
Ariel Backenroth
2006-08-14 21:12:10 +00:00
parent 0cffbc7aa1
commit 6aea4ef3af
9 changed files with 185 additions and 39 deletions

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.templating;
import org.w3c.dom.Document;
public interface InstanceData
{
public Document getContent();
public void setContent(final Document d);
}

View File

@@ -21,7 +21,7 @@ import java.io.Writer;
public interface TemplateInputMethod
{
public void generate(final Document xmlContent,
public void generate(final InstanceData instanceData,
final TemplateType tt,
final Writer out);

View File

@@ -129,6 +129,13 @@ public class TemplatingService
this.writeXML(n, new FileWriter(output));
}
public String writeXMLToString(final Node n)
{
final StringWriter result = new StringWriter();
this.writeXML(n, result);
return result.toString();
}
public Document parseXML(final String source)
throws ParserConfigurationException,
SAXException,

View File

@@ -44,7 +44,7 @@ public class XFormsInputMethod
{
}
public void generate(final Document xmlContent,
public void generate(final InstanceData instanceData,
final TemplateType tt,
final Writer out)
{
@@ -52,7 +52,7 @@ public class XFormsInputMethod
final FacesContext fc = FacesContext.getCurrentInstance();
final XFormsBean xforms = (XFormsBean)
FacesHelper.getManagedBean(fc, "XFormsBean");
xforms.setInstanceData(xmlContent);
xforms.setInstanceData(instanceData);
xforms.setTemplateType(tt);
try
{