List of usage examples for org.apache.commons.el.parser ELParser ExpressionString
final public Object ExpressionString() throws ParseException
From source file:gov.nih.nci.cabig.caaers.utils.el.EL.java
public String evaluate(String input) { try {//from w ww .ja va 2 s. c om StringReader rdr = new StringReader(input); ELParser parser = new ELParser(rdr); Object result = parser.ExpressionString(); if (result instanceof String) { return (String) result; } else if (result instanceof Expression) { Expression expr = (Expression) result; result = expr.evaluate(this.resolver); return result == null ? null : result.toString(); } else if (result instanceof ExpressionString) { Expression expr = (Expression) result; result = expr.evaluate(this.resolver); return result == null ? null : result.toString(); } else if (result instanceof BinaryOperatorExpression) { BinaryOperatorExpression expr = (BinaryOperatorExpression) result; result = expr.evaluate(this.resolver, this.mapper, null); return result.toString(); } else if (result instanceof BooleanLiteral) { BooleanLiteral expr = (BooleanLiteral) result; result = expr.evaluate(this.resolver, this.mapper, null); return result.toString(); } else { System.out.println("Incorrect type returned; not String, Expression or ExpressionString"); return ""; } } catch (ParseException pe) { throw new RuntimeException("ParseException thrown: " + pe.getMessage(), pe); } catch (ELException ele) { throw new RuntimeException("ELException thrown: " + ele.getMessage(), ele); } }
From source file:com.cybernostics.jsp2thymeleaf.api.expressions.ExpressionWalker.java
public boolean walkExpressionString(String toWalk, ExpressionVisitor v) throws ParseException { ELParser eLParser = new ELParser(new StringReader(toWalk)); final Object expr = eLParser.ExpressionString(); if (expr instanceof String) { v.visitString((String) expr); return false; }/*from w w w . j a v a2 s . c o m*/ walkExpression(expr, v); return true; }
From source file:it.cilea.osd.jdyna.web.tag.ExpressionEvaluatorImpl.java
/** * /* ww w. j a v a2 s . co m*/ * Gets the parsed form of the given expression string. If the parsed form * is cached (and caching is not bypassed), return the cached form, * otherwise parse and cache the value. Returns either a String, Expression, * or ExpressionString. **/ public Object parseExpressionString(String pExpressionString) throws ELException { // See if it's an empty String if (pExpressionString.length() == 0) { return ""; } // See if it's in the cache Object ret = null; if (ret == null) { // Parse the expression Reader r = new StringReader(pExpressionString); ELParser parser = new ELParser(r); try { ret = parser.ExpressionString(); } catch (ParseException exc) { throw new ELException(exc); } catch (TokenMgrError exc) { // Note - this should never be reached, since the parser is // constructed to tokenize any input (illegal inputs get // parsed to <BADLY_ESCAPED_STRING_LITERAL> or // <ILLEGAL_CHARACTER> throw new ELException(exc.getMessage()); } } return ret; }
From source file:org.apache.myfaces.el.ELParserHelper.java
/** * Gets the parsed form of the given expression string. Returns either an * Expression or ExpressionString./* w ww. ja v a 2 s .c o m*/ */ public static Object parseExpression(String expressionString) { expressionString = toJspElExpression(expressionString); ELParser parser = new ELParser(new StringReader(expressionString)); try { Object expression = parser.ExpressionString(); if (!(expression instanceof Expression) && !(expression instanceof ExpressionString)) { throw new ReferenceSyntaxException("Invalid expression: '" + expressionString + "'. Parsed Expression of unexpected type " + expression.getClass().getName()); } replaceSuffixes(expression); return expression; } catch (ParseException e) { String msg = "Invalid expression: '" + expressionString + "'"; throw new ReferenceSyntaxException(msg, e); } }
From source file:org.seasar.s2jsfplugin.validater.S2JSFHTMLValidator.java
/** JSFJX^^Oof?[V?s?B */ private void validateJSFTaglib(String jsfTagName, FuzzyXMLElement element) throws CoreException { String mayaPrefix = Util.getMayaPrefix(element); if (mayaPrefix == null) { return;//from w w w .j a va 2 s. c om } // UIR|?[lgK?{??H // // K?{?`FbN // TLDInfo tld = project.getTLDInfo(S2JSFPlugin.HTML_URI); // TagInfo tag = tld.getTagInfo(jsfTagName); // if(tld!=null){ // AttributeInfo[] attrs = tag.getAttributeInfo(); // for(int i=0;i<attrs.length;i++){ // if(attrs[i].isRequired() && element.getAttributeNode(mayaPrefix + ":" + attrs[i].getAttributeName())==null){ // createMarker(file,element.getOffset(),element.getOffset()+element.getLength(), // widget.getLineAtOffset(element.getOffset()), // mayaPrefix + ":" + attrs[i].getAttributeName() + "?K?{?B"); // return; // } // } // } // ?l`FbN FuzzyXMLAttribute[] attrs = element.getAttributes(); for (int i = 0; i < attrs.length; i++) { String attrName = attrs[i].getName(); String attrValue = attrs[i].getValue(); if (attrName.indexOf(":") <= 0) { continue; } String[] attrDim = attrName.split(":"); if (!attrDim[0].equals(mayaPrefix)) { continue; } String type = JSFTagDefinition.getAttributeInfo(jsfTagName, attrDim[1]); if (type == null) { continue; } attrValue = processExpression(attrs[i], attrValue); if (attrValue == null) { continue; } if (type == JSFTagDefinition.VALUE) { type = JSFTagDefinition.PROPERTY; } // ELV^bNXG?[m String el = attrs[i].getValue(); el = el.replaceFirst("^#", "\\$"); try { ELParser parser = new ELParser(new StringReader(el)); parser.ExpressionString(); } catch (Exception ex) { createAttributeValueMarker(attrs[i], createMessage(ValidationMessages.INVALID_EL, attrValue)); continue; } // V^bNXG?[BeanL?q?? StringBuffer sb = new StringBuffer(); boolean errorFlag = true; for (int j = 0; j < attrValue.length(); j++) { char c = attrValue.charAt(j); if (Character.isJavaIdentifierPart(c) || c == '.') { sb.append(c); } else { errorFlag = validateBinding(element, attrs[i], sb.toString(), type); sb.setLength(0); if (errorFlag == false) { break; } if (c == '[') { errorFlag = false; break; } } } if (errorFlag == true && sb.length() > 0) { validateBinding(element, attrs[i], sb.toString(), type); } } }
From source file:org.seasar.teeda.core.el.impl.commons.CommonsELParser.java
public Object parse(final String expression) { String jspExpression = JspELParserUtil.convertToJspExpression(expression); ELParser parser = new ELParser(new StringReader(jspExpression)); try {/*from w w w .j a v a 2s . com*/ Object obj = parser.ExpressionString(); getExpressionProcessor().processExpression(obj, Object.class); return obj; } catch (ParseException e) { throw new ReferenceSyntaxException(); } }
From source file:org.seasar.teeda.core.el.impl.commons.CommonsExpressionProcessorImplTest.java
public void testProcessExpression() { CommonsExpressionProcessorImpl processor = new CommonsExpressionProcessorImpl(); ELParser parser = new ELParser(new StringReader("${a.b}")); try {/* w w w . j av a2s .c o m*/ Object obj = parser.ExpressionString(); processor.processExpression(obj, Object.class); } catch (Exception ignore) { } try { processor.processExpression(new Object(), Object.class); fail(); } catch (IllegalStateException e) { success(); } }
From source file:org.seasar.teeda.core.el.impl.commons.CommonsExpressionProcessorImplTest.java
public void testEvaluate() { CommonsExpressionProcessorImpl processor = new CommonsExpressionProcessorImpl(); ELParser parser = new ELParser(new StringReader("${a}")); Object expression = null;// w w w .j ava2 s . c o m try { expression = parser.ExpressionString(); processor.processExpression(expression, Object.class); } catch (Exception ignore) { } MockVariableResolver resolver = getVariableResolver(); A a = new A(); resolver.putValue("a", a); Object o = processor.evaluate(getFacesContext(), expression); assertSame(a, o); }
From source file:org.seasar.teeda.core.el.impl.commons.CommonsExpressionProcessorImplTest.java
public void testEvaluate2() { CommonsExpressionProcessorImpl processor = new CommonsExpressionProcessorImpl(); ELParser parser = new ELParser(new StringReader("b${a}")); Object expression = null;// ww w . ja v a2s.c om try { expression = parser.ExpressionString(); processor.processExpression(expression, Object.class); } catch (Exception ignore) { } MockVariableResolver resolver = getVariableResolver(); resolver.putValue("a", "A"); MockApplication app = getApplication(); app.setVariableResolver(resolver); Object o = processor.evaluate(getFacesContext(), expression); assertEquals("bA", o); }
From source file:org.seasar.teeda.core.el.impl.commons.CommonsExpressionProcessorImplTest.java
public void testResolveBase1() { CommonsExpressionProcessorImpl processor = new CommonsExpressionProcessorImpl(); ELParser parser = new ELParser(new StringReader("${a}")); Object expression = null;// w w w .ja va 2s.c om try { expression = parser.ExpressionString(); processor.processExpression(expression, Object.class); } catch (Exception ignore) { } Object o = processor.resolveBase(getFacesContext(), expression); assertNotNull(o); assertTrue(o instanceof String); assertEquals("a", (String) o); }