dlr         01/08/08 00:35:33

  Modified:    src/adapter/org/apache/turbine/util BufferCache.java
                        SequencedHashtable.java StringStackBuffer.java
                        StringUtils.java TurbineException.java
                        TurbineRuntimeException.java
               src/java/org/apache/turbine TurbineException.java
                        TurbineRuntimeException.java
  Added:       lib      commons-util-0.1-dev.jar
  Log:
  Integrated aspiring commons-util JAR.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine/lib/commons-util-0.1-dev.jar
  
        <<Binary file>>
  
  
  1.2       +7 -102    
jakarta-turbine/src/adapter/org/apache/turbine/util/BufferCache.java
  
  Index: BufferCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/BufferCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- BufferCache.java  2001/07/10 00:40:02     1.1
  +++ BufferCache.java  2001/08/08 07:35:33     1.2
  @@ -60,29 +60,20 @@
    * A resizably fixed length object cache implementing the LRU
    * algorithm.  Convenient for buffering recently used objects.
    *
  + * @see org.apache.commons.util.BufferCache
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Leonard Richardson</a>
  - * @version $Id: BufferCache.java,v 1.1 2001/07/10 00:40:02 jvanzyl Exp $
  + * @version $Id: BufferCache.java,v 1.2 2001/08/08 07:35:33 dlr Exp $
  + *
  + * @deprecated Use org.apache.commons.util.BufferCache instead.
    */
  -public class BufferCache extends SequencedHashtable
  +public class BufferCache extends org.apache.commons.util.BufferCache
   {
       /**
  -     * The default maximum cache size.
  -     */
  -    private static final int DEFAULT_MAX_SIZE = 35;
  -
  -    /**
  -     * The size of the cache.  The newest elements in the sequence are kept
  -     * toward the end.
  -     */
  -    private int maxSize;
  -
  -    /**
        * Creates a new instance with default storage buffer pre-allocated.
        */
  -    public BufferCache ()
  +    public BufferCache()
       {
  -        this(DEFAULT_MAX_SIZE);
       }
   
       /**
  @@ -91,94 +82,8 @@
        * @param maxSize The maximum size of the cache (must be greater
        *                than zero).
        */
  -    public BufferCache (int maxSize)
  +    public BufferCache(int maxSize)
       {
           super(maxSize);
  -        assertReasonableMaxSize(maxSize);
  -        this.maxSize = maxSize;
  -    }
  -
  -    /**
  -     * Returns the current maximum size of the storage buffer.
  -     *
  -     * @return The current maximum size of the storage buffer.
  -     */
  -    public int getMaxSize()
  -    {
  -        return maxSize;
  -    }
  -
  -    /**
  -     * Changes the maximum size of the storage buffer.
  -     *
  -     * @param newMaxSize The new maximum size of the storage buffer.
  -     */
  -    public synchronized void resize (int newMaxSize)
  -    {
  -        assertReasonableMaxSize(newMaxSize);
  -
  -        // If the cache is shrinking, we may currently be storing more
  -        // entires than will fit in a cache of the new size.  If this is
  -        // so, then remove entries until we have as many as we can hold.
  -        if (newMaxSize > maxSize)
  -        {
  -            int actualSize = keySet().size();
  -            while (actualSize > newMaxSize)
  -            {
  -                remove(ELDEST_INDEX);
  -                actualSize--;
  -            }
  -        }
  -        maxSize = newMaxSize;
  -    }
  -
  -    /**
  -     * Stores the provided key/value pair, freshening its list index if the
  -     * specified key already exists.
  -     *
  -     * @param key   The key to the provided value.
  -     * @param value The value to store.
  -     * @return      The previous value for the specified key, or
  -     *              <code>null</code> if none.
  -     */
  -    public synchronized Object put (Object key, Object value)
  -    {
  -        int size = size();
  -        if (size > 0 && size + 1 >= maxSize)
  -        {
  -            // Stay within constraints of allocated buffer by releasing the
  -            // eldest buffered object.
  -            remove(ELDEST_INDEX);
  -        }
  -        return super.put(key, value);
  -    }
  -
  -    /**
  -     * Retrieves the value associated with the provided key, freshening the
  -     * sequence of the key as well.
  -     *
  -     * @param key The key whose value to retrieve.
  -     * @return    The keyed value.
  -     */
  -    public synchronized Object get (Object key)
  -    {
  -        Object value = super.get(key);
  -        if (value != null)
  -        {
  -            freshenSequence(key, value);
  -        }
  -        return value;
  -    }
  -
  -    /**
  -     * Asserts that the specified size is greater than zero.
  -     */
  -    private static final void assertReasonableMaxSize(int maxSize)
  -    {
  -        if (maxSize <= 0)
  -        {
  -            throw new IllegalArgumentException
  -                ("BufferCache size must be 1 or greater");
  -        }
       }
   }
  
  
  
  1.2       +4 -211    
