Java Code Examples for org.apache.jasper.JspCompilationContext#getResourceAsStream()

The following examples show how to use org.apache.jasper.JspCompilationContext#getResourceAsStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JspUtil.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static InputStream getInputStream(String fname, Jar jar,
        JspCompilationContext ctxt) throws IOException {

    InputStream in = null;

    if (jar != null) {
        String jarEntryName = fname.substring(1, fname.length());
        in = jar.getInputStream(jarEntryName);
    } else {
        in = ctxt.getResourceAsStream(fname);
    }

    if (in == null) {
        throw new FileNotFoundException(Localizer.getMessage(
                "jsp.error.file.not.found", fname));
    }

    return in;
}
 
Example 2
Source File: JspUtil.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static InputStream getInputStream(String fname, JarFile jarFile,
        JspCompilationContext ctxt, ErrorDispatcher err)
        throws JasperException, IOException {

    InputStream in = null;

    if (jarFile != null) {
        String jarEntryName = fname.substring(1, fname.length());
        ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
        if (jarEntry == null) {
            throw new FileNotFoundException(Localizer.getMessage(
                    "jsp.error.file.not.found", fname));
        }
        in = jarFile.getInputStream(jarEntry);
    } else {
        in = ctxt.getResourceAsStream(fname);
    }

    if (in == null) {
        throw new FileNotFoundException(Localizer.getMessage(
                "jsp.error.file.not.found", fname));
    }

    return in;
}
 
Example 3
Source File: JspUtil.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public static InputStream getInputStream(String fname, JarFile jarFile,
        JspCompilationContext ctxt, ErrorDispatcher err)
        throws JasperException, IOException {

    InputStream in = null;

    if (jarFile != null) {
        String jarEntryName = fname.substring(1, fname.length());
        ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
        if (jarEntry == null) {
            throw new FileNotFoundException(Localizer.getMessage(
                    "jsp.error.file.not.found", fname));
        }
        in = jarFile.getInputStream(jarEntry);
    } else {
        in = ctxt.getResourceAsStream(fname);
    }

    if (in == null) {
        throw new FileNotFoundException(Localizer.getMessage(
                "jsp.error.file.not.found", fname));
    }

    return in;
}
 
Example 4
Source File: JspUtil.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public static InputStream getInputStream(String fname, JarFile jarFile,
				     JspCompilationContext ctxt,
				     ErrorDispatcher err)
	throws JasperException, IOException {

       InputStream in = null;

if (jarFile != null) {
    String jarEntryName = fname.substring(1, fname.length());
    ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
    if (jarEntry == null) {
	err.jspError("jsp.error.file.not.found", fname);
    }
    in = jarFile.getInputStream(jarEntry);
} else {
    in = ctxt.getResourceAsStream(fname);
}

if (in == null) {
    err.jspError("jsp.error.file.not.found", fname);
}

return in;
   }
 
Example 5
Source File: JavacErrorDetail.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param javaFileName The name of the Java file in which the
 * compilation error occurred
 * @param javaLineNum The compilation error line number
 * @param jspFileName The name of the JSP file from which the Java source
 * file was generated
 * @param jspBeginLineNum The start line number of the JSP element
 * responsible for the compilation error
 * @param errMsg The compilation error message
 * @param ctxt The compilation context
 */
public JavacErrorDetail(String javaFileName,
        int javaLineNum,
        String jspFileName,
        int jspBeginLineNum,
        StringBuilder errMsg,
        JspCompilationContext ctxt) {

    this.javaFileName = javaFileName;
    this.javaLineNum = javaLineNum;
    this.errMsg = errMsg;
    this.jspFileName = jspFileName;
    // Note: this.jspBeginLineNum is set at the end of this method as it may
    //       be modified (corrected) during the execution of this method

    if (jspBeginLineNum > 0 && ctxt != null) {
        InputStream is = null;
        try {
            Jar tagJar = ctxt.getTagFileJar();
            if (tagJar != null) {
                // Strip leading '/'
                String entryName = jspFileName.substring(1);
                is = tagJar.getInputStream(entryName);
                this.jspFileName = tagJar.getURL(entryName);
            } else {
                is = ctxt.getResourceAsStream(jspFileName);
            }
            // Read both files in, so we can inspect them
            String[] jspLines = readFile(is);

            try (FileInputStream fis = new FileInputStream(ctxt.getServletJavaFileName())) {
                String[] javaLines = readFile(fis);

                if (jspLines.length < jspBeginLineNum) {
                    // Avoid ArrayIndexOutOfBoundsException
                    // Probably bug 48498 but could be some other cause
                    jspExtract = Localizer.getMessage("jsp.error.bug48498");
                    return;
                }

                // If the line contains the opening of a multi-line scriptlet
                // block, then the JSP line number we got back is probably
                // faulty.  Scan forward to match the java line...
                if (jspLines[jspBeginLineNum-1].lastIndexOf("<%") >
                    jspLines[jspBeginLineNum-1].lastIndexOf("%>")) {
                    String javaLine = javaLines[javaLineNum-1].trim();

                    for (int i=jspBeginLineNum-1; i<jspLines.length; i++) {
                        if (jspLines[i].indexOf(javaLine) != -1) {
                            // Update jsp line number
                            jspBeginLineNum = i+1;
                            break;
                        }
                    }
                }

                // copy out a fragment of JSP to display to the user
                StringBuilder fragment = new StringBuilder(1024);
                int startIndex = Math.max(0, jspBeginLineNum-1-3);
                int endIndex = Math.min(
                        jspLines.length-1, jspBeginLineNum-1+3);

                for (int i=startIndex;i<=endIndex; ++i) {
                    fragment.append(i+1);
                    fragment.append(": ");
                    fragment.append(jspLines[i]);
                    fragment.append(System.lineSeparator());
                }
                jspExtract = fragment.toString();
            }
        } catch (IOException ioe) {
            // Can't read files - ignore
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ignore) {
                    // Ignore
                }
            }
        }
    }
    this.jspBeginLineNum = jspBeginLineNum;
}