Author: snoopdave
Date: Mon Jan  2 20:51:15 2006
New Revision: 365539

URL: http://svn.apache.org/viewcvs?rev=365539&view=rev
Log:
Updating for APP draft 7

Added:
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModule.java
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleGenerator.java
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleImpl.java
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleParser.java
Modified:
    incubator/roller/trunk/sandbox/atomprotocol/rome.properties
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java
    
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
    
incubator/roller/trunk/sandbox/atomprotocol/tests/org/roller/presentation/atomapi04/AtomServletTest.java

Modified: incubator/roller/trunk/sandbox/atomprotocol/rome.properties
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/rome.properties?rev=365539&r1=365538&r2=365539&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/rome.properties (original)
+++ incubator/roller/trunk/sandbox/atomprotocol/rome.properties Mon Jan  2 
20:51:15 2006
@@ -38,9 +38,9 @@
                                   
 # Handle Atom Pub Protocol pubcontrol extension
                                       
-atom_1.0.item.ModuleParser.classes   
=org.roller.util.rome.PubControlModuleParser
+atom_1.0.item.ModuleParser.classes   
=org.roller.presentation.atomapi.PubControlModuleParser
 
-atom_1.0.item.ModuleGenerator.classes 
=org.roller.util.rome.PubControlModuleGenerator
+atom_1.0.item.ModuleGenerator.classes 
=org.roller.presentation.atomapi.PubControlModuleGenerator
                                   
 
 

Modified: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java?rev=365539&r1=365538&r2=365539&view=diff
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java
 (original)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java
 Mon Jan  2 20:51:15 2006
@@ -46,13 +46,11 @@
  *       title="My Blog Entries"
  *       href="http://example.org/reilly/main"; >
  *       <member-type>entry</member-type>
- *       <list-template>http://example.org/{index}</list-template>
  *     </collection>
  *     <collection
  *       title="Pictures"
  *       href="http://example.org/reilly/pic"; >
  *       <member-type>media</member-type>
- *       <list-template>http://example.org/p/{index}</list-template>
  *     </collection>
  *   </workspace>
  * </service>
@@ -150,17 +148,6 @@
             this.memberType = memberType;
         }
         
-        /**
-         * Template for forming list URIs
-         */
-        public String getListTemplate() {
-            return listTemplate;
-        }
-        
-        public void setListTemplate(String listTemplate) {
-            this.listTemplate = listTemplate;
-        }
-        
         /** The URI of the collection */
         public String getHref() {
             return href;
@@ -241,10 +228,6 @@
         if (memberType != null) {
             collection.setMemberType(memberType.getText());
         }
-        Element listTemplate = element.getChild("list-template",  ns);
-        if (listTemplate != null) {
-            collection.setListTemplate(listTemplate.getText());
-        }
         return collection;
     }
     
@@ -258,10 +241,6 @@
         Element memberType = new Element("member-type", ns);
         memberType.setText(collection.getMemberType());
         element.addContent(memberType);
-        
-        Element listTemplate = new Element("list-template", ns);
-        listTemplate.setText(collection.getListTemplate());
-        element.addContent(listTemplate);
         
         return element;
     }

Added: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModule.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModule.java?rev=365539&view=auto
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModule.java
 (added)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModule.java
 Mon Jan  2 20:51:15 2006
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed 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.
+ *
+ */
+package org.roller.presentation.atomapi;
+
+import com.sun.syndication.feed.module.Module;
+
+public interface PubControlModule extends Module {
+    public static final String URI = "http://purl.org/atom/app#";;
+    public Boolean getDraft();
+    public void setDraft(Boolean draft);
+}

Added: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleGenerator.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleGenerator.java?rev=365539&view=auto
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleGenerator.java
 (added)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleGenerator.java
 Mon Jan  2 20:51:15 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed 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.
+ *
+ */
+package org.roller.presentation.atomapi;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import com.sun.syndication.feed.module.Module;
+import com.sun.syndication.io.ModuleGenerator;
+
+public class PubControlModuleGenerator implements ModuleGenerator {
+    private static final Namespace PUBCONTROL_NS  = 
+        Namespace.getNamespace("app", PubControlModule.URI);
+
+    public String getNamespaceUri() {
+        return PubControlModule.URI;
+    }
+
+    private static final Set NAMESPACES;
+
+    static {
+        Set nss = new HashSet();
+        nss.add(PUBCONTROL_NS);
+        NAMESPACES = Collections.unmodifiableSet(nss);
+    }
+
+    public Set getNamespaces() {
+        return NAMESPACES;
+    }
+
+    public void generate(Module module, Element element) {
+        PubControlModule m = (PubControlModule)module;
+        if (m.getDraft() != null) {
+            String draft = m.getDraft().booleanValue() ? "yes" : "no";
+            Element control = new Element("control", PUBCONTROL_NS);
+            control.addContent(generateSimpleElement("draft", draft));
+            element.addContent(control);
+        }
+    }
+
+    protected Element generateSimpleElement(String name, String value)  {
+        Element element = new Element(name, PUBCONTROL_NS);
+        element.addContent(value);
+        return element;
+    }
+
+}

