[Yanel-commits] rev 22217 - in public/yanel/trunk/src: core/java/org/wyona/yanel/core/api/attributes core/java/org/wyona/yanel/servlet resources/file/src/java/org/wyona/yanel/impl/resources resources/xml/src/java/org/wyona/yanel/impl/resources

josias at wyona.com josias at wyona.com
Fri Jan 26 17:41:56 CET 2007


Author: josias
Date: 2007-01-26 17:41:54 +0100 (Fri, 26 Jan 2007)
New Revision: 22217

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
   public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
   public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/NodeResource.java
   public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
added methods for checkin/checkout/restore/view-revision to VersionableV2 interface and implemented them in XmlResource and NodeResource. further added checkin/checkout/view-revision to YanelServlet. to view a certain revision use the request parameter yanel.resource.revision=...

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java	2007-01-26 16:35:14 UTC (rev 22216)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/api/attributes/VersionableV2.java	2007-01-26 16:41:54 UTC (rev 22217)
@@ -16,12 +16,6 @@
 
 package org.wyona.yanel.core.api.attributes;
 
-import java.io.OutputStream;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.wyona.yanel.core.Path;
 import org.wyona.yanel.core.attributes.viewable.View;
 
 /**
@@ -29,16 +23,50 @@
  */
 public interface VersionableV2 {
 
+    /**
+     * Gets an array of revision names.
+     * @return
+     * @throws Exception
+     */
     public String[] getRevisions() throws Exception;
     
+    /**
+     * Gets the view of a certain revision.
+     * @param viewId
+     * @param revisionName
+     * @return
+     * @throws Exception
+     */
+    public View getView(String viewId, String revisionName) throws Exception;
+    
+    /**
+     * Restores an old revision with the given revision number.
+     * @param revisionName
+     * @throws Exception
+     */
+    public void restore(String revisionName) throws Exception;
+    
+    /**
+     * Checks out this resource. Noone else will be able to check it out afterwards.
+     * @param userID
+     * @throws Exception
+     */
+    public void checkout(String userID) throws Exception;
+    
+    /**
+     * Checks in this resource, and creates a new revision.
+     * @throws Exception
+     */
+    public void checkin() throws Exception;
+    
+    
     /*
      * Methods which could be added to this interface:
      * 
-     * public View getView(Path path, OutputStream out, String viewId, String revision) throws Exception;
-     * public void getView(HttpServletRequest request, HttpServletResponse response, String viewId, String revision) throws Exception;
-     * public void rollback(String revision) throws Exception;
      *
-     * getDiff(Path path, String rev1, String rev2) throws Exception;
+     * public boolean isCheckedOut() throws Exception;
+     * public String getCheckoutUserID() throws Exception;
+     * getDiff(String rev1, String rev2) throws Exception;
      * getHeadRevisionNumber() ?
      * 
      * open questions:

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2007-01-26 16:35:14 UTC (rev 22216)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2007-01-26 16:41:54 UTC (rev 22217)
@@ -223,6 +223,7 @@
             sessionAttributeElement.appendChild(doc.createTextNode(value));
         }
 
+        String usecase = request.getParameter("yanel.resource.usecase");
 
         Resource res = null;
         long lastModified = -1;
@@ -302,7 +303,12 @@
                         Element sizeElement = (Element) resourceElement.appendChild(doc.createElement("size"));
                         sizeElement.appendChild(doc.createTextNode(String.valueOf(size)));
                         try {
-                            view = ((ViewableV2) res).getView(viewId);
+                            String revisionName = request.getParameter("yanel.resource.revision");
+                            if (ResourceAttributeHelper.hasAttributeImplemented(res, "Versionable", "2") && revisionName != null) {
+                                view = ((VersionableV2) res).getView(viewId, revisionName);
+                            } else {
+                                view = ((ViewableV2) res).getView(viewId);
+                            }
                         } catch(org.wyona.yarep.core.NoSuchNodeException e) {
                             // TODO: Log all 404 within a dedicated file (with client info attached) such that an admin can react to it ...
                             String message = "No such node exception: " + e;
@@ -343,6 +349,22 @@
                     } else {
                         Element notVersionableElement = (Element) resourceElement.appendChild(doc.createElement("not-versionable"));
                     }
+                    
+                    
+                    if (usecase != null && usecase.equals("checkout")) {
+                        log.debug("Checkout data ...");
+                        if (ResourceAttributeHelper.hasAttributeImplemented(res, "Versionable", "2")) {
+                            // note: this will throw an exception if the document is checked out already
+                            // by another user.
+                            Identity identity = (Identity) request.getSession().getAttribute("identity");
+                            ((VersionableV2)res).checkout(identity.getUsername());
+                        }
+                        
+                        log.warn("Acquire lock has not been implemented yet ...!");
+                        // acquireLock();
+                    }
+
+
                 } else {
                         Element resourceIsNullElement = (Element) rootElement.appendChild(doc.createElement("resource-is-null"));
                 }
@@ -358,15 +380,6 @@
 
 
 
-        String usecase = request.getParameter("yanel.resource.usecase");
-
-        if (usecase != null && usecase.equals("checkout")) {
-            log.debug("Checkout data ...");
-            // TODO: Implement checkout ...
-            log.warn("Acquire lock has not been implemented yet ...!");
-            // acquireLock();
-        }
-
         String meta = request.getParameter("yanel.resource.meta");
         if (meta != null) {
             if (meta.length() > 0) {
@@ -452,7 +465,17 @@
         } else if (value != null && value.equals("checkin")) {
             log.debug("Checkin data ...");
             save(request, response);
-            // TODO: Implement checkin ...
+
+            Resource resource = getResource(request, response);
+            if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Versionable", "2")) {
+                try {
+                    ((VersionableV2)resource).checkin();
+                } catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                    throw new ServletException(e.getMessage(), e);
+                }
+            }
+
             log.warn("Release lock has not been implemented yet ...");
             // releaseLock();
             return;
@@ -510,7 +533,17 @@
         } else if (value != null && value.equals("checkin")) {
             log.debug("Checkin data ...");
             save(request, response);
-            // TODO: Implement checkin ...
+            
+            Resource resource = getResource(request, response);
+            if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Versionable", "2")) {
+                try {
+                    ((VersionableV2)resource).checkin();
+                } catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                    throw new ServletException(e.getMessage(), e);
+                }
+            }
+            
             log.warn("Release lock has not been implemented yet ...!");
             // releaseLock();
             return;

Modified: public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/NodeResource.java
===================================================================
--- public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/NodeResource.java	2007-01-26 16:35:14 UTC (rev 22216)
+++ public/yanel/trunk/src/resources/file/src/java/org/wyona/yanel/impl/resources/NodeResource.java	2007-01-26 16:41:54 UTC (rev 22217)
@@ -31,6 +31,7 @@
 import org.wyona.yarep.core.Node;
 import org.wyona.yarep.core.Repository;
 import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yarep.core.Revision;
 import org.wyona.yarep.util.RepoPath;
 
 import javax.servlet.http.HttpServletRequest;
@@ -64,6 +65,16 @@
         return null;
     }
 
+    public View getView(String viewId, String revisionName) throws Exception {
+        View defaultView = new View();
+        
+        defaultView.setInputStream(getRealm().getRepository().getNode(getPath())
+                .getRevision(revisionName).getInputStream());
+        defaultView.setMimeType(getMimeType(viewId));
+
+        return defaultView;
+    }
+
     /**
      *
      */
@@ -202,11 +213,37 @@
      *
      */
     public String[] getRevisions() throws Exception {
-        log.warn("Not implemented yet!");
-        return null; 
-        //return getRealm().getRepository().getRevisions(new Path(getPath()));
+        Revision[] revisions = getRealm().getRepository().getNode(getPath()).getRevisions();
+        String[] revisionNames = new String[revisions.length];
+        
+        for (int i=0; i<revisions.length; i++) {
+            revisionNames[i] = revisions[i].getRevisionName();
+        }
+        return revisionNames; 
     }
     
+    public void checkin() throws Exception {
+        getRealm().getRepository().getNode(getPath()).checkin();
+    }
+
+    public void checkout(String userID) throws Exception {
+        Node node = getRealm().getRepository().getNode(getPath()); 
+        if (node.isCheckedOut()) {
+            String checkoutUserID = node.getCheckoutUserID(); 
+            if (checkoutUserID.equals(userID)) {
+                log.warn("Resource " + getPath() + " is already checked out by this user: " + checkoutUserID);
+            } else {
+                throw new Exception("Resource is already checked out by another user: " + checkoutUserID);
+            }
+        } else {
+            node.checkout(userID);
+        }
+    }
+
+    public void restore(String revisionName) throws Exception {
+        getRealm().getRepository().getNode(getPath()).restore(revisionName);
+    }
+
     public boolean exists() throws Exception {
         log.warn("Not implemented yet!");
         return true; 

Modified: public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2007-01-26 16:35:14 UTC (rev 22216)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2007-01-26 16:41:54 UTC (rev 22217)
@@ -35,6 +35,7 @@
 import org.wyona.yarep.core.Node;
 import org.wyona.yarep.core.Repository;
 import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yarep.core.Revision;
 import org.wyona.yarep.util.RepoPath;
 
 import javax.servlet.http.HttpServletRequest;
@@ -81,10 +82,14 @@
         return null;
     }
 
+    public View getView(String viewId) throws Exception {
+        return getView(viewId, null);
+    }
+
     /**
      * Generates view
      */
-    public View getView(String viewId) throws Exception {
+    public View getView(String viewId, String revisionName) throws Exception {
         View defaultView = new View();
         String mimeType = getMimeType(getPath(), viewId);
         defaultView.setMimeType(mimeType);
@@ -118,7 +123,7 @@
 
                 org.xml.sax.XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
                 xmlReader.setEntityResolver(new org.apache.xml.resolver.tools.CatalogResolver());
-                transformer.transform(new SAXSource(xmlReader, new org.xml.sax.InputSource(getContentXML(repo, yanelPath))), new StreamResult(baos));
+                transformer.transform(new SAXSource(xmlReader, new org.xml.sax.InputSource(getContentXML(repo, yanelPath, revisionName))), new StreamResult(baos));
                 
                 InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
 
@@ -135,7 +140,7 @@
                 return defaultView;
             } else {
                 log.debug("Mime-Type: " + mimeType);
-                defaultView.setInputStream(getContentXML(repo, yanelPath));
+                defaultView.setInputStream(getContentXML(repo, yanelPath, revisionName));
             }
         } catch(Exception e) {
             log.error(e + " (" + getPath() + ", " + getRealm() + ")");
@@ -161,7 +166,7 @@
     /**
      *
      */
-    private InputStream getContentXML(Repository repo, String yanelPath) throws Exception {
+    private InputStream getContentXML(Repository repo, String yanelPath, String revisionName) throws Exception {
         if (yanelPath != null) {
             log.debug("Yanel Path: " + yanelPath);
             Resource res = yanel.getResourceManager().getResource(getRequest(), getResponse(), 
@@ -182,7 +187,13 @@
             }
         }
         
-        return repo.getNode(getPath()).getInputStream();
+        Node node;
+        if (revisionName != null) {
+            node = repo.getNode(getPath()).getRevision(revisionName);
+        } else {
+            node = repo.getNode(getPath());
+        }
+        return node.getInputStream();
     }
 
     /**
@@ -300,11 +311,38 @@
     }
 
     public String[] getRevisions() throws Exception {
-        //return getRealm().getRepository().getRevisions(getPath());
-        log.warn("Not implemented yet!");
-        return null; 
+        Revision[] revisions = getRealm().getRepository().getNode(getPath()).getRevisions();
+        String[] revisionNames = new String[revisions.length];
+        
+        for (int i=0; i<revisions.length; i++) {
+            revisionNames[i] = revisions[i].getRevisionName();
+        }
+        return revisionNames; 
     }
+    
+    public void checkin() throws Exception {
+        getRealm().getRepository().getNode(getPath()).checkin();
+    }
 
+    public void checkout(String userID) throws Exception {
+        Node node = getRealm().getRepository().getNode(getPath()); 
+        if (node.isCheckedOut()) {
+            String checkoutUserID = node.getCheckoutUserID(); 
+            if (checkoutUserID.equals(userID)) {
+                log.warn("Resource " + getPath() + " is already checked out by this user: " + checkoutUserID);
+            } else {
+                throw new Exception("Resource is already checked out by another user: " + checkoutUserID);
+            }
+        } else {
+            node.checkout(userID);
+        }
+    }
+
+    public void restore(String revisionName) throws Exception {
+        getRealm().getRepository().getNode(getPath()).restore(revisionName);
+    }
+
+
     public boolean exists() throws Exception {
         log.warn("Not implemented yet!");
         return true; 




More information about the Yanel-commits mailing list