Author: gmazza
Date: Sun Sep 8 19:46:04 2013
New Revision: 1520902
URL: http://svn.apache.org/r1520902
Log:
Various Sonar complaints fixed.
Modified:
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/I18nUtils.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
Modified:
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
Sun Sep 8 19:46:04 2013
@@ -144,14 +144,22 @@ public class JPAPlanetManagerImpl extend
Query q = strategy.getNamedQuery(
"Subscription.getByGroupOrderByInboundBlogsDesc");
q.setParameter(1, group);
- if (offset != 0) q.setFirstResult(offset);
- if (len != -1) q.setMaxResults(len);
+ if (offset != 0) {
+ q.setFirstResult(offset);
+ }
+ if (len != -1) {
+ q.setMaxResults(len);
+ }
result = q.getResultList();
} else {
Query q = strategy.getNamedQuery(
"Subscription.getAllOrderByInboundBlogsDesc");
- if (offset != 0) q.setFirstResult(offset);
- if (len != -1) q.setMaxResults(len);
+ if (offset != 0) {
+ q.setFirstResult(offset);
+ }
+ if (len != -1) {
+ q.setMaxResults(len);
+ }
result = q.getResultList();
}
return result;
@@ -253,8 +261,12 @@ public class JPAPlanetManagerImpl extend
}
Query q =
strategy.getNamedQuery("SubscriptionEntry.getBySubscription");
q.setParameter(1, sub);
- if (offset != 0) q.setFirstResult(offset);
- if (len != -1) q.setMaxResults(len);
+ if (offset != 0) {
+ q.setFirstResult(offset);
+ }
+ if (len != -1) {
+ q.setMaxResults(len);
+ }
return q.getResultList();
}
@@ -263,8 +275,7 @@ public class JPAPlanetManagerImpl extend
}
public List getEntries(PlanetGroup group, Date startDate, Date endDate,
int offset, int len) throws RollerException {
- StringBuffer queryString = new StringBuffer();
-
+
if (group == null) {
throw new WebloggerException("group cannot be null or empty");
}
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java
Sun Sep 8 19:46:04 2013
@@ -202,7 +202,7 @@ public class JPABookmarkManagerImpl impl
public void importBookmarks(
Weblog website, String folderName, String opml)
throws WebloggerException {
- String msg = "importBookmarks";
+
try {
// Build JDOC document OPML string
SAXBuilder builder = new SAXBuilder();
@@ -251,10 +251,18 @@ public class JPABookmarkManagerImpl impl
// better to truncate imported OPML fields than to fail import or drop
whole bookmark
// TODO: add way to notify user that fields were truncated
- if (title != null && title.length() > 254) title =
title.substring(0, 254);
- if (desc != null && desc.length() > 254) desc =
desc.substring(0, 254);
- if (url != null && url.length() > 254) url =
url.substring(0, 254);
- if (xmlUrl != null && xmlUrl.length() > 254) xmlUrl =
xmlUrl.substring(0, 254);
+ if (title != null && title.length() > 254) {
+ title = title.substring(0, 254);
+ }
+ if (desc != null && desc.length() > 254) {
+ desc = desc.substring(0, 254);
+ }
+ if (url != null && url.length() > 254) {
+ url = url.substring(0, 254);
+ }
+ if (xmlUrl != null && xmlUrl.length() > 254) {
+ xmlUrl = xmlUrl.substring(0, 254);
+ }
if (elem.getChildren().size()==0) {
// Leaf element. Store a bookmark
@@ -271,8 +279,8 @@ public class JPABookmarkManagerImpl impl
desc,
url,
xmlUrl,
- new Integer(0),
- new Integer(100),
+ 0,
+ 100,
null);
parent.addBookmark(bd);
// TODO: maybe this should be saving the folder?
@@ -351,8 +359,9 @@ public class JPABookmarkManagerImpl impl
public WeblogBookmarkFolder getRootFolder(Weblog website)
throws WebloggerException {
- if (website == null)
+ if (website == null) {
throw new WebloggerException("website is null");
+ }
Query q =
strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite&ParentNull");
q.setParameter(1, website);
@@ -365,8 +374,9 @@ public class JPABookmarkManagerImpl impl
public List getAllFolders(Weblog website)
throws WebloggerException {
- if (website == null)
+ if (website == null) {
throw new WebloggerException("Website is null");
+ }
Query q = strategy.getNamedQuery("WeblogBookmarkFolder.getByWebsite");
q.setParameter(1, website);
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
Sun Sep 8 19:46:04 2013
@@ -171,7 +171,7 @@ public class WeblogEntry implements Seri
//------------------------------------------------------- Good citizenship
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append("{");
buf.append(getId());
buf.append(", ").append(this.getAnchor());
@@ -182,8 +182,12 @@ public class WeblogEntry implements Seri
}
public boolean equals(Object other) {
- if (other == this) return true;
- if (other instanceof WeblogEntry != true) return false;
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof WeblogEntry)) {
+ return false;
+ }
WeblogEntry o = (WeblogEntry)other;
return new EqualsBuilder()
.append(getAnchor(), o.getAnchor())
@@ -212,7 +216,9 @@ public class WeblogEntry implements Seri
/** @ejb:persistent-field */
public void setId(String id) {
// Form bean workaround: empty string is never a valid id
- if (id != null && id.trim().length() == 0) return;
+ if (id != null && id.trim().length() == 0) {
+ return;
+ }
this.id = id;
}
@@ -427,7 +433,9 @@ public class WeblogEntry implements Seri
if (getEntryAttributes() != null) {
for (Iterator it = getEntryAttributes().iterator(); it.hasNext();
) {
WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
- if (name.equals(att.getName())) return att.getValue();
+ if (name.equals(att.getName())) {
+ return att.getValue();
+ }
}
}
return null;
@@ -675,13 +683,15 @@ public class WeblogEntry implements Seri
public void addTag(String name) throws WebloggerException {
Locale localeObject = getWebsite() != null ?
getWebsite().getLocaleInstance() : Locale.getDefault();
name = Utilities.normalizeTag(name, localeObject);
- if(name.length() == 0)
+ if (name.length() == 0) {
return;
+ }
for (Iterator it = getTags().iterator(); it.hasNext();) {
WeblogEntryTag tag = (WeblogEntryTag) it.next();
- if (tag.getName().equals(name))
+ if (tag.getName().equals(name)) {
return;
+ }
}
WeblogEntryTag tag = new WeblogEntryTag();
@@ -795,14 +805,14 @@ public class WeblogEntry implements Seri
} else {
// we want to use pubtime for calculating when comments expire, but
// if pubtime isn't set (like for drafts) then just use updatetime
- Date pubTime = getPubTime();
- if(pubTime == null) {
- pubTime = getUpdateTime();
+ Date inPubTime = getPubTime();
+ if (inPubTime == null) {
+ inPubTime = getUpdateTime();
}
Calendar expireCal = Calendar.getInstance(
getWebsite().getLocaleInstance());
- expireCal.setTime(pubTime);
+ expireCal.setTime(inPubTime);
expireCal.add(Calendar.DATE, getCommentDays().intValue());
Date expireDay = expireCal.getTime();
Date today = new Date();
@@ -943,7 +953,6 @@ public class WeblogEntry implements Seri
} catch (UnsupportedEncodingException e) {
// go with the "no encoding" version
}
- Weblog website = this.getWebsite();
return "/" + getWebsite().getHandle() + "/entry/" + lAnchor;
}
@@ -1155,12 +1164,13 @@ public class WeblogEntry implements Seri
} catch (WebloggerException ex) {
// security interceptor should ensure this never happens
mLogger.error("ERROR retrieving user's permission", ex);
+ return false;
}
boolean author = perm.hasAction(WeblogPermission.POST) ||
perm.hasAction(WeblogPermission.ADMIN);
boolean limited = !author &&
perm.hasAction(WeblogPermission.EDIT_DRAFT);
- if (author || (limited && isDraft()) || (limited && isPending())) {
+ if (author || (limited && (isDraft() || isPending()))) {
return true;
}
@@ -1173,8 +1183,8 @@ public class WeblogEntry implements Seri
private String render(String str) {
String ret = str;
mLogger.debug("Applying page plugins to string");
- Map plugins = getWebsite().getInitializedPlugins();
- if (str != null && plugins != null) {
+ Map inPlugins = getWebsite().getInitializedPlugins();
+ if (str != null && inPlugins != null) {
List entryPlugins = getPluginsList();
// if no Entry plugins, don't bother looping.
@@ -1183,11 +1193,11 @@ public class WeblogEntry implements Seri
// now loop over mPagePlugins, matching
// against Entry plugins (by name):
// where a match is found render Plugin.
- Iterator iter = plugins.keySet().iterator();
+ Iterator iter = inPlugins.keySet().iterator();
while (iter.hasNext()) {
String key = (String)iter.next();
if (entryPlugins.contains(key)) {
- WeblogEntryPlugin pagePlugin =
(WeblogEntryPlugin)plugins.get(key);
+ WeblogEntryPlugin pagePlugin = (WeblogEntryPlugin)
inPlugins.get(key);
try {
ret = pagePlugin.render(this, ret);
} catch (Exception e) {
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
Sun Sep 8 19:46:04 2013
@@ -107,8 +107,9 @@ public class SiteWideCache implements Ca
public Object get(String key) {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return null;
+ }
Object entry = contentCache.get(key);
@@ -124,8 +125,9 @@ public class SiteWideCache implements Ca
public void put(String key, Object value) {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return;
+ }
contentCache.put(key, value);
log.debug("PUT "+key);
@@ -134,8 +136,9 @@ public class SiteWideCache implements Ca
public void remove(String key) {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return;
+ }
contentCache.remove(key);
log.debug("REMOVE "+key);
@@ -144,8 +147,9 @@ public class SiteWideCache implements Ca
public void clear() {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return;
+ }
contentCache.clear();
this.lastUpdateTime = null;
@@ -328,8 +332,9 @@ public class SiteWideCache implements Ca
*/
public void invalidate(WeblogEntry entry) {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return;
+ }
this.contentCache.clear();
this.lastUpdateTime = null;
@@ -341,8 +346,9 @@ public class SiteWideCache implements Ca
*/
public void invalidate(Weblog website) {
- if(!cacheEnabled)
+ if (!cacheEnabled) {
return;
+ }
this.contentCache.clear();
this.lastUpdateTime = null;
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java
Sun Sep 8 19:46:04 2013
@@ -66,8 +66,8 @@ public class Blacklist {
private static Log mLogger = LogFactory.getLog(Blacklist.class);
private static Blacklist blacklist;
- private static final String blacklistFile = "blacklist.txt";
- private static final String lastUpdateStr = "Last update:";
+ private static final String BLACKLIST_FILE = "blacklist.txt";
+ private static final String LAST_UPDATE_STR = "Last update:";
/** We no longer have a blacklist update URL */
private static final String blacklistURL = null;
@@ -99,7 +99,7 @@ public class Blacklist {
/** Non-Static update method. */
public void update() {
- if (this.blacklistURL != null) {
+ if (blacklistURL != null) {
boolean blacklist_updated = this.downloadBlacklist();
if (blacklist_updated) {
this.loadBlacklistFromFile(null);
@@ -110,7 +110,7 @@ public class Blacklist {
/** Download the MT blacklist from the web to our uploads directory. */
private boolean downloadBlacklist() {
- boolean blacklist_updated = false;
+ boolean blacklistUpdated = false;
try {
mLogger.debug("Attempting to download MT blacklist");
@@ -147,14 +147,15 @@ public class Blacklist {
(this.lastModified == null ||
this.lastModified.getTime() < lastModifiedLong)) {
- mLogger.debug("my last modified =
"+this.lastModified.getTime());
- mLogger.debug("MT last modified = "+lastModifiedLong);
+ mLogger.debug("my last modified = " + (this.lastModified ==
null ? "(null)" :
+ this.lastModified.getTime()));
+ mLogger.debug("MT last modified = " + lastModifiedLong);
// save the new blacklist
InputStream instream = connection.getInputStream();
String uploadDir = WebloggerConfig.getProperty("uploads.dir");
- String path = uploadDir + File.separator + blacklistFile;
+ String path = uploadDir + File.separator + BLACKLIST_FILE;
FileOutputStream outstream = new FileOutputStream(path);
mLogger.debug("writing updated MT blacklist to "+path);
@@ -162,13 +163,14 @@ public class Blacklist {
// read from url and write to file
byte[] buf = new byte[4096];
int length = 0;
- while((length = instream.read(buf)) > 0)
+ while((length = instream.read(buf)) > 0) {
outstream.write(buf, 0, length);
+ }
outstream.close();
instream.close();
- blacklist_updated = true;
+ blacklistUpdated = true;
mLogger.debug("MT blacklist download completed.");
@@ -180,7 +182,7 @@ public class Blacklist {
mLogger.error("error downloading blacklist", e);
}
- return blacklist_updated;
+ return blacklistUpdated;
}
/**
@@ -196,7 +198,7 @@ public class Blacklist {
String path = blacklistFilePath;
if (path == null) {
String uploadDir = WebloggerConfig.getProperty("uploads.dir");
- path = uploadDir + File.separator + blacklistFile;
+ path = uploadDir + File.separator + BLACKLIST_FILE;
}
File blacklistFile = new File(path);
@@ -246,7 +248,9 @@ public class Blacklist {
readRule(line);
}
- if (saveStream) buf.append(line).append("\n");
+ if (saveStream) {
+ buf.append(line).append("\n");
+ }
}
} catch (Exception e) {
mLogger.error(e);
@@ -261,18 +265,21 @@ public class Blacklist {
}
private void readRule(String str) {
- if (StringUtils.isEmpty(str)) return; // bad condition
+ // check for bad condition
+ if (StringUtils.isEmpty(str)) {
+ return;
+ }
String rule = str.trim();
-
- if (str.indexOf('#') > 0) // line has a comment
- {
+
+ // line has a comment?
+ if (str.indexOf('#') > 0) {
int commentLoc = str.indexOf('#');
rule = str.substring(0, commentLoc-1).trim(); // strip comment
}
-
- if (rule.indexOf( '(' ) > -1) // regex rule
- {
+
+ // regex rule?
+ if (rule.indexOf( '(' ) > -1) {
// pre-compile patterns since they will be frequently used
blacklistRegex.add(Pattern.compile(rule));
} else if (StringUtils.isNotEmpty(rule)) {
@@ -282,9 +289,9 @@ public class Blacklist {
/** Read comment and try to parse out "Last update" value */
private void readComment(String str) {
- int lastUpdatePos = str.indexOf(lastUpdateStr);
+ int lastUpdatePos = str.indexOf(LAST_UPDATE_STR);
if (lastUpdatePos > -1) {
- str = str.substring(lastUpdatePos + lastUpdateStr.length());
+ str = str.substring(lastUpdatePos + LAST_UPDATE_STR.length());
str = str.trim();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd
HH:mm:ss");
@@ -311,7 +318,9 @@ public class Blacklist {
*/
public boolean isBlacklisted(
String str, List moreStringRules, List moreRegexRules) {
- if (str == null || StringUtils.isEmpty(str)) return false;
+ if (str == null || StringUtils.isEmpty(str)) {
+ return false;
+ }
// First iterate over blacklist, doing indexOf.
// Then iterate over blacklistRegex and test.
@@ -324,7 +333,9 @@ public class Blacklist {
stringRules.addAll(moreStringRules);
stringRules.addAll(blacklistStr);
}
- if (testStringRules(str, stringRules)) return true;
+ if (testStringRules(str, stringRules)) {
+ return true;
+ }
// test regex blacklisted
List regexRules = blacklistRegex;
@@ -339,12 +350,14 @@ public class Blacklist {
/**
* Test string only against rules provided by caller, NOT against built-in
blacklist.
* @param str String to be checked against rules
- * @param moreStringRules String rules to consider
- * @param moreRegexRules Regex rules to consider
+ * @param stringRules String rules to consider
+ * @param regexRules Regex rules to consider
*/
public static boolean matchesRulesOnly(
String str, List stringRules, List regexRules) {
- if (testStringRules(str, stringRules)) return true;
+ if (testStringRules(str, stringRules)) {
+ return true;
+ }
return testRegExRules(str, regexRules);
}
@@ -436,7 +449,9 @@ public class Blacklist {
StringTokenizer toker = new StringTokenizer(siteWords + "\n" +
weblogWords, "\n");
while (toker.hasMoreTokens()) {
String token = toker.nextToken().trim();
- if (token.startsWith("#")) continue;
+ if (token.startsWith("#")) {
+ continue;
+ }
if (token.startsWith("(")) {
regexRules.add(Pattern.compile(token));
} else {
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/I18nUtils.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/I18nUtils.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/I18nUtils.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/util/I18nUtils.java
Sun Sep 8 19:46:04 2013
@@ -31,16 +31,28 @@ public final class I18nUtils {
if (locale != null) {
String[] localeStr = StringUtils.split(locale,"_");
if (localeStr.length == 1) {
- if (localeStr[0] == null) localeStr[0] = "";
+ if (localeStr[0] == null) {
+ localeStr[0] = "";
+ }
return new Locale(localeStr[0]);
} else if (localeStr.length == 2) {
- if (localeStr[0] == null) localeStr[0] = "";
- if (localeStr[1] == null) localeStr[1] = "";
+ if (localeStr[0] == null) {
+ localeStr[0] = "";
+ }
+ if (localeStr[1] == null) {
+ localeStr[1] = "";
+ }
return new Locale(localeStr[0], localeStr[1]);
} else if (localeStr.length == 3) {
- if (localeStr[0] == null) localeStr[0] = "";
- if (localeStr[1] == null) localeStr[1] = "";
- if (localeStr[2] == null) localeStr[2] = "";
+ if (localeStr[0] == null) {
+ localeStr[0] = "";
+ }
+ if (localeStr[1] == null) {
+ localeStr[1] = "";
+ }
+ if (localeStr[2] == null) {
+ localeStr[2] = "";
+ }
return new Locale(localeStr[0], localeStr[1], localeStr[2]);
}
}
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java?rev=1520902&r1=1520901&r2=1520902&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
Sun Sep 8 19:46:04 2013
@@ -71,7 +71,7 @@ import org.apache.roller.weblogger.util.
public class MediaCollection {
private Weblogger roller;
private User user;
- private int maxEntries = 20;
+ private static final int MAX_ENTRIES = 20;
private final String atomURL;
private static Log log =
@@ -131,7 +131,9 @@ public class MediaCollection {
throw new AtomException("Duplicate file name");
}
- if (path.length() > 0) path = path + File.separator;
+ if (path.length() > 0) {
+ path = path + File.separator;
+ }
FileInputStream fis = new FileInputStream(tempFile);
MediaFile mf = new MediaFile();
@@ -168,7 +170,9 @@ public class MediaCollection {
throw new AtomException(
"File upload disabled, over-quota or other error",
fie);
} finally {
- if (tempFile != null) tempFile.delete();
+ if (tempFile != null) {
+ tempFile.delete();
+ }
}
}
throw new AtomException("Error saving media entry");
@@ -210,7 +214,6 @@ public class MediaCollection {
String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
try {
// authenticated client posted a weblog entry
- File tempFile = null;
String handle = pathInfo[0];
MediaFileManager fmgr = roller.getMediaFileManager();
Weblog website =
WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
@@ -245,19 +248,21 @@ public class MediaCollection {
String[] rawPathInfo = StringUtils.split(areq.getPathInfo(),"/");
try {
int start = 0;
- int max = maxEntries;
+ int max = MAX_ENTRIES;
String[] pathInfo = rawPathInfo;
if (rawPathInfo.length > 2) {
try {
start = Integer.parseInt(rawPathInfo[rawPathInfo.length -
1]);
pathInfo = new String[rawPathInfo.length - 1];
- for (int i=0; i<rawPathInfo.length - 1; i++) {
+ for (int i=0; i < rawPathInfo.length - 1; i++) {
pathInfo[i] = rawPathInfo[i];
}
} catch (Exception ingored) {}
}
String path = filePathFromPathInfo(pathInfo);
- if (!path.equals("")) path = path + File.separator;
+ if (!path.equals("")) {
+ path = path + File.separator;
+ }
String handle = pathInfo[0];
String absUrl = WebloggerRuntimeConfig.getAbsoluteContextURL();
@@ -295,9 +300,15 @@ public class MediaCollection {
public int compare(Object o1, Object o2) {
MediaFile f1 = (MediaFile)o1;
MediaFile f2 = (MediaFile)o2;
- if (f1.getLastModified() < f2.getLastModified()) return 1;
- else if (f1.getLastModified() == f2.getLastModified())
return 0;
- else return -1;
+ if (f1.getLastModified() < f2.getLastModified()) {
+ return 1;
+ }
+ else if (f1.getLastModified() == f2.getLastModified()) {
+ return 0;
+ }
+ else {
+ return -1;
+ }
}
});
@@ -320,7 +331,8 @@ public class MediaCollection {
}
List otherLinks = new ArrayList();
- if (start + count < files.size()) { // add next link
+ if (start + count < files.size()) {
+ // add next link
int nextOffset = start + max;
String url = atomURL
+"/"+ website.getHandle() + "/resources/" + path +
nextOffset;
@@ -329,7 +341,8 @@ public class MediaCollection {
nextLink.setHref(url);
otherLinks.add(nextLink);
}
- if (start > 0) { // add previous link
+ if (start > 0) {
+ // add previous link
int prevOffset = start > max ? start - max : 0;
String url = atomURL
+"/"+website.getHandle() + "/resources/" + path +
prevOffset;
@@ -407,7 +420,9 @@ public class MediaCollection {
throw new AtomException(
"Unexpected error during file upload", e);
} finally {
- if (tempFile != null) tempFile.delete();
+ if (tempFile != null) {
+ tempFile.delete();
+ }
}
}
throw new AtomException("Incorrect path information");
@@ -458,10 +473,12 @@ public class MediaCollection {
String path = null;
if (pathInfo.length > 2) {
for (int i = 2; i < pathInfo.length; i++) {
- if (path != null && path.length() > 0)
+ if (path != null && path.length() > 0) {
path = path + File.separator + pathInfo[i];
- else
+ }
+ else {
path = pathInfo[i];
+ }
}
} if (pathInfo.length == 2) {
path = "";
@@ -553,10 +570,14 @@ public class MediaCollection {
* content-type = "image/jpg"
* Might result in daveblog-200608201034.jpg
*/
- private String createFileName(Weblog weblog, String slug, String
contentType) {
+ private String createFileName(Weblog weblog, String title, String
contentType) {
- if (weblog == null) throw new IllegalArgumentException("weblog cannot
be null");
- if (contentType == null) throw new
IllegalArgumentException("contentType cannot be null");
+ if (weblog == null) {
+ throw new IllegalArgumentException("weblog cannot be null");
+ }
+ if (contentType == null) {
+ throw new IllegalArgumentException("contentType cannot be null");
+ }
String fileName = null;
@@ -567,9 +588,9 @@ public class MediaCollection {
String[] typeTokens = contentType.split("/");
String ext = typeTokens[1];
- if (slug != null && !slug.trim().equals("")) {
+ if (title != null && !title.trim().equals("")) {
// We've got a title, so use it to build file name
- StringTokenizer toker = new StringTokenizer(slug);
+ StringTokenizer toker = new StringTokenizer(title);
String tmp = null;
int count = 0;
while (toker.hasMoreTokens() && count < 5) {