Added: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleImpl.java?rev=365539&view=auto
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleImpl.java
 (added)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleImpl.java
 Mon Jan  2 20:51:15 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed 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.
+ *
+ */
+package org.roller.presentation.atomapi;
+
+import com.sun.syndication.feed.module.ModuleImpl;
+
+public class PubControlModuleImpl extends ModuleImpl implements 
PubControlModule {
+    private Boolean _draft;
+
+    public PubControlModuleImpl() {
+        super(PubControlModule.class,PubControlModule.URI);
+    }
+    public Boolean getDraft() {
+        return _draft;
+    }
+    public void setDraft(Boolean draft) {
+        _draft = draft;
+    }
+    public Class getInterface() {
+        return PubControlModule.class;
+    }
+    public void copyFrom(Object obj) {
+        PubControlModule m = (PubControlModule)obj;
+        setDraft(m.getDraft());
+    }
+}

Added: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleParser.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleParser.java?rev=365539&view=auto
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleParser.java
 (added)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/PubControlModuleParser.java
 Mon Jan  2 20:51:15 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed 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.
+ *
+ */
+package org.roller.presentation.atomapi;
+
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import com.sun.syndication.feed.module.Module;
+import com.sun.syndication.io.ModuleParser;
+
+public class PubControlModuleParser implements ModuleParser {
+
+    public String getNamespaceUri() {
+        return PubControlModule.URI;
+    }
+
+    public Namespace getContentNamespace() {
+        return Namespace.getNamespace(PubControlModule.URI);
+    }
+    public Module parse(Element elem) {
+        boolean foundSomething = false;
+        PubControlModule m = new PubControlModuleImpl();
+        Element e = elem.getChild("control", getContentNamespace());
+        if (e != null) {
+            Element draftElem = e.getChild("draft", getContentNamespace());
+            if (draftElem != null) {
+                if ("yes".equals(draftElem.getText())) 
m.setDraft(Boolean.TRUE); 
+                if ("no".equals(draftElem.getText())) 
m.setDraft(Boolean.FALSE);                
+            }
+        }
+        return m.getDraft()!=null ? m : null;
+    }
+}
+

Modified: 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java?rev=365539&r1=365538&r2=365539&view=diff
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
 (original)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
 Mon Jan  2 20:51:15 2006
@@ -50,8 +50,9 @@
 import javax.activation.FileTypeMap;
 import org.roller.RollerException;
 import org.roller.presentation.cache.CacheManager;
-import org.roller.util.rome.PubControlModule;
-import org.roller.util.rome.PubControlModuleImpl;
+import org.roller.presentation.atomapi.PubControlModule;
+import org.roller.presentation.atomapi.PubControlModuleImpl;
+import org.roller.util.WSSEUtilities;
 
 /**
  * Roller's Atom Protocol implementation.
@@ -172,38 +173,23 @@
     //----------------------------------------------------------------- 
collections
     
     /**
-     * Returns collection specified by pathInfo, constrained by a date range 
and
-     * starting at an offset within the collection.Returns 20 items at a time.
+     * Return collection specified by pathinfo.
      * <pre>
-     * Supports these three collection URI forms:
-     *    /<blog-name>/entries/{index}
-     *    /<blog-name>/resources/{index}
-     *    /<blog-name>/categories/{index}
+     * Supports these URI forms:
+     *    /<blog-name>/entries
+     *    /<blog-name>/entries/offset
+     *    /<blog-name>/resources
+     *    /<blog-name>/resources/offset
      * </pre>
-     * @param pathInfo Path info from URI
-     * @param start    Don't include members updated before this date (null 
allowed)
-     * @param end      Don't include members updated after this date (null 
allowed)
-     * @param offset   Offset within collection (for paging)
      */
     public Feed getCollection(String[] pathInfo) throws Exception {
         int start = 0;
         int end = mMaxEntries;
         if (pathInfo.length > 2) {
-            try { // parse int range in form M-N, either M or N may be omitted
+            try { 
                 String s = pathInfo[2].trim();
-                start = 0;
-                end = Integer.MAX_VALUE;
-                String[] range = s.split("-");
-                if (s.startsWith("-")) end = Integer.parseInt(range[1]);
-                else if (s.endsWith("-")) start = Integer.parseInt(range[0]);
-                else {
-                    start = Integer.parseInt(range[0]);
-                    end = Integer.parseInt(range[1]);
-                }
-                // never return more than mMaxEntries
-                if (end - start > mMaxEntries) {
-                    end = start + mMaxEntries;
-                }
+                start = Integer.parseInt(s);
+                if (start > 0) end = start + mMaxEntries;
             } catch (Throwable t) {
                 mLogger.warn("Unparsable range: " + pathInfo[2]);
             }
@@ -212,9 +198,7 @@
             return getCollectionOfEntries(pathInfo, start, end);
         } else if (pathInfo.length > 0 && pathInfo[1].equals("resources")) {
             return getCollectionOfResources(pathInfo, start, end);
-        } /* else if (pathInfo.length > 0 && pathInfo[1].equals("categories")) 
{
-            return getCollectionOfCategories(pathInfo, start, end);
-        }*/
+        }
         throw new Exception("ERROR: bad URL in getCollection()");
     }
     
