http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java index 1b4e21c..aa5b4c3 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/JspUtil.java @@ -17,19 +17,7 @@ package org.apache.struts2.jasper.compiler; -import java.io.CharArrayWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.util.Vector; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; - -import javax.el.FunctionMapper; -import javax.servlet.jsp.el.ExpressionEvaluator; - - +import org.apache.commons.lang3.BooleanUtils; import org.apache.struts2.el.ExpressionFactoryImpl; import org.apache.struts2.jasper.Constants; import org.apache.struts2.jasper.JasperException; @@ -37,7 +25,14 @@ import org.apache.struts2.jasper.JspCompilationContext; import org.apache.struts2.jasper.el.ExpressionEvaluatorImpl; import org.xml.sax.Attributes; -/** +import javax.el.FunctionMapper; +import javax.servlet.jsp.el.ExpressionEvaluator; +import java.io.*; +import java.util.Vector; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +/** * This class has all the utility method(s). * Ideally should move all the bean containers here. * @@ -54,39 +49,39 @@ public class JspUtil { private static final String META_INF_TAGS = "/META-INF/tags/"; // Delimiters for request-time expressions (JSP and XML syntax) - private static final String OPEN_EXPR = "<%="; + private static final String OPEN_EXPR = "<%="; private static final String CLOSE_EXPR = "%>"; - private static final String OPEN_EXPR_XML = "%="; + private static final String OPEN_EXPR_XML = "%="; private static final String CLOSE_EXPR_XML = "%"; private static int tempSequenceNumber = 0; - + //private static ExpressionEvaluatorImpl expressionEvaluator //= new ExpressionEvaluatorImpl(); - + //tc6 private final static ExpressionEvaluator expressionEvaluator = - new ExpressionEvaluatorImpl(new ExpressionFactoryImpl()); + new ExpressionEvaluatorImpl(new ExpressionFactoryImpl()); private static final String javaKeywords[] = { - "abstract", "assert", "boolean", "break", "byte", "case", - "catch", "char", "class", "const", "continue", - "default", "do", "double", "else", "enum", "extends", - "final", "finally", "float", "for", "goto", - "if", "implements", "import", "instanceof", "int", - "interface", "long", "native", "new", "package", - "private", "protected", "public", "return", "short", - "static", "strictfp", "super", "switch", "synchronized", - "this", "throws", "transient", "try", "void", - "volatile", "while" }; + "abstract", "assert", "boolean", "break", "byte", "case", + "catch", "char", "class", "const", "continue", + "default", "do", "double", "else", "enum", "extends", + "final", "finally", "float", "for", "goto", + "if", "implements", "import", "instanceof", "int", + "interface", "long", "native", "new", "package", + "private", "protected", "public", "return", "short", + "static", "strictfp", "super", "switch", "synchronized", + "this", "throws", "transient", "try", "void", + "volatile", "while"}; public static final int CHUNKSIZE = 1024; - - public static char[] removeQuotes(char []chars) { + + public static char[] removeQuotes(char[] chars) { CharArrayWriter caw = new CharArrayWriter(); for (int i = 0; i < chars.length; i++) { - if (chars[i] == '%' && chars[i+1] == '\\' && - chars[i+2] == '>') { + if (chars[i] == '%' && chars[i + 1] == '\\' && + chars[i + 2] == '>') { caw.write('%'); caw.write('>'); i = i + 2; @@ -97,7 +92,7 @@ public class JspUtil { return caw.toCharArray(); } - public static char[] escapeQuotes (char []chars) { + public static char[] escapeQuotes(char[] chars) { // Prescan to convert %\> to %> String s = new String(chars); while (true) { @@ -129,66 +124,72 @@ public class JspUtil { /** * Checks if the token is a runtime expression. - * In standard JSP syntax, a runtime expression starts with '<%' and - * ends with '%>'. When the JSP document is in XML syntax, a runtime + * In standard JSP syntax, a runtime expression starts with '<%' and + * ends with '%>'. When the JSP document is in XML syntax, a runtime * expression starts with '%=' and ends with '%'. * * @param token The token to be checked - * return whether the token is a runtime expression or not. + * @param isXml is xml syntax + * @return whether the token is a runtime expression or not. */ public static boolean isExpression(String token, boolean isXml) { - String openExpr; - String closeExpr; - if (isXml) { - openExpr = OPEN_EXPR_XML; - closeExpr = CLOSE_EXPR_XML; - } else { - openExpr = OPEN_EXPR; - closeExpr = CLOSE_EXPR; - } - if (token.startsWith(openExpr) && token.endsWith(closeExpr)) { - return true; - } else { - return false; - } + String openExpr; + String closeExpr; + if (isXml) { + openExpr = OPEN_EXPR_XML; + closeExpr = CLOSE_EXPR_XML; + } else { + openExpr = OPEN_EXPR; + closeExpr = CLOSE_EXPR; + } + if (token.startsWith(openExpr) && token.endsWith(closeExpr)) { + return true; + } else { + return false; + } } /** - * @return the "expression" part of a runtime expression, + * @param expression expression string + * @param isXml is xml + * @return the "expression" part of a runtime expression, * taking the delimiters out. */ - public static String getExpr (String expression, boolean isXml) { - String returnString; - String openExpr; - String closeExpr; - if (isXml) { - openExpr = OPEN_EXPR_XML; - closeExpr = CLOSE_EXPR_XML; - } else { - openExpr = OPEN_EXPR; - closeExpr = CLOSE_EXPR; - } - int length = expression.length(); - if (expression.startsWith(openExpr) && + public static String getExpr(String expression, boolean isXml) { + String returnString; + String openExpr; + String closeExpr; + if (isXml) { + openExpr = OPEN_EXPR_XML; + closeExpr = CLOSE_EXPR_XML; + } else { + openExpr = OPEN_EXPR; + closeExpr = CLOSE_EXPR; + } + int length = expression.length(); + if (expression.startsWith(openExpr) && expression.endsWith(closeExpr)) { - returnString = expression.substring( - openExpr.length(), length - closeExpr.length()); - } else { - returnString = ""; - } - return returnString; + returnString = expression.substring( + openExpr.length(), length - closeExpr.length()); + } else { + returnString = ""; + } + return returnString; } /** * Takes a potential expression and converts it into XML form + * + * @param expression expression string + * @return expressions as xml */ public static String getExprInXml(String expression) { String returnString; int length = expression.length(); - if (expression.startsWith(OPEN_EXPR) + if (expression.startsWith(OPEN_EXPR) && expression.endsWith(CLOSE_EXPR)) { - returnString = expression.substring (1, length - 1); + returnString = expression.substring(1, length - 1); } else { returnString = expression; } @@ -200,40 +201,45 @@ public class JspUtil { * Checks to see if the given scope is valid. * * @param scope The scope to be checked - * @param n The Node containing the 'scope' attribute whose value is to be - * checked - * @param err error dispatcher - * + * @param n The Node containing the 'scope' attribute whose value is to be + * checked + * @param err error dispatcher * @throws JasperException if scope is not null and different from - * "page", "request", "session", and - * "application" + * "page", "request", "session", and + * "application" */ public static void checkScope(String scope, Node n, ErrorDispatcher err) throws JasperException { - if (scope != null && !scope.equals("page") && !scope.equals("request") - && !scope.equals("session") && !scope.equals("application")) { - err.jspError(n, "jsp.error.invalid.scope", scope); - } + if (scope != null && !scope.equals("page") && !scope.equals("request") + && !scope.equals("session") && !scope.equals("application")) { + err.jspError(n, "jsp.error.invalid.scope", scope); + } } /** * Checks if all mandatory attributes are present and if all attributes * present have valid names. Checks attributes specified as XML-style * attributes as well as attributes specified using the jsp:attribute - * standard action. + * standard action. + * + * @param typeOfTag type of tag + * @param n node + * @param validAttributes valid attributes + * @param err error dispatcher + * @throws JasperException in case of Jasper errors */ public static void checkAttributes(String typeOfTag, - Node n, - ValidAttribute[] validAttributes, - ErrorDispatcher err) - throws JasperException { + Node n, + ValidAttribute[] validAttributes, + ErrorDispatcher err) + throws JasperException { Attributes attrs = n.getAttributes(); Mark start = n.getStart(); - boolean valid = true; + boolean valid = true; // AttributesImpl.removeAttribute is broken, so we do this... int tempLength = (attrs == null) ? 0 : attrs.getLength(); - Vector temp = new Vector(tempLength, 1); + Vector temp = new Vector(tempLength, 1); for (int i = 0; i < tempLength; i++) { String qName = attrs.getQName(i); if ((!qName.equals("xmlns")) && (!qName.startsWith("xmlns:"))) @@ -242,20 +248,19 @@ public class JspUtil { // Add names of attributes specified using jsp:attribute Node.Nodes tagBody = n.getBody(); - if( tagBody != null ) { + if (tagBody != null) { int numSubElements = tagBody.size(); - for( int i = 0; i < numSubElements; i++ ) { - Node node = tagBody.getNode( i ); - if( node instanceof Node.NamedAttribute ) { - String attrName = node.getAttributeValue( "name" ); - temp.addElement( attrName ); - // Check if this value appear in the attribute of the node - if (n.getAttributeValue(attrName) != null) { - err.jspError(n, "jsp.error.duplicate.name.jspattribute", - attrName); - } - } - else { + for (int i = 0; i < numSubElements; i++) { + Node node = tagBody.getNode(i); + if (node instanceof Node.NamedAttribute) { + String attrName = node.getAttributeValue("name"); + temp.addElement(attrName); + // Check if this value appear in the attribute of the node + if (n.getAttributeValue(attrName) != null) { + err.jspError(n, "jsp.error.duplicate.name.jspattribute", + attrName); + } + } else { // Nothing can come before jsp:attribute, and only // jsp:body can come after it. break; @@ -268,77 +273,80 @@ public class JspUtil { * If so only then proceed to see if the other attributes are valid * for the particular tag. */ - String missingAttribute = null; - - for (int i = 0; i < validAttributes.length; i++) { - int attrPos; - if (validAttributes[i].mandatory) { - attrPos = temp.indexOf(validAttributes[i].name); - if (attrPos != -1) { - temp.remove(attrPos); - valid = true; - } else { - valid = false; - missingAttribute = validAttributes[i].name; - break; - } + String missingAttribute = null; + + for (ValidAttribute validAttribute : validAttributes) { + int attrPos; + if (validAttribute.mandatory) { + attrPos = temp.indexOf(validAttribute.name); + if (attrPos != -1) { + temp.remove(attrPos); + valid = true; + } else { + valid = false; + missingAttribute = validAttribute.name; + break; + } + } } - } - // If mandatory attribute is missing then the exception is thrown - if (!valid) - err.jspError(start, "jsp.error.mandatory.attribute", typeOfTag, - missingAttribute); + // If mandatory attribute is missing then the exception is thrown + if (!valid) + err.jspError(start, "jsp.error.mandatory.attribute", typeOfTag, + missingAttribute); - // Check to see if there are any more attributes for the specified tag. + // Check to see if there are any more attributes for the specified tag. int attrLeftLength = temp.size(); - if (attrLeftLength == 0) - return; - - // Now check to see if the rest of the attributes are valid too. - String attribute = null; - - for (int j = 0; j < attrLeftLength; j++) { - valid = false; - attribute = (String) temp.elementAt(j); - for (int i = 0; i < validAttributes.length; i++) { - if (attribute.equals(validAttributes[i].name)) { - valid = true; - break; - } + if (attrLeftLength == 0) + return; + + // Now check to see if the rest of the attributes are valid too. + String attribute = null; + + for (int j = 0; j < attrLeftLength; j++) { + valid = false; + attribute = (String) temp.elementAt(j); + for (ValidAttribute validAttribute : validAttributes) { + if (attribute.equals(validAttribute.name)) { + valid = true; + break; + } + } + if (!valid) + err.jspError(start, "jsp.error.invalid.attribute", typeOfTag, + attribute); } - if (!valid) - err.jspError(start, "jsp.error.invalid.attribute", typeOfTag, - attribute); - } - // XXX *could* move EL-syntax validation here... (sb) + // XXX *could* move EL-syntax validation here... (sb) } - + public static String escapeQueryString(String unescString) { - if ( unescString == null ) - return null; - - String escString = ""; - String shellSpChars = "\\\""; - - for(int index=0; index<unescString.length(); index++) { - char nextChar = unescString.charAt(index); - - if( shellSpChars.indexOf(nextChar) != -1 ) - escString += "\\"; - - escString += nextChar; - } - return escString; + if (unescString == null) + return null; + + String escString = ""; + String shellSpChars = "\\\""; + + for (int index = 0; index < unescString.length(); index++) { + char nextChar = unescString.charAt(index); + + if (shellSpChars.indexOf(nextChar) != -1) + escString += "\\"; + + escString += nextChar; + } + return escString; } - + /** - * Escape the 5 entities defined by XML. + * Escape the 5 entities defined by XML. + * + * @param s xml string to escape + * @return escaped xml string */ public static String escapeXml(String s) { if (s == null) return null; StringBuffer sb = new StringBuffer(); - for(int i=0; i<s.length(); i++) { + for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '<') { sb.append("<"); @@ -360,187 +368,190 @@ public class JspUtil { /** * Replaces any occurrences of the character <tt>replace</tt> with the * string <tt>with</tt>. + * + * @param name string + * @param replace char to replace + * @param with replace with + * + * @return replaced string */ public static String replace(String name, char replace, String with) { - StringBuffer buf = new StringBuffer(); - int begin = 0; - int end; - int last = name.length(); - - while (true) { - end = name.indexOf(replace, begin); - if (end < 0) { - end = last; - } - buf.append(name.substring(begin, end)); - if (end == last) { - break; + StringBuilder buf = new StringBuilder(); + int begin = 0; + int end; + int last = name.length(); + + while (true) { + end = name.indexOf(replace, begin); + if (end < 0) { + end = last; + } + buf.append(name.substring(begin, end)); + if (end == last) { + break; + } + buf.append(with); + begin = end + 1; } - buf.append(with); - begin = end + 1; - } - - return buf.toString(); + + return buf.toString(); } public static class ValidAttribute { - String name; - boolean mandatory; - boolean rtexprvalue; // not used now - - public ValidAttribute (String name, boolean mandatory, - boolean rtexprvalue ) - { - this.name = name; - this.mandatory = mandatory; + String name; + boolean mandatory; + boolean rtexprvalue; // not used now + + public ValidAttribute(String name, boolean mandatory, + boolean rtexprvalue) { + this.name = name; + this.mandatory = mandatory; this.rtexprvalue = rtexprvalue; } - public ValidAttribute (String name, boolean mandatory) { - this( name, mandatory, false ); - } + public ValidAttribute(String name, boolean mandatory) { + this(name, mandatory, false); + } - public ValidAttribute (String name) { - this (name, false); - } + public ValidAttribute(String name) { + this(name, false); + } } - + /** * Convert a String value to 'boolean'. * Besides the standard conversions done by * Boolean.valueOf(s).booleanValue(), the value "yes" - * (ignore case) is also converted to 'true'. + * (ignore case) is also converted to 'true'. * If 's' is null, then 'false' is returned. * * @param s the string to be converted * @return the boolean value associated with the string s */ public static boolean booleanValue(String s) { - boolean b = false; - if (s != null) { - if (s.equalsIgnoreCase("yes")) { - b = true; - } else { - b = Boolean.valueOf(s).booleanValue(); - } - } - return b; + return BooleanUtils.toBoolean(s); } /** - * Returns the <tt>Class</tt> object associated with the class or - * interface with the given string name. - * * <p> The <tt>Class</tt> object is determined by passing the given string * name to the <tt>Class.forName()</tt> method, unless the given string * name represents a primitive type, in which case it is converted to a * <tt>Class</tt> object by appending ".class" to it (e.g., "int.class"). + * + * @param type type + * @param loader class loader + * + * @return the <tt>Class</tt> object associated with the class or + * interface with the given string name. + * + * @throws ClassNotFoundException if call was not found */ public static Class toClass(String type, ClassLoader loader) - throws ClassNotFoundException { - - Class c = null; - int i0 = type.indexOf('['); - int dims = 0; - if (i0 > 0) { - // This is an array. Count the dimensions - for (int i = 0; i < type.length(); i++) { - if (type.charAt(i) == '[') - dims++; + throws ClassNotFoundException { + + Class c = null; + int i0 = type.indexOf('['); + int dims = 0; + if (i0 > 0) { + // This is an array. Count the dimensions + for (int i = 0; i < type.length(); i++) { + if (type.charAt(i) == '[') + dims++; + } + type = type.substring(0, i0); } - type = type.substring(0, i0); - } - if ("boolean".equals(type)) - c = boolean.class; - else if ("char".equals(type)) - c = char.class; - else if ("byte".equals(type)) - c = byte.class; - else if ("short".equals(type)) - c = short.class; - else if ("int".equals(type)) - c = int.class; - else if ("long".equals(type)) - c = long.class; - else if ("float".equals(type)) - c = float.class; - else if ("double".equals(type)) - c = double.class; - else if (type.indexOf('[') < 0) - c = loader.loadClass(type); - - if (dims == 0) - return c; - - if (dims == 1) - return java.lang.reflect.Array.newInstance(c, 1).getClass(); - - // Array of more than i dimension - return java.lang.reflect.Array.newInstance(c, new int[dims]).getClass(); + if ("boolean".equals(type)) + c = boolean.class; + else if ("char".equals(type)) + c = char.class; + else if ("byte".equals(type)) + c = byte.class; + else if ("short".equals(type)) + c = short.class; + else if ("int".equals(type)) + c = int.class; + else if ("long".equals(type)) + c = long.class; + else if ("float".equals(type)) + c = float.class; + else if ("double".equals(type)) + c = double.class; + else if (type.indexOf('[') < 0) + c = loader.loadClass(type); + + if (dims == 0) + return c; + + if (dims == 1) + return java.lang.reflect.Array.newInstance(c, 1).getClass(); + + // Array of more than i dimension + return java.lang.reflect.Array.newInstance(c, new int[dims]).getClass(); } - + /** * Produces a String representing a call to the EL interpreter. - * @param expression a String containing zero or more "${}" expressions + * + * @param isTagFile is a tag file + * @param expression a String containing zero or more "${}" expressions * @param expectedType the expected type of the interpreted result - * @param fnmapvar Variable pointing to a function map. - * @param XmlEscape True if the result should do XML escaping + * @param fnmapvar Variable pointing to a function map. + * @param XmlEscape True if the result should do XML escaping * @return a String representing a call to the EL interpreter. */ public static String interpreterCall(boolean isTagFile, - String expression, + String expression, Class expectedType, String fnmapvar, - boolean XmlEscape ) - { + boolean XmlEscape) { /* * Determine which context object to use. */ - String jspCtxt = null; - if (isTagFile) - jspCtxt = "this.getJspContext()"; - else - jspCtxt = "_jspx_page_context"; + String jspCtxt = null; + if (isTagFile) + jspCtxt = "this.getJspContext()"; + else + jspCtxt = "_jspx_page_context"; /* * Determine whether to use the expected type's textual name * or, if it's a primitive, the name of its correspondent boxed * type. */ - String targetType = expectedType.getName(); - String primitiveConverterMethod = null; - if (expectedType.isPrimitive()) { - if (expectedType.equals(Boolean.TYPE)) { - targetType = Boolean.class.getName(); - primitiveConverterMethod = "booleanValue"; - } else if (expectedType.equals(Byte.TYPE)) { - targetType = Byte.class.getName(); - primitiveConverterMethod = "byteValue"; - } else if (expectedType.equals(Character.TYPE)) { - targetType = Character.class.getName(); - primitiveConverterMethod = "charValue"; - } else if (expectedType.equals(Short.TYPE)) { - targetType = Short.class.getName(); - primitiveConverterMethod = "shortValue"; - } else if (expectedType.equals(Integer.TYPE)) { - targetType = Integer.class.getName(); - primitiveConverterMethod = "intValue"; - } else if (expectedType.equals(Long.TYPE)) { - targetType = Long.class.getName(); - primitiveConverterMethod = "longValue"; - } else if (expectedType.equals(Float.TYPE)) { - targetType = Float.class.getName(); - primitiveConverterMethod = "floatValue"; - } else if (expectedType.equals(Double.TYPE)) { - targetType = Double.class.getName(); - primitiveConverterMethod = "doubleValue"; + String targetType = expectedType.getName(); + String primitiveConverterMethod = null; + if (expectedType.isPrimitive()) { + if (expectedType.equals(Boolean.TYPE)) { + targetType = Boolean.class.getName(); + primitiveConverterMethod = "booleanValue"; + } else if (expectedType.equals(Byte.TYPE)) { + targetType = Byte.class.getName(); + primitiveConverterMethod = "byteValue"; + } else if (expectedType.equals(Character.TYPE)) { + targetType = Character.class.getName(); + primitiveConverterMethod = "charValue"; + } else if (expectedType.equals(Short.TYPE)) { + targetType = Short.class.getName(); + primitiveConverterMethod = "shortValue"; + } else if (expectedType.equals(Integer.TYPE)) { + targetType = Integer.class.getName(); + primitiveConverterMethod = "intValue"; + } else if (expectedType.equals(Long.TYPE)) { + targetType = Long.class.getName(); + primitiveConverterMethod = "longValue"; + } else if (expectedType.equals(Float.TYPE)) { + targetType = Float.class.getName(); + primitiveConverterMethod = "floatValue"; + } else if (expectedType.equals(Double.TYPE)) { + targetType = Double.class.getName(); + primitiveConverterMethod = "doubleValue"; + } + } + + if (primitiveConverterMethod != null) { + XmlEscape = false; } - } - - if (primitiveConverterMethod != null) { - XmlEscape = false; - } /* * Build up the base call to the interpreter. @@ -556,33 +567,37 @@ public class JspUtil { // Note that PageContextImpl implements VariableResolver and // the generated Servlet/SimpleTag implements FunctionMapper, so // that machinery is already in place (mroth). - targetType = toJavaSourceType(targetType); - StringBuffer call = new StringBuffer( - "(" + targetType + ") " - + "org.apache.struts2.jasper.runtime.PageContextImpl.proprietaryEvaluate" - + "(" + Generator.quote(expression) + ", " - + targetType + ".class, " - + "(PageContext)" + jspCtxt - + ", " + fnmapvar - + ", " + XmlEscape - + ")"); + targetType = toJavaSourceType(targetType); + StringBuilder call = new StringBuilder( + "(" + targetType + ") " + + "org.apache.struts2.jasper.runtime.PageContextImpl.proprietaryEvaluate" + + "(" + Generator.quote(expression) + ", " + + targetType + ".class, " + + "(PageContext)" + jspCtxt + + ", " + fnmapvar + + ", " + XmlEscape + + ")"); /* * Add the primitive converter method if we need to. */ - if (primitiveConverterMethod != null) { - call.insert(0, "("); - call.append(")." + primitiveConverterMethod + "()"); - } - - return call.toString(); + if (primitiveConverterMethod != null) { + call.insert(0, "("); + call.append(")." + primitiveConverterMethod + "()"); + } + + return call.toString(); } /** * Validates the syntax of all ${} expressions within the given string. - * @param where the approximate location of the expressions in the JSP page + * + * @param where the approximate location of the expressions in the JSP page * @param expressions a string containing zero or more "${}" expressions - * @param err an error dispatcher to use + * @param expectedType expected class type + * @param functionMapper function mapper + * @param err an error dispatcher to use + * @throws JasperException in case of Jasper errors * @deprecated now delegated to the org.apache.el Package */ public static void validateExpressions(Mark where, @@ -592,24 +607,12 @@ public class JspUtil { ErrorDispatcher err) throws JasperException { -// try { -// -// JspUtil.expressionEvaluator.parseExpression( expressions, -// expectedType, functionMapper ); -// } -// catch( ELParseException e ) { -// err.jspError(where, "jsp.error.invalid.expression", expressions, -// e.toString() ); -// } -// catch( ELException e ) { -// err.jspError(where, "jsp.error.invalid.expression", expressions, -// e.toString() ); -// } } /** * Resets the temporary variable name. * (not thread-safe) + * * @deprecated */ public static void resetTemporaryVariableName() { @@ -617,7 +620,7 @@ public class JspUtil { } /** - * Generates a new temporary variable name. + * @return Generates a new temporary variable name. * (not thread-safe) * @deprecated */ @@ -626,206 +629,206 @@ public class JspUtil { } public static String coerceToPrimitiveBoolean(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToBoolean(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "false"; - else - return Boolean.valueOf(s).toString(); - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToBoolean(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "false"; + else + return Boolean.valueOf(s).toString(); + } } public static String coerceToBoolean(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Boolean) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Boolean.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Boolean(false)"; + if (isNamedAttribute) { + return "(Boolean) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Boolean.class)"; } else { - // Detect format error at translation time - return "new Boolean(" + Boolean.valueOf(s).toString() + ")"; + if (s == null || s.length() == 0) { + return "new Boolean(false)"; + } else { + // Detect format error at translation time + return "new Boolean(" + Boolean.valueOf(s).toString() + ")"; + } } } - } public static String coerceToPrimitiveByte(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToByte(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "(byte) 0"; - else - return "((byte)" + Byte.valueOf(s).toString() + ")"; - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToByte(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "(byte) 0"; + else + return "((byte)" + Byte.valueOf(s).toString() + ")"; + } } public static String coerceToByte(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Byte) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Byte.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Byte((byte) 0)"; + if (isNamedAttribute) { + return "(Byte) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Byte.class)"; } else { - // Detect format error at translation time - return "new Byte((byte)" + Byte.valueOf(s).toString() + ")"; + if (s == null || s.length() == 0) { + return "new Byte((byte) 0)"; + } else { + // Detect format error at translation time + return "new Byte((byte)" + Byte.valueOf(s).toString() + ")"; + } } } - } public static String coerceToChar(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToChar(" + s + ")"; - } else { - if (s == null || s.length() == 0) { - return "(char) 0"; + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToChar(" + s + ")"; } else { - char ch = s.charAt(0); - // this trick avoids escaping issues - return "((char) " + (int) ch + ")"; + if (s == null || s.length() == 0) { + return "(char) 0"; + } else { + char ch = s.charAt(0); + // this trick avoids escaping issues + return "((char) " + (int) ch + ")"; + } } } - } public static String coerceToCharacter(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Character) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Character.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Character((char) 0)"; + if (isNamedAttribute) { + return "(Character) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Character.class)"; } else { - char ch = s.charAt(0); - // this trick avoids escaping issues - return "new Character((char) " + (int) ch + ")"; + if (s == null || s.length() == 0) { + return "new Character((char) 0)"; + } else { + char ch = s.charAt(0); + // this trick avoids escaping issues + return "new Character((char) " + (int) ch + ")"; + } } } - } public static String coerceToPrimitiveDouble(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToDouble(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "(double) 0"; - else - return Double.valueOf(s).toString(); - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToDouble(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "(double) 0"; + else + return Double.valueOf(s).toString(); + } } public static String coerceToDouble(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Double) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Double.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Double(0)"; + if (isNamedAttribute) { + return "(Double) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Double.class)"; } else { - // Detect format error at translation time - return "new Double(" + Double.valueOf(s).toString() + ")"; + if (s == null || s.length() == 0) { + return "new Double(0)"; + } else { + // Detect format error at translation time + return "new Double(" + Double.valueOf(s).toString() + ")"; + } } } - } public static String coerceToPrimitiveFloat(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToFloat(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "(float) 0"; - else - return Float.valueOf(s).toString() + "f"; - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToFloat(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "(float) 0"; + else + return Float.valueOf(s).toString() + "f"; + } } public static String coerceToFloat(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Float) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Float.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Float(0)"; + if (isNamedAttribute) { + return "(Float) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Float.class)"; } else { - // Detect format error at translation time - return "new Float(" + Float.valueOf(s).toString() + "f)"; + if (s == null || s.length() == 0) { + return "new Float(0)"; + } else { + // Detect format error at translation time + return "new Float(" + Float.valueOf(s).toString() + "f)"; + } } } - } public static String coerceToInt(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToInt(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "0"; - else - return Integer.valueOf(s).toString(); - } + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToInt(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "0"; + else + return Integer.valueOf(s).toString(); + } } public static String coerceToInteger(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Integer) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Integer.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Integer(0)"; + if (isNamedAttribute) { + return "(Integer) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Integer.class)"; } else { - // Detect format error at translation time - return "new Integer(" + Integer.valueOf(s).toString() + ")"; + if (s == null || s.length() == 0) { + return "new Integer(0)"; + } else { + // Detect format error at translation time + return "new Integer(" + Integer.valueOf(s).toString() + ")"; + } } } - } public static String coerceToPrimitiveShort(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToShort(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "(short) 0"; - else - return "((short) " + Short.valueOf(s).toString() + ")"; - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToShort(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "(short) 0"; + else + return "((short) " + Short.valueOf(s).toString() + ")"; + } } - + public static String coerceToShort(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Short) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Short.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Short((short) 0)"; + if (isNamedAttribute) { + return "(Short) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Short.class)"; } else { - // Detect format error at translation time - return "new Short(\"" + Short.valueOf(s).toString() + "\")"; + if (s == null || s.length() == 0) { + return "new Short((short) 0)"; + } else { + // Detect format error at translation time + return "new Short(\"" + Short.valueOf(s).toString() + "\")"; + } } } - } - + public static String coerceToPrimitiveLong(String s, - boolean isNamedAttribute) { - if (isNamedAttribute) { - return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToLong(" + s + ")"; - } else { - if (s == null || s.length() == 0) - return "(long) 0"; - else - return Long.valueOf(s).toString() + "l"; - } + boolean isNamedAttribute) { + if (isNamedAttribute) { + return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToLong(" + s + ")"; + } else { + if (s == null || s.length() == 0) + return "(long) 0"; + else + return Long.valueOf(s).toString() + "l"; + } } public static String coerceToLong(String s, boolean isNamedAttribute) { - if (isNamedAttribute) { - return "(Long) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Long.class)"; - } else { - if (s == null || s.length() == 0) { - return "new Long(0)"; + if (isNamedAttribute) { + return "(Long) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Long.class)"; } else { - // Detect format error at translation time - return "new Long(" + Long.valueOf(s).toString() + "l)"; + if (s == null || s.length() == 0) { + return "new Long(0)"; + } else { + // Detect format error at translation time + return "new Long(" + Long.valueOf(s).toString() + "l)"; + } } } - } public static InputStream getInputStream(String fname, JarFile jarFile, JspCompilationContext ctxt, @@ -858,40 +861,37 @@ public class JspUtil { * the given tag file path. * * @param path Tag file path - * @param err Error dispatcher - * - * @return Fully-qualified class name of the tag handler corresponding to + * @param err Error dispatcher + * @return Fully-qualified class name of the tag handler corresponding to * the given tag file path - * - * @deprecated Use {@link #getTagHandlerClassName(String, String, - * ErrorDispatcher) - * See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 + * @throws JasperException in case of Jasper errors + * @deprecated Use {@link #getTagHandlerClassName(String, String, ErrorDispatcher)} + * See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 */ public static String getTagHandlerClassName(String path, - ErrorDispatcher err) - throws JasperException { + ErrorDispatcher err) + throws JasperException { return getTagHandlerClassName(path, null, err); } - + /** * Gets the fully-qualified class name of the tag handler corresponding to * the given tag file path. - * - * @param path - * Tag file path - * @param err - * Error dispatcher - * + * + * @param path Tag file path + * @param urn urn + * @param err Error dispatcher * @return Fully-qualified class name of the tag handler corresponding to - * the given tag file path + * the given tag file path + * @throws JasperException in case of Jasper errors */ public static String getTagHandlerClassName(String path, String urn, - ErrorDispatcher err) throws JasperException { + ErrorDispatcher err) throws JasperException { String className = null; int begin = 0; int index; - + index = path.lastIndexOf(".tag"); if (index == -1) { err.jspError("jsp.error.tagfile.badSuffix", path); @@ -922,8 +922,8 @@ public class JspUtil { } className += makeJavaPackage(path.substring(begin)); - - return className; + + return className; } private static String getClassNameBase(String urn) { @@ -939,11 +939,10 @@ public class JspUtil { * Converts the given path to a Java package or fully-qualified class name * * @param path Path to convert - * * @return Java package corresponding to the given path */ public static final String makeJavaPackage(String path) { - String classNameComponents[] = split(path,"/"); + String classNameComponents[] = split(path, "/"); StringBuffer legalClassNames = new StringBuffer(); for (int i = 0; i < classNameComponents.length; i++) { legalClassNames.append(makeJavaIdentifier(classNameComponents[i])); @@ -956,42 +955,42 @@ public class JspUtil { /** * Splits a string into it's components. + * * @param path String to split - * @param pat Pattern to split at + * @param pat Pattern to split at * @return the components of the path */ - private static final String [] split(String path, String pat) { + private static final String[] split(String path, String pat) { Vector comps = new Vector(); int pos = path.indexOf(pat); int start = 0; - while( pos >= 0 ) { - if(pos > start ) { - String comp = path.substring(start,pos); + while (pos >= 0) { + if (pos > start) { + String comp = path.substring(start, pos); comps.add(comp); } start = pos + pat.length(); - pos = path.indexOf(pat,start); + pos = path.indexOf(pat, start); } - if( start < path.length()) { + if (start < path.length()) { comps.add(path.substring(start)); } - String [] result = new String[comps.size()]; - for(int i=0; i < comps.size(); i++) { - result[i] = (String)comps.elementAt(i); + String[] result = new String[comps.size()]; + for (int i = 0; i < comps.size(); i++) { + result[i] = (String) comps.elementAt(i); } return result; } - + /** * Converts the given identifier to a legal Java identifier * * @param identifier Identifier to convert - * * @return Legal Java identifier corresponding to the given identifier */ public static final String makeJavaIdentifier(String identifier) { - StringBuffer modifiedIdentifier = - new StringBuffer(identifier.length()); + StringBuffer modifiedIdentifier = + new StringBuffer(identifier.length()); if (!Character.isJavaIdentifierStart(identifier.charAt(0))) { modifiedIdentifier.append('_'); } @@ -1010,9 +1009,11 @@ public class JspUtil { } return modifiedIdentifier.toString(); } - + /** * Mangle the specified character to create a legal Java class name. + * @param ch character + * @return new string */ public static final String mangleChar(char ch) { char[] result = new char[5]; @@ -1025,19 +1026,21 @@ public class JspUtil { } /** - * Test whether the argument is a Java keyword + * @param key string to check + * + * @return Test whether the argument is a Java keyword */ public static boolean isJavaKeyword(String key) { int i = 0; int j = javaKeywords.length; while (i < j) { - int k = (i+j)/2; + int k = (i + j) / 2; int result = javaKeywords[k].compareTo(key); if (result == 0) { return true; } if (result < 0) { - i = k+1; + i = k + 1; } else { j = k; } @@ -1053,7 +1056,6 @@ public class JspUtil { * so that we don't have to worry about it being a Java key word. * * @param name Identifier to convert - * * @return Legal Java identifier corresponding to the given identifier */ public static final String makeXmlJavaIdentifier(String name) { @@ -1067,19 +1069,19 @@ public class JspUtil { } static InputStreamReader getReader(String fname, String encoding, - JarFile jarFile, - JspCompilationContext ctxt, - ErrorDispatcher err) - throws JasperException, IOException { + JarFile jarFile, + JspCompilationContext ctxt, + ErrorDispatcher err) + throws JasperException, IOException { return getReader(fname, encoding, jarFile, ctxt, err, 0); } static InputStreamReader getReader(String fname, String encoding, - JarFile jarFile, - JspCompilationContext ctxt, - ErrorDispatcher err, int skip) - throws JasperException, IOException { + JarFile jarFile, + JspCompilationContext ctxt, + ErrorDispatcher err, int skip) + throws JasperException, IOException { InputStreamReader reader = null; InputStream in = getInputStream(fname, jarFile, ctxt, err); @@ -1094,16 +1096,16 @@ public class JspUtil { return reader; } - + /** * Handles taking input from TLDs - * 'java.lang.Object' -> 'java.lang.Object.class' - * 'int' -> 'int.class' - * 'void' -> 'Void.TYPE' - * 'int[]' -> 'int[].class' - * - * @param type - * @return + * 'java.lang.Object' -> 'java.lang.Object.class' + * 'int' -> 'int.class' + * 'void' -> 'Void.TYPE' + * 'int[]' -> 'int[].class' + * + * @param type java source type + * @return type */ public static String toJavaSourceTypeFromTld(String type) { if (type == null || "void".equals(type)) { @@ -1113,49 +1115,71 @@ public class JspUtil { } /** - * Class.getName() return arrays in the form "[[[<et>", where et, - * the element type can be one of ZBCDFIJS or L<classname>; + * Class.getName() return arrays in the form "[[[<et>", where et, + * the element type can be one of ZBCDFIJS or L<classname>; * It is converted into forms that can be understood by javac. + * + * @param type source type + * @return java source type */ public static String toJavaSourceType(String type) { - if (type.charAt(0) != '[') { - return type; - } + if (type.charAt(0) != '[') { + return type; + } - int dims = 1; - String t = null; - for (int i = 1; i < type.length(); i++) { - if (type.charAt(i) == '[') { - dims++; - } else { - switch (type.charAt(i)) { - case 'Z': t = "boolean"; break; - case 'B': t = "byte"; break; - case 'C': t = "char"; break; - case 'D': t = "double"; break; - case 'F': t = "float"; break; - case 'I': t = "int"; break; - case 'J': t = "long"; break; - case 'S': t = "short"; break; - case 'L': t = type.substring(i+1, type.indexOf(';')); break; + int dims = 1; + String t = null; + for (int i = 1; i < type.length(); i++) { + if (type.charAt(i) == '[') { + dims++; + } else { + switch (type.charAt(i)) { + case 'Z': + t = "boolean"; + break; + case 'B': + t = "byte"; + break; + case 'C': + t = "char"; + break; + case 'D': + t = "double"; + break; + case 'F': + t = "float"; + break; + case 'I': + t = "int"; + break; + case 'J': + t = "long"; + break; + case 'S': + t = "short"; + break; + case 'L': + t = type.substring(i + 1, type.indexOf(';')); + break; + } + break; + } } - break; + StringBuilder resultType = new StringBuilder(t); + for (; dims > 0; dims--) { + resultType.append("[]"); } - } - StringBuffer resultType = new StringBuffer(t); - for (; dims > 0; dims--) { - resultType.append("[]"); - } - return resultType.toString(); + return resultType.toString(); } /** * Compute the canonical name from a Class instance. Note that a - * simple replacment of '$' with '.' of a binary name would not work, + * simple replacement of '$' with '.' of a binary name would not work, * as '$' is a legal Java Identifier character. + * * @param c A instance of java.lang.Class - * @return The canonical name of c. + * @return The canonical name of c. */ public static String getCanonicalName(Class c) { @@ -1166,11 +1190,11 @@ public class JspUtil { return binaryName; } - StringBuffer buf = new StringBuffer(binaryName); + StringBuilder buf = new StringBuilder(binaryName); do { buf.setCharAt(c.getName().length(), '.'); c = c.getDeclaringClass(); - } while ( c != null); + } while (c != null); return buf.toString(); }
http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java index 91f6191..7507018 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/ServletWriter.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.PrintWriter; /** - * This is what is used to generate servlets. + * This is what is used to generate servlets. * * @author Anil K. Vijendran * @author Kin-man Chung @@ -35,20 +35,20 @@ public class ServletWriter { // The sink writer: PrintWriter writer; - + // servlet line numbers start from 1 private int javaLine = 1; public ServletWriter(PrintWriter writer) { - this.writer = writer; + this.writer = writer; } public void close() throws IOException { - writer.close(); + writer.close(); } - + // -------------------- Access informations -------------------- public int getJavaLine() { @@ -59,30 +59,32 @@ public class ServletWriter { // -------------------- Formatting -------------------- public void pushIndent() { - virtual_indent += TAB_WIDTH; - if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) - indent = virtual_indent; + virtual_indent += TAB_WIDTH; + if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) + indent = virtual_indent; } public void popIndent() { - virtual_indent -= TAB_WIDTH; - if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) - indent = virtual_indent; + virtual_indent -= TAB_WIDTH; + if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) + indent = virtual_indent; } /** * Print a standard comment for echo outputed chunk. - * @param start The starting position of the JSP chunk being processed. - * @param stop The ending position of the JSP chunk being processed. + * + * @param start The starting position of the JSP chunk being processed. + * @param stop The ending position of the JSP chunk being processed. + * @param chars characters as array */ public void printComment(Mark start, Mark stop, char[] chars) { if (start != null && stop != null) { - println("// from="+start); - println("// to="+stop); + println("// from=" + start); + println("// to=" + stop); } - + if (chars != null) - for(int i = 0; i < chars.length;) { + for (int i = 0; i < chars.length; ) { printin(); print("// "); while (chars[i] != '\n' && i < chars.length) @@ -92,10 +94,12 @@ public class ServletWriter { /** * Prints the given string followed by '\n' + * + * @param s string to print */ public void println(String s) { javaLine++; - writer.println(s); + writer.println(s); } /** @@ -103,74 +107,96 @@ public class ServletWriter { */ public void println() { javaLine++; - writer.println(""); + writer.println(""); } /** * Prints the current indention */ public void printin() { - writer.print(SPACES.substring(0, indent)); + writer.print(SPACES.substring(0, indent)); } /** * Prints the current indention, followed by the given string + * + * @param s string to print */ public void printin(String s) { - writer.print(SPACES.substring(0, indent)); - writer.print(s); + writer.print(SPACES.substring(0, indent)); + writer.print(s); } /** * Prints the current indention, and then the string, and a '\n'. + * + * @param s string to print */ public void printil(String s) { javaLine++; - writer.print(SPACES.substring(0, indent)); - writer.println(s); + writer.print(SPACES.substring(0, indent)); + writer.println(s); } /** + * <p> * Prints the given char. + * </p> * * Use println() to print a '\n'. + * + * @param c char to print */ public void print(char c) { - writer.print(c); + writer.print(c); } /** * Prints the given int. + * + * @param i int to print */ public void print(int i) { - writer.print(i); + writer.print(i); } /** + * <p> * Prints the given string. + * </p> * + * <p> * The string must not contain any '\n', otherwise the line count will be * off. + * </p> + * + * @param s string to print */ public void print(String s) { - writer.print(s); + writer.print(s); } /** + * <p> * Prints the given string. + * </p> * + * <p> * If the string spans multiple lines, the line count will be adjusted * accordingly. + * </p> + * + * @param s string to print */ public void printMultiLn(String s) { int index = 0; // look for hidden newlines inside strings - while ((index=s.indexOf('\n',index)) > -1 ) { + while ((index = s.indexOf('\n', index)) > -1) { javaLine++; index++; } - writer.print(s); + writer.print(s); } } http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java index 12cf227..4bbccf6 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapGenerator.java @@ -55,7 +55,7 @@ public class SmapGenerator { // Methods for adding mapping data /** - * Sets the filename (without path information) for the generated + * @param x Sets the filename (without path information) for the generated * source file. E.g., "foo$jsp.java". */ public synchronized void setOutputFileName(String x) { http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java index 801a02e..a1982c6 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapStratum.java @@ -44,14 +44,16 @@ public class SmapStratum { private int outputLineIncrement = 1; private boolean lineFileIDSet = false; - /** Sets InputStartLine. */ + /** + * @param inputStartLine Sets InputStartLine. + */ public void setInputStartLine(int inputStartLine) { if (inputStartLine < 0) throw new IllegalArgumentException("" + inputStartLine); this.inputStartLine = inputStartLine; } - /** Sets OutputStartLine. */ + /** @param outputStartLine Sets OutputStartLine. */ public void setOutputStartLine(int outputStartLine) { if (outputStartLine < 0) throw new IllegalArgumentException("" + outputStartLine); @@ -59,7 +61,7 @@ public class SmapStratum { } /** - * Sets lineFileID. Should be called only when different from + * @param lineFileID Sets lineFileID. Should be called only when different from * that of prior LineInfo object (in any given context) or 0 * if the current LineInfo has no (logical) predecessor. * <tt>LineInfo</tt> will print this file number no matter what. @@ -71,14 +73,14 @@ public class SmapStratum { this.lineFileIDSet = true; } - /** Sets InputLineCount. */ + /** @param inputLineCount Sets InputLineCount. */ public void setInputLineCount(int inputLineCount) { if (inputLineCount < 0) throw new IllegalArgumentException("" + inputLineCount); this.inputLineCount = inputLineCount; } - /** Sets OutputLineIncrement. */ + /** @param outputLineIncrement Sets OutputLineIncrement. */ public void setOutputLineIncrement(int outputLineIncrement) { if (outputLineIncrement < 0) throw new IllegalArgumentException("" + outputLineIncrement); @@ -86,7 +88,7 @@ public class SmapStratum { } /** - * Retrieves the current LineInfo as a String, print all values + * @return Retrieves the current LineInfo as a String, print all values * only when appropriate (but LineInfoID if and only if it's been * specified, as its necessity is sensitive to context). */ @@ -170,13 +172,7 @@ public class SmapStratum { */ public void optimizeLineSection() { -/* Some debugging code - for (int i = 0; i < lineData.size(); i++) { - LineInfo li = (LineInfo)lineData.get(i); - System.out.print(li.toString()); - } -*/ - //Incorporate each LineInfo into the previous LineInfo's + //Incorporate each LineInfo into the previous LineInfo's //outputLineIncrement, if possible int i = 0; while (i < lineData.size() - 1) { @@ -280,14 +276,14 @@ public class SmapStratum { // Methods to retrieve information /** - * Returns the name of the stratum. + * @return the name of the stratum. */ public String getStratumName() { return stratumName; } /** - * Returns the given stratum as a String: a StratumSection, + * @return the given stratum as a String: a StratumSection, * followed by at least one FileSection and at least one LineSection. */ public String getString() { http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java index ea18fa9..f49139e 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/SmapUtil.java @@ -62,6 +62,7 @@ public class SmapUtil { * @param ctxt Current compilation context * @param pageNodes The current JSP page * @return a SMAP for the page + * @throws IOException in case of IO errors */ public static String[] generateSmap( JspCompilationContext ctxt, http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java index 4c9b0f4..239fcdf 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/TldLocationsCache.java @@ -45,18 +45,26 @@ import org.apache.juli.logging.LogFactory; import org.apache.commons.io.FileUtils; /** + * <p> * A container for all tag libraries that are defined "globally" * for the web application. - * + * </p> + * + * <p> * Tag Libraries can be defined globally in one of two ways: - * 1. Via <taglib> elements in web.xml: + * </p> + * + * <ol> + * <li>Via <taglib> elements in web.xml: * the uri and location of the tag-library are specified in - * the <taglib> element. - * 2. Via packaged jar files that contain .tld files + * the <taglib> element.</li> + * <li>Via packaged jar files that contain .tld files * within the META-INF directory, or some subdirectory - * of it. The taglib is 'global' if it has the <uri> - * element defined. + * of it. The taglib is 'global' if it has the <uri> + * element defined.</li> + * </ol> * + * <p> * A mapping between the taglib URI and its associated TaglibraryInfoImpl * is maintained in this container. * Actually, that's what we'd like to do. However, because of the @@ -65,13 +73,16 @@ import org.apache.commons.io.FileUtils; * across page invocations. A bug has been submitted to the spec lead. * In the mean time, all we do is save the 'location' where the * TLD associated with a taglib URI can be found. + * </p> * + * <p> * When a JSP page has a taglib directive, the mappings in this container * are first searched (see method getLocation()). * If a mapping is found, then the location of the TLD is returned. * If no mapping is found, then the uri specified * in the taglib directive is to be interpreted as the location for * the TLD of this tag library. + * </p> * * @author Pierre Delisle * @author Jan Luehe @@ -116,7 +127,7 @@ public class TldLocationsCache { * Initializes the set of JARs that are known not to contain any TLDs */ static { - noTldJars = new HashSet<String>(); + noTldJars = new HashSet<>(); // Bootstrap JARs noTldJars.add("bootstrap.jar"); noTldJars.add("commons-daemon.jar"); @@ -215,6 +226,8 @@ public class TldLocationsCache { * second element denotes the name of the TLD entry in the jar file. * Returns null if the uri is not associated with any tag library 'exposed' * in the web application. + * + * @throws JasperException in case of Jasper errors */ public String[] getLocation(String uri) throws JasperException { if (!initialized) { @@ -223,8 +236,10 @@ public class TldLocationsCache { return (String[]) mappings.get(uri); } - /** - * Returns the type of a URI: + /** + * @param uri the URI + * + * @return the type of a URI: * ABS_URI * ROOT_REL_URI * NOROOT_REL_URI @@ -342,6 +357,7 @@ public class TldLocationsCache { * @param conn The JarURLConnection to the JAR file to scan * @param ignore true if any exceptions raised when processing the given * JAR should be ignored, false otherwise + * @throws JasperException in case of Jasper errors */ private void scanJar(JarURLConnection conn, boolean ignore) throws JasperException { @@ -545,7 +561,7 @@ public class TldLocationsCache { } /** - * Returns a list of absolute paths of the locations in the cache + * @return a list of absolute paths of the locations in the cache */ public Set<String> getAbsolutePathsOfLocations() { Set<String> paths = new HashSet<String>(mappings.size()); http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java index 1194572..8b0a122 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/compiler/tagplugin/TagPluginContext.java @@ -61,16 +61,21 @@ public interface TagPluginContext { /** * Generate Java source codes + * + * @param s string */ void generateJavaSource(String s); /** + * @param attribute the attribute to check * @return true if the attribute is specified and its value is a * translation-time constant. */ boolean isConstantAttribute(String attribute); /** + * @param attribute The specified attribute + * * @return A string that is the value of a constant attribute. Undefined * if the attribute is not a (translation-time) constant. * null if the attribute is not specified. @@ -112,12 +117,16 @@ public interface TagPluginContext { /** * Associate the attribute with a value in the current tagplugin context. * The plugin attributes can be used for communication among tags that - * must work together as a group. See <c:when> for an example. + * must work together as a group. See <c:when> for an example. + * + * @param attr The specified attribute + * @param value the value */ void setPluginAttribute(String attr, Object value); /** - * Get the value of an attribute in the current tagplugin context. + * @param attr The specified attribute + * @return the value of an attribute in the current tagplugin context. */ Object getPluginAttribute(String attr); } http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/AnnotationHelper.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/AnnotationHelper.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/AnnotationHelper.java index 36a9c56..339d443 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/AnnotationHelper.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/AnnotationHelper.java @@ -37,6 +37,13 @@ public class AnnotationHelper { /** * Call postConstruct method on the specified instance. Note: In Jasper, this * calls naming resources injection as well. + * + * @param processor annotation processor + * @param instance object instance + * + * @throws IllegalAccessException on error + * @throws InvocationTargetException on error + * @throws NamingException on error */ public static void postConstruct(AnnotationProcessor processor, Object instance) throws IllegalAccessException, InvocationTargetException, NamingException { @@ -49,6 +56,12 @@ public class AnnotationHelper { /** * Call preDestroy method on the specified instance. + * + * @param processor annotation processor + * @param instance object instance + * + * @throws IllegalAccessException on error + * @throws InvocationTargetException on error */ public static void preDestroy(AnnotationProcessor processor, Object instance) throws IllegalAccessException, InvocationTargetException { http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java index 8752d57..6561d97 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/BodyContentImpl.java @@ -39,10 +39,8 @@ import org.apache.struts2.jasper.Constants; */ public class BodyContentImpl extends BodyContent { - private static final String LINE_SEPARATOR = - System.getProperty("line.separator"); - private static final boolean LIMIT_BUFFER = - Boolean.valueOf(System.getProperty("org.apache.struts2.jasper.runtime.BodyContentImpl.LIMIT_BUFFER", "false")).booleanValue(); + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + private static final boolean LIMIT_BUFFER = Boolean.valueOf(System.getProperty("org.apache.struts2.jasper.runtime.BodyContentImpl.LIMIT_BUFFER", "false")); private char[] cb; private int nextChar; @@ -53,6 +51,8 @@ public class BodyContentImpl extends BodyContent { /** * Constructor. + * + * @param enclosingWriter jsp writer */ public BodyContentImpl(JspWriter enclosingWriter) { super(enclosingWriter); @@ -87,10 +87,13 @@ public class BodyContentImpl extends BodyContent { * directly to the underlying stream. Thus redundant * <code>DiscardableBufferedWriter</code>s will not copy data * unnecessarily. + * </p> * * @param cbuf A character array * @param off Offset from which to start reading characters * @param len Number of characters to write + * + * @throws IOException in case of IO errors */ public void write(char[] cbuf, int off, int len) throws IOException { if (writer != null) { @@ -116,6 +119,10 @@ public class BodyContentImpl extends BodyContent { /** * Write an array of characters. This method cannot be inherited from the * Writer class because it must suppress I/O exceptions. + * + * @param buf array of characters + * + * @throws IOException in case of IO errors */ public void write(char[] buf) throws IOException { if (writer != null) { @@ -131,6 +138,8 @@ public class BodyContentImpl extends BodyContent { * @param s String to be written * @param off Offset from which to start reading characters * @param len Number of characters to be written + * + * @throws IOException in case of IO errors */ public void write(String s, int off, int len) throws IOException { if (writer != null) { @@ -148,6 +157,10 @@ public class BodyContentImpl extends BodyContent { /** * Write a string. This method cannot be inherited from the Writer class * because it must suppress I/O exceptions. + * + * @param s string to write + * + * @throws IOException in case of IO errors */ public void write(String s) throws IOException { if (writer != null) { @@ -180,7 +193,7 @@ public class BodyContentImpl extends BodyContent { * #write(int)}</code> method. * * @param b The <code>boolean</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(boolean b) throws IOException { if (writer != null) { @@ -197,7 +210,7 @@ public class BodyContentImpl extends BodyContent { * #write(int)}</code> method. * * @param c The <code>char</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(char c) throws IOException { if (writer != null) { @@ -215,7 +228,7 @@ public class BodyContentImpl extends BodyContent { * method. * * @param i The <code>int</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(int i) throws IOException { if (writer != null) { @@ -233,7 +246,7 @@ public class BodyContentImpl extends BodyContent { * <code>{@link #write(int)}</code> method. * * @param l The <code>long</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(long l) throws IOException { if (writer != null) { @@ -251,7 +264,7 @@ public class BodyContentImpl extends BodyContent { * <code>{@link #write(int)}</code> method. * * @param f The <code>float</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(float f) throws IOException { if (writer != null) { @@ -269,7 +282,7 @@ public class BodyContentImpl extends BodyContent { * #write(int)}</code> method. * * @param d The <code>double</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(double d) throws IOException { if (writer != null) { @@ -288,7 +301,7 @@ public class BodyContentImpl extends BodyContent { * @param s The array of chars to be printed * * @throws NullPointerException If <code>s</code> is <code>null</code> - * @throws IOException + * @throws IOException in case of IO errors */ public void print(char[] s) throws IOException { if (writer != null) { @@ -306,7 +319,7 @@ public class BodyContentImpl extends BodyContent { * <code>{@link #write(int)}</code> method. * * @param s The <code>String</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(String s) throws IOException { if (s == null) s = "null"; @@ -325,7 +338,7 @@ public class BodyContentImpl extends BodyContent { * <code>{@link #write(int)}</code> method. * * @param obj The <code>Object</code> to be printed - * @throws IOException + * @throws IOException in case of IO errors */ public void print(Object obj) throws IOException { if (writer != null) { @@ -341,7 +354,7 @@ public class BodyContentImpl extends BodyContent { * <code>line.separator</code>, and is not necessarily a single newline * character (<code>'\n'</code>). * - * @throws IOException + * @throws IOException in case of IO errors */ public void println() throws IOException { newLine(); @@ -352,7 +365,9 @@ public class BodyContentImpl extends BodyContent { * as though it invokes <code>{@link #print(boolean)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write boolean + * + * @throws IOException in case of IO errors */ public void println(boolean x) throws IOException { print(x); @@ -364,7 +379,9 @@ public class BodyContentImpl extends BodyContent { * though it invokes <code>{@link #print(char)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write char + * + * @throws IOException in case of IO errors */ public void println(char x) throws IOException { print(x); @@ -376,7 +393,9 @@ public class BodyContentImpl extends BodyContent { * though it invokes <code>{@link #print(int)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write int + * + * @throws IOException in case of IO errors */ public void println(int x) throws IOException { print(x); @@ -388,7 +407,8 @@ public class BodyContentImpl extends BodyContent { * as though it invokes <code>{@link #print(long)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write long + * @throws IOException in case of IO errors */ public void println(long x) throws IOException { print(x); @@ -400,7 +420,9 @@ public class BodyContentImpl extends BodyContent { * behaves as though it invokes <code>{@link #print(float)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write float + * + * @throws IOException in case of IO errors */ public void println(float x) throws IOException { print(x); @@ -412,7 +434,9 @@ public class BodyContentImpl extends BodyContent { * line. This method behaves as though it invokes <code>{@link * #print(double)}</code> and then <code>{@link #println()}</code>. * - * @throws IOException + * @param x write double + * + * @throws IOException in case of IO errors */ public void println(double x) throws IOException{ print(x); @@ -424,7 +448,8 @@ public class BodyContentImpl extends BodyContent { * behaves as though it invokes <code>{@link #print(char[])}</code> and * then <code>{@link #println()}</code>. * - * @throws IOException + * @param x write char array + * @throws IOException in case of IO errors */ public void println(char x[]) throws IOException { print(x); @@ -436,7 +461,8 @@ public class BodyContentImpl extends BodyContent { * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write string + * @throws IOException in case of IO errors */ public void println(String x) throws IOException { print(x); @@ -448,7 +474,8 @@ public class BodyContentImpl extends BodyContent { * though it invokes <code>{@link #print(Object)}</code> and then * <code>{@link #println()}</code>. * - * @throws IOException + * @param x write object + * @throws IOException in case of IO errors */ public void println(Object x) throws IOException { print(x); @@ -563,7 +590,7 @@ public class BodyContentImpl extends BodyContent { } /** - * Sets the writer to which all output is written. + * @param writer Sets the writer to which all output is written. */ void setWriter(Writer writer) { this.writer = writer; @@ -577,7 +604,7 @@ public class BodyContentImpl extends BodyContent { if (closed) throw new IOException("Stream closed"); } - /** + /* * Reallocates buffer since the spec requires it to be unbounded. */ private void reAllocBuff(int len) {
