Search in sources :

Example 6 with SimpleOutboundVariable

use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.

the class URLConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    URL url = (URL) data;
    String escaped = JavascriptUtil.escapeJavaScript(url.toExternalForm());
    return new SimpleOutboundVariable('\"' + escaped + '\"', outctx, true);
}
Also used : SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) URL(java.net.URL)

Example 7 with SimpleOutboundVariable

use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.

the class DOM4JConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        // Using XSLT to convert to a stream. Setup the source
        if (!(data instanceof Node)) {
            throw new MarshallException(data.getClass());
        }
        Node node = (Node) data;
        OutputFormat outformat = OutputFormat.createCompactFormat();
        outformat.setEncoding("UTF-8");
        // Setup the destination
        StringWriter xml = new StringWriter();
        XMLWriter writer = new XMLWriter(xml, outformat);
        writer.write(node);
        writer.flush();
        xml.flush();
        String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : StringWriter(java.io.StringWriter) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Example 8 with SimpleOutboundVariable

use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.

the class DOMConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        Transformer transformer = xslFact.newTransformer();
        // Using XSLT to convert to a stream. Setup the source
        Source source;
        if (data instanceof Node) {
            Node node = (Node) data;
            source = new DOMSource(node);
        } else {
            throw new MarshallException(data.getClass());
        }
        // Setup the destination
        StringWriter xml = new StringWriter();
        StreamResult result = new StreamResult(xml);
        transformer.transform(source, result);
        xml.flush();
        String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Node(org.w3c.dom.Node) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source) MarshallException(org.directwebremoting.extend.MarshallException)

Example 9 with SimpleOutboundVariable

use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.

the class DateConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    long millis;
    if (data instanceof Calendar) {
        Calendar cal = (Calendar) data;
        millis = cal.getTime().getTime();
    } else if (data instanceof Date) {
        Date date = (Date) data;
        millis = date.getTime();
    } else {
        throw new MarshallException(data.getClass());
    }
    return new SimpleOutboundVariable("new Date(" + millis + ")", outctx, true);
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) Calendar(java.util.Calendar) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) Date(java.util.Date)

Example 10 with SimpleOutboundVariable

use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.

the class JDOMConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        Format outformat = Format.getCompactFormat();
        outformat.setEncoding("UTF-8");
        // Setup the destination
        StringWriter xml = new StringWriter();
        XMLOutputter writer = new XMLOutputter(outformat);
        // Using XSLT to convert to a stream. Setup the source
        if (data instanceof Document) {
            Document doc = (Document) data;
            writer.output(doc, xml);
        } else if (data instanceof Element) {
            Element ele = (Element) data;
            writer.output(ele, xml);
        } else {
            throw new MarshallException(data.getClass());
        }
        xml.flush();
        String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Element(org.jdom.Element) Document(org.jdom.Document) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Aggregations

SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)10 MarshallException (org.directwebremoting.extend.MarshallException)8 OutboundVariable (org.directwebremoting.extend.OutboundVariable)6 StringWriter (java.io.StringWriter)3 URL (java.net.URL)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Unit (javax.measure.unit.Unit)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Node (nu.xom.Node)1 Converter (org.directwebremoting.extend.Converter)1 NamedConverter (org.directwebremoting.extend.NamedConverter)1 Node (org.dom4j.Node)1 OutputFormat (org.dom4j.io.OutputFormat)1