org.apache.jasper.JspCompilationContext Java Examples

The following examples show how to use org.apache.jasper.JspCompilationContext. 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: JspServletWrapper.java    From packagedrone with Eclipse Public License 1.0 7 votes vote down vote up
JspServletWrapper(ServletConfig config, Options options, String jspUri,
                     boolean isErrorPage, JspRuntimeContext rctxt)
           throws JasperException {

this.isTagFile = false;
       this.config = config;
       this.options = options;
       this.jspUri = jspUri;
       this.jspProbeEmitter = (JspProbeEmitter)
           config.getServletContext().getAttribute(
               "org.glassfish.jsp.monitor.probeEmitter");

       ctxt = new JspCompilationContext(jspUri, isErrorPage, options,
				 config.getServletContext(),
				 this, rctxt);
       // START PWC 6468930
       String jspFilePath = ctxt.getRealPath(jspUri);
       if (jspFilePath != null) {
           jspFile = new File(jspFilePath);
       }
       // END PWC 6468930
   }
 
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: JspServletWrapper.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public JspServletWrapper(ServletContext servletContext,
		     Options options,
		     String tagFilePath,
		     TagInfo tagInfo,
		     JspRuntimeContext rctxt,
		     URL tagFileJarUrl)
    throws JasperException {

this.isTagFile = true;
       this.config = null;	// not used
       this.options = options;
this.jspUri = tagFilePath;
this.tripCount = 0;
       ctxt = new JspCompilationContext(jspUri, tagInfo, options,
				 servletContext, this, rctxt,
				 tagFileJarUrl);
   }
 
Example #4
Source File: WebAppParseSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public JspParserAPI.JspOpenInfo getJspOpenInfo(FileObject jspFile, boolean useEditor
        /*, URLClassLoader waClassLoader*/) {
    // PENDING - do caching for individual JSPs
    //  in fact should not be needed - see FastOpenInfoParser.java
    checkReinitCachesTask();
    JspCompilationContext ctxt = createCompilationContext(jspFile, useEditor);
    ExtractPageData epd = new ExtractPageData(ctxt);
    try {
        return new JspParserAPI.JspOpenInfo(epd.isXMLSyntax(), epd.getEncoding());
    } catch (Exception e) {
        LOG.fine(e.getMessage());
    } finally {
        resetClassLoaders();
    }
    return DEFAULT_JSP_OPEN_INFO;
}
 
Example #5
Source File: JspReader.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor: same as above constructor but with initialized reader
 * to the file given.
 */
public JspReader(JspCompilationContext ctxt,
                 String fname,
                 String encoding,
                 InputStreamReader reader,
                 ErrorDispatcher err)
        throws JasperException {

    this.context = ctxt;
    this.err = err;
    sourceFiles = new Vector<String>();
    currFileId = 0;
    size = 0;
    singleFile = false;
    pushFile(fname, encoding, reader);
}
 
Example #6
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 #7
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 #8
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 #9
Source File: JspReader.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor: same as above constructor but with initialized reader
 * to the file given.
 */
public JspReader(JspCompilationContext ctxt,
                 String fname,
                 String encoding,
                 InputStreamReader reader,
                 ErrorDispatcher err)
        throws JasperException {

    this.context = ctxt;
    this.err = err;
    sourceFiles = new Vector<String>();
    currFileId = 0;
    size = 0;
    singleFile = false;
    pushFile(fname, encoding, reader);
}
 
Example #10
Source File: JspServletWrapper.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public JspServletWrapper(ServletContext servletContext,
                         Options options,
                         String tagFilePath,
                         TagInfo tagInfo,
                         JspRuntimeContext rctxt,
                         JarResource tagJarResource) {

    this.isTagFile = true;
    this.config = null;        // not used
    this.options = options;
    this.jspUri = tagFilePath;
    this.tripCount = 0;
    unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
    unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
    unloadAllowed = unloadByCount || unloadByIdle ? true : false;
    ctxt = new JspCompilationContext(jspUri, tagInfo, options,
                                     servletContext, this, rctxt,
                                     tagJarResource);
}
 
