wms-winstone-1.0.5

        }
        if (delim != rangeBlock.length() - 1) {
          end = Integer.parseInt(rangeBlock.substring(delim + 1).trim());
        }
        totalSent += end - start;
        rangeText = rangeText + "," + start + "-" + end;
        ranges.add(start + "-" + end);
      }
      response.setStatus(206);
      response.addHeader("Content-Range", "bytes " + rangeText.substring(1) + "/" + res.length());
      response.setContentLength(totalSent);
      
      response.addHeader("Accept-Ranges", "bytes");
      response.addDateHeader("Last-Modified", res.lastModified());
      OutputStream out = response.getOutputStream();
      int bytesRead = 0;
      for (Iterator<String> i = ranges.iterator(); i.hasNext(); goto 1204)
      {
        String rangeBlock = (String)i.next();
        int delim = rangeBlock.indexOf('-');
        int start = Integer.parseInt(rangeBlock.substring(0, delim));
        int end = Integer.parseInt(rangeBlock.substring(delim + 1));
        int read = 0;
        if ((read != -1) && (bytesRead <= res.length()))
        {
          read = resStream.read();
          if ((bytesRead >= start) && (bytesRead < end)) {
            out.write(read);
          }
          bytesRead++;
        }
      }
      resStream.close();
    }
    else
    {
      response.sendError(416);
    }
  }
  
  private void generateDirectoryList(HttpServletRequest request, HttpServletResponse response, String path)
    throws ServletException, IOException
  {
    File dir = path.equals("") ? webRoot : new File(webRoot, path);
    File[] children = dir.listFiles();
    Arrays.sort(children);
    
    StringWriter rowString = new StringWriter();
    
    int rowCount = 0;
    if ((!path.equals("")) && (!path.equals("/")))
    {
      rowString.write(StringUtils.replaceToken(rowTemplate, new String[] { rowTextColour, evenColour, parentDirLabel, "..", noDateLabel, directoryLabel }));
      rowCount++;
    }
    DateFormat sdfFileDate = new SimpleDateFormat("dd-MM-yyyy HH:mm");
    for (int n = 0; n < children.length; n++) {
      if ((!children[n].getName().equalsIgnoreCase("web-inf")) && (!children[n].getName().equalsIgnoreCase("meta-inf")))
      {
        File file = children[n];
        String date = noDateLabel;
        String size = directoryLabel;
        if (!file.isDirectory())
        {
          size = "" + file.length();
          date = sdfFileDate.format(new Date(file.lastModified()));
        }
        rowString.write(StringUtils.replaceToken(rowTemplate, new String[] { rowTextColour, rowCount % 2 == 0 ? evenColour : oddColour, file.getName() + (file.isDirectory() ? "/" : ""), "./" + file.getName() + (file.isDirectory() ? "/" : ""), date, size }));
        
        rowCount++;
      }
    }
    String out = StringUtils.replaceToken(bodyTemplate, new String[] { headerColour, headerTextColour, labelColour, labelTextColour, new Date().toString(), serverVersion, path.equals("") ? "/" : path, rowString.toString() });
    
    response.setContentLength(out.getBytes().length);
    response.setContentType("text/html");
    Writer w = response.getWriter();
    w.write(out);
    w.close();
  }
  
  public static boolean isDescendant(File parent, File child, File commonBase)
    throws IOException
  {
    if (child.equals(parent)) {
      return Boolean.TRUE.booleanValue();
    }
    String canonicalParent = parent.getAbsoluteFile().getCanonicalPath();
    String canonicalChild = child.getAbsoluteFile().getCanonicalPath();
    if (canonicalChild.startsWith(canonicalParent)) {
      return Boolean.TRUE.booleanValue();
    }
    String childOCValue = constructOurCanonicalVersion(child, commonBase);
    String parentOCValue = constructOurCanonicalVersion(parent, commonBase);
    return childOCValue.startsWith(parentOCValue);
  }
  
  public static String constructOurCanonicalVersion(File current, File stopPoint)
  {
    int backOnes = 0;
    StringBuilder ourCanonicalVersion = new StringBuilder();
    while ((current != null) && (!current.equals(stopPoint)))
    {
      if (current.getName().equals("..")) {
        backOnes++;
      } else if (!current.getName().equals(".")) {
        if (backOnes > 0) {
          backOnes--;
        } else {
          ourCanonicalVersion.insert(0, "/" + current.getName());
        }
      }
      current = current.getParentFile();
    }
    return ourCanonicalVersion.toString();
  }
}

