com.opensymphony.module.sitemesh.mapper
public final class: EnvEntryDecoratorMapper [javadoc |
source]
java.lang.Object
com.opensymphony.module.sitemesh.mapper.AbstractDecoratorMapper
com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper
com.opensymphony.module.sitemesh.mapper.EnvEntryDecoratorMapper
All Implemented Interfaces:
DecoratorMapper
The EnvEntryDecoratorMapper allows the reference to a web-app environment entry for the
decorator name, and falls back to ConfigDecoratorMapper's behavior if no matching
environment entry is found.
In some cases, it's desirable to allow a deployer, as opposed to a developer,
to specify a decorator. In a .WAR file, this can be very difficult, since
decorator mappings are specified in decorators.xml (more or less).
This mapper corrects that by allowing two types of mapping. If the decorator
name is found in an <env-entry>, the entry's value is used
as the decorator reference.
Known Issues:
- It still uses the decorator path (from
decorators.xml). This
needs to be corrected for full functionality. If anyone has a suggestion
on how...
| Method from com.opensymphony.module.sitemesh.mapper.EnvEntryDecoratorMapper Detail: |
public Decorator getNamedDecorator(HttpServletRequest request,
String name) {
String resourceValue = getStringResource(name);
if (resourceValue == null) {
return super.getNamedDecorator(request, name);
}
else {
return new DefaultDecorator(name, resourceValue, null);
}
}
|
public static String getStringResource(String name) {
String value = null;
Context ctx = null;
try {
ctx = new InitialContext();
Object o = ctx.lookup("java:comp/env/" + name);
if (o != null) {
value = o.toString();
}
}
catch (NamingException ne) {
}
finally {
try {
if (ctx != null) ctx.close();
}
catch (NamingException ne) {
}
}
return value;
}
This pulls a value out of the web-app environment.
If the value isn't there, returns null. |