outputmodule.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 588 行 · 第 1/2 页

JAVA
588
字号
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */package com.caucho.quercus.lib;import com.caucho.quercus.annotation.Optional;import com.caucho.quercus.env.*;import com.caucho.quercus.module.AbstractQuercusModule;import com.caucho.quercus.module.ModuleStartupListener;import com.caucho.quercus.module.IniDefinitions;import com.caucho.quercus.module.IniDefinition;import com.caucho.util.L10N;import com.caucho.vfs.StreamImplOutputStream;import com.caucho.vfs.TempStream;import com.caucho.vfs.TempBuffer;import java.io.IOException;import java.io.OutputStream;import java.util.HashMap;import java.util.logging.Logger;import java.util.zip.DeflaterOutputStream;import java.util.zip.GZIPOutputStream;/** * PHP output routines. */public class OutputModule extends AbstractQuercusModule   implements ModuleStartupListener {  private static final L10N L = new L10N(OutputModule.class);  private static final Logger log = Logger.getLogger(OutputModule.class.getName());  private static final StringValue HTTP_ACCEPT_ENCODING    = new StringBuilderValue("HTTP_ACCEPT_ENCODING");  private static final IniDefinitions _iniDefinitions = new IniDefinitions();  // ob_gzhandler related variables/types  private enum Encoding {NONE, GZIP, DEFLATE};  private static class GZOutputPair {    public StringOutputStream _tempStream;    public OutputStream _outputStream;  }  private static HashMap<Env,GZOutputPair> _gzOutputPairs     = new HashMap<Env,GZOutputPair>();  /**   * Returns the default php.ini values.   */  public IniDefinitions getIniDefinitions()  {    return _iniDefinitions;  }  public void startup(Env env)  {    boolean isOutputBuffering = INI_OUTPUT_BUFFERING.getAsBoolean(env);    String handlerName = INI_OUTPUT_HANDLER.getAsString(env);    if (handlerName != null        && ! "".equals(handlerName)        && env.getFunction(handlerName) != null) {      Callback callback = env.createCallback(env.createString(handlerName));      ob_start(env, callback, 0, true);    } else if (isOutputBuffering) {      ob_start(env, null, 0, true);    }    ob_implicit_flush(env, isOutputBuffering);  }  /**   * Flushes the original output buffer.   */  public Value flush(Env env)  {    try {      // XXX: conflicts with dragonflycms install      env.getOriginalOut().flush();    } catch (IOException e) {    }    return NullValue.NULL;  }  /**   * Clears the output buffer.   */  public static Value ob_clean(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null) {      ob.clean();      return BooleanValue.TRUE;    }    else      return BooleanValue.FALSE;  }  /**   * Pops the output buffer, discarding the contents.   */  public static boolean ob_end_clean(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null) {      ob.clean();      Callback callback = ob.getCallback();      if (callback != null) {        ob.setCallback(null);      }    }    return env.popOutputBuffer();  }  /**   * Pops the output buffer.   */  public static boolean ob_end_flush(Env env)  {    return env.popOutputBuffer();  }  /**   * Returns the contents of the output buffer, emptying it afterwards.   */  public static Value ob_get_clean(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null) {      Value result = ob.getContents();      ob.clean();      return result;    }    else      return BooleanValue.FALSE;  }  /**   * Returns the contents of the current output buffer.   */  public static Value ob_get_contents(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null)      return ob.getContents();    else      return BooleanValue.FALSE;  }  /**   * Pops the output buffer and returns the contents.   */  public static Value ob_get_flush(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    Value result = BooleanValue.FALSE;    if (ob != null) {      result = ob.getContents();    }    env.popOutputBuffer();    return result;  }  /**   * Flushes this output buffer into the next one on the stack or   * to the default "output buffer" if no next output buffer exists.   * The callback associated with this buffer is also called with   * appropriate parameters.   */  public static Value ob_flush(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null) {      ob.flush();      return BooleanValue.TRUE;    }     else      return BooleanValue.FALSE;  }  /**   * Pushes the output buffer   */  public static Value ob_get_length(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null)      return LongValue.create(ob.getLength());    else      return BooleanValue.FALSE;  }  /**   * Gets the nesting level of the current output buffer   */  public static Value ob_get_level(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    if (ob != null)      return LongValue.create(ob.getLevel());    else      return LongValue.ZERO;  }  /**   * Helper recursive function that ensures the handlers are listed   * in the correct order in the array.   */  private static void listHandlers(Env env,				   OutputBuffer ob,				   ArrayValue handlers)  {    if (ob == null)      return;    listHandlers(env, ob.getNext(), handlers);    Callback callback = ob.getCallback();    if (callback != null)       handlers.put(env.createString(callback.getCallbackName()));    else      handlers.put(env.createString("default output handler"));  }    /**   * Returns a list of all the output handlers in use.   */  public static Value ob_list_handlers(Env env)  {    OutputBuffer ob = env.getOutputBuffer();    ArrayValue handlers = new ArrayValueImpl();    listHandlers(env, ob, handlers);    return handlers;  }  /**   * Inserts the common values for ob_get_status into an array.  Used   * by getFullStatus() and ob_get_status().   */  private static void putCommonStatus(ArrayValue element, OutputBuffer ob,                                      Env env, boolean fullStatus)  {    LongValue type = LongValue.ONE;    Callback callback = ob.getCallback();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?