com.github.jknack.handlebars.springmvc.HandlebarsViewResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of handlebars-springmvc Show documentation
Show all versions of handlebars-springmvc Show documentation
Spring MVC Integration for Handlebars.java
/**
* Copyright (c) 2012 Edgar Espina
* This file is part of Handlebars.java.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jknack.handlebars.springmvc;
import static org.apache.commons.lang3.Validate.notEmpty;
import static org.apache.commons.lang3.Validate.notNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
import org.springframework.web.servlet.view.AbstractUrlBasedView;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.TemplateLoader;
import com.github.jknack.handlebars.ValueResolver;
/**
* A Handlebars {@link ViewResolver view resolver}.
*
* @author edgar.espina
* @since 0.1
*/
public class HandlebarsViewResolver extends AbstractTemplateViewResolver
implements InitializingBean {
/**
* The default content type.
*/
public static final String DEFAULT_CONTENT_TYPE = "text/html;charset=UTF-8";
/**
* The handlebars object.
*/
private Handlebars handlebars;
/**
* The value's resolvers.
*/
private ValueResolver[] valueResolvers = ValueResolver.VALUE_RESOLVERS;
/**
* Fail on missing file. Default is: true.
*/
private boolean failOnMissingFile = true;
/**
* The helper registry.
*/
private Map> helpers = new HashMap>();
/**
* The helper source list.
*/
private List