use of com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper in project servoy-client by Servoy.
the class MediaDataproviderPropertyType method toJSON.
@Override
public JSONWriter toJSON(JSONWriter writer, String key, Object sabloValue, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
JSONUtils.addKeyIfPresent(writer, key);
if (sabloValue != null) {
if (sabloValue.getClass().isArray() && sabloValue.getClass().getComponentType() == byte.class) {
ByteArrayResourcePropertyType.INSTANCE.toJSON(writer, null, (byte[]) sabloValue, NGUtils.MEDIA_DATAPROVIDER_BYTE_ARRAY_CACHED_PD, clientConversion, dataConverterContext);
} else if (sabloValue instanceof Date) {
NGDatePropertyType.NG_INSTANCE.toJSON(writer, null, (Date) sabloValue, NGUtils.DATE_DATAPROVIDER_CACHED_PD, clientConversion, dataConverterContext);
} else if (sabloValue instanceof String) {
if (((String) sabloValue).toLowerCase().startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
String url = MediaPropertyType.INSTANCE.getMediaUrl(sabloValue, ((WebFormComponent) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution(), null);
MediaPropertyType.INSTANCE.toJSON(writer, key, new MediaWrapper(sabloValue, url), pd, clientConversion, dataConverterContext);
} else if (Boolean.TRUE.equals(pd.getConfig())) {
HTMLStringPropertyType.INSTANCE.toJSON(writer, null, (String) sabloValue, NGUtils.TEXT_PARSEHTML_DATAPROVIDER_CACHED_PD, clientConversion, dataConverterContext);
} else {
HTMLStringPropertyType.INSTANCE.toJSON(writer, null, (String) sabloValue, NGUtils.TEXT_NO_PARSEHTML_DATAPROVIDER_CACHED_PD, clientConversion, dataConverterContext);
}
} else {
// other primitive types
writer.value(sabloValue);
}
} else {
writer.value(null);
}
return writer;
}
use of com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper in project servoy-client by Servoy.
the class MediaPropertyType method wrap.
@Override
public MediaWrapper wrap(Object value, MediaWrapper previousValue, PropertyDescription propertyDescription, IWrappingContext dataConverterContext) {
if (previousValue != null && Utils.equalObjects(value, previousValue.mediaUrl)) {
return previousValue;
}
IServoyDataConverterContext servoyDataConverterContext = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext();
FlattenedSolution flattenedSolution = servoyDataConverterContext.getSolution();
INGApplication application = servoyDataConverterContext.getApplication();
String url = getMediaUrl(value, flattenedSolution, application);
if (url != null)
return new MediaWrapper(value, url);
if (value != null && !Utils.equalObjects(value, Integer.valueOf(0)))
Debug.log("cannot convert media " + value + " using converter context " + servoyDataConverterContext);
return null;
}
Aggregations