package org.jibeframework.core.ui.wrapper;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.jibeframework.core.Context;
@JsonSerialize(using = IconWrapper.Serializer.class)
public class IconWrapper extends Wrapper {
private String value;
public IconWrapper(String scope, String modelScope, Object value) {
super(scope, modelScope);
this.value = StringUtils.substringAfter((String) value, "icon::");
}
protected Object getValue() {
Context context = Context.getCurrentContext();
return context.getServletRequest().getContextPath() + "/images/" + value;
}
public static class Serializer extends JsonSerializer<IconWrapper> {
@Override
public void serialize(IconWrapper wrapper, JsonGenerator jgen, SerializerProvider provider) throws IOException,
JsonProcessingException {
jgen.writeObject(wrapper.getValue());
}
}
}