Package br.com.caelum.restfulie.opensearch.conveter

Source Code of br.com.caelum.restfulie.opensearch.conveter.DefaultTagsConveter

package br.com.caelum.restfulie.opensearch.conveter;

import br.com.caelum.restfulie.opensearch.Tags;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class DefaultTagsConveter implements Converter {

  @SuppressWarnings("rawtypes")
  public boolean canConvert(Class clazz) {
    return clazz.equals(Tags.class);
  }

  public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
  }

  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
   
    Tags tags = new Tags();
    String values = reader.getValue();
   
    if(values.equals("")) {
      return tags;
    }
   
    for (String value : values.trim().split("\\s+")) {
      tags.add(value);
    }
    return tags;
  }

}
TOP

Related Classes of br.com.caelum.restfulie.opensearch.conveter.DefaultTagsConveter

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.