📄 jspparseeventlistener.java
字号:
writer.println(); writer.println("if (_jspx_inited == false) {"); writer.pushIndent(); writer.println("_jspx_init();"); writer.println("_jspx_inited = true;"); writer.popIndent(); writer.println("}"); writer.println("_jspxFactory = JspFactory.getDefaultFactory();"); if (this.contentTypeDir == true) writer.println("response.setContentType(" + writer.quoteString(servletContentType) + ");"); else writer.println("response.setContentType(\"" + servletContentType + ";charset=8859_1\");"); writer.println("pageContext = _jspxFactory.getPageContext(this, request, response,\n" + "\t\t\t" + writer.quoteString(error) + ", " + genSessionVariable + ", " + bufferSize + ", " + autoFlush + ");"); writer.println(); writer.println("application = pageContext.getServletContext();"); writer.println("config = pageContext.getServletConfig();"); if (genSessionVariable) writer.println("session = pageContext.getSession();"); writer.println("out = pageContext.getOut();"); } private void generateFooter() throws JasperException { writer.popIndent(); //writer.println("} catch (Throwable t) {"); writer.println("} catch (Exception ex) {"); writer.pushIndent(); writer.println("if (out.getBufferSize() != 0)"); writer.pushIndent(); writer.println("out.clearBuffer();"); writer.popIndent(); writer.println("pageContext.handlePageException(ex);"); writer.popIndent(); writer.println("} finally {"); writer.pushIndent(); /* Do stuff here for finally actions... */ //writer.println("out.close();"); writer.println("out.flush();"); writer.println("_jspxFactory.releasePageContext(pageContext);"); writer.popIndent(); writer.println("}"); // Close the service method: writer.popIndent(); writer.println("}"); // Close the class definition: writer.popIndent(); writer.println("}"); } public void handleComment(Mark start, Mark stop) throws JasperException { Constants.message("jsp.message.htmlcomment", new Object[] { reader.getChars(start, stop) }, Logger.DEBUG); } interface PageDirectiveHandler { void handlePageDirectiveAttribute(JspParseEventListener listener, String value, Mark start, Mark stop) throws JasperException; } static final class PageDirectiveHandlerInfo { String attribute; PageDirectiveHandler handler; PageDirectiveHandlerInfo(String attribute, PageDirectiveHandler handler) { this.attribute = attribute; this.handler = handler; } } static final String languageStr = "language"; static final String extendsStr = "extends"; static final String importStr = "import"; static final String sessionStr = "session"; static final String bufferStr = "buffer"; static final String autoFlushStr = "autoFlush"; static final String isThreadSafeStr = "isThreadSafe"; static final String infoStr = "info"; static final String errorPageStr = "errorPage"; static final String isErrorPageStr = "isErrorPage"; static final String contentTypeStr = "contentType"; PageDirectiveHandlerInfo[] pdhis = new PageDirectiveHandlerInfo[] { new PageDirectiveHandlerInfo(languageStr, new LanguageHandler()), new PageDirectiveHandlerInfo(extendsStr, new ExtendsHandler()), new PageDirectiveHandlerInfo(importStr, new ImportsHandler()), new PageDirectiveHandlerInfo(sessionStr, new SessionHandler()), new PageDirectiveHandlerInfo(bufferStr, new BufferHandler()), new PageDirectiveHandlerInfo(autoFlushStr, new AutoFlushHandler()), new PageDirectiveHandlerInfo(isThreadSafeStr, new IsThreadSafeHandler()), new PageDirectiveHandlerInfo(infoStr, new InfoHandler()), new PageDirectiveHandlerInfo(isErrorPageStr, new IsErrorPageHandler()), new PageDirectiveHandlerInfo(contentTypeStr, new ContentTypeHandler()), new PageDirectiveHandlerInfo(errorPageStr, new ErrorPageHandler()) }; // FIXME: Need to further refine these abstractions by moving the code // to handle duplicate directive instance checks to outside. static final class ContentTypeHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String contentType, Mark start, Mark stop) throws JasperException { if (listener.contentTypeDir == true) throw new CompileException(start, Constants.getString("jsp.error.page.multiple.contenttypes")); listener.contentTypeDir = true; if (contentType == null) throw new CompileException(start, Constants.getString("jsp.error.page.invalid.contenttype")); listener.servletContentType = contentType; } } static final class SessionHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String session, Mark start, Mark stop) throws JasperException { if (listener.sessionDir == true) throw new CompileException (start, Constants.getString("jsp.error.page.multiple.session")); listener.sessionDir = true; if (session == null) throw new CompileException (start, Constants.getString("jsp.error.page.invalid.session")); if (session.equalsIgnoreCase("true")) listener.genSessionVariable = true; else if (session.equalsIgnoreCase("false")) listener.genSessionVariable = false; else throw new CompileException(start, "Invalid value for session"); } } static final class BufferHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String buffer, Mark start, Mark stop) throws JasperException { if (listener.bufferDir == true) throw new CompileException(start, Constants.getString("jsp.error.page.multiple.buffer")); listener.bufferDir = true; if (buffer != null) { if (buffer.equalsIgnoreCase("none")) listener.bufferSize = 0; else { Integer i = null; try { int ind = buffer.indexOf("k"); String num; if (ind == -1) num = buffer; else num = buffer.substring(0, ind); i = new Integer(num); } catch (NumberFormatException n) { throw new CompileException(start, Constants.getString( "jsp.error.page.invalid.buffer")); } listener.bufferSize = i.intValue()*1024; } } else throw new CompileException(start, Constants.getString("jsp.error.page.invalid.buffer")); } } static final class AutoFlushHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String autoflush, Mark start, Mark stop) throws JasperException { if (listener.autoFlushDir == true) throw new CompileException(start, Constants.getString("jsp.error.page.multiple.autoflush")); listener.autoFlushDir = true; if (autoflush == null) throw new CompileException(start, Constants.getString("jsp.error.page.invalid.autoflush")); if (autoflush.equalsIgnoreCase("true")) listener.autoFlush = true; else if (autoflush.equalsIgnoreCase("false")) listener.autoFlush = false; else throw new CompileException(start, Constants.getString("jsp.error.page.invalid.autoflush")); } } static final class IsThreadSafeHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String threadsafe, Mark start, Mark stop) throws JasperException { if (listener.threadsafeDir == true) throw new CompileException(start, Constants.getString("jsp.error.page.multiple.threadsafe")); listener.threadsafeDir = true; if (threadsafe == null) throw new CompileException (start, Constants.getString("jsp.error.page.invalid.threadsafe")); if (threadsafe.equalsIgnoreCase("true")) listener.singleThreaded = false; else if (threadsafe.equalsIgnoreCase("false")) listener.singleThreaded = true; else throw new CompileException (start, Constants.getString("jsp.error.page.invalid.threadsafe")); } } static final class InfoHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String info, Mark start, Mark stop) throws JasperException { if (listener.infoDir == true) throw new CompileException (start, Constants.getString("jsp.error.page.multiple.info")); listener.infoDir = true; if (info == null) throw new CompileException(start, Constants.getString("jsp.error.page.invalid.info")); GeneratorWrapper gen = listener. new GeneratorWrapper(new InfoGenerator(info), start, stop); listener.addGenerator(gen); } } static final class IsErrorPageHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String iserrorpage, Mark start, Mark stop) throws JasperException { if (listener.iserrorpageDir == true) throw new CompileException (start, Constants.getString("jsp.error.page.multiple.iserrorpage")); listener.iserrorpageDir = true; if (iserrorpage == null) throw new CompileException(start, Constants.getString("jsp.error.page.invalid.iserrorpage")); if (iserrorpage.equalsIgnoreCase("true")) listener.ctxt.setErrorPage(true); else if (iserrorpage.equalsIgnoreCase("false")) listener.ctxt.setErrorPage(false); else throw new CompileException(start, Constants.getString("jsp.error.page.invalid.iserrorpage")); } } static final class ErrorPageHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String errorpage, Mark start, Mark stop) throws JasperException { if (listener.errorpageDir == true) throw new CompileException(start, Constants.getString("jsp.error.page.multiple.errorpage")); listener.errorpageDir = true; if (errorpage != null) listener.error = errorpage; } } static final class LanguageHandler implements PageDirectiveHandler { public void handlePageDirectiveAttribute(JspParseEventListener listener, String language, Mark start, Mark stop) throws JasperException { if (listener.languageDir == true)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -