Package org.geoserver.rest.format

Source Code of org.geoserver.rest.format.StringFormat

/* Copyright (c) 2001 - 2008 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.rest.format;

import java.io.IOException;

import org.restlet.data.MediaType;
import org.restlet.resource.Representation;
import org.restlet.resource.StringRepresentation;

/**
* Simple format which takes and returns a string.
*
* @author Justin Deoliveira, OpenGEO
*/
public class StringFormat extends DataFormat {

    public StringFormat(MediaType mediaType) {
        super(mediaType);
    }
   
    @Override
    public Representation toRepresentation(Object object) {
        return new StringRepresentation( object.toString(), mediaType );
    }
   
    @Override
    public Object toObject(Representation representation) {
        try {
            return representation.getText();
        } catch (IOException e) {
            throw new RuntimeException( e );
        }
    }

}
TOP

Related Classes of org.geoserver.rest.format.StringFormat

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.