Example #11
Source File: JspServletWrapper.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public JspServletWrapper(ServletContext servletContext,
                         Options options,
                         String tagFilePath,
                         TagInfo tagInfo,
                         JspRuntimeContext rctxt,
                         Jar tagJar) {

    this.isTagFile = true;
    this.config = null;        // not used
    this.options = options;
    this.jspUri = tagFilePath;
    this.tripCount = 0;
    unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
    unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
    unloadAllowed = unloadByCount || unloadByIdle ? true : false;
    ctxt = new JspCompilationContext(jspUri, tagInfo, options,
                                     servletContext, this, rctxt,
                                     tagJar);
}
 
Example #12
Source File: Mark.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * Constructor
    */    
   Mark(JspCompilationContext ctxt, String filename, int line, int col) {
this.reader = null;
       this.ctxt = ctxt;
this.stream = null;
this.cursor = 0;
this.line = line;
this.col = col;
this.fileid = -1;
this.fileName = filename;
this.baseDir = "le-basedir";
this.encoding = "le-endocing";
this.includeStack = null;
   }
 
Example #13
Source File: Jsr199JavaCompiler.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void init(JspCompilationContext ctxt,
                 ErrorDispatcher errDispatcher,
                 boolean suppressLogging) {
    this.ctxt = ctxt;
    this.errDispatcher = errDispatcher;
    rtctxt = ctxt.getRuntimeContext();
    options.add("-proc:none");  // Disable annotation processing
}
 
Example #14
Source File: NullJavaCompiler.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void init(JspCompilationContext ctxt,
                 ErrorDispatcher errDispatcher,
                 boolean suppressLogging) {

    this.ctxt = ctxt;
    this.errDispatcher = errDispatcher;
}
 
Example #15
Source File: JspReader.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Constructor: same as above constructor but with initialized reader
 * to the file given.
 *
 * @param ctxt   The compilation context
 * @param fname  The file name
 * @param reader A reader for the JSP source file
 * @param err The error dispatcher
 *
 * @throws JasperException If an error occurs parsing the JSP file
 */
public JspReader(JspCompilationContext ctxt,
                 String fname,
                 InputStreamReader reader,
                 ErrorDispatcher err)
        throws JasperException {

    this.context = ctxt;
    this.err = err;

    try {
        CharArrayWriter caw = new CharArrayWriter();
        char buf[] = new char[1024];
        for (int i = 0 ; (i = reader.read(buf)) != -1 ;)
            caw.write(buf, 0, i);
        caw.close();
        current = new Mark(this, caw.toCharArray(), fname);
    } catch (Throwable ex) {
        ExceptionUtils.handleThrowable(ex);
        log.error("Exception parsing file ", ex);
        err.jspError("jsp.error.file.cannot.read", fname);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception any) {
                if(log.isDebugEnabled()) {
                    log.debug("Exception closing reader: ", any);
                }
            }
        }
    }
}
 
Example #16
Source File: Compiler.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public Compiler(JspCompilationContext ctxt, JspServletWrapper jsw) {
    this.jsw = jsw;
    this.ctxt = ctxt;
    this.jspcMode = false;
    this.options = ctxt.getOptions();
    this.log = Logger.getLogger(Compiler.class.getName());
    this.smapUtil = new SmapUtil(ctxt);
    this.errDispatcher = new ErrorDispatcher(jspcMode);
    this.javaCompiler = new NullJavaCompiler();
    javaCompiler.init(ctxt, errDispatcher, jspcMode);
    this.javaCompilerOptionsSet = false;
}
 
Example #17
Source File: JspReader.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public JspReader(JspCompilationContext ctxt,
	     String fname,
	     String encoding,
	     InputStreamReader reader,
	     ErrorDispatcher err)
    throws JasperException, FileNotFoundException {

       this.context = ctxt;
this.err = err;
sourceFiles = new ArrayList<String>();
currFileId = 0;
size = 0;
singleFile = false;
pushFile(fname, encoding, reader);
   }
 
