luehe 2002/07/29 15:29:01 Modified: jasper2/src/share/org/apache/jasper/compiler JspDocumentParser.java Parser.java ParserController.java jasper2/src/share/org/apache/jasper/resources messages.properties Log: Reject tag-file related actions when parsing JSP document, and reject page directive when parsing tag file document. Revision Changes Path 1.10 +51 -18 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java Index: JspDocumentParser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JspDocumentParser.java 25 Jul 2002 19:02:16 -0000 1.9 +++ JspDocumentParser.java 29 Jul 2002 22:29:01 -0000 1.10 @@ -91,42 +91,34 @@ = "http://xml.org/sax/properties/lexical-handler"; private ParserController parserController; - - // XXX - private JspCompilationContext ctxt; - + private JspCompilationContext ctxt; // XML document source private InputSource inputSource; - - // XXX private String path; - // Node representing the XML element currently being parsed private Node current; - // Document locator private Locator locator; - - // XXX private Hashtable taglibs; - // Flag indicating whether we are inside DTD declarations private boolean inDTD; - private ErrorDispatcher err; + private boolean isTagFile; /* * Constructor */ public JspDocumentParser(ParserController pc, String path, - InputStreamReader reader) { + InputStreamReader reader, + boolean isTagFile) { this.parserController = pc; this.ctxt = pc.getJspCompilationContext(); this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries(); this.err = pc.getCompiler().getErrorDispatcher(); this.path = path; this.inputSource = new InputSource(reader); + this.isTagFile = isTagFile; } /* @@ -137,8 +129,10 @@ public static Node.Nodes parse(ParserController pc, String path, InputStreamReader reader, - Node parent) throws JasperException { - JspDocumentParser handler = new JspDocumentParser(pc, path, reader); + Node parent, + boolean isTagFile) throws JasperException { + JspDocumentParser handler = new JspDocumentParser(pc, path, reader, + isTagFile); handler.current = parent; Node.Nodes pageNodes = null; @@ -191,6 +185,11 @@ throw new SAXException(je); } } else if (qName.equals(JSP_PAGE_DIRECTIVE)) { + if (isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.istagfile", qName), + locator); + } node = new Node.PageDirective(attrsCopy, start, current); String imports = attrs.getValue("import"); // There can only be one 'import' attribute per page directive @@ -238,13 +237,47 @@ } else if (qName.equals(JSP_ATTRIBUTE)) { node = new Node.NamedAttribute(attrsCopy, start, current); } else if (qName.equals(JSP_TAG_DIRECTIVE)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } node = new Node.TagDirective(attrsCopy, start, current); } else if (qName.equals(JSP_ATTRIBUTE_DIRECTIVE)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } node = new Node.AttributeDirective(attrsCopy, start, current); } else if (qName.equals(JSP_VARIABLE_DIRECTIVE)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } node = new Node.VariableDirective(attrsCopy, start, current); } else if (qName.equals(JSP_FRAGMENT_INPUT_DIRECTIVE)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } node = new Node.FragmentInputDirective(attrsCopy, start, current); + } else if (qName.equals(JSP_INVOKE)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } + node = new Node.InvokeAction(attrsCopy, start, current); + } else if (qName.equals(JSP_DO_BODY)) { + if (!isTagFile) { + throw new SAXParseException( + err.getString("jsp.error.action.isnottagfile", qName), + locator); + } + node = new Node.DoBodyAction(attrsCopy, start, current); } else { node = getCustomTag(qName, attrsCopy, start, current); if (node == null) { 1.16 +5 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Parser.java 26 Jul 2002 22:40:50 -0000 1.15 +++ Parser.java 29 Jul 2002 22:29:01 -0000 1.16 @@ -428,12 +428,12 @@ directive = "<%@ taglib"; parseTaglibDirective(parent); } else if (reader.matches("tag")) { - directive = "<%@ page"; + directive = "<%@ tag"; if (!isTagFile) { err.jspError(reader.mark(), "jsp.error.directive.isnottagfile", directive); } - parsePageDirective(parent); + parseTagDirective(parent); } else if (reader.matches("attribute")) { directive = "<%@ attribute"; if (!isTagFile) { 1.8 +2 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java Index: ParserController.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ParserController.java 24 Jul 2002 23:57:12 -0000 1.7 +++ ParserController.java 29 Jul 2002 22:29:01 -0000 1.8 @@ -196,7 +196,8 @@ reader = getReader(absFileName, encoding); if (isXml) { parsedPage = JspDocumentParser.parse(this, absFileName, - reader, parent); + reader, parent, + isTagFile); } else { JspReader r = new JspReader(ctxt, absFileName, encoding, reader, 1.18 +5 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties Index: messages.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- messages.properties 26 Jul 2002 22:40:50 -0000 1.17 +++ messages.properties 29 Jul 2002 22:29:01 -0000 1.18 @@ -65,9 +65,10 @@ jsp.error.unknownException=Unhandled error! You might want to consider having an error page \ to report such errors more gracefully jsp.error.invalid.directive=Invalid directive -jsp.error.idirective.istagfile={0} directive cannot be used in a tag file -jsp.error.idirective.isnottagfile={0} directive can only be used in a tag file -jsp.error.invalid.action.isnottagfile={0} action can be used in tag files only +jsp.error.directive.istagfile={0} directive cannot be used in a tag file +jsp.error.directive.isnottagfile={0} directive can only be used in a tag file +jsp.error.action.istagfile={0} action cannot be used in a tag file +jsp.error.action.isnottagfile={0} action can be used in tag files only jsp.error.unterminated=Unterminated {0} tag jsp.error.usebean.notinsamefile=useBean tag must begin and end in the same physical file jsp.error.unable.loadclass=Unable to load class {0}
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>