org.qi4j.library.struts2.codebehind
Class Qi4jCodebehindPackageProvider

java.lang.Object
  extended by org.qi4j.library.struts2.codebehind.Qi4jCodebehindPackageProvider
All Implemented Interfaces:
com.opensymphony.xwork2.config.PackageProvider

public class Qi4jCodebehindPackageProvider
extends Object
implements com.opensymphony.xwork2.config.PackageProvider

This is inspired by the ClasspathPackageProvider from the struts2-codebehind-plugin. Most of the code is directly copied from the 2.1.1 version of the plugin but modified to only look for the @Action annotation and to accept interfaces as well as classes.


Nested Class Summary
static class Qi4jCodebehindPackageProvider.ClasspathPageLocator
          ClasspathPathLocator searches the classpath for server pages.
static interface Qi4jCodebehindPackageProvider.PageLocator
          PageLocator defines a locate method that can be used to discover server pages.
 
Field Summary
protected static String DEFAULT_PAGE_EXTENSION
          The default page extension, to use in place of ".jsp".
protected static String DEFAULT_PAGE_PREFIX
          The default page prefix (or "path").
protected static String DEFAULT_PARENT_PACKAGE
          A setting to indicate a custom default parent package, to use in place of "struts-default".
protected static String FORCE_LOWER_CASE
          The default page prefix (or "path").
 
Constructor Summary
Qi4jCodebehindPackageProvider()
           
 
Method Summary
protected  String getClassSuffix()
           
 void init(com.opensymphony.xwork2.config.Configuration configuration)
           
static boolean isNotEmpty(String text)
           
protected  com.opensymphony.xwork2.config.entities.PackageConfig.Builder loadPackageConfig(String actionNamespace, String actionPackage, Class actionClass)
          Finds or creates the package configuration for an Action class.
 void loadPackages()
          Clears and loads the list of packages registered at construction.
protected  void loadPackages(String[] pkgs)
           
 boolean needsReload()
           
protected  void processActionClass(Class<?> cls, String[] pkgs)
          Create a default action mapping for a class instance.
 void setActionConfiguration(ActionConfiguration actionConfiguration)
           
 void setActionPackages(String packages)
           
 void setDefaultPageExtension(String defaultPageExtension)
          Register a default page extension to use when locating pages.
 void setDefaultPagePrefix(String defaultPagePrefix)
          Reigster a default page prefix to use when locating pages.
 void setDefaultParentPackage(String defaultParentPackage)
          Register a default parent package for the actions.
 void setForceLowerCase(String force)
          Whether to use a lowercase letter as the initial letter of an action.
 void setPageLocator(Qi4jCodebehindPackageProvider.PageLocator locator)
          Register a PageLocation to use to scan for server pages.
 void setServletContext(javax.servlet.ServletContext ctx)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_PREFIX

protected static final String DEFAULT_PAGE_PREFIX
The default page prefix (or "path"). Some applications may place pages under "/WEB-INF" as an extreme security precaution.

See Also:
Constant Field Values

DEFAULT_PAGE_EXTENSION

protected static final String DEFAULT_PAGE_EXTENSION
The default page extension, to use in place of ".jsp".

See Also:
Constant Field Values

DEFAULT_PARENT_PACKAGE

protected static final String DEFAULT_PARENT_PACKAGE
A setting to indicate a custom default parent package, to use in place of "struts-default".

See Also:
Constant Field Values

FORCE_LOWER_CASE

protected static final String FORCE_LOWER_CASE
The default page prefix (or "path"). Some applications may place pages under "/WEB-INF" as an extreme security precaution.

See Also:
Constant Field Values
Constructor Detail

Qi4jCodebehindPackageProvider

public Qi4jCodebehindPackageProvider()
Method Detail

setActionPackages

public void setActionPackages(String packages)

setServletContext

public void setServletContext(javax.servlet.ServletContext ctx)

setActionConfiguration

public void setActionConfiguration(ActionConfiguration actionConfiguration)

setDefaultParentPackage

public void setDefaultParentPackage(String defaultParentPackage)
Register a default parent package for the actions.

Parameters:
defaultParentPackage - the new defaultParentPackage

setDefaultPageExtension

public void setDefaultPageExtension(String defaultPageExtension)
Register a default page extension to use when locating pages.

Parameters:
defaultPageExtension - the new defaultPageExtension

setDefaultPagePrefix

public void setDefaultPagePrefix(String defaultPagePrefix)
Reigster a default page prefix to use when locating pages.

Parameters:
defaultPagePrefix - the defaultPagePrefix to set

setForceLowerCase

public void setForceLowerCase(String force)
Whether to use a lowercase letter as the initial letter of an action.

Parameters:
force - If false, actions will retain the initial uppercase letter from the Action class. (view.action (true) versus View.action (false)).

setPageLocator

public void setPageLocator(Qi4jCodebehindPackageProvider.PageLocator locator)
Register a PageLocation to use to scan for server pages.

Parameters:
locator -

init

public void init(com.opensymphony.xwork2.config.Configuration configuration)
          throws com.opensymphony.xwork2.config.ConfigurationException
Specified by:
init in interface com.opensymphony.xwork2.config.PackageProvider
Throws:
com.opensymphony.xwork2.config.ConfigurationException

needsReload

public boolean needsReload()
Specified by:
needsReload in interface com.opensymphony.xwork2.config.PackageProvider

loadPackages

public void loadPackages()
                  throws com.opensymphony.xwork2.config.ConfigurationException
Clears and loads the list of packages registered at construction.

Specified by:
loadPackages in interface com.opensymphony.xwork2.config.PackageProvider
Throws:
com.opensymphony.xwork2.config.ConfigurationException

loadPackages

protected void loadPackages(String[] pkgs)
                     throws com.opensymphony.xwork2.config.ConfigurationException
Throws:
com.opensymphony.xwork2.config.ConfigurationException

processActionClass

protected void processActionClass(Class<?> cls,
                                  String[] pkgs)
Create a default action mapping for a class instance. The namespace annotation is honored, if found, otherwise the Java package is converted into the namespace by changing the dots (".") to slashes ("/").

Parameters:
cls - Action or POJO instance to process
pkgs - List of packages that were scanned for Actions

getClassSuffix

protected String getClassSuffix()

loadPackageConfig

protected com.opensymphony.xwork2.config.entities.PackageConfig.Builder loadPackageConfig(String actionNamespace,
                                                                                          String actionPackage,
                                                                                          Class actionClass)
Finds or creates the package configuration for an Action class. The namespace annotation is honored, if found, and the namespace is checked for a parent configuration.

Parameters:
actionNamespace - The configuration namespace
actionPackage - The Java package containing our Action classes
actionClass - The Action class instance
Returns:
PackageConfig object for the Action class

isNotEmpty

public static final boolean isNotEmpty(String text)