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