You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2010/11/20 19:14:04 UTC
svn commit: r1037284 [3/12] - in /tomcat/taglibs/standard/trunk/jstlel: ./
src/main/java/org/apache/taglibs/standard/lang/jstl/
src/main/java/org/apache/taglibs/standard/lang/jstl/parser/
src/main/java/org/apache/taglibs/standard/lang/support/ src/main...
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELEvaluator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELEvaluator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELEvaluator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELEvaluator.java Sat Nov 20 18:14:00 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
@@ -25,15 +25,14 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import javax.servlet.jsp.PageContext;
+
import org.apache.taglibs.standard.lang.jstl.parser.ELParser;
import org.apache.taglibs.standard.lang.jstl.parser.ParseException;
import org.apache.taglibs.standard.lang.jstl.parser.Token;
import org.apache.taglibs.standard.lang.jstl.parser.TokenMgrError;
-import javax.servlet.jsp.PageContext;
-
/**
- *
* <p>This is the main class for evaluating expression Strings. An
* expression String is a String that may contain expressions of the
* form ${...}. Multiple expressions may appear in the same
@@ -42,12 +41,12 @@ import javax.servlet.jsp.PageContext;
* expressions and any intervening non-expression text, then
* converting the resulting String to the expected type using the
* PropertyEditor mechanism.
- *
+ * <p/>
* <p>In the special case where the expression String is a single
* expression, the value of the expression String is determined by
* evaluating the expression, without any intervening conversion to a
* String.
- *
+ * <p/>
* <p>The evaluator maintains a cache mapping expression Strings to
* their parsed results. For expression Strings containing no
* expression elements, it maintains a cache mapping
@@ -56,7 +55,7 @@ import javax.servlet.jsp.PageContext;
* time they are used. All instances of the evaluator share the same
* cache. The cache may be bypassed by setting a flag on the
* evaluator's constructor.
- *
+ * <p/>
* <p>The evaluator must be passed a VariableResolver in its
* constructor. The VariableResolver is used to resolve variable
* names encountered in expressions, and can also be used to implement
@@ -65,466 +64,459 @@ import javax.servlet.jsp.PageContext;
* lookups and implicit objects - these differences can be
* encapsulated in the VariableResolver passed to the evaluator's
* constructor.
- *
+ * <p/>
* <p>Most VariableResolvers will need to perform their resolution
* against some context. For example, a JSP environment needs a
* PageContext to resolve variables. The evaluate() method takes a
* generic Object context which is eventually passed to the
* VariableResolver - the VariableResolver is responsible for casting
* the context to the proper type.
- *
+ * <p/>
* <p>Once an evaluator instance has been constructed, it may be used
* multiple times, and may be used by multiple simultaneous Threads.
* In other words, an evaluator instance is well-suited for use as a
* singleton.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @author Shawn Bayern
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
+
+public class ELEvaluator {
+ //-------------------------------------
+ // Properties
+ //-------------------------------------
+
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ /**
+ * Name of configuration setting for maximum number of entries in the
+ * cached expression string map
+ */
+ private static final String EXPR_CACHE_PARAM
+ = "org.apache.taglibs.standard.lang.jstl.exprCacheSize";
+ /**
+ * Default maximum cache size
+ */
+ private static final int MAX_SIZE = 100;
+
+ /**
+ * The mapping from expression String to its parsed form (String,
+ * Expression, or ExpressionString)
+ * <p/>
+ * Using LRU Map with a maximum capacity to avoid out of bound map
+ * growth.
+ * <p/>
+ * NOTE: use LinkedHashmap if a dependency on J2SE 1.4+ is ok
+ */
+ static Map sCachedExpressionStrings = null;
+
+ /**
+ * The mapping from ExpectedType to Maps mapping literal String to
+ * parsed value *
+ */
+ static Map sCachedExpectedTypes = new HashMap();
+
+ /**
+ * The static Logger *
+ */
+ static Logger sLogger = new Logger(System.out);
+
+ /**
+ * The VariableResolver *
+ */
+ VariableResolver mResolver;
+
+ /**
+ * Flag if the cache should be bypassed *
+ */
+ boolean mBypassCache;
+
+ /**
+ * The PageContext *
+ */
+ PageContext pageContext;
+
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param pResolver the object that should be used to resolve
+ * variable names encountered in expressions. If null, all variable
+ * references will resolve to null.
+ */
+ public ELEvaluator(VariableResolver pResolver) {
+ mResolver = pResolver;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Enable cache bypass
+ *
+ * @param pBypassCache flag indicating cache should be bypassed
+ */
+ public void setBypassCache(boolean pBypassCache) {
+ mBypassCache = pBypassCache;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Evaluates the given expression String
+ *
+ * @param pExpressionString the expression String to be evaluated
+ * @param pContext the context passed to the VariableResolver for
+ * resolving variable names
+ * @param pExpectedType the type to which the evaluated expression
+ * should be coerced
+ * @return the expression String evaluated to the given expected
+ * type
+ */
+ public Object evaluate(String pExpressionString,
+ Object pContext,
+ Class pExpectedType,
+ Map functions,
+ String defaultPrefix)
+ throws ELException {
+ return evaluate(pExpressionString,
+ pContext,
+ pExpectedType,
+ functions,
+ defaultPrefix,
+ sLogger);
+ }
+
+ //-------------------------------------
+
+ /**
+ * Evaluates the given expression string
+ */
+ Object evaluate(String pExpressionString,
+ Object pContext,
+ Class pExpectedType,
+ Map functions,
+ String defaultPrefix,
+ Logger pLogger)
+ throws ELException {
+ // Check for null expression strings
+ if (pExpressionString == null) {
+ throw new ELException
+ (Constants.NULL_EXPRESSION_STRING);
+ }
-public class ELEvaluator
-{
- //-------------------------------------
- // Properties
- //-------------------------------------
-
- //-------------------------------------
- // Member variables
- //-------------------------------------
-
- /**
- * Name of configuration setting for maximum number of entries in the
- * cached expression string map
- */
- private static final String EXPR_CACHE_PARAM
- = "org.apache.taglibs.standard.lang.jstl.exprCacheSize";
- /**
- * Default maximum cache size
- */
- private static final int MAX_SIZE = 100;
-
- /** The mapping from expression String to its parsed form (String,
- * Expression, or ExpressionString)
- *
- * Using LRU Map with a maximum capacity to avoid out of bound map
- * growth.
- *
- * NOTE: use LinkedHashmap if a dependency on J2SE 1.4+ is ok
- */
- static Map sCachedExpressionStrings = null;
-
- /** The mapping from ExpectedType to Maps mapping literal String to
- parsed value **/
- static Map sCachedExpectedTypes = new HashMap();
-
- /** The static Logger **/
- static Logger sLogger = new Logger (System.out);
-
- /** The VariableResolver **/
- VariableResolver mResolver;
-
- /** Flag if the cache should be bypassed **/
- boolean mBypassCache;
-
- /** The PageContext **/
- PageContext pageContext;
-
-
- //-------------------------------------
- /**
- *
- * Constructor
- *
- * @param pResolver the object that should be used to resolve
- * variable names encountered in expressions. If null, all variable
- * references will resolve to null.
- **/
- public ELEvaluator (VariableResolver pResolver)
- {
- mResolver = pResolver;
- }
-
- //-------------------------------------
- /**
- * Enable cache bypass
- *
- * @param pBypassCache flag indicating cache should be bypassed
- **/
- public void setBypassCache(boolean pBypassCache) {
- mBypassCache = pBypassCache;
- }
-
- //-------------------------------------
- /**
- *
- * Evaluates the given expression String
- *
- * @param pExpressionString the expression String to be evaluated
- * @param pContext the context passed to the VariableResolver for
- * resolving variable names
- * @param pExpectedType the type to which the evaluated expression
- * should be coerced
- * @return the expression String evaluated to the given expected
- * type
- **/
- public Object evaluate (String pExpressionString,
- Object pContext,
- Class pExpectedType,
- Map functions,
- String defaultPrefix)
- throws ELException
- {
- return evaluate (pExpressionString,
- pContext,
- pExpectedType,
- functions,
- defaultPrefix,
- sLogger);
- }
-
- //-------------------------------------
- /**
- *
- * Evaluates the given expression string
- **/
- Object evaluate (String pExpressionString,
- Object pContext,
- Class pExpectedType,
- Map functions,
- String defaultPrefix,
- Logger pLogger)
- throws ELException
- {
- // Check for null expression strings
- if (pExpressionString == null) {
- throw new ELException
- (Constants.NULL_EXPRESSION_STRING);
- }
-
- // Set the PageContext;
- pageContext = (PageContext) pContext;
-
- // Get the parsed version of the expression string
- Object parsedValue = parseExpressionString (pExpressionString);
-
- // Evaluate differently based on the parsed type
- if (parsedValue instanceof String) {
- // Convert the String, and cache the conversion
- String strValue = (String) parsedValue;
- return convertStaticValueToExpectedType (strValue,
- pExpectedType,
- pLogger);
- }
-
- else if (parsedValue instanceof Expression) {
- // Evaluate the expression and convert
- Object value =
- ((Expression) parsedValue).evaluate (pContext,
- mResolver,
- functions,
- defaultPrefix,
- pLogger);
- return convertToExpectedType (value,
- pExpectedType,
- pLogger);
- }
-
- else if (parsedValue instanceof ExpressionString) {
- // Evaluate the expression/string list and convert
- String strValue =
- ((ExpressionString) parsedValue).evaluate (pContext,
- mResolver,
- functions,
- defaultPrefix,
- pLogger);
- return convertToExpectedType (strValue,
- pExpectedType,
- pLogger);
- }
-
- else {
- // This should never be reached
- return null;
- }
- }
-
- //-------------------------------------
- /**
- *
- * 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 "";
- }
-
- if (!(mBypassCache) && (sCachedExpressionStrings == null)) {
- createExpressionStringMap();
- }
-
- // See if it's in the cache
- Object ret =
- mBypassCache ?
- null :
- sCachedExpressionStrings.get (pExpressionString);
-
- if (ret == null) {
- // Parse the expression
- Reader r = new StringReader (pExpressionString);
- ELParser parser = new ELParser (r);
- try {
- ret = parser.ExpressionString ();
- if (!mBypassCache) {
- sCachedExpressionStrings.put (pExpressionString, ret);
- }
- }
- catch (ParseException exc) {
- throw new ELException
- (formatParseException (pExpressionString,
- 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;
- }
-
- //-------------------------------------
- /**
- *
- * Converts the given value to the specified expected type.
- **/
- Object convertToExpectedType (Object pValue,
- Class pExpectedType,
- Logger pLogger)
- throws ELException
- {
- return Coercions.coerce (pValue,
- pExpectedType,
- pLogger);
- }
-
- //-------------------------------------
- /**
- *
- * Converts the given String, specified as a static expression
- * string, to the given expected type. The conversion is cached.
- **/
- Object convertStaticValueToExpectedType (String pValue,
- Class pExpectedType,
- Logger pLogger)
- throws ELException
- {
- // See if the value is already of the expected type
- if (pExpectedType == String.class ||
- pExpectedType == Object.class) {
- return pValue;
- }
-
- // Find the cached value
- Map valueByString = getOrCreateExpectedTypeMap (pExpectedType);
- if (!mBypassCache &&
- valueByString.containsKey (pValue)) {
- return valueByString.get (pValue);
- }
- else {
- // Convert from a String
- Object ret = Coercions.coerce (pValue, pExpectedType, pLogger);
- valueByString.put (pValue, ret);
- return ret;
- }
- }
-
- //-------------------------------------
- /**
- *
- * Creates or returns the Map that maps string literals to parsed
- * values for the specified expected type.
- **/
- static Map getOrCreateExpectedTypeMap (Class pExpectedType)
- {
- synchronized (sCachedExpectedTypes) {
- Map ret = (Map) sCachedExpectedTypes.get (pExpectedType);
- if (ret == null) {
- ret = Collections.synchronizedMap (new HashMap ());
- sCachedExpectedTypes.put (pExpectedType, ret);
- }
- return ret;
- }
- }
-
- //-------------------------------------
- /**
- *
- * Creates LRU map of expression strings. If context parameter
- * specifying cache size is present use that as the maximum size
- * of the LRU map otherwise use default.
- **/
- private synchronized void createExpressionStringMap () {
- if (sCachedExpressionStrings != null) {
- return;
- }
-
- final int maxSize;
- if( (pageContext != null) && (pageContext.getServletContext() != null) ) {
- String value = pageContext.getServletContext().getInitParameter(EXPR_CACHE_PARAM);
- if (value != null) {
- maxSize = Integer.valueOf(value);
- } else {
- maxSize = MAX_SIZE;
- }
- } else {
- maxSize = MAX_SIZE;
- }
-
- // fall through if it couldn't find the parameter
- sCachedExpressionStrings = Collections.synchronizedMap(new LinkedHashMap() {
- @Override
- protected boolean removeEldestEntry(Map.Entry eldest) {
- return size() > maxSize;
- }
- });
- }
-
- //-------------------------------------
- // Formatting ParseException
- //-------------------------------------
- /**
- *
- * Formats a ParseException into an error message suitable for
- * displaying on a web page
- **/
- static String formatParseException (String pExpressionString,
- ParseException pExc)
- {
- // Generate the String of expected tokens
- StringBuffer expectedBuf = new StringBuffer ();
- int maxSize = 0;
- boolean printedOne = false;
-
- if (pExc.expectedTokenSequences == null)
- return pExc.toString();
-
- for (int i = 0; i < pExc.expectedTokenSequences.length; i++) {
- if (maxSize < pExc.expectedTokenSequences [i].length) {
- maxSize = pExc.expectedTokenSequences [i].length;
- }
- for (int j = 0; j < pExc.expectedTokenSequences [i].length; j++) {
- if (printedOne) {
- expectedBuf.append (", ");
- }
- expectedBuf.append
- (pExc.tokenImage [pExc.expectedTokenSequences [i] [j]]);
- printedOne = true;
- }
- }
- String expected = expectedBuf.toString ();
-
- // Generate the String of encountered tokens
- StringBuffer encounteredBuf = new StringBuffer ();
- Token tok = pExc.currentToken.next;
- for (int i = 0; i < maxSize; i++) {
- if (i != 0) encounteredBuf.append (" ");
- if (tok.kind == 0) {
- encounteredBuf.append (pExc.tokenImage [0]);
- break;
- }
- encounteredBuf.append (addEscapes (tok.image));
- tok = tok.next;
- }
- String encountered = encounteredBuf.toString ();
-
- // Format the error message
- return MessageFormat.format
- (Constants.PARSE_EXCEPTION,
- new Object [] {
- expected,
- encountered,
- });
- }
-
- //-------------------------------------
- /**
- *
- * Used to convert raw characters to their escaped version when
- * these raw version cannot be used as part of an ASCII string
- * literal.
- **/
- static String addEscapes (String str)
- {
- StringBuffer retval = new StringBuffer ();
- char ch;
- for (int i = 0; i < str.length (); i++) {
- switch (str.charAt (i)) {
- case 0 :
- continue;
- case '\b':
- retval.append ("\\b");
- continue;
- case '\t':
- retval.append ("\\t");
- continue;
- case '\n':
- retval.append ("\\n");
- continue;
- case '\f':
- retval.append ("\\f");
- continue;
- case '\r':
- retval.append ("\\r");
- continue;
- default:
- if ((ch = str.charAt (i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString (ch, 16);
- retval.append ("\\u" + s.substring (s.length () - 4, s.length ()));
- }
- else {
- retval.append (ch);
- }
- continue;
- }
- }
- return retval.toString ();
- }
-
- //-------------------------------------
- // Testing methods
- //-------------------------------------
- /**
- *
- * Parses the given expression string, then converts it back to a
- * String in its canonical form. This is used to test parsing.
- **/
- public String parseAndRender (String pExpressionString)
- throws ELException
- {
- Object val = parseExpressionString (pExpressionString);
- if (val instanceof String) {
- return (String) val;
- }
- else if (val instanceof Expression) {
- return "${" + ((Expression) val).getExpressionString () + "}";
- }
- else if (val instanceof ExpressionString) {
- return ((ExpressionString) val).getExpressionString ();
+ // Set the PageContext;
+ pageContext = (PageContext) pContext;
+
+ // Get the parsed version of the expression string
+ Object parsedValue = parseExpressionString(pExpressionString);
+
+ // Evaluate differently based on the parsed type
+ if (parsedValue instanceof String) {
+ // Convert the String, and cache the conversion
+ String strValue = (String) parsedValue;
+ return convertStaticValueToExpectedType(strValue,
+ pExpectedType,
+ pLogger);
+ } else if (parsedValue instanceof Expression) {
+ // Evaluate the expression and convert
+ Object value =
+ ((Expression) parsedValue).evaluate(pContext,
+ mResolver,
+ functions,
+ defaultPrefix,
+ pLogger);
+ return convertToExpectedType(value,
+ pExpectedType,
+ pLogger);
+ } else if (parsedValue instanceof ExpressionString) {
+ // Evaluate the expression/string list and convert
+ String strValue =
+ ((ExpressionString) parsedValue).evaluate(pContext,
+ mResolver,
+ functions,
+ defaultPrefix,
+ pLogger);
+ return convertToExpectedType(strValue,
+ pExpectedType,
+ pLogger);
+ } else {
+ // This should never be reached
+ return null;
+ }
}
- else {
- return "";
+
+ //-------------------------------------
+
+ /**
+ * 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 "";
+ }
+
+ if (!(mBypassCache) && (sCachedExpressionStrings == null)) {
+ createExpressionStringMap();
+ }
+
+ // See if it's in the cache
+ Object ret =
+ mBypassCache ?
+ null :
+ sCachedExpressionStrings.get(pExpressionString);
+
+ if (ret == null) {
+ // Parse the expression
+ Reader r = new StringReader(pExpressionString);
+ ELParser parser = new ELParser(r);
+ try {
+ ret = parser.ExpressionString();
+ if (!mBypassCache) {
+ sCachedExpressionStrings.put(pExpressionString, ret);
+ }
+ }
+ catch (ParseException exc) {
+ throw new ELException
+ (formatParseException(pExpressionString,
+ 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;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Converts the given value to the specified expected type.
+ */
+ Object convertToExpectedType(Object pValue,
+ Class pExpectedType,
+ Logger pLogger)
+ throws ELException {
+ return Coercions.coerce(pValue,
+ pExpectedType,
+ pLogger);
+ }
+
+ //-------------------------------------
+
+ /**
+ * Converts the given String, specified as a static expression
+ * string, to the given expected type. The conversion is cached.
+ */
+ Object convertStaticValueToExpectedType(String pValue,
+ Class pExpectedType,
+ Logger pLogger)
+ throws ELException {
+ // See if the value is already of the expected type
+ if (pExpectedType == String.class ||
+ pExpectedType == Object.class) {
+ return pValue;
+ }
+
+ // Find the cached value
+ Map valueByString = getOrCreateExpectedTypeMap(pExpectedType);
+ if (!mBypassCache &&
+ valueByString.containsKey(pValue)) {
+ return valueByString.get(pValue);
+ } else {
+ // Convert from a String
+ Object ret = Coercions.coerce(pValue, pExpectedType, pLogger);
+ valueByString.put(pValue, ret);
+ return ret;
+ }
+ }
+
+ //-------------------------------------
+
+ /**
+ * Creates or returns the Map that maps string literals to parsed
+ * values for the specified expected type.
+ */
+ static Map getOrCreateExpectedTypeMap(Class pExpectedType) {
+ synchronized (sCachedExpectedTypes) {
+ Map ret = (Map) sCachedExpectedTypes.get(pExpectedType);
+ if (ret == null) {
+ ret = Collections.synchronizedMap(new HashMap());
+ sCachedExpectedTypes.put(pExpectedType, ret);
+ }
+ return ret;
+ }
+ }
+
+ //-------------------------------------
+
+ /**
+ * Creates LRU map of expression strings. If context parameter
+ * specifying cache size is present use that as the maximum size
+ * of the LRU map otherwise use default.
+ */
+ private synchronized void createExpressionStringMap() {
+ if (sCachedExpressionStrings != null) {
+ return;
+ }
+
+ final int maxSize;
+ if ((pageContext != null) && (pageContext.getServletContext() != null)) {
+ String value = pageContext.getServletContext().getInitParameter(EXPR_CACHE_PARAM);
+ if (value != null) {
+ maxSize = Integer.valueOf(value);
+ } else {
+ maxSize = MAX_SIZE;
+ }
+ } else {
+ maxSize = MAX_SIZE;
+ }
+
+ // fall through if it couldn't find the parameter
+ sCachedExpressionStrings = Collections.synchronizedMap(new LinkedHashMap() {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return size() > maxSize;
+ }
+ });
+ }
+
+ //-------------------------------------
+ // Formatting ParseException
+ //-------------------------------------
+
+ /**
+ * Formats a ParseException into an error message suitable for
+ * displaying on a web page
+ */
+ static String formatParseException(String pExpressionString,
+ ParseException pExc) {
+ // Generate the String of expected tokens
+ StringBuffer expectedBuf = new StringBuffer();
+ int maxSize = 0;
+ boolean printedOne = false;
+
+ if (pExc.expectedTokenSequences == null) {
+ return pExc.toString();
+ }
+
+ for (int i = 0; i < pExc.expectedTokenSequences.length; i++) {
+ if (maxSize < pExc.expectedTokenSequences[i].length) {
+ maxSize = pExc.expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < pExc.expectedTokenSequences[i].length; j++) {
+ if (printedOne) {
+ expectedBuf.append(", ");
+ }
+ expectedBuf.append
+ (pExc.tokenImage[pExc.expectedTokenSequences[i][j]]);
+ printedOne = true;
+ }
+ }
+ String expected = expectedBuf.toString();
+
+ // Generate the String of encountered tokens
+ StringBuffer encounteredBuf = new StringBuffer();
+ Token tok = pExc.currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) {
+ encounteredBuf.append(" ");
+ }
+ if (tok.kind == 0) {
+ encounteredBuf.append(pExc.tokenImage[0]);
+ break;
+ }
+ encounteredBuf.append(addEscapes(tok.image));
+ tok = tok.next;
+ }
+ String encountered = encounteredBuf.toString();
+
+ // Format the error message
+ return MessageFormat.format
+ (Constants.PARSE_EXCEPTION,
+ new Object[]{
+ expected,
+ encountered,
+ });
+ }
+
+ //-------------------------------------
+
+ /**
+ * Used to convert raw characters to their escaped version when
+ * these raw version cannot be used as part of an ASCII string
+ * literal.
+ */
+ static String addEscapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i)) {
+ case 0:
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+ //-------------------------------------
+ // Testing methods
+ //-------------------------------------
+
+ /**
+ * Parses the given expression string, then converts it back to a
+ * String in its canonical form. This is used to test parsing.
+ */
+ public String parseAndRender(String pExpressionString)
+ throws ELException {
+ Object val = parseExpressionString(pExpressionString);
+ if (val instanceof String) {
+ return (String) val;
+ } else if (val instanceof Expression) {
+ return "${" + ((Expression) val).getExpressionString() + "}";
+ } else if (val instanceof ExpressionString) {
+ return ((ExpressionString) val).getExpressionString();
+ } else {
+ return "";
+ }
}
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELException.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELException.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELException.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ELException.java Sat Nov 20 18:14:00 2010
@@ -13,98 +13,88 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
/**
- *
* Represents any of the exception conditions that arise during the
* operation evaluation of the evaluator.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public class ELException
- extends Exception
-{
- //-------------------------------------
- // Member variables
- //-------------------------------------
-
- Throwable mRootCause;
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public ELException ()
- {
- super ();
- }
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public ELException (String pMessage)
- {
- super (pMessage);
- }
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public ELException (Throwable pRootCause)
- {
- mRootCause = pRootCause;
- }
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public ELException (String pMessage,
- Throwable pRootCause)
- {
- super (pMessage);
- mRootCause = pRootCause;
- }
-
- //-------------------------------------
- /**
- *
- * Returns the root cause
- **/
- public Throwable getRootCause ()
- {
- return mRootCause;
- }
-
- //-------------------------------------
- /**
- *
- * String representation
- **/
- public String toString ()
- {
- if (getMessage () == null) {
- return mRootCause.toString ();
- }
- else if (mRootCause == null) {
- return getMessage ();
+ extends Exception {
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ Throwable mRootCause;
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ELException() {
+ super();
+ }
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ELException(String pMessage) {
+ super(pMessage);
+ }
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ELException(Throwable pRootCause) {
+ mRootCause = pRootCause;
}
- else {
- return getMessage () + ": " + mRootCause;
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ELException(String pMessage,
+ Throwable pRootCause) {
+ super(pMessage);
+ mRootCause = pRootCause;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Returns the root cause
+ */
+ public Throwable getRootCause() {
+ return mRootCause;
+ }
+
+ //-------------------------------------
+
+ /**
+ * String representation
+ */
+ public String toString() {
+ if (getMessage() == null) {
+ return mRootCause.toString();
+ } else if (mRootCause == null) {
+ return getMessage();
+ } else {
+ return getMessage() + ": " + mRootCause;
+ }
}
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EmptyOperator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EmptyOperator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EmptyOperator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EmptyOperator.java Sat Nov 20 18:14:00 2010
@@ -13,189 +13,154 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
-
+ */
package org.apache.taglibs.standard.lang.jstl;
-
import java.lang.reflect.Array;
-
import java.util.Collection;
-
import java.util.Map;
-
/**
-
- *
-
* <p>The implementation of the empty operator
-
- *
-
+ *
* @author Nathan Abramson - Art Technology Group
-
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
-
- **/
-
+ */
public class EmptyOperator
- extends UnaryOperator
+ extends UnaryOperator
{
- //-------------------------------------
-
- // Singleton
-
- //-------------------------------------
-
-
-
- public static final EmptyOperator SINGLETON =
-
- new EmptyOperator ();
+ //-------------------------------------
+ // Singleton
+ //-------------------------------------
- //-------------------------------------
- /**
+ public static final EmptyOperator SINGLETON =
- *
+ new EmptyOperator();
- * Constructor
- **/
+ //-------------------------------------
- public EmptyOperator ()
+ /**
+ * Constructor
+ */
- {
+ public EmptyOperator()
- }
+ {
+ }
- //-------------------------------------
-
- // Expression methods
-
- //-------------------------------------
-
- /**
-
- *
-
- * Returns the symbol representing the operator
-
- **/
-
- public String getOperatorSymbol ()
-
- {
-
- return "empty";
-
- }
+ //-------------------------------------
+ // Expression methods
+ //-------------------------------------
- //-------------------------------------
+ /**
+ * Returns the symbol representing the operator
+ */
- /**
+ public String getOperatorSymbol()
- *
+ {
- * Applies the operator to the given value
+ return "empty";
- **/
+ }
- public Object apply (Object pValue,
- Object pContext,
+ //-------------------------------------
- Logger pLogger)
+ /**
+ * Applies the operator to the given value
+ */
- throws ELException
+ public Object apply(Object pValue,
- {
+ Object pContext,
- // See if the value is null
+ Logger pLogger)
- if (pValue == null) {
+ throws ELException
- return PrimitiveObjects.getBoolean (true);
+ {
- }
+ // See if the value is null
+ if (pValue == null) {
+ return PrimitiveObjects.getBoolean(true);
- // See if the value is a zero-length String
+ }
- else if ("".equals (pValue)) {
- return PrimitiveObjects.getBoolean (true);
-
- }
+ // See if the value is a zero-length String
+ else if ("".equals(pValue)) {
+ return PrimitiveObjects.getBoolean(true);
- // See if the value is a zero-length array
+ }
- else if (pValue.getClass ().isArray () &&
- Array.getLength (pValue) == 0) {
+ // See if the value is a zero-length array
- return PrimitiveObjects.getBoolean (true);
+ else if (pValue.getClass().isArray() &&
- }
+ Array.getLength(pValue) == 0) {
+ return PrimitiveObjects.getBoolean(true);
+ }
- // See if the value is an empty Collection
- else if (pValue instanceof Collection &&
+ // See if the value is an empty Collection
- ((Collection) pValue).isEmpty ()) {
+ else if (pValue instanceof Collection &&
- return PrimitiveObjects.getBoolean (true);
+ ((Collection) pValue).isEmpty()) {
- }
+ return PrimitiveObjects.getBoolean(true);
+ }
- // See if the value is an empty Map
+ // See if the value is an empty Map
- else if (pValue instanceof Map &&
+ else if (pValue instanceof Map &&
- ((Map) pValue).isEmpty ()) {
+ ((Map) pValue).isEmpty()) {
- return PrimitiveObjects.getBoolean (true);
+ return PrimitiveObjects.getBoolean(true);
- }
+ }
+ // Otherwise, not empty
- // Otherwise, not empty
+ else {
- else {
+ return PrimitiveObjects.getBoolean(false);
- return PrimitiveObjects.getBoolean (false);
+ }
}
- }
-
-
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EnumeratedMap.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EnumeratedMap.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EnumeratedMap.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EnumeratedMap.java Sat Nov 20 18:14:00 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
@@ -24,160 +24,155 @@ import java.util.Map;
import java.util.Set;
/**
- *
* <p>This is a Map implementation driven by a data source that only
* provides an enumeration of keys and a getValue(key) method. This
* class must be subclassed to implement those methods.
- *
+ * <p/>
* <p>Some of the methods may incur a performance penalty that
* involves enumerating the entire data source. In these cases, the
* Map will try to save the results of that enumeration, but only if
* the underlying data source is immutable.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public abstract class EnumeratedMap
- implements Map
-{
- //-------------------------------------
- // Member variables
- //-------------------------------------
-
- Map mMap;
-
- //-------------------------------------
- public void clear ()
- {
- throw new UnsupportedOperationException ();
- }
-
- //-------------------------------------
- public boolean containsKey (Object pKey)
- {
- return getValue (pKey) != null;
- }
-
- //-------------------------------------
- public boolean containsValue (Object pValue)
- {
- return getAsMap ().containsValue (pValue);
- }
-
- //-------------------------------------
- public Set entrySet ()
- {
- return getAsMap ().entrySet ();
- }
-
- //-------------------------------------
- public Object get (Object pKey)
- {
- return getValue (pKey);
- }
-
- //-------------------------------------
- public boolean isEmpty ()
- {
- return !enumerateKeys ().hasMoreElements ();
- }
-
- //-------------------------------------
- public Set keySet ()
- {
- return getAsMap ().keySet ();
- }
-
- //-------------------------------------
- public Object put (Object pKey, Object pValue)
- {
- throw new UnsupportedOperationException ();
- }
-
- //-------------------------------------
- public void putAll (Map pMap)
- {
- throw new UnsupportedOperationException ();
- }
-
- //-------------------------------------
- public Object remove (Object pKey)
- {
- throw new UnsupportedOperationException ();
- }
-
- //-------------------------------------
- public int size ()
- {
- return getAsMap ().size ();
- }
-
- //-------------------------------------
- public Collection values ()
- {
- return getAsMap ().values ();
- }
-
- //-------------------------------------
- // Abstract methods
- //-------------------------------------
- /**
- *
- * Returns an enumeration of the keys
- **/
- public abstract Enumeration enumerateKeys ();
-
- //-------------------------------------
- /**
- *
- * Returns true if it is possible for this data source to change
- **/
- public abstract boolean isMutable ();
-
- //-------------------------------------
- /**
- *
- * Returns the value associated with the given key, or null if not
- * found.
- **/
- public abstract Object getValue (Object pKey);
-
- //-------------------------------------
- /**
- *
- * Converts the MapSource to a Map. If the map is not mutable, this
- * is cached
- **/
- public Map getAsMap ()
- {
- if (mMap != null) {
- return mMap;
- }
- else {
- Map m = convertToMap ();
- if (!isMutable ()) {
- mMap = m;
- }
- return m;
- }
- }
-
- //-------------------------------------
- /**
- *
- * Converts to a Map
- **/
- Map convertToMap ()
- {
- Map ret = new HashMap ();
- for (Enumeration e = enumerateKeys (); e.hasMoreElements (); ) {
- Object key = e.nextElement ();
- Object value = getValue (key);
- ret.put (key, value);
+ implements Map {
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ Map mMap;
+
+ //-------------------------------------
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ //-------------------------------------
+
+ public boolean containsKey(Object pKey) {
+ return getValue(pKey) != null;
+ }
+
+ //-------------------------------------
+
+ public boolean containsValue(Object pValue) {
+ return getAsMap().containsValue(pValue);
+ }
+
+ //-------------------------------------
+
+ public Set entrySet() {
+ return getAsMap().entrySet();
+ }
+
+ //-------------------------------------
+
+ public Object get(Object pKey) {
+ return getValue(pKey);
+ }
+
+ //-------------------------------------
+
+ public boolean isEmpty() {
+ return !enumerateKeys().hasMoreElements();
+ }
+
+ //-------------------------------------
+
+ public Set keySet() {
+ return getAsMap().keySet();
+ }
+
+ //-------------------------------------
+
+ public Object put(Object pKey, Object pValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ //-------------------------------------
+
+ public void putAll(Map pMap) {
+ throw new UnsupportedOperationException();
+ }
+
+ //-------------------------------------
+
+ public Object remove(Object pKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ //-------------------------------------
+
+ public int size() {
+ return getAsMap().size();
+ }
+
+ //-------------------------------------
+
+ public Collection values() {
+ return getAsMap().values();
+ }
+
+ //-------------------------------------
+ // Abstract methods
+ //-------------------------------------
+
+ /**
+ * Returns an enumeration of the keys
+ */
+ public abstract Enumeration enumerateKeys();
+
+ //-------------------------------------
+
+ /**
+ * Returns true if it is possible for this data source to change
+ */
+ public abstract boolean isMutable();
+
+ //-------------------------------------
+
+ /**
+ * Returns the value associated with the given key, or null if not
+ * found.
+ */
+ public abstract Object getValue(Object pKey);
+
+ //-------------------------------------
+
+ /**
+ * Converts the MapSource to a Map. If the map is not mutable, this
+ * is cached
+ */
+ public Map getAsMap() {
+ if (mMap != null) {
+ return mMap;
+ } else {
+ Map m = convertToMap();
+ if (!isMutable()) {
+ mMap = m;
+ }
+ return m;
+ }
+ }
+
+ //-------------------------------------
+
+ /**
+ * Converts to a Map
+ */
+ Map convertToMap() {
+ Map ret = new HashMap();
+ for (Enumeration e = enumerateKeys(); e.hasMoreElements();) {
+ Object key = e.nextElement();
+ Object value = getValue(key);
+ ret.put(key, value);
+ }
+ return ret;
}
- return ret;
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualityOperator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualityOperator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualityOperator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualityOperator.java Sat Nov 20 18:14:00 2010
@@ -13,43 +13,40 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
/**
- *
* <p>This is the superclass for all equality operators (==, !=)
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public abstract class EqualityOperator
- extends BinaryOperator
-{
- //-------------------------------------
- /**
- *
- * Applies the operator to the given value
- **/
- public Object apply (Object pLeft,
- Object pRight,
- Object pContext,
- Logger pLogger)
- throws ELException
- {
- return Coercions.applyEqualityOperator (pLeft, pRight, this, pLogger);
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator given the fact that the two elements are
- * equal.
- **/
- public abstract boolean apply (boolean pAreEqual,
- Logger pLogger);
-
- //-------------------------------------
+ extends BinaryOperator {
+ //-------------------------------------
+
+ /**
+ * Applies the operator to the given value
+ */
+ public Object apply(Object pLeft,
+ Object pRight,
+ Object pContext,
+ Logger pLogger)
+ throws ELException {
+ return Coercions.applyEqualityOperator(pLeft, pRight, this, pLogger);
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator given the fact that the two elements are
+ * equal.
+ */
+ public abstract boolean apply(boolean pAreEqual,
+ Logger pLogger);
+
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualsOperator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualsOperator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualsOperator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/EqualsOperator.java Sat Nov 20 18:14:00 2010
@@ -13,60 +13,55 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
/**
- *
* <p>The implementation of the equals operator
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public class EqualsOperator
- extends EqualityOperator
-{
- //-------------------------------------
- // Singleton
- //-------------------------------------
-
- public static final EqualsOperator SINGLETON =
- new EqualsOperator ();
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public EqualsOperator ()
- {
- }
-
- //-------------------------------------
- // Expression methods
- //-------------------------------------
- /**
- *
- * Returns the symbol representing the operator
- **/
- public String getOperatorSymbol ()
- {
- return "==";
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator given the fact that the two elements are
- * equal.
- **/
- public boolean apply (boolean pAreEqual,
- Logger pLogger)
- {
- return pAreEqual;
- }
-
- //-------------------------------------
+ extends EqualityOperator {
+ //-------------------------------------
+ // Singleton
+ //-------------------------------------
+
+ public static final EqualsOperator SINGLETON =
+ new EqualsOperator();
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public EqualsOperator() {
+ }
+
+ //-------------------------------------
+ // Expression methods
+ //-------------------------------------
+
+ /**
+ * Returns the symbol representing the operator
+ */
+ public String getOperatorSymbol() {
+ return "==";
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator given the fact that the two elements are
+ * equal.
+ */
+ public boolean apply(boolean pAreEqual,
+ Logger pLogger) {
+ return pAreEqual;
+ }
+
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java Sat Nov 20 18:14:00 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
@@ -27,144 +27,142 @@ import javax.servlet.jsp.tagext.Tag;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluator;
/**
- *
* <p>This is the expression evaluator "adapter" that customizes it
* for use with the JSP Standard Tag Library. It uses a
* VariableResolver implementation that looks up variables from the
* PageContext and also implements its implicit objects. It also
* wraps ELExceptions in JspExceptions that describe the attribute
* name and value causing the error.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @author Shawn Bayern
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public class Evaluator
- implements ExpressionEvaluator
-{
- //-------------------------------------
- // Properties
- //-------------------------------------
-
- //-------------------------------------
- // Member variables
- //-------------------------------------
-
- /** The singleton instance of the evaluator **/
- static ELEvaluator sEvaluator =
- new ELEvaluator
- (new JSTLVariableResolver ());
-
- //-------------------------------------
- // ExpressionEvaluator methods
- //-------------------------------------
- /**
- *
- * Translation time validation of an attribute value. This method
- * will return a null String if the attribute value is valid;
- * otherwise an error message.
- **/
- public String validate (String pAttributeName,
- String pAttributeValue)
- {
- try {
- sEvaluator.setBypassCache(true);
- sEvaluator.parseExpressionString (pAttributeValue);
- sEvaluator.setBypassCache(false);
- return null;
- }
- catch (ELException exc) {
- return
- MessageFormat.format
- (Constants.ATTRIBUTE_PARSE_EXCEPTION,
- new Object [] {
- "" + pAttributeName,
- "" + pAttributeValue,
- exc.getMessage ()
- });
- }
- }
-
- //-------------------------------------
- /**
- *
- * Evaluates the expression at request time
- **/
- public Object evaluate (String pAttributeName,
- String pAttributeValue,
- Class pExpectedType,
- Tag pTag,
- PageContext pPageContext,
- Map functions,
- String defaultPrefix)
- throws JspException
- {
- try {
- return sEvaluator.evaluate
- (pAttributeValue,
- pPageContext,
- pExpectedType,
- functions,
- defaultPrefix);
- }
- catch (ELException exc) {
- throw new JspException
- (MessageFormat.format
- (Constants.ATTRIBUTE_EVALUATION_EXCEPTION,
- new Object [] {
- "" + pAttributeName,
- "" + pAttributeValue,
- exc.getMessage(),
- exc.getRootCause()
- }), exc.getRootCause());
- }
- }
-
- /** Conduit to old-style call for convenience. */
- public Object evaluate (String pAttributeName,
- String pAttributeValue,
- Class pExpectedType,
- Tag pTag,
- PageContext pPageContext)
- throws JspException
- {
- return evaluate(pAttributeName,
- pAttributeValue,
- pExpectedType,
- pTag,
- pPageContext,
- null,
- null);
- }
-
-
- //-------------------------------------
- // Testing methods
- //-------------------------------------
- /**
- *
- * Parses the given attribute value, then converts it back to a
- * String in its canonical form.
- **/
- public static String parseAndRender (String pAttributeValue)
- throws JspException
- {
- try {
- return sEvaluator.parseAndRender (pAttributeValue);
- }
- catch (ELException exc) {
- throw new JspException
- (MessageFormat.format
- (Constants.ATTRIBUTE_PARSE_EXCEPTION,
- new Object [] {
- "test",
- "" + pAttributeValue,
- exc.getMessage ()
- }));
+ implements ExpressionEvaluator {
+ //-------------------------------------
+ // Properties
+ //-------------------------------------
+
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ /**
+ * The singleton instance of the evaluator *
+ */
+ static ELEvaluator sEvaluator =
+ new ELEvaluator
+ (new JSTLVariableResolver());
+
+ //-------------------------------------
+ // ExpressionEvaluator methods
+ //-------------------------------------
+
+ /**
+ * Translation time validation of an attribute value. This method
+ * will return a null String if the attribute value is valid;
+ * otherwise an error message.
+ */
+ public String validate(String pAttributeName,
+ String pAttributeValue) {
+ try {
+ sEvaluator.setBypassCache(true);
+ sEvaluator.parseExpressionString(pAttributeValue);
+ sEvaluator.setBypassCache(false);
+ return null;
+ }
+ catch (ELException exc) {
+ return
+ MessageFormat.format
+ (Constants.ATTRIBUTE_PARSE_EXCEPTION,
+ new Object[]{
+ "" + pAttributeName,
+ "" + pAttributeValue,
+ exc.getMessage()
+ });
+ }
+ }
+
+ //-------------------------------------
+
+ /**
+ * Evaluates the expression at request time
+ */
+ public Object evaluate(String pAttributeName,
+ String pAttributeValue,
+ Class pExpectedType,
+ Tag pTag,
+ PageContext pPageContext,
+ Map functions,
+ String defaultPrefix)
+ throws JspException {
+ try {
+ return sEvaluator.evaluate
+ (pAttributeValue,
+ pPageContext,
+ pExpectedType,
+ functions,
+ defaultPrefix);
+ }
+ catch (ELException exc) {
+ throw new JspException
+ (MessageFormat.format
+ (Constants.ATTRIBUTE_EVALUATION_EXCEPTION,
+ new Object[]{
+ "" + pAttributeName,
+ "" + pAttributeValue,
+ exc.getMessage(),
+ exc.getRootCause()
+ }), exc.getRootCause());
+ }
+ }
+
+ /**
+ * Conduit to old-style call for convenience.
+ */
+ public Object evaluate(String pAttributeName,
+ String pAttributeValue,
+ Class pExpectedType,
+ Tag pTag,
+ PageContext pPageContext)
+ throws JspException {
+ return evaluate(pAttributeName,
+ pAttributeValue,
+ pExpectedType,
+ pTag,
+ pPageContext,
+ null,
+ null);
+ }
+
+
+ //-------------------------------------
+ // Testing methods
+ //-------------------------------------
+
+ /**
+ * Parses the given attribute value, then converts it back to a
+ * String in its canonical form.
+ */
+ public static String parseAndRender(String pAttributeValue)
+ throws JspException {
+ try {
+ return sEvaluator.parseAndRender(pAttributeValue);
+ }
+ catch (ELException exc) {
+ throw new JspException
+ (MessageFormat.format
+ (Constants.ATTRIBUTE_PARSE_EXCEPTION,
+ new Object[]{
+ "test",
+ "" + pAttributeValue,
+ exc.getMessage()
+ }));
+ }
}
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Expression.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Expression.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Expression.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Expression.java Sat Nov 20 18:14:00 2010
@@ -13,47 +13,45 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
import java.util.Map;
/**
- *
* <p>The abstract class from which all expression types
* derive.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @author Shawn Bayern
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
-public abstract class Expression
-{
- //-------------------------------------
- // Member variables
- //-------------------------------------
-
- //-------------------------------------
- /**
- *
- * Returns the expression in the expression language syntax
- **/
- public abstract String getExpressionString ();
-
- //-------------------------------------
- /**
- *
- * Evaluates the expression in the given context
- **/
- public abstract Object evaluate (Object pContext,
- VariableResolver pResolver,
- Map functions,
- String defaultPrefix,
- Logger pLogger)
- throws ELException;
+public abstract class Expression {
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ //-------------------------------------
+
+ /**
+ * Returns the expression in the expression language syntax
+ */
+ public abstract String getExpressionString();
+
+ //-------------------------------------
+
+ /**
+ * Evaluates the expression in the given context
+ */
+ public abstract Object evaluate(Object pContext,
+ VariableResolver pResolver,
+ Map functions,
+ String defaultPrefix,
+ Logger pLogger)
+ throws ELException;
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ExpressionString.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ExpressionString.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ExpressionString.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/ExpressionString.java Sat Nov 20 18:14:00 2010
@@ -13,101 +13,98 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
import java.util.Map;
/**
- *
* <p>Represents an expression String consisting of a mixture of
* Strings and Expressions.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @author Shawn Bayern
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
+
+public class ExpressionString {
+ //-------------------------------------
+ // Properties
+ //-------------------------------------
+ // property elements
+
+ Object[] mElements;
-public class ExpressionString
-{
- //-------------------------------------
- // Properties
- //-------------------------------------
- // property elements
-
- Object [] mElements;
- public Object [] getElements ()
- { return mElements; }
- public void setElements (Object [] pElements)
- { mElements = pElements; }
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public ExpressionString (Object [] pElements)
- {
- mElements = pElements;
- }
-
- //-------------------------------------
- /**
- *
- * Evaluates the expression string by evaluating each element,
- * converting it to a String (using toString, or "" for null values)
- * and concatenating the results into a single String.
- **/
- public String evaluate (Object pContext,
- VariableResolver pResolver,
- Map functions,
- String defaultPrefix,
- Logger pLogger)
- throws ELException
- {
- StringBuffer buf = new StringBuffer ();
- for (int i = 0; i < mElements.length; i++) {
- Object elem = mElements [i];
- if (elem instanceof String) {
- buf.append ((String) elem);
- }
- else if (elem instanceof Expression) {
- Object val =
- ((Expression) elem).evaluate (pContext,
- pResolver,
- functions,
- defaultPrefix,
- pLogger);
- if (val != null) {
- buf.append (val.toString ());
- }
- }
+ public Object[] getElements() {
+ return mElements;
}
- return buf.toString ();
- }
- //-------------------------------------
- /**
- *
- * Returns the expression in the expression language syntax
- **/
- public String getExpressionString ()
- {
- StringBuffer buf = new StringBuffer ();
- for (int i = 0; i < mElements.length; i++) {
- Object elem = mElements [i];
- if (elem instanceof String) {
- buf.append ((String) elem);
- }
- else if (elem instanceof Expression) {
- buf.append ("${");
- buf.append (((Expression) elem).getExpressionString ());
- buf.append ("}");
- }
+ public void setElements(Object[] pElements) {
+ mElements = pElements;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public ExpressionString(Object[] pElements) {
+ mElements = pElements;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Evaluates the expression string by evaluating each element,
+ * converting it to a String (using toString, or "" for null values)
+ * and concatenating the results into a single String.
+ */
+ public String evaluate(Object pContext,
+ VariableResolver pResolver,
+ Map functions,
+ String defaultPrefix,
+ Logger pLogger)
+ throws ELException {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < mElements.length; i++) {
+ Object elem = mElements[i];
+ if (elem instanceof String) {
+ buf.append((String) elem);
+ } else if (elem instanceof Expression) {
+ Object val =
+ ((Expression) elem).evaluate(pContext,
+ pResolver,
+ functions,
+ defaultPrefix,
+ pLogger);
+ if (val != null) {
+ buf.append(val.toString());
+ }
+ }
+ }
+ return buf.toString();
+ }
+
+ //-------------------------------------
+
+ /**
+ * Returns the expression in the expression language syntax
+ */
+ public String getExpressionString() {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < mElements.length; i++) {
+ Object elem = mElements[i];
+ if (elem instanceof String) {
+ buf.append((String) elem);
+ } else if (elem instanceof Expression) {
+ buf.append("${");
+ buf.append(((Expression) elem).getExpressionString());
+ buf.append("}");
+ }
+ }
+ return buf.toString();
}
- return buf.toString ();
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FloatingPointLiteral.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FloatingPointLiteral.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FloatingPointLiteral.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FloatingPointLiteral.java Sat Nov 20 18:14:00 2010
@@ -13,53 +13,48 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
/**
- *
* <p>An expression representing a floating point literal value. The
* value is stored internally as a double.
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public class FloatingPointLiteral
- extends Literal
-{
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public FloatingPointLiteral (String pToken)
- {
- super (getValueFromToken (pToken));
- }
-
- //-------------------------------------
- /**
- *
- * Parses the given token into the literal value
- **/
- static Object getValueFromToken (String pToken)
- {
- return new Double (pToken);
- }
-
- //-------------------------------------
- // Expression methods
- //-------------------------------------
- /**
- *
- * Returns the expression in the expression language syntax
- **/
- public String getExpressionString ()
- {
- return getValue ().toString ();
- }
+ extends Literal {
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public FloatingPointLiteral(String pToken) {
+ super(getValueFromToken(pToken));
+ }
+
+ //-------------------------------------
+
+ /**
+ * Parses the given token into the literal value
+ */
+ static Object getValueFromToken(String pToken) {
+ return new Double(pToken);
+ }
+
+ //-------------------------------------
+ // Expression methods
+ //-------------------------------------
+
+ /**
+ * Returns the expression in the expression language syntax
+ */
+ public String getExpressionString() {
+ return getValue().toString();
+ }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FunctionInvocation.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FunctionInvocation.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FunctionInvocation.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/FunctionInvocation.java Sat Nov 20 18:14:00 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
@@ -24,122 +24,136 @@ import java.util.List;
import java.util.Map;
/**
- *
* <p>Represents a function call.</p>
- *
+ *
* @author Shawn Bayern (in the style of Nathan's other classes)
- **/
+ */
public class FunctionInvocation
- extends Expression
-{
- //-------------------------------------
- // Properties
- //-------------------------------------
- // property index
-
- private String functionName;
- private List argumentList;
- public String getFunctionName() { return functionName; }
- public void setFunctionName(String f) { functionName = f; }
- public List getArgumentList() { return argumentList; }
- public void setArgumentList(List l) { argumentList = l; }
-
- //-------------------------------------
- /**
- * Constructor
- **/
- public FunctionInvocation (String functionName, List argumentList)
- {
- this.functionName = functionName;
- this.argumentList = argumentList;
- }
-
- //-------------------------------------
- // Expression methods
- //-------------------------------------
- /**
- * Returns the expression in the expression language syntax
- **/
- public String getExpressionString ()
- {
- StringBuffer b = new StringBuffer();
- b.append(functionName);
- b.append("(");
- Iterator i = argumentList.iterator();
- while (i.hasNext()) {
- b.append(((Expression) i.next()).getExpressionString());
- if (i.hasNext())
- b.append(", ");
- }
- b.append(")");
- return b.toString();
- }
-
-
- //-------------------------------------
- /**
- *
- * Evaluates by looking up the name in the VariableResolver
- **/
- public Object evaluate (Object pContext,
- VariableResolver pResolver,
- Map functions,
- String defaultPrefix,
- Logger pLogger)
- throws ELException
- {
-
- // if the Map is null, then the function is invalid
- if (functions == null)
- pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
-
- // normalize function name against default prefix
- String functionName = this.functionName;
- if (functionName.indexOf(":") == -1) {
- if (defaultPrefix == null)
- pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
- functionName = defaultPrefix + ":" + functionName;
- }
-
- // ensure that the function's name is mapped
- Method target = (Method) functions.get(functionName);
- if (target == null)
- pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
-
- // ensure that the number of arguments matches the number of parameters
- Class[] params = target.getParameterTypes();
- if (params.length != argumentList.size())
- pLogger.logError(Constants.INAPPROPRIATE_FUNCTION_ARG_COUNT,
- new Integer(params.length),
- new Integer(argumentList.size()));
-
- // now, walk through each parameter, evaluating and casting its argument
- Object[] arguments = new Object[argumentList.size()];
- for (int i = 0; i < params.length; i++) {
- // evaluate
- arguments[i] = ((Expression) argumentList.get(i)).evaluate(pContext,
- pResolver,
- functions,
- defaultPrefix,
- pLogger);
- // coerce
- arguments[i] = Coercions.coerce(arguments[i], params[i], pLogger);
- }
-
- // finally, invoke the target method, which we know to be static
- try {
- return (target.invoke(null, arguments));
- } catch (InvocationTargetException ex) {
- pLogger.logError(Constants.FUNCTION_INVOCATION_ERROR,
- ex.getTargetException(),
- functionName);
- return null;
- } catch (Exception ex) {
- pLogger.logError(Constants.FUNCTION_INVOCATION_ERROR, ex, functionName);
- return null;
+ extends Expression {
+ //-------------------------------------
+ // Properties
+ //-------------------------------------
+ // property index
+
+ private String functionName;
+ private List argumentList;
+
+ public String getFunctionName() {
+ return functionName;
+ }
+
+ public void setFunctionName(String f) {
+ functionName = f;
+ }
+
+ public List getArgumentList() {
+ return argumentList;
+ }
+
+ public void setArgumentList(List l) {
+ argumentList = l;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public FunctionInvocation(String functionName, List argumentList) {
+ this.functionName = functionName;
+ this.argumentList = argumentList;
+ }
+
+ //-------------------------------------
+ // Expression methods
+ //-------------------------------------
+
+ /**
+ * Returns the expression in the expression language syntax
+ */
+ public String getExpressionString() {
+ StringBuffer b = new StringBuffer();
+ b.append(functionName);
+ b.append("(");
+ Iterator i = argumentList.iterator();
+ while (i.hasNext()) {
+ b.append(((Expression) i.next()).getExpressionString());
+ if (i.hasNext()) {
+ b.append(", ");
+ }
+ }
+ b.append(")");
+ return b.toString();
+ }
+
+
+ //-------------------------------------
+
+ /**
+ * Evaluates by looking up the name in the VariableResolver
+ */
+ public Object evaluate(Object pContext,
+ VariableResolver pResolver,
+ Map functions,
+ String defaultPrefix,
+ Logger pLogger)
+ throws ELException {
+
+ // if the Map is null, then the function is invalid
+ if (functions == null) {
+ pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
+ }
+
+ // normalize function name against default prefix
+ String functionName = this.functionName;
+ if (functionName.indexOf(":") == -1) {
+ if (defaultPrefix == null) {
+ pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
+ }
+ functionName = defaultPrefix + ":" + functionName;
+ }
+
+ // ensure that the function's name is mapped
+ Method target = (Method) functions.get(functionName);
+ if (target == null) {
+ pLogger.logError(Constants.UNKNOWN_FUNCTION, functionName);
+ }
+
+ // ensure that the number of arguments matches the number of parameters
+ Class[] params = target.getParameterTypes();
+ if (params.length != argumentList.size()) {
+ pLogger.logError(Constants.INAPPROPRIATE_FUNCTION_ARG_COUNT,
+ new Integer(params.length),
+ new Integer(argumentList.size()));
+ }
+
+ // now, walk through each parameter, evaluating and casting its argument
+ Object[] arguments = new Object[argumentList.size()];
+ for (int i = 0; i < params.length; i++) {
+ // evaluate
+ arguments[i] = ((Expression) argumentList.get(i)).evaluate(pContext,
+ pResolver,
+ functions,
+ defaultPrefix,
+ pLogger);
+ // coerce
+ arguments[i] = Coercions.coerce(arguments[i], params[i], pLogger);
+ }
+
+ // finally, invoke the target method, which we know to be static
+ try {
+ return (target.invoke(null, arguments));
+ } catch (InvocationTargetException ex) {
+ pLogger.logError(Constants.FUNCTION_INVOCATION_ERROR,
+ ex.getTargetException(),
+ functionName);
+ return null;
+ } catch (Exception ex) {
+ pLogger.logError(Constants.FUNCTION_INVOCATION_ERROR, ex, functionName);
+ return null;
+ }
}
- }
- //-------------------------------------
+ //-------------------------------------
}
Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/GreaterThanOperator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/GreaterThanOperator.java?rev=1037284&r1=1037283&r2=1037284&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/GreaterThanOperator.java (original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/GreaterThanOperator.java Sat Nov 20 18:14:00 2010
@@ -13,107 +13,97 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.lang.jstl;
/**
- *
* <p>The implementation of the greater than operator
- *
+ *
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- **/
+ */
public class GreaterThanOperator
- extends RelationalOperator
-{
- //-------------------------------------
- // Singleton
- //-------------------------------------
-
- public static final GreaterThanOperator SINGLETON =
- new GreaterThanOperator ();
-
- //-------------------------------------
- /**
- *
- * Constructor
- **/
- public GreaterThanOperator ()
- {
- }
-
- //-------------------------------------
- // Expression methods
- //-------------------------------------
- /**
- *
- * Returns the symbol representing the operator
- **/
- public String getOperatorSymbol ()
- {
- return ">";
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator to the given value
- **/
- public Object apply (Object pLeft,
- Object pRight,
- Object pContext,
- Logger pLogger)
- throws ELException
- {
- if (pLeft == pRight) {
- return Boolean.FALSE;
- }
- else if (pLeft == null ||
- pRight == null) {
- return Boolean.FALSE;
- }
- else {
- return super.apply (pLeft, pRight, pContext, pLogger);
- }
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator to the given double values
- **/
- public boolean apply (double pLeft,
- double pRight,
- Logger pLogger)
- {
- return pLeft > pRight;
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator to the given long values
- **/
- public boolean apply (long pLeft,
- long pRight,
- Logger pLogger)
- {
- return pLeft > pRight;
- }
-
- //-------------------------------------
- /**
- *
- * Applies the operator to the given String values
- **/
- public boolean apply (String pLeft,
- String pRight,
- Logger pLogger)
- {
- return pLeft.compareTo (pRight) > 0;
- }
+ extends RelationalOperator {
+ //-------------------------------------
+ // Singleton
+ //-------------------------------------
+
+ public static final GreaterThanOperator SINGLETON =
+ new GreaterThanOperator();
+
+ //-------------------------------------
+
+ /**
+ * Constructor
+ */
+ public GreaterThanOperator() {
+ }
+
+ //-------------------------------------
+ // Expression methods
+ //-------------------------------------
+
+ /**
+ * Returns the symbol representing the operator
+ */
+ public String getOperatorSymbol() {
+ return ">";
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator to the given value
+ */
+ public Object apply(Object pLeft,
+ Object pRight,
+ Object pContext,
+ Logger pLogger)
+ throws ELException {
+ if (pLeft == pRight) {
+ return Boolean.FALSE;
+ } else if (pLeft == null ||
+ pRight == null) {
+ return Boolean.FALSE;
+ } else {
+ return super.apply(pLeft, pRight, pContext, pLogger);
+ }
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator to the given double values
+ */
+ public boolean apply(double pLeft,
+ double pRight,
+ Logger pLogger) {
+ return pLeft > pRight;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator to the given long values
+ */
+ public boolean apply(long pLeft,
+ long pRight,
+ Logger pLogger) {
+ return pLeft > pRight;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Applies the operator to the given String values
+ */
+ public boolean apply(String pLeft,
+ String pRight,
+ Logger pLogger) {
+ return pLeft.compareTo(pRight) > 0;
+ }
- //-------------------------------------
+ //-------------------------------------
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org