pagecontextimpl.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,055 行 · 第 1/4 页
JAVA
2,055 行
} public Enumeration getAttributeNamesInScope(int scope) { return getAttributeNames(scope); } /** * Finds an attribute in any of the scopes from page to webApp. * * @param name the attribute name. * * @return the attribute value */ public Object findAttribute(String name) { Object value; if ((value = getAttribute(name)) != null) return value; if ((value = getCauchoRequest().getAttribute(name)) != null) return value; HttpSession session = getSession(); if (session != null) { try { value = session.getAttribute(name); } catch (IllegalStateException e) { // jsp/162e log.log(Level.FINE, e.toString(), e); } if (value != null) return value; } return getServletContext().getAttribute(name); } /** * Return the scope of the named attribute. * * @param name the name of the attribute. * * @return the scope of the attribute */ public int getAttributesScope(String name) { if (getAttribute(name) != null) return PAGE_SCOPE; if (getCauchoRequest().getAttribute(name) != null) return REQUEST_SCOPE; HttpSession session = getSession(); if (session != null && session.getValue(name) != null) return SESSION_SCOPE; if (getApplication().getAttribute(name) != null) return APPLICATION_SCOPE; return 0; } /** * Sets the attribute map. */ public Map<String,Object> setMap(Map<String,Object> map) { Map<String,Object> oldMap = _attributes; _attributes = map; return oldMap; } /** * Returns the current writer. */ public JspWriter getOut() { return _out; } /** * Pushes a new BodyContent onto the JspWriter stack. */ public BodyContent pushBody() { BodyContentImpl body; if (_bodyOut != null) { body = _bodyOut; _bodyOut = null; } else body = BodyContentImpl.allocate(); CauchoResponse response = getCauchoResponse(); body.init(_out); _out = body; response.setForbidForward(true); try { _bodyResponseStream.flushBuffer(); } catch (IOException e) { } _bodyResponseStream.start(); _bodyResponseStream.setWriter(body); _bodyResponseStream.setEncoding(response.getCharacterEncoding()); response.setResponseStream(_bodyResponseStream); return body; } /** * Pushes a new writer onto the JspWriter stack. */ public JspWriter pushBody(Writer writer) { if (writer == _out) return null; JspWriter oldWriter = _out; StreamJspWriter jspWriter; jspWriter = new StreamJspWriter(); jspWriter.init(_out, writer); _out = jspWriter; getCauchoResponse().setForbidForward(true); _bodyResponseStream.setWriter(writer); getCauchoResponse().setResponseStream(_bodyResponseStream); return oldWriter; } /** * Pops the BodyContent from the JspWriter stack. * * @return the enclosing writer */ public JspWriter popBody() { BodyContentImpl bodyOut = (BodyContentImpl) _out; _out = bodyOut.getEnclosingWriter(); try { _bodyResponseStream.flushBuffer(); //if (_writeStream != null) // _writeStream.flushBuffer(); } catch (IOException e) { log.log(Level.WARNING, e.toString(), e); } if (_out instanceof StreamJspWriter) { StreamJspWriter writer = (StreamJspWriter) _out; _bodyResponseStream.setWriter(writer.getWriter()); if (_response != null) _bodyResponseStream.setEncoding(_response.getCharacterEncoding()); } else if (_out instanceof JspWriterAdapter) { if (getCauchoResponse() != null) { getCauchoResponse().setResponseStream(_responseStream); getCauchoResponse().setForbidForward(false); } } else if (_out instanceof BodyContentImpl) { BodyContentImpl body = (BodyContentImpl) _out; _bodyResponseStream.setWriter(body.getWriter()); if (_response != null) _bodyResponseStream.setEncoding(_response.getCharacterEncoding()); } return _out; } /** * Pops the BodyContent from the JspWriter stack. * * @return the enclosing writer */ public JspWriter popAndReleaseBody() throws IOException { BodyContentImpl body = (BodyContentImpl) getOut(); JspWriter out = popBody(); releaseBody(body); return out; } public void releaseBody(BodyContentImpl out) throws IOException { if (_bodyOut == null) { out.releaseNoFree(); _bodyOut = out; } else out.release(); } /** * Pops the BodyContent from the JspWriter stack. * * @param oldWriter the old writer */ public JspWriter setWriter(JspWriter oldWriter) { if (_out == oldWriter) return oldWriter; /* if (_out instanceof FlushBuffer) { try { ((FlushBuffer) _out).flushBuffer(); } catch (IOException e) { } } */ try { if (_out instanceof FlushBuffer) ((FlushBuffer) _out).flushBuffer(); } catch (IOException e) { } _out = oldWriter; // jsp/18eg if (_out instanceof StreamJspWriter) { StreamJspWriter writer = (StreamJspWriter) _out; _bodyResponseStream.setWriter(writer.getWriter()); } else if (_out instanceof JspWriterAdapter) { if (getCauchoResponse() != null) { getCauchoResponse().setResponseStream(_responseStream); getCauchoResponse().setForbidForward(false); } } else if (_out instanceof BodyContentImpl) { BodyContentImpl body = (BodyContentImpl) _out; _bodyResponseStream.setWriter(body.getWriter()); } return oldWriter; // getCauchoResponse().setWriter(_os); } /** * Returns the top writer. */ public PrintWriter getTopWriter() throws IOException { CauchoResponse response = getCauchoResponse(); AbstractResponseStream currentStream = response.getResponseStream(); response.setResponseStream(_responseStream); try { return response.getWriter(); } finally { response.setResponseStream(currentStream); } } /** * Returns the response output stream. */ ServletOutputStream getOutputStream() { try { return getCauchoResponse().getOutputStream(); } catch (IOException e) { throw new RuntimeException(e); } } /** * Returns the underlying servlet for the page. */ public Object getPage() { return _servlet; } /** * Returns the servlet request for the page. */ public ServletRequest getRequest() { return _request; } /** * Returns the servlet response for the page. */ public ServletResponse getResponse() { return getCauchoResponse(); } /** * Returns the servlet response for the page. */ public CauchoResponse getCauchoResponse() { return _response; } /** * Returns the servlet response for the page. */ public HttpServletRequest getCauchoRequest() { return _request; } public HttpSession getSession() { if (_session == null) _session = getCauchoRequest().getSession(false); return _session; } /** * Returns the session, throwing an IllegalStateException if it's * not available. */ public HttpSession getSessionScope() { if (_session == null) _session = getCauchoRequest().getSession(false); if (_session == null) throw new IllegalStateException(L.l("session is not available")); return _session; } public ServletConfig getServletConfig() { return _servlet.getServletConfig(); } /** * Returns the page's servlet context. */ public ServletContext getServletContext() { return _webApp; } /** * Returns the page's webApp. */ public WebApp getApplication() { return _webApp; } /** * Returns the page's error page. */ public String getErrorPage() { return _errorPage; } /** * Sets the page's error page. */ public void setErrorPage(String errorPage) { _errorPage = errorPage; } public Exception getException() { return (Exception) getThrowable(); } /** * Returns the Throwable stored by the error page. */ public Throwable getThrowable() { Throwable exn = (Throwable) getCauchoRequest().getAttribute(EXCEPTION); if (exn == null) exn = (Throwable) getCauchoRequest().getAttribute("javax.servlet.error.exception_type"); if (exn == null) exn = (Throwable) getCauchoRequest().getAttribute("javax.servlet.jsp:jspException"); return exn; } public void include(String relativeUrl) throws ServletException, IOException { include(relativeUrl, false); } /** * Include another servlet into the current output stream. * * @param relativeUrl url relative to the current request. */ public void include(String relativeUrl, String query, boolean flush) throws ServletException, IOException { if ("".equals(query)) { } else if (relativeUrl.indexOf('?') > 0) relativeUrl = relativeUrl + '&' + query; else relativeUrl = relativeUrl + '?' + query; include(relativeUrl, flush); } /** * Include another servlet into the current output stream. * * @param relativeUrl url relative to the current request. */ public void include(String relativeUrl, boolean flush) throws ServletException, IOException { RequestDispatcher rd = null; HttpServletRequest req = (HttpServletRequest) getCauchoRequest(); HttpServletResponse res = (HttpServletResponse) getResponse(); if (relativeUrl != null && ! relativeUrl.startsWith("/")) { String path = RequestAdapter.getPageServletPath(req); if (path == null) path = RequestAdapter.getPagePathInfo(req); if (path == null) path = "/"; int p = path.lastIndexOf('/'); if (p >= 0) { _cb.clear(); _cb.append(path, 0, p + 1); _cb.append(relativeUrl); rd = getServletContext().getRequestDispatcher(_cb.toString()); } } if (rd == null) rd = req.getRequestDispatcher(relativeUrl); if (rd == null) throw new ServletException(L.l("unknown including page `{0}'.", relativeUrl)); // the FlushBuffer needs to happen to deal with OpenSymphony (Bug#1710) // jsp/17e9, 15lc, 15m4 if (! flush) { } else if (_out instanceof FlushBuffer) ((FlushBuffer) _out).flushBuffer(); else if (flush) _out.flush(); rd.include(req, res); } /** * Include another servlet into the current output stream. * * @param relativeUrl url relative to the current request. */ public void forward(String relativeUrl, String query) throws ServletException, IOException { if ("".equals(query)) { } else if (relativeUrl.indexOf('?') > 0) relativeUrl = relativeUrl + '&' + query; else relativeUrl = relativeUrl + '?' + query; forward(relativeUrl); } /** * Forward a subrequest relative to the current url. Absolute URLs * are relative to the context root. * * @param relativeUrl url relative to the current file */ public void forward(String relativeUrl) throws ServletException, IOException { if (_bufferSize == 0) { // jsp/15m3, tck if (_out instanceof FlushBuffer) ((FlushBuffer) _out).flushBuffer();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?