use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class DOMConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = LocalUtil.decode(iv.getValue());
try {
if (buildFactory == null) {
buildFactory = DocumentBuilderFactory.newInstance();
}
DocumentBuilder builder = buildFactory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(value));
Document doc = builder.parse(is);
if (paramType == Document.class) {
return doc;
} else if (paramType == Element.class) {
return doc.getDocumentElement();
}
throw new MarshallException(paramType);
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
}
use of org.directwebremoting.extend.MarshallException 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.MarshallException 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.extend.MarshallException in project ma-core-public by infiniteautomation.
the class EnumConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = LocalUtil.decode(iv.getValue());
Object[] values;
try {
Method getter = paramType.getMethod("values", new Class[0]);
values = (Object[]) getter.invoke(paramType, (Object[]) null);
} catch (NoSuchMethodException ex) {
// But this catch block has the same effect
throw new MarshallException(paramType);
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
for (int i = 0; i < values.length; i++) {
Object en = values[i];
if (value.equals(en.toString())) {
return en;
}
}
throw new MarshallException(paramType);
}
use of org.directwebremoting.extend.MarshallException 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