kinman 2003/10/29 18:39:48 Modified: jasper2/src/share/org/apache/jasper/compiler ELFunctionMapper.java ELNode.java ELParser.java Log: - Add some javacdocs. Revision Changes Path 1.14 +33 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELFunctionMapper.java Index: ELFunctionMapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELFunctionMapper.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ELFunctionMapper.java 22 Sep 2003 21:01:20 -0000 1.13 +++ ELFunctionMapper.java 30 Oct 2003 02:39:48 -0000 1.14 @@ -62,18 +62,26 @@ import org.apache.jasper.JasperException; /** - * This class generates a mapper for an EL expression + * This class generates functions mappers for the EL expressions in the page. * Instead of a global mapper, a mapper is used for ecah call to EL * evaluator, thus avoiding the prefix overlapping and redefinition * issues. + * + * @author Kin-man Chung */ public class ELFunctionMapper { static private int currFunc = 0; private ErrorDispatcher err; - StringBuffer ds; - StringBuffer ss; + StringBuffer ds; // Contains codes to initialize the functions mappers. + StringBuffer ss; // Contains declarations of the functions mappers. + /** + * Creates the functions mappers for all EL expressions in the JSP page. + * + * @param compiler Current compiler, mainly for accessing error dispatcher. + * @param page The current compilation unit. + */ public static void map(Compiler compiler, Node.Nodes page) throws JasperException { @@ -94,6 +102,10 @@ } } + /** + * A visitor for the page. The places where EL is allowed are scanned + * for functions, and if found functions mappers are created. + */ class ELFunctionVisitor extends Node.Visitor { /** @@ -171,9 +183,13 @@ } } + /** + * Creates function mappers, if needed, from ELNodes + */ private void doMap(ELNode.Nodes el) throws JasperException { + // Only care about functions in ELNode's class Fvisitor extends ELNode.Visitor { ArrayList funcs = new ArrayList(); HashMap keyMap = new HashMap(); @@ -190,7 +206,7 @@ return; } - // First locate all functions in this expression + // First locate all unique functions in this EL Fvisitor fv = new Fvisitor(); el.visit(fv); ArrayList functions = fv.funcs; @@ -212,6 +228,7 @@ ds.append(" " + decName + "= "); ds.append("org.apache.jasper.runtime.ProtectedFunctionMapper"); + // Special case if there is only one function in the map String funcMethod = null; if (functions.size() == 1) { @@ -221,6 +238,7 @@ funcMethod = " " + decName + ".mapFunction"; } + // Setup arguments for either getMapForFunction or mapFunction for (int i = 0; i < functions.size(); i++) { ELNode.Function f = (ELNode.Function)functions.get(i); FunctionInfo funcInfo = f.getFunctionInfo(); @@ -266,6 +284,14 @@ el.setMapName(decName); } + /** + * Find the name of the function mapper for an EL. Reuse a + * previously generated one if possible. + * @param functions An ArrayList of ELNode.Function instances that + * represents the functions in an EL + * @return A previous generated function mapper name that can be used + * by this EL; null if none found. + */ private String matchMap(ArrayList functions) { String mapName = null; @@ -286,6 +312,9 @@ return mapName; } + /* + * @return An unique name for a function mapper. + */ private String getMapName() { return "_jspx_fnmap_" + currFunc++; } 1.4 +10 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELNode.java Index: ELNode.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELNode.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ELNode.java 25 Mar 2003 01:49:29 -0000 1.3 +++ ELNode.java 30 Oct 2003 02:39:48 -0000 1.4 @@ -66,6 +66,8 @@ * * It currently only defines functions. It can be expanded to define * all the components of an EL expression, if need to. + * + * @author Kin-man Chung */ abstract class ELNode { @@ -118,7 +120,8 @@ } /** - * Represents anything else EL expression, including function arguments etc + * Represents anything in EL expression, other than functions, including + * function arguments etc */ public static class ELText extends ELNode { @@ -139,7 +142,8 @@ /** * Represents a function - * Currently only the prefix and function name, but not its arguments. + * Currently only include the prefix and function name, but not its + * arguments. */ public static class Function extends ELNode { @@ -208,7 +212,7 @@ /* Name used for creating a map for the functions in this EL expression, for communication to Generator. */ - String mapName = null; + String mapName = null; // The function map associated this EL private List list; public Nodes() { @@ -262,6 +266,9 @@ } } + /* + * A visitor class for traversing ELNodes + */ public static class Visitor { public void visit(Root n) throws JasperException { 1.2 +44 -6 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELParser.java Index: ELParser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ELParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ELParser.java 19 Mar 2003 20:51:34 -0000 1.1 +++ ELParser.java 30 Oct 2003 02:39:48 -0000 1.2 @@ -64,6 +64,8 @@ * a ELNode.Nodes. * * Currently, it only handles text outside ${..} and functions in ${ ..}. + * + * @author Kin-man Chung */ public class ELParser { @@ -81,6 +83,12 @@ expr = new ELNode.Nodes(); } + /** + * Parse an EL expression + * @param expression The input expression string of the form + * Char* ('${' Char* '}')* Char* + * @return Parsed EL expression in ELNode.Nodes + */ public static ELNode.Nodes parse(String expression) { ELParser parser = new ELParser(expression); while (parser.hasNextChar()) { @@ -97,9 +105,10 @@ } /** - * Parse EL into functions and else. - [EMAIL PROTECTED] An ELLNode.Nodes representing the EL expression - * TODO: this should be rewritten for a full parser. + * Parse an EL expression string '${...}' + [EMAIL PROTECTED] An ELNode.Nodes representing the EL expression + * TODO: Currently only parsed into functions and text strings. This + * should be rewritten for a full parser. */ private ELNode.Nodes parseEL() { @@ -139,8 +148,8 @@ if (! (curToken instanceof Id)) { return false; } - String s1 = null; - String s2 = curToken.toString(); + String s1 = null; // Function prefix + String s2 = curToken.toString(); // Function name int mark = getIndex(); if (hasNext()) { Token t = nextToken(); @@ -166,7 +175,8 @@ } /** - * Skip until an EL expression is reached. + * Skip until an EL expression ('${') is reached, allowing escape sequences + * '\\' and '\$'. * @return The text string up to the EL expression */ private String skipUntilEL() { @@ -203,11 +213,18 @@ return buf.toString(); } + /* + * @return true if there is something left in EL expression buffer other + * than white spaces. + */ private boolean hasNext() { skipSpaces(); return hasNextChar(); } + /* + * @return The next token in the EL expression buffer. + */ private Token nextToken() { skipSpaces(); if (hasNextChar()) { @@ -233,6 +250,10 @@ return null; } + /* + * Parse a string in single or double quotes, allowing for escape sequences + * '\\', and ('\"', or "\'") + */ private Token parseQuotedChars(char quote) { StringBuffer buf = new StringBuffer(); buf.append(quote); @@ -254,6 +275,11 @@ return new QuotedString(buf.toString()); } + /* + * A collection of low level parse methods dealing with character in + * the EL expression buffer. + */ + private void skipSpaces() { while (hasNextChar()) { if (expression.charAt(index) > ' ') @@ -288,6 +314,9 @@ index = i; } + /* + * Represents a token in EL expression string + */ private static class Token { char toChar() { @@ -299,6 +328,9 @@ } } + /* + * Represents an ID token in EL + */ private static class Id extends Token { String id; @@ -311,6 +343,9 @@ } } + /* + * Represents a character token in EL + */ private static class Char extends Token { private char ch; @@ -328,6 +363,9 @@ } } + /* + * Represents a quoted (single or double) string token in EL + */ private static class QuotedString extends Token { private String value;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]