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

org.skyway.spring.util.viewresolution.AbsolutePathViewResolver Maven / Gradle / Ivy

The newest version!
/**
* Copyright 2007 - 2011 Skyway Software, Inc.
*/
package org.skyway.spring.util.viewresolution;

import java.util.Locale;

import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

/**
 * This View Resolver will only handle view names that contain the string WEB-INF.  This is to 
 * be backward compatible with controllers generated before 8.6 as they did not generate logical 
 * view names but absolute view names.
 *
 * It is assumed that this resolver will be configured without a suffix or prefix and will be
 * checked before all other resolvers.
 * 
 * @author CConway
 *
 */
public class AbsolutePathViewResolver extends UrlBasedViewResolver {
	private static final String WEB_INF_VIEW_PATH = "WEB-INF";
	
	/**
	 * Handle if the view name contains WEB-INF.  Otherwise let some other resolver
	 * handle it.
	 */
	public View resolveViewName(String viewName, Locale locale) throws Exception {
		if (viewName.toUpperCase().contains(WEB_INF_VIEW_PATH) || isIndexHtml(viewName)){
			return super.resolveViewName(viewName, locale);
		}
		
		return null;		
	}
	
	/**
	 * In controllers generated before 8.6, when a user tries to save they are redirected
	 * to this url: index{Data type name}.html.  This is a special test for that circumstance
	 * because it is not a view preceded by WEB-INF.
	 * 
	 * @param viewName
	 * @return
	 */
	protected boolean isIndexHtml(String viewName){
		return viewName.startsWith("index") && viewName.endsWith(".html") && viewName.length() > 10;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy