Package com.caucho.quercus.env

Examples of com.caucho.quercus.env.Env


   */
  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;
      }

      StreamImpl out;
     
      try {
        out = new VfsStream(null, response.getOutputStream());
      }
      catch (IllegalStateException e) {
        WriterStreamImpl writer = new WriterStreamImpl();
        writer.setWriter(response.getWriter());
       
        out = writer;
      }
     
      ws = new WriteStream(out);
     
      ws.setNewlineString("\n");

      Quercus quercus = getQuercus();
      quercus.setServletContext(_servletContext);
     
      env = quercus.createEnv(page, ws, request, response);
      try {
        env.start();
       
        env.setScriptGlobal("request", request);
        env.setScriptGlobal("response", response);
        env.setScriptGlobal("servletContext", _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);

      //  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 a thrown exception
        if (ws != null)
          ws.close();
      }
View Full Code Here


    WriteStream os = new WriteStream(StdoutStream.create());

    os.setNewlineString("\n");
    os.setEncoding("iso-8859-1");

    Env env = createEnv(page, os, null, null);
    env.start();

    if (_args.length > 0)
      env.setArgs(_args);

    try {
      env.execute();
    } catch (QuercusDieException e) {
      log.log(Level.FINER, e.toString(), e);
    } catch (QuercusExitException e) {
      log.log(Level.FINER, e.toString(), e);
    } catch (QuercusErrorException e) {
      log.log(Level.FINER, e.toString(), e);
    } finally {
      env.close();

      os.flush();
    }
  }
View Full Code Here

    WriteStream os = new WriteStream(StdoutStream.create());
     
    os.setNewlineString("\n");
    os.setEncoding("iso-8859-1");
   
    Env env = createEnv(page, os, null, null);
    env.start();
   
    try {
      env.execute();
    } catch (QuercusDieException e) {
    } catch (QuercusExitException e) {
    }
   
    env.close();
   
    os.flush();
  }
View Full Code Here

    else
      out = new WriteStream(StdoutStream.create());
   
    QuercusPage page = new InterpretedPage(program);

    Env env = new Env(_quercus, page, out, null, null);
   
    Value value = NullValue.NULL;
   
    try {
      value = program.execute(env);
View Full Code Here

  {
    // XXX: Not sure why this dependency would be useful
    // Environment.addDependency(new Depend(path));

    if (path.canRead()) {
      Env env = new Env(this);

      Value result = FileModule.parse_ini_file(env, path, false);

      if (result instanceof ArrayValue) {
        ArrayValue array = (ArrayValue) result;
View Full Code Here

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

   */
  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

   * 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) {
        }

        out = os;
      }
      else
        out = new NullWriteStream();

      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)
        result = resultV.toJavaObject();

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

      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

   * evaluates based on a reader.
   */
  public Object eval(Reader script, ScriptContext cxt)
    throws ScriptException
  {
    Env env = null;

    try {
      ReadStream reader = ReaderStream.open(script);
     
      QuercusProgram program = QuercusParser.parse(_quercus, null, reader);

      Writer writer = cxt.getWriter();
     
      WriteStream out;

      if (writer != null) {
        WriterStreamImpl s = new WriterStreamImpl();
        s.setWriter(writer);
        WriteStream os = new WriteStream(s);
       
        os.setNewlineString("\n");

        try {
          os.setEncoding("iso-8859-1");
        } catch (Exception e) {
        }

        out = os;
      }
      else
        out = new 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) {
        //php/2148
      }
     
      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

   */
  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();
       
        // GoogleAppEngine SDK is missing non-essential Jetty classes
        // (Jetty also hides server classes from webapp)
        //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)
          ws.close();
      }
View Full Code Here

TOP

Related Classes of com.caucho.quercus.env.Env

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.