Author: chathura
Date: Wed Dec 19 01:24:55 2007
New Revision: 11517
Log:
Implemented redirect from resource context to web context for browsing
collections.
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/ResourcesUtil.java
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/UIConstants.java
trunk/registry/modules/webapps/src/main/webapp/admin/error.jsp
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
Wed Dec 19 01:24:55 2007
@@ -27,6 +27,7 @@
import org.wso2.registry.web.beans.AdminBean;
import org.wso2.registry.web.utils.AdminUtil;
import org.wso2.registry.web.utils.TagUtil;
+import org.wso2.registry.web.utils.ResourcesUtil;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -420,22 +421,22 @@
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")) {
- // 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;
}
}
@@ -459,10 +460,29 @@
// the backend registry gives the details of the version
String qPart = request.getQueryString();
if (qPart != null && qPart.startsWith("v")) {
- path = path + "?" + qPart;
+ path = path + "?" + qPart;
}
- sendResourceContent(request, response, path);
+ Resource resource = null;
+ try {
+ resource = ResourcesUtil.getResource(request, path);
+ } catch (RegistryException e) {
+ request.getSession().setAttribute(UIConstants.ERROR_MESSAGE,
e.getMessage());
+ request.getRequestDispatcher(UIConstants.ERROR_JSP);
+ return;
+ }
+
+ if (resource == null) {
+ request.getSession().setAttribute(UIConstants.ERROR_MESSAGE,
"404 Not Found");
+ request.getRequestDispatcher(UIConstants.ERROR_JSP);
+ return;
+ }
+
+ if (resource.isDirectory()) {
+ response.sendRedirect("/wso2registry/web" + path);
+ } else {
+ sendResourceContent(request, response, path);
+ }
} else if (controlPart.startsWith(RegistryConstants.PATH_SEPARATOR +
UIConstants.SYSTEM_PATH)) {
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 01:24:55 2007
@@ -18,8 +18,6 @@
public class UIConstants {
- public static final String ERROR_MESSAGE = "regErrorMessage";
-
public static final String RESOURCE_BEAN = "resource";
public static final String COLLECTION_BEAN = "collection";
public static final String USER_MANAGEMENT_BEAN = "user_management";
@@ -38,6 +36,9 @@
public static final String USER_ATTR = "currentUser";
public static final String QUERY_ATTR = "regQuery";
+ public static final String ERROR_CODE = "error.code";
+ public static final String ERROR_MESSAGE = "error.message";
+
public static final String RESOURCES_JSP = "/admin/registry-resources.jsp";
public static final String USER_MANAGEMENT_JSP = "/admin/people.jsp";
public static final String ACTIVITY_JSP = "/admin/recent-activity.jsp";
@@ -48,4 +49,5 @@
public static final String AJAX_RATING_JSP = "/admin/ajax_rating.jsp";
public static final String AJAX_DESCRIPTION_JSP = "/admin/ajax_desc.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
+ public static final String ERROR_JSP = "/admin/error.jsp";
}
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/ResourcesUtil.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/ResourcesUtil.java
Wed Dec 19 01:24:55 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.utils;
+
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class ResourcesUtil {
+
+ public static Resource getResource(HttpServletRequest request, String path)
+ throws RegistryException {
+
+ SecureRegistry secureRegistry = CommonUtil.getUserRegistry(request);
+ if (secureRegistry.resourceExists(path)) {
+ return secureRegistry.get(path);
+ } else {
+ return null;
+ }
+ }
+}
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/error.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/error.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/error.jsp Wed Dec
19 01:24:55 2007
@@ -1,3 +1,4 @@
+<%@ page import="org.wso2.registry.web.UIConstants" %>
<html>
<head>
<title>WSO2 Registry</title>
@@ -10,27 +11,21 @@
<%
String msg = "Unknown error";
- Object o = request.getSession().getAttribute("error_message");
+ Object o = request.getSession().getAttribute(UIConstants.ERROR_MESSAGE);
+ String errorCode = (String)
request.getSession().getAttribute(UIConstants.ERROR_CODE);
if (o != null) {
msg = (String) o;
}
%>
+
+<% if (errorCode != null) { %>
+<h2><%=errorCode%></h2>
+<% } %>
+
<br/>
<font color="red"><%=msg%></font>
<br/>
-<div class="detail-section">
- <ul>
- <li><a href="/wso2registry/edit" title="Edit Registry">Edit</a></li>
- </ul>
- <ul>
- <li><a href="/wso2registry/view" title="View Registry">View</a></li>
- </ul>
-</div>
-
-<br/>
-<hr/>
-<address> Powered by WSO2 Registry</address>
</body>
</html>
\ No newline at end of file
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
Wed Dec 19 01:24:55 2007
@@ -332,7 +332,7 @@
<% } else { %>
<br/>
-<a href="/wso2registry/web<%=details.getContentPath()%>">Download</a>
+<a href="/wso2registry/resources<%=details.getContentPath()%>"
target="_blank">Download</a>
<br/>
<% } %>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev