roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghu...@apache.org
Subject svn commit: r1507256 - in /roller/trunk/app/src/main/java/org/apache/roller/weblogger: pojos/WeblogEntry.java pojos/WeblogEntryTagComparator.java pojos/wrapper/WeblogEntryWrapper.java webservices/atomprotocol/EntryCollection.java
Date Fri, 26 Jul 2013 10:53:14 GMT
Author: ghuber
Date: Fri Jul 26 10:53:14 2013
New Revision: 1507256

URL: http://svn.apache.org/r1507256
Log:
Sort tags by name.  Set ignores <orderBy> :(

Added:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntryTagComparator.java
Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/WeblogEntryWrapper.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java

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=1507256&r1=1507255&r2=1507256&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 Fri
Jul 26 10:53:14 2013
@@ -38,22 +38,21 @@ import java.util.StringTokenizer;
 import java.util.TreeSet;
 
 import org.apache.commons.lang.StringEscapeUtils;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
-import org.apache.roller.weblogger.business.WebloggerFactory;
-import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
-import org.apache.roller.weblogger.business.WeblogEntryManager;
 import org.apache.roller.util.DateUtil;
-import org.apache.roller.weblogger.util.I18nMessages;
 import org.apache.roller.util.UUIDGenerator;
+import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.UserManager;
+import org.apache.roller.weblogger.business.WeblogEntryManager;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
+import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
 import org.apache.roller.weblogger.util.HTMLSanitizer;
+import org.apache.roller.weblogger.util.I18nMessages;
 import org.apache.roller.weblogger.util.Utilities;
 
 /**
@@ -103,7 +102,7 @@ public class WeblogEntry implements Seri
     // Collection of name/value entry attributes
     private Set attSet = new TreeSet();
     
-    private Set tagSet = new HashSet();
+    private Set tagSet = new HashSet(); 
     private Set removedTags = new HashSet();
     private Set addedTags = new HashSet();
     
@@ -654,12 +653,13 @@ public class WeblogEntry implements Seri
      * @hibernate.collection-key column="entryid"
      * @hibernate.collection-one-to-many class="org.apache.roller.weblogger.pojos.WeblogEntryTag"
      */
-     public Set getTags()
+     public Set<WeblogEntryTag> getTags()
      {
          return tagSet;
      }
      
-     private void setTags(Set tagSet) throws WebloggerException
+     @SuppressWarnings("unused")
+    private void setTags(Set<WeblogEntryTag> tagSet) throws WebloggerException
      {
          this.tagSet = tagSet;
          this.removedTags = new HashSet();
@@ -748,7 +748,10 @@ public class WeblogEntry implements Seri
      */
     public String getTagsAsString() {
         StringBuffer sb = new StringBuffer();
-        for (Iterator it = getTags().iterator(); it.hasNext();) {
+        // Sort by name
+        Set<WeblogEntryTag> tmp = new TreeSet<WeblogEntryTag>(new WeblogEntryTagComparator());
+        tmp.addAll(getTags());
+        for (Iterator it = tmp.iterator(); it.hasNext();) {
             sb.append(((WeblogEntryTag) it.next()).getName()).append(" ");
         }
         if (sb.length() > 0) {
@@ -759,7 +762,7 @@ public class WeblogEntry implements Seri
     }
 
     public void setTagsAsString(String tags) throws WebloggerException {
-        if (tags == null) {
+        if (StringUtils.isEmpty(tags)) {
             tagSet.clear();
             return;
         }

Added: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntryTagComparator.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntryTagComparator.java?rev=1507256&view=auto
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntryTagComparator.java
(added)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntryTagComparator.java
Fri Jul 26 10:53:14 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.pojos;
+
+import java.util.Comparator;
+import java.io.Serializable;
+
+/**
+ * Sorts tags by name
+ */
+public class WeblogEntryTagComparator implements Comparator<WeblogEntryTag>,
+        Serializable {
+
+    private static final long serialVersionUID = 3720914385178339406L;
+   
+    /**
+     * Instantiates a new weblog entry tag comparator.
+     */
+    public WeblogEntryTagComparator() {
+    }
+
+    /**
+     * Compares two <em>WeblogEntryTag</em> instances according to their tag
+     * name.
+     */
+    public int compare(WeblogEntryTag o1, WeblogEntryTag o2) {
+        return o1.getName().toString().compareTo(o2.getName().toString());
+    }
+
+}

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/WeblogEntryWrapper.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/WeblogEntryWrapper.java?rev=1507256&r1=1507255&r2=1507256&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/WeblogEntryWrapper.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/WeblogEntryWrapper.java
Fri Jul 26 10:53:14 2013
@@ -23,12 +23,15 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
+
 import org.apache.roller.weblogger.business.URLStrategy;
 import org.apache.roller.weblogger.pojos.WeblogCategory;
 import org.apache.roller.weblogger.pojos.WeblogEntry;
 import org.apache.roller.weblogger.pojos.WeblogEntryAttribute;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
 import org.apache.roller.weblogger.pojos.WeblogEntryTag;
+import org.apache.roller.weblogger.pojos.WeblogEntryTagComparator;
 import org.apache.roller.weblogger.pojos.WeblogReferrer;
 import org.apache.roller.weblogger.util.HTMLSanitizer;
 
@@ -207,7 +210,9 @@ public class WeblogEntryWrapper {
     
     
     public List getTags() {
-        Set initialCollection = this.pojo.getTags();
+        // Sort by name
+        Set<WeblogEntryTag> initialCollection = new TreeSet<WeblogEntryTag>(new
WeblogEntryTagComparator());
+        initialCollection.addAll(this.pojo.getTags());
         
         // iterate through and wrap
         // we force the use of an ArrayList because it should be good enough to cover

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java?rev=1507256&r1=1507255&r2=1507256&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java
Fri Jul 26 10:53:14 2013
@@ -29,12 +29,16 @@ import com.sun.syndication.propono.atom.
 import com.sun.syndication.propono.atom.server.AtomNotAuthorizedException;
 import com.sun.syndication.propono.atom.server.AtomNotFoundException;
 import com.sun.syndication.propono.atom.server.AtomRequest;
+
 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.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -49,6 +53,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.WeblogCategory;
 import org.apache.roller.weblogger.pojos.WeblogEntry;
 import org.apache.roller.weblogger.pojos.WeblogEntryTag;
+import org.apache.roller.weblogger.pojos.WeblogEntryTagComparator;
 import org.apache.roller.weblogger.util.Utilities;
 import org.apache.roller.weblogger.util.cache.CacheManager;
 
@@ -342,7 +347,9 @@ public class EntryCollection {
         categories.add(atomCat);
         
         // Add Atom categories for each Weblogger tag with null scheme
-        for (Iterator tagit = entry.getTags().iterator(); tagit.hasNext();) {
+        Set<WeblogEntryTag> tmp = new TreeSet<WeblogEntryTag>(new WeblogEntryTagComparator());
+        tmp.addAll(entry.getTags());
+        for (Iterator tagit = tmp.iterator(); tagit.hasNext();) {
             WeblogEntryTag tag = (WeblogEntryTag) tagit.next();
             Category newcat = new Category();
             newcat.setTerm(tag.getName());



Mime
View raw message