[Yanel-commits] rev 34485 - in public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources: . navigation

michi at wyona.com michi at wyona.com
Tue Apr 1 09:09:06 CEST 2008


Author: michi
Date: 2008-04-01 09:09:05 +0200 (Tue, 01 Apr 2008)
New Revision: 34485

Added:
   public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/navigation/DataRepoSitetreeResource.java
Removed:
   public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/DataRepoSitetreeResource.java
Log:
moved

Deleted: public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/DataRepoSitetreeResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/DataRepoSitetreeResource.java	2008-04-01 07:08:51 UTC (rev 34484)
+++ public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/DataRepoSitetreeResource.java	2008-04-01 07:09:05 UTC (rev 34485)
@@ -1,164 +0,0 @@
-/*
- * Copyright 2006 Wyona
- */
-
-package org.wyona.yanel.impl.resources;
-
-import org.wyona.yanel.core.Resource;
-import org.wyona.yanel.core.api.attributes.ViewableV2;
-import org.wyona.yanel.core.attributes.viewable.View;
-import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
-import org.wyona.yanel.core.navigation.Node;
-import org.wyona.yanel.core.navigation.Sitetree;
-
-import org.apache.log4j.Category;
-
-/**
- *
- */
-public class DataRepoSitetreeResource extends Resource implements ViewableV2 {
-
-    private static Category log = Category.getInstance(DataRepoSitetreeResource.class);
-
-    /**
-     *
-     */
-    public DataRepoSitetreeResource() {
-    }
-
-    /**
-     *
-     */
-    public String getMimeType(String viewId) throws Exception {
-        if (viewId != null && viewId.equals("xml")) return "application/xml";
-        return "application/xhtml+xml";
-    }
-
-    /**
-     *
-     */
-    public long getSize() throws Exception {
-        return -1;
-    }
-
-    /**
-     *
-     */
-    public boolean exists() throws Exception {
-        return true;
-    }
-
-    /**
-     *
-     */
-    public View getView(String viewId) throws Exception {
-
-        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
-        if (viewId != null && viewId.equals("xml")) {
-            sb.append(getSitetreeAsXML());
-            //sb.append(getSitetreeAsXML(getPath().toString()));
-        } else {
-            sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><head><title>Browse Data Repository Sitetree</title></head><body><a href=\"?yanel.resource.viewid=xml\">Show XML</a><br/><br/>This content is being generated by the resource <![CDATA[" + getResourceTypeUniversalName() + "]]></body></html>");
-        }
-
-        View view = new View();
-        view.setMimeType(getMimeType(viewId));
-        view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
-        return view;
-    }
-
-    /**
-     *
-     */
-    public ViewDescriptor[] getViewDescriptors() {
-        try {
-            ViewDescriptor[] vd = new ViewDescriptor[2];
-            vd[0] = new ViewDescriptor("default");
-            vd[0].setMimeType(getMimeType(null));
-            vd[1] = new ViewDescriptor("xml");
-            vd[1].setMimeType(getMimeType("xml"));
-            return vd;
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            return null;
-        }
-    }
-
-    /**
-     * Get sitetree as XML
-     */
-    private String getSitetreeAsXML() {
-        StringBuffer sb = new StringBuffer("<sitetree>");
-        if (getRequest().getParameter("path") != null) {
-            sb.append(getNodeAsXML(request.getParameter("path")));
-        } else {
-            sb.append(getNodeAsXML("/"));
-        }
-
-        // TODO: Sitetree generated out of RDF resources and statements
-        /*
-        com.hp.hpl.jena.rdf.model.Resource rootResource = getRealm().getSitetreeRootResource();
-        sb.append(getNodeAsXML(rootResource));
-        */
-        sb.append("</sitetree>");
-
-        return sb.toString();
-    }
-
-    /**
-     * Get node as XML
-     */
-    private String getNodeAsXML(String path) {
-    //private String getNodeAsXML(com.hp.hpl.jena.rdf.model.Resource resource) {
-        //log.error("DEBUG: Path: " + path);
-        Sitetree sitetree = getRealm().getRepoNavigation();
-        Node node = sitetree.getNode(getRealm(), path);
-        StringBuffer sb = new StringBuffer("");
-
-        // TODO: Check for statements "parentOf" for this resource
-        /*
-        Statement[] st = resource.getStatements("parentOf");
-        if (st.length > 0) {
-            for (int i = 0; i < st.length; i++) {
-                Resource child = st.getObject();
-                URL url = getReal().getURLBuilder(child);
-            }
-        } else {
-            // Is not a collection, there are no children
-        }
-        */
-
-        if (node != null) {
-            if (node.isCollection()) {
-                sb.append("<collection path=\"" + path + "\" name=\"" + node.getName() + "\">");
-                Node[] children = node.getChildren();
-                for (int i = 0; i < children.length; i++) {
-                    String childPath = path + "/" + children[i].getName();
-                    if (path.equals("/")) {
-                        childPath = path + children[i].getName();
-                    }
-                    //log.debug("Child path: " + childPath);
-
-                    if (children[i].isCollection()) {
-                        sb.append(getNodeAsXML(childPath));
-                        //sb.append(getNodeAsXML(children[i].getPath()));
-                    } else if (children[i].isResource()) {
-                        sb.append("<resource path=\"" + childPath + "\" name=\"" + children[i].getName() + "\"/>");
-                        //sb.append("<resource path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
-                    } else {
-                        sb.append("<neither-resource-nor-collection path=\"" + childPath + "\" name=\"" + children[i].getName() + "\"/>");
-                        //sb.append("<neither-resource-nor-collection path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
-                    }
-                }
-                sb.append("</collection>");
-            } else {
-                sb.append("<resource path=\"" + path + "\" name=\"" + node.getName() + "\"/>");
-            }
-        } else {
-            String errorMessage = "node is null for path: " + path;
-            sb.append("<exception>" + errorMessage + "</exception>");
-            log.error(errorMessage);
-        }
-        return sb.toString();
-    }
-}

Copied: public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/navigation/DataRepoSitetreeResource.java (from rev 34414, public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/DataRepoSitetreeResource.java)
===================================================================
--- public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/navigation/DataRepoSitetreeResource.java	                        (rev 0)
+++ public/yanel/trunk/src/contributions/resources/data-repo-sitetree/src/java/org/wyona/yanel/impl/resources/navigation/DataRepoSitetreeResource.java	2008-04-01 07:09:05 UTC (rev 34485)
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.api.attributes.ViewableV2;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yanel.core.navigation.Node;
+import org.wyona.yanel.core.navigation.Sitetree;
+
+import org.apache.log4j.Category;
+
+/**
+ *
+ */
+public class DataRepoSitetreeResource extends Resource implements ViewableV2 {
+
+    private static Category log = Category.getInstance(DataRepoSitetreeResource.class);
+
+    /**
+     *
+     */
+    public DataRepoSitetreeResource() {
+    }
+
+    /**
+     *
+     */
+    public String getMimeType(String viewId) throws Exception {
+        if (viewId != null && viewId.equals("xml")) return "application/xml";
+        return "application/xhtml+xml";
+    }
+
+    /**
+     *
+     */
+    public long getSize() throws Exception {
+        return -1;
+    }
+
+    /**
+     *
+     */
+    public boolean exists() throws Exception {
+        return true;
+    }
+
+    /**
+     *
+     */
+    public View getView(String viewId) throws Exception {
+
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        if (viewId != null && viewId.equals("xml")) {
+            sb.append(getSitetreeAsXML());
+            //sb.append(getSitetreeAsXML(getPath().toString()));
+        } else {
+            sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><head><title>Browse Data Repository Sitetree</title></head><body><a href=\"?yanel.resource.viewid=xml\">Show XML</a><br/><br/>This content is being generated by the resource <![CDATA[" + getResourceTypeUniversalName() + "]]></body></html>");
+        }
+
+        View view = new View();
+        view.setMimeType(getMimeType(viewId));
+        view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+        return view;
+    }
+
+    /**
+     *
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        try {
+            ViewDescriptor[] vd = new ViewDescriptor[2];
+            vd[0] = new ViewDescriptor("default");
+            vd[0].setMimeType(getMimeType(null));
+            vd[1] = new ViewDescriptor("xml");
+            vd[1].setMimeType(getMimeType("xml"));
+            return vd;
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return null;
+        }
+    }
+
+    /**
+     * Get sitetree as XML
+     */
+    private String getSitetreeAsXML() {
+        StringBuffer sb = new StringBuffer("<sitetree>");
+        if (getRequest().getParameter("path") != null) {
+            sb.append(getNodeAsXML(request.getParameter("path")));
+        } else {
+            sb.append(getNodeAsXML("/"));
+        }
+
+        // TODO: Sitetree generated out of RDF resources and statements
+        /*
+        com.hp.hpl.jena.rdf.model.Resource rootResource = getRealm().getSitetreeRootResource();
+        sb.append(getNodeAsXML(rootResource));
+        */
+        sb.append("</sitetree>");
+
+        return sb.toString();
+    }
+
+    /**
+     * Get node as XML
+     */
+    private String getNodeAsXML(String path) {
+    //private String getNodeAsXML(com.hp.hpl.jena.rdf.model.Resource resource) {
+        //log.error("DEBUG: Path: " + path);
+        Sitetree sitetree = getRealm().getRepoNavigation();
+        Node node = sitetree.getNode(getRealm(), path);
+        StringBuffer sb = new StringBuffer("");
+
+        // TODO: Check for statements "parentOf" for this resource
+        /*
+        Statement[] st = resource.getStatements("parentOf");
+        if (st.length > 0) {
+            for (int i = 0; i < st.length; i++) {
+                Resource child = st.getObject();
+                URL url = getReal().getURLBuilder(child);
+            }
+        } else {
+            // Is not a collection, there are no children
+        }
+        */
+
+        if (node != null) {
+            if (node.isCollection()) {
+                sb.append("<collection path=\"" + path + "\" name=\"" + node.getName() + "\">");
+                Node[] children = node.getChildren();
+                for (int i = 0; i < children.length; i++) {
+                    String childPath = path + "/" + children[i].getName();
+                    if (path.equals("/")) {
+                        childPath = path + children[i].getName();
+                    }
+                    //log.debug("Child path: " + childPath);
+
+                    if (children[i].isCollection()) {
+                        sb.append(getNodeAsXML(childPath));
+                        //sb.append(getNodeAsXML(children[i].getPath()));
+                    } else if (children[i].isResource()) {
+                        sb.append("<resource path=\"" + childPath + "\" name=\"" + children[i].getName() + "\"/>");
+                        //sb.append("<resource path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
+                    } else {
+                        sb.append("<neither-resource-nor-collection path=\"" + childPath + "\" name=\"" + children[i].getName() + "\"/>");
+                        //sb.append("<neither-resource-nor-collection path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
+                    }
+                }
+                sb.append("</collection>");
+            } else {
+                sb.append("<resource path=\"" + path + "\" name=\"" + node.getName() + "\"/>");
+            }
+        } else {
+            String errorMessage = "node is null for path: " + path;
+            sb.append("<exception>" + errorMessage + "</exception>");
+            log.error(errorMessage);
+        }
+        return sb.toString();
+    }
+}



More information about the Yanel-commits mailing list