roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r574748 - in /roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol: Collection.java RollerAtomHandler.java
Date Wed, 12 Sep 2007 01:25:51 GMT
Author: snoopdave
Date: Tue Sep 11 18:25:51 2007
New Revision: 574748

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

Tested with latest Ape (pulled from CVS today) and found no errors.

Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/Collection.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/Collection.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/Collection.java?rev=574748&r1=574747&r2=574748&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/Collection.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/Collection.java
Tue Sep 11 18:25:51 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/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java?rev=574748&r1=574747&r2=574748&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
Tue Sep 11 18:25:51 2007
@@ -177,9 +177,9 @@
         } catch (WebloggerException re) {
             throw new AtomException("Getting user's weblogs", re);
         }
-        String accept = null;
-        try {
-            accept = getAcceptedContentTypeRange();
+        List uploadAccepts = new ArrayList();
+        try {           
+            uploadAccepts = getAcceptedContentTypeRange();
         } catch (WebloggerException re) {
             throw new AtomException("Getting site's accept range", re);
         }
@@ -196,7 +196,7 @@
                 // Create collection for entries within that workspace
                 Collection entryCol = new Collection("Weblog Entries", "text", 
                     atomURL+"/"+handle+"/entries");
-                entryCol.setAccept("application/atom+xml;type=entry");
+                entryCol.addAccept("application/atom+xml;type=entry");
                 try {  
                     // Add fixed categories using scheme that points to 
                     // weblog because categories are weblog specific
@@ -227,7 +227,7 @@
                 // Add media collection for upload dir
                 Collection uploadCol = new Collection("Media Files", "text", 
                     atomURL+"/"+handle+"/resources/");
-                uploadCol.setAccept(accept);
+                uploadCol.setAccepts(uploadAccepts);
                 workspace.addCollection(uploadCol);
 
                 // And add one media collection for each of weblog's upload sub-directories
@@ -238,7 +238,7 @@
                         Collection uploadSubCol = new Collection(
                             "Media Files: " + dirs[i].getPath(), "text",
                             atomURL+"/"+handle+"/resources/" + dirs[i].getPath());
-                        uploadSubCol.setAccept(accept);
+                        uploadSubCol.setAccepts(uploadAccepts);
                         workspace.addCollection(uploadSubCol);
                     }
                 } catch (FilePathException fpe) {
@@ -257,20 +257,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 WebloggerException {
-        StringBuffer sb = new StringBuffer();
+    private List getAcceptedContentTypeRange() throws WebloggerException {
+        List accepts = new ArrayList();
         Weblogger roller = WebloggerFactory.getWeblogger();
         Map config = roller.getPropertiesManager().getProperties();        
         String allows = ((RuntimeConfigProperty)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
@@ -626,6 +623,7 @@
                     
                     WeblogManager mgr = roller.getWeblogManager();
                     copyToRollerEntry(entry, rollerEntry);
+                    rollerEntry.setUpdateTime(new Timestamp(new Date().getTime()));
                     mgr.saveWeblogEntry(rollerEntry);
                     roller.flush();
                     
@@ -1191,7 +1189,7 @@
     /**
      * Copy fields from ROME entry to Weblogger entry.
      */
-    private void copyToRollerEntry(Entry entry,WeblogEntry rollerEntry) throws WebloggerException
{
+    private void copyToRollerEntry(Entry entry, WeblogEntry rollerEntry) throws WebloggerException
{
         
         Timestamp current = new Timestamp(System.currentTimeMillis());
         Timestamp pubTime = current;



Mime
View raw message