org.mortbay.jetty.util_6.1.23.v201012071420

16:49:43.842 INFO  jd.cli.Main - Decompiling org.mortbay.jetty.util_6.1.23.v201012071420.jar
package org.mortbay.component;

import org.mortbay.log.Log;
import org.mortbay.util.LazyList;

public abstract class AbstractLifeCycle
  implements LifeCycle
{
  private Object _lock = new Object();
  private final int FAILED = -1;
  private final int STOPPED = 0;
  private final int STARTING = 1;
  private final int STARTED = 2;
  private final int STOPPING = 3;
  private volatile int _state = 0;
  protected LifeCycle.Listener[] _listeners;
  
  protected void doStart()
    throws Exception
  {}
  
  protected void doStop()
    throws Exception
  {}
  
  public final void start()
    throws Exception
  {
    synchronized (_lock)
    {
      try
      {
        if ((_state == 2) || (_state == 1)) {
          return;
        }
        setStarting();
        doStart();
        Log.debug("started {}", this);
        setStarted();
      }
      catch (Exception e)
      {
        setFailed(e);
        throw e;
      }
      catch (Error e)
      {
        setFailed(e);
        throw e;
      }
    }
  }
  
  public final void stop()
    throws Exception
  {
    synchronized (_lock)
    {
      try
      {
        if ((_state == 3) || (_state == 0)) {
          return;
        }
        setStopping();
        doStop();
        Log.debug("stopped {}", this);
        setStopped();
      }
      catch (Exception e)
      {
        setFailed(e);
        throw e;
      }
      catch (Error e)
      {
        setFailed(e);
        throw e;
      }
    }
  }
  
  public boolean isRunning()
  {
    return (_state == 2) || (_state == 1);
  }
  
  public boolean isStarted()
  {
    return _state == 2;
  }
  
  public boolean isStarting()
  {
    return _state == 1;
  }
  
  public boolean isStopping()
  {
    return _state == 3;
  }
  
  public boolean isStopped()
  {
    return _state == 0;
  }
  
  public boolean isFailed()
  {
    return _state == -1;
  }
  
  public void addLifeCycleListener(LifeCycle.Listener listener)
  {
    _listeners = ((LifeCycle.Listener[])LazyList.addToArray(_listeners, listener, LifeCycle.Listener.class));
  }
  
  public void removeLifeCycleListener(LifeCycle.Listener listener)
  {
    _listeners = ((LifeCycle.Listener[])LazyList.removeFromArray(_listeners, listener));
  }
  
  private void setStarted()
  {
    _state = 2;
    if (_listeners != null) {
      for (int i = 0; i < _listeners.length; i++) {
        _listeners[i].lifeCycleStarted(this);
      }
    }
  }
  
  private void setStarting()
  {
    _state = 1;
    if (_listeners != null) {
      for (int i = 0; i < _listeners.length; i++) {
        _listeners[i].lifeCycleStarting(this);
      }
    }
  }
  
  private void setStopping()
  {
    _state = 3;
    if (_listeners != null) {
      for (int i = 0; i < _listeners.length; i++) {
        _listeners[i].lifeCycleStopping(this);
      }
    }
  }
  
  private void setStopped()
  {
    _state = 0;
    if (_listeners != null) {
      for (int i = 0; i < _listeners.length; i++) {
        _listeners[i].lifeCycleStopped(this);
      }
    }
  }
  
  private void setFailed(Throwable th)
  {
    Log.warn("failed " + this + ": " + th);
    Log.debug(th);
    _state = -1;
    if (_listeners != null) {
      for (int i = 0; i < _listeners.length; i++) {
        _listeners[i].lifeCycleFailure(this, th);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.component.AbstractLifeCycle
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

class Container$1 {}

/* Location:
 * Qualified Name:     org.mortbay.component.Container.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

import java.util.EventListener;

public abstract interface Container$Listener
  extends EventListener
{
  public abstract void addBean(Object paramObject);
  
  public abstract void removeBean(Object paramObject);
  
  public abstract void add(Container.Relationship paramRelationship);
  
  public abstract void remove(Container.Relationship paramRelationship);
}

/* Location:
 * Qualified Name:     org.mortbay.component.Container.Listener
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

public class Container$Relationship
{
  private Object _parent;
  private Object _child;
  private String _relationship;
  private Container _container;
  
  Container$Relationship(Container x0, Object x1, Object x2, String x3, Container.1 x4)
  {
    this(x0, x1, x2, x3);
  }
  
  private Container$Relationship(Container container, Object parent, Object child, String relationship)
  {
    _container = container;
    _parent = parent;
    _child = child;
    _relationship = relationship;
  }
  
  public Container getContainer()
  {
    return _container;
  }
  
  public Object getChild()
  {
    return _child;
  }
  
  public Object getParent()
  {
    return _parent;
  }
  
  public String getRelationship()
  {
    return _relationship;
  }
  
  public String toString()
  {
    return _parent + "---" + _relationship + "-->" + _child;
  }
  
  public int hashCode()
  {
    return _parent.hashCode() + _child.hashCode() + _relationship.hashCode();
  }
  
  public boolean equals(Object o)
  {
    if ((o == null) || (!(o instanceof Relationship))) {
      return false;
    }
    Relationship r = (Relationship)o;
    return (_parent == _parent) && (_child == _child) && (_relationship.equals(_relationship));
  }
}

/* Location:
 * Qualified Name:     org.mortbay.component.Container.Relationship
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

import java.util.EventListener;
import org.mortbay.log.Log;
import org.mortbay.util.LazyList;

public class Container
{
  private Object _listeners;
  
  public synchronized void addEventListener(Listener listener)
  {
    _listeners = LazyList.add(_listeners, listener);
  }
  
  public synchronized void removeEventListener(Listener listener)
  {
    _listeners = LazyList.remove(_listeners, listener);
  }
  
  public synchronized void update(Object parent, Object oldChild, Object child, String relationship)
  {
    if ((oldChild != null) && (!oldChild.equals(child))) {
      remove(parent, oldChild, relationship);
    }
    if ((child != null) && (!child.equals(oldChild))) {
      add(parent, child, relationship);
    }
  }
  
  public synchronized void update(Object parent, Object oldChild, Object child, String relationship, boolean addRemove)
  {
    if ((oldChild != null) && (!oldChild.equals(child)))
    {
      remove(parent, oldChild, relationship);
      if (addRemove) {
        removeBean(oldChild);
      }
    }
    if ((child != null) && (!child.equals(oldChild)))
    {
      if (addRemove) {
        addBean(child);
      }
      add(parent, child, relationship);
    }
  }
  
  public synchronized void update(Object parent, Object[] oldChildren, Object[] children, String relationship)
  {
    update(parent, oldChildren, children, relationship, false);
  }
  
  public synchronized void update(Object parent, Object[] oldChildren, Object[] children, String relationship, boolean addRemove)
  {
    Object[] newChildren = null;
    int i;
    if (children != null)
    {
      newChildren = new Object[children.length];
      for (i = children.length; i-- > 0;)
      {
        boolean new_child = true;
        int j;
        if (oldChildren != null) {
          for (j = oldChildren.length; j-- > 0;) {
            if ((children[i] != null) && (children[i].equals(oldChildren[j])))
            {
              oldChildren[j] = null;
              new_child = false;
            }
          }
        }
        if (new_child) {
          newChildren[i] = children[i];
        }
      }
    }
    int i;
    if (oldChildren != null) {
      for (i = oldChildren.length; i-- > 0;) {
        if (oldChildren[i] != null)
        {
          remove(parent, oldChildren[i], relationship);
          if (addRemove) {
            removeBean(oldChildren[i]);
          }
        }
      }
    }
    if (newChildren != null) {
      for (int i = 0; i < newChildren.length; i++) {
        if (newChildren[i] != null)
        {
          if (addRemove) {
            addBean(newChildren[i]);
          }
          add(parent, newChildren[i], relationship);
        }
      }
    }
  }
  
  public void addBean(Object obj)
  {
    if (_listeners != null) {
      for (int i = 0; i < LazyList.size(_listeners); i++)
      {
        Listener listener = (Listener)LazyList.get(_listeners, i);
        listener.addBean(obj);
      }
    }
  }
  
  public void removeBean(Object obj)
  {
    if (_listeners != null) {
      for (int i = 0; i < LazyList.size(_listeners); i++) {
        ((Listener)LazyList.get(_listeners, i)).removeBean(obj);
      }
    }
  }
  
  private void add(Object parent, Object child, String relationship)
  {
    if (Log.isDebugEnabled()) {
      Log.debug("Container " + parent + " + " + child + " as " + relationship);
    }
    if (_listeners != null)
    {
      Relationship event = new Relationship(this, parent, child, relationship, null);
      for (int i = 0; i < LazyList.size(_listeners); i++) {
        ((Listener)LazyList.get(_listeners, i)).add(event);
      }
    }
  }
  
  private void remove(Object parent, Object child, String relationship)
  {
    if (Log.isDebugEnabled()) {
      Log.debug("Container " + parent + " - " + child + " as " + relationship);
    }
    if (_listeners != null)
    {
      Relationship event = new Relationship(this, parent, child, relationship, null);
      for (int i = 0; i < LazyList.size(_listeners); i++) {
        ((Listener)LazyList.get(_listeners, i)).remove(event);
      }
    }
  }
  
  public static abstract interface Listener
    extends EventListener
  {
    public abstract void addBean(Object paramObject);
    
    public abstract void removeBean(Object paramObject);
    
    public abstract void add(Container.Relationship paramRelationship);
    
    public abstract void remove(Container.Relationship paramRelationship);
  }
  
  public static class Relationship
  {
    private Object _parent;
    private Object _child;
    private String _relationship;
    private Container _container;
    
    Relationship(Container x0, Object x1, Object x2, String x3, Container.1 x4)
    {
      this(x0, x1, x2, x3);
    }
    
    private Relationship(Container container, Object parent, Object child, String relationship)
    {
      _container = container;
      _parent = parent;
      _child = child;
      _relationship = relationship;
    }
    
    public Container getContainer()
    {
      return _container;
    }
    
    public Object getChild()
    {
      return _child;
    }
    
    public Object getParent()
    {
      return _parent;
    }
    
    public String getRelationship()
    {
      return _relationship;
    }
    
    public String toString()
    {
      return _parent + "---" + _relationship + "-->" + _child;
    }
    
    public int hashCode()
    {
      return _parent.hashCode() + _child.hashCode() + _relationship.hashCode();
    }
    
    public boolean equals(Object o)
    {
      if ((o == null) || (!(o instanceof Relationship))) {
        return false;
      }
      Relationship r = (Relationship)o;
      return (_parent == _parent) && (_child == _child) && (_relationship.equals(_relationship));
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.component.Container
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

import java.util.EventListener;

public abstract interface LifeCycle$Listener
  extends EventListener
{
  public abstract void lifeCycleStarting(LifeCycle paramLifeCycle);
  
  public abstract void lifeCycleStarted(LifeCycle paramLifeCycle);
  
  public abstract void lifeCycleFailure(LifeCycle paramLifeCycle, Throwable paramThrowable);
  
  public abstract void lifeCycleStopping(LifeCycle paramLifeCycle);
  
  public abstract void lifeCycleStopped(LifeCycle paramLifeCycle);
}

/* Location:
 * Qualified Name:     org.mortbay.component.LifeCycle.Listener
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.component;

import java.util.EventListener;

public abstract interface LifeCycle
{
  public abstract void start()
    throws Exception;
  
  public abstract void stop()
    throws Exception;
  
  public abstract boolean isRunning();
  
  public abstract boolean isStarted();
  
  public abstract boolean isStarting();
  
  public abstract boolean isStopping();
  
  public abstract boolean isStopped();
  
  public abstract boolean isFailed();
  
  public abstract void addLifeCycleListener(Listener paramListener);
  
  public abstract void removeLifeCycleListener(Listener paramListener);
  
  public static abstract interface Listener
    extends EventListener
  {
    public abstract void lifeCycleStarting(LifeCycle paramLifeCycle);
    
    public abstract void lifeCycleStarted(LifeCycle paramLifeCycle);
    
    public abstract void lifeCycleFailure(LifeCycle paramLifeCycle, Throwable paramThrowable);
    
    public abstract void lifeCycleStopping(LifeCycle paramLifeCycle);
    
    public abstract void lifeCycleStopped(LifeCycle paramLifeCycle);
  }
}

/* Location:
 * Qualified Name:     org.mortbay.component.LifeCycle
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.log;

import java.security.PrivilegedAction;

final class Log$1
  implements PrivilegedAction
{
  public Object run()
  {
    Log.__logClass = System.getProperty("org.mortbay.log.class", "org.mortbay.log.Slf4jLog");
    Log.__verbose = System.getProperty("VERBOSE", null) != null;
    Log.__ignored = System.getProperty("IGNORED", null) != null;
    return new Boolean(true);
  }
}

/* Location:
 * Qualified Name:     org.mortbay.log.Log.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.log;

import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.mortbay.util.Loader;

public class Log
{
  private static final String[] __nestedEx = { "getTargetException", "getTargetError", "getException", "getRootCause" };
  private static final Class[] __noArgs = new Class[0];
  public static final String EXCEPTION = "EXCEPTION ";
  public static final String IGNORED = "IGNORED";
  public static final String IGNORED_FMT = "IGNORED: {}";
  public static final String NOT_IMPLEMENTED = "NOT IMPLEMENTED ";
  public static String __logClass;
  public static boolean __verbose;
  public static boolean __ignored;
  private static Logger __log;
  
  static
  {
    AccessController.doPrivileged(new PrivilegedAction()
    {
      public Object run()
      {
        Log.__logClass = System.getProperty("org.mortbay.log.class", "org.mortbay.log.Slf4jLog");
        Log.__verbose = System.getProperty("VERBOSE", null) != null;
        Log.__ignored = System.getProperty("IGNORED", null) != null;
        return new Boolean(true);
      }
    });
    Class log_class = null;
    try
    {
      log_class = Loader.loadClass(Log.class, __logClass);
      __log = (Logger)log_class.newInstance();
    }
    catch (Throwable e)
    {
      log_class = StdErrLog.class;
      __log = new StdErrLog();
      __logClass = log_class.getName();
      if (__verbose) {
        e.printStackTrace();
      }
    }
    __log.info("Logging to {} via {}", __log, log_class.getName());
  }
  
  public static void setLog(Logger log)
  {
    __log = log;
  }
  
  public static Logger getLog()
  {
    return __log;
  }
  
  public static void debug(Throwable th)
  {
    if ((__log == null) || (!isDebugEnabled())) {
      return;
    }
    __log.debug("EXCEPTION ", th);
    unwind(th);
  }
  
  public static void debug(String msg)
  {
    if (__log == null) {
      return;
    }
    __log.debug(msg, null, null);
  }
  
  public static void debug(String msg, Object arg)
  {
    if (__log == null) {
      return;
    }
    __log.debug(msg, arg, null);
  }
  
  public static void debug(String msg, Object arg0, Object arg1)
  {
    if (__log == null) {
      return;
    }
    __log.debug(msg, arg0, arg1);
  }
  
  public static void ignore(Throwable th)
  {
    if (__log == null) {
      return;
    }
    if (__ignored)
    {
      __log.warn("IGNORED", th);
      unwind(th);
    }
    else if (__verbose)
    {
      __log.debug("IGNORED", th);
      unwind(th);
    }
  }
  
  public static void info(String msg)
  {
    if (__log == null) {
      return;
    }
    __log.info(msg, null, null);
  }
  
  public static void info(String msg, Object arg)
  {
    if (__log == null) {
      return;
    }
    __log.info(msg, arg, null);
  }
  
  public static void info(String msg, Object arg0, Object arg1)
  {
    if (__log == null) {
      return;
    }
    __log.info(msg, arg0, arg1);
  }
  
  public static boolean isDebugEnabled()
  {
    if (__log == null) {
      return false;
    }
    return __log.isDebugEnabled();
  }
  
  public static void warn(String msg)
  {
    if (__log == null) {
      return;
    }
    __log.warn(msg, null, null);
  }
  
  public static void warn(String msg, Object arg)
  {
    if (__log == null) {
      return;
    }
    __log.warn(msg, arg, null);
  }
  
  public static void warn(String msg, Object arg0, Object arg1)
  {
    if (__log == null) {
      return;
    }
    __log.warn(msg, arg0, arg1);
  }
  
  public static void warn(String msg, Throwable th)
  {
    if (__log == null) {
      return;
    }
    __log.warn(msg, th);
    unwind(th);
  }
  
  public static void warn(Throwable th)
  {
    if (__log == null) {
      return;
    }
    __log.warn("EXCEPTION ", th);
    unwind(th);
  }
  
  public static Logger getLogger(String name)
  {
    if (__log == null) {
      return __log;
    }
    if (name == null) {
      return __log;
    }
    return __log.getLogger(name);
  }
  
  private static void unwind(Throwable th)
  {
    if (th == null) {
      return;
    }
    for (int i = 0; i < __nestedEx.length; i++) {
      try
      {
        Method get_target = th.getClass().getMethod(__nestedEx[i], __noArgs);
        Throwable th2 = (Throwable)get_target.invoke(th, (Object[])null);
        if ((th2 != null) && (th2 != th)) {
          warn("Nested in " + th + ":", th2);
        }
      }
      catch (Exception ignore) {}
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.log.Log
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.log;

public abstract interface Logger
{
  public abstract boolean isDebugEnabled();
  
  public abstract void setDebugEnabled(boolean paramBoolean);
  
  public abstract void info(String paramString, Object paramObject1, Object paramObject2);
  
  public abstract void debug(String paramString, Throwable paramThrowable);
  
  public abstract void debug(String paramString, Object paramObject1, Object paramObject2);
  
  public abstract void warn(String paramString, Object paramObject1, Object paramObject2);
  
  public abstract void warn(String paramString, Throwable paramThrowable);
  
  public abstract Logger getLogger(String paramString);
}

/* Location:
 * Qualified Name:     org.mortbay.log.Logger
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.log;

import java.lang.reflect.Method;

public class Slf4jLog
  implements Logger
{
  private static final String LOGGER = "org.slf4j.Logger";
  private static final String LOGGERFACTORY = "org.slf4j.LoggerFactory";
  private static final Object[] NO_ARGS = new Object[0];
  private Method infoSOO;
  private Method debugSOO;
  private Method debugST;
  private Method debugEnabled;
  private Method warnSOO;
  private Method warnST;
  private Method errorST;
  private Object logger;
  
  public Slf4jLog()
    throws Exception
  {
    this("org.mortbay.log");
  }
  
  public Slf4jLog(String name)
    throws Exception
  {
    Class slf4j = null;
    Class slf4jf = null;
    try
    {
      slf4j = getClass().getClassLoader().loadClass("org.slf4j.Logger");
      slf4jf = getClass().getClassLoader().loadClass("org.slf4j.LoggerFactory");
    }
    catch (Exception e)
    {
      slf4j = Thread.currentThread().getContextClassLoader() == null ? Class.forName("org.slf4j.Logger") : Thread.currentThread().getContextClassLoader().loadClass("org.slf4j.Logger");
      slf4jf = Thread.currentThread().getContextClassLoader() == null ? Class.forName("org.slf4j.LoggerFactory") : Thread.currentThread().getContextClassLoader().loadClass("org.slf4j.LoggerFactory");
    }
    infoSOO = slf4j.getMethod("info", new Class[] { String.class, Object.class, Object.class });
    debugSOO = slf4j.getMethod("debug", new Class[] { String.class, Object.class, Object.class });
    debugST = slf4j.getMethod("debug", new Class[] { String.class, Throwable.class });
    debugEnabled = slf4j.getMethod("isDebugEnabled", new Class[0]);
    warnSOO = slf4j.getMethod("warn", new Class[] { String.class, Object.class, Object.class });
    warnST = slf4j.getMethod("warn", new Class[] { String.class, Throwable.class });
    errorST = slf4j.getMethod("error", new Class[] { String.class, Throwable.class });
    
    Method getLogger = slf4jf.getMethod("getLogger", new Class[] { String.class });
    logger = getLogger.invoke(null, new Object[] { name });
  }
  
  public void debug(String msg, Object arg0, Object arg1)
  {
    try
    {
      debugSOO.invoke(logger, new Object[] { msg, arg0, arg1 });
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public void debug(String msg, Throwable th)
  {
    try
    {
      debugST.invoke(logger, new Object[] { msg, th });
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public boolean isDebugEnabled()
  {
    try
    {
      return ((Boolean)debugEnabled.invoke(logger, NO_ARGS)).booleanValue();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return true;
  }
  
  public void info(String msg, Object arg0, Object arg1)
  {
    try
    {
      infoSOO.invoke(logger, new Object[] { msg, arg0, arg1 });
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public void warn(String msg, Object arg0, Object arg1)
  {
    try
    {
      warnSOO.invoke(logger, new Object[] { msg, arg0, arg1 });
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public void warn(String msg, Throwable th)
  {
    try
    {
      if (((th instanceof RuntimeException)) || ((th instanceof Error))) {
        errorST.invoke(logger, new Object[] { msg, th });
      } else {
        warnST.invoke(logger, new Object[] { msg, th });
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public Logger getLogger(String name)
  {
    try
    {
      return new Slf4jLog(name);
    }
    catch (Exception e)
    {
      Log.warn(e);
    }
    return this;
  }
  
  public String toString()
  {
    return logger.toString();
  }
  
  public void setDebugEnabled(boolean enabled)
  {
    warn("setDebugEnabled not implemented", null, null);
  }
}

/* Location:
 * Qualified Name:     org.mortbay.log.Slf4jLog
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.log;

import java.io.PrintStream;
import org.mortbay.util.DateCache;

public class StdErrLog
  implements Logger
{
  private static DateCache _dateCache;
  private static boolean __debug = System.getProperty("DEBUG", null) != null;
  private String _name;
  StringBuffer _buffer = new StringBuffer();
  
  static
  {
    try
    {
      _dateCache = new DateCache("yyyy-MM-dd HH:mm:ss");
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public StdErrLog()
  {
    this(null);
  }
  
  public StdErrLog(String name)
  {
    _name = (name == null ? "" : name);
  }
  
  public boolean isDebugEnabled()
  {
    return __debug;
  }
  
  public void setDebugEnabled(boolean enabled)
  {
    __debug = enabled;
  }
  
  public void info(String msg, Object arg0, Object arg1)
  {
    String d = _dateCache.now();
    int ms = _dateCache.lastMs();
    synchronized (_buffer)
    {
      tag(d, ms, ":INFO:");
      format(msg, arg0, arg1);
      System.err.println(_buffer.toString());
    }
  }
  
  public void debug(String msg, Throwable th)
  {
    if (__debug)
    {
      String d = _dateCache.now();
      int ms = _dateCache.lastMs();
      synchronized (_buffer)
      {
        tag(d, ms, ":DBUG:");
        format(msg);
        format(th);
        System.err.println(_buffer.toString());
      }
    }
  }
  
  public void debug(String msg, Object arg0, Object arg1)
  {
    if (__debug)
    {
      String d = _dateCache.now();
      int ms = _dateCache.lastMs();
      synchronized (_buffer)
      {
        tag(d, ms, ":DBUG:");
        format(msg, arg0, arg1);
        System.err.println(_buffer.toString());
      }
    }
  }
  
  public void warn(String msg, Object arg0, Object arg1)
  {
    String d = _dateCache.now();
    int ms = _dateCache.lastMs();
    synchronized (_buffer)
    {
      tag(d, ms, ":WARN:");
      format(msg, arg0, arg1);
      System.err.println(_buffer.toString());
    }
  }
  
  public void warn(String msg, Throwable th)
  {
    String d = _dateCache.now();
    int ms = _dateCache.lastMs();
    synchronized (_buffer)
    {
      tag(d, ms, ":WARN:");
      format(msg);
      format(th);
      System.err.println(_buffer.toString());
    }
  }
  
  private void tag(String d, int ms, String tag)
  {
    _buffer.setLength(0);
    _buffer.append(d);
    if (ms > 99) {
      _buffer.append('.');
    } else if (ms > 9) {
      _buffer.append(".0");
    } else {
      _buffer.append(".00");
    }
    _buffer.append(ms).append(tag).append(_name).append(':');
  }
  
  private void format(String msg, Object arg0, Object arg1)
  {
    int i0 = msg == null ? -1 : msg.indexOf("{}");
    int i1 = i0 < 0 ? -1 : msg.indexOf("{}", i0 + 2);
    if (i0 >= 0)
    {
      format(msg.substring(0, i0));
      format(String.valueOf(arg0 == null ? "null" : arg0));
      if (i1 >= 0)
      {
        format(msg.substring(i0 + 2, i1));
        format(String.valueOf(arg1 == null ? "null" : arg1));
        format(msg.substring(i1 + 2));
      }
      else
      {
        format(msg.substring(i0 + 2));
        if (arg1 != null)
        {
          _buffer.append(' ');
          format(String.valueOf(arg1));
        }
      }
    }
    else
    {
      format(msg);
      if (arg0 != null)
      {
        _buffer.append(' ');
        format(String.valueOf(arg0));
      }
      if (arg1 != null)
      {
        _buffer.append(' ');
        format(String.valueOf(arg1));
      }
    }
  }
  
  private void format(String msg)
  {
    if (msg == null) {
      _buffer.append("null");
    } else {
      for (int i = 0; i < msg.length(); i++)
      {
        char c = msg.charAt(i);
        if (Character.isISOControl(c))
        {
          if (c == '\n') {
            _buffer.append('|');
          } else if (c == '\r') {
            _buffer.append('<');
          } else {
            _buffer.append('?');
          }
        }
        else {
          _buffer.append(c);
        }
      }
    }
  }
  
  private void format(Throwable th)
  {
    if (th == null)
    {
      _buffer.append("null");
    }
    else
    {
      _buffer.append('\n');
      format(th.toString());
      StackTraceElement[] elements = th.getStackTrace();
      for (int i = 0; (elements != null) && (i < elements.length); i++)
      {
        _buffer.append("\n\tat ");
        format(elements[i].toString());
      }
    }
  }
  
  public Logger getLogger(String name)
  {
    if (((name == null) && (_name == null)) || ((name != null) && (name.equals(_name)))) {
      return this;
    }
    return new StdErrLog(name);
  }
  
  public String toString()
  {
    return "STDERR" + _name;
  }
}

/* Location:
 * Qualified Name:     org.mortbay.log.StdErrLog
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.mortbay.log.Log;
import org.mortbay.util.IO;

class CGI$1
  implements Runnable
{
  private final CGI this$0;
  
  CGI$1(CGI paramCGI, int paramInt, InputStream paramInputStream, OutputStream paramOutputStream) {}
  
  public void run()
  {
    try
    {
      if (val$inLength > 0) {
        IO.copy(val$inFromReq, val$outToCgi, val$inLength);
      }
      val$outToCgi.close();
    }
    catch (IOException e)
    {
      Log.ignore(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.servlet.CGI.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.servlet;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.mortbay.util.StringUtil;

class CGI$EnvList
{
  private Map envMap;
  
  CGI$EnvList()
  {
    envMap = new HashMap();
  }
  
  CGI$EnvList(EnvList l)
  {
    envMap = new HashMap(envMap);
  }
  
  public void set(String name, String value)
  {
    envMap.put(name, name + "=" + StringUtil.nonNull(value));
  }
  
  public String[] getEnvArray()
  {
    return (String[])envMap.values().toArray(new String[envMap.size()]);
  }
  
  public String toString()
  {
    return envMap.toString();
  }
}

/* Location:
 * Qualified Name:     org.mortbay.servlet.CGI.EnvList
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.servlet;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.log.Log;
import org.mortbay.util.IO;
import org.mortbay.util.StringUtil;

public class CGI
  extends HttpServlet
{
  private boolean _ok;
  private File _docRoot;
  private String _path;
  private String _cmdPrefix;
  private EnvList _env;
  private boolean _ignoreExitState;
  
  public void init()
    throws ServletException
  {
    _env = new EnvList();
    _cmdPrefix = getInitParameter("commandPrefix");
    
    String tmp = getInitParameter("cgibinResourceBase");
    if (tmp == null)
    {
      tmp = getInitParameter("resourceBase");
      if (tmp == null) {
        tmp = getServletContext().getRealPath("/");
      }
    }
    if (tmp == null)
    {
      Log.warn("CGI: no CGI bin !");
      return;
    }
    File dir = new File(tmp);
    if (!dir.exists())
    {
      Log.warn("CGI: CGI bin does not exist - " + dir);
      return;
    }
    if (!dir.canRead())
    {
      Log.warn("CGI: CGI bin is not readable - " + dir);
      return;
    }
    if (!dir.isDirectory())
    {
      Log.warn("CGI: CGI bin is not a directory - " + dir);
      return;
    }
    try
    {
      _docRoot = dir.getCanonicalFile();
    }
    catch (IOException e)
    {
      Log.warn("CGI: CGI bin failed - " + dir, e);
      return;
    }
    _path = getInitParameter("Path");
    if (_path != null) {
      _env.set("PATH", _path);
    }
    _ignoreExitState = "true".equalsIgnoreCase(getInitParameter("ignoreExitState"));
    Enumeration e = getInitParameterNames();
    while (e.hasMoreElements())
    {
      String n = (String)e.nextElement();
      if ((n != null) && (n.startsWith("ENV_"))) {
        _env.set(n.substring(4), getInitParameter(n));
      }
    }
    if (!_env.envMap.containsKey("SystemRoot"))
    {
      String os = System.getProperty("os.name");
      if ((os != null) && (os.toLowerCase().indexOf("windows") != -1))
      {
        String windir = System.getProperty("windir");
        _env.set("SystemRoot", windir != null ? windir : "C:\\WINDOWS");
      }
    }
    _ok = true;
  }
  
  public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
  {
    if (!_ok)
    {
      res.sendError(503);
      return;
    }
    String pathInContext = StringUtil.nonNull(req.getServletPath()) + StringUtil.nonNull(req.getPathInfo());
    if (Log.isDebugEnabled())
    {
      Log.debug("CGI: ContextPath : " + req.getContextPath());
      Log.debug("CGI: ServletPath : " + req.getServletPath());
      Log.debug("CGI: PathInfo    : " + req.getPathInfo());
      Log.debug("CGI: _docRoot    : " + _docRoot);
      Log.debug("CGI: _path       : " + _path);
      Log.debug("CGI: _ignoreExitState: " + _ignoreExitState);
    }
    String both = pathInContext;
    String first = both;
    String last = "";
    
    File exe = new File(_docRoot, first);
    while (((first.endsWith("/")) || (!exe.exists())) && (first.length() >= 0))
    {
      int index = first.lastIndexOf('/');
      
      first = first.substring(0, index);
      last = both.substring(index, both.length());
      exe = new File(_docRoot, first);
    }
    if ((first.length() == 0) || (!exe.exists()) || (exe.isDirectory()) || (!exe.getCanonicalPath().equals(exe.getAbsolutePath())))
    {
      res.sendError(404);
    }
    else
    {
      if (Log.isDebugEnabled())
      {
        Log.debug("CGI: script is " + exe);
        Log.debug("CGI: pathInfo is " + last);
      }
      exec(exe, last, req, res);
    }
  }
  
  private void exec(File command, String pathInfo, HttpServletRequest req, HttpServletResponse res)
    throws IOException
  {
    String path = command.getAbsolutePath();
    File dir = command.getParentFile();
    String scriptName = req.getRequestURI().substring(0, req.getRequestURI().length() - pathInfo.length());
    String scriptPath = getServletContext().getRealPath(scriptName);
    String pathTranslated = req.getPathTranslated();
    
    int len = req.getContentLength();
    if (len < 0) {
      len = 0;
    }
    if ((pathTranslated == null) || (pathTranslated.length() == 0)) {
      pathTranslated = path;
    }
    EnvList env = new EnvList(_env);
    
    env.set("AUTH_TYPE", req.getAuthType());
    env.set("CONTENT_LENGTH", Integer.toString(len));
    env.set("CONTENT_TYPE", req.getContentType());
    env.set("GATEWAY_INTERFACE", "CGI/1.1");
    if ((pathInfo != null) && (pathInfo.length() > 0)) {
      env.set("PATH_INFO", pathInfo);
    }
    env.set("PATH_TRANSLATED", pathTranslated);
    env.set("QUERY_STRING", req.getQueryString());
    env.set("REMOTE_ADDR", req.getRemoteAddr());
    env.set("REMOTE_HOST", req.getRemoteHost());
    
    env.set("REMOTE_USER", req.getRemoteUser());
    env.set("REQUEST_METHOD", req.getMethod());
    env.set("SCRIPT_NAME", scriptName);
    env.set("SCRIPT_FILENAME", scriptPath);
    env.set("SERVER_NAME", req.getServerName());
    env.set("SERVER_PORT", Integer.toString(req.getServerPort()));
    env.set("SERVER_PROTOCOL", req.getProtocol());
    env.set("SERVER_SOFTWARE", getServletContext().getServerInfo());
    
    Enumeration enm = req.getHeaderNames();
    while (enm.hasMoreElements())
    {
      String name = (String)enm.nextElement();
      String value = req.getHeader(name);
      env.set("HTTP_" + name.toUpperCase().replace('-', '_'), value);
    }
    env.set("HTTPS", req.isSecure() ? "ON" : "OFF");
    
    String execCmd = path;
    if ((execCmd.charAt(0) != '"') && (execCmd.indexOf(" ") >= 0)) {
      execCmd = "\"" + execCmd + "\"";
    }
    if (_cmdPrefix != null) {
      execCmd = _cmdPrefix + " " + execCmd;
    }
    Process p = dir == null ? Runtime.getRuntime().exec(execCmd, env.getEnvArray()) : Runtime.getRuntime().exec(execCmd, env.getEnvArray(), dir);
    
    final InputStream inFromReq = req.getInputStream();
    final OutputStream outToCgi = p.getOutputStream();
    final int inLength = len;
    
    IO.copyThread(p.getErrorStream(), System.err);
    
    new Thread(new Runnable()
    {
      public void run()
      {
        try
        {
          if (inLength > 0) {
            IO.copy(inFromReq, outToCgi, inLength);
          }
          outToCgi.close();
        }
        catch (IOException e)
        {
          Log.ignore(e);
        }
      }
    }).start();
    OutputStream os = null;
    try
    {
      String line = null;
      InputStream inFromCgi = p.getInputStream();
      while ((line = getTextLineFromStream(inFromCgi)).length() > 0) {
        if (!line.startsWith("HTTP"))
        {
          int k = line.indexOf(':');
          if (k > 0)
          {
            String key = line.substring(0, k).trim();
            String value = line.substring(k + 1).trim();
            if ("Location".equals(key))
            {
              res.sendRedirect(value);
            }
            else if ("Status".equals(key))
            {
              String[] token = value.split(" ");
              int status = Integer.parseInt(token[0]);
              res.setStatus(status);
            }
            else
            {
              res.addHeader(key, value);
            }
          }
        }
      }
      os = res.getOutputStream();
      IO.copy(inFromCgi, os);
      p.waitFor();
      if (!_ignoreExitState)
      {
        int exitValue = p.exitValue();
        if (0 != exitValue)
        {
          Log.warn("Non-zero exit status (" + exitValue + ") from CGI program: " + path);
          if (!res.isCommitted()) {
            res.sendError(500, "Failed to exec CGI");
          }
        }
      }
    }
    catch (IOException e)
    {
      Log.debug("CGI: Client closed connection!");
    }
    catch (InterruptedException ie)
    {
      Log.debug("CGI: interrupted!");
    }
    finally
    {
      if (os != null) {
        try
        {
          os.close();
        }
        catch (Exception e)
        {
          Log.ignore(e);
        }
      }
      os = null;
      p.destroy();
    }
  }
  
  private String getTextLineFromStream(InputStream is)
    throws IOException
  {
    StringBuffer buffer = new StringBuffer();
    int b;
    while (((b = is.read()) != -1) && (b != 10)) {
      buffer.append((char)b);
    }
    return buffer.toString().trim();
  }
  
  private static class EnvList
  {
    private Map envMap;
    
    EnvList()
    {
      envMap = new HashMap();
    }
    
    EnvList(EnvList l)
    {
      envMap = new HashMap(envMap);
    }
    
    public void set(String name, String value)
    {
      envMap.put(name, name + "=" + StringUtil.nonNull(value));
    }
    
    public String[] getEnvArray()
    {
      return (String[])envMap.values().toArray(new String[envMap.size()]);
    }
    
    public String toString()
    {
      return envMap.toString();
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.servlet.CGI
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ConcatServlet
  extends HttpServlet
{
  boolean _development;
  long _lastModified;
  ServletContext _context;
  
  public void init()
    throws ServletException
  {
    _lastModified = System.currentTimeMillis();
    _context = getServletContext();
    _development = "true".equals(getInitParameter("development"));
  }
  
  protected long getLastModified(HttpServletRequest req)
  {
    return _development ? -1L : _lastModified;
  }
  
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    String q = req.getQueryString();
    if (q == null)
    {
      resp.sendError(204);
      return;
    }
    String[] parts = q.split("\
1 2 3 4 5 6 7 8 9 10

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd