[dna-commits] DNA SVN: r616 - in trunk: dna-common/src/test/java/org/jboss/dna/common/util and 11 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Nov 5 13:14:33 EST 2008


Author: rhauch
Date: 2008-11-05 13:14:32 -0500 (Wed, 05 Nov 2008)
New Revision: 616

Added:
   trunk/dna-common/src/main/java/org/jboss/dna/common/util/Base64.java
   trunk/dna-common/src/test/java/org/jboss/dna/common/util/Base64Test.java
Removed:
   trunk/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
   trunk/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
Modified:
   trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
   trunk/dna-common/src/test/java/org/jboss/dna/common/util/StringUtilTest.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicProperty.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/InMemoryBinary.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/JodaDateTime.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
   trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
   trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/RuleService.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
   trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java
   trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
Log:
DNA-247 - Remove DateUtil class and StringUtil.readableString(...) methods
http://jira.jboss.com/jira/browse/DNA-247

Removed the DateUtil class, since it provided a subset of the functionality that is already available in Joda Time, which is being used by 'dna-graph'.  Also deleted the StringUtil.readableString(...) methods, replacing them with calls to List.toString(), Set.toString(), Property.toString(), and Map.toString().  Since the toString() method on arrays is crappy, used "Arrays.asList(array).toString()".

Ensured that Property.toString() returns a readable string, and that the Value classes all have readable toString() methods.  Most were find, but the InMemoryBinary value class had a poor toString() method, so this was changed to output the Base64 encoding of the binary content.  To do this, I added a Base64 utility class based on Federate's class (which was simplified from the public domain class at http://iharder.sourceforge.net/current/java/base64/).

