Author: chathura
Date: Wed Dec 19 00:55:22 2007
New Revision: 11508

Log:


Implemented support for retrieving resource content from the URL 
***/resources/<path>



Modified:
   trunk/registry/modules/webapps/conf/web.xml
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java

Modified: trunk/registry/modules/webapps/conf/web.xml
==============================================================================
--- trunk/registry/modules/webapps/conf/web.xml (original)
+++ trunk/registry/modules/webapps/conf/web.xml Wed Dec 19 00:55:22 2007
@@ -39,6 +39,10 @@
         <servlet-name>WebServlet</servlet-name>
         <url-pattern>/system/*</url-pattern>
     </servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>WebServlet</servlet-name>
+        <url-pattern>/resources/*</url-pattern>
+    </servlet-mapping>
 
     <welcome-file-list>
       <welcome-file>admin/index.jsp</welcome-file>

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
   Wed Dec 19 00:55:22 2007
@@ -418,22 +418,24 @@
             if (qPart != null) {
                 if (qPart.startsWith("v")) {
 
-                    // check if URL is for the resource content (i.e. 
/mycollection/myreosurce?v2&content
+                    path = path + "?" + qPart;
 
-                    String[] q = qPart.split("&");
-                    if (q.length == 2) {
-                        if (q[1].equals("content")) {
-                            path = path + "?" + q[0];
-                            sendResourceContent(request, response, path);
-                            return;
-                        }
-                    } else {
-                        path = path + "?" + qPart;
-                    }
-
-                } else if (qPart.equals("content")) {
-                    sendResourceContent(request, response, path);
-                    return;
+                //    // 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")) {
+                //            path = path + "?" + q[0];
+                //            sendResourceContent(request, response, path);
+                //            return;
+                //        }
+                //    } else {
+                //        path = path + "?" + qPart;
+                //    }
+                //
+                //} else if (qPart.equals("content")) {
+                //    sendResourceContent(request, response, path);
+                //    return;
                 }
             }
 
@@ -443,8 +445,26 @@
 
             forwardToResources(request, response, path);
 
-        } else
-        if (controlPart.startsWith(RegistryConstants.PATH_SEPARATOR + 
UIConstants.SYSTEM_PATH)) {
+        } else if (controlPart.startsWith(RegistryConstants.PATH_SEPARATOR + 
UIConstants.RESOURCES_PATH)) {
+
+            if (uri.equals("") || uri.endsWith(UIConstants.RESOURCES_PATH + 
RegistryConstants.PATH_SEPARATOR)) {
+                path = RegistryConstants.ROOT_PATH;
+
+            } else {
+                path = uri.substring((contextRoot + 
RegistryConstants.PATH_SEPARATOR + UIConstants.RESOURCES_PATH).
+                        length(), uri.length());
+            }
+
+            // 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;
+            }
+
+            sendResourceContent(request, response, path);
+
+        } else if (controlPart.startsWith(RegistryConstants.PATH_SEPARATOR + 
UIConstants.SYSTEM_PATH)) {
 
             // process system requests
 
@@ -662,12 +682,17 @@
         try {
             Object content = resource.getContent();
             if (content != null) {
-                if (content instanceof byte[]) {
+
+                if (resource.getMediaType() != null && 
resource.getMediaType().length() > 0) {
+                    response.setContentType(resource.getMediaType());
+                } else {
                     response.setContentType("application/download");
+                }
+
+                if (content instanceof byte[]) {
                     response.getOutputStream().write((byte[]) content);
                     response.flushBuffer();
                 } else {
-                    response.setContentType("application/download");
                     response.getWriter().write(content.toString());
                 }
             }

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
 (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
 Wed Dec 19 00:55:22 2007
@@ -31,6 +31,7 @@
     public static final String AJAX_RATING_BEAN = "ajaxRating";
     public static final String AJAX_DESCRIPTION_STRING = "ajaxDesc";
 
+    public static final String RESOURCES_PATH = "resources";
     public static final String WEB_PATH = "web";
     public static final String SYSTEM_PATH = "system";
     public static final String PATH_ATTR = "path";

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
       (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
       Wed Dec 19 00:55:22 2007
@@ -138,12 +138,13 @@
             }
         }
 
-        String[] qParts = path.split("\\?");
-        if (qParts.length > 1) {
-            contentPath = path + "&content";
-        } else {
-            contentPath = path + "?content";
-        }
+        contentPath = path;
+        //String[] qParts = path.split("\\?");
+        //if (qParts.length > 1) {
+        //    contentPath = path + "&content";
+        //} else {
+        //    contentPath = path + "?content";
+        //}
 
         Resource resource = registry.get(path);
 

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

Reply via email to