public Object getProperty(Map context, Object target, Object name) throws OgnlException { MessageSource messageSource = (MessageSource) target; ExternalContext externalContext; Object root = Ognl.getRoot(context); if (root instanceof RequestContext) { externalContext = ((RequestContext) root).getExternalContext(); } else { externalContext = ExternalContextHolder.getExternalContext(); } if (externalContext != null) { return messageSource.getMessage(name.toString(), null, null, externalContext.getLocale()); } else { return messageSource.getMessage(name.toString(), null, null, null); } }
public Class classForName(String className, Map context) throws ClassNotFoundException { Object root = Ognl.getRoot(context); try { if (root instanceof CompoundRoot) { if (className.startsWith("vs")) { CompoundRoot compoundRoot = (CompoundRoot) root; if ("vs".equals(className)) { return compoundRoot.peek().getClass(); } int index = Integer.parseInt(className.substring(2)); return compoundRoot.get(index - 1).getClass(); } } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Got exception when tried to get class for name [#0]", e, className); } } return Thread.currentThread().getContextClassLoader().loadClass(className); }
/** * Sets the object's properties using the default type converter. * * @param props the properties being set * @param o the object * @param context the action context * @param throwPropertyExceptions boolean which tells whether it should throw exceptions for * problems setting the properties */ public void setProperties(Map<String, ?> props, Object o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException{ if (props == null) { return; } Ognl.setTypeConverter(context, getTypeConverterFromContext(context)); Object oldRoot = Ognl.getRoot(context); Ognl.setRoot(context, o); for (Map.Entry<String, ?> entry : props.entrySet()) { String expression = entry.getKey(); internalSetProperty(expression, entry.getValue(), o, context, throwPropertyExceptions); } Ognl.setRoot(context, oldRoot); }
/** * Sets the named property to the supplied value on the Object. * * @param name the name of the property to be set * @param value the value to set into the named property * @param o the object upon which to set the property * @param context the context which may include the TypeConverter * @param throwPropertyExceptions boolean which tells whether it should throw exceptions for * problems setting the property */ public void setProperty(String name, Object value, Object o, Map<String, Object> context, boolean throwPropertyExceptions) { Ognl.setTypeConverter(context, getTypeConverterFromContext(context)); Object oldRoot = Ognl.getRoot(context); Ognl.setRoot(context, o); internalSetProperty(name, value, o, context, throwPropertyExceptions); Ognl.setRoot(context, oldRoot); }