StrutsXmlConfigurationProviderpublic class StrutsXmlConfigurationProvider extends com.opensymphony.xwork2.config.providers.XmlConfigurationProvider Override Xwork class so we can use an arbitrary config file |
Fields Summary |
---|
private static final Log | LOG | private File | baseDir | private String | filename | private String | reloadKey | private ServletContext | servletContext |
Constructors Summary |
---|
public StrutsXmlConfigurationProvider(boolean errorIfMissing)Constructs the configuration provider
this("struts.xml", errorIfMissing, null);
| public StrutsXmlConfigurationProvider(String filename, boolean errorIfMissing, ServletContext ctx)Constructs the configuration provider
super(filename, errorIfMissing);
this.servletContext = ctx;
this.filename = filename;
reloadKey = "configurationReload-"+filename;
Map<String,String> dtdMappings = new HashMap<String,String>(getDtdMappings());
dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.0//EN", "struts-2.0.dtd");
setDtdMappings(dtdMappings);
File file = new File(filename);
if (file.getParent() != null) {
this.baseDir = file.getParentFile();
}
|
Methods Summary |
---|
protected java.net.URL | findInFileSystem(java.lang.String fileName)
URL url = null;
File file = new File(fileName);
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to load file " + file);
}
// Trying relative path to original file
if (!file.exists()) {
file = new File(baseDir, fileName);
}
if (file.exists()) {
try {
url = file.toURL();
} catch (MalformedURLException e) {
throw new IOException("Unable to convert "+file+" to a URL");
}
}
return url;
| protected java.util.Iterator | getConfigurationUrls(java.lang.String fileName)Look for the configuration file on the classpath and in the file system
URL url = null;
if (baseDir != null) {
url = findInFileSystem(fileName);
if (url == null) {
return super.getConfigurationUrls(fileName);
}
}
if (url != null) {
List<URL> list = new ArrayList<URL>();
list.add(url);
return list.iterator();
} else {
return super.getConfigurationUrls(fileName);
}
| public void | loadPackages()
ActionContext ctx = ActionContext.getContext();
ctx.put(reloadKey, Boolean.TRUE);
super.loadPackages();
| public boolean | needsReload()Overrides needs reload to ensure it is only checked once per request
ActionContext ctx = ActionContext.getContext();
return ctx.get(reloadKey) == null && super.needsReload();
| public void | register(com.opensymphony.xwork2.inject.ContainerBuilder containerBuilder, com.opensymphony.xwork2.util.location.LocatableProperties props)
if (servletContext != null && !containerBuilder.contains(ServletContext.class)) {
containerBuilder.factory(ServletContext.class, new Factory() {
public Object create(Context context) throws Exception {
return servletContext;
}
});
}
super.register(containerBuilder, props);
| public java.lang.String | toString()
return ("Struts XML configuration provider ("+filename+")");
|
|