You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ge...@apache.org on 2011/07/19 07:54:08 UTC
svn commit: r1148184 - in
/geronimo/server/trunk/plugins/console/console-portal-driver/src:
main/java/org/apache/geronimo/console/navigation/ main/webapp/WEB-INF/
main/webapp/WEB-INF/themes/ test/java/org/apache/geronimo/console/navigation/
Author: genspring
Date: Tue Jul 19 05:54:07 2011
New Revision: 1148184
URL: http://svn.apache.org/viewvc?rev=1148184&view=rev
Log:
GERONIMO-6078 Navigation tree displays wrong links for different roles, patch from Shenghao Fang
Modified:
geronimo/server/trunk/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/navigation/NavigationJsonGenerator.java
geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml
geronimo/server/trunk/plugins/console/console-portal-driver/src/test/java/org/apache/geronimo/console/navigation/NavigationJsonGeneratorTest.java
Modified: geronimo/server/trunk/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/navigation/NavigationJsonGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/navigation/NavigationJsonGenerator.java?rev=1148184&r1=1148183&r2=1148184&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/navigation/NavigationJsonGenerator.java (original)
+++ geronimo/server/trunk/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/navigation/NavigationJsonGenerator.java Tue Jul 19 05:54:07 2011
@@ -52,37 +52,34 @@ import org.slf4j.LoggerFactory;
*/
public class NavigationJsonGenerator {
-
- private static Map<String, Map<String, TreeNode>> navigationTrees=new HashMap<String, Map<String, TreeNode>>();
-
+
+ // private static Map<String, Map<String, TreeNode>> navigationTrees = new HashMap<String, Map<String, TreeNode>>();
+
public static final String ALL = "all";
-
- private final static List<String> monitorRolePermitPages = Arrays.asList(
- "0/Welcome",
- "1-1-1/Application Server/System Information/Server Information",
- "1-1-2/Application Server/System Information/Java System Info",
- "1-1-4/Application Server/System Information/Thread Pools",
- "1-8/Server/Monitoring"
- );
-
-
- private static Map<String, List<String>> rolePagesMap=new HashMap<String, List<String>>();
-
+
+ private final static List<String> monitorRolePermitPages = Arrays
+ .asList("0/Welcome", "1-1-1/Application Server/System Information/Server Information",
+ "1-1-2/Application Server/System Information/Java System Info",
+ "1-1-4/Application Server/System Information/Thread Pools",
+ "5-1/Monitoring and Troubleshooting/Monitoring");
+
+ private static Map<String, List<String>> rolePagesMap = new HashMap<String, List<String>>();
+
static {
-
+
rolePagesMap.put("monitor", monitorRolePermitPages);
-
+
}
-
- public static List<PageConfig> filterPagesByRole(List<PageConfig> pageConfigList, HttpServletRequest request){
-
- List<String> permitPages=null;
-
- if(request.isUserInRole("monitor")){
-
- permitPages=rolePagesMap.get("monitor");
+
+ public static List<PageConfig> filterPagesByRole(List<PageConfig> pageConfigList, HttpServletRequest request) {
+
+ List<String> permitPages = null;
+
+ if (request.isUserInRole("monitor")) {
+
+ permitPages = rolePagesMap.get("monitor");
}
-
+
if (permitPages == null) {
return pageConfigList;
}
@@ -96,129 +93,105 @@ public class NavigationJsonGenerator {
filteredPageConfigList.add(pc);
}
}
-
+
return filteredPageConfigList;
-
+
};
-
-
+
private ResourceBundle navigationResourcebundle;
-
+
private static final Logger log = LoggerFactory.getLogger(NavigationJsonGenerator.class);
-
+
public NavigationJsonGenerator(Locale locale) {
if (locale == null) {
navigationResourcebundle = ResourceBundle.getBundle("org.apache.geronimo.console.i18n.ConsoleResource");
} else {
- navigationResourcebundle = ResourceBundle.getBundle("org.apache.geronimo.console.i18n.ConsoleResource",locale);
+ navigationResourcebundle = ResourceBundle.getBundle("org.apache.geronimo.console.i18n.ConsoleResource",
+ locale);
}
}
-
-
- private Map<String, TreeNode> getNavigationTree(List<PageConfig> pageConfigList, String mode){
-
- Map<String, TreeNode> navigationTree;
-
- if (navigationTrees.get(mode) != null) {
- navigationTree = navigationTrees.get(mode);
- } else {
- navigationTree = new TreeMap<String, TreeNode>();
+ public Map<String, TreeNode> getNavigationTree(List<PageConfig> pageConfigList, String mode) {
+ Map<String, TreeNode> navigationTree = new TreeMap<String, TreeNode>();
- for (PageConfig pc : pageConfigList) {
- if (mode.equals(ALL) || (pc.getMode() != null && mode.equals(pc.getMode()))) {
- try {
- new TreeNode(pc).populateTree(navigationTree);
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- continue;
- }
+ for (PageConfig pc : pageConfigList) {
+ if (mode.equals(ALL) || (pc.getMode() != null && mode.equals(pc.getMode()))) {
+ try {
+ new TreeNode(pc).populateTree(navigationTree);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
}
}
-
- navigationTrees.put(mode, navigationTree);
-
}
return navigationTree;
}
-
-
- public String generateTreeJSON(List<PageConfig> pageConfigList, String contextPath, String DefaultIcon, String mode, int threshold) {
-
- Map<String, TreeNode> navigationTree=this.getNavigationTree(pageConfigList, mode);
-
-
- boolean isTreeAList=this.isTreeAList(pageConfigList, mode, threshold);
-
-
+
+ public String generateTreeJSON(Map<String, TreeNode> navigationTree, String contextPath, String DefaultIcon,
+ String mode, int threshold) {
+
+ // Map<String, TreeNode> navigationTree = this.getNavigationTree(pageConfigList, mode);
+
+ boolean isTreeAList = this.isTreeAList(navigationTree, mode, threshold);
+
StringBuilder sb = new StringBuilder(10);
sb.append("[");
-
-
- if(!isTreeAList){
-
-
- boolean hasTopNode=false;
+
+ if (!isTreeAList) {
+
+ boolean hasTopNode = false;
for (TreeNode node : navigationTree.values()) {
// when menu items number is less than 6, let's only display the basic menu to the user.
// because the user won't need a t to organize the.
- if (node.isTopNode()) {
- sb.append("\n");
- appendNodeToTreeJSON(sb, node, contextPath, DefaultIcon);
- hasTopNode=true;
- }
-
+ if (node.isTopNode()) {
+ sb.append("\n");
+ appendNodeToTreeJSON(sb, node, contextPath, DefaultIcon);
+ hasTopNode = true;
+ }
}
-
- //remove the extra ','
- if(hasTopNode){
- sb.deleteCharAt(sb.length()-1);
+
+ // remove the extra ','
+ if (hasTopNode) {
+ sb.deleteCharAt(sb.length() - 1);
}
sb.append("\n]");
-
+
} else {
-
- boolean hasLeafNode=false;
+
+ boolean hasLeafNode = false;
for (TreeNode node : navigationTree.values()) {
if (node.isLeafNode()) {
-
+
sb.append("\n");
-
+
appendBasicListJSON(sb, node, contextPath, DefaultIcon);
-
- hasLeafNode=true;
- }
- }
- //remove the extra ','
- if(hasLeafNode){
- sb.deleteCharAt(sb.length()-1);
+
+ hasLeafNode = true;
+ }
+ }
+ // remove the extra ','
+ if (hasLeafNode) {
+ sb.deleteCharAt(sb.length() - 1);
}
-
+
sb.append("\n]");
-
+
}
-
-
-
return sb.toString();
}
-
-
+
private void appendNodeToTreeJSON(StringBuilder sb, TreeNode node, String contextPath, String DefaultIcon) {
sb.append("{");
-
-
if (!node.isLeafNode()) {
- sb.append("label: \'"+getLocalizedString(node.getLabel()) + "\'");
+ sb.append("label: \'" + getLocalizedString(node.getLabel()) + "\'");
} else {
sb.append("label: \'<img src=\"" + contextPath + node.getIcon() + "\" alt=\"\" border=\"0\"> ");
sb.append("<a href=\"" + contextPath + "/portal/" + node.getId() + "/" + node.getPath() + "\">"
@@ -235,24 +208,21 @@ public class NavigationJsonGenerator {
for (TreeNode child : node.getChildren().values()) {
appendNodeToTreeJSON(sb, child, contextPath, DefaultIcon);
}
-
- //remove the extra ','
- sb.deleteCharAt(sb.length()-1);
-
+
+ // remove the extra ','
+ sb.deleteCharAt(sb.length() - 1);
+
sb.append("]\n");
}
sb.append("},");
}
-
-
+
private void appendBasicListJSON(StringBuilder sb, TreeNode node, String contextPath, String DefaultIcon) {
sb.append("{");
-
-
if (node.isLeafNode()) {
sb.append("label: \'<img src=\"" + contextPath + node.getIcon() + "\" alt=\"\" border=\"0\"> ");
sb.append("<a href=\"" + contextPath + "/portal/" + node.getId() + "/" + node.getPath() + "\">"
@@ -265,17 +235,15 @@ public class NavigationJsonGenerator {
sb.append("},");
}
-
-
- public String generateQuickLauncherJSON(List<PageConfig> pageConfigList, String contextPath, String DefaultIcon, String mode) {
-
-
- Map<String, TreeNode> navigationTree=this.getNavigationTree(pageConfigList, mode);
+ public String generateQuickLauncherJSON(Map<String, TreeNode> navigationTree, String contextPath,
+ String DefaultIcon, String mode) {
+
+ // Map<String, TreeNode> navigationTree = this.getNavigationTree(pageConfigList, mode);
StringBuilder sb = new StringBuilder(10);
sb.append("[\n");
-
+
for (TreeNode node : navigationTree.values()) {
if (node.isTopNode()) {
@@ -283,47 +251,43 @@ public class NavigationJsonGenerator {
}
}
- //remove the extra ','
- sb.deleteCharAt(sb.length()-1);
+ // remove the extra ','
+ sb.deleteCharAt(sb.length() - 1);
sb.append("\n]");
return sb.toString();
}
-
-
+
private void appendNodeToQuickLauncherJSON(StringBuilder sb, TreeNode node, String contextPath, String DefaultIcon) {
if (node.isLeafNode()) {
sb.append("\n{");
sb.append("label: \'<img src=\"").append(contextPath).append(node.getIcon()).append("\"> ");
sb.append("<span>").append(getLocalizedString(node.getLabel())).append("</span>\'");
- sb.append(",");
+ sb.append(",");
sb.append("name: \'").append(getLocalizedString(node.getLabel())).append("\'");
sb.append(",");
sb.append("href:\'").append(contextPath + "/portal/" + node.getId() + "/" + node.getPath() + "\'");
sb.append("},");
}
-
+
if (node.getChildren() != null) {
for (TreeNode child : node.getChildren().values()) {
appendNodeToQuickLauncherJSON(sb, child, contextPath, DefaultIcon);
}
-
- //remove the extra ','
- //sb.deleteCharAt(sb.length()-1);
- }
-
+ // remove the extra ','
+ // sb.deleteCharAt(sb.length()-1);
+ }
}
-
-
+
private String getLocalizedString(String key) {
try {
-
+
return navigationResourcebundle.getString(key);
} catch (Exception e) {
@@ -336,40 +300,37 @@ public class NavigationJsonGenerator {
return key;
}
-
- public boolean isTreeHasValidItem(List<PageConfig> pageConfigList, String mode){
-
- Map<String, TreeNode> navigationTree=this.getNavigationTree(pageConfigList, mode);
-
-
- for (TreeNode node:navigationTree.values()){
-
- if(node.isLeafNode()){
+
+ public boolean isTreeHasValidItem(Map<String, TreeNode> navigationTree, String mode) {
+
+ // Map<String, TreeNode> navigationTree = this.getNavigationTree(pageConfigList, mode);
+
+ for (TreeNode node : navigationTree.values()) {
+
+ if (node.isLeafNode()) {
return true;
}
-
+
}
-
+
return false;
}
-
-
- private boolean isTreeAList(List<PageConfig> pageConfigList, String mode, int threshold ){
-
- Map<String, TreeNode> navigationTree=this.getNavigationTree(pageConfigList, mode);
-
-
- int leafNodeCount=0;
-
- for (TreeNode node:navigationTree.values()){
-
- if(node.isLeafNode()){
- leafNodeCount=leafNodeCount+1;
+
+ private boolean isTreeAList(Map<String, TreeNode> navigationTree, String mode, int threshold) {
+
+ // Map<String, TreeNode> navigationTree = this.getNavigationTree(pageConfigList, mode);
+
+ int leafNodeCount = 0;
+
+ for (TreeNode node : navigationTree.values()) {
+
+ if (node.isLeafNode()) {
+ leafNodeCount = leafNodeCount + 1;
}
-
+
}
-
- return leafNodeCount< threshold;
+
+ return leafNodeCount < threshold;
}
}
Modified: geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp?rev=1148184&r1=1148183&r2=1148184&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp (original)
+++ geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp Tue Jul 19 05:54:07 2011
@@ -23,8 +23,9 @@ limitations under the License.
<fmt:setBundle basename="org.apache.geronimo.console.i18n.ConsoleResource"/>
<%response.setContentType("text/html; charset=UTF-8");%>
-<%@ page import="java.util.List,java.util.ArrayList,java.util.HashMap,
+<%@ page import="java.util.List,java.util.ArrayList,java.util.Map,
org.apache.geronimo.pluto.impl.PageConfig,
+ org.apache.geronimo.console.navigation.TreeNode,
org.apache.geronimo.console.navigation.NavigationJsonGenerator"%>
<%
@@ -41,16 +42,16 @@ limitations under the License.
<%
List<PageConfig> filteredPageConfigList = NavigationJsonGenerator.filterPagesByRole(pageConfigList,request);
-
-
NavigationJsonGenerator generator = new NavigationJsonGenerator(request.getLocale());
-
- String treeJson = generator.generateTreeJSON(filteredPageConfigList, request.getContextPath(), "/images/ico_doc_16x16.gif", "all", 8);
- String treeJsonBasic = generator.generateTreeJSON(filteredPageConfigList, request.getContextPath(), "/images/ico_doc_16x16.gif","basic", 8);
- String listJson = generator.generateQuickLauncherJSON(filteredPageConfigList, request.getContextPath(), "/images/ico_doc_16x16.gif", "all");
- String listJsonBasic = generator.generateQuickLauncherJSON(filteredPageConfigList, request.getContextPath(), "/images/ico_doc_16x16.gif","basic");
- boolean isBasicTreeHasValidItem=generator.isTreeHasValidItem(filteredPageConfigList,"basic");
+ Map<String, TreeNode> treeBasic = generator.getNavigationTree(filteredPageConfigList, "basic");
+ String treeJsonBasic = generator.generateTreeJSON(treeBasic, request.getContextPath(), "/images/ico_doc_16x16.gif", "basic", 8);
+ String listJsonBasic = generator.generateQuickLauncherJSON(treeBasic, request.getContextPath(), "/images/ico_doc_16x16.gif", "basic");
+ boolean isBasicTreeHasValidItem=generator.isTreeHasValidItem(treeBasic, "basic");
+
+ Map<String, TreeNode> treeAll = generator.getNavigationTree(filteredPageConfigList, "all");
+ String treeJson = generator.generateTreeJSON(treeAll, request.getContextPath(), "/images/ico_doc_16x16.gif", "all", 8);
+ String listJson = generator.generateQuickLauncherJSON(treeAll, request.getContextPath(), "/images/ico_doc_16x16.gif", "all");
%>
Modified: geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml?rev=1148184&r1=1148183&r2=1148184&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml (original)
+++ geronimo/server/trunk/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml Tue Jul 19 05:54:07 2011
@@ -309,8 +309,8 @@ limitations under the License.
<url-pattern>/portal/1-1-2/Application Server/System Information/Java System Info/*</url-pattern>
<url-pattern>/portal/1-1-4/Application Server/System Information/Thread Pools</url-pattern>
<url-pattern>/portal/1-1-4/Application Server/System Information/Thread Pools/*</url-pattern>
- <url-pattern>/portal/1-8/Server/Monitoring</url-pattern>
- <url-pattern>/portal/1-8/Server/Monitoring/*</url-pattern>
+ <url-pattern>/portal/5-1/Monitoring and Troubleshooting/Monitoring</url-pattern>
+ <url-pattern>/portal/5-1/Monitoring and Troubleshooting/Monitoring/*</url-pattern>
<url-pattern>/forwards/*</url-pattern>
<url-pattern>/dwr/*</url-pattern>
<http-method>GET</http-method>
Modified: geronimo/server/trunk/plugins/console/console-portal-driver/src/test/java/org/apache/geronimo/console/navigation/NavigationJsonGeneratorTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/console/console-portal-driver/src/test/java/org/apache/geronimo/console/navigation/NavigationJsonGeneratorTest.java?rev=1148184&r1=1148183&r2=1148184&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/console/console-portal-driver/src/test/java/org/apache/geronimo/console/navigation/NavigationJsonGeneratorTest.java (original)
+++ geronimo/server/trunk/plugins/console/console-portal-driver/src/test/java/org/apache/geronimo/console/navigation/NavigationJsonGeneratorTest.java Tue Jul 19 05:54:07 2011
@@ -18,6 +18,7 @@ package org.apache.geronimo.console.navi
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -69,15 +70,21 @@ public class NavigationJsonGeneratorTest
public void testGenerateTreeJSON() {
System.out.println("testGenerateTreeJSON() ------ ");
- String json = navigationJsonGenerator.generateTreeJSON(pageList, "console", "/images/ico_deploy_16x16.gif",
- "all", 3);
+
+ Map<String, TreeNode> navigationTree = null;
+
+ navigationTree = navigationJsonGenerator.getNavigationTree(pageList, "all");
+ String json = navigationJsonGenerator.generateTreeJSON(navigationTree, "console",
+ "/images/ico_deploy_16x16.gif", "all", 3);
String expected = "[\n{label: \'cat1\',id: \'1\',children: [{label: \'cat1-1\',id: \'1-1\',children: [{label: \'cat1-1-1\',id: \'1-1-1\',children: [{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/1-1-1-1/cat1/cat1-1/cat1-1-1/item1-1-1-1\">item1-1-1-1</a>\',id: \'1-1-1-1\'}]\n}]\n},{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/1-2/cat1/item1-2\">item1-2</a>\',id: \'1-2\'}]\n},\n{label: \'cat2\',id: \'2\',children: [{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/2-2/cat2/item2-2\">item2-2</a>\',id: \'2-2\'}]\n}\n]";
System.out.println(json);
Assert.assertEquals(expected, json);
- json = navigationJsonGenerator.generateTreeJSON(pageList, "console", "/images/ico_deploy_16x16.gif", "all", 5);
+ navigationTree = navigationJsonGenerator.getNavigationTree(pageList, "all");
+ json = navigationJsonGenerator.generateTreeJSON(navigationTree, "console", "/images/ico_deploy_16x16.gif",
+ "all", 5);
expected = "[\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/1-1-1-1/cat1/cat1-1/cat1-1-1/item1-1-1-1\">item1-1-1-1</a>\',id: \'1-1-1-1\'},\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/1-2/cat1/item1-2\">item1-2</a>\',id: \'1-2\'},\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/2-2/cat2/item2-2\">item2-2</a>\',id: \'2-2\'},\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\" alt=\"\" border=\"0\"> <a href=\"console/portal/2-2-1/cat2/cat2-1/item2-2-1\">item2-2-1</a>\',id: \'2-2-1\'}\n]";
System.out.println(json);
@@ -87,7 +94,9 @@ public class NavigationJsonGeneratorTest
public void testGenerateQuickLauncherJSON() {
System.out.println("testGenerateQuickLauncherJSON() ------ ");
- String json = navigationJsonGenerator.generateQuickLauncherJSON(pageList, "console",
+
+ Map<String, TreeNode> navigationTree = navigationJsonGenerator.getNavigationTree(pageList, "all");
+ String json = navigationJsonGenerator.generateQuickLauncherJSON(navigationTree, "console",
"/images/ico_deploy_16x16.gif", "all");
String expected = "[\n\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\"> <span>item1-1-1-1</span>\',name: \'item1-1-1-1\',href:\'console/portal/1-1-1-1/cat1/cat1-1/cat1-1-1/item1-1-1-1'},\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\"> <span>item1-2</span>\',name: \'item1-2\',href:\'console/portal/1-2/cat1/item1-2\'},\n{label: \'<img src=\"console/images/ico_deploy_16x16.gif\"> <span>item2-2</span>\',name: \'item2-2\',href:\'console/portal/2-2/cat2/item2-2\'}\n]";