roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r575075 - in /roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol: Collection.java RollerAtomHandler.java
Date Wed, 12 Sep 2007 20:59:19 GMT
Author: snoopdave
Date: Wed Sep 12 13:59:19 2007
New Revision: 575075

URL: http://svn.apache.org/viewvc?rev=575075&view=rev
Log:
Fix for http://opensource.atlassian.com/projects/roller/browse/ROL-1533
- Now uses multiple <accept> elements for resource collections

Modified:
    roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/Collection.java
    roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java

Modified: roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/Collection.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/Collection.java?rev=575075&r1=575074&r2=575075&view=diff
==============================================================================
--- roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/Collection.java
(original)
+++ roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/Collection.java
Wed Sep 12 13:59:19 2007
@@ -43,6 +43,7 @@
     private String listTemplate = null;
     private String href = null;
     private List categories = new ArrayList(); // of Categories objects    
+    private List accepts = new ArrayList(); // of Strings
     
     /**
      * Collection MUST have title and href.
@@ -59,12 +60,16 @@
     /**
      * Comma separated list of media-ranges accepted by collection.
      */
-    public String getAccept() {
-        return accept;
+    public List getAccepts() {
+        return accepts;
     }
     
-    public void setAccept(String accept) {
-        this.accept = accept;
+    public void addAccept(String accept) {
+        this.accepts.add(accept);
+    }
+
+    public void setAccepts(List accepts) {
+        this.accepts = accepts;
     }
     
     /** The URI of the collection */
@@ -116,7 +121,7 @@
         } else if (entry && entryType.equals(accept)) {
             return true;
         } else {
-            String[] rules = accept.split(",");
+            String[] rules = (String[])accepts.toArray(new String[accepts.size()]);
             for (int i=0; i<rules.length; i++) {
                 String rule = rules[i].trim();
                 if (rule.equals(ct)) return true;
@@ -168,9 +173,12 @@
             element.addContent(catsElem);
         }
         
-        Element memberType = new Element("accept", AtomService.ATOM_PROTOCOL);
-        memberType.setText(collection.getAccept());
-        element.addContent(memberType);
+        for (Iterator it = collection.getAccepts().iterator(); it.hasNext();) {
+            String range = (String)it.next();
+            Element acceptElem = new Element("accept", AtomService.ATOM_PROTOCOL);
+            acceptElem.setText(range);
+            element.addContent(acceptElem);
+        }
         
         return element;
     }
@@ -186,9 +194,12 @@
         }
         Collection collection = new Collection(newTitle, newType, newHref);
                 
-        Element memberType = element.getChild("accept",  AtomService.ATOM_PROTOCOL);
-        if (memberType != null) {
-            collection.setAccept(memberType.getText());
+        List acceptElems = element.getChildren("accept",  AtomService.ATOM_PROTOCOL);
+        if (acceptElems != null && acceptElems.size() > 0) {
+            for (Iterator it = acceptElems.iterator(); it.hasNext();) {
+                Element acceptElem = (Element)it.next();
+                collection.addAccept(acceptElem.getTextTrim());
+            }
         }
         
         // Loop to parse <app:categories> element to Categories objects

Modified: roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java?rev=575075&r1=575074&r2=575075&view=diff
==============================================================================
--- roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java
(original)
+++ roller/branches/roller_3.1/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java
Wed Sep 12 13:59:19 2007
@@ -69,7 +69,7 @@
 import org.apache.roller.pojos.WeblogEntryTagData;
 import org.apache.roller.pojos.WeblogResource;
 import org.apache.roller.util.URLUtilities;
-import org.apache.roller.util.cache.CacheManager;
+import org.apache.roller.util.cache.CacheManager; 
 
 /**
  * Roller's Atom Protocol implementation.
@@ -177,9 +177,9 @@
         } catch (RollerException re) {
             throw new AtomException("ERROR: getting user's weblogs", re);
         }
-        String accept = null;
+        List uploadAccepts = new ArrayList();
         try {
-            accept = getAcceptedContentTypeRange();
+            uploadAccepts = getAcceptedContentTypeRange();
         } catch (RollerException re) {
             throw new AtomException("ERROR: getting site's accept range", re);
         }
@@ -193,7 +193,7 @@
                 
                 Collection entryCol = new Collection("Weblog Entries", "text", 
                     URLUtilities.getAtomProtocolURL(true)+"/"+handle+"/entries");
-                entryCol.setAccept("application/atom+xml;type=entry");
+                entryCol.addAccept("application/atom+xml;type=entry");
                 entryCol.setHref(URLUtilities.getAtomProtocolURL(true)+"/"+handle+"/entries");
                 try {                    
                     // Add fixed categories using scheme that points to 
@@ -224,7 +224,7 @@
                                 
                 Collection uploadCol = new Collection("Media Files", "text", 
                     URLUtilities.getAtomProtocolURL(true)+"/"+handle+"/resources/");
-                uploadCol.setAccept(accept);
+                uploadCol.setAccepts(uploadAccepts);
                 uploadCol.setHref(URLUtilities.getAtomProtocolURL(true)+"/"+handle+"/resources");
                 workspace.addCollection(uploadCol);
             }
@@ -236,20 +236,17 @@
      * Build accept range by taking things that appear to be content-type rules 
      * from site's file-upload allowed extensions.
      */
-    private String getAcceptedContentTypeRange() throws RollerException {
-        StringBuffer sb = new StringBuffer();
+    private List getAcceptedContentTypeRange() throws RollerException {
+        List accepts = new ArrayList();
         Roller roller = RollerFactory.getRoller();
         Map config = roller.getPropertiesManager().getProperties();        
         String allows = ((RollerPropertyData)config.get("uploads.types.allowed")).getValue();
         String[] rules = StringUtils.split(StringUtils.deleteWhitespace(allows), ",");
         for (int i=0; i<rules.length; i++) {
             if (rules[i].indexOf("/") == -1) continue;
-            if (sb.length() != 0) {
-                sb.append(",");
-            }
-            sb.append(rules[i]);
+            accepts.add(rules[i]);
         }
-        return sb.toString();              
+        return accepts;             
     }   
     
     //----------------------------------------------------------------- collections
@@ -553,6 +550,7 @@
                 if (canEdit(rollerEntry)) {
                     WeblogManager mgr = mRoller.getWeblogManager();
                     copyToRollerEntry(entry, rollerEntry);
+                    rollerEntry.setUpdateTime(new Timestamp(new Date().getTime()));
                     mgr.saveWeblogEntry(rollerEntry);
                     mRoller.flush();
 



Mime
View raw message