use of org.directwebremoting.dwrp.SimpleOutboundVariable in project jaffa-framework by jaffa-projects.
the class CurrencyConverter method convertOutbound.
/*
* (non-Javadoc)
*
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object,
* org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
Double out = 0.0;
// Error out if an unsupported class is passed
if (!(data instanceof Currency)) {
log.warn("Unsupported input. Class=" + data.getClass() + ", data=" + data);
throw new MarshallException(data.getClass());
}
String currency = data.toString();
if (currency != null && currency != "") {
String layout = CurrencyFieldMetaData.getCurrencyFormat();
NumberFormat fmt;
if (LocaleContext.getLocale() != null) {
fmt = NumberFormat.getCurrencyInstance(LocaleContext.getLocale());
} else {
fmt = NumberFormat.getCurrencyInstance();
}
fmt.setCurrency(java.util.Currency.getInstance(Currency.USD));
if (layout != null && layout.length() > 0 && fmt instanceof DecimalFormat) {
((DecimalFormat) fmt).applyPattern(layout);
}
try {
out = Double.valueOf((fmt.parse(currency)).doubleValue());
currency = out.toString();
} catch (ParseException e) {
}
}
return new SimpleOutboundVariable(currency, outctx, true);
}
use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.
the class XOMConverter 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;
String script = EnginePrivate.xmlStringToJavascriptDom(node.toXML());
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 BlabberConverterManager method convertOutbound.
/*
* (non-Javadoc)
*
* @see org.directwebremoting.ConverterManager#convertOutbound(java.lang.Object,
* org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object object, OutboundContext outctx) throws MarshallException {
if (object == null) {
return new SimpleOutboundVariable("null", outctx, true);
}
// Check to see if we have done this one already
OutboundVariable ov = outctx.get(object);
if (ov != null) {
// So the object as been converted already, we just need to refer to it.
return ov.getReferenceVariable();
}
// So we will have to do the conversion
Converter converter = getConverter(object);
if (converter == null) {
log.error(Messages.getString("DefaultConverterManager.MissingConverter", object.getClass().getName()));
return new SimpleOutboundVariable("null", outctx, true);
}
return converter.convertOutbound(object, outctx);
}
use of org.directwebremoting.dwrp.SimpleOutboundVariable in project ma-core-public by infiniteautomation.
the class UnitBeanConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.extend.Converter#convertOutbound(java.lang.Object, org.directwebremoting.extend.OutboundContext)
*/
@Override
public OutboundVariable convertOutbound(Object paramObject, OutboundContext paramOutboundContext) throws MarshallException {
// Convert from Unit to String
// Check to see if we have done this one already
OutboundVariable ov = paramOutboundContext.get(paramObject);
if (ov != null) {
// So the object as been converted already, we just need to refer to it.
return ov.getReferenceVariable();
}
if (paramObject instanceof Unit<?>) {
Unit<?> unit = (Unit<?>) paramObject;
String unitString = UnitUtil.formatLocal(unit);
if (unit == unit.ONE)
unitString = "ONE";
return new SimpleOutboundVariable("'" + unitString + "';", paramOutboundContext, false);
} else {
throw new MarshallException(paramObject.getClass());
}
}
use of org.directwebremoting.dwrp.SimpleOutboundVariable in project jaffa-framework by jaffa-projects.
the class JaffaDateConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// Error out if an unsupported class is passed
if (!(data instanceof DateOnly) && !(data instanceof DateTime)) {
log.warn("Unsupported input. Class=" + data.getClass() + ", data=" + data);
throw new MarshallException(data.getClass());
}
// Create a javascipt Date object.
// When using server time, Pass the individual date elements. This will ensure that a similar date will be constructed in the client's timezone.
// When not using server time, pass the millisecond since 1970 value. This will result in a date adjusted to the client's timezone.
StringBuilder jsDateConstructor = new StringBuilder("new Date(");
Boolean useServerTime = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(RULE_NAME_USE_SERVER_TIME));
if (data instanceof DateOnly) {
DateOnly d = (DateOnly) data;
if (useServerTime != null && useServerTime)
jsDateConstructor.append(d.year()).append(',').append(d.month()).append(',').append(d.day());
else
jsDateConstructor.append(d.timeInMillis());
} else {
DateTime d = (DateTime) data;
if (useServerTime != null && useServerTime)
jsDateConstructor.append(d.year()).append(',').append(d.month()).append(',').append(d.day()).append(',').append(d.hourOfDay()).append(',').append(d.minute()).append(',').append(d.second()).append(',').append(d.milli());
else
jsDateConstructor.append(d.timeInMillis());
}
String output = jsDateConstructor.append(')').toString();
if (log.isDebugEnabled())
log.debug("Outbound '" + data + "' converted to '" + output + '\'');
return new SimpleOutboundVariable(output, outctx, true);
}
Aggregations