Example #18
Source File: GetParseData.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of ExtractPageData */
public GetParseData(JspCompilationContext ctxt, int errorReportingMode) {
    this.ctxt = ctxt;
    this.errorReportingMode = errorReportingMode;
    options = ctxt.getOptions();
    compHacks = new CompilerHacks(ctxt);
}
 
Example #19
Source File: Mark.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Constructor
 */
Mark(JspCompilationContext ctxt, String filename, int line, int col) {
    this.ctxt = ctxt;
    this.stream = null;
    this.cursor = 0;
    this.line = line;
    this.col = col;
    this.fileName = filename;
}
 
Example #20
Source File: JspServletWrapper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public JspServletWrapper(ServletConfig config, Options options,
        String jspUri, JspRuntimeContext rctxt) {

    this.isTagFile = false;
    this.config = config;
    this.options = options;
    this.jspUri = jspUri;
    unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
    unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
    unloadAllowed = unloadByCount || unloadByIdle ? true : false;
    ctxt = new JspCompilationContext(jspUri, options,
                                     config.getServletContext(),
                                     this, rctxt);
}
 
Example #21
Source File: WebAppParseSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JspParserAPI.ParseResult analyzePage(FileObject jspFile, /*String compilationURI, */
        int errorReportingMode) {
    // PENDING - do caching for individual JSPs
    checkReinitCachesTask();
    JspCompilationContext ctxt = createCompilationContext(jspFile, true);

    try {
        return callTomcatParser(jspFile, ctxt, waContextClassLoader, errorReportingMode);
    } finally {
        resetClassLoaders();
    }
}
 
Example #22
Source File: JspServletWrapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public JspServletWrapper(ServletConfig config, Options options,
        String jspUri, JspRuntimeContext rctxt) {

    this.isTagFile = false;
    this.config = config;
    this.options = options;
    this.jspUri = jspUri;
    unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
    unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
    unloadAllowed = unloadByCount || unloadByIdle ? true : false;
    ctxt = new JspCompilationContext(jspUri, options,
                                     config.getServletContext(),
                                     this, rctxt);
}
 
Example #23
Source File: XMLEncodingDetector.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Autodetects the encoding of the XML document supplied by the given
 * input stream.
 *
 * Encoding autodetection is done according to the XML 1.0 specification,
 * Appendix F.1: Detection Without External Encoding Information.
 *
 * @return Two-element array, where the first element (of type
 * java.lang.String) contains the name of the (auto)detected encoding, and
 * the second element (of type java.lang.Boolean) specifies whether the 
 * encoding was specified using the 'encoding' attribute of an XML prolog
 * (TRUE) or autodetected (FALSE).
 */
public static Object[] getEncoding(String fname, JarFile jarFile,
                                   JspCompilationContext ctxt,
                                   ErrorDispatcher err)
    throws IOException, JasperException
{
    InputStream inStream = JspUtil.getInputStream(fname, jarFile, ctxt,
                                                  err);
    XMLEncodingDetector detector = new XMLEncodingDetector();
    Object[] ret = detector.getEncoding(inStream, err);
    inStream.close();

    return ret;
}
 
Example #24
Source File: TagLibraryInfoImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
        throws JasperException {

    int uriType = TldLocationsCache.uriType(uri);
    if (uriType == TldLocationsCache.ABS_URI) {
        err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
                uri);
    } else if (uriType == TldLocationsCache.NOROOT_REL_URI) {
        uri = ctxt.resolveRelativeUri(uri);
    }

    if (uri.endsWith(".jar")) {
        URL url = null;
        try {
            url = ctxt.getResource(uri);
        } catch (Exception ex) {
            err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
                    .toString());
        }
        if (url == null) {
            err.jspError("jsp.error.tld.missing_jar", uri);
        }
        return new TldLocation("META-INF/taglib.tld", url.toString());
    } else if (uri.startsWith("/WEB-INF/lib/")
            || uri.startsWith("/WEB-INF/classes/") ||
            (uri.startsWith("/WEB-INF/tags/") && uri.endsWith(".tld")
                    && !uri.endsWith("implicit.tld"))) {
        err.jspError("jsp.error.tld.invalid_tld_file", uri);
    }

    return new TldLocation(uri);
}
 
