use of org.directwebremoting.extend.OutboundVariable 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.extend.OutboundVariable 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);
}
}
use of org.directwebremoting.extend.OutboundVariable in project ma-core-public by infiniteautomation.
the class MapConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// First we just collect our converted children
Map ovs = (Map) LocalUtil.classNewInstance("OrderedConvertOutbound", "java.util.LinkedHashMap", Map.class);
if (ovs == null) {
ovs = new HashMap();
}
ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
outctx.put(data, ov);
// Loop through the map outputting any init code and collecting
// converted outbound variables into the ovs map
Map map = (Map) data;
for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
// It would be nice to check for Enums here
if (!(key instanceof String) && !sentNonStringWarning) {
log.warn("--Javascript does not support non string keys. Converting '" + key.getClass().getName() + "' using toString()");
sentNonStringWarning = true;
}
String outkey = JavascriptUtil.escapeJavaScript(key.toString());
// OutboundVariable ovkey = config.convertOutbound(key, outctx);
// buffer.append(ovkey.getInitCode());
// outkey = ovkey.getAssignCode();
OutboundVariable nested = config.convertOutbound(value, outctx);
ovs.put(outkey, nested);
}
ov.init(ovs, null);
return ov;
}
use of org.directwebremoting.extend.OutboundVariable in project ma-core-public by infiniteautomation.
the class AbstractOutboundVariable method getChildDeclareCodes.
/**
* Grab all the declare codes together
* @return A declare string
*/
private String getChildDeclareCodes() {
if (children == null) {
return "";
}
StringBuffer buffer = new StringBuffer();
// Make sure the nested things are declared
for (Iterator it = children.iterator(); it.hasNext(); ) {
OutboundVariable nested = (OutboundVariable) it.next();
buffer.append(nested.getDeclareCode());
}
return buffer.toString();
}
use of org.directwebremoting.extend.OutboundVariable in project ma-core-public by infiniteautomation.
the class ObjectOutboundVariable method getNotInlineDefinition.
/* (non-Javadoc)
* @see org.directwebremoting.dwrp.AbstractOutboundVariable#getNotInlineDefinition()
*/
protected NotInlineDefinition getNotInlineDefinition() {
String declareCode;
if (!isNamed) {
declareCode = "var " + getVariableName() + "={};";
} else {
declareCode = "var " + getVariableName() + "=new " + scriptClassName + "();";
}
StringBuffer buildCode = new StringBuffer();
for (Iterator it = ovs.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
OutboundVariable nested = (OutboundVariable) entry.getValue();
String nestedAssignCode = nested.getAssignCode();
String varName = getVariableName();
// I dont think we need this check: && !isRecursive()
if (LocalUtil.isSimpleName(name)) {
buildCode.append(varName);
buildCode.append('.');
buildCode.append(name);
buildCode.append('=');
buildCode.append(nestedAssignCode);
buildCode.append(';');
} else {
buildCode.append(varName);
buildCode.append("['");
buildCode.append(name);
buildCode.append("']=");
buildCode.append(nestedAssignCode);
buildCode.append(';');
}
}
buildCode.append("\r\n");
return new NotInlineDefinition(declareCode, buildCode.toString());
}
Aggregations