use of javax.el.ImportHandler in project tomcat by apache.
the class ScopedAttributeELResolver method getValue.
@Override
public Object getValue(ELContext context, Object base, Object property) {
Objects.requireNonNull(context);
Object result = null;
if (base == null) {
context.setPropertyResolved(base, property);
if (property != null) {
String key = property.toString();
PageContext page = (PageContext) context.getContext(JspContext.class);
result = page.findAttribute(key);
if (result == null) {
boolean resolveClass = true;
// Performance short-cut available when running on Tomcat
if (AST_IDENTIFIER_KEY != null) {
// Tomcat will set this key to Boolean.TRUE if the
// identifier is a stand-alone identifier (i.e.
// identifier) rather than part of an AstValue (i.e.
// identifier.something). Imports do not need to be
// checked if this is a stand-alone identifier
Boolean value = (Boolean) context.getContext(AST_IDENTIFIER_KEY);
if (value != null && value.booleanValue()) {
resolveClass = false;
}
}
// This might be the name of an imported class
ImportHandler importHandler = context.getImportHandler();
if (importHandler != null) {
Class<?> clazz = null;
if (resolveClass) {
clazz = importHandler.resolveClass(key);
}
if (clazz != null) {
result = new ELClass(clazz);
}
if (result == null) {
// This might be the name of an imported static field
clazz = importHandler.resolveStatic(key);
if (clazz != null) {
try {
result = clazz.getField(key).get(null);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
// Most (all?) of these should have been
// prevented by the checks when the import
// was defined.
}
}
}
}
}
}
}
return result;
}
use of javax.el.ImportHandler in project wildfly by wildfly.
the class ImportedClassELResolver method getValue.
@Override
public Object getValue(final ELContext context, final Object base, final Object property) {
if (base != null) {
return null;
}
if (!(property instanceof String)) {
return null;
}
final ImportHandler importHandler = context.getImportHandler();
if (importHandler == null) {
return null;
}
final String klassName = (String) property;
Object cacheResult = cache.get(klassName);
if (cacheResult != null) {
if (cacheResult == NULL_MARKER) {
return null;
} else {
context.setPropertyResolved(true);
return new ELClass((Class) cacheResult);
}
}
final Class<?> klass;
if (WildFlySecurityManager.isChecking()) {
klass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
@Override
public Class<?> run() {
return importHandler.resolveClass(klassName);
}
});
} else {
klass = importHandler.resolveClass(klassName);
}
if (klass != null) {
cache.put(klassName, klass);
context.setPropertyResolved(true);
return new ELClass(klass);
} else {
cache.put(klassName, NULL_MARKER);
}
return null;
}
Aggregations