You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mo...@locus.apache.org on 1999/12/23 09:30:21 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/jasper/resources messages.properties
mode 99/12/23 00:30:21
Modified: src/share/org/apache/jasper/compiler JspUtil.java
Parser.java
src/share/org/apache/jasper/resources messages.properties
Log:
Fix for checking for mandatory attributes for tags like jsp:include jsp:forward etc.
Revision Changes Path
1.5 +98 -22 jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java
Index: JspUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JspUtil.java 1999/12/21 21:38:03 1.4
+++ JspUtil.java 1999/12/23 08:30:20 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v 1.4 1999/12/21 21:38:03 rubys Exp $
- * $Revision: 1.4 $
- * $Date: 1999/12/21 21:38:03 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspUtil.java,v 1.5 1999/12/23 08:30:20 mode Exp $
+ * $Revision: 1.5 $
+ * $Date: 1999/12/23 08:30:20 $
*
* ====================================================================
*
@@ -65,6 +65,8 @@
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Enumeration;
import org.apache.jasper.Constants;
import org.apache.jasper.JasperException;
@@ -80,6 +82,7 @@
* Ideally should move all the bean containers here.
*
* @author Mandar Raje.
+ * @author Rajiv Mordani.
*/
public class JspUtil {
@@ -122,16 +125,19 @@
int length = returnString.length();
if (expression.endsWith(CLOSE_EXPR))
- returnString = returnString.substring (0, length - CLOSE_EXPR.length());
+ returnString = returnString.substring (0, length -
+ CLOSE_EXPR.length());
else if (expression.endsWith(CLOSE_EXPR_2))
- returnString = returnString.substring (0, length - CLOSE_EXPR_2.length());
+ returnString = returnString.substring (0, length -
+ CLOSE_EXPR_2.length());
return returnString;
}
// Parses the XML document contained in the InputStream.
- public static XmlDocument parseXMLDoc(InputStream in, URL dtdURL, String dtdId)
- throws JasperException {
+ public static XmlDocument parseXMLDoc(InputStream in, URL dtdURL,
+ String dtdId) throws JasperException
+ {
XmlDocument tld;
XmlDocumentBuilder builder = new XmlDocumentBuilder();
@@ -153,22 +159,84 @@
builder.setDisableNamespaces(false);
parser.parse(new InputSource(in));
} catch (SAXException sx) {
- throw new JasperException(Constants.getString("jsp.error.parse.error.in.TLD",
- new Object[] {
- sx.getMessage()
- }
- ));
+ throw new JasperException(Constants.getString(
+ "jsp.error.parse.error.in.TLD", new Object[] {
+ sx.getMessage()
+ }));
} catch (IOException io) {
- throw new JasperException(Constants.getString("jsp.error.unable.to.open.TLD",
- new Object[] {
- io.getMessage()
- }
- ));
+ throw new JasperException(Constants.getString(
+ "jsp.error.unable.to.open.TLD", new Object[] {
+ io.getMessage() }));
}
tld = builder.getDocument();
return tld;
}
+
+ public static void checkAttributes (String typeOfTag, Hashtable attrs,
+ ValidAttribute[] validAttributes)
+ throws JasperException
+ {
+ boolean valid = true;
+ Hashtable temp = (Hashtable)attrs.clone ();
+
+ /**
+ * First check to see if all the mandatory attributes are present.
+ * 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++) {
+
+ if (validAttributes[i].mandatory) {
+ if (temp.get (validAttributes[i].name) != null) {
+ temp.remove (validAttributes[i].name);
+ valid = true;
+ } else {
+ valid = false;
+ missingAttribute = validAttributes[i].name;
+ break;
+ }
+ }
+ }
+
+ /**
+ * If mandatory attribute is missing then the exception is thrown.
+ */
+ if (!valid)
+ throw new JasperException(Constants.getString(
+ "jsp.error.mandatory.attribute",
+ new Object[] { typeOfTag, missingAttribute}));
+
+ /**
+ * Check to see if there are any more attributes for the specified
+ * tag.
+ */
+ if (temp.size() == 0)
+ return;
+
+ /**
+ * Now check to see if the rest of the attributes are valid too.
+ */
+ Enumeration enum = temp.keys ();
+ String attribute = null;
+
+ while (enum.hasMoreElements ()) {
+ valid = false;
+ attribute = (String) enum.nextElement ();
+ for (int i = 0; i < validAttributes.length; i++) {
+ if (attribute.equals(validAttributes[i].name)) {
+ valid = true;
+ break;
+ }
+ }
+ if (!valid)
+ throw new JasperException(Constants.getString(
+ "jsp.error.invalid.attribute",
+ new Object[] { typeOfTag, attribute }));
+ }
+ }
public static String escapeQueryString(String unescString) {
if ( unescString == null )
@@ -188,10 +256,18 @@
return escString;
}
-}
-
-
-
-
+ public static class ValidAttribute {
+ String name;
+ boolean mandatory;
+
+ public ValidAttribute (String name, boolean mandatory) {
+ this.name = name;
+ this.mandatory = mandatory;
+ }
+ public ValidAttribute (String name) {
+ this (name, false);
+ }
+ }
+}
1.10 +81 -89 jakarta-tomcat/src/share/org/apache/jasper/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Parser.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Parser.java 1999/12/21 21:38:03 1.9
+++ Parser.java 1999/12/23 08:30:20 1.10
@@ -70,6 +70,7 @@
* the code generator backend.
*
* @author Anil K. Vijendran
+ * @author Rajiv Mordani
*/
public class Parser {
/**
@@ -121,25 +122,31 @@
"taglib"
};
- private static final String[] validAttributes = {
- "language",
- "extends",
- "import",
- "session",
- "buffer",
- "autoFlush",
- "isThreadSafe",
- "info",
- "errorPage",
- "isErrorPage",
- "contentType",
- "file",
- "uri",
- "prefix"
+ private static final JspUtil.ValidAttribute[] pageDvalidAttrs = {
+ new JspUtil.ValidAttribute ("language"),
+ new JspUtil.ValidAttribute ("extends"),
+ new JspUtil.ValidAttribute ("import"),
+ new JspUtil.ValidAttribute ("session"),
+ new JspUtil.ValidAttribute ("buffer"),
+ new JspUtil.ValidAttribute ("autoFlush"),
+ new JspUtil.ValidAttribute ("isThreadSafe"),
+ new JspUtil.ValidAttribute ("info"),
+ new JspUtil.ValidAttribute ("errorPage"),
+ new JspUtil.ValidAttribute ("isErrorPage"),
+ new JspUtil.ValidAttribute ("contentType")
};
-
- public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
- throws JasperException
+
+ private static final JspUtil.ValidAttribute[] includeDvalidAttrs = {
+ new JspUtil.ValidAttribute ("file", true)
+ };
+
+ private static final JspUtil.ValidAttribute[] tagDvalidAttrs = {
+ new JspUtil.ValidAttribute ("uri", true),
+ new JspUtil.ValidAttribute ("prefix", true)
+ };
+
+ public boolean accept(ParseEventListener listener, JspReader reader,
+ Parser parser) throws JasperException
{
String close;
String open;
@@ -172,7 +179,15 @@
// Parse the attr-val pairs.
Hashtable attrs = reader.parseTagAttributes();
- checkAttributes ("Directive", attrs.keys(), validAttributes);
+ if (match.equals ("page"))
+ JspUtil.checkAttributes ("Page directive", attrs,
+ pageDvalidAttrs);
+ else if (match.equals("include"))
+ JspUtil.checkAttributes ("Include directive", attrs,
+ includeDvalidAttrs);
+ else if (match.equals("taglib"))
+ JspUtil.checkAttributes ("Taglib directive", attrs,
+ tagDvalidAttrs);
// Match close.
reader.skipSpaces();
@@ -206,9 +221,9 @@
private static final String OPEN_INDIVIDUAL_PARAM = "<jsp:param";
private static final String CLOSE_INDIVIDUAL_PARAM = "/>";
- private static final String[] validAttributes = {
- "page",
- "flush"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute("page", true),
+ new JspUtil.ValidAttribute("flush")
};
public boolean accept(ParseEventListener listener, JspReader reader,
@@ -220,7 +235,7 @@
Mark start = reader.mark();
reader.advance(OPEN_INCLUDE.length());
Hashtable attrs = reader.parseTagAttributes();
- checkAttributes ("Include", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("Include", attrs, validAttributes);
reader.skipSpaces();
if (!reader.matches(CLOSE_INCLUDE_NO_BODY)) {
@@ -290,10 +305,11 @@
private static final String OPEN_INDIVIDUAL_PARAM = "<jsp:param";
private static final String CLOSE_INDIVIDUAL_PARAM = "/>";
- private static final String[] validAttributes = {
- "page"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute("page", true)
};
- public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
+ public boolean accept(ParseEventListener listener, JspReader reader,
+ Parser parser)
throws JasperException
{
if (reader.matches(OPEN_FORWARD)) {
@@ -301,7 +317,7 @@
reader.advance(OPEN_FORWARD.length());
Hashtable attrs = reader.parseTagAttributes();
Hashtable param = new Hashtable();
- checkAttributes ("Forward", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("Forward", attrs, validAttributes);
reader.skipSpaces();
if (!reader.matches(CLOSE_FORWARD_NO_BODY)) {
if (!reader.matches(CLOSE_FORWARD_BODY))
@@ -407,7 +423,7 @@
private static final String END_OPEN_DECL_2 = ">";
private static final String CLOSE_DECL_2 = "</jsp:decl>";
- private static final String[] validAttributes = {
+ private static final JspUtil.ValidAttribute[] validAttributes = {
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -438,7 +454,7 @@
reader.advance(end_open.length());
reader.skipSpaces();
- checkAttributes("Declaration", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes("Declaration", attrs, validAttributes);
}
Mark start = reader.mark();
@@ -467,7 +483,7 @@
private static final String END_OPEN_EXPR_2 = ">";
private static final String CLOSE_EXPR_2 = "</jsp:expression>";
- private static final String[] validAttributes = {
+ private static final JspUtil.ValidAttribute[] validAttributes = {
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -498,7 +514,7 @@
reader.advance(end_open.length());
reader.skipSpaces();
- checkAttributes("Expression", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes("Expression", attrs, validAttributes);
}
Mark start = reader.mark();
@@ -526,7 +542,7 @@
private static final String END_OPEN_SCRIPTLET_2 = ">";
private static final String CLOSE_SCRIPTLET_2 = "</jsp:scriptlet>";
- private static final String[] validAttributes = {
+ private static final JspUtil.ValidAttribute[] validAttributes = {
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -557,7 +573,7 @@
reader.advance(end_open.length());
reader.skipSpaces();
- checkAttributes("Scriptlet", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes("Scriptlet", attrs, validAttributes);
}
Mark start = reader.mark();
@@ -585,12 +601,12 @@
private static final String CLOSE_BEAN_2 = "</jsp:useBean>";
private static final String CLOSE_BEAN_3 = ">";
- private static final String[] validAttributes = {
- "id",
- "scope",
- "class",
- "type",
- "beanName"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute("id"),
+ new JspUtil.ValidAttribute("scope"),
+ new JspUtil.ValidAttribute("class"),
+ new JspUtil.ValidAttribute("type"),
+ new JspUtil.ValidAttribute("beanName")
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -600,7 +616,7 @@
Mark start = reader.mark();
reader.advance(OPEN_BEAN.length());
Hashtable attrs = reader.parseTagAttributesBean();
- checkAttributes ("useBean", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("useBean", attrs, validAttributes);
reader.skipSpaces();
if (!reader.matches(CLOSE_BEAN)) {
if (!reader.matches(CLOSE_BEAN_3))
@@ -650,9 +666,9 @@
private static final String OPEN_GETPROPERTY = "<jsp:getProperty";
private static final String CLOSE_GETPROPERTY = "/>";
- private static final String[] validAttributes = {
- "name",
- "property"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute("name", true),
+ new JspUtil.ValidAttribute("property", true)
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -662,7 +678,7 @@
Mark start = reader.mark();
reader.advance(OPEN_GETPROPERTY.length());
Hashtable attrs = reader.parseTagAttributes ();
- checkAttributes ("getProperty", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("getProperty", attrs, validAttributes);
reader.skipSpaces();
if (!reader.matches(CLOSE_GETPROPERTY))
throw new ParseException(reader.mark(),
@@ -690,11 +706,11 @@
private static final String OPEN_SETPROPERTY = "<jsp:setProperty";
private static final String CLOSE_SETPROPERTY = "/>";
- private static final String[] validAttributes = {
- "name",
- "property",
- "value",
- "param"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute("name", true),
+ new JspUtil.ValidAttribute("property", true),
+ new JspUtil.ValidAttribute("value"),
+ new JspUtil.ValidAttribute("param")
};
public boolean accept(ParseEventListener listener, JspReader reader, Parser parser)
@@ -704,7 +720,7 @@
Mark start = reader.mark();
reader.advance(OPEN_SETPROPERTY.length());
Hashtable attrs = reader.parseTagAttributes ();
- checkAttributes ("setProperty", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("setProperty", attrs, validAttributes);
reader.skipSpaces();
if (!reader.matches(CLOSE_SETPROPERTY))
throw new ParseException(reader.mark(),
@@ -851,22 +867,20 @@
private static final String OPEN_FALLBACK = "<jsp:fallback>";
private static final String CLOSE_FALLBACK = "</jsp:fallback>";
- private static final String[] validAttributes = {
- "type",
- "code",
- "codebase",
- "align",
- "archive",
- "height",
- "hspace",
- "jreversion",
- "name",
- "vspace",
- "width",
- "nspluginurl",
- "iepluginurl",
- "params",
- "fallback"
+ private static final JspUtil.ValidAttribute[] validAttributes = {
+ new JspUtil.ValidAttribute ("type",true),
+ new JspUtil.ValidAttribute("code", true),
+ new JspUtil.ValidAttribute("codebase"),
+ new JspUtil.ValidAttribute("align"),
+ new JspUtil.ValidAttribute("archive"),
+ new JspUtil.ValidAttribute("height"),
+ new JspUtil.ValidAttribute("hspace"),
+ new JspUtil.ValidAttribute("jreversion"),
+ new JspUtil.ValidAttribute("name"),
+ new JspUtil.ValidAttribute("vspace"),
+ new JspUtil.ValidAttribute("width"),
+ new JspUtil.ValidAttribute("nspluginurl"),
+ new JspUtil.ValidAttribute("iepluginurl")
};
public boolean accept(ParseEventListener listener, JspReader reader,
@@ -888,7 +902,7 @@
Hashtable param = null;
String fallback = null;
- checkAttributes ("plugin", attrs.keys(), validAttributes);
+ JspUtil.checkAttributes ("plugin", attrs, validAttributes);
if (reader.matches (OPEN_PARAMS)) {
param = new Hashtable ();
boolean paramsClosed = false;
@@ -1051,27 +1065,5 @@
caw.write((char) reader.nextChar());
}
flushCharData();
- }
-
-
- public static void checkAttributes (String typeOfTag, Enumeration enum,
- String[] validAttributes) throws JasperException
- {
- String attribute = null;
- boolean valid;
- while (enum.hasMoreElements()) {
- valid = false;
- attribute = (String) enum.nextElement();
- for (int i=0; i < validAttributes.length; i++) {
- if (attribute.equals (validAttributes[i])) {
- valid = true;
- break;
- }
- }
- if (!(valid))
- throw new JasperException(Constants.getString(
- "jsp.error.invalid.attribute",
- new Object[] { typeOfTag, attribute }));
- }
}
}
1.6 +2 -2 jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties
Index: messages.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- messages.properties 1999/11/03 23:43:41 1.5
+++ messages.properties 1999/12/23 08:30:20 1.6
@@ -64,7 +64,7 @@
jsp.error.unable.compile=Unable to compile class for JSP
jsp.error.unable.load=Unable to compile class for JSP
jsp.error.unable.rename=Unable to rename class file {0} to {1}
-jsp.error.invalid.attribute={0}: Invalid attribute, {1}
+jsp.error.mandatory.attribute={0}: Mandatory attribute {1} missing
jsp.engine.info=JSP 1.1 Engine EA
jsp.error.invalid.attribute={0}: Invalid attribute, {1}
jsp.error.usebean.class.notfound=Class: {0} not found
@@ -134,4 +134,4 @@
jsp.error.unable.to_find_method=Unable to find setter method for attribute: {0}
jsp.error.unable.to_introspect=Unable to introspect on tag handler class: {0} because of {1}
jsp.error.invalid_attributes=Attributes are invalid according to TagInfo
-jsp.error.bad_tag=No such tag {0} in the tag library imported with prefix {1}
\ No newline at end of file
+jsp.error.bad_tag=No such tag {0} in the tag library imported with prefix {1}