Java源码示例:org.apache.jasper.JspCompilationContext
示例1
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
}
示例2
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);
}
示例3
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;
}
示例4
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;
}
示例5
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;
}
示例6
/**
* 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);
}
示例7
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);
}
示例8
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;
}
示例9
/**
* 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);
}
示例10
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);
}
示例11
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;
}
示例12
private String[] generateTLDLocation(String uri,
JspCompilationContext ctxt)
throws JasperException {
int uriType = TldScanner.uriType(uri);
if (uriType == TldScanner.ABS_URI) {
err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
uri);
} else if (uriType == TldScanner.NOROOT_REL_URI) {
uri = ctxt.resolveRelativeUri(uri);
}
String[] location = new String[2];
location[0] = uri;
if (location[0].endsWith("jar")) {
URL url = null;
try {
url = ctxt.getResource(location[0]);
} catch (Exception ex) {
err.jspError("jsp.error.tld.unable_to_get_jar", location[0],
ex.toString());
}
if (url == null) {
err.jspError("jsp.error.tld.missing_jar", location[0]);
}
location[0] = url.toString();
location[1] = "META-INF/taglib.tld";
}
return location;
}
示例13
/**
* 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;
}
示例14
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);
}
示例15
/**
* 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);
}
}
}
}
}
示例16
@Override
public String interpreterCall(JspCompilationContext context,
boolean isTagFile, String expression,
Class<?> expectedType, String fnmapvar) {
return JspUtil.interpreterCall(isTagFile, expression, expectedType,
fnmapvar);
}
示例17
/** 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);
}
示例18
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();
}
}
示例19
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);
}
示例20
/**
* 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;
}
示例21
/**
* 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;
}
示例22
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);
}
}
示例23
/**
* 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);
}
}
}
}
示例24
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);
}
示例25
/**
* 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;
}
示例26
/**
* 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;
}
示例27
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);
}
}
示例28
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);
}
示例29
@Override
public String interpreterCall(JspCompilationContext context,
boolean isTagFile, String expression,
Class<?> expectedType, String fnmapvar, boolean xmlEscape) {
return JspUtil.interpreterCall(isTagFile, expression, expectedType,
fnmapvar, xmlEscape);
}
示例30
/**
* 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);
}
}
}
}