All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mysema.commons.freemarker.FreeMarkerHelper Maven / Gradle / Ivy

There is a newer version: 0.2.4
Show newest version
/*
 * Copyright (c) 2009 Mysema Ltd.
 * All rights reserved.
 * 
 */
package com.mysema.commons.freemarker;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import freemarker.core.Environment;
import freemarker.ext.beans.BeanModel;
import freemarker.ext.servlet.HttpRequestHashModel;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateModelException;

/**
 * FreeMarkerHelper provides
 *
 * @author tiwe
 * @version $Id$
 */
public abstract class FreeMarkerHelper implements TemplateDirectiveModel{

    protected HttpServletRequest getRequest(Environment env) throws TemplateModelException{
        return ((HttpRequestHashModel)env.getDataModel().get("Request")).getRequest();
    }

    protected HttpServletResponse getResponse(Environment env) throws TemplateModelException{
        return ((HttpRequestHashModel)env.getDataModel().get("Request")).getResponse();
    }
    
    @SuppressWarnings("unchecked")
    protected Object getParam(Map params, String key){
        Object val = params.get(key);
        return val != null ? ((BeanModel)val).getWrappedObject() : null;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy