[Yanel-commits] rev 21580 - in public/yanel/trunk/src: core/java/org/wyona/yanel/core/navigation core/java/org/wyona/yanel/servlet impl/java/org/wyona/yanel/impl/navigation

michi at wyona.com michi at wyona.com
Wed Jan 10 00:34:03 CET 2007


Author: michi
Date: 2007-01-10 00:34:01 +0100 (Wed, 10 Jan 2007)
New Revision: 21580

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/navigation/Node.java
   public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java
   public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/navigation/NodeRTIImpl.java
Log:
getChildren implemented

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/navigation/Node.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/navigation/Node.java	2007-01-09 23:17:23 UTC (rev 21579)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/navigation/Node.java	2007-01-09 23:34:01 UTC (rev 21580)
@@ -16,6 +16,8 @@
 
 package org.wyona.yanel.core.navigation;
 
+import org.wyona.yanel.core.Path;
+
 /**
  * Also see org.w3c.dom.Node
  */
@@ -74,4 +76,9 @@
      *
      */
     public Node getPreviousSibling();
+
+    /**
+     *
+     */
+    public Path getPath();
 }

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-09 23:17:23 UTC (rev 21579)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/servlet/YanelServlet.java	2007-01-09 23:34:01 UTC (rev 21580)
@@ -987,7 +987,7 @@
         Resource resource = getResource(request, response);
         //Node node = resource.getRealm().getSitetree().getNode(resource.getPath());
         Node node = sitetree.getNode(resource.getRealm(),resource.getPath());
-        log.error("DEBUG: Node: " + node);
+        log.error("DEBUG: Node: " + node + ", " + resource.getPath());
 
         String depth = request.getHeader("Depth");
         log.error("DEBUG: Depth: " + depth);
@@ -995,53 +995,69 @@
         StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
         sb.append("<multistatus xmlns=\"DAV:\">");
         if (depth.equals("0")) {
-            // TODO: decide if the requested node is a collection or a resource
-            sb.append("  <response>");
-            sb.append("    <href>"+request.getRequestURI()+"</href>");
-            sb.append("    <propstat>");
-            sb.append("      <prop>");
-            sb.append("        <resourcetype><collection/></resourcetype>");
-            sb.append("        <getcontenttype>http/unix-directory</getcontenttype>");
-            sb.append("      </prop>");
-            sb.append("      <status>HTTP/1.1 200 OK</status>");
-            sb.append("    </propstat>");
-            sb.append("  </response>");
-/*
-        sb.append("  <response>");
-        sb.append("    <href>/yanel/yanel-website/roadmap.html</href>");
-        sb.append("    <propstat>");
-        sb.append("      <prop>");
-        sb.append("        <resourcetype/>");
-        sb.append("      </prop>");
-        sb.append("    </propstat>");
-        sb.append("  </response>");
-*/
+            if (node.isCollection()) {
+                sb.append("  <response>");
+                sb.append("    <href>"+request.getRequestURI()+"</href>");
+                sb.append("    <propstat>");
+                sb.append("      <prop>");
+                sb.append("        <resourcetype><collection/></resourcetype>");
+                sb.append("        <getcontenttype>http/unix-directory</getcontenttype>");
+                sb.append("      </prop>");
+                sb.append("      <status>HTTP/1.1 200 OK</status>");
+                sb.append("    </propstat>");
+                sb.append("  </response>");
+            } else if (node.isResource()) {
+                sb.append("  <response>");
+                sb.append("    <href>"+request.getRequestURI()+"</href>");
+                sb.append("    <propstat>");
+                sb.append("      <prop>");
+                sb.append("        <resourcetype/>");
+                // TODO: Does getcontenttype also be set for resources?
+                sb.append("        <getcontenttype>http/unix-directory</getcontenttype>");
+                sb.append("      </prop>");
+                sb.append("      <status>HTTP/1.1 200 OK</status>");
+                sb.append("    </propstat>");
+                sb.append("  </response>");
+            } else {
+                log.error("Neither collection nor resource!");
+            }
         } else if (depth.equals("1")) {
-            log.warn("TODO: List children of this node");
-            sb.append("  <response>");
-            sb.append("    <href>"+request.getRequestURI()+"/directory/</href>");
-            sb.append("    <propstat>");
-            sb.append("      <prop>");
-            sb.append("        <displayname>A Directory</displayname>");
-            sb.append("        <resourcetype><collection/></resourcetype>");
-            sb.append("        <getcontenttype>http/unix-directory</getcontenttype>");
-            sb.append("      </prop>");
-            sb.append("      <status>HTTP/1.1 200 OK</status>");
-            sb.append("    </propstat>");
-            sb.append("  </response>");
-            sb.append("  <response>");
-            sb.append("    <href>"+request.getRequestURI()+"/file.txt</href>");
-            sb.append("    <propstat>");
-            sb.append("      <prop>");
-            sb.append("        <displayname>A File</displayname>");
-            sb.append("        <resourcetype/>");
-            sb.append("        <getcontenttype>http/unix-directory</getcontenttype>");
-            sb.append("      </prop>");
-            sb.append("      <status>HTTP/1.1 200 OK</status>");
-            sb.append("    </propstat>");
-            sb.append("  </response>");
+            Node[] children = node.getChildren();
+            if (children != null) {
+                for (int i = 0; i < children.length; i++) {
+                    if (children[i].isCollection()) {
+                        sb.append("  <response>\n");
+                        sb.append("    <href>" + request.getRequestURI() + children[i].getPath() + "/</href>\n");
+                        sb.append("    <propstat>\n");
+                        sb.append("      <prop>\n");
+                        sb.append("        <displayname>A Directory</displayname>\n");
+                        sb.append("        <resourcetype><collection/></resourcetype>\n");
+                        sb.append("        <getcontenttype>http/unix-directory</getcontenttype>\n");
+                        sb.append("      </prop>\n");
+                        sb.append("      <status>HTTP/1.1 200 OK</status>\n");
+                        sb.append("    </propstat>\n");
+                        sb.append("  </response>\n");
+                    } else if(children[i].isResource()) {
+                        sb.append("  <response>\n");
+                        sb.append("    <href>"+request.getRequestURI()+children[i].getPath()+"</href>\n");
+                        sb.append("    <propstat>\n");
+                        sb.append("      <prop>\n");
+                        sb.append("        <displayname>A File</displayname>\n");
+                        sb.append("        <resourcetype/>\n");
+                        sb.append("        <getcontenttype>http/unix-directory</getcontenttype>\n");
+                        sb.append("      </prop>\n");
+                        sb.append("      <status>HTTP/1.1 200 OK</status>\n");
+                        sb.append("    </propstat>\n");
+  		        sb.append("  </response>\n");
+                    } else {
+                        log.error("Neither collection nor resource: " + children[i].getPath());
+                    }
+                }
+            } else {
+                log.warn("No children!");
+            }
         } else if (depth.equals("infinity")) {
-             log.warn("TODO: List childen and their children and their childre ...");
+             log.warn("TODO: List children and their children and their children ...");
         } else {
              log.error("No such depth: " + depth);
         }

Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/navigation/NodeRTIImpl.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/navigation/NodeRTIImpl.java	2007-01-09 23:17:23 UTC (rev 21579)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/navigation/NodeRTIImpl.java	2007-01-09 23:34:01 UTC (rev 21580)
@@ -18,6 +18,9 @@
 
 import org.wyona.yanel.core.navigation.Node;
 
+import org.wyona.yarep.core.Path;
+import org.wyona.yarep.core.Repository;
+
 import org.apache.log4j.Category;
 
 /**
@@ -27,14 +30,15 @@
 
     private static Category log = Category.getInstance(NodeRTIImpl.class);
 
-    org.wyona.yarep.core.Path path;
+    Path path;
+    Repository repo;
 
     /**
      *
      */
     public NodeRTIImpl(org.wyona.yarep.core.Repository repo, org.wyona.yanel.core.Path path) {
-        this.path = new org.wyona.yarep.core.Path(path.toString());
-        log.error("Path: " + path);
+        this.path = new Path(path.toString());
+        this.repo = repo;
     }
 
     /**
@@ -74,6 +78,7 @@
      *
      */
     public boolean isResource() {
+        if (isCollection()) return false;
         return true;
     }
 
@@ -81,14 +86,39 @@
      *
      */
     public boolean isCollection() {
-        return true;
+        try {
+            Path[] children = repo.getChildren(path);
+            for (int i = 0; i < children.length; i++) {
+                if (children[i].getName().indexOf(".yanel-rti") > 0) {
+                    return true;
+                }
+            }
+        } catch(Exception e) {
+            log.error(e);
+        }
+        return false;
     }
 
     /**
      *
      */
     public Node[] getChildren() {
-        return null;
+        java.util.Vector c = new java.util.Vector();
+        try {
+            Path[] children = repo.getChildren(path);
+            for (int i = 0; i < children.length; i++) {
+                if (children[i].getName().indexOf(".yanel-rti") > 0) {
+                    c.add(children[i]);
+                }
+            }
+        } catch(Exception e) {
+            log.error(e);
+        }
+        Node[] nodes = new Node[c.size()];
+        for (int i = 0; i < c.size(); i++) {
+            nodes[i] = new NodeRTIImpl(repo, new org.wyona.yanel.core.Path(((Path) c.elementAt(i)).toString()));
+        }
+        return nodes;
     }
 
     /**
@@ -111,4 +141,11 @@
     public Node getPreviousSibling() {
         return null;
     }
+
+    /**
+     *
+     */
+    public org.wyona.yanel.core.Path getPath() {
+        return new org.wyona.yanel.core.Path(path.toString());
+    }
 }




More information about the Yanel-commits mailing list