roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r331195 - in /incubator/roller/trunk/sandbox/atomprotocol: ./ lib/ src/org/roller/presentation/atomapi/ src/org/roller/util/ src/org/roller/util/rome/
Date Mon, 07 Nov 2005 04:25:24 GMT
Author: snoopdave
Date: Sun Nov  6 20:24:58 2005
New Revision: 331195

URL: http://svn.apache.org/viewcvs?rev=331195&view=rev
Log:
Atom Pub. Protocol Draft 06 implementation

Added:
    incubator/roller/trunk/sandbox/atomprotocol/rome.properties
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModule.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleGenerator.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleImpl.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleParser.java
Removed:
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java
Modified:
    incubator/roller/trunk/sandbox/atomprotocol/lib/rome-0.8.jar
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomHandler.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomService.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java
    incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java

Modified: incubator/roller/trunk/sandbox/atomprotocol/lib/rome-0.8.jar
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/lib/rome-0.8.jar?rev=331195&r1=331194&r2=331195&view=diff
==============================================================================
Binary files - no diff available.

Added: incubator/roller/trunk/sandbox/atomprotocol/rome.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/rome.properties?rev=331195&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/rome.properties (added)
+++ incubator/roller/trunk/sandbox/atomprotocol/rome.properties Sun Nov  6 20:24:58 2005
@@ -0,0 +1,49 @@
+
+# Some RSS 0.91 feeds have pubDates in items
+
+WireFeedParser.classes=org.roller.util.rome.PlanetRSS091UParser \
+	                   org.roller.util.rome.PlanetRSS091NParser    
+	                                
+Converter.classes     =org.roller.util.rome.PlanetConverterForRSS091U \
+	                   org.roller.util.rome.PlanetConverterForRSS091N \
+	                   org.roller.util.rome.PlanetConverterForRSS20
+	              
+# Handle funky RSS (RSS 2.0 with <dc:date> and/or <content:encoded>)
+
+rss_2.0.feed.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+                                      org.roller.util.rome.ContentModuleGenerator
+                                      
+rss_2.0.item.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+                                      org.roller.util.rome.ContentModuleGenerator
+                                      
+rss_2.0.feed.ModuleParser.classes    =com.sun.syndication.io.impl.DCModuleParser \
+                                      org.roller.util.rome.ContentModuleParser
+                                      
+rss_2.0.item.ModuleParser.classes    =com.sun.syndication.io.impl.DCModuleParser \
+                                      org.roller.util.rome.ContentModuleParser
+                                      
+# Handle <content:encoded> in RSS 1.0 
+
+rss_1.0.feed.ModuleParser.classes    =com.sun.syndication.io.impl.DCModuleParser \
+                                      org.roller.util.rome.ContentModuleParser
+                                      
+rss_1.0.item.ModuleParser.classes    =com.sun.syndication.io.impl.DCModuleParser \
+                                      org.roller.util.rome.ContentModuleParser
+                                      
+rss_1.0.feed.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+                                      org.roller.util.rome.ContentModuleGenerator
+
+rss_1.0.item.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+                                      org.roller.util.rome.ContentModuleGenerator
+                                  
+# Handle Atom Pub Protocol pubcontrol extension
+                                      
+atom_1.0.item.ModuleParser.classes   =org.roller.util.rome.PubControlModuleParser
+
+atom_1.0.item.ModuleGenerator.classes =org.roller.util.rome.PubControlModuleGenerator
+                                  
+
+
+
+
+              
\ No newline at end of file

Modified: incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomHandler.java?rev=331195&r1=331194&r2=331195&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomHandler.java (original)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomHandler.java Sun Nov  6 20:24:58 2005
@@ -19,13 +19,11 @@
 import java.util.Date;
 
 import com.sun.syndication.feed.atom.Entry;
+import com.sun.syndication.feed.atom.Feed;
 
 /**
  * Interface to be supported by an Atom server, expected lifetime: one request.
  * AtomServlet calls this generic interface instead of Roller specific APIs. 
- * Does not impose any specific set of collections, just three collection types: 
- * entries, resources and categories. Implementations determine what collections 
- * of each type exist and what URIs are used to get and edit them.
  * <p />
  * Designed to be Roller independent.
  * 
@@ -43,20 +41,9 @@
     
     /**
      * Return collection
-     * @param pathInfo Used to determine which collection
+     * @param pathInfo Used to determine which collection and range
      */   
-    public AtomCollection getCollection(String[] pathInfo) throws Exception;
-    
-    /**
-     * Return collection restricted by date range
-     * @param pathInfo Used to determine which collection
-     * @param start    Start date or null if none
-     * @param end      End date or null of none
-     * @param offset   Offset into query results (or -1 if none)
-     */
-    public AtomCollection getCollection(
-            String[] pathInfo, Date start, Date end, int offset) 
-        throws Exception; 
+    public Feed getCollection(String[] pathInfo) throws Exception;
     
     /**
      * Create a new entry specified by pathInfo and posted entry.
@@ -88,37 +75,35 @@
      * @param contentType MIME type of uploaded content
      * @param data Binary data representing uploaded content
      */
