public static String translateOgnl(String message, Map<Object, Object> args) { OgnlValueStack stack = new OgnlValueStack(); stack.push(args); return TextParseUtil.translateVariables(message, stack); }
/** * @see com.opensymphony.xwork2.util.ValueStack#setValue(java.lang.String, java.lang.Object, boolean) */ public void setValue(String expr, Object value, boolean throwExceptionOnFailure) { Map<String, Object> context = getContext(); try { trySetValue(expr, value, throwExceptionOnFailure, context); } catch (OgnlException e) { handleOgnlException(expr, value, throwExceptionOnFailure, e); } catch (RuntimeException re) { //XW-281 handleRuntimeException(expr, value, throwExceptionOnFailure, re); } finally { cleanUpContext(context); } }
private Object tryFindValue(String expr) throws OgnlException { Object value; expr = lookupForOverrides(expr); if (defaultType != null) { value = findValue(expr, defaultType); } else { value = getValueUsingOgnl(expr); if (value == null) { value = findInContext(expr); } } return value; }
/** * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String) */ public Object findValue(String expr, boolean throwExceptionOnFailure) { try { setupExceptionOnFailure(throwExceptionOnFailure); return tryFindValueWhenExpressionIsNotNull(expr); } catch (OgnlException e) { return handleOgnlException(expr, throwExceptionOnFailure, e); } catch (Exception e) { return handleOtherException(expr, throwExceptionOnFailure, e); } finally { ReflectionContextState.clear(context); } }
private Map retrieveSetMap() { Map setMap; Object topObj = peek(); if (shouldUseOldMap(topObj)) { setMap = (Map) topObj; } else { setMap = new HashMap(); setMap.put(MAP_IDENTIFIER_KEY, ""); push(setMap); } return setMap; }
private Object tryFindValue(String expr, Class asType) throws OgnlException { Object value = null; try { expr = lookupForOverrides(expr); value = getValue(expr, asType); if (value == null) { value = findInContext(expr); return converter.convertValue(getContext(), value, asType); } } finally { context.remove(THROW_EXCEPTION_ON_FAILURE); } return value; }
private Object readResolve() { // TODO: this should be done better ActionContext ac = ActionContext.getContext(); Container cont = ac.getContainer(); XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class); CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName()); TextProvider prov = cont.getInstance(TextProvider.class, "system"); boolean allow = "true".equals(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS)); OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allow); aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class)); aStack.setRoot(xworkConverter, accessor, this.root, allow); return aStack; }
public ValueStack createValueStack() { ValueStack stack = new OgnlValueStack(xworkConverter, compoundRootAccessor, textProvider, allowStaticMethodAccess); container.inject(stack); stack.getContext().put(ActionContext.CONTAINER, container); return stack; }
private Object handleOtherException(String expr, boolean throwExceptionOnFailure, Exception e) { logLookupFailure(expr, e); if (throwExceptionOnFailure) throw new XWorkException(e); return findInContext(expr); }
private Object handleOgnlException(String expr, boolean throwExceptionOnFailure, OgnlException e) { Object ret = findInContext(expr); if (ret == null) { if (shouldLogMissingPropertyWarning(e)) { LOG.warn("Could not find property [#0]!", e, expr); } if (throwExceptionOnFailure) { throw new XWorkException(e); } } return ret; }
/** * @see com.opensymphony.xwork2.util.ValueStack#findString(java.lang.String) */ public String findString(String expr) { return (String) findValue(expr, String.class); }
@Override public Locale resolveLocale(HttpServletRequest request) { Locale result = null; OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack(); for (Object o : stack.getRoot()) { if (o instanceof LocaleProvider) { LocaleProvider lp = (LocaleProvider) o; result = lp.getLocale(); break; } } // Falling back to the request locale if (result == null) { result = request.getLocale(); } return result; } }
private Object findInContext(String name) { return getContext().get(name); }
/** * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String, java.lang.Class) */ public Object findValue(String expr, Class asType, boolean throwExceptionOnFailure) { try { setupExceptionOnFailure(throwExceptionOnFailure); return tryFindValueWhenExpressionIsNotNull(expr, asType); } catch (OgnlException e) { final Object value = handleOgnlException(expr, throwExceptionOnFailure, e); return converter.convertValue(getContext(), value, asType); } catch (Exception e) { final Object value = handleOtherException(expr, throwExceptionOnFailure, e); return converter.convertValue(getContext(), value, asType); } finally { ReflectionContextState.clear(context); } }
public ValueStack createValueStack(ValueStack stack) { ValueStack result = new OgnlValueStack(stack, xworkConverter, compoundRootAccessor, allowStaticMethodAccess); container.inject(result); stack.getContext().put(ActionContext.CONTAINER, container); return result; }
public Object findValue(String expr) { return findValue(expr, false); }
@Override public String getResource(String messageKey, String defaultValue, Object... params) { String message = null; PageContext pageContext = null; // I'm so ashamed about that... pageContext = (PageContext) params[0]; // Both title and titleKey attributes are not used if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } // the titleKey attribute is used else { OgnlValueStack stack = (OgnlValueStack) TagUtils.getStack(pageContext); for (Object o : stack.getRoot()) { if (o instanceof TextProvider) { TextProvider tp = (TextProvider) o; message = tp.getText(messageKey, UNDEFINED_KEY + messageKey + UNDEFINED_KEY); break; } } } return message; } }
public String findString(String expr, boolean throwExceptionOnFailure) { return (String) findValue(expr, String.class, throwExceptionOnFailure); }
public Object findValue(String expr, Class asType) { return findValue(expr, asType, false); }