Author: chathura
Date: Sun Dec  9 21:24:40 2007
New Revision: 10754

Log:


Added resource content download functionality.

Fixed some UI issues.



Added:
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandlerAction.java
Modified:
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   Sun Dec  9 21:24:40 2007
@@ -392,8 +392,25 @@
             // if user is browsing an old version of the resource, we append 
it to the path, so that
             // the backend registry gives the details of the version
             String qPart = request.getQueryString();
-            if (qPart != null && qPart.startsWith("v")) {
-                path = path + "?" + qPart;
+            if (qPart != null) {
+                if (qPart.startsWith("v")) {
+
+                    path = path + "?" + qPart;
+
+                    // check if URL is for the resource content (i.e. 
/mycollection/myreosurce?v2&content
+
+                    String[] q = qPart.split("&");
+                    if (q.length == 2) {
+                        if (q[1].equals("content")) {
+                            sendResourceContent(request, response, path);
+                            return;
+                        }
+                    }
+
+                } else if (qPart.equals("content")) {
+                    sendResourceContent(request, response, path);
+                    return;
+                }
             }
 
             // whenever a user selects a URL for a resource path, we set that 
path in the user's
@@ -548,6 +565,37 @@
         }
     }
 
+    private void sendResourceContent(HttpServletRequest request, 
HttpServletResponse response, String path) {
+
+        ResourceHandlerAction handlerAction = new ResourceHandlerAction();
+
+        Resource resource = null;
+        try {
+            resource = handlerAction.getResource(request, path);
+        } catch (RegistryException e) {
+            setErrorMessage(request, e.getMessage());
+            e.printStackTrace();
+        }
+
+        try {
+            Object content = resource.getContent();
+            if (content != null) {
+                if (content instanceof byte[]) {
+                    //response.setContentType(resource.getMediaType());
+                    response.getOutputStream().write((byte[])content);
+                    response.flushBuffer();
+                } else {
+                    //response.setContentType(resource.getMediaType());
+                    response.getWriter().write(content.toString());
+                }
+            }
+
+            response.getWriter().flush();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
     /**
      * To find the name of the war , so getting that from the request context 
path
      *

Added: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandlerAction.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandlerAction.java
       Sun Dec  9 21:24:40 2007
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.wso2.registry.web.actions;
+
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * This class and all other action classes have to be replaced with proper 
utility classes and
+ * simple beans.
+ */
+public class ResourceHandlerAction extends AbstractRegistryAction {
+
+    public Resource getResource(HttpServletRequest request, String path)
+            throws RegistryException {
+
+        setRequest(request);
+
+        Resource resource = getRegistry().get(path);
+
+        return resource;
+    }
+}

Modified: 
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
Sun Dec  9 21:24:40 2007
@@ -42,7 +42,7 @@
 <% } %>
 <div class="breadcrumb">
     <%
-        Iterator iNavPaths = collection.getNavigatablePaths().iterator();
+        Iterator iNavPaths = details.getNavigatablePaths().iterator();
         while (iNavPaths.hasNext()) {
             ResourcePath resourcePath = (ResourcePath) iNavPaths.next();
     %>
@@ -55,7 +55,11 @@
 
 <!-- Display the details of main node -->
 <div class="resource-head">
-    <a href="/wso2registry/web<%=details.getPath()%>" class="folder-small 
headding1"><%=details.getName()%></a>
+    <% if (details.isCollection()) { %>
+    <div class="folder-small headding1"><%=details.getName()%></div>
+    <% } else { %>
+    <div class="resource-small headding1"><%=details.getName()%></div>
+    <% } %>
     
     <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
         <tr>
@@ -183,7 +187,7 @@
             ResourceData resourceData = (ResourceData) iterator.next();
     %>
     <tr id="1">
-        <td><a href="/wso2registry/web/<%=resourceData.getRelativePath()%>" 
class="folder-small"><%=resourceData.getName()%></a></td>
+        <td><% if (resourceData.getResourceType() == ResourceData.COLLECTION) 
{ %><a href="/wso2registry/web/<%=resourceData.getRelativePath()%>" 
class="folder-small"><%=resourceData.getName()%></a><% } else { %><a 
href="/wso2registry/web/<%=resourceData.getRelativePath()%>" 
class="resource-small"><%=resourceData.getName()%></a><% } %></td>
         <td><%=resourceData.getCreatedOn()%></td>
         <td><%=resourceData.getAuthorUserName()%></td>
         <td>
@@ -213,7 +217,14 @@
 
 </table>
 
+<% } else { %>
+
+<br/>
+<a href="/wso2registry/web<%=details.getPath()%>?content">Download</a>
+<br/>
+
 <% } %>
+
 <!-- Listing Comments -->
 
 <h2>Comments</h2>

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to