jakarta-turbine/src/adapter/org/apache/turbine/util/SequencedHashtable.java
  
  Index: SequencedHashtable.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/SequencedHashtable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- SequencedHashtable.java   2001/07/10 00:40:03     1.1
  +++ SequencedHashtable.java   2001/08/08 07:35:33     1.2
  @@ -54,14 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.Collection;
  -import java.util.Hashtable;
  -import java.util.Iterator;
  -import java.util.LinkedList;
  -import java.util.List;
  -import java.util.Map;
  -import java.util.Set;
  -
   /**
    * A {@link java.util.Hashtable} whose keys are sequenced.  The
    * sequencing of the keys allow easy access to the values in the order
  @@ -83,31 +75,17 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Henning P. Schmiedehausen</a>
  + *
  + * @deprecated Use org.apache.commons.util.SequencedHashtable instead.
    */
  -public class SequencedHashtable extends Hashtable
  +public class SequencedHashtable
  +    extends org.apache.commons.util.SequencedHashtable
   {
       /**
  -     * The index of the eldest element in the collection.
  -     */
  -    protected static final int ELDEST_INDEX = 0;
  -
  -    /**
  -     * Indicator for an unknown index.
  -     */
  -    private static final int UNKNOWN_INDEX = -1;
  -
  -    /**
  -     * The sequence used to keep track of the hash keys.  Younger objects are
  -     * kept towards the end of the list.  Does not allow duplicates.
  -     */
  -    private LinkedList keySequence;
  -
  -    /**
        * Creates a new instance with default storage.
        */
       public SequencedHashtable ()
       {
  -        keySequence = new LinkedList();
       }
   
       /**
  @@ -118,190 +96,5 @@
       public SequencedHashtable (int size)
       {
           super(size);
  -        keySequence = new LinkedList();
  -    }
  -
  -    /**
  -     * Clears all elements.
  -     */
  -    public synchronized void clear ()
  -    {
  -        super.clear();
  -        keySequence.clear();
  -    }
  -
  -    /**
  -     * Creates a shallow copy of this object, preserving the internal
  -     * structure by copying only references.  The keys, values, and
  -     * sequence are not <code>clone()</code>'d.
  -     *
  -     * @return A clone of this instance.
  -     */
  -    public synchronized Object clone ()
  -    {
  -        SequencedHashtable seqHash = (SequencedHashtable) super.clone();
  -        seqHash.keySequence = (LinkedList) keySequence.clone();
  -        return seqHash;
  -    }
  -
  -    /**
  -     * Returns the key at the specified index.
  -     */
  -    public Object get (int index)
  -    {
  -        return keySequence.get(index);
  -    }
  -
  -    /**
  -     * Returns the value at the specified index.
  -     */
  -    public Object getValue (int index)
  -    {
  -        return get(get(index));
  -    }
  -
  -    /**
  -     * Returns the index of the specified key.
  -     */
  -    public int indexOf (Object key)
  -    {
  -        return keySequence.indexOf(key);
  -    }
  -
  -    /**
  -     * Returns a key iterator.
  -     */
  -    public Iterator iterator ()
  -    {
  -        return keySequence.iterator();
  -    }
  -
  -    /**
  -     * Returns the last index of the specified key.
  -     */
  -    public int lastIndexOf (Object key)
  -    {
  -        return keySequence.lastIndexOf(key);
  -    }
  -
  -    /**
  -     * Returns the ordered sequence of keys.
  -     * 
  -     * This method is meant to be used for retrieval of Key / Value pairs
  -     * in e.g. Velocity:
  -     * <PRE>
  -     * ## $table contains a sequenced hashtable
  -     * #foreach ($key in $table.sequence())
  -     * &lt;TR&gt;
  -     * &lt;TD&gt;Key: $key&lt;/TD&gt;
  -     * &lt;/TD&gt;Value: $table.get($key)&lt;/TD&gt;
  -     * &lt;/TR&gt;
  -     * #end
  -     * </PRE>
  -     *
  -     * @return The ordered list of keys.
  -     */
  -    public List sequence()
  -    {
  -        return keySequence;
  -    }
  -
  -    /**
  -     * Stores the provided key/value pair.  Freshens the sequence of existing
  -     * elements.
  -     *
  -     * @param key   The key to the provided value.
  -     * @param value The value to store.
  -     * @return      The previous value for the specified key, or
  -     *              <code>null</code> if none.
  -     */
  -    public synchronized Object put (Object key, Object value)
  -    {
  -        Object prevValue = super.put(key, value);
  -        freshenSequence(key, prevValue);
  -        return prevValue;
  -    }
  -
  -    /**
  -     * Freshens the sequence of the element <code>value</code> if
  -     * <code>value</code> is not <code>null</code>.
  -     *
  -     * @param key   The key whose sequence to freshen.
  -     * @param value The value whose existance to check before removing the old
  -     *              key sequence.
  -     */
  -    protected void freshenSequence(Object key, Object value)
  -    {
  -        if (value != null)
  -        {
  -            // Freshening existing element's sequence.
  -            keySequence.remove(key);
  -        }
  -        keySequence.add(key);
  -    }
  -
  -    /**
  -     * Stores the provided key/value pairs.
  -     *
  -     * @param t The key/value pairs to store.
  -     */
  -    public synchronized void putAll (Map t)
  -    {
  -        Set set = t.entrySet();
  -        for (Iterator iter = set.iterator(); iter.hasNext(); )
  -        {
  -            Map.Entry e = (Map.Entry)iter.next();
  -            put(e.getKey(), e.getValue());
  -        }
  -    }
  -
  -    /**
  -     * Removes the element at the specified index.
  -     *
  -     * @param index The index of the object to remove.
  -     * @return      The previous value coressponding the <code>key</code>, or
  -     *              <code>null</code> if none existed.
  -     */
  -    public Object remove (int index)
  -    {
  -        return remove(index, null);
  -    }
  -
  -    /**
  -     * Removes the element with the specified key.
  -     *
  -     * @param key   The <code>Map</code> key of the object to remove.
  -     * @return      The previous value coressponding the <code>key</code>, or
  -     *              <code>null</code> if none existed.
  -     */
  -    public Object remove (Object key)
  -    {
  -        return remove(UNKNOWN_INDEX, key);
  -    }
  -
  -    /**
  -     * Removes the element with the specified key or index.
  -     *
  -     * @param index The index of the object to remove, or
  -     *              <code>UNKNOWN_INDEX</code> if not known.
  -     * @param key   The <code>Map</code> key of the object to remove.
  -     * @return      The previous value coressponding the <code>key</code>, or
  -     *              <code>null</code> if none existed.
  -     */
  -    private final synchronized Object remove (int index, Object key)
  -    {
  -        if (index == UNKNOWN_INDEX)
  -        {
  -            index = indexOf(key);
  -        }
  -        if (key == null)
  -        {
  -            key = get(index);
  -        }
  -        if (index != UNKNOWN_INDEX)
  -        {
  -            keySequence.remove(index);
  -        }
  -        return super.remove(key);
       }
   }
  
  
  
  1.2       +6 -185    
