/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.nir.nmail.viewresolver;

import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 *
 * @author attila
 */
public class NmailViewResolver extends InternalResourceViewResolver {
    private String ajaxPrefix;
    private static final String ajax = ".ajax";
    private String pagePrefix;
    
    @Override
    protected AbstractUrlBasedView buildView(String viewName) throws Exception {
        
        if (viewName.endsWith(ajax)) {
            int index = viewName.lastIndexOf(ajax);
            viewName = viewName.substring(0,index);
            setPrefix(ajaxPrefix);
        }
        else {
            setPrefix(pagePrefix);
        }
        
        return super.buildView(viewName);
    }

    public String getAjaxPrefix() {
        return ajaxPrefix;
    }

    public void setAjaxPrefix(String ajaxPrefix) {
        this.ajaxPrefix = ajaxPrefix;
    }

    public String getPagePrefix() {
        return pagePrefix;
    }

    public void setPagePrefix(String pagePrefix) {
        this.pagePrefix = pagePrefix;
    }
    
    
}
