Package com.caucho.jsp

Examples of com.caucho.jsp.PageContextImpl$PageELContext


  {
    try {
      if (_valueExpr == null)
        return EVAL_BODY_BUFFERED;

      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      ELContext env = pageContext.getELContext();
   
      String name = _nameExpr.evalString(env);

      if (name == null)
        return SKIP_BODY;
View Full Code Here


      if (bodyContent != null)
        value = bodyContent.getString().trim();
      else
        value = "";
   
      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      ELContext env = pageContext.getELContext();
   
      String name = _nameExpr.evalString(env);

      Object parent = getParent();
      if (! (parent instanceof NameValueTag))
View Full Code Here

  {
    JspWriter jspWriter = null;

    _query.clear();

    PageContextImpl pageContext = (PageContextImpl) this.pageContext;
   
    try {
      if (_varReader != null) {
        jspWriter = pageContext.pushBody();
       
        handleBody();

        BodyContentImpl body = (BodyContentImpl) pageContext.getOut();

        _reader = body.getReader();

        pageContext.setAttribute(_varReader, _reader);

        return EVAL_BODY_INCLUDE;
      }
      else
        return EVAL_BODY_BUFFERED;
    } catch (JspException e) {
      throw e;
    } catch (Exception e) {
      throw new JspException(e);
    } finally {
      if (jspWriter != null)
        pageContext.popBody();
    }
  }
View Full Code Here

  }

  private void handleBody()
    throws JspException, ServletException, IOException, ELException
  {
    PageContextImpl pageContext = (PageContextImpl) this.pageContext;
    ELContext env = pageContext.getELContext();
   
    String url = _urlExpr.evalString(env);

    if (url == null || url.equals(""))
      throw new JspTagException(L.l("URL may not be null for `{0}'",
                                    _urlExpr));

    if (_query == null || _query.getLength() == 0) {
    }
    else if (url.indexOf('?') > 0)
      url = url + '&' + _query;
    else
      url = url + '?' + _query;

    JspWriter out = pageContext.getOut();
    if (out instanceof FlushBuffer)
      ((FlushBuffer) out).flushBuffer();
    else
      out.flush();

    if (_contextExpr != null) {
      String context = _contextExpr.evalString(env);

      if (! url.startsWith("/"))
        throw new JspException(L.l("URL `{0}' must start with `/' with context `{0}'", url, context));
       
      if (context != null && context.startsWith("/")) {
        ServletContext app = pageContext.getServletContext().getContext(context);

        try {
          RequestDispatcher disp = app.getRequestDispatcher(url);

          if (disp == null)
            throw new JspException(L.l("URL `{0}' does not map to any servlet",
                                       url));

          CauchoResponse response = (CauchoResponse) pageContext.getResponse();
          response.getResponseStream().setEncoding(null);

          disp.include(pageContext.getRequest(), response);
        } catch (FileNotFoundException e) {
          throw new JspException(L.l("`{0}' is an unknown file or servlet.",
                                     url));
        }
      }
      else
        handleExternalBody(context + url);
     
      return;
    }

    int colon = url.indexOf(':');
    int slash = url.indexOf('/');
    if (slash == 0 || colon < 0 || slash < 0 || slash < colon) {
      ServletRequest request = pageContext.getRequest();

      try {
        RequestDispatcher disp = request.getRequestDispatcher(url);

        if (disp == null)
          throw new JspException(L.l("URL `{0}' does not map to any servlet",
                                     url));

        CauchoResponse response = (CauchoResponse) pageContext.getResponse();
        response.getResponseStream().setEncoding(null);

        disp.include(pageContext.getRequest(), response);
      } catch (FileNotFoundException e) {
        throw new JspException(L.l("URL `{0}' is an unknown file or servlet.",
                                   url));
      }
    }
View Full Code Here

  }

  private void handleExternalBody(String url)
    throws JspException, ServletException, IOException, ELException
  {
    PageContextImpl pageContext = (PageContextImpl) this.pageContext;
    ELContext env = pageContext.getELContext();
   
    URL netURL = new URL(url);

    URLConnection conn = netURL.openConnection();

    if (conn instanceof HttpURLConnection)
      ((HttpURLConnection) conn).setFollowRedirects(true);

    InputStream is = conn.getInputStream();
    try {
      ReadStream in = Vfs.openRead(is);
      String encoding = conn.getContentEncoding();
      String contentType = conn.getContentType();

      if (_charEncodingExpr != null) {
        encoding = _charEncodingExpr.evalString(env);
        if (encoding != null && ! encoding.equals(""))
          in.setEncoding(encoding);
      }
      else if (encoding != null)
        in.setEncoding(encoding);
      else if (contentType != null) {
        int p = contentType.indexOf("charset=");
        if (p > 0) {
          CharBuffer cb = new CharBuffer();
          for (int i = p + 8; i < contentType.length(); i++) {
            int ch = contentType.charAt(i);
            if (ch == '"' || ch == '\'') {
            }
            else if (ch >= 'a' && ch <= 'z')
              cb.append((char) ch);
            else if (ch >= 'A' && ch <= 'Z')
              cb.append((char) ch);
            else if (ch >= '0' && ch <= '9')
              cb.append((char) ch);
            else if (ch == '-' || ch == '_')
              cb.append((char) ch);
            else
              break;
          }
          encoding = cb.toString();

          in.setEncoding(encoding);
        }
      }
     
      JspWriter out = pageContext.getOut();

      int ch;
      while ((ch = in.readChar()) >= 0)
        out.print((char) ch);
    } finally {
View Full Code Here

    throws ELException
  {
    if (! (env instanceof PageContextImpl.PageELContext))
      return null;
   
    PageContextImpl page
      = ((PageContextImpl.PageELContext) env).getPageContext();
   
    switch (_index) {
    case PAGE_CONTEXT:
      return page;

    case APPLICATION_SCOPE:
      return new AttributeMap(page, PageContext.APPLICATION_SCOPE);

    case SESSION_SCOPE:
      return new AttributeMap(page, PageContext.SESSION_SCOPE);

    case REQUEST_SCOPE:
      return new AttributeMap(page, PageContext.REQUEST_SCOPE);

    case PAGE_SCOPE:
      return new AttributeMap(page, PageContext.PAGE_SCOPE);

    case PARAM_VALUES:
      return page.getRequest().getParameterMap();

    case PARAM: {
      HashMap<String,String> map = new HashMap<String,String>();
      Map pMap = page.getRequest().getParameterMap();
      Iterator iter = pMap.entrySet().iterator();
     
      while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String []value = (String []) entry.getValue();
        map.put(key, value[0]);
      }
     
      return map;
    }

    case INIT_PARAM:
    {
      ServletContext app = page.getServletContext();
      HashMap<String,String> map = new HashMap<String,String>();
      Enumeration e = app.getInitParameterNames();

      while (e.hasMoreElements()) {
        String name = (String) e.nextElement();

        map.put(name, app.getInitParameter(name));
      }
     
      return map;
    }

    case HEADER:
    {
      HttpServletRequest req = (HttpServletRequest) page.getRequest();
      HashMap<String,String> map = new HashMap<String,String>();
      Enumeration e = req.getHeaderNames();

      while (e.hasMoreElements()) {
        String name = (String) e.nextElement();

        map.put(name, req.getHeader(name));
      }
     
      return map;
    }

    case HEADER_VALUES:
    {
      HttpServletRequest req = (HttpServletRequest) page.getRequest();
      HashMap<String,String[]> map = new HashMap<String,String[]>();
      Enumeration e = req.getHeaderNames();

      while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        Enumeration values = req.getHeaders(name);
     
        ArrayList<String> list = new ArrayList<String>();

        while (values.hasMoreElements())
          list.add((String) values.nextElement());

        map.put(name, list.toArray(new String[list.size()]));
      }
     
      return map;
    }

    case COOKIE:
    {
      HashMap<String,Object> map = new HashMap<String,Object>();
      Cookie []cookies = ((HttpServletRequest) page.getRequest()).getCookies();

      for (int i = 0; cookies != null && i < cookies.length; i++) {
        if (map.get(cookies[i].getName()) == null)
          map.put(cookies[i].getName(), cookies[i]);
      }
View Full Code Here

    throws ELException
  {
    if (! (env instanceof PageContextImpl.PageELContext))
      return env.getELResolver().getValue(env, null, "pageScope");
   
    PageContextImpl page
      = ((PageContextImpl.PageELContext) env).getPageContext();
   
    return new PageContextAttributeMap(page, PageContext.PAGE_SCOPE);
  }
View Full Code Here

      Object scope = elResolver.getValue(env, null, "pageScope");
     
      return elResolver.getValue(env, scope, _field);
    }
   
    PageContextImpl pageContext
      = ((PageContextImpl.PageELContext) env).getPageContext();

    return pageContext.getAttribute(_field);
  }
View Full Code Here

      elResolver.setValue(env, scope, _field, value);

      return;
    }
   
    PageContextImpl pageContext
      = ((PageContextImpl.PageELContext) env).getPageContext();

    pageContext.setAttribute(_field, value);
  }
View Full Code Here

    throws ELException
  {
    if (! (env instanceof PageContextImpl.PageELContext))
      return null;
   
    PageContextImpl page
      = ((PageContextImpl.PageELContext) env).getPageContext();
   
    return page;
  }
View Full Code Here

TOP

Related Classes of com.caucho.jsp.PageContextImpl$PageELContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.