home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / jserv / javax / servlet / jsp / PageContext.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-26  |  6.0 KB  |  243 lines

  1. package javax.servlet.jsp;
  2.  
  3. import java.io.IOException;
  4. import java.util.Enumeration;
  5. import java.util.Hashtable;
  6. import javax.servlet.Servlet;
  7. import javax.servlet.ServletConfig;
  8. import javax.servlet.ServletContext;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.ServletRequest;
  11. import javax.servlet.ServletResponse;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpSession;
  14.  
  15. public abstract class PageContext {
  16.    public static final int PAGE_SCOPE = 1;
  17.    public static final int REQUEST_SCOPE = 2;
  18.    public static final int SESSION_SCOPE = 3;
  19.    public static final int APPLICATION_SCOPE = 4;
  20.    public static final String PAGE = "javax.servlet.jsp.jspPage";
  21.    public static final String PAGECONTEXT = "javax.servlet.jsp.jspPageContext";
  22.    public static final String REQUEST = "javax.servlet.jsp.jspRequest";
  23.    public static final String RESPONSE = "javax.servlet.jsp.jspResponse";
  24.    public static final String CONFIG = "javax.servlet.jsp.jspConfig";
  25.    public static final String SESSION = "javax.servlet.jsp.jspSession";
  26.    public static final String OUT = "javax.servlet.jsp.jspOut";
  27.    public static final String APPCONTEXT = "javax.servlet.jsp.jspAppContext";
  28.    public static final String EXCEPTION = "javax.servlet.jsp.jspException";
  29.    protected Servlet servlet;
  30.    protected ServletConfig config;
  31.    protected ServletContext context;
  32.    protected JspFactory factory;
  33.    protected boolean needsSession;
  34.    protected String errorPageURL;
  35.    protected boolean autoFlush;
  36.    protected int bufferSize;
  37.    protected transient Hashtable attributes = new Hashtable(16);
  38.    protected transient ServletRequest request;
  39.    protected transient ServletResponse response;
  40.    protected transient HttpSession session;
  41.    protected transient JspWriter out;
  42.  
  43.    protected PageContext(JspFactory var1) {
  44.       this.factory = var1;
  45.    }
  46.  
  47.    public void initialize(Servlet var1, ServletRequest var2, ServletResponse var3, String var4, boolean var5, int var6, boolean var7) throws IOException, IllegalStateException, IllegalArgumentException {
  48.       this.servlet = var1;
  49.       this.config = var1.getServletConfig();
  50.       this.context = this.config.getServletContext();
  51.       this.needsSession = var5;
  52.       this.errorPageURL = var4;
  53.       this.bufferSize = var6;
  54.       this.autoFlush = var7;
  55.       this.request = var2;
  56.       this.response = var3;
  57.       if (var2 instanceof HttpServletRequest) {
  58.          this.session = ((HttpServletRequest)var2).getSession(var5);
  59.       }
  60.  
  61.       if (var5 && this.session == null) {
  62.          throw new IllegalStateException("Page needs a session and none is available");
  63.       } else {
  64.          this.out = this._createOut(var6, var7);
  65.          if (this.out == null) {
  66.             throw new IllegalStateException("failed initialize JspWriter");
  67.          } else {
  68.             this.setAttribute("javax.servlet.jsp.jspOut", this.out);
  69.             this.setAttribute("javax.servlet.jsp.jspRequest", var2);
  70.             this.setAttribute("javax.servlet.jsp.jspResponse", var3);
  71.             if (this.session != null) {
  72.                this.setAttribute("javax.servlet.jsp.jspSession", this.session);
  73.             }
  74.  
  75.             this.setAttribute("javax.servlet.jsp.jspPage", var1);
  76.             this.setAttribute("javax.servlet.jsp.jspConfig", this.config);
  77.             this.setAttribute("javax.servlet.jsp.jspPageContext", this);
  78.             this.setAttribute("javax.servlet.jsp.jspAppContext", this.context);
  79.          }
  80.       }
  81.    }
  82.  
  83.    public void release() {
  84.       this.servlet = null;
  85.       this.config = null;
  86.       this.context = null;
  87.       this.needsSession = false;
  88.       this.errorPageURL = null;
  89.       this.bufferSize = -1;
  90.       this.autoFlush = true;
  91.       this.request = null;
  92.       this.response = null;
  93.       this.out = null;
  94.       this.session = null;
  95.       this.attributes.clear();
  96.    }
  97.  
  98.    public Object getAttribute(String var1) {
  99.       return this.attributes.get(var1);
  100.    }
  101.  
  102.    public Object getAttributeWithScope(String var1, int var2) {
  103.       switch (var2) {
  104.          case 1:
  105.             return this.attributes.get(var1);
  106.          case 2:
  107.             return this.request.getAttribute(var1);
  108.          case 3:
  109.             if (this.session == null) {
  110.                throw new IllegalArgumentException("can't access SESSION_SCOPE without an HttpSession");
  111.             }
  112.  
  113.             return this.session.getValue(var1);
  114.          case 4:
  115.             return this.context.getAttribute(var1);
  116.          default:
  117.             throw new IllegalArgumentException("unidentified scope");
  118.       }
  119.    }
  120.  
  121.    public void setAttribute(String var1, Object var2) {
  122.       this.attributes.put(var1, var2);
  123.    }
  124.  
  125.    public void setAttributeInScope(String var1, Object var2, int var3) {
  126.       switch (var3) {
  127.          case 1:
  128.             this.attributes.put(var1, var2);
  129.             return;
  130.          case 2:
  131.             this.request.setAttribute(var1, var2);
  132.             return;
  133.          case 3:
  134.             if (this.session == null) {
  135.                throw new IllegalArgumentException("can't access SESSION_SCOPE without an HttpSession");
  136.             }
  137.  
  138.             this.session.putValue(var1, var2);
  139.             return;
  140.          case 4:
  141.             this.context.setAttribute(var1, var2);
  142.             return;
  143.          default:
  144.       }
  145.    }
  146.  
  147.    public void removeAttribute(String var1) {
  148.       this.attributes.remove(var1);
  149.    }
  150.  
  151.    public void removeAttributeInScope(String var1, int var2) {
  152.       switch (var2) {
  153.          case 1:
  154.             this.attributes.remove(var1);
  155.             return;
  156.          case 2:
  157.             throw new IllegalArgumentException("cant remove Attributes from request scope");
  158.          case 3:
  159.             if (this.session == null) {
  160.                throw new IllegalArgumentException("can't access SESSION_SCOPE without an HttpSession");
  161.             }
  162.  
  163.             this.session.removeValue(var1);
  164.             return;
  165.          case 4:
  166.             this.context.removeAttribute(var1);
  167.             return;
  168.          default:
  169.       }
  170.    }
  171.  
  172.    public int getAttributesScope(String var1) {
  173.       if (this.attributes.get(var1) != null) {
  174.          return 1;
  175.       } else if (this.request.getAttribute(var1) != null) {
  176.          return 2;
  177.       } else if (this.session != null && this.session.getValue(var1) != null) {
  178.          return 3;
  179.       } else {
  180.          return this.context.getAttribute(var1) != null ? 4 : 0;
  181.       }
  182.    }
  183.  
  184.    public Enumeration getAttributeNamesInScope(int var1) {
  185.       switch (var1) {
  186.          case 1:
  187.             return this.attributes.keys();
  188.          case 2:
  189.             return this.request.getAttributeNames();
  190.          case 3:
  191.             if (this.session != null) {
  192.                return new _StringArrayEnum(this.session.getValueNames());
  193.             }
  194.  
  195.             throw new IllegalArgumentException("can't access SESSION_SCOPE without an HttpSession");
  196.          case 4:
  197.             return this.context.getAttributeNames();
  198.          default:
  199.             return new 1();
  200.       }
  201.    }
  202.  
  203.    public JspWriter getOut() {
  204.       return this.out;
  205.    }
  206.  
  207.    public HttpSession getSession() {
  208.       return this.session;
  209.    }
  210.  
  211.    public Servlet getServlet() {
  212.       return this.servlet;
  213.    }
  214.  
  215.    public ServletConfig getServletConfig() {
  216.       return this.config;
  217.    }
  218.  
  219.    public ServletContext getServletContext() {
  220.       return this.config.getServletContext();
  221.    }
  222.  
  223.    public ServletRequest getServletRequest() {
  224.       return this.request;
  225.    }
  226.  
  227.    public ServletResponse getServletResponse() {
  228.       return this.response;
  229.    }
  230.  
  231.    public Exception getException() {
  232.       return (Exception)this.request.getAttribute("javax.servlet.jsp.jspException");
  233.    }
  234.  
  235.    public abstract void forward(String var1) throws ServletException, IOException;
  236.  
  237.    public abstract void include(String var1, JspWriter var2) throws ServletException, IOException;
  238.  
  239.    public abstract void handlePageException(Exception var1);
  240.  
  241.    protected abstract JspWriter _createOut(int var1, boolean var2) throws IOException, IllegalArgumentException;
  242. }
  243.