/* Location:
 * Qualified Name:     net.winstone.servlet.StaticResourceServlet
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.tools;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Map;
import net.winstone.boot.BootStrap;
import net.winstone.boot.Command;
import net.winstone.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WinstoneControl
{
  private static final int TIMEOUT = 10000;
  protected Logger logger = LoggerFactory.getLogger(getClass());
  
  public static void main(String[] argv)
  {
    new WinstoneControl().call(argv);
  }
  
  private static void printUsage()
  {
    System.out.println("Winstone Command Line Controller\nUsage: java winstone.tools.WinstoneControl <operation> --host=<host> --port=<control port>\n\n<operation> can be \"shutdown\" or \"reload:<prefix>\"");
  }
  
  public void call(String[] argv)
  {
    Map<String, String> options = new BootStrap(argv).loadArgs("operation");
    if ((options.isEmpty()) || (options.containsKey("usage")) || (options.containsKey("help")))
    {
      printUsage();
      return;
    }
    assert (options != null);
    
    String operation = (String)options.get("operation");
    if ((options.containsKey("controlPort")) && (!options.containsKey("port"))) {
      options.put("port", options.get("controlPort"));
    }
    if ((operation == null) || (operation.equals("")))
    {
      printUsage();
      return;
    }
    String host = StringUtils.stringArg(options, "host", "localhost");
    String port = StringUtils.stringArg(options, "port", "8081");
    logger.info("Connecting to {}:{}", host, port);
    if (operation.equalsIgnoreCase("shutdown"))
    {
      execute(host, port, Command.SHUTDOWN, null);
    }
    else if (operation.toLowerCase().startsWith("reload:"))
    {
      execute(host, port, Command.RELOAD, operation.substring("reload:".length()));
      logger.info("Successfully sent webapp reload command to {}:{}", host, port);
    }
    else
    {
      printUsage();
    }
  }
  
  private void execute(String host, String port, Command command, String extra)
  {
    Socket socket = null;
    try
    {
      socket = new Socket(host, Integer.parseInt(port));
      socket.setSoTimeout(10000);
      OutputStream out = socket.getOutputStream();
      out.write(command.getCode());
      if (extra != null)
      {
        ObjectOutputStream objOut = new ObjectOutputStream(out);
        objOut.writeUTF(host);
        objOut.writeUTF(extra);
        objOut.close();
      }
      logger.info("Successfully sent server shutdown command to {}:{}", host, port); return;
    }
    catch (NumberFormatException e)
    {
      logger.error("execute: " + command, e);
    }
    catch (UnknownHostException e)
    {
      logger.error("execute: " + command, e);
    }
    catch (IOException e)
    {
      logger.error("execute: " + command, e);
    }
    finally
    {
      if (socket != null) {
        try
        {
          socket.close();
        }
        catch (IOException e) {}
      }
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.tools.WinstoneControl
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

public final class Base64
{
  private static byte[] B64_DECODE_ARRAY = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1 };
  
  public static String decode(String input)
  {
    char[] inBytes = input.toCharArray();
    byte[] outBytes = new byte[(int)(inBytes.length * 0.75F)];
    
    int length = decode(inBytes, outBytes, 0, inBytes.length, 0);
    return new String(outBytes, 0, length);
  }
  
  public static int decode(char[] input, byte[] output, int inOffset, int inLength, int outOffset)
  {
    if (inLength == 0) {
      return 0;
    }
    int outIndex = outOffset;
    for (int inIndex = inOffset; inIndex < inLength;)
    {
      int thisPassInBytes = Math.min(inLength - inIndex, 4);
      while ((thisPassInBytes > 1) && (input[(inIndex + thisPassInBytes - 1)] == '=')) {
        thisPassInBytes--;
      }
      if (thisPassInBytes == 2)
      {
        int outBuffer = (B64_DECODE_ARRAY[input[inIndex]] & 0xFF) << 18 | (B64_DECODE_ARRAY[input[(inIndex + 1)]] & 0xFF) << 12;
        output[outIndex] = ((byte)(outBuffer >> 16 & 0xFF));
        outIndex++;
      }
      else if (thisPassInBytes == 3)
      {
        int outBuffer = (B64_DECODE_ARRAY[input[inIndex]] & 0xFF) << 18 | (B64_DECODE_ARRAY[input[(inIndex + 1)]] & 0xFF) << 12 | (B64_DECODE_ARRAY[input[(inIndex + 2)]] & 0xFF) << 6;
        output[outIndex] = ((byte)(outBuffer >> 16 & 0xFF));
        output[(outIndex + 1)] = ((byte)(outBuffer >> 8 & 0xFF));
        outIndex += 2;
      }
      else if (thisPassInBytes == 4)
      {
        int outBuffer = (B64_DECODE_ARRAY[input[inIndex]] & 0xFF) << 18 | (B64_DECODE_ARRAY[input[(inIndex + 1)]] & 0xFF) << 12 | (B64_DECODE_ARRAY[input[(inIndex + 2)]] & 0xFF) << 6 | B64_DECODE_ARRAY[input[(inIndex + 3)]] & 0xFF;
        
        output[outIndex] = ((byte)(outBuffer >> 16 & 0xFF));
        output[(outIndex + 1)] = ((byte)(outBuffer >> 8 & 0xFF));
        output[(outIndex + 2)] = ((byte)(outBuffer & 0xFF));
        outIndex += 3;
      }
      inIndex += thisPassInBytes;
    }
    return outIndex;
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.Base64
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

class BoundedExecutorService$1
  implements Runnable
{
  BoundedExecutorService$1(BoundedExecutorService paramBoundedExecutorService, Runnable paramRunnable) {}
  
  public void run()
  {
    try
    {
      val$task.run();
    }
    finally
    {
      BoundedExecutorService.access$000(this$0);
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.BoundedExecutorService.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;

public class BoundedExecutorService
  extends AbstractExecutorService
{
  private final List<Runnable> tasks = new LinkedList();
  private final ExecutorService base;
  private final int max;
  private int current;
  private boolean isShutdown = false;
  
  public BoundedExecutorService(ExecutorService base, int max)
  {
    this.base = base;
    this.max = max;
  }
  
  public synchronized void execute(Runnable r)
  {
    if (isShutdown) {
      throw new RejectedExecutionException("already shut down");
    }
    tasks.add(r);
    if (current < max) {
      scheduleNext();
    }
  }
  
  private synchronized void scheduleNext()
  {
    if (tasks.isEmpty())
    {
      if (isShutdown) {
        base.shutdown();
      }
      return;
    }
    final Runnable task = (Runnable)tasks.remove(0);
    base.execute(new Runnable()
    {
      public void run()
      {
        try
        {
          task.run();
        }
        finally
        {
          BoundedExecutorService.this.done();
        }
      }
    });
    current += 1;
  }
  
  private synchronized void done()
  {
    current -= 1;
    scheduleNext();
  }
  
  public synchronized void shutdown()
  {
    isShutdown = true;
    if (tasks.isEmpty()) {
      base.shutdown();
    }
  }
  
  public synchronized List<Runnable> shutdownNow()
  {
    isShutdown = true;
    List<Runnable> r = base.shutdownNow();
    r.addAll(tasks);
    tasks.clear();
    return r;
  }
  
  public boolean isShutdown()
  {
    return isShutdown;
  }
  
  public boolean isTerminated()
  {
    return base.isTerminated();
  }
  
  public boolean awaitTermination(long timeout, TimeUnit unit)
    throws InterruptedException
  {
    return base.awaitTermination(timeout, unit);
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.BoundedExecutorService
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.text.DateFormat;
import java.util.Date;

public final class DateCache
{
  private final DateFormat dateFormat;
  private String result = null;
  private long lastTimeInSeconds = -1L;
  
  public DateCache(DateFormat format)
  {
    dateFormat = format;
  }
  
  public String now()
  {
    return format(System.currentTimeMillis());
  }
  
  public String format(long time)
  {
    long seconds = time / 1000L;
    if ((lastTimeInSeconds < 0L) || (lastTimeInSeconds != seconds))
    {
      lastTimeInSeconds = (time / 1000L);
      Date d = new Date(time);
      synchronized (dateFormat)
      {
        result = dateFormat.format(d);
      }
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.DateCache
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtils
{
  private static final DateFormat gmtFormat;
  private static final SimpleDateFormat shortFormat = new SimpleDateFormat("MMM dd HH:mm");
  private static final SimpleDateFormat longFormat = new SimpleDateFormat("MMM dd yyyy");
  
  static
  {
    gmtFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.US);
    gmtFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
  }
  
  public static String getGmt(Date date)
  {
    return gmtFormat.format(date) + " GMT";
  }
  
  public static String lsDateStr(Date date)
  {
    if (Math.abs(System.currentTimeMillis() - date.getTime()) < 15811200000L) {
      return shortFormat.format(date);
    }
    return longFormat.format(date);
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.DateUtils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;

public class FileUtils
{
  public static void copy(File src, File dst, boolean overwrite)
    throws IOException, IllegalArgumentException
  {
    if ((!src.isFile()) || (!src.exists())) {
      throw new IllegalArgumentException("Source file '" + src.getAbsolutePath() + "' not found!");
    }
    if (dst.exists()) {
      if (dst.isDirectory()) {
        dst = new File(dst, src.getName());
      } else if (dst.isFile())
      {
        if (!overwrite) {
          throw new IllegalArgumentException("Destination file '" + dst.getAbsolutePath() + "' already exists!");
        }
      }
      else {
        throw new IllegalArgumentException("Invalid destination object '" + dst.getAbsolutePath() + "'!");
      }
    }
    File dstParent = dst.getParentFile();
    if ((!dstParent.exists()) && 
      (!dstParent.mkdirs())) {
      throw new IOException("Failed to create directory " + dstParent.getAbsolutePath());
    }
    long fileSize = src.length();
    if (fileSize > 20971520L)
    {
      FileInputStream in = new FileInputStream(src);
      FileOutputStream out = new FileOutputStream(dst);
      try
      {
        int doneCnt = -1;
        int bufSize = 32768;
        byte[] buf = new byte[32768];
        while ((doneCnt = in.read(buf, 0, 32768)) >= 0) {
          if (doneCnt == 0) {
            Thread.yield();
          } else {
            out.write(buf, 0, doneCnt);
          }
        }
        out.flush();
      }
      finally
      {
        try
        {
          in.close();
        }
        catch (IOException e) {}
        try
        {
          out.close();
        }
        catch (IOException e) {}
      }
    }
    FileInputStream fis = new FileInputStream(src);
    FileOutputStream fos = new FileOutputStream(dst);
    FileChannel in = fis.getChannel();FileChannel out = fos.getChannel();
    try
    {
      long offs = 0L;long doneCnt = 0L;
      long copyCnt = Math.min(65536L, fileSize);
      do
      {
        doneCnt = in.transferTo(offs, copyCnt, out);
        offs += doneCnt;
        fileSize -= doneCnt;
      } while (fileSize > 0L);
      return;
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e) {}
      try
      {
        out.close();
      }
      catch (IOException e) {}
      try
      {
        fis.close();
      }
      catch (IOException e) {}
      try
      {
        fos.close();
      }
      catch (IOException e) {}
    }
  }
  
  public static void copyStream(InputStream in, OutputStream out)
    throws IOException
  {
    copyStream(in, out, -1L);
  }
  
  public static void copyStream(InputStream in, OutputStream out, long maxLen)
    throws IOException
  {
    byte[] buf = new byte['?'];
    if (maxLen <= 0L)
    {
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
    }
    long max = maxLen;
    int len;
    while ((len = in.read(buf)) > 0) {
      if (len <= max)
      {
        out.write(buf, 0, len);
        max -= len;
      }
      else
      {
        out.write(buf, 0, (int)max);
      }
    }
  }
  
  public static boolean delete(File from)
  {
    if ((from != null) && (from.exists()))
    {
      if (from.isDirectory()) {
        for (File child : from.listFiles()) {
          delete(child);
        }
      }
      return from.delete();
    }
    return Boolean.FALSE.booleanValue();
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.FileUtils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

public abstract interface LifeCycle
{
  public abstract void initialize();
  
  public abstract void destroy();
}

/* Location:
 * Qualified Name:     net.winstone.util.LifeCycle
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.Map.Entry;

public class MapConverter
{
  public static <T> T apply(Map<String, String> map, T target)
    throws IllegalArgumentException
  {
    try
    {
      for (Map.Entry<String, String> entry : map.entrySet())
      {
        Field field = null;
        try
        {
          field = target.getClass().getDeclaredField((String)entry.getKey());
        }
        catch (NoSuchFieldException e) {}
        if (field != null)
        {
          boolean notAccessible = Boolean.FALSE.booleanValue();
          if (!field.isAccessible())
          {
            field.setAccessible(Boolean.TRUE.booleanValue());
            notAccessible = Boolean.TRUE.booleanValue();
          }
          if (field.getType().equals(String.class)) {
            field.set(target, entry.getValue());
          } else if ((field.getType().equals(Integer.class)) || (field.getType().equals(Integer.TYPE))) {
            field.setInt(target, Integer.parseInt((String)entry.getValue()));
          } else if ((field.getType().equals(Long.class)) || (field.getType().equals(Long.TYPE))) {
            field.setLong(target, Long.parseLong((String)entry.getValue()));
          } else if ((field.getType().equals(Boolean.class)) || (field.getType().equals(Boolean.TYPE))) {
            field.setBoolean(target, Boolean.parseBoolean((String)entry.getValue()));
          }
          if (notAccessible) {
            field.setAccessible(Boolean.FALSE.booleanValue());
          }
        }
      }
    }
    catch (IllegalAccessException e)
    {
      throw new IllegalArgumentException(e);
    }
    return target;
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.MapConverter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public final class MapLoader
{
  public static Map<String, String> load(ResourceBundle resourceBundle)
  {
    Map<String, String> resources = new HashMap();
    if (resourceBundle != null)
    {
      Enumeration<String> keys = resourceBundle.getKeys();
      String key = null;
      while (keys.hasMoreElements())
      {
        key = (String)keys.nextElement();
        String value = resourceBundle.getString(key);
        resources.put(key, value);
      }
    }
    return resources;
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.MapLoader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.util.Hashtable;
import java.util.Map;

public class SizeRestrictedHashMap<K, V>
  extends Hashtable<K, V>
{
  private static final long serialVersionUID = 530449428559953521L;
  private final int maximumCapacity;
  
  public SizeRestrictedHashMap(int initialCapacity, float loadFactor, int maximumCapacity)
  {
    super(initialCapacity, loadFactor);
    this.maximumCapacity = maximumCapacity;
  }
  
  public SizeRestrictedHashMap(int initialCapacity, int maximumCapacity)
  {
    super(initialCapacity);
    this.maximumCapacity = maximumCapacity;
  }
  
  public SizeRestrictedHashMap(int maximumCapacity)
  {
    this.maximumCapacity = maximumCapacity;
  }
  
  public SizeRestrictedHashMap(Map<? extends K, ? extends V> t, int maximumCapacity)
  {
    super(t);
    this.maximumCapacity = maximumCapacity;
  }
  
  public V put(K key, V value)
  {
    if (size() > maximumCapacity) {
      throw new IllegalStateException("Hash table size limit exceeded");
    }
    return (V)super.put(key, value);
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.SizeRestrictedHashMap
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.util.Hashtable;
import java.util.Map;

public class SizeRestrictedHashtable<K, V>
  extends Hashtable<K, V>
{
  private static final long serialVersionUID = -3783614228146621688L;
  private final int maximumCapacity;
  
  public SizeRestrictedHashtable(int initialCapacity, float loadFactor, int cap)
  {
    super(initialCapacity, loadFactor);
    maximumCapacity = cap;
  }
  
  public SizeRestrictedHashtable(int initialCapacity, int cap)
  {
    super(initialCapacity);
    maximumCapacity = cap;
  }
  
  public SizeRestrictedHashtable(int cap)
  {
    maximumCapacity = cap;
  }
  
  public SizeRestrictedHashtable(Map<? extends K, ? extends V> t, int cap)
  {
    super(t);
    maximumCapacity = cap;
  }
  
  public V put(K key, V value)
  {
    if (size() > maximumCapacity) {
      throw new IllegalStateException("Hash table size limit exceeded");
    }
    return (V)super.put(key, value);
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.SizeRestrictedHashtable
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class StringUtils
{
  public <T> T checkNotNull(T value, String message)
    throws IllegalArgumentException
  {
    if (value == null) {
      throw new IllegalArgumentException(message);
    }
    return value;
  }
  
  public String checkNotEmpty(String value, String message)
    throws IllegalArgumentException
  {
    if ((value != null) && (!"".equals(value))) {
      return value;
    }
    throw new IllegalArgumentException(message);
  }
  
  public static File fileArg(Map<String, String> args, String name)
  {
    String value = (String)args.get(name);
    return value != null ? new File(value) : null;
  }
  
  public static boolean booleanArg(Map<String, String> args, String name, boolean defaultTrue)
  {
    String value = (String)args.get(name);
    if (defaultTrue) {
      return (value == null) || (value.equalsIgnoreCase("true")) || (value.equalsIgnoreCase("yes"));
    }
    return (value != null) && ((value.equalsIgnoreCase("true")) || (value.equalsIgnoreCase("yes")));
  }
  
  public static String stringArg(Map<String, String> args, String name, String defaultValue)
  {
    return args.get(name) == null ? defaultValue : (String)args.get(name);
  }
  
  public static int intArg(Map<String, String> args, String name, int defaultValue)
  {
    return Integer.parseInt(stringArg(args, name, Integer.toString(defaultValue)));
  }
  
  public static String get(String value, String defaultValue)
  {
    if ((value == null) || ("".equals(value))) {
      return defaultValue;
    }
    return value;
  }
  
  public static String extractQueryAnchor(String path, boolean query)
  {
    int qp = path.indexOf('?');
    if (query)
    {
      if (qp >= 0) {
        return path.substring(qp + 1);
      }
      return null;
    }
    int hp = path.indexOf('#');
    if (qp >= 0)
    {
      if ((hp >= 0) && (hp < qp)) {
        return path.substring(0, hp);
      }
      return path.substring(0, qp);
    }
    if (hp >= 0) {
      return path.substring(0, hp);
    }
    return path;
  }
  
  @Deprecated
  public static String globalReplace(String input, String fromMarker, String toValue)
  {
    StringBuilder out = new StringBuilder(input);
    globalReplace(out, fromMarker, toValue);
    return out.toString();
  }
  
  @Deprecated
  public static String globalReplace(String input, String[][] parameters)
  {
    if (parameters != null)
    {
      StringBuilder out = new StringBuilder(input);
      for (int n = 0; n < parameters.length; n++) {
        globalReplace(out, parameters[n][0], parameters[n][1]);
      }
      return out.toString();
    }
    return input;
  }
  
  @Deprecated
  public static void globalReplace(StringBuilder input, String fromMarker, String toValue)
  {
    if (input == null) {
      return;
    }
    if (fromMarker == null) {
      return;
    }
    String value = toValue == null ? "(null)" : toValue;
    int index = 0;
    int foundAt = input.indexOf(fromMarker, index);
    while (foundAt != -1)
    {
      input.replace(foundAt, foundAt + fromMarker.length(), value);
      index = foundAt + toValue.length();
      foundAt = input.indexOf(fromMarker, index);
    }
  }
  
  public static String replace(String input, String sub, String with)
  {
    int fromIndex = 0;
    int index = input.indexOf(sub, fromIndex);
    if (index == -1) {
      return input;
    }
    StringBuilder buf = new StringBuilder(input.length() + with.length());
    do
    {
      buf.append(input.substring(fromIndex, index));
      buf.append(with);
      fromIndex = index + sub.length();
    } while ((index = input.indexOf(sub, fromIndex)) != -1);
    if (fromIndex < input.length()) {
      buf.append(input.substring(fromIndex, input.length()));
    }
    return buf.toString();
  }
  
  public static String replace(String input, String[][] tokens)
  {
    if ((tokens != null) && (input != null))
    {
      String out = input;
      for (int n = 0; n < tokens.length; n++) {
        out = replace(out, tokens[n][0], tokens[n][1]);
      }
      return out;
    }
    return input;
  }
  
  public static String replaceToken(String input, String... parameters)
  {
    if ((input != null) && (parameters != null))
    {
      String[][] tokens = new String[parameters.length][2];
      for (int n = 0; n < parameters.length; n++) {
        tokens[n] = { "[#" + n + "]", parameters[n] };
      }
      return replace(input, tokens);
    }
    return input;
  }
  
  public static String htmlEscapeBasicMarkup(String text)
  {
    StringBuilder buf = new StringBuilder(text.length() + 64);
    for (int i = 0; i < text.length(); i++)
    {
      char ch = text.charAt(i);
      switch (ch)
      {
      case '<': 
        buf.append("&lt;");
        break;
      case '&': 
        buf.append("&amp;");
        break;
      case '>': 
        buf.append("&gt;");
        break;
      default: 
        buf.append(ch);
      }
    }
    return buf.toString();
  }
  
  public static String canonicalPath(String path)
  {
    List<String> r = new ArrayList(Arrays.asList(path.split("[/\\\\]+")));
    for (int i = 0; i < r.size();)
    {
      String cur = (String)r.get(i);
      if ((cur.length() == 0) || (cur.equals(".")))
      {
        r.remove(i);
      }
      else if (cur.equals(".."))
      {
        r.remove(i);
        if (i > 0)
        {
          r.remove(i - 1);
          i--;
        }
      }
      else
      {
        i++;
      }
    }
    StringBuilder buf = new StringBuilder();
    if (path.startsWith("/")) {
      buf.append('/');
    }
    boolean first = Boolean.TRUE.booleanValue();
    for (Object aR : r)
    {
      String token = (String)aR;
      if (!first) {
        buf.append('/');
      } else {
        first = Boolean.FALSE.booleanValue();
      }
      buf.append(token);
    }
    if ((path.endsWith("/")) && ((buf.length() == 0) || (buf.charAt(buf.length() - 1) != '/'))) {
      buf.append('/');
    }
    return buf.toString();
  }
  
  public static String noCRLF(String text)
  {
    return text.replace('\r', ' ').replace('\n', ' ');
  }
}

/* Location:
 * Qualified Name:     net.winstone.util.StringUtils
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

import net.winstone.boot.BootStrap;

public class Winstone
{
  public static void main(String[] args)
  {
    BootStrap bootStrap = new BootStrap(args);
    Server server = bootStrap.boot();
    if (server != null) {
      server.start();
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.Winstone
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

import java.io.PrintStream;
import java.io.PrintWriter;

public class WinstoneException
  extends RuntimeException
{
  private static final long serialVersionUID = 3080421704084165118L;
  private final Throwable nestedError;
  
  public WinstoneException(String message)
  {
    this(message, null);
  }
  
  public WinstoneException(String message, Throwable pError)
  {
    super(message);
    nestedError = pError;
  }
  
  public Throwable getNestedError()
  {
    return nestedError;
  }
  
  public void printStackTrace(PrintWriter p)
  {
    if (nestedError != null) {
      nestedError.printStackTrace(p);
    }
    p.write("\n");
    super.printStackTrace(p);
  }
  
  public void printStackTrace(PrintStream p)
  {
    if (nestedError != null) {
      nestedError.printStackTrace(p);
    }
    p.println("\n");
    super.printStackTrace(p);
  }
  
  public void printStackTrace()
  {
    if (nestedError != null) {
      nestedError.printStackTrace();
    }
    super.printStackTrace();
  }
}

/* Location:
 * Qualified Name:     net.winstone.WinstoneException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

class WinstoneResourceBundle$WinstoneResourceBundleHolder
{
  private static WinstoneResourceBundle bundle = new WinstoneResourceBundle("net.winstone.winstone-message");
}

/* Location:
 * Qualified Name:     net.winstone.WinstoneResourceBundle.WinstoneResourceBundleHolder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import net.winstone.util.MapLoader;
import net.winstone.util.StringUtils;

public class WinstoneResourceBundle
  implements Iterable<String>
{
  protected final Map<String, String> resources;
  
  private static class WinstoneResourceBundleHolder
  {
    private static WinstoneResourceBundle bundle = new WinstoneResourceBundle("net.winstone.winstone-message");
  }
  
  public static WinstoneResourceBundle getInstance()
  {
    return WinstoneResourceBundleHolder.bundle;
  }
  
  public WinstoneResourceBundle(String baseName)
  {
    this(ResourceBundle.getBundle(baseName));
  }
  
  public WinstoneResourceBundle(String baseName, Locale locale)
  {
    this(ResourceBundle.getBundle(baseName, locale));
  }
  
  public WinstoneResourceBundle(String baseName, Locale locale, ClassLoader classLoader)
  {
    this(ResourceBundle.getBundle(baseName, locale, classLoader));
  }
  
  public WinstoneResourceBundle(ResourceBundle resourceBundle)
  {
    resources = MapLoader.load(resourceBundle);
  }
  
  public Iterator<String> iterator()
  {
    return resources.keySet().iterator();
  }
  
  @Deprecated
  public Iterable<String> getKeys()
  {
    return resources.keySet();
  }
  
  public String getString(String key)
  {
    return (String)resources.get(key);
  }
  
  public String getString(String key, String... parameters)
  {
    return StringUtils.replaceToken((String)resources.get(key), parameters);
  }
}

/* Location:
 * Qualified Name:     net.winstone.WinstoneResourceBundle
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
1 2 3 4 5 6 7 8 9 10 11 12 13 14

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-2019. Infinite Loop Ltd