Package org.jibeframework.core.ui.wrapper

Source Code of org.jibeframework.core.ui.wrapper.IconWrapper

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());

    }
  }

}
TOP

Related Classes of org.jibeframework.core.ui.wrapper.IconWrapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.