You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2013/11/26 07:30:08 UTC

svn commit: r1545553 - in /tomcat/trunk: java/org/apache/jasper/compiler/JspDocumentParser.java java/org/apache/jasper/compiler/JspUtil.java test/org/apache/jasper/compiler/TestJspDocumentParser.java

Author: jboynes
Date: Tue Nov 26 06:30:07 2013
New Revision: 1545553

URL: http://svn.apache.org/r1545553
Log:
use an InputSource in JspDocumentParser to provide a base URI for resolution

Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java
    tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java
    tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java

Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java?rev=1545553&r1=1545552&r2=1545553&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java Tue Nov 26 06:30:07 2013
@@ -19,7 +19,6 @@ package org.apache.jasper.compiler;
 import java.io.CharArrayWriter;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -171,27 +170,24 @@ class JspDocumentParser
 
             // Parse the input
             SAXParser saxParser = getSAXParser(validate, jspDocParser);
-            InputStream inStream = null;
+            InputSource source = JspUtil.getInputSource(path, jar, jspDocParser.ctxt);
             try {
-                inStream = JspUtil.getInputStream(path, jar, jspDocParser.ctxt);
-                saxParser.parse(new InputSource(inStream), jspDocParser);
+                saxParser.parse(source, jspDocParser);
             } catch (EnableDTDValidationException e) {
                 saxParser = getSAXParser(true, jspDocParser);
                 jspDocParser.isValidating = true;
-                if (inStream != null) {
-                    try {
-                        inStream.close();
-                    } catch (Exception any) {
-                    }
+                try {
+                    source.getByteStream().close();
+                } catch (IOException e2) {
+                    // ignore
                 }
-                inStream = JspUtil.getInputStream(path, jar, jspDocParser.ctxt);
-                saxParser.parse(new InputSource(inStream), jspDocParser);
+                source = JspUtil.getInputSource(path, jar, jspDocParser.ctxt);
+                saxParser.parse(source, jspDocParser);
             } finally {
-                if (inStream != null) {
-                    try {
-                        inStream.close();
-                    } catch (Exception any) {
-                    }
+                try {
+                    source.getByteStream().close();
+                } catch (IOException e) {
+                    // ignore
                 }
             }
 

Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java?rev=1545553&r1=1545552&r2=1545553&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java Tue Nov 26 06:30:07 2013
@@ -28,6 +28,7 @@ import org.apache.jasper.JasperException
 import org.apache.jasper.JspCompilationContext;
 import org.apache.tomcat.util.scan.Jar;
 import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
 
 /**
  * This class has all the utility method(s). Ideally should move all the bean
@@ -664,6 +665,20 @@ public class JspUtil {
         return in;
     }
 
+    public static InputSource getInputSource(String fname, Jar jar, JspCompilationContext ctxt)
+        throws IOException {
+        InputSource source;
+        if (jar != null) {
+            String jarEntryName = fname.substring(1, fname.length());
+            source = new InputSource(jar.getInputStream(jarEntryName));
+            source.setSystemId(jar.getURL(jarEntryName));
+        } else {
+            source = new InputSource(ctxt.getResourceAsStream(fname));
+            source.setSystemId(ctxt.getResource(fname).toExternalForm());
+        }
+        return source;
+    }
+
     /**
      * Gets the fully-qualified class name of the tag handler corresponding to
      * the given tag file path.

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java?rev=1545553&r1=1545552&r2=1545553&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java Tue Nov 26 06:30:07 2013
@@ -132,7 +132,6 @@ public class TestJspDocumentParser exten
 
         tomcat.start();
 
-        ByteChunk bc = new ByteChunk();
         String path = "http://localhost:" + getPort() + "/test/valid.jspx";
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(true);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org