@@ -235,12 +219,34 @@
                     null,   // catName
                     null,   // status
                     start, // offset (for range paging)
-                    end - start + 1);  // maxEntries
+                    end - start + 2);  // maxEntries
             Feed feed = new Feed();
             List atomEntries = new ArrayList();
+            int count = 0;
             for (Iterator iter = entries.iterator(); iter.hasNext();) {
                 WeblogEntryData rollerEntry = (WeblogEntryData)iter.next();
                 atomEntries.add(createAtomEntry(rollerEntry));
+                count++;
+            }
+            if (count > start - end) { // add next link
+                int nextOffset = start + mMaxEntries; 
+                String url = absUrl + "/app/" + website.getHandle() + 
"/entries/" + nextOffset;
+                Link nextLink = new Link();
+                nextLink.setRel("next");
+                nextLink.setHref(url);
+                List next = new ArrayList();
+                next.add(nextLink);
+                feed.setOtherLinks(next);
+            }
+            if (start > 0) { // add previous link
+                int prevOffset = start > mMaxEntries ? start - mMaxEntries : 0;
+                String url = absUrl + "/app/" +website.getHandle() + 
"/entries/" + prevOffset;
+                Link prevLink = new Link();
+                prevLink.setRel("previous");
+                prevLink.setHref(url);
+                List prev = new ArrayList();
+                prev.add(prevLink);
+                feed.setOtherLinks(prev);
             }
             feed.setEntries(atomEntries);
             return feed;
@@ -261,12 +267,34 @@
         if (canView(website)) {            
             Feed feed = new Feed();
             List atomEntries = new ArrayList();
+            int count = 0;
             if (files != null && start < files.length) {
                 end = (end > files.length) ? files.length : end;
                 for (int i=start; i<end; i++) {                   
                     Entry entry = createAtomResourceEntry(website, files[i]);
                     atomEntries.add(entry);
+                    count++;
                 }
+            }
+            if (start + count > files.length) { // add next link
+                int nextOffset = start + mMaxEntries; 
+                String url = absUrl + "/app/" + website.getHandle() + 
"/resources/" + nextOffset;
+                Link nextLink = new Link();
+                nextLink.setRel("next");
+                nextLink.setHref(url);
+                List next = new ArrayList();
+                next.add(nextLink);
+                feed.setOtherLinks(next);
+            }
+            if (start > 0) { // add previous link
+                int prevOffset = start > mMaxEntries ? start - mMaxEntries : 0;
+                String url = absUrl + "/app/" +website.getHandle() + 
"/resources/" + prevOffset;
+                Link prevLink = new Link();
+                prevLink.setRel("previous");
+                prevLink.setHref(url);
+                List prev = new ArrayList();
+                prev.add(prevLink);
+                feed.setOtherLinks(prev);
             }
             feed.setEntries(atomEntries);
             return feed;

Modified: 
incubator/roller/trunk/sandbox/atomprotocol/tests/org/roller/presentation/atomapi04/AtomServletTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/tests/org/roller/presentation/atomapi04/AtomServletTest.java?rev=365539&r1=365538&r2=365539&view=diff
==============================================================================
--- 
incubator/roller/trunk/sandbox/atomprotocol/tests/org/roller/presentation/atomapi04/AtomServletTest.java
 (original)
+++ 
incubator/roller/trunk/sandbox/atomprotocol/tests/org/roller/presentation/atomapi04/AtomServletTest.java
 Mon Jan  2 20:51:15 2006
@@ -27,7 +27,7 @@
 import org.roller.presentation.atomapi.AtomCollection;
 import org.roller.presentation.atomapi.AtomService;
 import org.roller.presentation.atomapi.AtomServlet;
-import org.roller.presentation.atomapi.WSSEUtilities;
+import org.roller.util.WSSEUtilities;
 import org.roller.util.Utilities;
 
 import com.mockrunner.mock.web.ActionMockObjectFactory;


Reply via email to