Polishing

This commit is contained in:
Juergen Hoeller
2014-08-12 22:24:50 +02:00
parent 3038f03fee
commit 0c89279d61
10 changed files with 100 additions and 85 deletions

View File

@@ -26,25 +26,24 @@ import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
/**
* Simple implementation of ViewResolver that interprets a view name
* as bean name in the current application context, i.e. in the XML
* file of the executing DispatcherServlet.
* A simple implementation of {@link org.springframework.web.servlet.ViewResolver}
* that interprets a view name as a bean name in the current application context,
* i.e. typically in the XML file of the executing {@code DispatcherServlet}.
*
* <p>This resolver can be handy for small applications, keeping all
* definitions ranging from controllers to views in the same place.
* For normal applications, XmlViewResolver will be the better choice, as
* it separates the XML view bean definitions into a dedicated views file.
* View beans should virtually never have references to any other
* application beans - such a separation will make this clear.
* <p>This resolver can be handy for small applications, keeping all definitions
* ranging from controllers to views in the same place. For larger applications,
* {@link XmlViewResolver} will be the better choice, as it separates the XML
* view bean definitions into a dedicated views file.
*
* <p>This ViewResolver does not support internationalization.
* Conside ResourceBundleViewResolver if you need to apply different
* view resources per locale.
* <p>Note: Neither this {@code ViewResolver} nor {@link XmlViewResolver} supports
* internationalization. Consider {@link ResourceBundleViewResolver} if you need
* to apply different view resources per locale.
*
* <p>Note: This ViewResolver implements the Ordered interface to allow for
* flexible participation in ViewResolver chaining. For example, some special
* views could be defined via this ViewResolver (giving it 0 as "order" value),
* while all remaining views could be resolved by a UrlBasedViewResolver.
* <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface
* in order to allow for flexible participation in {@code ViewResolver} chaining.
* For example, some special views could be defined via this {@code ViewResolver}
* (giving it 0 as "order" value), while all remaining views could be resolved by
* a {@link UrlBasedViewResolver}.
*
* @author Juergen Hoeller
* @since 18.06.2003
@@ -62,14 +61,14 @@ public class BeanNameViewResolver extends WebApplicationObjectSupport implements
}
public int getOrder() {
return order;
return this.order;
}
public View resolveViewName(String viewName, Locale locale) throws BeansException {
ApplicationContext context = getApplicationContext();
if (!context.containsBean(viewName)) {
// Allow for ViewResolver chaining.
// Allow for ViewResolver chaining...
return null;
}
return context.getBean(viewName, View.class);

View File

@@ -36,24 +36,22 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.View;
/**
* {@link org.springframework.web.servlet.ViewResolver} implementation
* that uses bean definitions in a {@link ResourceBundle}, specified by
* the bundle basename.
* A {@link org.springframework.web.servlet.ViewResolver} implementation that uses
* bean definitions in a {@link ResourceBundle}, specified by the bundle basename.
*
* <p>The bundle is typically defined in a properties file, located in
* the class path. The default bundle basename is "views".
* <p>The bundle is typically defined in a properties file, located in the classpath.
* The default bundle basename is "views".
*
* <p>This {@code ViewResolver} supports localized view definitions,
* using the default support of {@link java.util.PropertyResourceBundle}.
* For example, the basename "views" will be resolved as class path resources
* "views_de_AT.properties", "views_de.properties", "views.properties" -
* for a given Locale "de_AT".
* <p>This {@code ViewResolver} supports localized view definitions, using the
* default support of {@link java.util.PropertyResourceBundle}. For example, the
* basename "views" will be resolved as class path resources "views_de_AT.properties",
* "views_de.properties", "views.properties" - for a given Locale "de_AT".
*
* <p>Note: this {@code ViewResolver} implements the {@link Ordered}
* interface to allow for flexible participation in {@code ViewResolver}
* chaining. For example, some special views could be defined via this
* {@code ViewResolver} (giving it 0 as "order" value), while all
* remaining views could be resolved by a {@link UrlBasedViewResolver}.
* <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface
* in order to allow for flexible participation in {@code ViewResolver} chaining.
* For example, some special views could be defined via this {@code ViewResolver}
* (giving it 0 as "order" value), while all remaining views could be resolved by
* a {@link UrlBasedViewResolver}.
*
* @author Rod Johnson
* @author Juergen Hoeller
@@ -109,7 +107,7 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver
* @see java.util.ResourceBundle#getBundle(String)
*/
public void setBasename(String basename) {
setBasenames(new String[] {basename});
setBasenames(basename);
}
/**
@@ -172,7 +170,7 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver
* <p>Allows for pre-initialization of common Locales, eagerly checking
* the view configuration for those Locales.
*/
public void setLocalesToInitialize(Locale[] localesToInitialize) {
public void setLocalesToInitialize(Locale... localesToInitialize) {
this.localesToInitialize = localesToInitialize;
}
@@ -196,7 +194,7 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver
return factory.getBean(viewName, View.class);
}
catch (NoSuchBeanDefinitionException ex) {
// to allow for ViewResolver chaining
// Allow for ViewResolver chaining...
return null;
}
}

View File

@@ -32,18 +32,20 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.View;
/**
* Implementation of ViewResolver that uses bean definitions in an
* XML file, specified by resource location. The file will typically
* be located in the WEB-INF directory; default is "/WEB-INF/views.xml".
* A {@link org.springframework.web.servlet.ViewResolver} implementation that uses
* bean definitions in a dedicated XML file for view definitions, specified by
* resource location. The file will typically be located in the WEB-INF directory;
* the default is "/WEB-INF/views.xml".
*
* <p>This ViewResolver does not support internationalization.
* Consider ResourceBundleViewResolver if you need to apply
* different view resources per locale.
* <p>This {@code ViewResolver} does not support internationalization at the level
* of its definition resources. Consider {@link ResourceBundleViewResolver} if you
* need to apply different view resources per locale.
*
* <p>Note: This ViewResolver implements the Ordered interface to allow for
* flexible participation in ViewResolver chaining. For example, some special
* views could be defined via this ViewResolver (giving it 0 as "order" value),
* while all remaining views could be resolved by a UrlBasedViewResolver.
* <p>Note: This {@code ViewResolver} implements the {@link Ordered} interface
* in order to allow for flexible participation in {@code ViewResolver} chaining.
* For example, some special views could be defined via this {@code ViewResolver}
* (giving it 0 as "order" value), while all remaining views could be resolved by
* a {@link UrlBasedViewResolver}.
*
* @author Juergen Hoeller
* @since 18.06.2003
@@ -70,7 +72,7 @@ public class XmlViewResolver extends AbstractCachingViewResolver
}
public int getOrder() {
return order;
return this.order;
}
/**
@@ -109,7 +111,7 @@ public class XmlViewResolver extends AbstractCachingViewResolver
return factory.getBean(viewName, View.class);
}
catch (NoSuchBeanDefinitionException ex) {
// to allow for ViewResolver chaining
// Allow for ViewResolver chaining...
return null;
}
}