Example #25
Source File: Mark.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 */    
Mark(JspCompilationContext ctxt, String filename, int line, int col) {

    this.reader = null;
    this.ctxt = ctxt;
    this.stream = null;
    this.cursor = 0;
    this.line = line;
    this.col = col;
    this.fileId = -1;
    this.fileName = filename;
    this.baseDir = "le-basedir";
    this.encoding = "le-endocing";
    this.includeStack = null;
}
 
Example #26
Source File: JDTJavaCompiler.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void init(JspCompilationContext ctxt,
                 ErrorDispatcher errDispatcher,
                 boolean suppressLogging) {
    this.errDispatcher = errDispatcher;
    this.ctxt = ctxt;
    log = Logger.getLogger(JDTJavaCompiler.class.getName());
    if (suppressLogging) {
        log.setLevel(Level.OFF);
    }
}
 
Example #27
Source File: TagLibraryInfoImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
        throws JasperException {

    int uriType = TldLocationsCache.uriType(uri);
    if (uriType == TldLocationsCache.ABS_URI) {
        err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
                uri);
    } else if (uriType == TldLocationsCache.NOROOT_REL_URI) {
        uri = ctxt.resolveRelativeUri(uri);
    }

    if (uri.endsWith(".jar")) {
        URL url = null;
        try {
            url = ctxt.getResource(uri);
        } catch (Exception ex) {
            err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
                    .toString());
        }
        if (url == null) {
            err.jspError("jsp.error.tld.missing_jar", uri);
        }
        return new TldLocation("META-INF/taglib.tld", url.toString());
    } else {
        return new TldLocation(uri);
    }
}
 
Example #28
Source File: Mark.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 */    
Mark(JspCompilationContext ctxt, String filename, int line, int col) {

    this.reader = null;
    this.ctxt = ctxt;
    this.stream = null;
    this.cursor = 0;
    this.line = line;
    this.col = col;
    this.fileId = -1;
    this.fileName = filename;
    this.baseDir = "le-basedir";
    this.encoding = "le-endocing";
    this.includeStack = null;
}
 
Example #29
Source File: XMLEncodingDetector.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Autodetects the encoding of the XML document supplied by the given
 * input stream.
 *
 * Encoding autodetection is done according to the XML 1.0 specification,
 * Appendix F.1: Detection Without External Encoding Information.
 *
 * @return Two-element array, where the first element (of type
 * java.lang.String) contains the name of the (auto)detected encoding, and
 * the second element (of type java.lang.Boolean) specifies whether the 
 * encoding was specified using the 'encoding' attribute of an XML prolog
 * (TRUE) or autodetected (FALSE).
 */
public static Object[] getEncoding(String fname, JarFile jarFile,
                                   JspCompilationContext ctxt,
                                   ErrorDispatcher err)
    throws IOException, JasperException
{
    InputStream inStream = JspUtil.getInputStream(fname, jarFile, ctxt,
                                                  err);
    XMLEncodingDetector detector = new XMLEncodingDetector();
    Object[] ret = detector.getEncoding(inStream, err);
    inStream.close();

    return ret;
}
 
Example #30
Source File: JspRuntimeContext.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Method used by background thread to check the JSP dependencies
 * registered with this class for JSP's.
 */
public void checkCompile() {

    if (lastCompileCheck < 0) {
        // Checking was disabled
        return;
    }
    long now = System.currentTimeMillis();
    if (now > (lastCompileCheck + (options.getCheckInterval() * 1000L))) {
        lastCompileCheck = now;
    } else {
        return;
    }
    
    Object [] wrappers = jsps.values().toArray();
    for (int i = 0; i < wrappers.length; i++ ) {
        JspServletWrapper jsw = (JspServletWrapper)wrappers[i];
        JspCompilationContext ctxt = jsw.getJspEngineContext();
        // JspServletWrapper also synchronizes on this when
        // it detects it has to do a reload
        synchronized(jsw) {
            try {
                ctxt.compile();
            } catch (FileNotFoundException ex) {
                ctxt.incrementRemoved();
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                jsw.getServletContext().log("Background compile failed",
                                            t);
            }
        }
    }

}