Examples of Env


Examples of com.caucho.quercus.env.Env

  public Env createEnv(QuercusPage page,
                       WriteStream out,
                       HttpServletRequest request,
                       HttpServletResponse response)
  {
    return new Env(this, page, out, request, response);
  }
View Full Code Here

Examples of com.caucho.quercus.env.Env

  @Override
  public void service(HttpServletRequest request,
                      HttpServletResponse response)
    throws ServletException, IOException
  {
    Env env = null;
    WriteStream ws = null;
   
    try {
      Path path = getPath(request);

      QuercusPage page;

      try {
        page = getQuercus().parse(path);
      }
      catch (FileNotFoundException ex) {
        // php/2001
        log.log(Level.FINER, ex.toString(), ex);

        response.sendError(HttpServletResponse.SC_NOT_FOUND);

        return;
      }


      ws = openWrite(response);
     
      // php/6006
      ws.setNewlineString("\n");

      QuercusContext quercus = getQuercus();
     
      env = quercus.createEnv(page, ws, request, response);
      quercus.setServletContext(_servletContext);
     
      try {
        env.start();
       
        // php/2030, php/2032, php/2033
        // Jetty hides server classes from web-app
        // http://docs.codehaus.org/display/JETTY/Classloading
        //
        // env.setGlobalValue("request", env.wrapJava(request));
        // env.setGlobalValue("response", env.wrapJava(response));
        // env.setGlobalValue("servletContext", env.wrapJava(_servletContext));

        StringValue prepend
          = quercus.getIniValue("auto_prepend_file").toStringValue(env);
        if (prepend.length() > 0) {
          Path prependPath = env.lookup(prepend);
         
          if (prependPath == null)
            env.error(L.l("auto_prepend_file '{0}' not found.", prepend));
          else {
            QuercusPage prependPage = getQuercus().parse(prependPath);
            prependPage.executeTop(env);
          }
        }

        env.executeTop();

        StringValue append
          = quercus.getIniValue("auto_append_file").toStringValue(env);
        if (append.length() > 0) {
          Path appendPath = env.lookup(append);
         
          if (appendPath == null)
            env.error(L.l("auto_append_file '{0}' not found.", append));
          else {
            QuercusPage appendPage = getQuercus().parse(appendPath);
            appendPage.executeTop(env);
          }
        }
        //   return;
      }
      catch (QuercusExitException e) {
        throw e;
      }
      catch (QuercusErrorException e) {
        throw e;
      }
      catch (QuercusLineRuntimeException e) {
        log.log(Level.FINE, e.toString(), e);

        ws.println(e.getMessage());
        //  return;
      }
      catch (QuercusValueException e) {
        log.log(Level.FINE, e.toString(), e);
       
        ws.println(e.toString());

        //  return;
      }
      catch (Throwable e) {
        if (response.isCommitted())
          e.printStackTrace(ws.getPrintWriter());

        ws = null;

        throw e;
      }
      finally {
        if (env != null)
          env.close();

        // don't want a flush for an exception
        if (ws != null && env.getDuplex() == null)
          ws.close();
      }
    }
    catch (QuercusDieException e) {
      // normal exit
View Full Code Here

Examples of com.caucho.quercus.env.Env

  /**
   * evaluates based on a reader.
   */
  public Object eval(ScriptContext cxt) throws ScriptException {

    Env env = null;

    try {
      Writer writer = cxt.getWriter();

      WriteStream out;

      if (writer != null) {
        ReaderWriterStream s = new ReaderWriterStream(null, writer);
        WriteStream os = new WriteStream(s);

        os.setNewlineString("\n");

        try {
          os.setEncoding("utf-8");
        } catch (Exception e) {
          e.printStackTrace();
        }

        out = os;
      } else
        { out = new NullWriteStream();
        System.out.println("aaaa");
        }

      QuercusPage page = new InterpretedPage(_program);

      env = new Env(_engine.getQuercus(), page, out, null, null);

      env.setScriptContext(cxt);

      // php/214g
      env.start();

      Value resultV = _program.execute(env);

      Object result = null;
      if (resultV != null)
View Full Code Here

Examples of com.caucho.quercus.env.Env

  /**
   * run based on a reader.
   */
  public Object run(String script) throws ScriptException {
    Env env = null;
    ScriptContext cxt = this.getContext();
    try {
      ReadStream reader = com.caucho.vfs.StringReader.open(script);
      reader.setEncoding("utf-8");
      QuercusProgram program = QuercusParser
          .parse(_quercus, null, reader);
      Writer writer = cxt.getWriter();
      WriteStream out;

      if (writer != null) {

        ReaderWriterStream s = new ReaderWriterStream(null, writer);
        WriteStream os = new WriteStream(s);

        os.setNewlineString("\n");

        try {
          os.setEncoding("utf-8");
        } catch (Exception e) {
          e.printStackTrace();
        }

        out = os;
      } else {
        out = new NullWriteStream();
        System.out.println("NullWriteStream");
      }

      QuercusPage page = new InterpretedPage(program);

      env = new Env(_quercus, page, out, null, null);

      env.setScriptContext(cxt);

      // php/214c
      env.start();

      Object result = null;

      try {
        Value value = program.execute(env);

        if (value != null)
          result = value.toJavaObject();
      } catch (QuercusExitException e) {
        e.printStackTrace();
      }

      out.flushBuffer();
      out.free();

      // flush buffer just in case
      //
      // jrunscript in interactive mode does not automatically flush its
      // buffers after every input, so output to stdout will not be seen
      // until the output buffer is full
      //
      // http://bugs.caucho.com/view.php?id=1914
      writer.flush();

      return result;

      /*
       * } catch (ScriptException e) { throw e;
       */
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new ScriptException(e);
    } catch (Throwable e) {
      throw new RuntimeException(e);
    } finally {
      if (env != null)
        env.close();
    }
  }
View Full Code Here

Examples of com.caucho.xpath.Env

    addFunction("document", new DocumentFun(transformer));
    DocumentFun docFun = new DocumentFun(transformer);
    docFun.setHtml(true);
    addFunction("html_document", docFun);

    Env env = XPath.createEnv();
    env.setFunctions(_funs);
    StylesheetEnv ssEnv = new StylesheetEnv();
    ssEnv.setPath(getPath());
    env.setStylesheetEnv(ssEnv);

    out.disableEscaping(_defaultDisableEscaping);

    if (_strip != null && ! _strip.isEmpty()) {
      stripSpaces(xml);
View Full Code Here

Examples of com.caucho.xpath.Env

      JspWriter out = pageContext.getOut();

      Node node = pageContext.getNodeEnv();

      Env env = XPath.createEnv();
      env.setVarEnv(pageContext.getVarEnv());

      String value = _select.evalString(node, env);

      env.free();

      if (_escapeXml)
        com.caucho.el.Expr.toStreamEscaped(out, value);
      else
        out.print(value);
View Full Code Here

Examples of com.caucho.xpath.Env

                              com.caucho.xpath.Expr select,
                              boolean doEscape)
    throws JspException, XPathException, IOException
  {
    try {
      Env env = XPath.createEnv();
      env.setVarEnv(pageContext.getVarEnv());
     
      Node node = pageContext.getNodeEnv();

      String value = select.evalString(node, env);

      env.free();

      if (doEscape)
        com.caucho.el.Expr.toStreamEscaped(out, value);
      else
        out.print(value);
View Full Code Here

Examples of com.caucho.xpath.Env

  public static Object evalObject(PageContextImpl pageContext,
                                  com.caucho.xpath.Expr select)
    throws XPathException, JspException
  {
    try {
      Env env = XPath.createEnv();
      env.setVarEnv(pageContext.getVarEnv());
     
      Node node = pageContext.getNodeEnv();
     
      Object value = select.evalObject(node, env);

      env.free();

      return value;
    } catch (javax.el.ELException e) {
      throw new JspException(e);
    }
View Full Code Here

Examples of com.caucho.xpath.Env

  public int doStartTag()
    throws JspException
  {
    try {
      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      Env env = XPath.createEnv();
      env.setVarEnv(pageContext.getVarEnv());
     
      _oldEnv = pageContext.getNodeEnv();
      Object obj = _select.evalObject(_oldEnv, env);

      env.free();

      if (obj == null)
        return SKIP_BODY;

      if (obj instanceof Iterator)
View Full Code Here

Examples of com.caucho.xpath.Env

  public static boolean evalBoolean(PageContextImpl pageContext,
                                    com.caucho.xpath.Expr select)
    throws XPathException, JspException
  {
    try {
      Env env = XPath.createEnv();
      env.setVarEnv(((PageContextImpl) pageContext).getVarEnv());
     
      Node node = pageContext.getNodeEnv();
     
      boolean test = select.evalBoolean(node, env);

      env.free();

      return test;
    } catch (javax.el.ELException e) {
      throw new JspException(e);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.