Author: remy.maucherat(a)jboss.com
Date: 2014-01-21 10:44:23 -0500 (Tue, 21 Jan 2014)
New Revision: 2349
Modified:
branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELNode.java
branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELParser.java
Log:
Another EL parser patch (not the last one since it has to do the same as the real EL
parser without being a real EL parser).
Modified: branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELNode.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELNode.java 2014-01-20
20:30:54 UTC (rev 2348)
+++ branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELNode.java 2014-01-21
15:44:23 UTC (rev 2349)
@@ -113,16 +113,18 @@
*/
public static class Function extends ELNode {
- private String prefix;
- private String name;
+ private final String prefix;
+ private final String name;
+ private final String originalText;
private String uri;
private FunctionInfo functionInfo;
private String methodName;
private String[] parameters;
- Function(String prefix, String name) {
+ Function(String prefix, String name, String originalText) {
this.prefix = prefix;
this.name = name;
+ this.originalText = originalText;
}
public void accept(Visitor v) throws JasperException {
@@ -137,6 +139,10 @@
return name;
}
+ public String getOriginalText() {
+ return originalText;
+ }
+
public void setUri(String uri) {
this.uri = uri;
}
Modified: branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELParser.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELParser.java 2014-01-20
20:30:54 UTC (rev 2348)
+++ branches/7.4.x/src/main/java/org/apache/jasper/compiler/ELParser.java 2014-01-21
15:44:23 UTC (rev 2349)
@@ -38,7 +38,7 @@
private Token curToken; // current token
private Token prevToken; // previous token
- private StringBuilder whiteSpace = new StringBuilder();
+ private String whiteSpace = "";
private final ELNode.Nodes expr;
@@ -96,7 +96,9 @@
*
* @return An ELNode.Nodes representing the EL expression
*
- * TODO: Can this be refactored to use the standard EL implementation?
+ * Note: This can not be refactored to use the standard EL implementation as
+ * the EL API does not provide the level of access required to the
+ * parsed expression.
*/
private ELNode.Nodes parseEL() {
@@ -115,7 +117,7 @@
// Output whatever is in buffer
if (buf.length() > 0) {
ELexpr.add(new ELNode.ELText(buf.toString()));
- buf = new StringBuilder();
+ buf.setLength(0);
}
if (!parseFunction()) {
ELexpr.add(new ELNode.ELText(curToken.toString()));
@@ -138,12 +140,13 @@
* arguments
*/
private boolean parseFunction() {
- if (!(curToken instanceof Id) || isELReserved(curToken.toString()) ||
+ if (!(curToken instanceof Id) || isELReserved(curToken.toTrimmedString()) ||
prevToken instanceof Char && prevToken.toChar() == '.')
{
return false;
}
String s1 = null; // Function prefix
- String s2 = curToken.toString(); // Function name
+ String s2 = curToken.toTrimmedString(); // Function name
+ int start = index - curToken.toString().length();
Token original = curToken;
if (hasNext()) {
int mark = getIndex() - whiteSpace.length();
@@ -153,7 +156,7 @@
Token t2 = nextToken();
if (t2 instanceof Id) {
s1 = s2.trim();
- s2 = t2.toString();
+ s2 = t2.toTrimmedString();
if (hasNext()) {
curToken = nextToken();
}
@@ -161,7 +164,7 @@
}
}
if (curToken.toChar() == '(') {
- ELexpr.add(new ELNode.Function(s1, s2.trim()));
+ ELexpr.add(new ELNode.Function(s1, s2, expression.substring(start, index
- 1)));
return true;
}
curToken = original;
@@ -245,29 +248,29 @@
}
private String getAndResetWhiteSpace() {
- String result = whiteSpace.toString();
- whiteSpace = new StringBuilder();
+ String result = whiteSpace;
+ whiteSpace = "";
return result;
}
/*
+ * Implementation note: This method assumes that it is always preceded by a
+ * call to hasNext() in order for whitespace handling to be correct.
+ *
* @return The next token in the EL expression buffer.
*/
private Token nextToken() {
prevToken = curToken;
- skipSpaces();
if (hasNextChar()) {
char ch = nextChar();
if (Character.isJavaIdentifierStart(ch)) {
- StringBuilder buf = new StringBuilder();
- buf.append(ch);
+ int start = index - 1;
while (index < expression.length() &&
Character.isJavaIdentifierPart(
ch = expression.charAt(index))) {
- buf.append(ch);
nextChar();
}
- return new Id(getAndResetWhiteSpace(), buf.toString());
+ return new Id(getAndResetWhiteSpace(), expression.substring(start,
index));
}
if (ch == '\'' || ch == '"') {
@@ -311,13 +314,14 @@
*/
private void skipSpaces() {
+ int start = index;
while (hasNextChar()) {
char c = expression.charAt(index);
if (c > ' ')
break;
- whiteSpace.append(c);
index++;
}
+ whiteSpace = expression.substring(start, index);
}
private boolean hasNextChar() {
@@ -359,6 +363,10 @@
return whiteSpace;
}
+ String toTrimmedString() {
+ return "";
+ }
+
String getWhiteSpace() {
return whiteSpace;
}
@@ -379,6 +387,11 @@
public String toString() {
return whiteSpace + id;
}
+
+ @Override
+ String toTrimmedString() {
+ return id;
+ }
}
/*
@@ -402,6 +415,11 @@
public String toString() {
return whiteSpace + ch;
}
+
+ @Override
+ String toTrimmedString() {
+ return "" + ch;
+ }
}
/*
@@ -420,6 +438,11 @@
public String toString() {
return whiteSpace + value;
}
+
+ @Override
+ String toTrimmedString() {
+ return value;
+ }
}
public char getType() {
@@ -445,11 +468,7 @@
@Override
public void visit(Function n) throws JasperException {
- if (n.getPrefix() != null) {
- output.append(n.getPrefix());
- output.append(':');
- }
- output.append(n.getName());
+ output.append(n.getOriginalText());
output.append('(');
}
Show replies by date