-    public String postResource(String[] pathInfo, String name, String contentType, 
+    public String postMedia(String[] pathInfo, String name, String contentType, 
             InputStream is) throws Exception;
 
     /**
      * Update a resource.
      * @param pathInfo Path info portion of URL
      */
-    public void putResource(String[] pathInfo, String contentType, 
+    public void putMedia(String[] pathInfo, String contentType, 
             InputStream is) throws Exception;
     
     /**
      * Delete resource specified by pathInfo.
      * @param pathInfo Path info portion of URL
      */
-    public void deleteResource(String[] pathInfo) throws Exception;
+    public void deleteMedia(String[] pathInfo) throws Exception;
     
     /**
      * Get resource file path (so Servlet can determine MIME type).
      * @param pathInfo Path info portion of URL
      */
-    public String getResourceFilePath(String[] pathInfo) throws Exception;
+    public String getMediaFilePath(String[] pathInfo) throws Exception;
     
     public boolean isIntrospectionURI(String [] pathInfo);  
  
     public boolean isCollectionURI(String [] pathInfo);   
     public boolean isEntryCollectionURI(String [] pathInfo);   
-    public boolean isResourceCollectionURI(String [] pathInfo);   
-    public boolean isCategoryCollectionURI(String [] pathInfo);  
+    public boolean isMediaCollectionURI(String [] pathInfo);   
     
     public boolean isEntryURI(String[] pathInfo);
-    public boolean isResourceURI(String[] pathInfo);
-    public boolean isCategoryURI(String[] pathInfo);
+    public boolean isMediaURI(String[] pathInfo);
 }
 

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=331195&r1=331194&r2=331195&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 Sun Nov  6 20:24:58 2005
@@ -26,249 +26,243 @@
 
 /**
  * This class models an Atom workspace.
- * 
  * @author Dave Johnson
  */
-/*
- * Based on: draft-ietf-atompub-protocol-04.txt 
+/* Based on: draft-ietf-atompub-protocol-06.txt
  * 
- * appService = 
- *    element app:service { 
- *       (appWorkspace* & anyElement* ) 
+ * appService =
+ *    element app:service {
+ *       appCommonAttributes,
+ *       ( appWorkspace+ 
+ *         & extensionElement* )
  *    }
- * 
+ *
  * Here is an example Atom workspace:
  * 
- * <?xml version="1.0" encoding='utf-8'?> 
- * <service
- *    xmlns="http://purl.org/atom/app#"> 
- *    <workspace title="Main Site" > 
- *       <collection
- *          contents="entries" title="My Blog Entries"
- *          href="http://example.org/reilly/feed" /> 
- *       <collection contents="generic"
- *          title="Documents" href="http://example.org/reilly/pic" /> 
- *    </workspace>
- *    <workspace title="Side Bar Blog"> 
- *       <collection contents="entries"
- *          title="Entries" href="http://example.org/reilly/feed" /> 
- *       <collection
- *          contents="http://example.net/booklist" title="Books"
- *          href="http://example.org/reilly/books" /> 
- *    </workspace> 
+ * <?xml version="1.0" encoding='utf-8'?>
+ * <service xmlns="http://purl.org/atom/app#">
+ *   <workspace title="Main Site" >
+ *     <collection
+ *       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>
  */
-public class AtomService
-{
-    public static final Namespace ns = 
-        Namespace.getNamespace("http://purl.org/atom/app#");
+public class AtomService {
+    public static final Namespace ns =
+            Namespace.getNamespace("http://purl.org/atom/app#");
     
     private List workspaces = new ArrayList();
-
-    public AtomService()
-    {
-    }
-
-    public void addWorkspace(AtomService.Workspace workspace)
-    {
+    
+    public AtomService() {
+    }
+    
+    public void addWorkspace(AtomService.Workspace workspace) {
         workspaces.add(workspace);
     }
-
-    public List getWorkspaces()
-    {
+    
+    public List getWorkspaces() {
         return workspaces;
     }
-
-    public void setWorkspaces(List workspaces)
-    {
+    
+    public void setWorkspaces(List workspaces) {
         this.workspaces = workspaces;
     }
-
+    
     /**
      * This class models an Atom workspace.
-     * 
+     *
      * @author Dave Johnson
      */
     /*
      * appWorkspace = element app:workspace { attribute title { text }, (
      * appCollection* & anyElement* ) }
      */
-    public static class Workspace
-    {
+    public static class Workspace {
         private String title       = null;
         private List   collections = new ArrayList();
-
-        public Workspace()
-        {
-        }
-
-        public List getCollections()
-        {
+        
+        public Workspace() {
+        }
+        
+        public List getCollections() {
             return collections;
         }
-
-        public void setCollections(List collections)
-        {
+        
+        public void setCollections(List collections) {
             this.collections = collections;
         }
-
-        public void addCollection(AtomService.Collection col)
-        {
+        
+        public void addCollection(AtomService.Collection col) {
             collections.add(col);
         }
-
+        
         /** Workspace must have a human readable title */
-        public String getTitle()
-        {
+        public String getTitle() {
             return title;
         }
-
-        public void setTitle(String title)
-        {
+        
+        public void setTitle(String title) {
             this.title = title;
         }
     }
-
+    
     /**
-     * This class models an Atom workspace collection.
-     * 
+     * This class models an Atom workspace collection.    
      * @author Dave Johnson
      */
-    /*
-     * appCollection = element app:collection { attribute title { text },
-     * attribute contents { text }, attribute href { text }, anyElement* }
+    /* appCollection =
+     *       element app:collection {
+     *          appCommonAttributes,
+     *          attribute title { text },
+     *          attribute href { text },
+     *          ( appMemberType
+     *            & appListTemplate
+     *            & extensionElement* )
+     *       }
      */
-    public static class Collection
-    {
-        private String title;
-        private String contents = "generic";
-        private String href;
-
-        public Collection()
-        {
+    public static class Collection {
+        private String title = null;
+        private String memberType = "entry"; // or "media"
+        private String listTemplate = null;
+        private String href = null;
+        
+        public Collection() {
         }
-
+        
         /**
-         * Contents attribute conveys the nature of a collection's member
-         * resources. May be "entry" or "generic" and defaults to "generic"
+         * Member type May be "entry" or "media".
          */
-        public String getContents()
-        {
-            return contents;
-        }
-
-        public void setContents(String contents)
-        {
-            this.contents = contents;
-        }
-
-                /** The URI of the collection */
-        public String getHref()
-        {
+        public String getMemberType() {
+            return memberType;
+        }
+        
+        public void setMemberType(String memberType) {
+            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;
         }
-
-        public void setHref(String href)
-        {
+        
+        public void setHref(String href) {
             this.href = href;
         }
-
-                /** Must have human readable title */
-        public String getTitle()
-        {
+        
+        /** Must have human readable title */
+        public String getTitle() {
             return title;
         }
-
-        public void setTitle(String title)
-        {
+        
+        public void setTitle(String title) {
             this.title = title;
         }
     }
-
+    
     /** Deserialize an Atom service XML document into an object */
-    public static AtomService documentToService(Document document)
-    {
+    public static AtomService documentToService(Document document) {
         AtomService service = new AtomService();
         Element root = document.getRootElement();
         List spaces = root.getChildren("workspace", ns);
         Iterator iter = spaces.iterator();
-        while (iter.hasNext())
-        {
+        while (iter.hasNext()) {
             Element e = (Element) iter.next();
             service.addWorkspace(AtomService.elementToWorkspace(e));
         }
         return service;
     }
-
+    
     /** Serialize an AtomService object into an XML document */
-    public static Document serviceToDocument(AtomService service)
-    {
+    public static Document serviceToDocument(AtomService service) {
         Document doc = new Document();
         Element root = new Element("service", ns);
         doc.setRootElement(root);
         Iterator iter = service.getWorkspaces().iterator();
-        while (iter.hasNext())
-        {
+        while (iter.hasNext()) {
             AtomService.Workspace space = (AtomService.Workspace) iter.next();
             root.addContent(AtomService.workspaceToElement(space));
         }
         return doc;
     }
-
+    
     /** Deserialize a Atom workspace XML element into an object */
-    public static AtomService.Workspace elementToWorkspace(Element element)
-    {
+    public static AtomService.Workspace elementToWorkspace(Element element) {
         AtomService.Workspace space = new AtomService.Workspace();
         space.setTitle(element.getAttribute("title").getValue());
         List collections = element.getChildren("collection", ns);
         Iterator iter = collections.iterator();
-        while (iter.hasNext())
-        {
+        while (iter.hasNext()) {
             Element e = (Element) iter.next();
             space.addCollection(AtomService.elementToCollection(e));
         }
         return space;
     }
-
+    
     /** Serialize an AtomService.Workspace object into an XML element */
-    public static Element workspaceToElement(Workspace space)
-    {
+    public static Element workspaceToElement(Workspace space) {
         Namespace ns = Namespace.getNamespace("http://purl.org/atom/app#");
         Element element = new Element("workspace", ns);
         element.setAttribute("title", space.getTitle());
         Iterator iter = space.getCollections().iterator();
-        while (iter.hasNext())
-        {
+        while (iter.hasNext()) {
             AtomService.Collection col = (AtomService.Collection) iter.next();
             element.addContent(collectionToElement(col));
         }
         return element;
     }
-
+    
     /** Deserialize an Atom service collection XML element into an object */
-    public static AtomService.Collection elementToCollection(Element element)
-    {
+    public static AtomService.Collection elementToCollection(Element element) {
         AtomService.Collection collection = new AtomService.Collection();
         collection.setTitle(element.getAttribute("title").getValue());
         collection.setHref(element.getAttribute("href").getValue());
-        if (element.getAttribute("href") != null)
-        {
-            collection.setContents(element.getAttribute("contents").getValue());
+        Element memberType = element.getChild("member-type",  ns);
+        if (memberType != null) {
+            collection.setMemberType(memberType.getText());
+        }
+        Element listTemplate = element.getChild("list-template",  ns);
+        if (listTemplate != null) {
+            collection.setListTemplate(listTemplate.getText());
         }
         return collection;
     }
-
+    
     /** Serialize an AtomService.Collection object into an XML element */
-    public static Element collectionToElement(AtomService.Collection collection)
-    {
+    public static Element collectionToElement(AtomService.Collection collection) {
         Namespace ns = Namespace.getNamespace("http://purl.org/atom/app#");
         Element element = new Element("collection", ns);
-        element.setAttribute("title", collection.getTitle()); 
+        element.setAttribute("title", collection.getTitle());
         element.setAttribute("href", collection.getHref());
-        if (collection.getContents() != null)
-        {
-            element.setAttribute("contents", collection.getContents());
-        }
+        
+        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;
     }
 }

Modified: incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java?rev=331195&r1=331194&r2=331195&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java (original)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java Sun Nov  6 20:24:58 2005
@@ -51,24 +51,22 @@
 /**
  * Atom Servlet implements Atom by calling a Roller independent handler.
  * @web.servlet name="AtomServlet"
- * @web.servlet-mapping url-pattern="/app05/*"
+ * @web.servlet-mapping url-pattern="/app/*"
  * @author David M Johnson
  */
-public class AtomServlet extends HttpServlet
-{
-    public static final String FEED_TYPE = "atom_1.0"; 
+public class AtomServlet extends HttpServlet {
+    public static final String FEED_TYPE = "atom_1.0";
+    
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(AtomServlet.class);
     
-    private static Log mLogger = 
-        LogFactory.getFactory().getInstance(AtomServlet.class);
-
     //-----------------------------------------------------------------------------
     /**
      * Create an Atom request handler.
      * TODO: make AtomRequestHandler implementation configurable.
      */
-    private AtomHandler createAtomRequestHandler(HttpServletRequest request)
-    {
-        return new RollerAtomHandler(request);   
+    private AtomHandler createAtomRequestHandler(HttpServletRequest request) {
+        return new RollerAtomHandler(request);
     }
     
     //-----------------------------------------------------------------------------
@@ -76,19 +74,15 @@
      * Handles an Atom GET by calling handler and writing results to response.
      */
     protected void doGet(HttpServletRequest req, HttpServletResponse res)
-        throws ServletException, IOException
-    {
+    throws ServletException, IOException {
         AtomHandler handler = createAtomRequestHandler(req);
         String userName = handler.getAuthenticatedUsername();
-        if (userName != null) 
-        {
+        if (userName != null) {
             String[] pathInfo = getPathInfo(req);
-            try
-            {
-                if (handler.isIntrospectionURI(pathInfo)) 
-                {
+            try {
+                if (handler.isIntrospectionURI(pathInfo)) {
                     // return an Atom Service document
-                    AtomService service = handler.getIntrospection(pathInfo);                   
+                    AtomService service = handler.getIntrospection(pathInfo);
                     Document doc = AtomService.serviceToDocument(service);
                     Writer writer = res.getWriter();
                     XMLOutputter outputter = new XMLOutputter();
@@ -96,100 +90,65 @@
                     outputter.output(doc, writer);
                     writer.close();
                     res.setStatus(HttpServletResponse.SC_OK);
-                }
-                else if (handler.isCollectionURI(pathInfo))
-                {
+                } else if (handler.isCollectionURI(pathInfo)) {
                     // return a collection
-                    String ranges = req.getHeader("Range");
-                    if (ranges == null) req.getParameter("Range");
-                    AtomCollection col = null;
-                    if (ranges != null) 
-                    {
-                        /* // return a range of collection members
-                        AtomCollection.Range range = 
-                            AtomCollection.parseRange(req.getHeader("Range"));
-                        int offset = 0;
-                        String offsetString = req.getParameter("offset");
-                        if (offsetString != null) 
-                        {
-                            offset = Integer.parseInt(offsetString);
-                        }
-                        col= handler.getCollection(
-                            pathInfo, range.start, range.end, offset); */
-                    }
-                    else 
-                    {
-                        col= handler.getCollection(pathInfo);
-                    }
-                    // serialize collection to XML and write it out
-                    Document doc = AtomCollection.collectionToDocument(col);
+                    Feed col = handler.getCollection(pathInfo);
+                    col.setFeedType(FEED_TYPE);
+                    WireFeedOutput wireFeedOutput = new WireFeedOutput();
+                    Document feedDoc = wireFeedOutput.outputJDom(col);
                     Writer writer = res.getWriter();
                     XMLOutputter outputter = new XMLOutputter();
                     outputter.setFormat(Format.getPrettyFormat());
-                    outputter.output(doc, writer);
+                    outputter.output(feedDoc, writer);
                     writer.close();
                     res.setStatus(HttpServletResponse.SC_OK);
-                }
-                else if (handler.isEntryURI(pathInfo)) 
-                {
+                } else if (handler.isEntryURI(pathInfo)) {
                     // return an entry
-                    Entry entry = handler.getEntry(pathInfo);                    
-                    Writer writer = res.getWriter(); 
-                    serializeEntry(entry, writer);                    
+                    Entry entry = handler.getEntry(pathInfo);
+                    Writer writer = res.getWriter();
+                    serializeEntry(entry, writer);
                     writer.close();
-                }
-                else if (handler.isResourceURI(pathInfo))
-                {
+                } else if (handler.isMediaURI(pathInfo)) {
                     // return a resource
-                    String absPath = handler.getResourceFilePath(pathInfo);
+                    String absPath = handler.getMediaFilePath(pathInfo);
                     String type = getServletContext().getMimeType(absPath);
                     res.setContentType(type);
                     Utilities.copyInputToOutput(
                         new FileInputStream(absPath), res.getOutputStream());
-                }
-                else
-                {
+                } else {
                     res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 }
-            }
-            catch (Exception e)
-            {
-                res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            } catch (Exception e) {
+                //res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 e.printStackTrace(res.getWriter());
                 mLogger.error(e);
             }
-        }
-        else 
-        {
+        } else {
             res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         }
     }
     
-    //-----------------------------------------------------------------------------  
+    //-----------------------------------------------------------------------------
     /**
      * Handles an Atom POST by calling handler to identify URI, reading/parsing
      * data, calling handler and writing results to response.
      */
     protected void doPost(HttpServletRequest req, HttpServletResponse res)
-        throws ServletException, IOException
-    {
+    throws ServletException, IOException {
         AtomHandler handler = createAtomRequestHandler(req);
         String userName = handler.getAuthenticatedUsername();
-        if (userName != null) 
-        {
+        if (userName != null) {
             String[] pathInfo = getPathInfo(req);
-            try
-            {
-                if (handler.isEntryCollectionURI(pathInfo)) 
-                {
-                    /* // parse incoming entry                    
+            try {
+                if (handler.isEntryCollectionURI(pathInfo)) {
+                    // parse incoming entry
                     Entry unsavedEntry = parseEntry(
                         new InputStreamReader(req.getInputStream()));
-                    
+                     
                     // call handler to post it
                     Entry savedEntry = handler.postEntry(pathInfo, unsavedEntry);
-                    Iterator links = savedEntry.getLinks().iterator();
-                    
+                    Iterator links = savedEntry.getAlternateLinks().iterator();
+                     
                     // return alternate link as Location header
                     while (links.hasNext()) {
                         Link link = (Link) links.next();
@@ -197,157 +156,123 @@
                             res.addHeader("Location", link.getHref());
                             break;
                         }
-                    }                  
+                    }
                     // write entry back out to response
                     res.setStatus(HttpServletResponse.SC_CREATED);
-                    Writer writer = res.getWriter(); 
-                    serializeEntry(savedEntry, writer);                    
-                    writer.close(); */
-                }
-                else if (handler.isResourceCollectionURI(pathInfo)) 
-                {
+                    Writer writer = res.getWriter();
+                    serializeEntry(savedEntry, writer);
+                    writer.close(); 
+                } else if (handler.isMediaCollectionURI(pathInfo)) {
                     // get incoming file name from HTTP header
                     String name = req.getHeader("Name");
                     
                     // hand input stream of to hander to post file
-                    String location = handler.postResource(
-                       pathInfo, name, req.getContentType(), req.getInputStream());
+                    String location = handler.postMedia(
+                            pathInfo, name, req.getContentType(), req.getInputStream());
                     res.setStatus(HttpServletResponse.SC_CREATED);
                     res.setHeader("Location", location);
-                }
-                else
-                {
+                } else {
                     res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 e.printStackTrace(res.getWriter());
                 mLogger.error(e);
             }
-        }
-        else 
-        {
+        } else {
             res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         }
     }
-
-    //-----------------------------------------------------------------------------    
+    
+    //-----------------------------------------------------------------------------
     /**
      * Handles an Atom PUT by calling handler to identify URI, reading/parsing
      * data, calling handler and writing results to response.
      */
     protected void doPut(HttpServletRequest req, HttpServletResponse res)
-        throws ServletException, IOException
-    {
+    throws ServletException, IOException {
         AtomHandler handler = createAtomRequestHandler(req);
         String userName = handler.getAuthenticatedUsername();
-        if (userName != null) 
-        {
+        if (userName != null) {
             String[] pathInfo = getPathInfo(req);
-            try
-            {
-                if (handler.isEntryURI(pathInfo)) 
-                {
+            try {
+                if (handler.isEntryURI(pathInfo)) {
                     // parse incoming entry
                     Entry unsavedEntry = parseEntry(
-                        new InputStreamReader(req.getInputStream()));
+                            new InputStreamReader(req.getInputStream()));
                     
                     // call handler to put entry
                     Entry updatedEntry = handler.putEntry(pathInfo, unsavedEntry);
                     
                     // write entry back out to response
-                    Writer writer = res.getWriter(); 
-                    serializeEntry(updatedEntry, writer);                    
+                    Writer writer = res.getWriter();
+                    serializeEntry(updatedEntry, writer);
                     res.setStatus(HttpServletResponse.SC_OK);
                     writer.close();
-                }
-                else if (handler.isResourceCollectionURI(pathInfo)) 
-                {
+                } else if (handler.isMediaCollectionURI(pathInfo)) {
                     // handle input stream to handler
-                    handler.putResource(
-                        pathInfo, req.getContentType(), req.getInputStream());
+                    handler.putMedia(
+                            pathInfo, req.getContentType(), req.getInputStream());
                     res.setStatus(HttpServletResponse.SC_OK);
-                }
-                else
-                {
+                } else {
                     res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 e.printStackTrace(res.getWriter());
                 mLogger.error(e);
             }
-        }
-        else 
-        {
+        } else {
             res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         }
     }
-
+    
     //-----------------------------------------------------------------------------
     /**
      * Handle Atom DELETE by calling appropriate handler.
      */
     protected void doDelete(HttpServletRequest req, HttpServletResponse res)
-        throws ServletException, IOException
-    {
+    throws ServletException, IOException {
         AtomHandler handler = createAtomRequestHandler(req);
         String userName = handler.getAuthenticatedUsername();
-        if (userName != null) 
-        {
+        if (userName != null) {
             String[] pathInfo = getPathInfo(req);
-            try
-            {
-                if (handler.isEntryURI(pathInfo)) 
-                {
-                    handler.deleteEntry(pathInfo); 
+            try {
+                if (handler.isEntryURI(pathInfo)) {
+                    handler.deleteEntry(pathInfo);
                     res.setStatus(HttpServletResponse.SC_OK);
-                }
-                else if (handler.isResourceURI(pathInfo)) 
-                {
-                    handler.deleteResource(pathInfo); 
+                } else if (handler.isMediaURI(pathInfo)) {
+                    handler.deleteMedia(pathInfo);
                     res.setStatus(HttpServletResponse.SC_OK);
-                }
-                else
-                {
+                } else {
                     res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                 e.printStackTrace(res.getWriter());
                 mLogger.error(e);
             }
-        }
-        else 
-        {
+        } else {
             res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
         }
     }
     
     //-----------------------------------------------------------------------------
     /**
-     * Convenience method to return the PathInfo from the request.  
+     * Convenience method to return the PathInfo from the request.
      */
-    protected String[] getPathInfo(HttpServletRequest request)
-    {
+    protected String[] getPathInfo(HttpServletRequest request) {
         String mPathInfo = request.getPathInfo();
         mPathInfo = (mPathInfo!=null) ? mPathInfo : "";
-        return StringUtils.split(mPathInfo,"/");   
+        return StringUtils.split(mPathInfo,"/");
     }
-
-    /** 
+    
+    /**
      * Utility method to make up for a Rome shortcoming:
      * Rome can only serialize entire feeds, not individual elements
      */
-    public static void serializeEntry(Entry entry, Writer writer) 
-        throws IllegalArgumentException, FeedException, IOException
-    {
+    public static void serializeEntry(Entry entry, Writer writer)
+    throws IllegalArgumentException, FeedException, IOException {
         // Build a feed containing only the entry
         List entries = new ArrayList();
         entries.add(entry);
@@ -366,20 +291,19 @@
         
         StringWriter sw = new StringWriter();  // DEBUG
         outputter.output(entryElement, sw);    // DEBUG
-        System.out.println(sw.toString());     // DEBUG    
+        System.out.println(sw.toString());     // DEBUG
         writer.write(sw.toString());           // DEBUG
         
         //outputter.output(entryElement, writer);
     }
     
-    /** 
+    /**
      * Utility method to make up for a Rome shortcoming:
      * Rome can only parse Atom data with XML document root 'feed'
      */
-    public static Entry parseEntry(Reader rd) 
-        throws JDOMException, IOException, IllegalArgumentException, FeedException 
-    {
-        // Parse entry into JDOM tree        
+    public static Entry parseEntry(Reader rd)
+    throws JDOMException, IOException, IllegalArgumentException, FeedException {
+        // Parse entry into JDOM tree
         SAXBuilder builder = new SAXBuilder();
         Document entryDoc = builder.build(rd);
         Element fetchedEntryElement = entryDoc.getRootElement();
@@ -389,7 +313,7 @@
         Feed feed = new Feed();
         feed.setFeedType(FEED_TYPE);
         WireFeedOutput wireFeedOutput = new WireFeedOutput();
-        Document feedDoc = wireFeedOutput.outputJDom(feed); 
+        Document feedDoc = wireFeedOutput.outputJDom(feed);
         feedDoc.getRootElement().addContent(fetchedEntryElement);
         
         WireFeedInput input = new WireFeedInput();

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=331195&r1=331194&r2=331195&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 Sun Nov  6 20:24:58 2005
@@ -19,7 +19,6 @@
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
@@ -31,10 +30,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.util.RequestUtils;
-import org.roller.RollerException;
 import org.roller.model.FileManager;
 import org.roller.model.Roller;
-import org.roller.model.WeblogManager;
 import org.roller.pojos.UserData;
 import org.roller.pojos.PermissionsData;
 import org.roller.pojos.WeblogCategoryData;
@@ -48,9 +45,13 @@
 import com.sun.syndication.feed.atom.Content;
 import com.sun.syndication.feed.atom.Category;
 import com.sun.syndication.feed.atom.Entry;
+import com.sun.syndication.feed.atom.Feed;
 import com.sun.syndication.feed.atom.Link;
 import com.sun.syndication.io.impl.Base64;
+import javax.activation.FileTypeMap;
 import org.roller.RollerException;
+import org.roller.util.rome.PubControlModule;
+import org.roller.util.rome.PubControlModuleImpl;
 
 /**
  * Roller's Atom Protocol implementation.
@@ -73,7 +74,7 @@
  *    ----------------   ------------
  *       entries           entry
  *       resources         resource
- *       categories        categories
+ *       categories        categories (not yet)
  * soon:
  *       users             user
  *       templates         template
@@ -106,7 +107,8 @@
         mRollerContext = RollerContext.getRollerContext(request);
         
         // TODO: decide what to do about authentication, is WSSE going to fly?
-        mUsername = authenticateWSSE(request);
+        //mUsername = authenticateWSSE(request);
+        mUsername = authenticateBASIC(request);
         
         if (mUsername != null) {
             try {
@@ -116,14 +118,6 @@
                 mLogger.error("ERROR: setting user", e);
             }
         }
-        //        try
-        //        {
-        //            md5Helper = MessageDigest.getInstance("MD5");
-        //        }
-        //        catch (NoSuchAlgorithmException e)
-        //        {
-        //            mLogger.debug("ERROR creating MD5 helper", e);
-        //        }
     }
     
     /**
@@ -156,20 +150,22 @@
                     
                     AtomService.Collection entryCol = new AtomService.Collection();
                     entryCol.setTitle("Collection: Weblog Entries for " + handle);
-                    entryCol.setContents("entries");
-                    entryCol.setHref(absUrl + "/atom/"+handle+"/entries");
+                    entryCol.setMemberType("entry");
+                    entryCol.setHref(absUrl + "/app/"+handle+"/entries");
+                    entryCol.setListTemplate(absUrl + "/app/"+handle+"/entries/{index}");
                     workspace.addCollection(entryCol);
                     
-                    AtomService.Collection catCol = new AtomService.Collection();
+                    /*AtomService.Collection catCol = new AtomService.Collection();
                     catCol.setTitle("Collection: Categories for " + handle);
-                    catCol.setContents("categories");
-                    catCol.setHref(absUrl + "/atom/"+handle+"/categories");
-                    workspace.addCollection(catCol);
+                    catCol.setMemberType("entry");
+                    catCol.setHref(absUrl + "/app/"+handle+"/categories");
+                    workspace.addCollection(catCol);*/
                     
                     AtomService.Collection uploadCol = new AtomService.Collection();
-                    uploadCol.setTitle("Collection: File uploads for " + handle);
-                    uploadCol.setContents("generic");
-                    uploadCol.setHref(absUrl + "/atom/"+handle+"/resources");
+                    uploadCol.setTitle("Collection: Resources for " + handle);
+                    uploadCol.setMemberType("media");
+                    uploadCol.setHref(absUrl + "/app/"+handle+"/resources");
+                    uploadCol.setListTemplate(absUrl + "/app/"+handle+"/resources/{index}");
                     workspace.addCollection(uploadCol);
                 }
             }
@@ -181,102 +177,78 @@
     //----------------------------------------------------------------- collections
     
     /**
-     * Returns collection specified by pathInfo with no date range specified.
-     * Just calls the other getCollection(), but with offset = -1.
-     */
-    public AtomCollection getCollection(String[] pathInfo) throws Exception {
-        return getCollection(pathInfo, null, new Date(), -1);
-    }
-    
-    /**
      * Returns collection specified by pathInfo, constrained by a date range and
      * starting at an offset within the collection.Returns 20 items at a time.
      * <pre>
      * Supports these three collection URI forms:
-     *    /<blog-name>/entries
-     *    /<blog-name>/resources
-     *    /<blog-name>/categories
+     *    /<blog-name>/entries/{index}
+     *    /<blog-name>/resources/{index}
+     *    /<blog-name>/categories/{index}
      * </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 AtomCollection getCollection(
-            String[] pathInfo, Date start, Date end, int offset)
-            throws Exception {
+    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
+                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;
+                }
+            } catch (Throwable t) {
+                mLogger.warn("Unparsable range: " + pathInfo[2]);
+            }
+        }
         if (pathInfo.length > 0 && pathInfo[1].equals("entries")) {
-            return getCollectionOfEntries(pathInfo, start, end, offset);
+            return getCollectionOfEntries(pathInfo, start, end);
         } else if (pathInfo.length > 0 && pathInfo[1].equals("resources")) {
-            return getCollectionOfResources(pathInfo, start, end, offset);
-        } else if (pathInfo.length > 0 && pathInfo[1].equals("categories")) {
-            return getCollectionOfCategories(pathInfo, start, end, offset);
-        }
+            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()");
     }
     
     /**
      * Helper method that returns collection of entries, called by getCollection().
      */
-    public AtomCollection getCollectionOfEntries(
-            String[] pathInfo, Date start, Date end, int offset)
-            throws Exception {
+    public Feed getCollectionOfEntries(
+            String[] pathInfo, int start, int end) throws Exception {
         String handle = pathInfo[0];
         String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
         WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
         List entries = null;
         if (canView(website)) {
-            if (pathInfo.length == 2) // handle /blogname/entries
-            {
-                // return most recent blog entries
-                if (offset == -1) {
-                    entries = mRoller.getWeblogManager().getWeblogEntries(
-                            website,           // website
-                            start,             // startDate
-                            end,               // endDate
-                            null,              // catName
-                            null, // status
-                            new Integer(mMaxEntries + 1)); // maxEntries
-                } else {
-                    entries = mRoller.getWeblogManager().getWeblogEntries(
-                            website,           // website
-                            start,             // startDate
-                            end,               // endDate
-                            null,              // catName
-                            null, // status
-                            offset,            // offset (for range paging)
-                            mMaxEntries + 1);  // maxEntries
-                }
-            } else if (pathInfo.length == 3) // handle /blogname/entries/entryid
-            {
-                // return entries previous to entry specified by pathInfo
-                String entryid = pathInfo[2];
-                WeblogManager wmgr = mRoller.getWeblogManager();
-                WeblogEntryData entry = wmgr.retrieveWeblogEntry(entryid);
-                entries = wmgr.getPreviousEntries(entry, null, mMaxEntries + 1);
-            } else throw new Exception("ERROR: bad URL");
-            
-            // build collection
-            AtomCollection col = new AtomCollection();
-            /* if (entries.size() > mMaxEntries) {
-                // there are more entries, so include next link
-                WeblogEntryData lastEntry =
-                        (WeblogEntryData)entries.get(entries.size() - 1);
-                col.setNext(createNextLink(lastEntry, start, end, offset));
-            } 
-            // add up to max entries to collection
-            int count = 0;
-            Iterator iter = entries.iterator();
-            while (iter.hasNext() && count++ < mMaxEntries) {
+            entries = mRoller.getWeblogManager().getWeblogEntries(
+                    website,  // website
+                    null,   // startDate
+                    null,   // endDate
+                    null,   // catName
+                    null,   // status
+                    start, // offset (for range paging)
+                    end);  // maxEntries
+            Feed feed = new Feed();
+            List atomEntries = new ArrayList();
+            for (Iterator iter = entries.iterator(); iter.hasNext();) {
                 WeblogEntryData rollerEntry = (WeblogEntryData)iter.next();
-                AtomCollection.Member member = new AtomCollection.Member();
-                member.setTitle(rollerEntry.getDisplayTitle());
-                member.setUpdated(rollerEntry.getUpdateTime());
-                member.setHref(absUrl
-                        + "/atom/" + handle + "/entry/" + rollerEntry.getId());
-                col.addMember(member);
-            } */
-            return col;
+                atomEntries.add(createAtomEntry(rollerEntry));
+            }
+            feed.setEntries(atomEntries);
+            return feed;
         }
         throw new Exception("ERROR: not authorized");
     }
@@ -284,57 +256,94 @@
     /**
      * Helper method that returns collection of resources, called by getCollection().
      */
-    public AtomCollection getCollectionOfResources(
-            String[] pathInfo, Date start, Date end, int offset) throws Exception {
+    public Feed getCollectionOfResources(
+            String[] pathInfo, int start, int end) throws Exception {
         String handle = pathInfo[0];
         String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
         WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
         FileManager fmgr = mRoller.getFileManager();
         File[] files = fmgr.getFiles(website);
         if (canView(website)) {
-            AtomCollection col = new AtomCollection();
-            /* for (int i=0; i<files.length; i++) {
-                AtomCollection.Member member = new AtomCollection.Member();
-                member.setTitle(files[i].getName());
-                member.setUpdated(new Date(files[i].lastModified()));
-                member.setHref(absUrl
-                        + "/atom/" + website.getHandle() + "/resource/" + files[i].getName() );
-                col.addMember(member);
-            } */
-            return col;
+            
+            Feed feed = new Feed();
+            List atomEntries = new ArrayList();
+            if (files != null && start < files.length) {
+                end = (end > files.length) ? files.length : end;
+                for (int i=start; i<end; i++) {
+                    
+                    Entry entry = new Entry();
+                    entry.setTitle(files[i].getName());
+                    entry.setUpdated(new Date(files[i].lastModified()));
+                    
+                    String href = absUrl
+                            + "/app/" + website.getHandle()
+                            + "/resource/" + files[i].getName();
+                    
+                    FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
+                    String contentType = map.getContentType(files[i]);
+                    
+                    Link editlink = new Link();
+                    editlink.setRel("edit");
+                    editlink.setHref(absUrl 
+                        + "/resource/" + website.getHandle() 
+                        + "/" + files[i].getName());
+                    List otherlinks = new ArrayList();
+                    otherlinks.add(editlink);
+                    entry.setOtherLinks(otherlinks);
+                    
+                    Content content = new Content();
+                    content.setSrc(href);
+                    content.setType(contentType);
+                    List contents = new ArrayList();
+                    contents.add(content);
+                    entry.setContents(contents);
+                    
+                    atomEntries.add(entry);
+                }
+            }
+            feed.setEntries(atomEntries);
+            return feed;
         }
         throw new Exception("ERROR: not authorized");
     }
     
-    /**
-     * Helper method that returns collection of categories, called by getCollection().
-     */
-    public AtomCollection getCollectionOfCategories(
-            String[] pathInfo, Date start, Date end, int offset) throws Exception {
+    /* public Feed getCollectionOfCategories(
+            String[] pathInfo, int start, int end) throws Exception {
         String handle = pathInfo[0];
         String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
         WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
         WeblogManager wmgr = mRoller.getWeblogManager();
         List items = wmgr.getWeblogCategories(website);
         if (canView(website)) {
-            AtomCollection col = new AtomCollection();
-            /* Iterator iter = items.iterator();
+            Feed feed = new Feed();
+            List atomEntries = new ArrayList();
+            Iterator iter = items.iterator();
             Date now = new Date();
             while (iter.hasNext()) {
                 WeblogCategoryData item = (WeblogCategoryData)iter.next();
-                AtomCollection.Member member = new AtomCollection.Member();
+                Entry entry = new Entry();
                 String name = item.getPath();
                 if (name.equals("/")) continue;
-                member.setTitle(name);
-                member.setUpdated(now);
-                member.setHref(absUrl + "/atom/"  
-                    + website.getHandle() + "/category/" + item.getId());
-                col.addMember(member);
-            } */
+                entry.setTitle(name);
+                entry.setUpdated(now);
+     
+                String href = absUrl
+                    + "/atom/" + website.getHandle()
+                    + "/category/" + item.getId();
+     
+                Content content = new Content();
+                content.setValue(name);
+                List contents = new ArrayList();
+                contents.add(content);
+                entry.setContents(contents);
+     
+                atomEntries.add(entry);
+            }
+            feed.setEntries(atomEntries);
             return col;
         }
         throw new Exception("ERROR: not authorized");
-    }
+    }*/
     
     //--------------------------------------------------------------------- entries
     
@@ -401,18 +410,26 @@
                     Content romeContent = (Content)contents.get(0);
                     rollerEntry.setText(romeContent.getValue());
                 }
-
                 
+                PubControlModule control = (PubControlModule)
+                    entry.getModule("http://purl.org/atom/app#");
+                if (control!=null && control.getDraft()!=null) {
+                    if (control.getDraft().booleanValue()) {
+                        rollerEntry.setStatus(WeblogEntryData.DRAFT);
+                    } else {
+                        rollerEntry.setStatus(WeblogEntryData.PUBLISHED);
+                    }
+                }    
                 rollerEntry.setUpdateTime(new Timestamp(new Date().getTime()));
                 if (entry.getPublished() != null) {
                     rollerEntry.setPubTime(
-                        new Timestamp(entry.getPublished().getTime()));
+                            new Timestamp(entry.getPublished().getTime()));
                 }
                 if (entry.getCategories() != null
                         && entry.getCategories().size() > 0) {
                     Category atomCat = (Category)entry.getCategories().get(0);
-                    WeblogCategoryData cat = 
-                        mRoller.getWeblogManager().getWeblogCategoryByPath(
+                    WeblogCategoryData cat =
+                            mRoller.getWeblogManager().getWeblogCategoryByPath(
                             rollerEntry.getWebsite(), atomCat.getTerm());
                     if (cat != null) {
                         rollerEntry.setCategory(cat);
@@ -453,7 +470,7 @@
      * TODO: do we need to handle mutli-part MIME uploads?
      * TODO: use Jakarta Commons File-upload?
      */
-    public String postResource(String[] pathInfo,
+    public String postMedia(String[] pathInfo,
             String name, String contentType, InputStream is)
             throws Exception {
         // authenticated client posted a weblog entry
@@ -502,7 +519,7 @@
     /**
      * Get absolute path to resource specified by path info.
      */
-    public String getResourceFilePath(String[] pathInfo) throws Exception {
+    public String getMediaFilePath(String[] pathInfo) throws Exception {
         // ==> /<blogname>/resources/<filename>
         String uploadPath = RollerContext.getUploadPath(
                 mRequest.getSession(true).getServletContext());
@@ -513,11 +530,11 @@
      * Update resource specified by pathInfo using data from input stream.
      * Expects pathInfo of form /blog-name/resources/name
      */
-    public void putResource(String[] pathInfo,
+    public void putMedia(String[] pathInfo,
             String contentType, InputStream is) throws Exception {
         if (pathInfo.length > 2) {
             String name = pathInfo[2];
-            postResource(pathInfo, name, contentType, is);
+            postMedia(pathInfo, name, contentType, is);
         }
         throw new Exception("ERROR: bad pathInfo");
     }
@@ -526,7 +543,7 @@
      * Delete resource specified by pathInfo.
      * Expects pathInfo of form /blog-name/resources/name
      */
-    public void deleteResource(String[] pathInfo) throws Exception {
+    public void deleteMedia(String[] pathInfo) throws Exception {
         // authenticated client posted a weblog entry
         String handle = pathInfo[0];
         WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
@@ -564,7 +581,7 @@
     /**
      * True if URL is a resource URI.
      */
-    public boolean isResourceURI(String[] pathInfo) {
+    public boolean isMediaURI(String[] pathInfo) {
         if (pathInfo.length > 1 && pathInfo[1].equals("resource")) return true;
         return false;
     }
@@ -598,7 +615,7 @@
     /**
      * True if URL is a resource collection URI.
      */
-    public boolean isResourceCollectionURI(String[] pathInfo) {
+    public boolean isMediaCollectionURI(String[] pathInfo) {
         if (pathInfo.length > 1 && pathInfo[1].equals("resources")) return true;
         return false;
     }
@@ -723,8 +740,8 @@
                             String realpassword = LoginServlet.getEncryptedPassword(
                                     request, user.getUserName(), user.getPassword());
                             password = userPass.substring(p+1);
-                            if (    (!userID.trim().equals(user.getUserName()))
-                            && (!password.trim().equals(realpassword))) {
+                            if (    (userID.trim().equals(user.getUserName()))
+                            && (password.trim().equals(realpassword))) {
                                 valid = true;
                             }
                         }
@@ -741,28 +758,6 @@
     //----------------------------------------------------------- internal utilities
     
     /**
-     * Create next member list suitable for use in entry collection.
-     * Puts state date, end date and off set in request parameters.
-     */
-    private String createNextLink(
-            WeblogEntryData entry, Date start, Date end, int offset) {
-        SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );
-        String absUrl = mRollerContext.getAbsoluteContextUrl();
-        String url = absUrl + "/atom/" + mUsername + "/entries/" + entry.getId();
-        if (offset != -1 && start != null && end != null) {
-            url  = url + "?Range=" + df.format(start) + "/" + df.format(end);
-        } else if (offset != -1 && start != null) {
-            url  = url + "?Range=" + df.format(start) + "/";
-        } else if (offset != -1 && end != null) {
-            url  = url + "?Range=/" + df.format(end);
-        }
-        if (offset != -1) {
-            url = url + "&offset=" + (offset + mMaxEntries);
-        }
-        return url;
-    }
-    
-    /**
      * Create a Rome Atom entry based on a Roller entry.
      * Content is escaped.
      * Link is stored as rel=alternate link.
@@ -785,14 +780,30 @@
         Category atomCat = new Category();
         atomCat.setTerm(entry.getCategory().getPath());
         categories.add(atomCat);
-        atomEntry.setCategories(categories); 
-                
-        List links = new ArrayList();
+        atomEntry.setCategories(categories);
+        
         Link altlink = new Link();
         altlink.setRel("alternate");
         altlink.setHref(entry.getPermaLink());
-        links.add(altlink);
-        atomEntry.setAlternateLinks(links);
+        List altlinks = new ArrayList();
+        altlinks.add(altlink);
+        atomEntry.setAlternateLinks(altlinks);
+        
+        String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
+        Link editlink = new Link();
+        editlink.setRel("edit");
+        editlink.setHref(absUrl + "/app/"
+                + entry.getWebsite().getHandle() + "/entry/" + entry.getId());
+        List otherlinks = new ArrayList();
+        otherlinks.add(editlink);
+        atomEntry.setOtherLinks(otherlinks);
+        
+        List modules = new ArrayList();
+        PubControlModule pubControl = new PubControlModuleImpl();
+        pubControl.setDraft(
+            new Boolean(!WeblogEntryData.PUBLISHED.equals(entry.getStatus())));
+        modules.add(pubControl);
+        atomEntry.setModules(modules);
         
         return atomEntry;
     }
@@ -800,9 +811,9 @@
     /**
      * Create a Roller weblog entry based on a Rome Atom entry object
      */
-    private WeblogEntryData createRollerEntry(WebsiteData website, Entry entry) 
-        throws RollerException {
-
+    private WeblogEntryData createRollerEntry(WebsiteData website, Entry entry)
+    throws RollerException {
+        
         Timestamp current = new Timestamp(System.currentTimeMillis());
         Timestamp pubTime = current;
         Timestamp updateTime = current;
@@ -821,14 +832,23 @@
         rollerEntry.setPubTime(pubTime);
         rollerEntry.setUpdateTime(updateTime);
         rollerEntry.setWebsite(website);
-        rollerEntry.setStatus(WeblogEntryData.PUBLISHED);
+        
+        PubControlModule control = 
+            (PubControlModule)entry.getModule("http://purl.org/atom/app#");
+        if (control != null && control.getDraft() != null) {
+            if (!control.getDraft().booleanValue()) {
+                rollerEntry.setStatus(WeblogEntryData.PUBLISHED);
+            }
+        } else {
+            rollerEntry.setStatus(WeblogEntryData.DRAFT);
+        }
         
         List categories = entry.getCategories();
         if (categories != null && categories.size() > 0) {
             Category cat = (Category)categories.get(0);
             System.out.println(cat.getTerm());
-            WeblogCategoryData rollerCat = 
-                mRoller.getWeblogManager().getWeblogCategoryByPath(
+            WeblogCategoryData rollerCat =
+                    mRoller.getWeblogManager().getWeblogCategoryByPath(
                     website, cat.getTerm());
             rollerEntry.setCategory(rollerCat);
         } else {

Added: incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModule.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModule.java?rev=331195&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModule.java (added)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModule.java Sun Nov  6 20:24:58 2005
@@ -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.util.rome;
+
+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/util/rome/PubControlModuleGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleGenerator.java?rev=331195&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleGenerator.java (added)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleGenerator.java Sun Nov  6 20:24:58 2005
@@ -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.util.rome;
+
+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/util/rome/PubControlModuleImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleImpl.java?rev=331195&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleImpl.java (added)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleImpl.java Sun Nov  6 20:24:58 2005
@@ -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.util.rome;
+
+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/util/rome/PubControlModuleParser.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleParser.java?rev=331195&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleParser.java (added)
+++ incubator/roller/trunk/sandbox/atomprotocol/src/org/roller/util/rome/PubControlModuleParser.java Sun Nov  6 20:24:58 2005
@@ -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.util.rome;
+
+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;
+    }
+}
+



Mime
View raw message