commons-cli-1.0

16:34:38.185 INFO  jd.cli.Main - Decompiling commons-cli-1.0.jar
package org.apache.commons.cli;

public class AlreadySelectedException
  extends ParseException
{
  public AlreadySelectedException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.AlreadySelectedException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

public class ParseException
  extends Exception
{
  public ParseException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.ParseException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class CommandLine
{
  private List args = new LinkedList();
  private Map options = new HashMap();
  private Map hashcodeMap = new HashMap();
  private Option[] optionsArray;
  
  public boolean hasOption(String opt)
  {
    return options.containsKey(opt);
  }
  
  public boolean hasOption(char opt)
  {
    return hasOption(String.valueOf(opt));
  }
  
  public Object getOptionObject(String opt)
  {
    String res = getOptionValue(opt);
    
    Object type = ((Option)((List)options.get(opt)).iterator().next()).getType();
    return res == null ? null : TypeHandler.createValue(res, type);
  }
  
  public Object getOptionObject(char opt)
  {
    return getOptionObject(String.valueOf(opt));
  }
  
  public String getOptionValue(String opt)
  {
    String[] values = getOptionValues(opt);
    return values == null ? null : values[0];
  }
  
  public String getOptionValue(char opt)
  {
    return getOptionValue(String.valueOf(opt));
  }
  
  public String[] getOptionValues(String opt)
  {
    List values = new ArrayList();
    if (options.containsKey(opt))
    {
      List opts = (List)options.get(opt);
      Iterator iter = opts.iterator();
      while (iter.hasNext())
      {
        Option optt = (Option)iter.next();
        values.addAll(optt.getValuesList());
      }
    }
    return values.size() == 0 ? null : (String[])values.toArray(new String[0]);
  }
  
  public String[] getOptionValues(char opt)
  {
    return getOptionValues(String.valueOf(opt));
  }
  
  public String getOptionValue(String opt, String defaultValue)
  {
    String answer = getOptionValue(opt);
    return answer != null ? answer : defaultValue;
  }
  
  public String getOptionValue(char opt, String defaultValue)
  {
    return getOptionValue(String.valueOf(opt), defaultValue);
  }
  
  public String[] getArgs()
  {
    String[] answer = new String[args.size()];
    args.toArray(answer);
    return answer;
  }
  
  public List getArgList()
  {
    return args;
  }
  
  void addArg(String arg)
  {
    args.add(arg);
  }
  
  void addOption(Option opt)
  {
    hashcodeMap.put(new Integer(opt.hashCode()), opt);
    
    String key = opt.getOpt();
    if (" ".equals(key)) {
      key = opt.getLongOpt();
    }
    if (options.get(key) != null)
    {
      ((List)options.get(key)).add(opt);
    }
    else
    {
      options.put(key, new ArrayList());
      ((List)options.get(key)).add(opt);
    }
  }
  
  public Iterator iterator()
  {
    return hashcodeMap.values().iterator();
  }
  
  public Option[] getOptions()
  {
    Collection processed = hashcodeMap.values();
    
    optionsArray = new Option[processed.size()];
    
    return (Option[])processed.toArray(optionsArray);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.CommandLine
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.ArrayList;
import java.util.List;

public class Option
  implements Cloneable
{
  public static final int UNINITIALIZED = -1;
  public static final int UNLIMITED_VALUES = -2;
  private String opt;
  private String longOpt;
  private boolean hasArg;
  private String argName;
  private String description;
  private boolean required;
  private boolean optionalArg;
  private int numberOfArgs = -1;
  private Object type;
  private ArrayList values = new ArrayList();
  private char id;
  private char valuesep;
  
  private void validateOption(String opt)
    throws IllegalArgumentException
  {
    if (opt == null) {
      throw new IllegalArgumentException("opt is null");
    }
    if (opt.length() == 1)
    {
      char ch = opt.charAt(0);
      if (!isValidOpt(ch)) {
        throw new IllegalArgumentException("illegal option value '" + ch + "'");
      }
      id = ch;
    }
    else
    {
      char[] chars = opt.toCharArray();
      for (int i = 0; i < chars.length; i++) {
        if (!isValidChar(chars[i])) {
          throw new IllegalArgumentException("opt contains illegal character value '" + chars[i] + "'");
        }
      }
    }
  }
  
  private boolean isValidOpt(char c)
  {
    return (isValidChar(c)) || (c == ' ') || (c == '?') || (c == '@');
  }
  
  private boolean isValidChar(char c)
  {
    return Character.isJavaIdentifierPart(c);
  }
  
  public int getId()
  {
    return id;
  }
  
  public Option(String opt, String description)
    throws IllegalArgumentException
  {
    this(opt, null, false, description);
  }
  
  public Option(String opt, boolean hasArg, String description)
    throws IllegalArgumentException
  {
    this(opt, null, hasArg, description);
  }
  
  public Option(String opt, String longOpt, boolean hasArg, String description)
    throws IllegalArgumentException
  {
    validateOption(opt);
    
    this.opt = opt;
    this.longOpt = longOpt;
    if (hasArg) {
      numberOfArgs = 1;
    }
    this.hasArg = hasArg;
    this.description = description;
  }
  
  public String getOpt()
  {
    return opt;
  }
  
  public Object getType()
  {
    return type;
  }
  
  public void setType(Object type)
  {
    this.type = type;
  }
  
  public String getLongOpt()
  {
    return longOpt;
  }
  
  public void setLongOpt(String longOpt)
  {
    this.longOpt = longOpt;
  }
  
  public void setOptionalArg(boolean optionalArg)
  {
    this.optionalArg = optionalArg;
  }
  
  public boolean hasOptionalArg()
  {
    return optionalArg;
  }
  
  public boolean hasLongOpt()
  {
    return longOpt != null;
  }
  
  public boolean hasArg()
  {
    return (numberOfArgs > 0) || (numberOfArgs == -2);
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public boolean isRequired()
  {
    return required;
  }
  
  public void setRequired(boolean required)
  {
    this.required = required;
  }
  
  public void setArgName(String argName)
  {
    this.argName = argName;
  }
  
  public String getArgName()
  {
    return argName;
  }
  
  public boolean hasArgName()
  {
    return (argName != null) && (argName.length() > 0);
  }
  
  public boolean hasArgs()
  {
    return (numberOfArgs > 1) || (numberOfArgs == -2);
  }
  
  public void setArgs(int num)
  {
    numberOfArgs = num;
  }
  
  public void setValueSeparator(char sep)
  {
    valuesep = sep;
  }
  
  public char getValueSeparator()
  {
    return valuesep;
  }
  
  public int getArgs()
  {
    return numberOfArgs;
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer().append("[ option: ");
    
    buf.append(opt);
    if (longOpt != null) {
      buf.append(" ").append(longOpt);
    }
    buf.append(" ");
    if (hasArg) {
      buf.append("+ARG");
    }
    buf.append(" :: ").append(description);
    if (type != null) {
      buf.append(" :: ").append(type);
    }
    buf.append(" ]");
    return buf.toString();
  }
  
  public boolean addValue(String value)
  {
    switch (numberOfArgs)
    {
    case -1: 
      return false;
    case -2: 
      if (getValueSeparator() > 0)
      {
        int index = 0;
        while ((index = value.indexOf(getValueSeparator())) != -1)
        {
          values.add(value.substring(0, index));
          value = value.substring(index + 1);
        }
      }
      values.add(value);
      return true;
    }
    if (getValueSeparator() > 0)
    {
      int index = 0;
      while ((index = value.indexOf(getValueSeparator())) != -1)
      {
        if (values.size() > numberOfArgs - 1) {
          return false;
        }
        values.add(value.substring(0, index));
        value = value.substring(index + 1);
      }
    }
    if (values.size() > numberOfArgs - 1) {
      return false;
    }
    values.add(value);
    return true;
  }
  
  public String getValue()
  {
    return values.size() == 0 ? null : (String)values.get(0);
  }
  
  public String getValue(int index)
    throws IndexOutOfBoundsException
  {
    return values.size() == 0 ? null : (String)values.get(index);
  }
  
  public String getValue(String defaultValue)
  {
    String value = getValue();
    return value != null ? value : defaultValue;
  }
  
  public String[] getValues()
  {
    return values.size() == 0 ? null : (String[])values.toArray(new String[0]);
  }
  
  public List getValuesList()
  {
    return values;
  }
  
  public Object clone()
  {
    Option option = new Option(getOpt(), getDescription());
    option.setArgs(getArgs());
    option.setOptionalArg(hasOptionalArg());
    option.setRequired(isRequired());
    option.setLongOpt(getLongOpt());
    option.setType(getType());
    option.setValueSeparator(getValueSeparator());
    return option;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.Option
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

public abstract interface CommandLineParser
{
  public abstract CommandLine parse(Options paramOptions, String[] paramArrayOfString)
    throws ParseException;
  
  public abstract CommandLine parse(Options paramOptions, String[] paramArrayOfString, boolean paramBoolean)
    throws ParseException;
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.CommandLineParser
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Options
{
  private Map shortOpts = new HashMap();
  private Map longOpts = new HashMap();
  private List requiredOpts = new ArrayList();
  private Map optionGroups = new HashMap();
  
  public Options addOptionGroup(OptionGroup group)
  {
    Iterator options = group.getOptions().iterator();
    if (group.isRequired()) {
      requiredOpts.add(group);
    }
    while (options.hasNext())
    {
      Option option = (Option)options.next();
      
      option.setRequired(false);
      addOption(option);
      
      optionGroups.put(option.getOpt(), group);
    }
    return this;
  }
  
  public Options addOption(String opt, boolean hasArg, String description)
  {
    addOption(opt, null, hasArg, description);
    return this;
  }
  
  public Options addOption(String opt, String longOpt, boolean hasArg, String description)
  {
    addOption(new Option(opt, longOpt, hasArg, description));
    return this;
  }
  
  public Options addOption(Option opt)
  {
    String shortOpt = "-" + opt.getOpt();
    if (opt.hasLongOpt()) {
      longOpts.put("--" + opt.getLongOpt(), opt);
    }
    if (opt.isRequired()) {
      requiredOpts.add(shortOpt);
    }
    shortOpts.put(shortOpt, opt);
    
    return this;
  }
  
  public Collection getOptions()
  {
    List opts = new ArrayList(shortOpts.values());
    
    Iterator iter = longOpts.values().iterator();
    while (iter.hasNext())
    {
      Object item = iter.next();
      if (!opts.contains(item)) {
        opts.add(item);
      }
    }
    return Collections.unmodifiableCollection(opts);
  }
  
  List helpOptions()
  {
    return new ArrayList(shortOpts.values());
  }
  
  public List getRequiredOptions()
  {
    return requiredOpts;
  }
  
  public Option getOption(String opt)
  {
    Option option = null;
    if (opt.length() == 1) {
      option = (Option)shortOpts.get("-" + opt);
    } else if (opt.startsWith("--")) {
      option = (Option)longOpts.get(opt);
    } else {
      option = (Option)shortOpts.get(opt);
    }
    return option == null ? null : (Option)option.clone();
  }
  
  public boolean hasOption(String opt)
  {
    if (opt.length() == 1) {
      return shortOpts.containsKey("-" + opt);
    }
    if (opt.startsWith("--")) {
      return longOpts.containsKey(opt);
    }
    return shortOpts.containsKey(opt);
  }
  
  public OptionGroup getOptionGroup(Option opt)
  {
    return (OptionGroup)optionGroups.get(opt.getOpt());
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    
    buf.append("[ Options: [ short ");
    buf.append(shortOpts.toString());
    buf.append(" ] [ long ");
    buf.append(longOpts);
    buf.append(" ]");
    
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.Options
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

public class OptionGroup
{
  private HashMap optionMap = new HashMap();
  private String selected;
  private boolean required;
  
  public OptionGroup addOption(Option opt)
  {
    optionMap.put("-" + opt.getOpt(), opt);
    return this;
  }
  
  public Collection getNames()
  {
    return optionMap.keySet();
  }
  
  public Collection getOptions()
  {
    return optionMap.values();
  }
  
  public void setSelected(Option opt)
    throws AlreadySelectedException
  {
    if ((selected == null) || (selected.equals(opt.getOpt()))) {
      selected = opt.getOpt();
    } else {
      throw new AlreadySelectedException("an option from this group has already been selected: '" + selected + "'");
    }
  }
  
  public String getSelected()
  {
    return selected;
  }
  
  public void setRequired(boolean required)
  {
    this.required = required;
  }
  
  public boolean isRequired()
  {
    return required;
  }
  
  public String toString()
  {
    StringBuffer buff = new StringBuffer();
    
    Iterator iter = getOptions().iterator();
    
    buff.append("[");
    while (iter.hasNext())
    {
      Option option = (Option)iter.next();
      
      buff.append("-");
      buff.append(option.getOpt());
      buff.append(" ");
      buff.append(option.getDescription());
      if (iter.hasNext()) {
        buff.append(", ");
      }
    }
    buff.append("]");
    
    return buff.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.OptionGroup
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public abstract class Parser
  implements CommandLineParser
{
  private CommandLine cmd;
  private Options options;
  private List requiredOptions;
  
  protected abstract String[] flatten(Options paramOptions, String[] paramArrayOfString, boolean paramBoolean);
  
  public CommandLine parse(Options options, String[] arguments)
    throws ParseException
  {
    return parse(options, arguments, false);
  }
  
  public CommandLine parse(Options opts, String[] arguments, boolean stopAtNonOption)
    throws ParseException
  {
    options = opts;
    requiredOptions = options.getRequiredOptions();
    cmd = new CommandLine();
    
    boolean eatTheRest = false;
    
    List tokenList = Arrays.asList(flatten(opts, arguments, stopAtNonOption));
    ListIterator iterator = tokenList.listIterator();
    while (iterator.hasNext())
    {
      String t = (String)iterator.next();
      if ("--".equals(t))
      {
        eatTheRest = true;
      }
      else if ("-".equals(t))
      {
        if (stopAtNonOption) {
          eatTheRest = true;
        } else {
          cmd.addArg(t);
        }
      }
      else if (t.startsWith("-"))
      {
        if ((stopAtNonOption) && (!options.hasOption(t)))
        {
          eatTheRest = true;
          cmd.addArg(t);
        }
        else
        {
          processOption(t, iterator);
        }
      }
      else
      {
        cmd.addArg(t);
        if (stopAtNonOption) {
          eatTheRest = true;
        }
      }
      if (eatTheRest) {
        while (iterator.hasNext())
        {
          String str = (String)iterator.next();
          if (!"--".equals(str)) {
            cmd.addArg(str);
          }
        }
      }
    }
    checkRequiredOptions();
    return cmd;
  }
  
  private void checkRequiredOptions()
    throws MissingOptionException
  {
    if (requiredOptions.size() > 0)
    {
      Iterator iter = requiredOptions.iterator();
      StringBuffer buff = new StringBuffer();
      while (iter.hasNext()) {
        buff.append(iter.next());
      }
      throw new MissingOptionException(buff.toString());
    }
  }
  
  public void processArgs(Option opt, ListIterator iter)
    throws ParseException
  {
    while (iter.hasNext())
    {
      String var = (String)iter.next();
      if (options.hasOption(var))
      {
        iter.previous();
        break;
      }
      if (!opt.addValue(var))
      {
        iter.previous();
        break;
      }
    }
    if ((opt.getValues() == null) && (!opt.hasOptionalArg())) {
      throw new MissingArgumentException("no argument for:" + opt.getOpt());
    }
  }
  
  private void processOption(String arg, ListIterator iter)
    throws ParseException
  {
    Option opt = null;
    
    boolean hasOption = options.hasOption(arg);
    if (!hasOption) {
      throw new UnrecognizedOptionException("Unrecognized option: " + arg);
    }
    opt = options.getOption(arg);
    if (opt.isRequired()) {
      requiredOptions.remove("-" + opt.getOpt());
    }
    if (options.getOptionGroup(opt) != null)
    {
      OptionGroup group = options.getOptionGroup(opt);
      if (group.isRequired()) {
        requiredOptions.remove(group);
      }
      group.setSelected(opt);
    }
    if (opt.hasArg()) {
      processArgs(opt, iter);
    }
    cmd.addOption(opt);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.Parser
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

public class MissingOptionException
  extends ParseException
{
  public MissingOptionException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.MissingOptionException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.ArrayList;

public class GnuParser
  extends Parser
{
  private ArrayList tokens = new ArrayList();
  
  private void init()
  {
    tokens.clear();
  }
  
  protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption)
  {
    init();
    boolean eatTheRest = false;
    Option currentOption = null;
    for (int i = 0; i < arguments.length; i++)
    {
      if ("--".equals(arguments[i]))
      {
        eatTheRest = true;
        tokens.add("--");
      }
      else if ("-".equals(arguments[i]))
      {
        tokens.add("-");
      }
      else if (arguments[i].startsWith("-"))
      {
        Option option = options.getOption(arguments[i]);
        if (option == null)
        {
          Option specialOption = options.getOption(arguments[i].substring(0, 2));
          if (specialOption != null)
          {
            tokens.add(arguments[i].substring(0, 2));
            tokens.add(arguments[i].substring(2));
          }
          else if (stopAtNonOption)
          {
            eatTheRest = true;
            tokens.add(arguments[i]);
          }
          else
          {
            tokens.add(arguments[i]);
          }
        }
        else
        {
          currentOption = option;
          
          Option specialOption = options.getOption(arguments[i].substring(0, 2));
          if ((specialOption != null) && (option == null))
          {
            tokens.add(arguments[i].substring(0, 2));
            tokens.add(arguments[i].substring(2));
          }
          else if ((currentOption != null) && (currentOption.hasArg()))
          {
            if (currentOption.hasArg())
            {
              tokens.add(arguments[i]);
              currentOption = null;
            }
            else if (currentOption.hasArgs())
            {
              tokens.add(arguments[i]);
            }
            else if (stopAtNonOption)
            {
              eatTheRest = true;
              tokens.add("--");
              tokens.add(arguments[i]);
            }
            else
            {
              tokens.add(arguments[i]);
            }
          }
          else if (currentOption != null)
          {
            tokens.add(arguments[i]);
          }
          else if (stopAtNonOption)
          {
            eatTheRest = true;
            tokens.add("--");
            tokens.add(arguments[i]);
          }
          else
          {
            tokens.add(arguments[i]);
          }
        }
      }
      else
      {
        tokens.add(arguments[i]);
      }
      if (eatTheRest) {
        for (i++; i < arguments.length; i++) {
          tokens.add(arguments[i]);
        }
      }
    }
    return (String[])tokens.toArray(new String[0]);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.GnuParser
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.Comparator;

class HelpFormatter$StringBufferComparator
  implements Comparator
{
  HelpFormatter$StringBufferComparator(HelpFormatter.1 x0)
  {
    this();
  }
  
  public int compare(Object o1, Object o2)
  {
    String str1 = stripPrefix(o1.toString());
    String str2 = stripPrefix(o2.toString());
    return str1.compareTo(str2);
  }
  
  private String stripPrefix(String strOption)
  {
    int iStartIndex = strOption.lastIndexOf('-');
    if (iStartIndex == -1) {
      iStartIndex = 0;
    }
    return strOption.substring(iStartIndex);
  }
  
  private HelpFormatter$StringBufferComparator() {}
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.HelpFormatter.StringBufferComparator
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

class HelpFormatter$1 {}

/* Location:
 * Qualified Name:     org.apache.commons.cli.HelpFormatter.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class HelpFormatter
{
  public static final int DEFAULT_WIDTH = 74;
  public static final int DEFAULT_LEFT_PAD = 1;
  public static final int DEFAULT_DESC_PAD = 3;
  public static final String DEFAULT_SYNTAX_PREFIX = "usage: ";
  public static final String DEFAULT_OPT_PREFIX = "-";
  public static final String DEFAULT_LONG_OPT_PREFIX = "--";
  public static final String DEFAULT_ARG_NAME = "arg";
  public int defaultWidth;
  public int defaultLeftPad;
  public int defaultDescPad;
  public String defaultSyntaxPrefix;
  public String defaultNewLine;
  public String defaultOptPrefix;
  public String defaultLongOptPrefix;
  public String defaultArgName;
  
  public HelpFormatter()
  {
    defaultWidth = 74;
    defaultLeftPad = 1;
    defaultDescPad = 3;
    defaultSyntaxPrefix = "usage: ";
    defaultNewLine = System.getProperty("line.separator");
    defaultOptPrefix = "-";
    defaultLongOptPrefix = "--";
    defaultArgName = "arg";
  }
  
  public void printHelp(String cmdLineSyntax, Options options)
  {
    printHelp(defaultWidth, cmdLineSyntax, null, options, null, false);
  }
  
  public void printHelp(String cmdLineSyntax, Options options, boolean autoUsage)
  {
    printHelp(defaultWidth, cmdLineSyntax, null, options, null, autoUsage);
  }
  
  public void printHelp(String cmdLineSyntax, String header, Options options, String footer)
  {
    printHelp(cmdLineSyntax, header, options, footer, false);
  }
  
  public void printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)
  {
    printHelp(defaultWidth, cmdLineSyntax, header, options, footer, autoUsage);
  }
  
  public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer)
  {
    printHelp(width, cmdLineSyntax, header, options, footer, false);
  }
  
  public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)
  {
    PrintWriter pw = new PrintWriter(System.out);
    printHelp(pw, width, cmdLineSyntax, header, options, defaultLeftPad, defaultDescPad, footer, autoUsage);
    
    pw.flush();
  }
  
  public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer)
    throws IllegalArgumentException
  {
    printHelp(pw, width, cmdLineSyntax, header, options, leftPad, descPad, footer, false);
  }
  
  public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer, boolean autoUsage)
    throws IllegalArgumentException
  {
    if ((cmdLineSyntax == null) || (cmdLineSyntax.length() == 0)) {
      throw new IllegalArgumentException("cmdLineSyntax not provided");
    }
    if (autoUsage) {
      printUsage(pw, width, cmdLineSyntax, options);
    } else {
      printUsage(pw, width, cmdLineSyntax);
    }
    if ((header != null) && (header.trim().length() > 0)) {
      printWrapped(pw, width, header);
    }
    printOptions(pw, width, options, leftPad, descPad);
    if ((footer != null) && (footer.trim().length() > 0)) {
      printWrapped(pw, width, footer);
    }
  }
  
  public void printUsage(PrintWriter pw, int width, String app, Options options)
  {
    StringBuffer buff = new StringBuffer(defaultSyntaxPrefix).append(app).append(" ");
    
    ArrayList list = new ArrayList();
    for (Iterator i = options.getOptions().iterator(); i.hasNext();)
    {
      Option option = (Option)i.next();
      
      OptionGroup group = options.getOptionGroup(option);
      if ((group != null) && (!list.contains(group)))
      {
        list.add(group);
        
        Collection names = group.getNames();
        
        buff.append("[");
        for (Iterator iter = names.iterator(); iter.hasNext();)
        {
          buff.append(iter.next());
          if (iter.hasNext()) {
            buff.append(" | ");
          }
        }
        buff.append("]");
      }
      else
      {
        if (!option.isRequired()) {
          buff.append("[");
        }
        if (!" ".equals(option.getOpt())) {
          buff.append("-").append(option.getOpt());
        } else {
          buff.append("--").append(option.getLongOpt());
        }
        if (option.hasArg()) {
          buff.append(" ");
        }
        if (option.hasArg()) {
          buff.append(option.getArgName());
        }
        if (!option.isRequired()) {
          buff.append("]");
        }
        buff.append(" ");
      }
    }
    printWrapped(pw, width, buff.toString().indexOf(' ') + 1, buff.toString());
  }
  
  public void printUsage(PrintWriter pw, int width, String cmdLineSyntax)
  {
    int argPos = cmdLineSyntax.indexOf(' ') + 1;
    printWrapped(pw, width, defaultSyntaxPrefix.length() + argPos, defaultSyntaxPrefix + cmdLineSyntax);
  }
  
  public void printOptions(PrintWriter pw, int width, Options options, int leftPad, int descPad)
  {
    StringBuffer sb = new StringBuffer();
    renderOptions(sb, width, options, leftPad, descPad);
    pw.println(sb.toString());
  }
  
  public void printWrapped(PrintWriter pw, int width, String text)
  {
    printWrapped(pw, width, 0, text);
  }
  
  public void printWrapped(PrintWriter pw, int width, int nextLineTabStop, String text)
  {
    StringBuffer sb = new StringBuffer(text.length());
    renderWrappedText(sb, width, nextLineTabStop, text);
    pw.println(sb.toString());
  }
  
  protected StringBuffer renderOptions(StringBuffer sb, int width, Options options, int leftPad, int descPad)
  {
    String lpad = createPadding(leftPad);
    String dpad = createPadding(descPad);
    
    int max = 0;
    
    List prefixList = new ArrayList();
    
    List optList = options.helpOptions();
    Collections.sort(optList, new StringBufferComparator(null));
    Option option;
    StringBuffer optBuf;
    for (Iterator i = optList.iterator(); i.hasNext();)
    {
      option = (Option)i.next();
      optBuf = new StringBuffer(8);
      if (option.getOpt().equals(" "))
      {
        optBuf.append(lpad).append("   " + defaultLongOptPrefix).append(option.getLongOpt());
      }
      else
      {
        optBuf.append(lpad).append(defaultOptPrefix).append(option.getOpt());
        if (option.hasLongOpt()) {
          optBuf.append(',').append(defaultLongOptPrefix).append(option.getLongOpt());
        }
      }
      if (option.hasArg()) {
        if (option.hasArgName()) {
          optBuf.append(" <").append(option.getArgName()).append('>');
        } else {
          optBuf.append(' ');
        }
      }
      prefixList.add(optBuf);
      max = optBuf.length() > max ? optBuf.length() : max;
    }
    int x = 0;
    for (Iterator i = optList.iterator(); i.hasNext();)
    {
      option = (Option)i.next();
      optBuf = new StringBuffer(prefixList.get(x++).toString());
      if (optBuf.length() < max) {
        optBuf.append(createPadding(max - optBuf.length()));
      }
      optBuf.append(dpad);
      
      int nextLineTabStop = max + descPad;
      renderWrappedText(sb, width, nextLineTabStop, option.getDescription());
      if (i.hasNext()) {
        sb.append(defaultNewLine);
      }
    }
    return sb;
  }
  
  protected StringBuffer renderWrappedText(StringBuffer sb, int width, int nextLineTabStop, String text)
  {
    int pos = findWrapPos(text, width, 0);
    if (pos == -1)
    {
      sb.append(rtrim(text));
      return sb;
    }
    sb.append(rtrim(text.substring(0, pos))).append(defaultNewLine);
    
    String padding = createPadding(nextLineTabStop);
    for (;;)
    {
      text = padding + text.substring(pos).trim();
      pos = findWrapPos(text, width, nextLineTabStop);
      if (pos == -1)
      {
        sb.append(text);
        return sb;
      }
      sb.append(rtrim(text.substring(0, pos))).append(defaultNewLine);
    }
  }
  
  protected int findWrapPos(String text, int width, int startPos)
  {
    int pos = -1;
    if ((((pos = text.indexOf('\n', startPos)) != -1) && (pos <= width)) || (((pos = text.indexOf('\t', startPos)) != -1) && (pos <= width))) {
      return pos;
    }
    if (startPos + width >= text.length()) {
      return -1;
    }
    pos = startPos + width;
    char c;
    while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ') && (c != '\n') && (c != '\r')) {
      pos--;
    }
    if (pos > startPos) {
      return pos;
    }
    pos = startPos + width;
    while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ') && (c != '\n') && (c != '\r')) {
      pos++;
    }
    return pos == text.length() ? -1 : pos;
  }
  
  protected String createPadding(int len)
  {
    StringBuffer sb = new StringBuffer(len);
    for (int i = 0; i < len; i++) {
      sb.append(' ');
    }
    return sb.toString();
  }
  
  protected String rtrim(String s)
  {
    if ((s == null) || (s.length() == 0)) {
      return s;
    }
    int pos = s.length();
    while ((pos >= 0) && (Character.isWhitespace(s.charAt(pos - 1)))) {
      pos--;
    }
    return s.substring(0, pos);
  }
  
  private static class StringBufferComparator
    implements Comparator
  {
    StringBufferComparator(HelpFormatter.1 x0)
    {
      this();
    }
    
    public int compare(Object o1, Object o2)
    {
      String str1 = stripPrefix(o1.toString());
      String str2 = stripPrefix(o2.toString());
      return str1.compareTo(str2);
    }
    
    private String stripPrefix(String strOption)
    {
      int iStartIndex = strOption.lastIndexOf('-');
      if (iStartIndex == -1) {
        iStartIndex = 0;
      }
      return strOption.substring(iStartIndex);
    }
    
    private StringBufferComparator() {}
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.HelpFormatter
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

public class MissingArgumentException
  extends ParseException
{
  public MissingArgumentException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.MissingArgumentException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Date;

public class PatternOptionBuilder
{
  public static final Class STRING_VALUE = String.class;
  public static final Class OBJECT_VALUE = Object.class;
  public static final Class NUMBER_VALUE = Number.class;
  public static final Class DATE_VALUE = Date.class;
  public static final Class CLASS_VALUE = Class.class;
  public static final Class EXISTING_FILE_VALUE = FileInputStream.class;
  public static final Class FILE_VALUE = File.class;
  public static final Class FILES_VALUE = new File[0];
  public static final Class URL_VALUE = URL.class;
  
  public static Object getValueClass(char ch)
  {
    if (ch == '@') {
      return OBJECT_VALUE;
    }
    if (ch == ':') {
      return STRING_VALUE;
    }
    if (ch == '%') {
      return NUMBER_VALUE;
    }
    if (ch == '+') {
      return CLASS_VALUE;
    }
    if (ch == '#') {
      return DATE_VALUE;
    }
    if (ch == '<') {
      return EXISTING_FILE_VALUE;
    }
    if (ch == '>') {
      return FILE_VALUE;
    }
    if (ch == '*') {
      return FILES_VALUE;
    }
    if (ch == '/') {
      return URL_VALUE;
    }
    return null;
  }
  
  public static boolean isValueCode(char ch)
  {
    if ((ch != '@') && (ch != ':') && (ch != '%') && (ch != '+') && (ch != '#') && (ch != '<') && (ch != '>') && (ch != '*') && (ch != '/')) {
      return false;
    }
    return true;
  }
  
  public static Options parsePattern(String pattern)
  {
    int sz = pattern.length();
    
    char opt = ' ';
    char ch = ' ';
    boolean required = false;
    Object type = null;
    
    Options options = new Options();
    for (int i = 0; i < sz; i++)
    {
      ch = pattern.charAt(i);
      if (!isValueCode(ch))
      {
        if (opt != ' ')
        {
          OptionBuilder.hasArg(type != null);OptionBuilder.isRequired(required);OptionBuilder.withType(type);options.addOption(OptionBuilder.create(opt));
          
          required = false;
          type = null;
          opt = ' ';
        }
        opt = ch;
      }
      else if (ch == '!')
      {
        required = true;
      }
      else
      {
        type = getValueClass(ch);
      }
    }
    if (opt != ' ')
    {
      OptionBuilder.hasArg(type != null);OptionBuilder.isRequired(required);OptionBuilder.withType(type);options.addOption(OptionBuilder.create(opt));
    }
    return options;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.PatternOptionBuilder
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class PosixParser
  extends Parser
{
  private ArrayList tokens = new ArrayList();
  private boolean eatTheRest;
  private Option currentOption;
  private Options options;
  
  private void init()
  {
    eatTheRest = false;
    tokens.clear();
    currentOption = null;
  }
  
  protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption)
  {
    init();
    this.options = options;
    
    Iterator iter = Arrays.asList(arguments).iterator();
    String token = null;
    while (iter.hasNext())
    {
      token = (String)iter.next();
      if (token.startsWith("--"))
      {
        if (token.indexOf('=') != -1)
        {
          tokens.add(token.substring(0, token.indexOf('=')));
          tokens.add(token.substring(token.indexOf('=') + 1, token.length()));
        }
        else
        {
          tokens.add(token);
        }
      }
      else if ("-".equals(token))
      {
        processSingleHyphen(token);
      }
      else if (token.startsWith("-"))
      {
        int tokenLength = token.length();
        if (tokenLength == 2) {
          processOptionToken(token, stopAtNonOption);
        } else {
          burstToken(token, stopAtNonOption);
        }
      }
      else if (stopAtNonOption)
      {
        process(token);
      }
      else
      {
        tokens.add(token);
      }
      gobble(iter);
    }
    return (String[])tokens.toArray(new String[0]);
  }
  
  private void gobble(Iterator iter)
  {
    if (eatTheRest) {
      while (iter.hasNext()) {
        tokens.add(iter.next());
      }
    }
  }
  
  private void process(String value)
  {
    if ((currentOption != null) && (currentOption.hasArg()))
    {
      if (currentOption.hasArg())
      {
        tokens.add(value);
        currentOption = null;
      }
      else if (currentOption.hasArgs())
      {
        tokens.add(value);
      }
    }
    else
    {
      eatTheRest = true;
      tokens.add("--");
      tokens.add(value);
    }
  }
  
  private void processSingleHyphen(String hyphen)
  {
    tokens.add(hyphen);
  }
  
  private void processOptionToken(String token, boolean stopAtNonOption)
  {
    if (options.hasOption(token))
    {
      currentOption = options.getOption(token);
      tokens.add(token);
    }
    else if (stopAtNonOption)
    {
      eatTheRest = true;
    }
  }
  
  protected void burstToken(String token, boolean stopAtNonOption)
  {
    int tokenLength = token.length();
    for (int i = 1; i < tokenLength; i++)
    {
      String ch = String.valueOf(token.charAt(i));
      boolean hasOption = options.hasOption(ch);
      if (hasOption)
      {
        tokens.add("-" + ch);
        currentOption = options.getOption(ch);
        if ((currentOption.hasArg()) && (token.length() != i + 1))
        {
          tokens.add(token.substring(i + 1));
          break;
        }
      }
      else if (stopAtNonOption)
      {
        process(token.substring(i));
      }
      else
      {
        tokens.add("-" + ch);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.cli.PosixParser
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.cli;

import java.io.File;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import org.apache.commons.lang.NumberUtils;

public class TypeHandler
{
  public static Object createValue(String str, Object obj)
  {
    return createValue(str, (Class)obj);
  }
  
  public static Object createValue(String str, Class clazz)
  {
    if (PatternOptionBuilder.STRING_VALUE == clazz) {
      return str;
    }
    if (PatternOptionBuilder.OBJECT_VALUE == clazz) {
      return createObject(str);
    }
    if (PatternOptionBuilder.NUMBER_VALUE == clazz) {
      return createNumber(str);
    }
    if (PatternOptionBuilder.DATE_VALUE == clazz) {
      return createDate(str);
    }
    if (PatternOptionBuilder.CLASS_VALUE == clazz) {
      return createClass(str);
    }
    if (PatternOptionBuilder.FILE_VALUE == clazz) {
      return createFile(str);
    }
    if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz) {
      return creat
1 2

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