jakarta-turbine/src/adapter/org/apache/turbine/util/StringStackBuffer.java
  
  Index: StringStackBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/StringStackBuffer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- StringStackBuffer.java    2001/07/10 00:40:03     1.1
  +++ StringStackBuffer.java    2001/08/08 07:35:33     1.2
  @@ -54,196 +54,17 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.Iterator;
  -import java.util.Stack;
  +import org.apache.commons.util.StringStack;
   
   /**
    * This class implements a Stack for String objects.
    *
  + * @see org.apache.commons.util.StringStack
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
  - * @version $Id: StringStackBuffer.java,v 1.1 2001/07/10 00:40:03 jvanzyl Exp $
  + * @version $Id: StringStackBuffer.java,v 1.2 2001/08/08 07:35:33 dlr Exp $
  + *
  + * @deprecated Use org.apache.commons.util.StringStack instead.
    */
  -public class StringStackBuffer
  +public class StringStackBuffer extends StringStack
   {
  -    /** The stack. */
  -    private Stack stk = null;
  -
  -    /**
  -     * Constructor.
  -     */
  -    public StringStackBuffer()
  -    {
  -        stk = new Stack();
  -    }
  -
  -    /**
  -     * Adds the String to the collection if it does not already
  -     * contain it.
  -     *
  -     * @param s A String.
  -     * @return A StringStackBuffer.
  -     */
  -    public StringStackBuffer add( String s )
  -    {
  -        if ( s != null  &&  !contains(s) )
  -             stk.push(s);
  -        return this;
  -    }
  -
  -    /**
  -     * Adds all Strings in the given StringStackBuffer to the collection
  -     * (skipping those it already contains)
  -     *
  -     * @param s A StringStackBuffer.
  -     * @return A StringStackBuffer.
  -     */
  -    public StringStackBuffer addAll( StringStackBuffer s )
  -    {
  -        Iterator it = s.stk.iterator();
  -        while (it.hasNext())
  -            add((String)it.next());
  -        return this;
  -    }
  -
  -    /**
  -     * Clears the Stack.
  -     *
  -     */
  -    public void clear()
  -    {
  -        stk.clear();
  -    }
  -    
  -    /**
  -     * Does the Stack contain this String?
  -     *
  -     * @param s A String.
  -     * @return True if the Stack contains this String.
  -     */
  -    public boolean contains( String s )
  -    {
  -        return ( stk.search(s) != -1 );
  -    }
  -
  -    /**
  -     * Is the Stack empty?
  -     * @return True if the Stack is empty.
  -     */
  -    public boolean empty()
  -    {
  -        return stk.empty();
  -    }
  -
  -    /**
  -     * Get a String off the Stack at a certain position.
  -     *
  -     * @param i An int with the position.
  -     * @return A String.
  -     */
  -    public String get(int i)
  -    {
  -        return (String) stk.elementAt(i);
  -    }
  -
  -    /**
  -     * What is the size of the Stack?
  -     *
  -     * @return An int, the size of the Stack.
  -     */
  -    public int size()
  -    {
  -        return stk.size();
  -    }
  -
  -    /**
  -     * Converts the stack to a single {@link java.lang.String} with no
  -     * separator.
  -     *
  -     * @return The stack elements as a single block of text.
  -     */
  -    public String toString()
  -    {
  -        return toString("");
  -    }
  -
  -    /**
  -     * Converts the stack to a single {@link java.lang.String}.
  -     *
  -     * @param separator The text to use as glue between elements in
  -     * the stack.
  -     * @return The stack elements--glued together by
  -     * <code>separator</code>--as a single block of text.
  -     */
  -    public String toString( String separator )
  -    {
  -        String s;
  -        if ( size() > 0 )
  -        {
  -            if ( separator == null )
  -            {
  -                separator = "";
  -            }
  - 
  -            // Determine what size to pre-allocate for the buffer.
  -            int totalSize = 0;
  -            for (int i = 0; i < stk.size(); i++)
  -            {
  -                totalSize += get(i).length();
  -            }
  -            totalSize += (stk.size() - 1) * separator.length();
  -
  -            StringBuffer sb = new StringBuffer(totalSize).append( get(0) );
  -            for (int i = 1; i < stk.size(); i++)
  -            {
  -                sb.append(separator).append(get(i));
  -            }
  -            s = sb.toString();
  -        }
  -        else
  -        {
  -            s = "";
  -        }
  -        return s;
  -    }
  -
  -    /**
  -     * Compares two StringStackBuffers.  Considered equal if the toString()
  -     * methods are equal.
  -     *
  -     */
  -    public boolean equals(Object ssbuf)
  -    {
  -        boolean isEquiv = false;
  -        if ( ssbuf == null || !(ssbuf instanceof StringStackBuffer) ) 
  -        {
  -            isEquiv = false;
  -        }
  -    
  -        else if ( ssbuf == this ) 
  -        {
  -            isEquiv = true;
  -        }
  -        
  -        else if ( this.toString().equals(ssbuf.toString()) )
  -        {
  -            isEquiv = true;
  -        }
  -        
  -        return isEquiv;
  -    }
  -
  -    public String[] toStringArray()
  -    {
  -        String[] ss = new String[size()];
  -        for (int i=0; i<size(); i++) 
  -        {
  -            ss[i]=get(i);
  -        }
  -        return ss;
  -    }
   }
  -
  -
  -
  -
  -
  
  
  
  1.2       +5 -311    
