/** * Converted object from variable translation. * * @param open * @param expression * @param stack * @param asType * @return Converted object from variable translation. */ public static Object translateVariables(char open, String expression, ValueStack stack, Class asType) { return translateVariables(open, expression, stack, asType, null); }
/** * Parse <code>expression</code> passed in against value stack. * * @param expression an OGNL expression * @param type type to return * @return Object */ protected Object parse(String expression, Class type) { if (expression == null) { return null; } return TextParseUtil.translateVariables('$', expression, stack, type); }
/** * Converted object from variable translation. * * @param open * @param expression * @param stack * @param asType * @param evaluator * @return Converted object from variable translation. */ public static Object translateVariables(char open, String expression, ValueStack stack, Class asType, ParsedValueEvaluator evaluator) { return translateVariables(new char[]{open} , expression, stack, asType, evaluator, MAX_RECURSION); }
/** * Converted object from variable translation. * * @param open * @param expression * @param stack * @param asType * @param evaluator * @return Converted object from variable translation. */ public static Object translateVariables(char open, String expression, ValueStack stack, Class asType, ParsedValueEvaluator evaluator, int maxLoopCount) { return translateVariables(new char[]{open}, expression, stack, asType, evaluator, maxLoopCount); }
/** * Converted object from variable translation. * * @param open * @param expression * @param stack * @param asType * @param evaluator * @return Converted object from variable translation. */ public static Object translateVariables(char[] openChars, String expression, ValueStack stack, Class asType, ParsedValueEvaluator evaluator) { return translateVariables(openChars, expression, stack, asType, evaluator, MAX_RECURSION); }
/** * Converts all instances of ${...}, and %{...} in <code>expression</code> to the value returned * by a call to {@link ValueStack#findValue(java.lang.String)}. If an item cannot * be found on the stack (null is returned), then the entire variable ${...} is not * displayed, just as if the item was on the stack but returned an empty string. * * @param expression an expression that hasn't yet been translated * @return the parsed expression */ public static String translateVariables(String expression, ValueStack stack) { return translateVariables(new char[]{'$', '%'}, expression, stack, String.class, null).toString(); }
/** * Converts all instances of ${...} in <code>expression</code> to the value returned * by a call to {@link ValueStack#findValue(java.lang.String)}. If an item cannot * be found on the stack (null is returned), then the entire variable ${...} is not * displayed, just as if the item was on the stack but returned an empty string. * * @param open * @param expression * @param stack * @return Translated variable String */ public static String translateVariables(char open, String expression, ValueStack stack) { return translateVariables(open, expression, stack, String.class, null).toString(); }
/** * Function similarly as {@link #translateVariables(char, String, ValueStack)} * except for the introduction of an additional <code>evaluator</code> that allows * the parsed value to be evaluated by the <code>evaluator</code>. The <code>evaluator</code> * could be null, if it is it will just be skipped as if it is just calling * {@link #translateVariables(char, String, ValueStack)}. * * <p/> * * A typical use-case would be when we need to URL Encode the parsed value. To do so * we could just supply a URLEncodingEvaluator for example. * * @param expression * @param stack * @param evaluator The parsed Value evaluator (could be null). * @return the parsed (and possibly evaluated) variable String. */ public static String translateVariables(String expression, ValueStack stack, ParsedValueEvaluator evaluator) { return translateVariables(new char[]{'$', '%'}, expression, stack, String.class, evaluator).toString(); }
private boolean isInChainHistory(String namespace, String actionName, String methodName) { LinkedList<? extends String> chainHistory = ActionChainResult.getChainHistory(); if (chainHistory == null) { return false; } else { // Actions to skip Set<String> skipActionsList = new HashSet<String>(); if (skipActions != null && skipActions.length() > 0) { ValueStack stack = ActionContext.getContext().getValueStack(); String finalSkipActions = TextParseUtil.translateVariables(this.skipActions, stack); skipActionsList.addAll(TextParseUtil.commaDelimitedStringToSet(finalSkipActions)); } if (!skipActionsList.contains(actionName)) { // Get if key is in the chain history return chainHistory.contains(makeKey(namespace, actionName, methodName)); } return false; } }
private Object findValue(String expr, Class toType) { ValueStack stack = context.getStack(); if (altSyntax && toType == String.class) { return TextParseUtil.translateVariables('%', expr, stack); } else { return stack.findValue(ComponentUtils.stripExpressionIfAltSyntax(stack, expr), toType); } } }
@Override protected void doExecute(String finalLocation,ActionInvocation invocation) throws Exception { HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE); HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(HTTP_REQUEST); String resultCodeAsLocation = invocation.getResultCode(); if(resultCodeAsLocation == null) { return; } //proecss with ONGL expression resultCodeAsLocation = TextParseUtil.translateVariables(resultCodeAsLocation,invocation.getStack()); if(resultCodeAsLocation.startsWith("!")) { doRedirect(invocation,request, response, resultCodeAsLocation.substring(1)); return; } if(resultCodeAsLocation.startsWith(REDIRECT_PREFIX)) { doRedirect(invocation,request, response, resultCodeAsLocation.substring(REDIRECT_PREFIX.length())); return; } if(resultCodeAsLocation.startsWith(FORWARD_PREFIX)) { doDispatcher(response, request, resultCodeAsLocation.substring(FORWARD_PREFIX.length())); return; } doDispatcher(response, request, resultCodeAsLocation); }
/** * Evaluates the OGNL stack to find an Object of the given type. Will * evaluate <code>expr</code> the portion wrapped with altSyntax (%{...}) * against stack when altSyntax is on, else the whole <code>expr</code> is * evaluated against the stack. * <p/> * This method only supports the altSyntax. So this should be set to true. * * @param expr * OGNL expression. * @param toType * the type expected to find. * @return the Object found, or <tt>null</tt> if not found. */ protected Object findValue(String expr, Class<?> toType) { if (altSyntax() && toType == String.class) { return TextParseUtil.translateVariables('%', expr, stack); } else { expr = stripExpressionIfAltSyntax(expr); return stack.findValue(expr, toType, false); } }
String resultStr = translateVariables(expression, stack, evaluator); if (shallBeIncluded(resultStr, excludeEmptyElements)) { resultCol.add(resultStr);
/** * Gets the default message. */ private static GetDefaultMessageReturnArg getDefaultMessage(String key, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) { GetDefaultMessageReturnArg result = null; boolean found = true; if (key != null) { String message = findDefaultText(key, locale); if (message == null) { message = defaultMessage; found = false; // not found in bundles } // defaultMessage may be null if (message != null) { MessageFormat mf = buildMessageFormat(TextParseUtil.translateVariables(message, valueStack), locale); String msg = formatWithNullDetection(mf, args); result = new GetDefaultMessageReturnArg(msg, found); } } return result; }
message = TextParseUtil.translateVariables(message, stack);
/** * Gets the message from the named resource bundle. */ private static String getMessage(String bundleName, Locale locale, String key, ValueStack valueStack, Object[] args) { ResourceBundle bundle = findResourceBundle(bundleName, locale); if (bundle == null) { return null; } reloadBundles(valueStack.getContext()); try { String message = TextParseUtil.translateVariables(bundle.getString(key), valueStack); MessageFormat mf = buildMessageFormat(message, locale); return formatWithNullDetection(mf, args); } catch (MissingResourceException e) { if (devMode) { LOG.warn("Missing key [#0] in bundle [#1]!", key, bundleName); } else if (LOG.isDebugEnabled()) { LOG.debug("Missing key [#0] in bundle [#1]!", key, bundleName); } return null; } }
ValueStack stack = ActionContext.getContext().getValueStack(); String finalNamespace = this.namespace != null ? TextParseUtil.translateVariables(namespace, stack) : invocation.getProxy().getNamespace(); String finalActionName = TextParseUtil.translateVariables(actionName, stack); String finalMethodName = this.methodName != null ? TextParseUtil.translateVariables(this.methodName, stack) : null;
Object val = entry.getValue(); if (parse && val instanceof String) { val = TextParseUtil.translateVariables(val.toString(), stack);
reloadBundles(valueStack.getContext()); String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack); MessageFormat mf = buildMessageFormat(message, locale);