DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22502>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22502 Jasper can't parse a XML format JSP file encoding Summary: Jasper can't parse a XML format JSP file encoding Product: Tomcat 4 Version: 4.1.27 Platform: All OS/Version: All Status: NEW Severity: Normal Priority: Other Component: Jasper AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Tomcat5 is able to parse a XML format JSP file encoding, but Tomcat4 isn't. I thought org.xml.sax.InputSource didn't instantiate with java.io.InputStream. So, I read Jasper source and made two patches as follows. jakarta-tomcat-4.1.27-src/jasper/src/share/org/apache/jasper/compiler/JspDocumentParser.java jakarta-tomcat-4.1.27-src/jasper/src/share/org/apache/jasper/compiler/ParserController.java --- original/JspDocumentParser.java Mon Aug 18 14:26:17 2003 +++ ../jakarta-tomcat-4.1.27-src/jasper/src/share/org/apache/jasper/compiler/Jsp DocumentParser.java Mon Aug 18 16:25:27 2003 @@ -128,6 +128,16 @@ this.path = path; this.inputSource = new InputSource(reader); } + public JspDocumentParser(ParserController pc, + String path, + InputStream inputstream) { + 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(inputstream); + } /* * Parses a JSP document by responding to SAX events. @@ -139,6 +149,46 @@ InputStreamReader reader, Node parent) throws JasperException { JspDocumentParser handler = new JspDocumentParser(pc, path, reader); + handler.current = parent; + Node.Nodes pageNodes = null; + + try { + // Use the default (non-validating) parser + SAXParserFactory factory = SAXParserFactory.newInstance(); + + // Configure the parser + SAXParser saxParser = factory.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, handler); + xmlReader.setErrorHandler(handler); + + // Parse the input + saxParser.parse(handler.inputSource, handler); + + if (parent == null) { + // Add the jsp:root element to the parse result + pageNodes = new Node.Nodes((Node.JspRoot) handler.current); + } else { + pageNodes = parent.getBody(); + } + } catch (IOException ioe) { + handler.err.jspError("jsp.error.data.file.read", path, ioe); + } catch (Exception e) { + handler.err.jspError(e); + } + + return pageNodes; + } + /* + * Parses a JSP document by responding to SAX events. + * + * @throws JasperException XXX + */ + public static Node.Nodes parse(ParserController pc, + String path, + InputStream inputstream, + Node parent) throws JasperException { + JspDocumentParser handler = new JspDocumentParser(pc, path, inputstream) ; handler.current = parent; Node.Nodes pageNodes = null; ############################################################################ --- original/ParserController.java Mon Aug 18 14:26:24 2003 +++ ../jakarta-tomcat-4.1.27-src/jasper/src/share/org/apache/jasper/compiler/Par serController.java Mon Aug 18 16:29:06 2003 @@ -167,6 +167,7 @@ String absFileName = resolveFileName(inFileName); String encoding = topFileEncoding; InputStreamReader reader = null; + InputStream is = null; try { // Figure out what type of JSP document we are dealing with reader = getReader(absFileName, encoding); @@ -188,11 +189,12 @@ // dispatch to the proper parser - reader = getReader(absFileName, encoding); if (isXml) { - parsedPage = JspDocumentParser.parse(this, absFileName, - reader, parent); + is = getInputStream(absFileName); + parsedPage = JspDocumentParser.parse(this, absFileName, is, + parent); } else { + reader = getReader(absFileName, encoding); JspReader r = new JspReader(ctxt, absFileName, encoding, reader, compiler.getErrorDispatcher()); @@ -206,6 +208,12 @@ } catch (Exception any) { } } + if (is != null) { + try { + is.close(); + } catch (Exception any) { + } + } } return parsedPage; @@ -312,6 +320,17 @@ Constants.getString("jsp.error.unsupported.encoding", new Object[]{encoding})); } + } + private InputStream getInputStream(String file) + throws FileNotFoundException + { + InputStream in; + + in = ctxt.getResourceAsStream(file); + if (in == null) { + throw new FileNotFoundException(file); + } + return in; } private void p(String s) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]