jakarta-turbine/src/adapter/org/apache/turbine/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/StringUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- StringUtils.java  2001/07/10 00:40:03     1.1
  +++ StringUtils.java  2001/08/08 07:35:33     1.2
  @@ -54,324 +54,18 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.ByteArrayOutputStream;
  -import java.io.OutputStream;
  -import java.io.PrintWriter;
  -import java.util.NoSuchElementException;
  -import java.util.StringTokenizer;
  -
   /**
    * This is where common String manipulation routines should go.
    *
  + * @see org.apache.commons.util.StringUtils
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Greg Coladonato</a>
  - * @version $Id: StringUtils.java,v 1.1 2001/07/10 00:40:03 jvanzyl Exp $
  + * @version $Id: StringUtils.java,v 1.2 2001/08/08 07:35:33 dlr Exp $
  + *
  + * @deprecated Use org.apache.commons.util.StringUtils instead.
    */
   public class StringUtils
  +    extends org.apache.commons.util.StringUtils
   {
  -    /**
  -     * Deal with null strings converting them to "" instead.  It also
  -     * invokes String.trim() on the output.
  -     *
  -     * @param foo A String.
  -     * @return A String.
  -     */
  -    public static final String makeString(String foo)
  -    {
  -        return (foo == null ? "" : foo.trim());
  -    }
  -
  -    /**
  -     * Validates that the supplied string is neither <code>null</code>
  -     * nor the empty string.
  -     *
  -     * @param foo The text to check.
  -     * @return Whether valid.
  -     */
  -    public static final boolean isValid(String foo)
  -    {
  -        return (foo != null && foo.length() > 0);
  -    }
  -    
  -    /**
  -     * Determine whether a (trimmed) string is empty
  -     *
  -     * @param foo The text to check.
  -     * @return Whether empty.
  -     */
  -    public static final boolean isEmpty(String foo)
  -    {
  -        return (foo == null || foo.trim().length() == 0);
  -    }
  -
  -    /**
  -     * Returns the output of printStackTrace as a String.
  -     *
  -     * @param e The source to extract a stack trace from.
  -     * @return The extracted stack trace.
  -     */
  -    public static final String stackTrace(Throwable e)
  -    {
  -        String trace = null;
  -        try
  -        {
  -            // And show the Error Screen.
  -            ByteArrayOutputStream buf = new ByteArrayOutputStream();
  -            e.printStackTrace( new PrintWriter(buf, true) );
  -            trace = buf.toString();
  -        }
  -        catch (Exception f)
  -        {
  -            // Do nothing.
  -        }
  -        return trace;
  -    }
  -    
  -    /**
  -     * Returns the output of printStackTrace as a String.
  -     *
  -     * @param e A Throwable.
  -     * @param addPre a boolean to add HTML <pre> tags around the stacktrace
  -     * @return A String.
  -     */
  -    public static final String stackTrace(Throwable e, boolean addPre)
  -    {
  -        if (addPre)
  -        {
  -            return "<pre>" + stackTrace(e) + "</pre>";
  -        }
  -        else
  -        {
  -            return stackTrace(e);    
  -        }
  -    }
  -
  -    /**
  -     * Compares two Strings, returns true if their values are the
  -     * same.
  -     *
  -     * @param s1 The first string.
  -     * @param s2 The second string.
  -     * @return True if the values of both strings are the same.
  -     */
  -    public static boolean equals( String s1,
  -                                  String s2 )
  -    {
  -        if (s1 == null)
  -        {
  -            return (s2 == null);
  -        }
  -        else if (s2 == null)
  -        {
  -            // s1 is not null
  -            return false;
  -        }
  -        else
  -        {
  -            return s1.equals(s2);
  -        }
  -    }
  -
  -    public static final int PPKEY_CLASSNAME = 0;
  -    public static final int PPKEY_ID = 1;
  -    public static final int PPKEY_PROPERTY = 2;
  -
  -    /**
  -     * Takes a String of the form <code>substring[substring]substring</code>
  -     * and returns the three parsed substrings.
  -     *
  -     * @return A three element {@link java.lang.String} array populated by
  -     * any parsed object key components.
  -     */
  -    public static String[] parseObjectKey(String s)
  -    {
  -        String[] objectKey = new String[3];
  -        StringTokenizer st = new StringTokenizer(s, "[]");
  -        int count = st.countTokens();
  -        if (count > 1)
  -        {
  -            objectKey[0] = st.nextToken();
  -            objectKey[1] = st.nextToken();
  -            if (count == 3)
  -            {
  -                objectKey[2] = st.nextToken();
  -            }
  -        }
  -        return objectKey;
  -    }
  -
  -
  -    /**
  -     * Remove Underscores from a string and replaces first
  -     * Letters with Capitals.  foo_bar becomes FooBar
  -     */
  -    public static String removeUnderScores (String data)
  -    {
  -        String temp = null;
  -        StringBuffer out = new StringBuffer();
  -        temp = data;
  -
  -        StringTokenizer st = new StringTokenizer(temp, "_");
  -        while (st.hasMoreTokens())
  -        {
  -            String element = (String) st.nextElement();
  -            out.append ( firstLetterCaps(element));
  -        }
  -        return out.toString();
  -    }
  -
  -    /**
  -     * Makes the first letter caps and leaves the rest as is.
  -     */
  -    public static String firstLetterCaps ( String data )
  -    {
  -        StringBuffer sbuf = new StringBuffer(data.length());
  -        sbuf.append(data.substring(0, 1).toUpperCase())
  -            .append(data.substring(1));
  -        return sbuf.toString();
  -    }
  -
  -    /**
  -     * Splits the provided CSV text into a list.
  -     *
  -     * @param text      The CSV list of values to split apart.
  -     * @param separator The separator character.
  -     * @return          The list of values.
  -     */
  -    public static String[] split(String text, String separator)
  -    {
  -        StringTokenizer st = new StringTokenizer(text, separator);
  -        String[] values = new String[st.countTokens()];
  -        int pos = 0;
  -        while (st.hasMoreTokens())
  -        {
  -            values[pos++] = st.nextToken();
  -        }
  -        return values;
  -    }
  -
  -    /**
  -     * Joins the elements of the provided array into a single string
  -     * containing a list of CSV elements.
  -     *
  -     * @param list      The list of values to join together.
  -     * @param separator The separator character.
  -     * @return          The CSV text.
  -     */
  -    public static String join(String[] list, String separator)
  -    {
  -        StringBuffer csv = new StringBuffer();
  -        for (int i = 0; i < list.length; i++)
  -        {
  -            if (i > 0)
  -            {
  -                csv.append(separator);
  -            }
  -            csv.append(list[i]);
  -        }
  -        return csv.toString();
  -    }
  -
  -    /**
  -     * Takes a block of text which might have long lines in it and wraps
  -     * the long lines based on the supplied wrapColumn parameter. It was
  -     * initially implemented for use by VelocityEmail. If there are tabs
  -     * in inString, you are going to get results that are a bit strange,
  -     * since tabs are a single character but are displayed as 4 or 8
  -     * spaces. Remove the tabs.
  -     *
  -     * @param inString   Text which is in need of word-wrapping.
  -     * @param newline    The characters that define a newline.
  -     * @param wrapColumn The column to wrap the words at.
  -     * @return           The text with all the long lines word-wrapped.
  -     */
  -
  -    public static String wrapText (String inString, String newline,
  -                                   int wrapColumn)
  -    {
  -        StringTokenizer lineTokenizer = new StringTokenizer (
  -                inString, newline, true);
  -        StringBuffer stringBuffer = new StringBuffer();
  -
  -        while (lineTokenizer.hasMoreTokens ())
  -        {
  -            try
  -            {
  -                String nextLine = lineTokenizer.nextToken();
  -
  -                if (nextLine.length() > wrapColumn)
  -                {
  -                    // This line is long enough to be wrapped.
  -                    nextLine = wrapLine (nextLine, newline, wrapColumn);
  -                }
  -
  -                stringBuffer.append (nextLine);
  -            }
  -            catch (NoSuchElementException nsee)
  -            {
  -                // thrown by nextToken(), but I don't know why it would
  -                break;
  -            }
  -        }
  -
  -        return (stringBuffer.toString());
  -    }
  -
  -    /**
  -     * Wraps a single line of text. Called by wrapText(). I can't
  -     * think of any good reason for exposing this to the public, 
  -     * since wrapText should always be used AFAIK.
  -     *
  -     * @param line       A line which is in need of word-wrapping.
  -     * @param newline    The characters that define a newline.
  -     * @param wrapColumn The column to wrap the words at.
  -     * @return           A line with newlines inserted.
  -     */
  -
  -    protected static String wrapLine (String line, String newline,
  -                                      int wrapColumn)
  -    {
  -        StringBuffer wrappedLine = new StringBuffer();
  -
  -        while (line.length() > wrapColumn)
  -        {
  -            int spaceToWrapAt = line.lastIndexOf (' ', wrapColumn);
  -
  -            if (spaceToWrapAt >= 0)
  -            {
  -                wrappedLine.append (line.substring (0, spaceToWrapAt));
  -                wrappedLine.append (newline);
  -                line = line.substring (spaceToWrapAt + 1);
  -            }
  -
  -            // This must be a really long word or URL. Pass it
  -            // through unchanged even though it's longer than the
  -            // wrapColumn would allow. This behavior could be
  -            // dependent on a parameter for those situations when
  -            // someone wants long words broken at line length.
  -            else
  -            {
  -                spaceToWrapAt = line.indexOf (' ', wrapColumn);
  -
  -                if (spaceToWrapAt >= 0)
  -                {
  -                    wrappedLine.append (line.substring (0, spaceToWrapAt));
  -                    wrappedLine.append (newline);
  -                    line = line.substring (spaceToWrapAt + 1);
  -                }
  -                else
  -                {
  -                    wrappedLine.append (line);
  -                    line = "";
  -                }
  -            }
  -        }
  -
  -        // Whatever is left in line is short enough to just pass through,
  -        // just like a small small kidney stone
  -        wrappedLine.append (line);
  -
  -        return (wrappedLine.toString());
  -    }
   }
  
  
  
  1.2       +15 -6     
