diff --git a/source/java/org/alfresco/web/bean/ajax/XFormsBean.java b/source/java/org/alfresco/web/bean/ajax/XFormsBean.java index 7a01b131b3..8f3527f219 100644 --- a/source/java/org/alfresco/web/bean/ajax/XFormsBean.java +++ b/source/java/org/alfresco/web/bean/ajax/XFormsBean.java @@ -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(""); + 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(""); + 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); + } + } } diff --git a/source/java/org/alfresco/web/templating/InstanceData.java b/source/java/org/alfresco/web/templating/InstanceData.java new file mode 100644 index 0000000000..a88558e558 --- /dev/null +++ b/source/java/org/alfresco/web/templating/InstanceData.java @@ -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); +} \ No newline at end of file diff --git a/source/java/org/alfresco/web/templating/TemplateInputMethod.java b/source/java/org/alfresco/web/templating/TemplateInputMethod.java index 35a589102c..ec7a8d144d 100644 --- a/source/java/org/alfresco/web/templating/TemplateInputMethod.java +++ b/source/java/org/alfresco/web/templating/TemplateInputMethod.java @@ -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); diff --git a/source/java/org/alfresco/web/templating/TemplatingService.java b/source/java/org/alfresco/web/templating/TemplatingService.java index 20af4b24f1..59ee466128 100644 --- a/source/java/org/alfresco/web/templating/TemplatingService.java +++ b/source/java/org/alfresco/web/templating/TemplatingService.java @@ -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, diff --git a/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java b/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java index e5fbfda5ce..100599771d 100644 --- a/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java +++ b/source/java/org/alfresco/web/templating/xforms/XFormsInputMethod.java @@ -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 { diff --git a/source/web/jsp/content/create-content-wizard/create-xml.jsp b/source/web/jsp/content/create-content-wizard/create-xml.jsp index 40db58b871..6fb42de5b5 100644 --- a/source/web/jsp/content/create-content-wizard/create-xml.jsp +++ b/source/web/jsp/content/create-content-wizard/create-xml.jsp @@ -21,12 +21,33 @@ <%@ page import="org.alfresco.web.app.Application" %> <%@ page import="org.alfresco.web.templating.*" %> <%@ page import="org.alfresco.web.bean.content.CreateContentWizard" %> +<%@ page import="org.w3c.dom.Document" %> <% -CreateContentWizard wiz = (CreateContentWizard) +final CreateContentWizard wiz = (CreateContentWizard) Application.getWizardManager().getBean(); TemplateType tt = wiz.getTemplateType(); TemplateInputMethod tim = tt.getInputMethods().get(0); -TemplatingService ts = TemplatingService.getInstance(); -tim.generate(wiz.getContent() != null ? ts.parseXML(wiz.getContent()) : null, tt, out); +final TemplatingService ts = TemplatingService.getInstance(); +final InstanceData instanceData = new InstanceData() { + + public Document getContent() + { + try + { + return wiz.getContent() != null ? ts.parseXML(wiz.getContent()) : null; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public void setContent(final Document d) + { + wiz.setContent(ts.writeXMLToString(d)); + } +}; +tim.generate(instanceData, tt, out); %> diff --git a/source/web/jsp/content/create-xml-content-type-wizard/edit.jsp b/source/web/jsp/content/create-xml-content-type-wizard/edit.jsp index 91a719b01b..b4960411b2 100644 --- a/source/web/jsp/content/create-xml-content-type-wizard/edit.jsp +++ b/source/web/jsp/content/create-xml-content-type-wizard/edit.jsp @@ -22,11 +22,15 @@ <%@ page import="org.alfresco.web.app.Application" %> <%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %> <%@ page import="org.alfresco.web.templating.*" %> - +<%@ page import="org.w3c.dom.Document" %> <% CreateXmlContentTypeWizard wiz = (CreateXmlContentTypeWizard) Application.getWizardManager().getBean(); TemplateType tt = wiz.getTemplateType(); TemplateInputMethod tim = tt.getInputMethods().get(0); -tim.generate(null, tt, out); +final InstanceData instanceData = new InstanceData() { + public Document getContent() { return null; } + public void setContent(Document d) { } +}; +tim.generate(instanceData, tt, out); %> diff --git a/source/web/jsp/dialog/edit-xml-inline.jsp b/source/web/jsp/dialog/edit-xml-inline.jsp index 7728e8c463..c48b5d6d27 100644 --- a/source/web/jsp/dialog/edit-xml-inline.jsp +++ b/source/web/jsp/dialog/edit-xml-inline.jsp @@ -27,17 +27,41 @@ org.alfresco.service.cmr.repository.*, org.alfresco.web.bean.content.*, org.alfresco.web.templating.*" %> +<%@ page import="java.io.*" %> +<%@ page import="org.alfresco.web.app.Application" %> +<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %> +<%@ page import="org.alfresco.web.templating.*" %> +<%@ page import="org.w3c.dom.Document" %> <% -CheckinCheckoutBean ccb = (CheckinCheckoutBean)session.getAttribute("CheckinCheckoutBean"); +final CheckinCheckoutBean ccb = (CheckinCheckoutBean) + session.getAttribute("CheckinCheckoutBean"); NodeRef nr = ccb.getDocument().getNodeRef(); String ttName = (String)ccb.getNodeService().getProperty(nr, CreateContentWizard.TT_QNAME); -TemplatingService ts = TemplatingService.getInstance(); -TemplateType tt = ts.getTemplateType(ttName); -System.out.println("tt " + tt); +final TemplatingService ts = TemplatingService.getInstance(); +final TemplateType tt = ts.getTemplateType(ttName); TemplateInputMethod tim = tt.getInputMethods().get(0); -String url = tim.getInputURL(ts.parseXML(ccb.getDocumentContent()), tt); -System.out.println("inputurl " + url); +final InstanceData instanceData = new InstanceData() { + + public Document getContent() + { + try + { + return ccb.getDocumentContent() != null ? ts.parseXML(ccb.getDocumentContent()) : null; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public void setContent(final Document d) + { + ccb.setEditorOutput(ts.writeXMLToString(d)); + } +}; %> + @@ -152,8 +176,8 @@ System.out.println("inputurl " + url); <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %> - +<% tim.generate(instanceData, tt, out); %> + <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %> diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index a3e7c175f6..1ca5e87f7d 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -110,7 +110,30 @@ function load_body(body, ui_element_stack) var nodeRef = document.createElement("div"); nodeRef.setAttribute("style", "height: 200px; border: solid 1px black;"); cell.appendChild(nodeRef); - var w = dojo.widget.createWidget("Editor", { items: ["|", "bold", "italic", "underline", "strikethrough", "|", "colorGroup", "|", "createLink", "insertImage" ] }, nodeRef); + var id = o.getAttribute("id"); + var initial_value = get_initial_value(o); + nodeRef.appendChild(document.createTextNode(initial_value)); + var w = dojo.widget.createWidget("Editor", + { + widgetId: id, + focusOnLoad: false, + items: [ "|", "bold", "italic", "underline", "strikethrough", "|", "colorGroup", "|", "createLink", "insertImage" ] + }, + nodeRef); + dojo.event.connect(w, + "setRichText", + function(event) + { + dojo.event.connect(w._richText, + "onBlur", + function() + { + setXFormsValue(w.widgetId, + w._richText.getEditorContent()); + }); + + }); + break; case "xforms:input": var id = o.getAttribute("id"); @@ -266,11 +289,17 @@ function load_body(body, ui_element_stack) for (var i in values) { var radio = document.createElement("input"); + radio.setAttribute("id", o.getAttribute("id")); radio.setAttribute("name", o.getAttribute("id")); radio.setAttribute("type", "radio"); radio.setAttribute("value", values[i].value); if (values[i].value == initial_value) radio.setAttribute("checked", "true"); + radio.onclick = function(event) + { + setXFormsValue(this.getAttribute("id"), + this.value); + } nodeRef.appendChild(radio); nodeRef.appendChild(document.createTextNode(values[i].label)); } @@ -278,6 +307,7 @@ function load_body(body, ui_element_stack) else { var combobox = document.createElement("select"); + combobox.setAttribute("id", o.getAttribute("id")); nodeRef.appendChild(combobox); for (var i in values) { @@ -288,6 +318,11 @@ function load_body(body, ui_element_stack) option.setAttribute("selected", "true"); combobox.appendChild(option); } + combobox.onchange = function(event) + { + setXFormsValue(this.getAttribute("id"), + this.options[this.selectedIndex].value); + } } break; case "xforms:submit": @@ -414,7 +449,7 @@ function fireAction(id) mimetype: "text/xml", load: function(type, data, evt) { - alert("fired action " + id); + // alert("fired action " + id); }, error: function(type, e) {