Package org.geoserver.rest.format

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

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

import org.restlet.data.MediaType;
import org.restlet.ext.freemarker.TemplateRepresentation;
import org.restlet.resource.Representation;

import freemarker.template.Configuration;

/**
* A read-only format which uses a Freemarker template for output.
* <p>
* This class is a thin wrapper around {@link TemplateRepresentation}.
* </p>
*
* @author David Winslow <dwinslow@openplans.org>
*/
public class FreemarkerFormat extends DataFormat {
    /**
     * the freemarker configuration.
     */
    private Configuration myConfig;
    /**
     * the name of the template to execute.
     */
    private String myTemplateFileName;

    /**
     * Set up a new FreemarkerFormat
     *
     * @param templateName the filename of the template to use
     * @param c a Class object to use for retrieving the template resource
     * @param type the MediaType of the result
     */
    public FreemarkerFormat(String templateName, Class c, MediaType type){
        super(type);
        myTemplateFileName = templateName;
        myConfig = new Configuration();
        myConfig.setClassForTemplateLoading(c, "");
    }

    @Override
    public Object toObject(Representation representation) {
        throw new UnsupportedOperationException();
    }
   
    @Override
    public Representation toRepresentation(Object object) {
        return new TemplateRepresentation(myTemplateFileName, myConfig, object, mediaType);
    }

}
TOP

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

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.