jakarta-turbine/src/adapter/org/apache/turbine/util/TurbineException.java
  
  Index: TurbineException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/TurbineException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- TurbineException.java     2001/07/13 19:15:20     1.1
  +++ TurbineException.java     2001/08/08 07:35:33     1.2
  @@ -54,18 +54,27 @@
    * <http://www.apache.org/>.
    */
   
  -public class TurbineException 
  -    extends org.apache.turbine.TurbineException 
  +/**
  + * @deprecated Use org.apache.turbine.TurbineException instead.
  + */
  +public class TurbineException extends org.apache.turbine.TurbineException
   {
  +    public TurbineException()
  +    {
  +    }
   
  -    public TurbineException( String msg )
  +    public TurbineException(String msg)
       {
           super(msg);
       }
  -
  -    public TurbineException( String msg, Throwable nested )
  +    
  +    public TurbineException(Throwable nested)
       {
  +        super(nested);
  +    }
  +    
  +    public TurbineException(String msg, Throwable nested)
  +    {
           super(msg, nested);
       }
  -
   }
  
  
  
  1.2       +22 -1     
jakarta-turbine/src/adapter/org/apache/turbine/util/TurbineRuntimeException.java
  
  Index: TurbineRuntimeException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/adapter/org/apache/turbine/util/TurbineRuntimeException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- TurbineRuntimeException.java      2001/07/13 19:15:20     1.1
  +++ TurbineRuntimeException.java      2001/08/08 07:35:33     1.2
  @@ -54,7 +54,28 @@
    * <http://www.apache.org/>.
    */
   
  -public class TurbineRuntimeException 
  +/**
  + * @deprecated Use org.apache.turbine.TurbineRuntimeException instead.
  + */
  +public class TurbineRuntimeException
       extends org.apache.turbine.TurbineRuntimeException 
   {
  +    public TurbineRuntimeException()
  +    {
  +    }
  +
  +    public TurbineRuntimeException(String msg)
  +    {
  +        super(msg);
  +    }
  +
  +    public TurbineRuntimeException(Throwable nested)
  +    {
  +        super(nested);
  +    }
  +
  +    public TurbineRuntimeException(String msg, Throwable nested)
  +    {
  +        super(msg, nested);
  +    }
   }
  
  
  
  1.3       +8 -255    
