Search in sources :

Example 1 with MediaWrapper

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;
}
Also used : MediaWrapper(com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper) Date(java.util.Date)

Example 2 with MediaWrapper

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;
}
Also used : MediaWrapper(com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IServoyDataConverterContext(com.servoy.j2db.server.ngclient.IServoyDataConverterContext)

Aggregations

MediaWrapper (com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)1 IServoyDataConverterContext (com.servoy.j2db.server.ngclient.IServoyDataConverterContext)1 Date (java.util.Date)1