Modified: 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java?rev=1520953&r1=1520952&r2=1520953&view=diff
==============================================================================
--- 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java 
(original)
+++ 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java 
Mon Sep  9 02:49:44 2013
@@ -87,7 +87,6 @@ public class MailUtil {
         }
         
         try {
-            UserManager umgr = 
WebloggerFactory.getWeblogger().getUserManager();
             WeblogManager wmgr = 
WebloggerFactory.getWeblogger().getWeblogManager();
             
             String userName = entry.getCreator().getUserName();
@@ -159,9 +158,6 @@ public class MailUtil {
         }
         
         try {
-            UserManager umgr = 
WebloggerFactory.getWeblogger().getUserManager();
-            
-            String userName = user.getUserName();
             String from = website.getEmailAddress();
             String cc[] = new String[] {from};
             String bcc[] = new String[0];
@@ -302,21 +298,18 @@ public class MailUtil {
             List comments = entry.getComments(true, true);
             for (Iterator it = comments.iterator(); it.hasNext();) {
                 WeblogEntryComment comment = (WeblogEntryComment) it.next();
-                if (!StringUtils.isEmpty(comment.getEmail())) {
-                    // If user has commented twice,
-                    // count the most recent notify setting
-                    if (commentObject.getApproved()) {
-                        if (comment.getNotify().booleanValue()) {
-                            // only add those with valid email
-                            if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) 
{
-                                log.info("Add to subscribers list : " + 
comment.getEmail());
-                                subscribers.add(comment.getEmail());
-                            }
-                        } else {
-                            // remove user who doesn't want to be notified
-                            log.info("Remove from subscribers list : " + 
comment.getEmail());
-                            subscribers.remove(comment.getEmail());
+                if (!StringUtils.isEmpty(comment.getEmail()) && 
commentObject.getApproved()) {
+                    // If user has commented twice, count the most recent 
notify setting
+                    if (comment.getNotify()) {
+                        // only add those with valid email
+                        if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) {
+                            log.info("Add to subscribers list : " + 
comment.getEmail());
+                            subscribers.add(comment.getEmail());
                         }
+                    } else {
+                        // remove user who doesn't want to be notified
+                        log.info("Remove from subscribers list : " + 
comment.getEmail());
+                        subscribers.remove(comment.getEmail());
                     }
                 }
             }
@@ -612,7 +605,9 @@ public class MailUtil {
         if (! StringUtils.isEmpty(from)) {
             InternetAddress sentFrom = new InternetAddress(from);
             message.setFrom(sentFrom);
-            if (log.isDebugEnabled()) log.debug("e-mail from: " + sentFrom);
+            if (log.isDebugEnabled()) {
+                log.debug("e-mail from: " + sentFrom);
+            }
         }
         
         if (to!=null) {
@@ -620,7 +615,9 @@ public class MailUtil {
             
             for (int i = 0; i < to.length; i++) {
                 sendTo[i] = new InternetAddress(to[i]);
-                if (log.isDebugEnabled()) log.debug("sending e-mail to: " + 
to[i]);
+                if (log.isDebugEnabled()) {
+                    log.debug("sending e-mail to: " + to[i]);
+                }
             }
             message.setRecipients(Message.RecipientType.TO, sendTo);
         }
@@ -630,7 +627,9 @@ public class MailUtil {
             
             for (int i = 0; i < cc.length; i++) {
                 copyTo[i] = new InternetAddress(cc[i]);
-                if (log.isDebugEnabled()) log.debug("copying e-mail to: " + 
cc[i]);
+                if (log.isDebugEnabled()) {
+                    log.debug("copying e-mail to: " + cc[i]);
+                }
             }
             message.setRecipients(Message.RecipientType.CC, copyTo);
         }
@@ -640,7 +639,9 @@ public class MailUtil {
             
             for (int i = 0; i < bcc.length; i++) {
                 copyTo[i] = new InternetAddress(bcc[i]);
-                if (log.isDebugEnabled()) log.debug("blind copying e-mail to: 
" + bcc[i]);
+                if (log.isDebugEnabled()) {
+                    log.debug("blind copying e-mail to: " + bcc[i]);
+                }
             }
             message.setRecipients(Message.RecipientType.BCC, copyTo);
         }
@@ -680,7 +681,9 @@ public class MailUtil {
             transport.close();
         }
         
-        if (bFailedToSome) throw sendex;
+        if (bFailedToSome) {
+            throw sendex;
+        }
     }
     
     
@@ -728,7 +731,9 @@ public class MailUtil {
             )
             throws MessagingException {
         String[] recipient = null;
-        if (to!=null) recipient = new String[] {to};
+        if (to != null) {
+            recipient = new String[] {to};
+        }
         
         sendMessage(from, recipient, cc, bcc, subject, content, "text/plain; 
charset=utf-8");
     }
@@ -760,9 +765,15 @@ public class MailUtil {
         String[] copy = null;
         String[] bcopy = null;
         
-        if (to!=null) recipient = new String[] {to};
-        if (cc!=null) copy = new String[] {cc};
-        if (bcc!=null) bcopy = new String[] {bcc};
+        if (to!=null) {
+            recipient = new String[] {to};
+        }
+        if (cc!=null) {
+            copy = new String[] {cc};
+        }
+        if (bcc!=null) {
+            bcopy = new String[] {bcc};
+        }
         
         sendMessage(from, recipient, copy, bcopy, subject, content, 
"text/plain; charset=utf-8");
     }
@@ -815,9 +826,15 @@ public class MailUtil {
         String[] copy = null;
         String[] bcopy = null;
         
-        if (to!=null) recipient = new String[] {to};
-        if (cc!=null) copy = new String[] {cc};
-        if (bcc!=null) bcopy = new String[] {bcc};
+        if (to != null) {
+            recipient = new String[] {to};
+        }
+        if (cc != null) {
+            copy = new String[] {cc};
+        }
+        if (bcc != null) {
+            bcopy = new String[] {bcc};
+        }
         
         sendMessage(from, recipient, copy, bcopy, subject, content, 
"text/html; charset=utf-8");
     }
@@ -845,7 +862,9 @@ public class MailUtil {
             )
             throws MessagingException {
         String[] recipient = null;
-        if (to!=null) recipient = new String[] {to};
+        if (to != null) {
+            recipient = new String[] {to};
+        }
         
         sendMessage(from, recipient, cc, bcc, subject, content, "text/html; 
charset=utf-8");
     }

Modified: 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java?rev=1520953&r1=1520952&r2=1520953&view=diff
==============================================================================
--- 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java 
(original)
+++ 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Utilities.java 
Mon Sep  9 02:49:44 2013
@@ -174,14 +174,16 @@ public class Utilities {
                 ret.append(str.substring(start, beginTag));
                 
                 // replace each tag with a space (looks better)
-                if (addSpace) ret.append(" ");
+                if (addSpace) {
+                    ret.append(" ");
+                }
             }
             endTag = str.indexOf('>', beginTag);
             
             // if endTag found move "cursor" forward
             if (endTag > -1) {
                 start = endTag + 1;
-                beginTag = str.indexOf("<", start);
+                beginTag = str.indexOf('<', start);
             }
             // if no endTag found, get rest of str and break
             else {
@@ -202,8 +204,12 @@ public class Utilities {
      * @return String with HTML removed and HTML special characters escaped.
      */
     public static String removeAndEscapeHTML( String s ) {
-        if ( s==null ) return "";
-        else return Utilities.escapeHTML( Utilities.removeHTML(s) );
+        if ( s==null ) {
+            return "";
+        }
+        else {
+            return Utilities.escapeHTML( Utilities.removeHTML(s) );
+        }
     }
     
     //------------------------------------------------------------------------
@@ -211,8 +217,7 @@ public class Utilities {
      * Autoformat.
      */
     public static String autoformat(String s) {
-        String ret = StringUtils.replace(s, "\n", "<br />");
-        return ret;
+        return StringUtils.replace(s, "\n", "<br />");
     }
     
     
@@ -292,10 +297,12 @@ public class Utilities {
     public static String stringArrayToString(String[] stringArray, String 
delim) {
         String ret = "";
         for (int i = 0; i < stringArray.length; i++) {
-            if (ret.length() > 0)
+            if (ret.length() > 0) {
                 ret = ret + delim + stringArray[i];
-            else
+            }
+            else {
                 ret = stringArray[i];
+            }
         }
         return ret;
     }
@@ -305,10 +312,12 @@ public class Utilities {
     public static String stringListToString(List<String> stringList, String 
delim) {
         String ret = "";
         for (String s : stringList) {
-            if (ret.length() > 0)
+            if (ret.length() > 0) {
                 ret = ret + delim + s;
-            else
+            }
+            else {
                 ret = s;
+            }
         }
         return ret;
     }
@@ -350,7 +359,7 @@ public class Utilities {
         while (toker.hasMoreTokens()) {
             String sInt = toker.nextToken();
             int nInt = Integer.parseInt(sInt);
-            intArray[i++] = new Integer(nInt).intValue();
+            intArray[i++] = nInt;
         }
         return intArray;
     }
@@ -360,10 +369,12 @@ public class Utilities {
     public static String intArrayToString(int[] intArray) {
         String ret = "";
         for (int i = 0; i < intArray.length; i++) {
-            if (ret.length() > 0)
+            if (ret.length() > 0) {
                 ret = ret + "," + Integer.toString(intArray[i]);
-            else
+            }
+            else {
                 ret = Integer.toString(intArray[i]);
+            }
         }
         return ret;
     }
@@ -448,8 +459,9 @@ public class Utilities {
                         "Reading input stream, " + ex.getMessage());
             }
             
-            if (bytes < 0)
+            if (bytes < 0) {
                 break;
+            }
             
             length -= bytes;
             
@@ -484,8 +496,9 @@ public class Utilities {
         byte buffer[] = new byte[8192];
         for (int count = 0; count != -1;) {
             count = in.read(buffer, 0, 8192);
-            if (count != -1)
+            if (count != -1) {
                 out.write(buffer, 0, count);
+            }
         }
         
         try {
@@ -599,7 +612,6 @@ public class Utilities {
             } else {
                 // no it wasnt, so we'll cut it off at the upper limit
                 str2 = str2.substring(0, upper);
-                loc = upper;
             }
             
             // the string was truncated, so we append the appendToEnd String
@@ -688,8 +700,7 @@ public class Utilities {
     public static String truncateText(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) {
             upper = lower;
@@ -711,7 +722,6 @@ public class Utilities {
             } else {
                 // no it wasnt, so we'll cut it off at the upper limit
                 str2 = str2.substring(0, upper);
-                loc = upper;
             }
             // the string was truncated, so we append the appendToEnd String
             str = str2 + appendToEnd;
@@ -779,7 +789,7 @@ public class Utilities {
             // could this be better done with a regular expression?
             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!)
                 int endIndex = lcresult.indexOf(closeTag, stringIndex);
@@ -795,7 +805,6 @@ public class Utilities {
                         // Looks like it, so remove it.
                         result.delete(stringIndex, endIndex + 1);
                         lcresult.delete(stringIndex, endIndex + 1);
-                        
                     }
                 }
             }
@@ -810,13 +819,16 @@ public class Utilities {
      * @return
      */
     public static String extractHTML(String str) {
-        if (str == null) return "";
+        if (str == null) {
+            return "";
+        }
         StringBuffer ret = new StringBuffer(str.length());
         int start = 0;
         int beginTag = str.indexOf('<');
         int endTag = 0;
-        if (beginTag == -1)
+        if (beginTag == -1) {
             return str;
+        }
         
         while (beginTag >= start) {
             endTag = str.indexOf('>', beginTag);
@@ -839,7 +851,9 @@ public class Utilities {
     
     
     public static String hexEncode(String str) {
-        if (StringUtils.isEmpty(str)) return str;
+        if (StringUtils.isEmpty(str)) {
+            return str;
+        }
         
         return RegexUtil.encode(str);
     }
@@ -855,10 +869,12 @@ public class Utilities {
      */
     public static final String encode(String s) {
         try {
-            if (s != null)
+            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
             return s;
@@ -872,10 +888,12 @@ public class Utilities {
      */
     public static final String decode(String s) {
         try {
-            if (s != null)
+            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
             return s;
@@ -888,7 +906,7 @@ public class Utilities {
      */
     public static int stringToInt(String string) {
         try {
-            return Integer.valueOf(string).intValue();
+            return Integer.valueOf(string);
         } catch (NumberFormatException e) {
             mLogger.debug("Invalid Integer:" + string);
         }
@@ -900,7 +918,7 @@ public class Utilities {
      */
     public static String toBase64(byte[] aValue) {
         
-        final String m_strBase64Chars =
+        final String strBase64Chars =
                 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         
         int byte1;
@@ -916,10 +934,10 @@ public class Utilities {
             byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
             byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
             
-            tt.append(m_strBase64Chars.charAt(byte1 / 4));
-            tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 
16)));
-            tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + 
((byte2 & 0xF) * 4)) : '='));
-            tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : 
'='));
+            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(((bByte3) ? strBase64Chars.charAt(byte3 & 0x3F) : '='));
         }
         
         return tt.toString();
@@ -930,8 +948,9 @@ public class Utilities {
      * @return
      */
     public static String stripInvalidTagCharacters(String tag) {
-        if (tag == null)
+        if (tag == null) {
             throw new NullPointerException();
+        }
 
         StringBuffer sb = new StringBuffer();
         char[] charArray = tag.toCharArray();
@@ -964,8 +983,9 @@ public class Utilities {
      */
     public static List splitStringAsTags(String tags)  {
         String[] tagsarr = StringUtils.split(tags, TAG_SPLIT_CHARS);
-        if(tagsarr == null)
+        if(tagsarr == null) {
             return Collections.EMPTY_LIST;
+        }
         return Arrays.asList(tagsarr);
     }
     
@@ -1060,8 +1080,9 @@ public class Utilities {
      * {@link javax.mail.internet.InternetAddress}, but almost always 
undesired.
      */
     public static boolean isValidEmailAddress(String aEmailAddress) {
-        if (aEmailAddress == null)
+        if (aEmailAddress == null) {
             return false;
+        }
         boolean result = true;
         try {
             // See if its valid

Modified: 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java?rev=1520953&r1=1520952&r2=1520953&view=diff
==============================================================================
--- 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
 (original)
+++ 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
 Mon Sep  9 02:49:44 2013
@@ -92,8 +92,8 @@ import org.apache.roller.weblogger.pojos
 public class RollerAtomHandler implements AtomHandler {
     protected Weblogger roller = null;
     protected User user = null;
-    protected int  maxEntries = 20;
-    protected      String atomURL = null;
+    protected int maxEntries = 20;
+    protected String atomURL = null;
     
     protected static boolean throttle = true;
     
@@ -301,7 +301,9 @@ public class RollerAtomHandler implement
      */
     public boolean isAtomServiceURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length==0) return true;
+        if (pathInfo.length==0) {
+            return true;
+        }
         return false;
     }
     
@@ -310,8 +312,12 @@ public class RollerAtomHandler implement
      */
     public boolean isEntryURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length > 2 && pathInfo[1].equals("entry")) return true;
-        if (pathInfo.length > 2 && pathInfo[1].equals("resource") && 
pathInfo[pathInfo.length-1].endsWith(".media-link")) return true;
+        if (pathInfo.length > 2 && pathInfo[1].equals("entry")) {
+            return true;
+        }
+        if (pathInfo.length > 2 && pathInfo[1].equals("resource") && 
pathInfo[pathInfo.length-1].endsWith(".media-link")) {
+            return true;
+        }
         return false;
     }
         
@@ -320,7 +326,9 @@ public class RollerAtomHandler implement
      */
     public boolean isMediaEditURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length > 1 && pathInfo[1].equals("resource")) return true;
+        if (pathInfo.length > 1 && pathInfo[1].equals("resource")) {
+            return true;
+        }
         return false;
     }
         
@@ -329,9 +337,15 @@ public class RollerAtomHandler implement
      */
     public boolean isCollectionURI(AtomRequest areq) {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        if (pathInfo.length > 1 && pathInfo[1].equals("entries")) return true;
-        if (pathInfo.length > 1 && pathInfo[1].equals("resources")) return 
true;
-        if (pathInfo.length > 1 && pathInfo[1].equals("categories")) return 
true;
+        if (pathInfo.length > 1 && pathInfo[1].equals("entries")) {
+            return true;
+        }
+        if (pathInfo.length > 1 && pathInfo[1].equals("resources")) {
+            return true;
+        }
+        if (pathInfo.length > 1 && pathInfo[1].equals("categories")) {
+            return true;
+        }
         return false;
     }
     
@@ -388,7 +402,9 @@ public class RollerAtomHandler implement
      */
     protected String authenticateWSSE(HttpServletRequest request) {
         String wsseHeader = request.getHeader("X-WSSE");
-        if (wsseHeader == null) return null;
+        if (wsseHeader == null) {
+            return null;
+        }
         
         String ret = null;
         String userName = null;
@@ -415,11 +431,11 @@ public class RollerAtomHandler implement
         }
         String digest = null;
         try {
-            User user = roller.getUserManager().getUserByUserName(userName);
+            User inUser = roller.getUserManager().getUserByUserName(userName);
             digest = WSSEUtilities.generateDigest(
                     WSSEUtilities.base64Decode(nonce),
                     created.getBytes("UTF-8"),
-                    user.getPassword().getBytes("UTF-8"));
+                    inUser.getPassword().getBytes("UTF-8"));
             if (digest.equals(passwordDigest)) {
                 ret = userName;
             }
@@ -448,8 +464,8 @@ public class RollerAtomHandler implement
                         int p = userPass.indexOf(':');
                         if (p != -1) {
                             userID = userPass.substring(0, p);
-                            User user = 
roller.getUserManager().getUserByUserName(userID);
-                            boolean enabled = user.getEnabled().booleanValue();
+                            User inUser = 
roller.getUserManager().getUserByUserName(userID);
+                            boolean enabled = inUser.getEnabled();
                             if (enabled) {
                                 // are passwords encrypted?
                                 String encrypted =
@@ -459,7 +475,7 @@ public class RollerAtomHandler implement
                                     password = 
Utilities.encodePassword(password,
                                             
WebloggerConfig.getProperty("passwds.encryption.algorithm"));
                                 }
-                                valid = user.getPassword().equals(password);
+                                valid = inUser.getPassword().equals(password);
                             }
                         }
                     }
@@ -468,7 +484,9 @@ public class RollerAtomHandler implement
         } catch (Exception e) {
             log.debug(e);
         }
-        if (valid) return userID;
+        if (valid) {
+            return userID;
+        }
         return null;
     }
 
@@ -499,11 +517,13 @@ 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) try { 
-            synchronized (RollerAtomHandler.class) { 
-                Thread.sleep(1000); 
-            }  
-        } catch (Exception ignored) {} 
+        if (throttle) {
+            try {
+                synchronized (RollerAtomHandler.class) {
+                    Thread.sleep(1000);
+                }
+            } catch (Exception ignored) {}
+        }
     }
 
 }


Reply via email to