jakarta-turbine/src/java/org/apache/turbine/TurbineException.java
  
  Index: TurbineException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/TurbineException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- TurbineException.java     2001/07/30 20:39:21     1.2
  +++ TurbineException.java     2001/08/08 07:35:33     1.3
  @@ -54,279 +54,32 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.OutputStream;
  -import java.io.PrintStream;
  -import java.io.PrintWriter;
  -import java.io.StringWriter;
  -import java.io.Writer;
  -import java.util.LinkedList;
  -import java.util.StringTokenizer;
  +import org.apache.commons.util.exception.NestableException;
   
   /**
  - * The base class of all exceptions thrown by Turbine.
  + * The base class of all regular exceptions thrown by Torque.
    *
  - * It is intended to ease the debugging by carrying on the information
  - * about the exception which was caught and provoked throwing the 
  - * current exception. Catching and rethrowing may occur multiple
  - * times, and provided that all exceptions except the first one
  - * are descendands of <code>TurbineException</code>, when the 
  - * exception is finally printed out using any of the <code>
  - * printStackTrace()</code> methods, the stacktrace will contain 
  - * the information about all exceptions thrown and caught on
  - * the way.
  - * <p> Running the following program
  - * <p><blockquote><pre>
  - *  1 import org.apache.turbine.TurbineException;
  - *  2
  - *  3 public class Test {
  - *  4     public static void main( String[] args ) {
  - *  5         try {
  - *  6             a();
  - *  7         } catch(Exception e) {
  - *  8             e.printStackTrace();
  - *  9         }
  - * 10      }
  - * 11  
  - * 12      public static void a() throws Exception {
  - * 13          try {
  - * 14              b();
  - * 15          } catch(Exception e) {
  - * 16              throw new TurbineException("foo", e);
  - * 17          }
  - * 18      }
  - * 19  
  - * 20      public static void b() throws Exception {
  - * 21          try {
  - * 22              c();
  - * 23          } catch(Exception e) {
  - * 24              throw new TurbineException("bar", e);
  - * 25          }
  - * 26      }
  - * 27   
  - * 28      public static void c() throws Exception {
  - * 29          throw new Exception("baz");
  - * 30      }
  - * 31 }
  - * </pre></blockquote>
  - * <p>Yields the following stacktrace:
  - * <p><blockquote><pre>
  - * java.lang.Exception: baz: bar: foo
  - *    at Test.c(Test.java:29)
  - *    at Test.b(Test.java:22)
  - * rethrown as TurbineException: bar
  - *    at Test.b(Test.java:24)
  - *    at Test.a(Test.java:14)
  - * rethrown as TurbineException: foo
  - *    at Test.a(Test.java:16)
  - *    at Test.main(Test.java:6)
  - * </pre></blockquote><br>
  - *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    */
  -public class TurbineException 
  -    extends Exception
  +public class TurbineException extends NestableException
   {
  -    /** 
  -     * Holds the reference to the exception or error that caused
  -     * this exception to be thrown.
  -     */
  -    private Throwable nested = null;
  - 
  -    /**
  -     * Constructs a new <code>TurbineException</code> without specified 
  -     * detail message.
  -     */
       public TurbineException()
       {
  -        super();
       }
   
  -    /**
  -     * Constructs a new <code>TurbineException</code> with specified 
  -     * detail message.
  -     *
  -     * @param msg The error message.
  -     */
       public TurbineException(String msg)
       {
           super(msg);
       }
  - 
  -    /**
  -     * Constructs a new <code>TurbineException</code> with specified 
  -     * nested <code>Throwable</code>.
  -     *
  -     * @param nested The exception or error that caused this exception 
  -     *               to be thrown.
  -     */
  -    public TurbineException(Throwable nested)
  -    {
  -        super();
  -        this.nested = nested;
  -    }
  - 
  -    /**
  -     * Constructs a new <code>TurbineException</code> with specified 
  -     * detail message and nested <code>Throwable</code>.
  -     *
  -     * @param msg    The error message.
  -     * @param nested The exception or error that caused this exception 
  -     *               to be thrown.
  -     */
  -    public TurbineException(String msg, Throwable nested)
  -    {
  -        super(msg);
  -        this.nested = nested;
  -    }
  - 
  -    /**
  -     * Returns the error message of this and any nested <code>Throwable</code>.
  -     *
  -     * @return The error message.
  -     */
  -    public String getMessage()
  -    {
  -        StringBuffer msg = new StringBuffer();
  -        String ourMsg = super.getMessage();
  -        if (ourMsg != null)
  -        {
  -            msg.append(ourMsg);
  -        }
  -        if (nested != null)
  -        {
  -            String nestedMsg = nested.getMessage();
  -            if (nestedMsg != null)
  -            {
  -                if (ourMsg != null)
  -                {
  -                    msg.append(": ");
  -                }
  -                msg.append(nestedMsg);
  -            }
  -            
  -        }
  -        return (msg.length() > 0 ? msg.toString() : null);
  -    }
   
  -    /**
  -     * Prints the stack trace of this exception the the standar error 
  -     * stream.
  -     */
  -    public void printStackTrace()
  -    {
  -        synchronized(System.err) 
  -        {
  -            printStackTrace(System.err);
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception to the specified print stream.
  -     *
  -     * @param out <code>PrintStream</code> to use for output.
  -     */
  -    public void printStackTrace(PrintStream out) 
  -    {
  -        synchronized(out) 
  -        {
  -            PrintWriter pw = new PrintWriter(out, false);
  -            printStackTrace(pw);
  -            // Flush the PrintWriter before it's GC'ed.
  -            pw.flush();
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception to the specified print writer.
  -     *
  -     * @param out <code>PrintWriter</code> to use for output.
  -     */
  -    public void printStackTrace(PrintWriter out)
  -    {
  -        synchronized(out) 
  -        {
  -            printStackTrace(out, 0);
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception skiping a specified number
  -     * of stack frames.
  -     *
  -     * @param out  <code>PrintWriter</code> to use for output.
  -     * @param skip The numbere of stack frames to skip.
  -     */
  -    public void printStackTrace(PrintWriter out, int skip)
  +    public TurbineException(Throwable nested)
       {
  -        String[] st = captureStackTrace();
  -        if(nested != null) 
  -        {
  -            if(nested instanceof TurbineException) 
  -            {
  -                ((TurbineException)nested).printStackTrace(out, st.length - 2);
  -            } 
  -            else if(nested instanceof TurbineRuntimeException) 
  -            {
  -                ((TurbineRuntimeException)nested).printStackTrace(out, st.length - 
2);
  -            } 
  -            else 
  -            {
  -                String[] nst = captureStackTrace(nested);
  -                for(int i = 0; i < nst.length - st.length + 2; i++) 
  -                {
  -                    out.println(nst[i]);
  -                }
  -            }
  -            out.print("rethrown as ");
  -        }
  -        for(int i=0; i<st.length - skip; i++) 
  -        {
  -            out.println(st[i]);
  -        }
  +        super(nested);
       }
   
  -    /**
  -     * Captures the stack trace associated with this exception.
  -     *
  -     * @return an array of Strings describing stack frames.
  -     */ 
  -    private String[] captureStackTrace() 
  -    {
  -        StringWriter sw = new StringWriter();
  -        super.printStackTrace(new PrintWriter(sw, true));
  -        return splitStackTrace(sw.getBuffer().toString());
  -    }
  - 
  -    /**
  -     * Captures the stack trace associated with a <code>Throwable</code> 
  -     * object.
  -     *
  -     * @param t The <code>Throwable</code>.
  -     * @return  An array of strings describing each stack frame.
  -     */
  -    private String[] captureStackTrace(Throwable t) 
  -    {
  -        StringWriter sw = new StringWriter();
  -        t.printStackTrace(new PrintWriter(sw, true));
  -        return splitStackTrace(sw.getBuffer().toString());
  -    }
  -  
  -    /**
  -     * Splits the stack trace given as a newline separated string
  -     * into an array of stack frames.
  -     * 
  -     * @param stackTrace The stack trace.
  -     * @return           An array of strings describing each stack frame.
  -     */
  -    private String[] splitStackTrace(String stackTrace) 
  +    public TurbineException(String msg, Throwable nested)
       {
  -        String linebreak = System.getProperty("line.separator");
  -        StringTokenizer st = new StringTokenizer(stackTrace, linebreak);
  -        LinkedList list = new LinkedList();
  -        while(st.hasMoreTokens()) 
  -        {
  -            list.add(st.nextToken());
  -        }
  -        return (String [])list.toArray(new String[] {});
  +        super(msg, nested);
       }
   }
  
  
  
  1.3       +7 -176    
jakarta-turbine/src/java/org/apache/turbine/TurbineRuntimeException.java
  
  Index: TurbineRuntimeException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/TurbineRuntimeException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- TurbineRuntimeException.java      2001/07/30 20:39:21     1.2
  +++ TurbineRuntimeException.java      2001/08/08 07:35:33     1.3
  @@ -54,201 +54,32 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.OutputStream;
  -import java.io.PrintStream;
  -import java.io.PrintWriter;
  -import java.io.StringWriter;
  -import java.io.Writer;
  -import java.util.LinkedList;
  -import java.util.StringTokenizer;
  +import org.apache.commons.util.exception.NestableRuntimeException;
   
   /**
    * This is a base class of runtime exeptions thrown by Turbine.
  - *
  - * This class represents a non-checked type exception (see 
  - * {@see java.lang.RuntimeException}). It has the nested stack trace
  - * functionality found in the {@see TurbineException} class.
    * 
  - * It's sad that this class is a straight copy/paste of Turbine exception. 
  - * I wish that Java supported NonCheckedException marker interface...
  - * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rafal Krzewski</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    */
  -public class TurbineRuntimeException 
  -    extends RuntimeException
  +public class TurbineRuntimeException extends NestableRuntimeException
   {
  -    /** 
  -     * Holds the reference to the exception or error that caused
  -     * this exception to be thrown.
  -     */
  -    private Throwable nested = null;
  - 
  -    /**
  -     * Constructs a new <code>TurbineRuntimeException</code> without specified 
  -     * detail message.
  -     */
       public TurbineRuntimeException()
       {
  -        super();
       }
   
  -    /**
  -     * Constructs a new <code>TurbineRuntimeException</code> with specified 
  -     * detail message.
  -     *
  -     * @param msg the error message.
  -     */
       public TurbineRuntimeException(String msg)
       {
           super(msg);
       }
  - 
  -    /**
  -     * Constructs a new <code>TurbineRuntimeException</code> with specified 
  -     * nested <code>Throwable</code>.
  -     *
  -     * @param nested the exception or error that caused this exception 
  -     *               to be thrown.
  -     */
  +    
       public TurbineRuntimeException(Throwable nested)
       {
  -        super();
  -        this.nested = nested;
  +        super(nested);
       }
  - 
  -    /**
  -     * Constructs a new <code>TurbineRuntimeException</code> with specified 
  -     * detail message and nested <code>Throwable</code>.
  -     *
  -     * @param msg the error message.
  -     * @param nested the exception or error that caused this exception 
  -     *               to be thrown.
  -     */
  +    
       public TurbineRuntimeException(String msg, Throwable nested)
  -    {
  -        super(msg);
  -        this.nested = nested;
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception the the standar error 
  -     * stream.
  -     */
  -    public void printStackTrace()
  -    {
  -        synchronized(System.err) 
  -        {
  -            printStackTrace(System.err);
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception to the specified print stream.
  -     *
  -     * @param out <code>PrintStream</code> to use for output
  -     */
  -    public void printStackTrace(PrintStream out) 
  -    {
  -        synchronized(out) 
  -        {
  -            PrintWriter pw=new PrintWriter(out, false);
  -            printStackTrace(pw);
  -            // flush the PrintWriter before it's GCed
  -            pw.flush();
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception to the specified print writer.
  -     *
  -     * @param out <code>PrintWriter</code> to use for output.
  -     */
  -    public void printStackTrace(PrintWriter out)
  -    {
  -        synchronized(out) 
  -        {
  -            printStackTrace(out, 0);
  -        }
  -    }
  - 
  -    /**
  -     * Prints the stack trace of this exception skiping a specified number
  -     * of stack frames.
  -     *
  -     * @param out <code>PrintWriter</code> to use for output.
  -     * @param skip the numbere of stack frames to skip.
  -     */
  -    public void printStackTrace(PrintWriter out, int skip)
  -    {
  -        String[] st = captureStackTrace();
  -        if(nested != null) 
  -        {
  -            if(nested instanceof TurbineRuntimeException) 
  -            {
  -                ((TurbineRuntimeException)nested).printStackTrace(out, st.length - 
2);
  -            } 
  -            else if(nested instanceof TurbineException) 
  -            {
  -                ((TurbineException)nested).printStackTrace(out, st.length - 2);
  -            } 
  -            else 
  -            {
  -                String[] nst = captureStackTrace(nested);
  -                for(int i = 0; i<nst.length - st.length + 2; i++) 
  -                {
  -                    out.println(nst[i]);
  -                }
  -            }
  -            out.print("rethrown as ");
  -        }
  -        for(int i=0; i<st.length - skip; i++) 
  -        {
  -            out.println(st[i]);
  -        }
  -    }
  -
  -    /**
  -     * Captures the stack trace associated with this exception.
  -     *
  -     * @return an array of Strings describing stack frames.
  -     */ 
  -    private String[] captureStackTrace() 
  -    {
  -        StringWriter sw = new StringWriter();
  -        super.printStackTrace(new PrintWriter(sw, true));
  -        return splitStackTrace(sw.getBuffer().toString());
  -    }
  - 
  -    /**
  -     * Captures the stack trace associated with a <code>Throwable</code> 
  -     * object.
  -     *
  -     * @param t the <code>Throwable</code>.
  -     * @return an array of Strings describing stack frames.
  -     */
  -    private String[] captureStackTrace(Throwable t) 
  -    {
  -        StringWriter sw = new StringWriter();
  -        t.printStackTrace(new PrintWriter(sw, true));
  -        return splitStackTrace(sw.getBuffer().toString());
  -    }
  -  
  -    /**
  -     * Splits the stack trace given as a newline separated string
  -     * into an array of stack frames.
  -     * 
  -     * @param stackTrace the stack trace.
  -     * @return an array of Strings describing stack frames.
  -     */
  -    private String[] splitStackTrace(String stackTrace) 
       {
  -        String linebreak = System.getProperty("line.separator");
  -        StringTokenizer st = new StringTokenizer(stackTrace, linebreak);
  -        LinkedList list = new LinkedList();
  -        while(st.hasMoreTokens()) 
  -        {
  -            list.add(st.nextToken());
  -        }
  -        return (String [])list.toArray(new String[] {});
  +        super(msg, nested);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to