Added: trunk/dna-common/src/main/java/org/jboss/dna/common/util/Base64.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/Base64.java	                        (rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/Base64.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -0,0 +1,404 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.util;
+
+/**
+ * <p>
+ * Encodes and decodes to and from Base64 notation.
+ * </p>
+ * <p>
+ * Homepage: <a href="http://iharder.net/base64">http://iharder.net/base64</a>.
+ * </p>
+ * <p>
+ * The <tt>options</tt> parameter, which appears in a few places, is used to pass several pieces of information to the encoder. In
+ * the "higher level" methods such as encodeBytes( bytes, options ) the options parameter can be used to indicate such things as
+ * first gzipping the bytes before encoding them, not inserting linefeeds (though that breaks strict Base64 compatibility), and
+ * encoding using the URL-safe and Ordered dialects.
+ * </p>
+ * <p>
+ * The constants defined in Base64 can be OR-ed together to combine options, so you might make a call like this:
+ * </p>
+ * <code>String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DONT_BREAK_LINES );</code>
+ * <p>
+ * to compress the data before encoding it and then making the output have no newline characters.
+ * </p>
+ * <p>
+ * Change Log:
+ * </p>
+ * <ul>
+ * <li>v2.2.2 - Fixed encodeFileToFile and decodeFileToFile to use the Base64.InputStream class to encode and decode on the fly
+ * which uses less memory than encoding/decoding an entire file into memory before writing.</li>
+ * <li>v2.2.1 - Fixed bug using URL_SAFE and ORDERED encodings. Fixed bug when using very small files (~< 40 bytes).</li>
+ * <li>v2.2 - Added some helper methods for encoding/decoding directly from one file to the next. Also added a main() method to
+ * support command line encoding/decoding from one file to the next. Also added these Base64 dialects:
+ * <ol>
+ * <li>The default is RFC3548 format.</li>
+ * <li>Calling Base64.setFormat(Base64.BASE64_FORMAT.URLSAFE_FORMAT) generates URL and file name friendly format as described in
+ * Section 4 of RFC3548. http://www.faqs.org/rfcs/rfc3548.html</li>
+ * <li>Calling Base64.setFormat(Base64.BASE64_FORMAT.ORDERED_FORMAT) generates URL and file name friendly format that preserves
+ * lexical ordering as described in http://www.faqs.org/qa/rfcc-1940.html</li>
+ * </ol>
+ * Special thanks to Jim Kellerman at <a href="http://www.powerset.com/">http://www.powerset.com/</a> for contributing the new
+ * Base64 dialects.</li>
+ * <li>v2.1 - Cleaned up javadoc comments and unused variables and methods. Added some convenience methods for reading and writing
+ * to and from files.</li>
+ * <li>v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems with other encodings (like EBCDIC).</li>
+ * <li>v2.0.1 - Fixed an error when decoding a single byte, that is, when the encoded data was a single byte.</li>
+ * <li>v2.0 - I got rid of methods that used booleans to set options. Now everything is more consolidated and cleaner. The code
+ * now detects when data that's being decoded is gzip-compressed and will decompress it automatically. Generally things are
+ * cleaner. You'll probably have to change some method calls that you were making to support the new options format (<tt>int</tt>s
+ * that you "OR" together).</li>
+ * <li>v1.5.1 - Fixed bug when decompressing and decoding to a byte[] using <tt>decode( String s, boolean gzipCompressed )</tt>.
+ * Added the ability to "suspend" encoding in the Output Stream so you can turn on and off the encoding if you need to embed
+ * base64 data in an otherwise "normal" stream (like an XML file).</li>
+ * <li>v1.5 - Output stream pases on flush() command but doesn't do anything itself. This helps when using GZIP streams. Added the
+ * ability to GZip-compress objects before encoding them.</li>
+ * <li>v1.4 - Added helper methods to read/write files.</li>
+ * <li>v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.</li>
+ * <li>v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream where last buffer being read, if not
+ * completely full, was not returned.</li>
+ * <li>v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.</li>
+ * <li>v1.3.3 - Fixed I/O streams which were totally messed up.</li>
+ * </ul>
+ * <p>
+ * I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but
+ * with plenty of well-wishing instead! Please visit <a href="http://iharder.net/base64">http://iharder.net/base64</a>
+ * periodically to check for updates or to contribute improvements.
+ * </p>
+ * 
+ * @author Robert Harder
+ * @author rob at iharder.net
+ * @version 2.2.2
+ */
+public class Base64 {
+
+    /* ********  P R I V A T E   F I E L D S  ******** */
+
+    /** Maximum line length (76) of Base64 output. */
+    private final static int MAX_LINE_LENGTH = 76;
+
+    /** The equals sign (=) as a byte. */
+    private final static byte EQUALS_SIGN = (byte)'=';
+
+    /** The new line character (\n) as a byte. */
+    private final static byte NEW_LINE = (byte)'\n';
+
+    /** Preferred encoding. */
+    private final static String PREFERRED_ENCODING = "UTF-8";
+
+    private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding
+    private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding
+
+    /* ********  S T A N D A R D   B A S E 6 4   A L P H A B E T  ******** */
+
+    /** The 64 valid Base64 values. */
+    /* Host platform me be something funny like EBCDIC, so we hardcode these values. */
+    private final static byte[] _STANDARD_ALPHABET = {(byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F',
+        (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O', (byte)'P', (byte)'Q',
+        (byte)'R', (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', (byte)'a', (byte)'b',
+        (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m',
+        (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x',
+        (byte)'y', (byte)'z', (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8',
+        (byte)'9', (byte)'+', (byte)'/'};
+
+    /**
+     * Translates a Base64 value to either its 6-bit reconstruction value or a negative number indicating some other meaning.
+     **/
+    private final static byte[] _STANDARD_DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+        -5, -5, // Whitespace: Tab and Linefeed
+        -9, -9, // Decimal 11 - 12
+        -5, // Whitespace: Carriage Return
+        -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
+        -9, -9, -9, -9, -9, // Decimal 27 - 31
+        -5, // Whitespace: Space
+        -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
+        62, // Plus sign at decimal 43
+        -9, -9, -9, // Decimal 44 - 46
+        63, // Slash at decimal 47
+        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
+        -9, -9, -9, // Decimal 58 - 60
+        -1, // Equals sign at decimal 61
+        -9, -9, -9, // Decimal 62 - 64
+        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
+        14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
+        -9, -9, -9, -9, -9, -9, // Decimal 91 - 96
+        26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm'
+        39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z'
+        -9, -9, -9, -9 // Decimal 123 - 126
+    /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 127 - 139
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 140 - 152
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 153 - 165
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 166 - 178
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 179 - 191
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 192 - 204
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 205 - 217
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 218 - 230
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,     // Decimal 231 - 243
+    -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9         // Decimal 244 - 255 */
+    };
+
+    /** Defeats instantiation. */
+    private Base64() {
+    }
+
+    /* ********  E N C O D I N G   M E T H O D S  ******** */
+
+    /**
+     * <p>
+     * Encodes up to three bytes of the array <var>source</var> and writes the resulting four Base64 bytes to
+     * <var>destination</var>. The source and destination arrays can be manipulated anywhere along their length by specifying
+     * <var>srcOffset</var> and <var>destOffset</var>. This method does not check to make sure your arrays are large enough to
+     * accomodate <var>srcOffset</var> + 3 for the <var>source</var> array or <var>destOffset</var> + 4 for the
+     * <var>destination</var> array. The actual number of significant bytes in your array is given by <var>numSigBytes</var>.
+     * </p>
+     * <p>
+     * This is the lowest level of the encoding methods with all possible parameters.
+     * </p>
+     * 
+     * @param source the array to convert
+     * @param srcOffset the index where conversion begins
+     * @param numSigBytes the number of significant bytes in your array
+     * @param destination the array to hold the conversion
+     * @param destOffset the index where output will be put
+     * @return the <var>destination</var> array
+     * @since 1.3
+     */
+    private static byte[] encode3to4( byte[] source,
+                                      int srcOffset,
+                                      int numSigBytes,
+                                      byte[] destination,
+                                      int destOffset ) {
+        byte[] ALPHABET = _STANDARD_ALPHABET;
+
+        // 1 2 3
+        // 01234567890123456789012345678901 Bit position
+        // --------000000001111111122222222 Array position from threeBytes
+        // --------| || || || | Six bit groups to index ALPHABET
+        // >>18 >>12 >> 6 >> 0 Right shift necessary
+        // 0x3f 0x3f 0x3f Additional AND
+
+        // Create buffer with zero-padding if there are only one or two
+        // significant bytes passed in the array.
+        // We have to shift left 24 in order to flush out the 1's that appear
+        // when Java treats a value as negative that is cast from a byte to an int.
+        int inBuff = (numSigBytes > 0 ? ((source[srcOffset] << 24) >>> 8) : 0)
+                     | (numSigBytes > 1 ? ((source[srcOffset + 1] << 24) >>> 16) : 0)
+                     | (numSigBytes > 2 ? ((source[srcOffset + 2] << 24) >>> 24) : 0);
+
+        switch (numSigBytes) {
+            case 3:
+                destination[destOffset] = ALPHABET[(inBuff >>> 18)];
+                destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
+                destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
+                destination[destOffset + 3] = ALPHABET[(inBuff) & 0x3f];
+                return destination;
+
+            case 2:
+                destination[destOffset] = ALPHABET[(inBuff >>> 18)];
+                destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
+                destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
+                destination[destOffset + 3] = EQUALS_SIGN;
+                return destination;
+
+            case 1:
+                destination[destOffset] = ALPHABET[(inBuff >>> 18)];
+                destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
+                destination[destOffset + 2] = EQUALS_SIGN;
+                destination[destOffset + 3] = EQUALS_SIGN;
+                return destination;
+
+            default:
+                return destination;
+        } // end switch
+    } // end encode3to4
+
+    /**
+     * Encodes a byte array into Base64 notation. Does not GZip-compress data.
+     * 
+     * @param source The data to convert
+     * @return the encoded data
+     * @since 1.4
+     */
+    public static String encodeBytes( byte[] source ) {
+        // Convert option to boolean in way that code likes it.
+        boolean breakLines = false;
+        int len = source.length;
+        int len43 = len * 4 / 3;
+        byte[] outBuff = new byte[(len43) // Main 4:3
+                                  + ((len % 3) > 0 ? 4 : 0) // Account for padding
+                                  + (breakLines ? (len43 / MAX_LINE_LENGTH) : 0)]; // New lines
+        int d = 0;
+        int e = 0;
+        int len2 = len - 2;
+        int lineLength = 0;
+        for (; d < len2; d += 3, e += 4) {
+            encode3to4(source, d, 3, outBuff, e);
+
+            lineLength += 4;
+            if (breakLines && lineLength == MAX_LINE_LENGTH) {
+                outBuff[e + 4] = NEW_LINE;
+                e++;
+                lineLength = 0;
+            } // end if: end of line
+        } // en dfor: each piece of array
+
+        if (d < len) {
+            encode3to4(source, d, len - d, outBuff, e);
+            e += 4;
+        } // end if: some padding needed
+
+        // Return value according to relevant encoding.
+        try {
+            return new String(outBuff, 0, e, PREFERRED_ENCODING);
+        } // end try
+        catch (java.io.UnsupportedEncodingException uue) {
+            return new String(outBuff, 0, e);
+        } // end catch
+
+    } // end else: don't compress
+
+    /* ********  D E C O D I N G   M E T H O D S  ******** */
+
+    /**
+     * Decodes four bytes from array <var>source</var> and writes the resulting bytes (up to three of them) to
+     * <var>destination</var>. The source and destination arrays can be manipulated anywhere along their length by specifying
+     * <var>srcOffset</var> and <var>destOffset</var>. This method does not check to make sure your arrays are large enough to
+     * accomodate <var>srcOffset</var> + 4 for the <var>source</var> array or <var>destOffset</var> + 3 for the
+     * <var>destination</var> array. This method returns the actual number of bytes that were converted from the Base64 encoding.
+     * <p>
+     * This is the lowest level of the decoding methods with all possible parameters.
+     * </p>
+     * 
+     * @param source the array to convert
+     * @param srcOffset the index where conversion begins
+     * @param destination the array to hold the conversion
+     * @param destOffset destination offset
+     * @return the number of decoded bytes converted
+     * @since 1.3
+     */
+    private static int decode4to3( byte[] source,
+                                   int srcOffset,
+                                   byte[] destination,
+                                   int destOffset ) {
+        byte[] DECODABET = _STANDARD_DECODABET;
+
+        // Example: Dk==
+        if (source[srcOffset + 2] == EQUALS_SIGN) {
+            // Two ways to do the same thing. Don't know which way I like best.
+            // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+            // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );
+            int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12);
+
+            destination[destOffset] = (byte)(outBuff >>> 16);
+            return 1;
+        }
+
+        // Example: DkL=
+        else if (source[srcOffset + 3] == EQUALS_SIGN) {
+            // Two ways to do the same thing. Don't know which way I like best.
+            // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+            // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
+            // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 );
+            int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12)
+                          | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6);
+
+            destination[destOffset] = (byte)(outBuff >>> 16);
+            destination[destOffset + 1] = (byte)(outBuff >>> 8);
+            return 2;
+        }
+
+        // Example: DkLE
+        else {
+            // Two ways to do the same thing. Don't know which way I like best.
+            // int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+            // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
+            // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 )
+            // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );
+            int outBuff = ((DECODABET[source[srcOffset]] & 0xFF) << 18) | ((DECODABET[source[srcOffset + 1]] & 0xFF) << 12)
+                          | ((DECODABET[source[srcOffset + 2]] & 0xFF) << 6) | ((DECODABET[source[srcOffset + 3]] & 0xFF));
+
+            destination[destOffset] = (byte)(outBuff >> 16);
+            destination[destOffset + 1] = (byte)(outBuff >> 8);
+            destination[destOffset + 2] = (byte)(outBuff);
+
+            return 3;
+        }
+    } // end decodeToBytes
+
+    /**
+     * Decodes data from Base64 notation.
+     * 
+     * @param s the string to decode
+     * @return the decoded data
+     * @since 1.4
+     */
+    public static byte[] decode( String s ) {
+        byte[] source;
+        try {
+            source = s.getBytes(PREFERRED_ENCODING);
+        } // end try
+        catch (java.io.UnsupportedEncodingException uee) {
+            source = s.getBytes();
+        } // end catch
+        // </change>
+        if (source.length % 4 != 0) {
+            throw new IllegalArgumentException("Source bytes are not valid"); //$NON-NLS-1$
+        }
+        byte[] DECODABET = _STANDARD_DECODABET;
+        int len = source.length;
+        byte[] outBuff = new byte[len * 3 / 4]; // Upper limit on size of output
+        int outBuffPosn = 0;
+
+        byte[] b4 = new byte[4];
+        int b4Posn = 0;
+        int i = 0;
+        byte sbiCrop = 0;
+        byte sbiDecode = 0;
+        for (i = 0; i < len; i++) {
+            sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits
+            sbiDecode = DECODABET[sbiCrop];
+
+            if (sbiDecode >= WHITE_SPACE_ENC) // White space, Equals sign or better
+            {
+                if (sbiDecode >= EQUALS_SIGN_ENC) {
+                    b4[b4Posn++] = sbiCrop;
+                    if (b4Posn > 3) {
+                        outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn);
+                        b4Posn = 0;
+
+                        // If that was the equals sign, break out of 'for' loop
+                        if (sbiCrop == EQUALS_SIGN) break;
+                    } // end if: quartet built
+
+                } // end if: equals sign or better
+
+            } // end if: white space, equals sign or better
+            else {
+                throw new IllegalArgumentException("Source bytes are not valid"); //$NON-NLS-1$
+            } // end else:
+        } // each input character
+
+        byte[] out = new byte[outBuffPosn];
+        System.arraycopy(outBuff, 0, out, 0, outBuffPosn);
+        return out;
+    } // end decode
+}


Property changes on: trunk/dna-common/src/main/java/org/jboss/dna/common/util/Base64.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -1,277 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.common.util;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.common.CommonI18n;
-
-/**
- * Utilities for working with dates.
- * <p>
- * Many of the methods that convert dates to and from strings utilize the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO
- * 8601:2004</a> standard string format <code>yyyy-MM-ddTHH:mm:ss.SSSZ</code>, where <blockquote>
- * 
- * <pre>
- * Symbol   Meaning                 Presentation        Example
- * ------   -------                 ------------        -------
- * y        year                    (Number)            1996
- * M        month in year           (Number)            07
- * d        day in month            (Number)            10
- * h        hour in am/pm (1&tilde;12)    (Number)            12
- * H        hour in day (0&tilde;23)      (Number)            0
- * m        minute in hour          (Number)            30
- * s        second in minute        (Number)            55
- * S        millisecond             (Number)            978
- * Z        time zone               (Number)            -0600
- * </pre>
- * 
- * </blockquote>
- * </p>
- * <p>
- * This class is written to be thread safe. As {@link SimpleDateFormat} is not threadsafe, no shared instances are used.
- * </p>
- * @author Randall Hauch
- */
- at ThreadSafe
-public class DateUtil {
-
-    public static final String ISO_8601_2004_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
-
-    /**
-     * Parse the date contained in the supplied string. The date must follow one of the standard ISO 8601 formats, of the form
-     * <code><i>datepart</i>T<i>timepart</i></code>, where <code><i>datepart</i></code> is one of the following forms:
-     * <p>
-     * <dl>
-     * <dt>YYYYMMDD</dt>
-     * <dd>The 4-digit year, the 2-digit month (00-12), and the 2-digit day of the month (00-31). The month and day are optional,
-     * but the month is required if the day is given.</dd>
-     * <dt>YYYY-MM-DD</dt>
-     * <dd>The 4-digit year, the 2-digit month (00-12), and the 2-digit day of the month (00-31). The month and day are optional,
-     * but the month is required if the day is given.</dd>
-     * <dt>YYYY-Www-D</dt>
-     * <dd>The 4-digit year followed by 'W', the 2-digit week number (00-53), and the day of the week (1-7). The day of week
-     * number is optional.</dd>
-     * <dt>YYYYWwwD</dt>
-     * <dd>The 4-digit year followed by 'W', the 2-digit week number (00-53), and the day of the week (1-7). The day of week
-     * number is optional.</dd>
-     * <dt>YYYY-DDD</dt>
-     * <dd>The 4-digit year followed by the 3-digit day of the year (000-365)</dd>
-     * <dt>YYYYDDD</dt>
-     * <dd>The 4-digit year followed by the 3-digit day of the year (000-365)</dd>
-     * </dl>
-     * </p>
-     * <p>
-     * The <code><i>timepart</i></code> consists of one of the following forms that contain the 2-digit hour (00-24), the
-     * 2-digit minutes (00-59), the 2-digit seconds (00-59), and the 1-to-3 digit milliseconds. The minutes, seconds and
-     * milliseconds are optional, but any component is required if it is followed by another component (e.g., minutes are required
-     * if the seconds are given).
-     * <dl>
-     * <dt>hh:mm:ss.SSS</dt>
-     * <dt>hhmmssSSS</dt>
-     * </dl>
-     * </p>
-     * <p>
-     * followed by one of the following time zone definitions:
-     * <dt>Z</dt>
-     * <dd>The uppercase or lowercase 'Z' to denote UTC time</dd>
-     * <dt>&#177;hh:mm</dt>
-     * <dd>The 2-digit hour and the 2-digit minute offset from UTC</dd>
-     * <dt>&#177;hhmm</dt>
-     * <dd>The 2-digit hour and the 2-digit minute offset from UTC</dd>
-     * <dt>&#177;hh</dt>
-     * <dd>The 2-digit hour offset from UTC</dd>
-     * <dt>hh:mm</dt>
-     * <dd>The 2-digit hour and the 2-digit minute offset from UTC</dd>
-     * <dt>hhmm</dt>
-     * <dd>The 2-digit hour and the 2-digit minute offset from UTC</dd>
-     * <dt>hh</dt>
-     * <dd>The 2-digit hour offset from UTC</dd>
-     * </dl>
-     * </p>
-     * @param dateString the string containing the date to be parsed
-     * @return the parsed date as a {@link Calendar} object.
-     * @throws ParseException if there is a problem parsing the string
-     */
-    public static Calendar getCalendarFromStandardString( final String dateString ) throws ParseException {
-        // Example: 2008-02-16T12:30:45.123-0600
-        // Example: 2008-W06-6
-        // Example: 2008-053
-        //
-        // Group Optional Field Description
-        // ----- -------- --------- ------------------------------------------
-        // 1 no 2008 4 digit year as a number
-        // 2 yes 02-16 or W06-6 or 053
-        // 3 yes W06-6
-        // 4 yes 06 2 digit week number (00-59)
-        // 5 yes 6 1 digit day of week as a number (1-7)
-        // 6 yes 02-16
-        // 7 yes 02 2 digit month as a number (00-19)
-        // 8 yes -16
-        // 9 yes 16 2 digit day of month as a number (00-39)
-        // 10 yes 02 2 digit month as a number (00-19)
-        // 11 yes 16 2 digit day of month as a number (00-39)
-        // 12 yes 234 3 digit day of year as a number (000-399)
-        // 13 yes T12:30:45.123-0600
-        // 14 yes 12 2 digit hour as a number (00-29)
-        // 15 yes 30 2 digit minute as a number (00-59)
-        // 16 yes :45.123
-        // 17 yes 45 2 digit second as a number (00-59)
-        // 18 yes .123
-        // 19 yes 123 1, 2 or 3 digit milliseconds as a number (000-999)
-        // 20 yes -0600
-        // 21 yes Z The letter 'Z' if in UTC
-        // 22 yes -06 1 or 2 digit time zone hour offset as a signed number
-        // 23 yes + the plus or minus in the time zone offset
-        // 24 yes 00 1 or 2 digit time zone hour offset as an unsigned number (00-29)
-        // 25 yes 00 1 or 2 digit time zone minute offset as a number (00-59)
-        final String regex =
-            "^(\\d{4})-?(([wW]([012345]\\d)-?([1234567])?)|(([01]\\d)(-([0123]\\d))?)|([01]\\d)([0123]\\d)|([0123]\\d\\d))?(T([012]\\d):?([012345]\\d)(:?([012345]\\d)(.(\\d{1,3}))?)?((Z)|(([+-])(\\d{2})):?(\\d{2})?)?)?$";
-        final Pattern pattern = Pattern.compile(regex);
-        final Matcher matcher = pattern.matcher(dateString);
-        if (!matcher.matches()) {
-            throw new ParseException(CommonI18n.dateParsingFailure.text(dateString), 0);
-        }
-        String year = matcher.group(1);
-        String week = matcher.group(4);
-        String dayOfWeek = matcher.group(5);
-        String month = matcher.group(7);
-        if (month == null) month = matcher.group(10);
-        String dayOfMonth = matcher.group(9);
-        if (dayOfMonth == null) dayOfMonth = matcher.group(11);
-        String dayOfYear = matcher.group(12);
-        String hourOfDay = matcher.group(14);
-        String minutesOfHour = matcher.group(15);
-        String seconds = matcher.group(17);
-        String milliseconds = matcher.group(19);
-        String timeZoneSign = matcher.group(23);
-        String timeZoneHour = matcher.group(24);
-        String timeZoneMinutes = matcher.group(25);
-        if (matcher.group(21) != null) {
-            timeZoneHour = "00";
-            timeZoneMinutes = "00";
-        }
-
-        // Create the calendar object and start setting the fields ...
-        Calendar calendar = Calendar.getInstance();
-        calendar.clear();
-
-        // And start setting the fields. Note that Integer.parseInt should never fail, since we're checking for null and the
-        // regular expression should only have digits in these strings!
-        if (year != null) calendar.set(Calendar.YEAR, Integer.parseInt(year));
-        if (month != null) {
-            calendar.set(Calendar.MONTH, Integer.parseInt(month) - 1); // month is zero-based!
-            if (dayOfMonth != null) calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayOfMonth));
-        } else if (week != null) {
-            calendar.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(week));
-            if (dayOfWeek != null) calendar.set(Calendar.DAY_OF_WEEK, Integer.parseInt(dayOfWeek));
-        } else if (dayOfYear != null) {
-            calendar.set(Calendar.DAY_OF_YEAR, Integer.parseInt(dayOfYear));
-        }
-        if (hourOfDay != null) calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hourOfDay));
-        if (minutesOfHour != null) calendar.set(Calendar.MINUTE, Integer.parseInt(minutesOfHour));
-        if (seconds != null) calendar.set(Calendar.SECOND, Integer.parseInt(seconds));
-        if (milliseconds != null) calendar.set(Calendar.MILLISECOND, Integer.parseInt(milliseconds));
-        if (timeZoneHour != null) {
-            int zoneOffsetInMillis = Integer.parseInt(timeZoneHour) * 60 * 60 * 1000;
-            if ("-".equals(timeZoneSign)) zoneOffsetInMillis *= -1;
-            if (timeZoneMinutes != null) {
-                int minuteOffsetInMillis = Integer.parseInt(timeZoneMinutes) * 60 * 1000;
-                if (zoneOffsetInMillis < 0) {
-                    zoneOffsetInMillis -= minuteOffsetInMillis;
-                } else {
-                    zoneOffsetInMillis += minuteOffsetInMillis;
-                }
-            }
-            calendar.set(Calendar.ZONE_OFFSET, zoneOffsetInMillis);
-        }
-        return calendar;
-    }
-
-    /**
-     * Parse the date contained in the supplied string. This method simply calls {@link Calendar#getTime()} on the result of
-     * {@link #getCalendarFromStandardString(String)}.
-     * @param dateString the string containing the date to be parsed
-     * @return the parsed date as a {@link Calendar} object.
-     * @throws ParseException if there is a problem parsing the string
-     * @see #getCalendarFromStandardString(String)
-     */
-    public static Date getDateFromStandardString( String dateString ) throws ParseException {
-        return getCalendarFromStandardString(dateString).getTime();
-    }
-
-    /**
-     * Obtain an ISO 8601:2004 string representation of the date given the supplied milliseconds since the epoch.
-     * @param millisecondsSinceEpoch the milliseconds for the date
-     * @return the string in the {@link #ISO_8601_2004_FORMAT standard format}
-     * @see #getDateAsStandardString(Date)
-     * @see #getDateFromStandardString(String)
-     * @see #getCalendarFromStandardString(String)
-     */
-    public static String getDateAsStandardString( final long millisecondsSinceEpoch ) {
-        return getDateAsStandardString(new Date(millisecondsSinceEpoch));
-    }
-
-    /**
-     * Obtain an ISO 8601:2004 string representation of the date given the supplied milliseconds since the epoch.
-     * @param date the date in calendar form
-     * @return the string in the {@link #ISO_8601_2004_FORMAT standard format}
-     * @see #getDateAsStandardString(Date)
-     * @see #getDateFromStandardString(String)
-     * @see #getCalendarFromStandardString(String)
-     */
-    public static String getDateAsStandardString( final Calendar date ) {
-        return getDateAsStandardString(date.getTime());
-    }
-
-    /**
-     * Obtain an ISO 8601:2004 string representation of the supplied date.
-     * @param date the date
-     * @return the string in the {@link #ISO_8601_2004_FORMAT standard format}
-     * @see #getDateAsStandardString(long)
-     * @see #getDateFromStandardString(String)
-     * @see #getCalendarFromStandardString(String)
-     */
-    public static String getDateAsStandardString( final java.util.Date date ) {
-        return new SimpleDateFormat(ISO_8601_2004_FORMAT).format(date);
-    }
-
-    public static String getDateAsStringForCurrentLocale( final java.util.Date date ) {
-        return getDateAsStringForLocale(date, Locale.getDefault());
-    }
-
-    public static String getDateAsStringForLocale( final java.util.Date date, Locale locale ) {
-        return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG).format(date);
-    }
-
-    private DateUtil() {
-        // Prevent instantiation
-    }
-
-}

Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -30,15 +30,11 @@
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.jboss.dna.common.CommonI18n;
-import org.jboss.dna.common.SystemFailureException;
 
 /**
  * Utilities for string processing and manipulation.
@@ -376,252 +372,6 @@
     }
 
     /**
-     * Create a human-readable form of the supplied object by choosing the representation format based upon the object type.
-     * <p>
-     * <ul>
-     * <li>A null reference results in the "null" string.</li>
-     * <li>A string is written wrapped by double quotes.</li>
-     * <li>A boolean is written using {@link Boolean#toString()}.</li>
-     * <li>A {@link Number number} is written using the standard {@link Number#toString() toString()} method.</li>
-     * <li>A {@link java.util.Date date} is written using the the {@link DateUtil#getDateAsStandardString(java.util.Date)} utility
-     * method.</li>
-     * <li>A {@link java.sql.Date SQL date} is written using the the {@link DateUtil#getDateAsStandardString(java.util.Date)}
-     * utility method.</li>
-     * <li>A {@link Calendar Calendar instance} is written using the the {@link DateUtil#getDateAsStandardString(Calendar)}
-     * utility method.</li>
-     * <li>An array of bytes is written with a leading "[ " and trailing " ]" surrounding the bytes written as UTF-8.
-     * <li>An array of objects is written with a leading "[ " and trailing " ]", and with all objects sent through
-     * {@link #readableString(Object)} and separated by ", ".</li>
-     * <li>A collection of objects (e.g, <code>Collection<?></code>) is written with a leading "[ " and trailing " ]", and with
-     * all objects sent through {@link #readableString(Object)} and separated by ", ".</li>
-     * <li>A map of objects (e.g, <code>Map<?></code>) is written with a leading "{ " and trailing " }", and with all map entries
-     * written in the form "key => value" and separated by ", ". All key and value objects are sent through the
-     * {@link #readableString(Object)} method.</li>
-     * <li>Any other object is written using the object's {@link Object#toString() toString()} method.</li>
-     * </ul>
-     * </p>
-     * <p>
-     * This method is capable of generating strings for nested objects. For example, a <code>Map<Date,Object[]></code> would be
-     * written in the form:
-     * 
-     * <pre>
-     *    { 2008-02-03T14:22:49 =&gt; [ &quot;description&quot;, 3, [ 003459de7389g23aef, true ] ] }
-     * </pre>
-     * 
-     * </p>
-     * 
-     * @param obj the object that is to be converted to a string.
-     * @return the string representation that is to be human readable
-     */
-    public static String readableString( Object obj ) {
-        if (obj == null) return "null";
-        if (obj instanceof Boolean) return ((Boolean)obj).toString();
-        if (obj instanceof String) return "\"" + obj.toString() + "\"";
-        if (obj instanceof Number) return obj.toString();
-        if (obj instanceof Map<?, ?>) return readableString((Map<?, ?>)obj);
-        if (obj instanceof Collection<?>) return readableString((Collection<?>)obj);
-        if (obj instanceof byte[]) return readableString((byte[])obj);
-        if (obj instanceof boolean[]) return readableString((boolean[])obj);
-        if (obj instanceof short[]) return readableString((short[])obj);
-        if (obj instanceof int[]) return readableString((int[])obj);
-        if (obj instanceof long[]) return readableString((long[])obj);
-        if (obj instanceof float[]) return readableString((float[])obj);
-        if (obj instanceof double[]) return readableString((double[])obj);
-        if (obj instanceof Object[]) return readableString((Object[])obj);
-        if (obj instanceof Calendar) return DateUtil.getDateAsStandardString((Calendar)obj);
-        if (obj instanceof java.util.Date) return DateUtil.getDateAsStandardString((java.util.Date)obj);
-        if (obj instanceof java.sql.Date) return DateUtil.getDateAsStandardString((java.sql.Date)obj);
-        return obj.toString();
-    }
-
-    protected static String readableEmptyArray( Class<?> arrayClass ) {
-        assert arrayClass != null;
-        Class<?> componentType = arrayClass.getComponentType();
-        if (componentType.isArray()) return "[" + readableEmptyArray(componentType) + "]";
-        return "[]";
-    }
-
-    protected static String readableString( Object[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (Object value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( int[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (int value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( short[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (short value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( long[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (long value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( boolean[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (boolean value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( float[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (float value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( double[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (double value : array) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( byte[] array ) {
-        assert array != null;
-        if (array.length == 0) return readableEmptyArray(array.getClass());
-        StringBuilder sb = new StringBuilder();
-        sb.append("[ ");
-        try {
-            sb.append(new String(array, "UTF-8"));
-        } catch (UnsupportedEncodingException e) {
-            throw new SystemFailureException(e);
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( Collection<?> collection ) {
-        assert collection != null;
-        if (collection.isEmpty()) return "[]";
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("[ ");
-        for (Object value : collection) {
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(value));
-        }
-        sb.append(" ]");
-        return sb.toString();
-    }
-
-    protected static String readableString( Map<?, ?> map ) {
-        assert map != null;
-        if (map.isEmpty()) return "{}";
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        sb.append("{ ");
-        for (Map.Entry<?, ?> entry : map.entrySet()) {
-            Object key = entry.getKey();
-            Object value = entry.getValue();
-            if (first) {
-                first = false;
-            } else {
-                sb.append(", ");
-            }
-            sb.append(readableString(key));
-            sb.append(" => ");
-            sb.append(readableString(value));
-        }
-        sb.append(" }");
-        return sb.toString();
-    }
-
-    /**
      * Get the stack trace of the supplied exception.
      * 
      * @param throwable the exception for which the stack trace is to be returned

Added: trunk/dna-common/src/test/java/org/jboss/dna/common/util/Base64Test.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/Base64Test.java	                        (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/Base64Test.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.util;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class Base64Test {
+
+    // =========================================================================
+    // H E L P E R M E T H O D S
+    // =========================================================================
+
+    // =========================================================================
+    // T E S T C A S E S
+    // =========================================================================
+
+    @Test
+    public void testBasicExamples() {
+        // Make up some source objects
+        byte[] originalBytes = {(byte)-2, (byte)-1, (byte)0, (byte)1, (byte)2};
+
+        // Display original array
+        System.out.println("\n\nOriginal array: ");
+        for (int i = 0; i < originalBytes.length; i++)
+            System.out.print(originalBytes[i] + " ");
+        System.out.println();
+
+        // Encode serialized bytes
+        String encBytes = Base64.encodeBytes(originalBytes);
+
+        // Print encoded bytes
+        System.out.println("Bytes, encoded ( " + encBytes.getBytes().length + " bytes):\n" + encBytes);
+
+        // Decode bytes
+        byte[] decBytes = Base64.decode(encBytes);
+
+        // Display decoded bytes
+        System.out.println("Encoded Bytes -> decoded: ");
+        for (int i = 0; i < decBytes.length; i++)
+            System.out.print(decBytes[i] + " ");
+        System.out.println();
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void testEncodeNullByteArray() {
+        Base64.encodeBytes(null);
+    }
+
+    @Test
+    public void testEncodeEmptyByteArray() {
+        String result = Base64.encodeBytes(new byte[] {});
+        assertThat(result, is(notNullValue()));
+        assertThat(result.length(), is(0));
+    }
+
+}


Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/util/Base64Test.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -1,208 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.dna.common.util;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.containsString;
-import java.util.Calendar;
-import java.util.Date;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- */
-public class DateUtilTest {
-
-    private Calendar calendar;
-    private Date validDate;
-
-    @Before
-    public void beforeEach() {
-        this.calendar = Calendar.getInstance();
-        this.calendar.set(2008, 1, 3, 14, 22, 49);
-        this.validDate = this.calendar.getTime();
-    }
-
-    @Test
-    public void shouldConvertDateToStringUsingStandardFormat() {
-        assertThat(DateUtil.getDateAsStandardString(this.validDate), containsString("2008-02-03T14:22:49"));
-    }
-
-    @Test
-    public void shouldConvertDateToStringAndBack() throws Exception {
-        String str = DateUtil.getDateAsStandardString(this.validDate);
-        Date output = DateUtil.getDateFromStandardString(str);
-        assertThat(output, is(this.validDate));
-        String outputStr = DateUtil.getDateAsStandardString(output);
-        assertThat(outputStr, is(str));
-    }
-
-    // @Test
-    // public void shouldConvertStringToCalendarAndBack() throws Exception {
-    // String input = "2008-02";
-    // Calendar cal = DateUtil.getCalendarFromStandardString(input);
-    // String output = DateUtil.getDateAsStandardString(cal);
-    // assertThat(output, is(input));
-    // }
-
-    @Test
-    public void shouldConvertStringToDateWithDelimitersAndNoTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("2008-02-03T14:22:49.111");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(false));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-    }
-
-    @Test
-    public void shouldConvertStringToDateWithNoDelimitersAndNoTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("20080203T142249.111");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(false));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-    }
-
-    @Test
-    public void shouldConvertStringToDateWithDelimitersAndUtcTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("2008-02-03T14:22:49.111Z");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(true));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-        assertThat(cal.get(Calendar.ZONE_OFFSET), is(0)); // in milliseconds
-    }
-
-    @Test
-    public void shouldConvertStringToDateWithDelimitersAndHourTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("2008-02-03T14:22:49.111-06");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(true));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-        assertThat(cal.get(Calendar.ZONE_OFFSET), is(-6 * 60 * 60 * 1000)); // in milliseconds
-    }
-
-    @Test
-    public void shouldConvertStringToDateWithDelimitersAndHourAndMinuteTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("2008-02-03T14:22:49.111-0622");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(true));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-        assertThat(cal.get(Calendar.ZONE_OFFSET), is((-6 * 60 - 22) * 60 * 1000)); // in milliseconds
-    }
-
-    @Test
-    public void shouldConvertStringToDateWithDelimitersAndPositiveHourAndMinuteTimeZone() throws Exception {
-        Calendar cal = DateUtil.getCalendarFromStandardString("2008-02-03T14:22:49.111+0622");
-        assertThat(cal.isSet(Calendar.ZONE_OFFSET), is(true));
-        assertThat(cal.isSet(Calendar.WEEK_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_YEAR), is(false));
-        assertThat(cal.isSet(Calendar.DAY_OF_WEEK), is(false));
-        assertThat(cal.get(Calendar.YEAR), is(2008));
-        assertThat(cal.get(Calendar.MONTH), is(2 - 1)); // zero-based month!
-        assertThat(cal.get(Calendar.DAY_OF_MONTH), is(3));
-        assertThat(cal.get(Calendar.HOUR_OF_DAY), is(14));
-        assertThat(cal.get(Calendar.MINUTE), is(22));
-        assertThat(cal.get(Calendar.SECOND), is(49));
-        assertThat(cal.get(Calendar.MILLISECOND), is(111));
-        assertThat(cal.get(Calendar.ZONE_OFFSET), is((+6 * 60 + 22) * 60 * 1000)); // in milliseconds
-    }
-
-    @Test
-    public void shouldConvertDateStringsToCalendar() throws Exception {
-        assertThat(DateUtil.getCalendarFromStandardString("2008").get(Calendar.YEAR), is(2008));
-        assertThat(DateUtil.getCalendarFromStandardString("2008-02").get(Calendar.MONTH), is(2 - 1));
-        assertThat(DateUtil.getCalendarFromStandardString("200802").get(Calendar.MONTH), is(2 - 1));
-        assertThat(DateUtil.getCalendarFromStandardString("2008-02-16").get(Calendar.DAY_OF_MONTH), is(16));
-        assertThat(DateUtil.getCalendarFromStandardString("20080216").get(Calendar.DAY_OF_MONTH), is(16));
-        assertThat(DateUtil.getCalendarFromStandardString("2008216").get(Calendar.DAY_OF_YEAR), is(216));
-        assertThat(DateUtil.getCalendarFromStandardString("2008-216").get(Calendar.DAY_OF_YEAR), is(216));
-        assertThat(DateUtil.getCalendarFromStandardString("2008W216").get(Calendar.WEEK_OF_YEAR), is(21));
-        assertThat(DateUtil.getCalendarFromStandardString("2008-W216").get(Calendar.WEEK_OF_YEAR), is(21));
-    }
-
-    @Test
-    public void shouldConvertCalendarToStringAndBackMultipleTimes() throws Exception {
-        Calendar cal1 = Calendar.getInstance();
-        String cal1Str = DateUtil.getDateAsStandardString(cal1);
-        Calendar cal2 = DateUtil.getCalendarFromStandardString(cal1Str);
-        // Force the calculation of all fields for both calendars ...
-        cal1.add(Calendar.DAY_OF_YEAR, 1);
-        cal2.add(Calendar.DAY_OF_YEAR, 1);
-        cal1.add(Calendar.DAY_OF_YEAR, -1);
-        cal2.add(Calendar.DAY_OF_YEAR, -1);
-        assertThat(cal1.getTimeInMillis(), is(cal2.getTimeInMillis()));
-        assertThat(cal1.compareTo(cal2), is(0));
-        assertThat(cal1, is(cal2));
-        String cal2Str = DateUtil.getDateAsStandardString(cal2);
-        assertThat(cal1Str, is(cal2Str));
-        Calendar cal3 = DateUtil.getCalendarFromStandardString(cal2Str);
-        cal3.add(Calendar.DAY_OF_YEAR, 1);
-        cal3.add(Calendar.DAY_OF_YEAR, -1);
-        assertThat(cal1, is(cal3));
-        assertThat(cal3, is(cal3));
-        String cal3Str = DateUtil.getDateAsStandardString(cal3);
-        assertThat(cal1Str, is(cal3Str));
-        assertThat(cal2Str, is(cal3Str));
-    }
-
-}

Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/util/StringUtilTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/StringUtilTest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/StringUtilTest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -34,7 +34,6 @@
 import java.io.PrintStream;
 import java.io.Reader;
 import java.io.StringReader;
-import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
 
@@ -351,65 +350,6 @@
         assertThat(trace, containsString(this.getClass().getName()));
     }
 
-    @Test
-    public void readableStringShouldReturnStringForNull() {
-        assertThat(StringUtil.readableString((Object)null), is("null"));
-    }
-
-    @Test
-    public void readableStringShouldReturnStringFormOfBoolean() {
-        assertThat(StringUtil.readableString(true), is(Boolean.TRUE.toString()));
-        assertThat(StringUtil.readableString(false), is(Boolean.FALSE.toString()));
-        assertThat(StringUtil.readableString(Boolean.TRUE), is(Boolean.TRUE.toString()));
-        assertThat(StringUtil.readableString(Boolean.FALSE), is(Boolean.FALSE.toString()));
-    }
-
-    @Test
-    public void readableStringShouldReturnStringFormOfNumber() {
-        assertThat(StringUtil.readableString(1), is("1"));
-        assertThat(StringUtil.readableString(-513), is("-513"));
-        assertThat(StringUtil.readableString(-513.3f), is("-513.3"));
-        assertThat(StringUtil.readableString(-513.3d), is("-513.3"));
-        assertThat(StringUtil.readableString(new Short((short)1)), is("1"));
-        assertThat(StringUtil.readableString(new Integer(-513)), is("-513"));
-        assertThat(StringUtil.readableString(new Float(-513.3f)), is("-513.3"));
-        assertThat(StringUtil.readableString(new Double(-513.3d)), is("-513.3"));
-    }
-
-    @Test
-    public void readableStringShouldWrapObjectArrayWithSquareBraces() {
-        assertThat(StringUtil.readableString(new int[] {}), is("[]"));
-        assertThat(StringUtil.readableString(new int[] {1}), is("[ 1 ]"));
-        assertThat(StringUtil.readableString(new int[] {1, 2, 3, 4}), is("[ 1, 2, 3, 4 ]"));
-        assertThat(StringUtil.readableString(new short[] {1, 2, 3, 4}), is("[ 1, 2, 3, 4 ]"));
-        assertThat(StringUtil.readableString(new boolean[] {true, false}), is("[ true, false ]"));
-        assertThat(StringUtil.readableString(new long[] {1, 2, 3, 4}), is("[ 1, 2, 3, 4 ]"));
-        assertThat(StringUtil.readableString(new float[] {51.0f, 52.0f, 53.0f, 54.0f}), is("[ 51.0, 52.0, 53.0, 54.0 ]"));
-        assertThat(StringUtil.readableString(new double[] {51.0d, 52.0d, 53.0d, 54.0d}), is("[ 51.0, 52.0, 53.0, 54.0 ]"));
-    }
-
-    @Test
-    public void readableStringShouldHandleEmptyArraysOfArrays() {
-        assertThat(StringUtil.readableString(new int[][] {}), is("[[]]"));
-        assertThat(StringUtil.readableString(new boolean[][][][][][] {}), is("[[[[[[]]]]]]"));
-        assertThat(StringUtil.readableString(new ArrayList<List<List<?>>>()), is("[]"));
-    }
-
-    @Test
-    public void readableStringShouldHandleNestedObjects() {
-        assertThat(StringUtil.readableString(new int[][] {new int[] {1, 2}, new int[] {3, 4}}), is("[ [ 1, 2 ], [ 3, 4 ] ]"));
-        List<String> list1 = new ArrayList<String>();
-        list1.add("a1");
-        list1.add("a2");
-        List<String> list2 = new ArrayList<String>();
-        list2.add("b1");
-        list2.add("b2");
-        List<List<String>> list3 = new ArrayList<List<String>>();
-        list3.add(list1);
-        list3.add(list2);
-        assertThat(StringUtil.readableString(list3), is("[ [ \"a1\", \"a2\" ], [ \"b1\", \"b2\" ] ]"));
-    }
-
     @Test( expected = IllegalArgumentException.class )
     public void normalizeShouldFailIfTextNull() {
         StringUtil.normalize(null);

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -30,7 +30,6 @@
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.common.util.CheckArg;
 import org.jboss.dna.common.util.HashCode;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.properties.Name;
 import org.jboss.dna.graph.properties.Path;
 import org.jboss.dna.graph.properties.Property;
@@ -465,7 +464,7 @@
             if (this.hasIdProperties()) sb.append(" && ");
         }
         if (this.hasIdProperties()) {
-            sb.append(StringUtil.readableString(this.getIdProperties()));
+            sb.append(this.getIdProperties().toString());
             if (this.hasPath()) sb.append(" ]");
         }
         return sb.toString();

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicProperty.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicProperty.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicProperty.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -21,9 +21,9 @@
  */
 package org.jboss.dna.graph.properties.basic;
 
+import java.util.Arrays;
 import java.util.Iterator;
 import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.properties.Name;
 import org.jboss.dna.graph.properties.Property;
 import org.jboss.dna.graph.properties.ValueComparators;
@@ -120,9 +120,9 @@
         sb.append(getName());
         sb.append(" = ");
         if (isSingle()) {
-            sb.append(StringUtil.readableString(getValues().next()));
+            sb.append(getValues().next());
         } else {
-            sb.append(StringUtil.readableString(getValuesAsArray()));
+            sb.append(Arrays.asList(getValuesAsArray()));
         }
         return sb.toString();
     }

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/InMemoryBinary.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/InMemoryBinary.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/InMemoryBinary.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -28,6 +28,7 @@
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.Base64;
 import org.jboss.dna.common.util.CheckArg;
 import org.jboss.dna.common.util.Logger;
 import org.jboss.dna.graph.GraphI18n;
@@ -156,11 +157,7 @@
     public String toString() {
         StringBuilder sb = new StringBuilder(super.toString());
         sb.append(" len=").append(getSize()).append("; [");
-        int len = (int)Math.min(getSize(), 20l);
-        for (int i = 0; i != len; ++i) {
-            if (i != 0) sb.append(',');
-            sb.append(this.bytes[i]);
-        }
+        sb.append(Base64.encodeBytes(this.bytes));
         return sb.toString();
     }
 

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/JodaDateTime.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/JodaDateTime.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/JodaDateTime.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -47,7 +47,6 @@
     private static final int MILLIS_IN_HOUR = 1000 * 60 * 60;
 
     private final DateTime instance;
-    private transient String formattedString;
 
     public JodaDateTime() {
         this.instance = new DateTime();
@@ -231,12 +230,7 @@
      * {@inheritDoc}
      */
     public String getString() {
-        if (this.formattedString == null) {
-            // This is transient and can be done multiple times by concurrent threads (without locking),
-            // since the object is immutable
-            this.formattedString = this.instance.toString(org.joda.time.format.ISODateTimeFormat.dateTime());
-        }
-        return this.formattedString;
+        return this.instance.toString(org.joda.time.format.ISODateTimeFormat.dateTime());
     }
 
     /**
@@ -410,7 +404,7 @@
      * @see org.jboss.dna.graph.properties.DateTime#minus(long, java.util.concurrent.TimeUnit)
      */
     public org.jboss.dna.graph.properties.DateTime minus( long timeAmount,
-                                                   TimeUnit unit ) {
+                                                          TimeUnit unit ) {
         CheckArg.isNotNull(unit, "unit");
         return new JodaDateTime(this.instance.minus(TimeUnit.MILLISECONDS.convert(timeAmount, unit)));
     }
@@ -493,7 +487,7 @@
      * @see org.jboss.dna.graph.properties.DateTime#plus(long, java.util.concurrent.TimeUnit)
      */
     public org.jboss.dna.graph.properties.DateTime plus( long timeAmount,
-                                                  TimeUnit unit ) {
+                                                         TimeUnit unit ) {
         CheckArg.isNotNull(unit, "unit");
         return new JodaDateTime(this.instance.plus(TimeUnit.MILLISECONDS.convert(timeAmount, unit)));
     }

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -28,7 +28,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.GraphI18n;
 import org.jboss.dna.graph.Location;
 import org.jboss.dna.graph.NodeConflictBehavior;
@@ -280,7 +279,7 @@
      */
     @Override
     public String toString() {
-        return "create node at " + at() + " with properties " + StringUtil.readableString(properties());
+        return "create node at " + at() + " with properties " + properties();
     }
 
 }

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -27,7 +27,6 @@
 import java.util.Iterator;
 import java.util.Set;
 import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.GraphI18n;
 import org.jboss.dna.graph.Location;
 import org.jboss.dna.graph.properties.Name;
@@ -191,7 +190,7 @@
      */
     @Override
     public String toString() {
-        return "remove from " + from() + " properties named " + StringUtil.readableString(propertyNames());
+        return "remove from " + from() + " properties named " + propertyNames();
     }
 
 }

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -28,7 +28,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.GraphI18n;
 import org.jboss.dna.graph.Location;
 import org.jboss.dna.graph.properties.Property;
@@ -188,7 +187,7 @@
      */
     @Override
     public String toString() {
-        return "update properties on " + on() + " to " + StringUtil.readableString(properties());
+        return "update properties on " + on() + " to " + properties();
     }
 
 }

Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -34,7 +34,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.transaction.xa.XAResource;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.cache.CachePolicy;
 import org.jboss.dna.graph.connectors.RepositoryConnection;
 import org.jboss.dna.graph.connectors.RepositoryConnectionFactory;
@@ -137,7 +136,7 @@
             assertThat("missing property " + propertyName, actual, is(expectedProperty));
         }
         if (!propertiesByName.isEmpty()) {
-            System.out.println("Properties for " + path + "\n" + StringUtil.readableString(propertiesByName));
+            System.out.println("Properties for " + path + "\n" + propertiesByName);
         }
         assertThat(propertiesByName.isEmpty(), is(true));
     }

Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/SimpleRepository.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -21,6 +21,7 @@
  */
 package org.jboss.dna.graph.connectors;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -30,7 +31,6 @@
 import java.util.concurrent.ConcurrentMap;
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.DnaLexicon;
 import org.jboss.dna.graph.ExecutionContext;
 import org.jboss.dna.graph.properties.Name;
@@ -134,7 +134,7 @@
                                          Object... values ) {
         Logger logger = context.getLogger(getClass());
         if (logger.isTraceEnabled()) {
-            logger.trace("Setting property {0} on {1} to {2}", propertyName, path, StringUtil.readableString(values));
+            logger.trace("Setting property {0} on {1} to {2}", propertyName, path, Arrays.asList(values));
         }
         PathFactory pathFactory = context.getValueFactories().getPathFactory();
         PropertyFactory propertyFactory = context.getPropertyFactory();

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/RuleService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/RuleService.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/RuleService.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -54,7 +54,6 @@
 import org.jboss.dna.common.component.StandardClassLoaderFactory;
 import org.jboss.dna.common.util.CheckArg;
 import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.repository.RepositoryI18n;
 import org.jboss.dna.repository.services.AbstractServiceAdministrator;
 import org.jboss.dna.repository.services.AdministeredService;
@@ -76,7 +75,8 @@
 @ThreadSafe
 public class RuleService implements AdministeredService {
 
-    protected static final ClassLoaderFactory DEFAULT_CLASSLOADER_FACTORY = new StandardClassLoaderFactory(RuleService.class.getClassLoader());
+    protected static final ClassLoaderFactory DEFAULT_CLASSLOADER_FACTORY = new StandardClassLoaderFactory(
+                                                                                                           RuleService.class.getClassLoader());
 
     /**
      * The administrative component for this service.
@@ -110,7 +110,8 @@
         /**
          * {@inheritDoc}
          */
-        public boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+        public boolean awaitTermination( long timeout,
+                                         TimeUnit unit ) throws InterruptedException {
             return doAwaitTermination(timeout, unit);
         }
 
@@ -126,7 +127,8 @@
 
     /**
      * Create a new rule service, configured with no rule sets. Upon construction, the system is
-     * {@link ServiceAdministrator#isPaused() paused} and must be configured and then {@link ServiceAdministrator#start() started}.
+     * {@link ServiceAdministrator#isPaused() paused} and must be configured and then {@link ServiceAdministrator#start() started}
+     * .
      */
     public RuleService() {
         this.logger = Logger.getLogger(this.getClass());
@@ -189,7 +191,7 @@
      * @return true if the rule set was added, or false if the rule set was not added (because it wasn't necessary)
      * @throws IllegalArgumentException if <code>ruleSet</code> is null
      * @throws InvalidRuleSetException if the supplied rule set is invalid, incomplete, incorrectly defined, or uses a JSR-94
-     * service provider that cannot be found
+     *         service provider that cannot be found
      * @see #updateRuleSet(RuleSet)
      * @see #removeRuleSet(String)
      */
@@ -211,7 +213,10 @@
             // Now register a new execution set ...
             RuleAdministrator ruleAdmin = ruleServiceProvider.getRuleAdministrator();
             if (ruleAdmin == null) {
-                throw new InvalidRuleSetException(RepositoryI18n.unableToObtainJsr94RuleAdministrator.text(providerUri, ruleSet.getComponentClassname(), ruleSetName));
+                throw new InvalidRuleSetException(
+                                                  RepositoryI18n.unableToObtainJsr94RuleAdministrator.text(providerUri,
+                                                                                                           ruleSet.getComponentClassname(),
+                                                                                                           ruleSetName));
             }
 
             // Is there is an existing rule set and, if so, whether it has changed ...
@@ -264,9 +269,15 @@
         } catch (InvalidRuleSetException e) {
             throw e;
         } catch (ConfigurationException t) {
-            throw new InvalidRuleSetException(RepositoryI18n.unableToObtainJsr94RuleAdministrator.text(providerUri, ruleSet.getComponentClassname(), ruleSetName));
+            throw new InvalidRuleSetException(
+                                              RepositoryI18n.unableToObtainJsr94RuleAdministrator.text(providerUri,
+                                                                                                       ruleSet.getComponentClassname(),
+                                                                                                       ruleSetName));
         } catch (RemoteException t) {
-            throw new InvalidRuleSetException(RepositoryI18n.errorUsingJsr94RuleAdministrator.text(providerUri, ruleSet.getComponentClassname(), ruleSetName));
+            throw new InvalidRuleSetException(
+                                              RepositoryI18n.errorUsingJsr94RuleAdministrator.text(providerUri,
+                                                                                                   ruleSet.getComponentClassname(),
+                                                                                                   ruleSetName));
         } catch (IOException t) {
             throw new InvalidRuleSetException(RepositoryI18n.errorReadingRulesAndProperties.text(ruleSetName));
         } catch (RuleExecutionSetDeregistrationException t) {
@@ -285,7 +296,7 @@
      * @param ruleSet the rule set to be updated
      * @return true if the rule set was updated, or false if the rule set was not updated (because it wasn't necessary)
      * @throws InvalidRuleSetException if the supplied rule set is invalid, incomplete, incorrectly defined, or uses a JSR-94
-     * service provider that cannot be found
+     *         service provider that cannot be found
      * @see #addRuleSet(RuleSet)
      * @see #removeRuleSet(String)
      */
@@ -345,19 +356,21 @@
 
     /**
      * Execute the set of rules defined by the supplied rule set name. This method is safe to be concurrently called by multiple
-     * threads, and is properly synchronized with the methods to {@link #addRuleSet(RuleSet) add},
-     * {@link #updateRuleSet(RuleSet) update}, and {@link #removeRuleSet(String) remove} rule sets.
+     * threads, and is properly synchronized with the methods to {@link #addRuleSet(RuleSet) add}, {@link #updateRuleSet(RuleSet)
+     * update}, and {@link #removeRuleSet(String) remove} rule sets.
      * 
      * @param ruleSetName the {@link RuleSet#getName() name} of the {@link RuleSet} that should be used
      * @param globals the global variables
      * @param facts the facts
      * @return the results of executing the rule set
      * @throws IllegalArgumentException if the rule set name is null, empty or blank, or if there is no rule set with the given
-     * name
-     * @throws SystemFailureException if there is no JSR-94 rule service provider with the
-     * {@link RuleSet#getProviderUri() RuleSet's provider URI}.
+     *         name
+     * @throws SystemFailureException if there is no JSR-94 rule service provider with the {@link RuleSet#getProviderUri() 
+     *         RuleSet's provider URI}.
      */
-    public List<?> executeRules( String ruleSetName, Map<String, Object> globals, Object... facts ) {
+    public List<?> executeRules( String ruleSetName,
+                                 Map<String, Object> globals,
+                                 Object... facts ) {
         CheckArg.isNotEmpty(ruleSetName, "rule set name");
         List<?> result = null;
         List<?> factList = Arrays.asList(facts);
@@ -386,10 +399,11 @@
             }
             if (this.logger.isTraceEnabled()) {
                 String msg = "Executed rule set '{1}' with globals {2} and facts {3} resulting in {4}";
-                this.logger.trace(msg, ruleSetName, StringUtil.readableString(globals), StringUtil.readableString(facts), StringUtil.readableString(result));
+                this.logger.trace(msg, ruleSetName, globals, Arrays.asList(facts), result);
             }
         } catch (Throwable t) {
-            throw new SystemFailureException(RepositoryI18n.errorExecutingRuleSetWithGlobalsAndFacts.text(ruleSetName, StringUtil.readableString(globals), StringUtil.readableString(facts)), t);
+            String msg = RepositoryI18n.errorExecutingRuleSetWithGlobalsAndFacts.text(ruleSetName, globals, Arrays.asList(facts));
+            throw new SystemFailureException(msg, t);
         } finally {
             this.lock.readLock().unlock();
         }
@@ -412,7 +426,8 @@
         this.shutdownLatch.countDown();
     }
 
-    protected boolean doAwaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+    protected boolean doAwaitTermination( long timeout,
+                                          TimeUnit unit ) throws InterruptedException {
         return this.shutdownLatch.await(timeout, unit);
     }
 
@@ -446,11 +461,16 @@
             } catch (ConfigurationException ce) {
                 throw ce;
             } catch (Throwable t) {
-                throw new InvalidRuleSetException(RepositoryI18n.unableToObtainJsr94ServiceProvider.text(providerUri, ruleSet.getComponentClassname()), t);
+                throw new InvalidRuleSetException(
+                                                  RepositoryI18n.unableToObtainJsr94ServiceProvider.text(providerUri,
+                                                                                                         ruleSet.getComponentClassname()),
+                                                  t);
             }
         }
         if (ruleServiceProvider == null) {
-            throw new InvalidRuleSetException(RepositoryI18n.unableToObtainJsr94ServiceProvider.text(providerUri, ruleSet.getComponentClassname()));
+            throw new InvalidRuleSetException(
+                                              RepositoryI18n.unableToObtainJsr94ServiceProvider.text(providerUri,
+                                                                                                     ruleSet.getComponentClassname()));
         }
         return ruleServiceProvider;
     }
@@ -465,7 +485,8 @@
      * @throws RuleExecutionSetDeregistrationException
      * @throws RemoteException
      */
-    private RuleServiceProvider deregister( RuleSet ruleSet ) throws ConfigurationException, RuleExecutionSetDeregistrationException, RemoteException {
+    private RuleServiceProvider deregister( RuleSet ruleSet )
+        throws ConfigurationException, RuleExecutionSetDeregistrationException, RemoteException {
         assert ruleSet != null;
         // Look up the provider ...
         String providerUri = ruleSet.getProviderUri();

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -31,7 +31,6 @@
 import net.jcip.annotations.Immutable;
 import net.jcip.annotations.NotThreadSafe;
 import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.JcrLexicon;
 import org.jboss.dna.graph.properties.Name;
 import org.jboss.dna.graph.properties.Path;
@@ -186,7 +185,7 @@
      */
     @Override
     public String toString() {
-        return StringUtil.readableString(this.data);
+        return this.data.toString();
     }
 
     /**
@@ -262,7 +261,7 @@
          */
         @Override
         public String toString() {
-            return "[" + this.name + "=" + StringUtil.readableString(value) + "]";
+            return "[" + this.name + "=" + value + "]";
         }
     }
 

Modified: trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -26,6 +26,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -260,8 +261,7 @@
         for (Map.Entry<String, Object[]> property : properties.entrySet()) {
             String name = StringUtil.justifyLeft(property.getKey(), maxLength, ' ');
             Object[] values = property.getValue();
-            String valueStr = StringUtil.readableString(values);
-            if (values.length == 1) valueStr = StringUtil.readableString(values[0]);
+            String valueStr = values.length == 1 ? values[0].toString() : Arrays.asList(values).toString();
             System.out.println(" " + name + " = " + valueStr);
         }
     }

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -28,7 +28,6 @@
 import java.util.List;
 import java.util.NoSuchElementException;
 import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.Location;
 import org.jboss.dna.graph.properties.DateTime;
 import org.jboss.dna.graph.properties.Name;
@@ -383,10 +382,7 @@
             while (propIter.hasNext()) {
                 if (!first) sb.append(", ");
                 else first = false;
-                Property property = propIter.next();
-                sb.append(property.getName());
-                sb.append('=');
-                sb.append(StringUtil.readableString(property.getValuesAsArray()));
+                sb.append(propIter.next());
             }
             sb.append(" }");
         }

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergePlan.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -36,7 +36,6 @@
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.common.CommonI18n;
 import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.connector.federation.contribution.Contribution;
 import org.jboss.dna.connector.federation.contribution.EmptyContribution;
 import org.jboss.dna.graph.properties.DateTime;
@@ -361,7 +360,7 @@
             }
             sb.append(contribution);
         }
-        sb.append(StringUtil.readableString(getAnnotations()));
+        sb.append(getAnnotations());
         return sb.toString();
     }
 

Modified: trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-11-04 18:00:14 UTC (rev 615)
+++ trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-11-05 18:14:32 UTC (rev 616)
@@ -22,6 +22,7 @@
 package org.jboss.dna.connector.jbosscache;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -34,7 +35,6 @@
 import org.jboss.cache.Cache;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
-import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.graph.DnaLexicon;
 import org.jboss.dna.graph.ExecutionContext;
 import org.jboss.dna.graph.Location;
@@ -482,9 +482,7 @@
 
         // Record the list of children as a property on the parent ...
         // (Do this last, as it doesn't need to be done if there's an exception in the above logic)
-        context.getLogger(getClass()).trace("Updating child list of {0} to: {1}",
-                                            parent.getFqn(),
-                                            StringUtil.readableString(childNames));
+        context.getLogger(getClass()).trace("Updating child list of {0} to: {1}", parent.getFqn(), Arrays.asList(childNames));
         parent.put(JBossCacheLexicon.CHILD_PATH_SEGMENT_LIST, childNames); // replaces any existing value
 
         if (addChildWithName) {




More information about the dna-commits mailing list