roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r1588757 [16/25] - in /roller/branches/rome2/app/src: main/java/org/apache/roller/ main/java/org/apache/roller/planet/business/ main/java/org/apache/roller/planet/business/fetcher/ main/java/org/apache/roller/planet/business/jpa/ main/java/...
Date Sun, 20 Apr 2014 13:39:01 GMT
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java Sun Apr 20 13:38:51 2014
@@ -19,8 +19,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -29,98 +27,98 @@ import javax.activation.MimetypesFileTyp
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.codec.binary.Base64;
 import org.apache.roller.util.RegexUtil;
+import org.apache.roller.util.RollerConstants;
 
-        
 /**
  * General purpose utilities, not for use in templates.
  */
 public class Utilities {
     /** The <code>Log</code> instance for this class. */
     private static Log mLogger = LogFactory.getLog(Utilities.class);
-    
+
     public static final String TAG_SPLIT_CHARS = " ,\n\r\f\t";
-      
-    private static Pattern mLinkPattern =
-            Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);    
-    private static final Pattern OPENING_B_TAG_PATTERN = 
-            Pattern.compile("&lt;b&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_B_TAG_PATTERN = 
-            Pattern.compile("&lt;/b&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_I_TAG_PATTERN = 
-            Pattern.compile("&lt;i&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_I_TAG_PATTERN = 
-            Pattern.compile("&lt;/i&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_BLOCKQUOTE_TAG_PATTERN = 
-            Pattern.compile("&lt;blockquote&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_BLOCKQUOTE_TAG_PATTERN = 
-            Pattern.compile("&lt;/blockquote&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern BR_TAG_PATTERN = 
-            Pattern.compile("&lt;br */*&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_P_TAG_PATTERN = 
-            Pattern.compile("&lt;p&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_P_TAG_PATTERN = 
-            Pattern.compile("&lt;/p&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_PRE_TAG_PATTERN = 
-            Pattern.compile("&lt;pre&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_PRE_TAG_PATTERN = 
-            Pattern.compile("&lt;/pre&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_UL_TAG_PATTERN = 
-            Pattern.compile("&lt;ul&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_UL_TAG_PATTERN = 
-            Pattern.compile("&lt;/ul&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_OL_TAG_PATTERN = 
-            Pattern.compile("&lt;ol&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_OL_TAG_PATTERN = 
-            Pattern.compile("&lt;/ol&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_LI_TAG_PATTERN = 
-            Pattern.compile("&lt;li&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_LI_TAG_PATTERN = 
-            Pattern.compile("&lt;/li&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern CLOSING_A_TAG_PATTERN = 
-            Pattern.compile("&lt;/a&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern OPENING_A_TAG_PATTERN = 
-            Pattern.compile("&lt;a href=.*?&gt;", Pattern.CASE_INSENSITIVE);
-    private static final Pattern QUOTE_PATTERN = 
-            Pattern.compile("&quot;", Pattern.CASE_INSENSITIVE);
-    
-    
-    //------------------------------------------------------------------------
+
+    private static Pattern mLinkPattern = Pattern.compile("<a href=.*?>",
+            Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_B_TAG_PATTERN = Pattern.compile(
+            "&lt;b&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_B_TAG_PATTERN = Pattern.compile(
+            "&lt;/b&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_I_TAG_PATTERN = Pattern.compile(
+            "&lt;i&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_I_TAG_PATTERN = Pattern.compile(
+            "&lt;/i&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_BLOCKQUOTE_TAG_PATTERN = Pattern
+            .compile("&lt;blockquote&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_BLOCKQUOTE_TAG_PATTERN = Pattern
+            .compile("&lt;/blockquote&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern BR_TAG_PATTERN = Pattern.compile(
+            "&lt;br */*&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_P_TAG_PATTERN = Pattern.compile(
+            "&lt;p&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_P_TAG_PATTERN = Pattern.compile(
+            "&lt;/p&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_PRE_TAG_PATTERN = Pattern.compile(
+            "&lt;pre&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_PRE_TAG_PATTERN = Pattern.compile(
+            "&lt;/pre&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_UL_TAG_PATTERN = Pattern.compile(
+            "&lt;ul&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_UL_TAG_PATTERN = Pattern.compile(
+            "&lt;/ul&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_OL_TAG_PATTERN = Pattern.compile(
+            "&lt;ol&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_OL_TAG_PATTERN = Pattern.compile(
+            "&lt;/ol&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_LI_TAG_PATTERN = Pattern.compile(
+            "&lt;li&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_LI_TAG_PATTERN = Pattern.compile(
+            "&lt;/li&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_A_TAG_PATTERN = Pattern.compile(
+            "&lt;/a&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_A_TAG_PATTERN = Pattern.compile(
+            "&lt;a href=.*?&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern QUOTE_PATTERN = Pattern.compile("&quot;",
+            Pattern.CASE_INSENSITIVE);
+
+    // ------------------------------------------------------------------------
     /** Strip jsessionid off of a URL */
-    public static String stripJsessionId( String url ) {
+    public static String stripJsessionId(String url) {
         // Strip off jsessionid found in referer URL
         int startPos = url.indexOf(";jsessionid=");
-        if ( startPos != -1 ) {
-            int endPos = url.indexOf('?',startPos);
-            if ( endPos == -1 ) {
-                url = url.substring(0,startPos);
+        if (startPos != -1) {
+            int endPos = url.indexOf('?', startPos);
+            if (endPos == -1) {
+                url = url.substring(0, startPos);
             } else {
-                url = url.substring(0,startPos)
-                + url.substring(endPos,url.length());
+                url = url.substring(0, startPos)
+                        + url.substring(endPos, url.length());
             }
         }
         return url;
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
-     * Escape, but do not replace HTML.
-     * The default behaviour is to escape ampersands.
+     * Escape, but do not replace HTML. The default behaviour is to escape
+     * ampersands.
      */
     public static String escapeHTML(String s) {
         return escapeHTML(s, true);
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
      * Escape, but do not replace HTML.
-     * @param escapeAmpersand Optionally escape
-     * ampersands (&amp;).
+     * 
+     * @param escapeAmpersand
+     *            Optionally escape ampersands (&amp;).
      */
     public static String escapeHTML(String s, boolean escapeAmpersand) {
         // got to do amp's first so we don't double escape
@@ -133,26 +131,24 @@ public class Utilities {
         s = StringUtils.replace(s, ">", "&gt;");
         return s;
     }
-     
+
     public static String unescapeHTML(String str) {
-        return StringEscapeUtils.unescapeHtml(str);
+        return StringEscapeUtils.unescapeHtml4(str);
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
-     * Remove occurrences of html, defined as any text
-     * between the characters "&lt;" and "&gt;".  Replace
-     * any HTML tags with a space.
+     * Remove occurrences of html, defined as any text between the characters
+     * "&lt;" and "&gt;". Replace any HTML tags with a space.
      */
     public static String removeHTML(String str) {
         return removeHTML(str, true);
     }
-    
+
     /**
-     * Remove occurrences of html, defined as any text
-     * between the characters "&lt;" and "&gt;".
-     * Optionally replace HTML tags with a space.
-     *
+     * Remove occurrences of html, defined as any text between the characters
+     * "&lt;" and "&gt;". Optionally replace HTML tags with a space.
+     * 
      * @param str
      * @param addSpace
      * @return
@@ -172,14 +168,14 @@ public class Utilities {
         while (beginTag >= start) {
             if (beginTag > 0) {
                 ret.append(str.substring(start, beginTag));
-                
+
                 // replace each tag with a space (looks better)
                 if (addSpace) {
                     ret.append(" ");
                 }
             }
             endTag = str.indexOf('>', beginTag);
-            
+
             // if endTag found move "cursor" forward
             if (endTag > -1) {
                 start = endTag + 1;
@@ -197,32 +193,34 @@ public class Utilities {
         }
         return ret.toString().trim();
     }
-    
-    //------------------------------------------------------------------------
-    /** Run both removeHTML and escapeHTML on a string.
-     * @param s String to be run through removeHTML and escapeHTML.
+
+    // ------------------------------------------------------------------------
+    /**
+     * Run both removeHTML and escapeHTML on a string.
+     * 
+     * @param s
+     *            String to be run through removeHTML and escapeHTML.
      * @return String with HTML removed and HTML special characters escaped.
      */
-    public static String removeAndEscapeHTML( String s ) {
-        if ( s==null ) {
+    public static String removeAndEscapeHTML(String s) {
+        if (s == null) {
             return "";
-        }
-        else {
-            return Utilities.escapeHTML( Utilities.removeHTML(s) );
+        } else {
+            return Utilities.escapeHTML(Utilities.removeHTML(s));
         }
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
      * Autoformat.
      */
     public static String autoformat(String s) {
         return StringUtils.replace(s, "\n", "<br />");
     }
-    
-    
+
     /**
-     * Code (stolen from Pebble) to add rel="nofollow" string to all links in HTML.
+     * Code (stolen from Pebble) to add rel="nofollow" string to all links in
+     * HTML.
      */
     public static String addNofollow(String html) {
         if (html == null || html.length() == 0) {
@@ -236,8 +234,8 @@ public class Utilities {
             String link = html.substring(start, end);
             buf.append(html.substring(0, start));
             if (link.contains("rel=\"nofollow\"")) {
-                buf.append(
-                        link.substring(0, link.length() - 1) + " rel=\"nofollow\">");
+                buf.append(link.substring(0, link.length() - 1)
+                        + " rel=\"nofollow\">");
             } else {
                 buf.append(link);
             }
@@ -247,20 +245,18 @@ public class Utilities {
         buf.append(html);
         return buf.toString();
     }
-    
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
      * Replaces occurences of non-alphanumeric characters with an underscore.
      */
     public static String replaceNonAlphanumeric(String str) {
         return replaceNonAlphanumeric(str, '_');
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
-     * Replaces occurrences of non-alphanumeric characters with a
-     * supplied char.
+     * Replaces occurrences of non-alphanumeric characters with a supplied char.
      */
     public static String replaceNonAlphanumeric(String str, char subst) {
         StringBuilder ret = new StringBuilder(str.length());
@@ -269,13 +265,13 @@ public class Utilities {
             if (Character.isLetterOrDigit(testChars[i])) {
                 ret.append(testChars[i]);
             } else {
-                ret.append( subst );
+                ret.append(subst);
             }
         }
         return ret.toString();
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /**
      * Remove occurences of non-alphanumeric characters.
      */
@@ -284,116 +280,97 @@ public class Utilities {
         char[] testChars = str.toCharArray();
         for (int i = 0; i < testChars.length; i++) {
             // MR: Allow periods in page links
-            if (Character.isLetterOrDigit(testChars[i]) ||
-                    testChars[i] == '.') {
+            if (Character.isLetterOrDigit(testChars[i]) || testChars[i] == '.') {
                 ret.append(testChars[i]);
             }
         }
         return ret.toString();
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /** Convert string array to string with delimeters. */
     public static String stringArrayToString(String[] stringArray, String delim) {
-        String ret = "";
+        StringBuilder bldr = new StringBuilder();
         for (int i = 0; i < stringArray.length; i++) {
-            if (ret.length() > 0) {
-                ret = ret + delim + stringArray[i];
-            }
-            else {
-                ret = stringArray[i];
+            if (bldr.length() > 0) {
+                bldr.append(delim).append(stringArray[i]);
+            } else {
+                bldr.append(stringArray[i]);
             }
         }
-        return ret;
+        return bldr.toString();
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     /** Convert string array to string with delimeters. */
-    public static String stringListToString(List<String> stringList, String delim) {
-        String ret = "";
+    public static String stringListToString(List<String> stringList,
+            String delim) {
+        StringBuilder bldr = new StringBuilder();
         for (String s : stringList) {
-            if (ret.length() > 0) {
-                ret = ret + delim + s;
-            }
-            else {
-                ret = s;
+            if (bldr.length() > 0) {
+                bldr.append(delim).append(s);
+            } else {
+                bldr.append(s);
             }
         }
-        return ret;
+        return bldr.toString();
     }
-    
-    //--------------------------------------------------------------------------
+
+    // --------------------------------------------------------------------------
     /** Convert string with delimeters to string array. */
-    public static String[] stringToStringArray(String instr, String delim)
-    throws NoSuchElementException, NumberFormatException {
-        StringTokenizer toker = new StringTokenizer(instr, delim);
-        String stringArray[] = new String[toker.countTokens()];
-        int i = 0;
-        
-        while (toker.hasMoreTokens()) {
-            stringArray[i++] = toker.nextToken();
-        }
-        return stringArray;
-    }
-    
-    //--------------------------------------------------------------------------
-    /** Convert string with delimeters to string list. */
-    public static List<String> stringToStringList(String instr, String delim)
-    throws NoSuchElementException, NumberFormatException {
-        StringTokenizer toker = new StringTokenizer(instr, delim);
+    public static String[] stringToStringArray(String instr, String delim) {
+        return StringUtils.split(instr, delim);
+    }
+
+    // --------------------------------------------------------------------------
+    /** Convert string with delimiters to string list.
+     */
+    public static List<String> stringToStringList(String instr, String delim) {
         List<String> stringList = new ArrayList<String>();
-        while (toker.hasMoreTokens()) {
-            stringList.add(toker.nextToken());
-        }
+        String[] str = StringUtils.split(instr, delim);
+        Collections.addAll(stringList, str);
         return stringList;
     }
-    
-    //--------------------------------------------------------------------------
+
+    // --------------------------------------------------------------------------
     /** Convert string to integer array. */
-    public static int[] stringToIntArray(String instr, String delim)
-    throws NoSuchElementException, NumberFormatException {
-        StringTokenizer toker = new StringTokenizer(instr, delim);
-        int intArray[] = new int[toker.countTokens()];
+    public static int[] stringToIntArray(String instr, String delim) {
+        String[] str = StringUtils.split(instr, delim);
+        int intArray[] = new int[str.length];
         int i = 0;
-        
-        while (toker.hasMoreTokens()) {
-            String sInt = toker.nextToken();
-            int nInt = Integer.parseInt(sInt);
+        for (String string : str) {
+            int nInt = Integer.parseInt(string);
             intArray[i++] = nInt;
         }
         return intArray;
     }
-    
-    //-------------------------------------------------------------------
+
+    // -------------------------------------------------------------------
     /** Convert integer array to a string. */
     public static String intArrayToString(int[] intArray) {
-        String ret = "";
-        for (int i = 0; i < intArray.length; i++) {
-            if (ret.length() > 0) {
-                ret = ret + "," + Integer.toString(intArray[i]);
-            }
-            else {
-                ret = Integer.toString(intArray[i]);
+        StringBuilder bldr = new StringBuilder();
+        for (int s : intArray) {
+            if (bldr.length() > 0) {
+                bldr.append(",").append(Integer.toString(s));
+            } else {
+                bldr.append(Integer.toString(s));
             }
         }
-        return ret;
+        return bldr.toString();
     }
-    
-    //------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------
     public static void copyFile(File from, File to) throws IOException {
-        InputStream in = null;
-        OutputStream out = null;
-        
+        InputStream in;
+        OutputStream out;
+
         try {
             in = new FileInputStream(from);
         } catch (IOException ex) {
-            throw new IOException(
-                    "Utilities.copyFile: opening input stream '"
-                    + from.getPath()
-                    + "', "
-                    + ex.getMessage());
+            throw new IOException("Utilities.copyFile: opening input stream '"
+                    + from.getPath() + "', " + ex.getMessage());
         }
-        
+
         try {
             out = new FileOutputStream(to);
         } catch (Exception ex) {
@@ -401,16 +378,13 @@ public class Utilities {
                 in.close();
             } catch (IOException ex1) {
             }
-            throw new IOException(
-                    "Utilities.copyFile: opening output stream '"
-                    + to.getPath()
-                    + "', "
-                    + ex.getMessage());
+            throw new IOException("Utilities.copyFile: opening output stream '"
+                    + to.getPath() + "', " + ex.getMessage());
         }
-        
+
         copyInputToOutput(in, out, from.length());
     }
-    
+
     /**
      * Reads an inputstream into a string
      */
@@ -425,28 +399,25 @@ public class Utilities {
         return sb.toString();
     }
 
-    //------------------------------------------------------------------------
+    // ------------------------------------------------------------------------
     /**
-     * Utility method to copy an input stream to an output stream.
-     * Wraps both streams in buffers. Ensures right numbers of bytes copied.
+     * Utility method to copy an input stream to an output stream. Wraps both
+     * streams in buffers. Ensures right numbers of bytes copied.
      */
-    public static void copyInputToOutput(
-            InputStream input,
-            OutputStream output,
-            long byteCount)
-            throws IOException {
+    public static void copyInputToOutput(InputStream input,
+            OutputStream output, long byteCount) throws IOException {
         int bytes;
         long length;
-        
+
         BufferedInputStream in = new BufferedInputStream(input);
         BufferedOutputStream out = new BufferedOutputStream(output);
-        
+
         byte[] buffer;
-        buffer = new byte[8192];
-        
+        buffer = new byte[RollerConstants.EIGHT_KB_IN_BYTES];
+
         for (length = byteCount; length > 0;) {
-            bytes = (int) (length > 8192 ? 8192 : length);
-            
+            bytes = (int) (length > RollerConstants.EIGHT_KB_IN_BYTES ? RollerConstants.EIGHT_KB_IN_BYTES : length);
+
             try {
                 bytes = in.read(buffer, 0, bytes);
             } catch (IOException ex) {
@@ -455,16 +426,16 @@ public class Utilities {
                     out.close();
                 } catch (IOException ex1) {
                 }
-                throw new IOException(
-                        "Reading input stream, " + ex.getMessage());
+                throw new IOException("Reading input stream, "
+                        + ex.getMessage());
             }
-            
+
             if (bytes < 0) {
                 break;
             }
-            
+
             length -= bytes;
-            
+
             try {
                 out.write(buffer, 0, bytes);
             } catch (IOException ex) {
@@ -473,11 +444,11 @@ public class Utilities {
                     out.close();
                 } catch (IOException ex1) {
                 }
-                throw new IOException(
-                        "Writing output stream, " + ex.getMessage());
+                throw new IOException("Writing output stream, "
+                        + ex.getMessage());
             }
         }
-        
+
         try {
             in.close();
             out.close();
@@ -485,22 +456,20 @@ public class Utilities {
             throw new IOException("Closing file streams, " + ex.getMessage());
         }
     }
-    
-    //------------------------------------------------------------------------
-    public static void copyInputToOutput(
-            InputStream input,
-            OutputStream output)
+
+    // ------------------------------------------------------------------------
+    public static void copyInputToOutput(InputStream input, OutputStream output)
             throws IOException {
         BufferedInputStream in = new BufferedInputStream(input);
         BufferedOutputStream out = new BufferedOutputStream(output);
-        byte buffer[] = new byte[8192];
+        byte buffer[] = new byte[RollerConstants.EIGHT_KB_IN_BYTES];
         for (int count = 0; count != -1;) {
-            count = in.read(buffer, 0, 8192);
+            count = in.read(buffer, 0, RollerConstants.EIGHT_KB_IN_BYTES);
             if (count != -1) {
                 out.write(buffer, 0, count);
             }
         }
-        
+
         try {
             in.close();
             out.close();
@@ -508,23 +477,25 @@ public class Utilities {
             throw new IOException("Closing file streams, " + ex.getMessage());
         }
     }
-    
+
     /**
      * Encode a string using algorithm specified in web.xml and return the
-     * resulting encrypted password. If exception, the plain credentials
-     * string is returned
-     *
-     * @param password Password or other credentials to use in authenticating
-     *        this username
-     * @param algorithm Algorithm used to do the digest
-     *
+     * resulting encrypted password. If exception, the plain credentials string
+     * is returned
+     * 
+     * @param password
+     *            Password or other credentials to use in authenticating this
+     *            username
+     * @param algorithm
+     *            Algorithm used to do the digest
+     * 
      * @return encypted password based on the algorithm.
      */
     public static String encodePassword(String password, String algorithm) {
         byte[] unencodedPassword = password.getBytes();
-        
-        MessageDigest md = null;
-        
+
+        MessageDigest md;
+
         try {
             // first create an instance, given the provider
             md = MessageDigest.getInstance(algorithm);
@@ -532,37 +503,38 @@ public class Utilities {
             mLogger.error("Exception: " + e);
             return password;
         }
-        
+
         md.reset();
-        
+
         // call the update method one or more times
         // (useful when you don't know the size of your data, eg. stream)
         md.update(unencodedPassword);
-        
+
         // now calculate the hash
         byte[] encodedPassword = md.digest();
-        
+
         StringBuilder buf = new StringBuilder();
-        
+
         for (int i = 0; i < encodedPassword.length; i++) {
             if ((encodedPassword[i] & 0xff) < 0x10) {
                 buf.append("0");
             }
-            
+
             buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
         }
-        
+
         return buf.toString();
     }
-    
+
     /**
-     * Encode a string using Base64 encoding. Used when storing passwords
-     * as cookies.
-     *
-     * This is weak encoding in that anyone can use the decodeString
-     * routine to reverse the encoding.
-     *
-     * @param str String to encode
+     * Encode a string using Base64 encoding. Used when storing passwords as
+     * cookies.
+     * 
+     * This is weak encoding in that anyone can use the decodeString routine to
+     * reverse the encoding.
+     * 
+     * @param str
+     *            String to encode
      * @return String
      * @throws IOException
      */
@@ -570,11 +542,12 @@ public class Utilities {
         String encodedStr = new String(Base64.encodeBase64(str.getBytes()));
         return (encodedStr.trim());
     }
-    
+
     /**
      * Decode a string using Base64 encoding.
-     *
-     * @param str String to decode
+     * 
+     * @param str
+     *            String to decode
      * @return decoded string
      * @throws IOException
      */
@@ -582,78 +555,81 @@ public class Utilities {
         String value = new String(Base64.decodeBase64(str.getBytes()));
         return (value);
     }
-    
+
     /**
      * Strips HTML and truncates.
      */
-    public static String truncate(
-            String str, int lower, int upper, String appendToEnd) {
+    public static String truncate(String str, int lower, int upper,
+            String appendToEnd) {
         // strip markup from the string
         String str2 = removeHTML(str, false);
-        
+
         // quickly adjust the upper if it is set lower than 'lower'
         if (upper < lower) {
             upper = lower;
         }
-        
+
         // now determine if the string fits within the upper limit
         // if it does, go straight to return, do not pass 'go' and collect $200
-        if(str2.length() > upper) {
+        if (str2.length() > upper) {
             // the magic location int
             int loc;
-            
+
             // first we determine where the next space appears after lower
             loc = str2.lastIndexOf(' ', upper);
-            
+
             // now we'll see if the location is greater than the lower limit
-            if(loc >= lower) {
+            if (loc >= lower) {
                 // yes it was, so we'll cut it off here
                 str2 = str2.substring(0, loc);
             } else {
                 // no it wasnt, so we'll cut it off at the upper limit
                 str2 = str2.substring(0, upper);
             }
-            
+
             // the string was truncated, so we append the appendToEnd String
             str2 = str2 + appendToEnd;
         }
-        
+
         return str2;
     }
-    
+
     /**
      * This method based on code from the String taglib at Apache Jakarta:
-     * http://cvs.apache.org/viewcvs/jakarta-taglibs/string/src/org/apache/taglibs/string/util/StringW.java?rev=1.16&content-type=text/vnd.viewcvs-markup
-     * Copyright (c) 1999 The Apache Software Foundation.
-     * Author: timster@mac.com
-     *
+     * http:/
+     * /cvs.apache.org/viewcvs/jakarta-taglibs/string/src/org/apache/taglibs
+     * /string/util/StringW.java?rev=1.16&content-type=text/vnd.viewcvs-markup
+     * Copyright (c) 1999 The Apache Software Foundation. Author:
+     * timster@mac.com
+     * 
      * @param str
      * @param lower
      * @param upper
      * @param appendToEnd
      * @return
      */
-    public static String truncateNicely(String str, int lower, int upper, String appendToEnd) {
+    public static String truncateNicely(String str, int lower, int upper,
+            String appendToEnd) {
         // strip markup from the string
         String str2 = removeHTML(str, false);
         boolean diff = (str2.length() < str.length());
-        
+
         // quickly adjust the upper if it is set lower than 'lower'
-        if(upper < lower) {
+        if (upper < lower) {
             upper = lower;
         }
-        
+
         // now determine if the string fits within the upper limit
         // if it does, go straight to return, do not pass 'go' and collect $200
-        if(str2.length() > upper) {
+        if (str2.length() > upper) {
             // the magic location int
             int loc;
-            
+
             // first we determine where the next space appears after lower
             loc = str2.lastIndexOf(' ', upper);
-            
+
             // now we'll see if the location is greater than the lower limit
-            if(loc >= lower) {
+            if (loc >= lower) {
                 // yes it was, so we'll cut it off here
                 str2 = str2.substring(0, loc);
             } else {
@@ -661,29 +637,30 @@ public class Utilities {
                 str2 = str2.substring(0, upper);
                 loc = upper;
             }
-            
+
             // HTML was removed from original str
             if (diff) {
-                
+
                 // location of last space in truncated string
                 loc = str2.lastIndexOf(' ', loc);
-                
-                // get last "word" in truncated string (add 1 to loc to eliminate space
-                String str3 = str2.substring(loc+1);
-                
+
+                // get last "word" in truncated string (add 1 to loc to
+                // eliminate space
+                String str3 = str2.substring(loc + 1);
+
                 // find this fragment in original str, from 'loc' position
                 loc = str.indexOf(str3, loc) + str3.length();
-                
+
                 // get truncated string from original str, given new 'loc'
                 str2 = str.substring(0, loc);
-                
+
                 // get all the HTML from original str after loc
                 str3 = extractHTML(str.substring(loc));
-                
+
                 // remove any tags which generate visible HTML
                 // This call is unecessary, all HTML has already been stripped
-                //str3 = removeVisibleHTMLTags(str3);
-                
+                // str3 = removeVisibleHTMLTags(str3);
+
                 // append the appendToEnd String and
                 // add extracted HTML back onto truncated string
                 str = str2 + appendToEnd + str3;
@@ -691,32 +668,33 @@ public class Utilities {
                 // the string was truncated, so we append the appendToEnd String
                 str = str2 + appendToEnd;
             }
-            
+
         }
-        
+
         return str;
     }
-    
-    public static String truncateText(String str, int lower, int upper, String appendToEnd) {
+
+    public static String truncateText(String str, int lower, int upper,
+            String appendToEnd) {
         // strip markup from the string
         String str2 = removeHTML(str, false);
 
         // quickly adjust the upper if it is set lower than 'lower'
-        if(upper < lower) {
+        if (upper < lower) {
             upper = lower;
         }
-        
+
         // now determine if the string fits within the upper limit
         // if it does, go straight to return, do not pass 'go' and collect $200
-        if(str2.length() > upper) {
+        if (str2.length() > upper) {
             // the magic location int
             int loc;
-            
+
             // first we determine where the next space appears after lower
             loc = str2.lastIndexOf(' ', upper);
-            
+
             // now we'll see if the location is greater than the lower limit
-            if(loc >= lower) {
+            if (loc >= lower) {
                 // yes it was, so we'll cut it off here
                 str2 = str2.substring(0, loc);
             } else {
@@ -728,7 +706,7 @@ public class Utilities {
         }
         return str;
     }
-    
+
     /**
      * @param str
      * @return
@@ -739,69 +717,82 @@ public class Utilities {
         str = str.replaceAll("<br/>", "");
         str = str.replaceAll("<br />", "");
         str = str.replaceAll("<p></p>", "");
-        str = str.replaceAll("<p/>","");
-        str = str.replaceAll("<p />","");
+        str = str.replaceAll("<p/>", "");
+        str = str.replaceAll("<p />", "");
         return str;
     }
-    
+
     /**
      * Need need to get rid of any user-visible HTML tags once all text has been
-     * removed such as &lt;BR&gt;. This sounds like a better approach than removing
-     * all HTML tags and taking the chance to leave some tags un-closed.
-     *
+     * removed such as &lt;BR&gt;. This sounds like a better approach than
+     * removing all HTML tags and taking the chance to leave some tags
+     * un-closed.
+     * 
      * WARNING: this method has serious performance problems a
-     *
-     * @author Alexis Moussine-Pouchkine (alexis.moussine-pouchkine@france.sun.com)
+     * 
+     * @author Alexis Moussine-Pouchkine
+     *         (alexis.moussine-pouchkine@france.sun.com)
      * @author Lance Lavandowska
-     * @param str the String object to modify
+     * @param str
+     *            the String object to modify
      * @return the new String object without the HTML "visible" tags
      */
     private static String removeVisibleHTMLTags(String str) {
         str = stripLineBreaks(str);
         StringBuilder result = new StringBuilder(str);
         StringBuilder lcresult = new StringBuilder(str.toLowerCase());
-        
-        // <img should take care of smileys
-        String[] visibleTags = {"<img"}; // are there others to add?
+
+        // <img should take care of smileys, others to add?
+        String[] visibleTags = { "<img" };
         int stringIndex;
-        for ( int j = 0 ;  j < visibleTags.length ; j++ ) {
-            while ( (stringIndex = lcresult.indexOf(visibleTags[j])) != -1 ) {
-                if ( visibleTags[j].endsWith(">") )  {
-                    result.delete(stringIndex, stringIndex+visibleTags[j].length() );
-                    lcresult.delete(stringIndex, stringIndex+visibleTags[j].length() );
+        for (int j = 0; j < visibleTags.length; j++) {
+            while ((stringIndex = lcresult.indexOf(visibleTags[j])) != -1) {
+                if (visibleTags[j].endsWith(">")) {
+                    result.delete(stringIndex,
+                            stringIndex + visibleTags[j].length());
+                    lcresult.delete(stringIndex,
+                            stringIndex + visibleTags[j].length());
                 } else {
-                    // need to delete everything up until next closing '>', for <img for instance
+                    // need to delete everything up until next closing '>', for
+                    // <img for instance
                     int endIndex = result.indexOf(">", stringIndex);
                     if (endIndex > -1) {
-                        // only delete it if we find the end!  If we don't the HTML may be messed up, but we
+                        // only delete it if we find the end! If we don't the
+                        // HTML may be messed up, but we
                         // can't safely delete anything.
-                        result.delete(stringIndex, endIndex + 1 );
-                        lcresult.delete(stringIndex, endIndex + 1 );
+                        result.delete(stringIndex, endIndex + 1);
+                        lcresult.delete(stringIndex, endIndex + 1);
                     }
                 }
             }
         }
-        
-        // TODO:  This code is buggy by nature.  It doesn't deal with nesting of tags properly.
-        // remove certain elements with open & close tags
-        String[] openCloseTags = {"li", "a", "div", "h1", "h2", "h3", "h4"}; // more ?
+
+        // TODO: This code is buggy by nature. It doesn't deal with nesting of
+        // tags properly.
+        // remove certain elements with open & close tags, more available?
+        String[] openCloseTags = { "li", "a", "div", "h1", "h2", "h3", "h4" };
         for (int j = 0; j < openCloseTags.length; j++) {
             // could this be better done with a regular expression?
-            String closeTag = "</"+openCloseTags[j]+">";
+            String closeTag = "</" + openCloseTags[j] + ">";
             int lastStringIndex = 0;
-            while ((stringIndex = lcresult.indexOf( "<"+openCloseTags[j], lastStringIndex)) > -1) {
+            while ((stringIndex = lcresult.indexOf("<" + openCloseTags[j],
+                    lastStringIndex)) > -1) {
                 lastStringIndex = stringIndex;
-                // Try to find the matching closing tag  (ignores possible nesting!)
+                // Try to find the matching closing tag (ignores possible
+                // nesting!)
                 int endIndex = lcresult.indexOf(closeTag, stringIndex);
                 if (endIndex > -1) {
                     // If we found it delete it.
-                    result.delete(stringIndex, endIndex+closeTag.length());
-                    lcresult.delete(stringIndex, endIndex+closeTag.length());
+                    result.delete(stringIndex, endIndex + closeTag.length());
+                    lcresult.delete(stringIndex, endIndex + closeTag.length());
                 } else {
-                    // Try to see if it is a self-closed empty content tag, i.e. closed with />.
+                    // Try to see if it is a self-closed empty content tag, i.e.
+                    // closed with />.
                     endIndex = lcresult.indexOf(">", stringIndex);
-                    int nextStart = lcresult.indexOf("<", stringIndex+1);
-                    if (endIndex > stringIndex && lcresult.charAt(endIndex-1) == '/' && (endIndex < nextStart || nextStart == -1)) {
+                    int nextStart = lcresult.indexOf("<", stringIndex + 1);
+                    if (endIndex > stringIndex
+                            && lcresult.charAt(endIndex - 1) == '/'
+                            && (endIndex < nextStart || nextStart == -1)) {
                         // Looks like it, so remove it.
                         result.delete(stringIndex, endIndex + 1);
                         lcresult.delete(stringIndex, endIndex + 1);
@@ -809,12 +800,13 @@ public class Utilities {
                 }
             }
         }
-        
+
         return result.toString();
     }
-    
+
     /**
      * Extract (keep) JUST the HTML from the String.
+     * 
      * @param str
      * @return
      */
@@ -829,14 +821,14 @@ public class Utilities {
         if (beginTag == -1) {
             return str;
         }
-        
+
         while (beginTag >= start) {
             endTag = str.indexOf('>', beginTag);
-            
+
             // if endTag found, keep tag
             if (endTag > -1) {
-                ret.append( str.substring(beginTag, endTag+1) );
-                
+                ret.append(str.substring(beginTag, endTag + 1));
+
                 // move start forward and find another tag
                 start = endTag + 1;
                 beginTag = str.indexOf('<', start);
@@ -848,54 +840,59 @@ public class Utilities {
         }
         return ret.toString();
     }
-    
-    
+
     public static String hexEncode(String str) {
         if (StringUtils.isEmpty(str)) {
             return str;
         }
-        
+
         return RegexUtil.encode(str);
     }
-    
+
     public static String encodeEmail(String str) {
-        return str!=null ? RegexUtil.encodeEmail(str) : null;
+        return str != null ? RegexUtil.encodeEmail(str) : null;
     }
 
     /**
      * URL encoding.
-     * @param s a string to be URL-encoded
-     * @return URL encoding of s using character encoding UTF-8; null if s is null.
+     * 
+     * @param s
+     *            a string to be URL-encoded
+     * @return URL encoding of s using character encoding UTF-8; null if s is
+     *         null.
      */
     public static final String encode(String s) {
         try {
             if (s != null) {
                 return URLEncoder.encode(s, "UTF-8");
-            }
-            else {
+            } else {
                 return s;
             }
         } catch (UnsupportedEncodingException e) {
-            // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+            // Java Spec requires UTF-8 be in all Java environments, so this
+            // should not happen
             return s;
         }
     }
 
     /**
      * URL decoding.
-     * @param s a URL-encoded string to be URL-decoded
-     * @return URL decoded value of s using character encoding UTF-8; null if s is null.
+     * 
+     * @param s
+     *            a URL-encoded string to be URL-decoded
+     * @return URL decoded value of s using character encoding UTF-8; null if s
+     *         is null.
      */
     public static final String decode(String s) {
         try {
             if (s != null) {
                 return URLDecoder.decode(s, "UTF-8");
-            }
-            else {
+            } else {
                 return s;
             }
         } catch (UnsupportedEncodingException e) {
-            // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+            // Java Spec requires UTF-8 be in all Java environments, so this
+            // should not happen
             return s;
         }
     }
@@ -912,37 +909,38 @@ public class Utilities {
         }
         return 0;
     }
-                    
+
     /**
      * Convert a byte array into a Base64 string (as used in mime formats)
      */
     public static String toBase64(byte[] aValue) {
-        
-        final String strBase64Chars =
-                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-        
+
+        final String strBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
         int byte1;
         int byte2;
         int byte3;
         int iByteLen = aValue.length;
         StringBuilder tt = new StringBuilder();
-        
+
         for (int i = 0; i < iByteLen; i += 3) {
             boolean bByte2 = (i + 1) < iByteLen;
             boolean bByte3 = (i + 2) < iByteLen;
             byte1 = aValue[i] & 0xFF;
             byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
             byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
-            
+
             tt.append(strBase64Chars.charAt(byte1 / 4));
-            tt.append(strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
-            tt.append(((bByte2) ? strBase64Chars.charAt((byte3 / 64) + ((byte2 & 0xF) * 4)) : '='));
+            tt.append(strBase64Chars
+                    .charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
+            tt.append(((bByte2) ? strBase64Chars.charAt((byte3 / 64)
+                    + ((byte2 & 0xF) * 4)) : '='));
             tt.append(((bByte3) ? strBase64Chars.charAt(byte3 & 0x3F) : '='));
         }
-        
+
         return tt.toString();
     }
-    
+
     /**
      * @param tag
      * @return
@@ -958,9 +956,10 @@ public class Utilities {
             char c = charArray[i];
 
             // fast-path exclusions quotes and commas are obvious
+            // 34 = double-quote, 44 = comma
             switch (c) {
-            case 34: // "
-            case 44: // ,
+            case 34:
+            case 44:
                 continue;
             }
 
@@ -971,39 +970,39 @@ public class Utilities {
         }
         return sb.toString();
     }
-        
+
     public static String normalizeTag(String tag, Locale locale) {
         tag = Utilities.stripInvalidTagCharacters(tag);
-        return locale == null ? tag.toLowerCase() : tag.toLowerCase(locale);        
+        return locale == null ? tag.toLowerCase() : tag.toLowerCase(locale);
     }
-    
+
     /**
      * @param tags
      * @return
      */
-    public static List splitStringAsTags(String tags)  {
+    public static List splitStringAsTags(String tags) {
         String[] tagsarr = StringUtils.split(tags, TAG_SPLIT_CHARS);
-        if(tagsarr == null) {
-            return Collections.EMPTY_LIST;
+        if (tagsarr == null) {
+            return Collections.emptyList();
         }
         return Arrays.asList(tagsarr);
     }
-    
-    
+
     /**
      * Transforms the given String into a subset of HTML displayable on a web
      * page. The subset includes &lt;b&gt;, &lt;i&gt;, &lt;p&gt;, &lt;br&gt;,
      * &lt;pre&gt; and &lt;a href&gt; (and their corresponding end tags).
-     *
-     * @param s   the String to transform
-     * @return    the transformed String
+     * 
+     * @param s
+     *            the String to transform
+     * @return the transformed String
      */
     public static String transformToHTMLSubset(String s) {
-        
+
         if (s == null) {
             return null;
         }
-        
+
         s = replace(s, OPENING_B_TAG_PATTERN, "<b>");
         s = replace(s, CLOSING_B_TAG_PATTERN, "</b>");
         s = replace(s, OPENING_I_TAG_PATTERN, "<i>");
@@ -1022,7 +1021,7 @@ public class Utilities {
         s = replace(s, OPENING_LI_TAG_PATTERN, "<li>");
         s = replace(s, CLOSING_LI_TAG_PATTERN, "</li>");
         s = replace(s, QUOTE_PATTERN, "\"");
-        
+
         // HTTP links
         s = replace(s, CLOSING_A_TAG_PATTERN, "</a>");
         Matcher m = OPENING_A_TAG_PATTERN.matcher(s);
@@ -1034,17 +1033,17 @@ public class Utilities {
             s = s.substring(0, start) + link + s.substring(end, s.length());
             m = OPENING_A_TAG_PATTERN.matcher(s);
         }
-        
+
         // escaped angle brackets
         s = s.replaceAll("&amp;lt;", "&lt;");
         s = s.replaceAll("&amp;gt;", "&gt;");
         s = s.replaceAll("&amp;#", "&#");
-        
+
         return s;
     }
-    
-    
-    private static String replace(String string, Pattern pattern, String replacement) {
+
+    private static String replace(String string, Pattern pattern,
+            String replacement) {
         Matcher m = pattern.matcher(string);
         return m.replaceAll(replacement);
     }
@@ -1052,17 +1051,18 @@ public class Utilities {
     public static String getContentTypeFromFileName(String fileName) {
 
         FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
-        
+
         // TODO: figure out why PNG is missing from Java MIME types
         if (map instanceof MimetypesFileTypeMap) {
             try {
-                ((MimetypesFileTypeMap)map).addMimeTypes("image/png png PNG");
-            } catch (Exception ignored) {}
+                ((MimetypesFileTypeMap) map).addMimeTypes("image/png png PNG");
+            } catch (Exception ignored) {
+            }
         }
 
         return map.getContentType(fileName);
     }
-    
+
     /**
      * Validate the form of an email address.
      * 
@@ -1095,7 +1095,7 @@ public class Utilities {
         }
         return result;
     }
-    
+
     /**
      * Checks for name and domain.
      * 
@@ -1108,5 +1108,5 @@ public class Utilities {
         return tokens.length == 2 && StringUtils.isNotEmpty(tokens[0])
                 && StringUtils.isNotEmpty(tokens[1]);
     }
-    
+
 }

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/Cache.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/Cache.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/Cache.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/Cache.java Sun Apr 20 13:38:51 2014
@@ -59,6 +59,6 @@ public interface Cache {
     /**
      * get cache stats.
      */
-    Map getStats();
+    Map<String, Object> getStats();
     
 }

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CacheManager.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CacheManager.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CacheManager.java Sun Apr 20 13:38:51 2014
@@ -20,7 +20,6 @@ package org.apache.roller.weblogger.util
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import org.apache.commons.logging.Log;
@@ -61,10 +60,10 @@ public final class CacheManager {
     private static CacheFactory cacheFactory = null;
     
     // a set of all registered cache handlers
-    private static Set cacheHandlers = new HashSet();
+    private static Set<CacheHandler> cacheHandlers = new HashSet<CacheHandler>();
     
     // a map of all registered caches
-    private static Map caches = new HashMap();
+    private static Map<String, Cache> caches = new HashMap<String, Cache>();
     
     
     static {
@@ -104,10 +103,10 @@ public final class CacheManager {
         if(customHandlers != null && customHandlers.trim().length() > 0) {
             
             String[] cHandlers = customHandlers.split(",");
-            for(int i=0; i < cHandlers.length; i++) {
+            for (String cHandler : cHandlers) {
                 // use reflection to instantiate the handler class
                 try {
-                    Class handlerClass = Class.forName(cHandlers[i]);
+                    Class handlerClass = Class.forName(cHandler);
                     CacheHandler customHandler = 
                             (CacheHandler) handlerClass.newInstance();
                     
@@ -116,7 +115,7 @@ public final class CacheManager {
                     log.error("It appears that your handler does not implement "+
                             "the CacheHandler interface",cce);
                 } catch(Exception e) {
-                    log.error("Unable to instantiate cache handler ["+cHandlers[i]+"]", e);
+                    log.error("Unable to instantiate cache handler ["+cHandler+"]", e);
                 }
             }
         }
@@ -201,9 +200,9 @@ public final class CacheManager {
      * invalidated.
      */
     public static void registerHandler(CacheHandler handler) {
-        
+
         log.debug("Registering handler "+handler);
-        
+
         if(handler != null) {
             cacheHandlers.add(handler);
         }
@@ -213,10 +212,8 @@ public final class CacheManager {
     public static void invalidate(WeblogEntry entry) {
         
         log.debug("invalidating entry = "+entry.getAnchor());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(entry);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(entry);
         }
     }
     
@@ -224,10 +221,8 @@ public final class CacheManager {
     public static void invalidate(Weblog website) {
         
         log.debug("invalidating website = "+website.getHandle());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(website);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(website);
         }
     }
     
@@ -235,10 +230,8 @@ public final class CacheManager {
     public static void invalidate(WeblogBookmark bookmark) {
         
         log.debug("invalidating bookmark = "+bookmark.getId());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(bookmark);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(bookmark);
         }
     }
     
@@ -246,10 +239,8 @@ public final class CacheManager {
     public static void invalidate(WeblogBookmarkFolder folder) {
         
         log.debug("invalidating folder = "+folder.getId());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(folder);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(folder);
         }
     }
     
@@ -257,10 +248,8 @@ public final class CacheManager {
     public static void invalidate(WeblogEntryComment comment) {
         
         log.debug("invalidating comment = "+comment.getId());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(comment);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(comment);
         }
     }
     
@@ -272,10 +261,8 @@ public final class CacheManager {
         // NOTE: Invalidating an entire website for each referer is not
         //       good for our caching.  This may need reevaluation later.
         //lastExpiredCache.put(referer.getWebsite().getHandle(), new Date());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(referer);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(referer);
         }
     }
     
@@ -283,32 +270,25 @@ public final class CacheManager {
     public static void invalidate(User user) {
         
         log.debug("invalidating user = "+user.getUserName());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(user);
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(user);
         }
     }
     
     
     public static void invalidate(WeblogCategory category) {
         
-        log.debug("invalidating category = "+category.getId());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(category);
+        log.debug("invalidating category = " + category.getId());
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(category);
         }
     }
     
     
     public static void invalidate(WeblogTemplate template) {
-        
-        log.debug("invalidating template = "+template.getId());
-        
-        Iterator handlers = cacheHandlers.iterator();
-        while(handlers.hasNext()) {
-            ((CacheHandler) handlers.next()).invalidate(template);
+        log.debug("invalidating template = " + template.getId());
+        for (CacheHandler handler : cacheHandlers) {
+            handler.invalidate(template);
         }
     }
 
@@ -317,13 +297,7 @@ public final class CacheManager {
      * Flush the entire cache system.
      */
     public static void clear() {
-        
-        // loop through all caches and trigger a clear
-        Cache cache = null;
-        Iterator cachesIT = caches.values().iterator();
-        while(cachesIT.hasNext()) {
-            cache = (Cache) cachesIT.next();
-            
+        for (Cache cache : caches.values()) {
             cache.clear();
         }
     }
@@ -333,8 +307,7 @@ public final class CacheManager {
      * Flush a single cache.
      */
     public static void clear(String cacheId) {
-        
-        Cache cache = (Cache) caches.get(cacheId);
+        Cache cache = caches.get(cacheId);
         if(cache != null) {
             cache.clear();
         }
@@ -349,18 +322,11 @@ public final class CacheManager {
      * This is here with the full expectation that it will be replaced by
      * something a bit more elaborate, like JMX.
      */
-    public static Map getStats() {
-        
-        Map allStats = new HashMap();
-        
-        Cache cache = null;
-        Iterator cachesIT = caches.values().iterator();
-        while(cachesIT.hasNext()) {
-            cache = (Cache) cachesIT.next();
-            
+    public static Map<String, Map<String, Object>> getStats() {
+        Map<String, Map<String, Object>> allStats = new HashMap<String, Map<String, Object>>();
+        for (Cache cache : caches.values()) {
             allStats.put(cache.getId(), cache.getStats());
         }
-        
         return allStats;
     }
     

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CachedContent.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CachedContent.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CachedContent.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/CachedContent.java Sun Apr 20 13:38:51 2014
@@ -9,6 +9,7 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
 
 
 /**
@@ -18,9 +19,6 @@ public class CachedContent implements Se
     
     private static Log log = LogFactory.getLog(CachedContent.class);
     
-    // default to an 8K buffered cache
-    public static final int DEFAULT_SIZE = 8192;
-    
     // the byte array we use to maintain the cached content
     private byte[] content = new byte[0];
     
@@ -40,7 +38,7 @@ public class CachedContent implements Se
         if(size > 0) {
             this.outstream = new ByteArrayOutputStream(size);
         } else {
-            this.outstream = new ByteArrayOutputStream(DEFAULT_SIZE);
+            this.outstream = new ByteArrayOutputStream(RollerConstants.EIGHT_KB_IN_BYTES);
         }
         
         // construct writer from output stream

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheFactoryImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheFactoryImpl.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheFactoryImpl.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheFactoryImpl.java Sun Apr 20 13:38:51 2014
@@ -63,7 +63,7 @@ public class ExpiringLRUCacheFactoryImpl
         
         Cache cache = new ExpiringLRUCacheImpl(id, size, timeout);
         
-        log.debug("new cache constructed. size="+size+", timeout="+timeout);
+        log.debug("new cache constructed. size=" + size + ", timeout=" + timeout);
         
         return cache;
     }

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheImpl.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheImpl.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/ExpiringLRUCacheImpl.java Sun Apr 20 13:38:51 2014
@@ -20,6 +20,7 @@ package org.apache.roller.weblogger.util
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
 
 
 /**
@@ -35,7 +36,7 @@ public class ExpiringLRUCacheImpl extend
     protected ExpiringLRUCacheImpl(String id) {
         
         super(id);
-        this.timeout = 60 * 60 * 1000;
+        this.timeout = RollerConstants.HOUR_IN_MS;
     }
     
     
@@ -44,8 +45,8 @@ public class ExpiringLRUCacheImpl extend
         super(id, maxsize);
         
         // timeout is specified in seconds; only positive values allowed
-        if(timeout > 0) {
-            this.timeout = timeout * 1000;
+        if (timeout > 0) {
+            this.timeout = timeout * RollerConstants.SEC_IN_MS;
         }
     }
     

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheFactoryImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheFactoryImpl.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheFactoryImpl.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheFactoryImpl.java Sun Apr 20 13:38:51 2014
@@ -39,7 +39,6 @@ public class LRUCacheFactoryImpl impleme
      * Construct a new instance of a Roller LRUCache.
      */
     public Cache constructCache(Map properties) {
-        
         int size = 100;
         String id = "unknown";
         
@@ -50,7 +49,7 @@ public class LRUCacheFactoryImpl impleme
         }
         
         String cacheId = (String) properties.get("id");
-        if(cacheId != null) {
+        if (cacheId != null) {
             id = cacheId;
         }
         

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheImpl.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheImpl.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/cache/LRUCacheImpl.java Sun Apr 20 13:38:51 2014
@@ -23,8 +23,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
 
 
 /**
@@ -32,8 +31,6 @@ import org.apache.commons.logging.LogFac
  */
 public class LRUCacheImpl implements Cache {
     
-    private static Log log = LogFactory.getLog(LRUCacheImpl.class);
-    
     private String id = null;
     private Map cache = null;
     
@@ -112,19 +109,19 @@ public class LRUCacheImpl implements Cac
     }
     
     
-    public Map getStats() {
+    public Map<String, Object> getStats() {
         
-        Map stats = new HashMap();
+        Map<String, Object> stats = new HashMap<String, Object>();
         stats.put("startTime", this.startTime);
-        stats.put("hits", new Double(this.hits));
-        stats.put("misses", new Double(this.misses));
-        stats.put("puts", new Double(this.puts));
-        stats.put("removes", new Double(this.removes));
+        stats.put("hits", this.hits);
+        stats.put("misses", this.misses);
+        stats.put("puts", this.puts);
+        stats.put("removes", this.removes);
         
         // calculate efficiency
         if((misses - removes) > 0) {
             double efficiency = hits / (misses + hits);
-            stats.put("efficiency", new Double(efficiency * 100));
+            stats.put("efficiency", efficiency * RollerConstants.PERCENT_100);
         }
         
         return stats;

Propchange: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/
------------------------------------------------------------------------------
  Merged /roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices:r1546818-1588713

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java Sun Apr 20 13:38:51 2014
@@ -23,6 +23,7 @@ import com.sun.syndication.feed.atom.Ent
 import com.sun.syndication.feed.atom.Feed;
 import com.sun.syndication.feed.atom.Link;
 import com.sun.syndication.feed.atom.Person;
+import com.sun.syndication.feed.module.Module;
 import com.sun.syndication.feed.synd.SyndPerson;
 import org.rometools.propono.atom.common.rome.AppModule;
 import org.rometools.propono.atom.common.rome.AppModuleImpl;
@@ -35,12 +36,11 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
@@ -53,6 +53,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.WeblogCategory;
 import org.apache.roller.weblogger.pojos.WeblogEntry;
+import org.apache.roller.weblogger.pojos.WeblogEntrySearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogEntryTag;
 import org.apache.roller.weblogger.pojos.WeblogEntryTagComparator;
 import org.apache.roller.weblogger.util.Utilities;
@@ -114,8 +115,8 @@ public class EntryCollection {
 
             rollerEntry = mgr.getWeblogEntry(rollerEntry.getId());
             Entry newEntry = createAtomEntry(rollerEntry);
-            for (Iterator it = newEntry.getOtherLinks().iterator(); it.hasNext();) {
-                Link link = (Link)it.next();
+            for (Object objLink : newEntry.getOtherLinks()) {
+                Link link = (Link) objLink;
                 if ("edit".equals(link.getRel())) {
                     log.debug("Exiting");
                     return createAtomEntry(rollerEntry);
@@ -172,20 +173,12 @@ public class EntryCollection {
             if (!RollerAtomHandler.canView(user, website)) {
                 throw new AtomNotAuthorizedException("Not authorized to access website: " + handle);
             }
-            List entries = roller.getWeblogEntryManager().getWeblogEntries( 
-                    website,           // website
-                    null,              // user
-                    null,              // startDate
-                    null,              // endDate
-                    null,              // catName
-                    null,              // tags
-                    null,              // status
-                    null,              // text
-                    "updateTime",      // sortby
-                    null,
-                    null,              // locale
-                    start,             // offset (for range paging)
-                    max + 1);          // MAX_ENTRIES
+            WeblogEntrySearchCriteria wesc = new WeblogEntrySearchCriteria();
+            wesc.setWeblog(website);
+            wesc.setSortBy(WeblogEntrySearchCriteria.SortBy.UPDATE_TIME);
+            wesc.setOffset(start);
+            wesc.setMaxResults(max + 1);
+            List<WeblogEntry> entries = roller.getWeblogEntryManager().getWeblogEntries(wesc);
             Feed feed = new Feed();
             feed.setId(atomURL
                 +"/"+website.getHandle() + "/entries/" + start);
@@ -197,18 +190,20 @@ public class EntryCollection {
             link.setType("text/html");
             feed.setAlternateLinks(Collections.singletonList(link));
 
-            List atomEntries = new ArrayList();
+            List<Entry> atomEntries = new ArrayList<Entry>();
             int count = 0;
-            for (Iterator iter = entries.iterator(); iter.hasNext() && count < MAX_ENTRIES; count++) {
-                WeblogEntry rollerEntry = (WeblogEntry)iter.next();
+            for (WeblogEntry rollerEntry : entries) {
+                if (count++ >= MAX_ENTRIES) {
+                    break;
+                }
                 Entry entry = createAtomEntry(rollerEntry);
                 atomEntries.add(entry);
-                if (count == 0) {
+                if (count == 1) {
                     // first entry is most recent
                     feed.setUpdated(entry.getUpdated());
                 }
             }
-            List links = new ArrayList();
+            List<Link> links = new ArrayList<Link>();
             if (entries.size() > max) {
                 // add next link
                 int nextOffset = start + max;
@@ -326,7 +321,7 @@ public class EntryCollection {
         Content content = new Content();
         content.setType(Content.HTML);
         content.setValue(entry.getText());
-        List contents = new ArrayList();
+        List<Content> contents = new ArrayList<Content>();
         contents.add(content);
         
         atomEntry.setContents(contents);
@@ -345,17 +340,16 @@ public class EntryCollection {
         atomEntry.setAuthors(   (List<SyndPerson>)Collections.singletonList(author));
         
         // Add Atom category for Weblogger category, using category scheme
-        List categories = new ArrayList();
+        List<Category> categories = new ArrayList<Category>();
         Category atomCat = new Category();
         atomCat.setScheme(RollerAtomService.getWeblogCategoryScheme(entry.getWebsite()));
-        atomCat.setTerm(entry.getCategory().getPath().substring(1));
+        atomCat.setTerm(entry.getCategory().getName());
         categories.add(atomCat);
         
         // Add Atom categories for each Weblogger tag with null scheme
         Set<WeblogEntryTag> tmp = new TreeSet<WeblogEntryTag>(new WeblogEntryTagComparator());
         tmp.addAll(entry.getTags());
-        for (Iterator tagit = tmp.iterator(); tagit.hasNext();) {
-            WeblogEntryTag tag = (WeblogEntryTag) tagit.next();
+        for (WeblogEntryTag tag : tmp) {
             Category newcat = new Category();
             newcat.setTerm(tag.getName());
             categories.add(newcat);
@@ -365,7 +359,7 @@ public class EntryCollection {
         Link altlink = new Link();
         altlink.setRel("alternate");
         altlink.setHref(entry.getPermalink());
-        List altlinks = new ArrayList();
+        List<Link> altlinks = new ArrayList<Link>();
         altlinks.add(altlink);
         atomEntry.setAlternateLinks(altlinks);
         
@@ -374,11 +368,11 @@ public class EntryCollection {
         editlink.setHref(
                 atomURL
                 +"/"+entry.getWebsite().getHandle() + "/entry/" + entry.getId());
-        List otherlinks = new ArrayList();
+        List<Link> otherlinks = new ArrayList<Link>();
         otherlinks.add(editlink);
         atomEntry.setOtherLinks(otherlinks);
         
-        List modules = new ArrayList();
+        List<Module> modules = new ArrayList<Module>();
         AppModule app = new AppModuleImpl();
         app.setDraft(!WeblogEntry.PUBLISHED.equals(entry.getStatus()));
         app.setEdited(entry.getUpdateTime());
@@ -425,17 +419,15 @@ public class EntryCollection {
         // Atom categories with weblog-level scheme are Weblogger categories.
         // Atom supports multiple cats, but Weblogger supports one/entry
         // so here we take accept the first category that exists.
-        List categories = entry.getCategories();
+        List<Category> categories = entry.getCategories();
         if (categories != null && categories.size() > 0) {
-            for (int i=0; i<categories.size(); i++) {
-                Category cat = (Category)categories.get(i);
-                
+            for (Category cat : categories) {
                 if (cat.getScheme() != null && cat.getScheme().equals(
                         RollerAtomService.getWeblogCategoryScheme(rollerEntry.getWebsite()))) {
                     String catString = cat.getTerm();
                     if (catString != null) {
                         WeblogCategory rollerCat =
-                                roller.getWeblogEntryManager().getWeblogCategoryByPath(
+                                roller.getWeblogEntryManager().getWeblogCategoryByName(
                                 rollerEntry.getWebsite(), catString);
                         if (rollerCat != null) {
                             // Found a valid category, so break out
@@ -456,8 +448,7 @@ public class EntryCollection {
         String tags = "";
         StringBuilder buff = new StringBuilder();
         if (categories != null && categories.size() > 0) {
-            for (int i=0; i<categories.size(); i++) {
-                Category cat = (Category)categories.get(i);            
+            for (Category cat : categories) {
                 if (cat.getScheme() == null) {
                     buff.append(" ").append(cat.getTerm());
                 }                

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java Sun Apr 20 13:38:51 2014
@@ -38,20 +38,18 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.StringTokenizer;
 import java.util.TreeSet;
 import java.util.UUID;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.FileIOException;
 import org.apache.roller.weblogger.business.MediaFileManager;
-import org.apache.roller.weblogger.business.URLStrategy;
 import org.apache.roller.weblogger.business.WeblogManager;
 import org.apache.roller.weblogger.business.Weblogger;
 import org.apache.roller.weblogger.business.WebloggerFactory;
@@ -131,9 +129,6 @@ public class MediaCollection {
                         throw new AtomException("Duplicate file name");
                     }
 
-                    if (path.length() > 0) {
-                        path = path + File.separator;
-                    }
                     FileInputStream fis = new FileInputStream(tempFile);
 
                     MediaFile mf = new MediaFile();
@@ -157,8 +152,8 @@ public class MediaCollection {
                                       
                     MediaFile stored = fileMgr.getMediaFile(mf.getId());
                     Entry mediaEntry = createAtomResourceEntry(website, stored);
-                    for (Iterator it = mediaEntry.getOtherLinks().iterator(); it.hasNext();) {
-                        Link link = (Link)it.next();
+                    for (Object objLink : mediaEntry.getOtherLinks()) {
+                        Link link = (Link) objLink;
                         if ("edit".equals(link.getRel())) {
                             log.debug("Exiting");
                             return mediaEntry;
@@ -254,9 +249,7 @@ public class MediaCollection {
                 try {
                     start = Integer.parseInt(rawPathInfo[rawPathInfo.length - 1]);
                     pathInfo = new String[rawPathInfo.length - 1];
-                    for (int i=0; i < rawPathInfo.length - 1; i++) {
-                        pathInfo[i] = rawPathInfo[i];
-                    }
+                    System.arraycopy(rawPathInfo, 0, pathInfo, 0, rawPathInfo.length - 1);
                 } catch (Exception ingored) {}
             }
             String path = filePathFromPathInfo(pathInfo);
@@ -496,8 +489,6 @@ public class MediaCollection {
         String editMediaURI = 
                 atomURL+"/"+ website.getHandle()
                 + "/resource/" + filePath;
-        URLStrategy urlStrategy = WebloggerFactory.getWeblogger().getUrlStrategy();
-        
         String contentType = Utilities.getContentTypeFromFileName(file.getName());
         
         Entry entry = new Entry();

Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java Sun Apr 20 13:38:51 2014
@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletReq
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
 import org.apache.roller.weblogger.business.Weblogger;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.User;
@@ -41,7 +42,7 @@ import javax.servlet.http.HttpServletRes
 import net.oauth.OAuthAccessor;
 import net.oauth.OAuthMessage;
 import net.oauth.server.OAuthServlet;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.OAuthManager;
 import org.apache.roller.weblogger.config.WebloggerConfig;
@@ -95,14 +96,14 @@ public class RollerAtomHandler implement
     protected int maxEntries = 20;
     protected String atomURL = null;
     
-    protected static boolean throttle = true;
+    protected static final boolean THROTTLE;
     
     protected static Log log =
             LogFactory.getFactory().getInstance(RollerAtomHandler.class);
     
     static {
-        throttle = WebloggerConfig
-            .getBooleanProperty("webservices.atomprotocol.oneSecondThrottle");
+        THROTTLE = WebloggerConfig
+            .getBooleanProperty("webservices.atomprotocol.oneSecondThrottle", true);
     }
     
     //------------------------------------------------------------ construction
@@ -115,14 +116,15 @@ public class RollerAtomHandler implement
     public RollerAtomHandler(HttpServletRequest request, HttpServletResponse response) {
         roller = WebloggerFactory.getWeblogger();
 
-        String userName = null;
+        String userName;
         if ("oauth".equals(WebloggerRuntimeConfig.getProperty("webservices.atomPubAuth"))) {
             userName = authenticationOAUTH(request, response);
 
         } else if ("wsse".equals(WebloggerRuntimeConfig.getProperty("webservices.atomPubAuth"))) {
             userName = authenticateWSSE(request);
 
-        } else { // default to basic
+        } else {
+            // default to basic
             userName = authenticateBASIC(request);
         }
 
@@ -225,12 +227,11 @@ public class RollerAtomHandler implement
     public Entry getEntry(AtomRequest areq) throws AtomException {
         log.debug("Entering");
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length > 2) // URI is /blogname/entries/entryid
-        {
+        // URI is /blogname/entries/entryid
+        if (pathInfo.length > 2) {
             if (pathInfo[1].equals("entry")) {
                 EntryCollection ecol = new EntryCollection(user, atomURL);
                 return ecol.getEntry(areq);
-
             } else if (pathInfo[1].equals("resource") && pathInfo[pathInfo.length - 1].endsWith(".media-link")) {
                 MediaCollection mcol = new MediaCollection(user, atomURL);
                 return mcol.getEntry(areq);                    
@@ -278,12 +279,11 @@ public class RollerAtomHandler implement
         log.debug("Entering");
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
         if (pathInfo.length > 2) {
-            if (pathInfo[1].equals("entry")) // URI is /blogname/entry/entryid
-            {                    
+            // URI is /blogname/entry/entryid
+            if (pathInfo[1].equals("entry")) {
                 EntryCollection ecol = new EntryCollection(user, atomURL);
                 ecol.deleteEntry(areq);
                 return;
-
             } else if (pathInfo[1].equals("resource")) {
                 MediaCollection mcol = new MediaCollection(user, atomURL);
                 mcol.deleteEntry(areq);
@@ -301,10 +301,7 @@ public class RollerAtomHandler implement
      */
     public boolean isAtomServiceURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length==0) {
-            return true;
-        }
-        return false;
+        return pathInfo.length == 0;
     }
     
     /**
@@ -322,7 +319,7 @@ public class RollerAtomHandler implement
     }
         
     /**
-     * True if URL is media edit URI. Media can be udpated, but not metadata.
+     * True if URL is media edit URI. Media can be updated, but not metadata.
      */
     public boolean isMediaEditURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
@@ -383,14 +380,14 @@ public class RollerAtomHandler implement
     /**
      * Return true if user is allowed to view an entry.
      */
-    public static  boolean canView(User u, WeblogEntry entry) {
+    public static boolean canView(User u, WeblogEntry entry) {
         return canEdit(u, entry);
     }
     
     /**
      * Return true if user is allowed to view a website.
      */
-    public static  boolean canView(User u, Weblog website) {
+    public static boolean canView(User u, Weblog website) {
         return canEdit(u, website);
     }
     
@@ -517,10 +514,10 @@ public class RollerAtomHandler implement
     public static void oneSecondThrottle() {
         // Throttle one entry per second per weblog because time-
         // stamp in MySQL and other DBs has only 1 sec resolution
-        if (throttle) {
+        if (THROTTLE) {
             try {
                 synchronized (RollerAtomHandler.class) {
-                    Thread.sleep(1000);
+                    Thread.sleep(RollerConstants.SEC_IN_MS);
                 }
             } catch (Exception ignored) {}
         }



Mime
View raw message