Commit 74dff134 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Refactored admin console framework.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@497 b35dd754-fafc-0310-a699-88a17e54d16e
parent 89c34392
......@@ -8,7 +8,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/i18n" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
......
......@@ -12,6 +12,7 @@
package org.jivesoftware.admin;
import org.jivesoftware.util.StringUtils;
import org.dom4j.Element;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;
......@@ -177,51 +178,51 @@ public class SidebarTag extends BodyTagSupport {
if (subPageID != null || pageID != null) {
if (pageID == null) {
pageID = AdminConsole.lookupPageID(subPageID);
Element subPage = AdminConsole.getElemnetByID(subPageID);
pageID = subPage.getParent().getParent().attributeValue("id");
}
// Top level menu items
if (AdminConsole.getItems().size() > 0) {
if (AdminConsole.getModel().elements().size() > 0) {
JspWriter out = pageContext.getOut();
StringBuffer buf = new StringBuffer();
AdminConsole.Item current = null;
AdminConsole.Item subcurrent = null;
Element current = null;
Element subcurrent = null;
if (subPageID != null) {
subcurrent = AdminConsole.getItem(subPageID);
// Lookup the pageID based on the subPageID:
pageID = AdminConsole.lookupPageID(subPageID);
subcurrent = AdminConsole.getElemnetByID(subPageID);
}
current = AdminConsole.getElemnetByID(pageID);
AdminConsole.Item root = AdminConsole.getRootByChildID(pageID);
current = AdminConsole.getItem(pageID);
Element currentTab = (Element)AdminConsole.getModel().selectSingleNode(
"//*[@id='" + pageID + "']/ancestor::tab");
boolean isSubmenu = false;
if (subPageID != null && current != null) {
isSubmenu = AdminConsole.isSubMenItem(subcurrent);
if (subcurrent != null) {
isSubmenu = subcurrent.getParent().getParent().getName().equals("item");
}
// Loop through all items in the root, print them out
if (root != null) {
Collection items = root.getItems();
if (currentTab != null) {
Collection items = currentTab.elements();
if (items.size() > 0) {
buf.append("<ul>");
for (Iterator iter=items.iterator(); iter.hasNext(); ) {
AdminConsole.Item item = (AdminConsole.Item)iter.next();
String header = item.getName();
Element sidebar = (Element)iter.next();
String header = sidebar.attributeValue("name");
// Print the header:
String hcss = getHeadercss();
if (hcss == null) {
hcss = "";
}
buf.append("<li class=\"").append(hcss).append("\">").append(clean(header)).append("</li>");
// Now print all subitems:
for (Iterator subitems=item.getItems().iterator(); subitems.hasNext(); ) {
AdminConsole.Item subitem = (AdminConsole.Item)subitems.next();
String subitemID = subitem.getId();
String subitemName = subitem.getName();
String subitemURL = subitem.getUrl();
String subitemDescr = subitem.getDescription();
// Now print all items:
for (Iterator subitems=sidebar.elementIterator(); subitems.hasNext(); ) {
Element item = (Element)subitems.next();
String subitemID = item.attributeValue("id");
String subitemName = item.attributeValue("name");
String subitemURL = item.attributeValue("url");
String subitemDescr = item.attributeValue("description");
String value = getBodyContent().getString();
if (value != null) {
value = StringUtils.replace(value, "[id]", clean(subitemID));
......@@ -230,7 +231,7 @@ public class SidebarTag extends BodyTagSupport {
value = StringUtils.replace(value, "[url]", clean(subitemURL));
}
String css = getCss();
boolean isCurrent = subitem.equals(current);
boolean isCurrent = item.equals(current);
boolean showSubmenu = subPageID != null;
if (isCurrent && !showSubmenu) {
css = getCurrentcss();
......@@ -239,24 +240,24 @@ public class SidebarTag extends BodyTagSupport {
// Print out a submenu if one exists:
if (isSubmenu && isCurrent) {
// Get the parent of the current item so we can get its items - those will be
// siblings of the current item:
Iterator siblings = subcurrent.getParent().getItems().iterator();
// Get the parent of the current item so we can get its
// items - those will be siblings of the current item:
Iterator siblings = subcurrent.getParent().elementIterator();
boolean hadNext = siblings.hasNext();
if (hadNext) {
// Print out beginning UL
buf.append("<ul class=\"subitems\">\n");
// Print the header LI
String subheader = subcurrent.getParent().getName();
String subheader = subcurrent.getParent().attributeValue("name");
buf.append("<li class=\"").append(hcss).append("\">").append(clean(subheader)).append("</li>");
}
String extraParams = pageInfo.getExtraParams();
while (siblings.hasNext()) {
AdminConsole.Item sibling = (AdminConsole.Item)siblings.next();
String sibID = sibling.getId();
String sibName = sibling.getName();
String sibDescr = sibling.getDescription();
String sibURL = sibling.getUrl();
Element sibling = (Element)siblings.next();
String sibID = sibling.attributeValue("id");
String sibName = sibling.attributeValue("name");
String sibDescr = sibling.attributeValue("description");
String sibURL = sibling.attributeValue("url");
if (extraParams != null) {
sibURL += ((sibURL.indexOf('?') > -1 ? "&" : "?") + extraParams);
}
......
......@@ -12,13 +12,13 @@
package org.jivesoftware.admin;
import org.jivesoftware.util.StringUtils;
import org.dom4j.Element;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.ServletRequest;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.io.IOException;
/**
......@@ -123,26 +123,32 @@ public class TabsTag extends BodyTagSupport {
if (pageInfo != null) {
pageID = pageInfo.getPageID();
}
// Get root items from the data model:
Collection<AdminConsole.Item> items = AdminConsole.getItems();
if (items.size() > 0) {
// Get tabs from the model:
List tabs = AdminConsole.getModel().selectNodes("//tab");
if (tabs.size() > 0) {
JspWriter out = pageContext.getOut();
// Build up the output in a buffer (is probably faster than a bunch of out.write's)
StringBuffer buf = new StringBuffer();
buf.append("<ul>");
String body = getBodyContent().getString();
// For each root item, print out an LI
AdminConsole.Item root = AdminConsole.getRootByChildID(pageID);
for (AdminConsole.Item item : items) {
// For each tab, print out an <LI>.
Element currentTab = null;
if (pageID != null) {
currentTab = (Element)AdminConsole.getModel().selectSingleNode(
"//*[@id='" + pageID + "']/ancestor::tab");
}
for (int i=0; i<tabs.size(); i++) {
Element tab = (Element)tabs.get(i);
String value = body;
if (value != null) {
value = StringUtils.replace(value, "[id]", clean(item.getId()));
value = StringUtils.replace(value, "[url]", clean(item.getUrl()));
value = StringUtils.replace(value, "[name]", clean(item.getName()));
value = StringUtils.replace(value, "[description]", clean(item.getDescription()));
// The URL for the tab should be the URL of the first item in the tab.
value = StringUtils.replace(value, "[id]", clean(tab.attributeValue("id")));
value = StringUtils.replace(value, "[url]", clean(tab.attributeValue("url")));
value = StringUtils.replace(value, "[name]", clean(tab.attributeValue("name")));
value = StringUtils.replace(value, "[description]", clean(tab.attributeValue("description")));
}
String css = getCss();
if (item.equals(root)) {
if (tab.equals(currentTab)) {
css = getCurrentcss();
}
buf.append("<li class=\"").append(css).append("\">");
......
......@@ -131,7 +131,7 @@ public class PluginManager {
Attribute attr = (Attribute)urls.get(i);
attr.setValue("/plugins/" + pluginDir.getName() + "/" + attr.getValue());
}
AdminConsole.addXMLSource(adminElement);
AdminConsole.addModel(adminElement);
}
}
else {
......
......@@ -5,9 +5,9 @@
<logo-image>images/header-title.gif</logo-image>
</global>
<tab id="server" name="Server" description="Click to manage server settings">
<tab id="tab-server" name="Server" url="index.jsp" description="Click to manage server settings">
<sidebar name="Server Manager">
<sidebar id="sidebar-server-manager" name="Server Manager">
<item id="server-settings" name="Server Settings"
url="index.jsp"
......@@ -26,7 +26,7 @@
description="Click to view server logs" />
</sidebar>
<sidebar name="Server Settings">
<sidebar id="sidebar-server-settings" name="Server Settings">
<item id="server-reg-and-login" name="Registration &amp; Login"
url="reg-settings.jsp"
......@@ -54,15 +54,15 @@
</sidebar>
</tab>
<tab id="users" name="Users" description="Click to manage users">
<tab id="tab-users" name="Users" url="user-summary.jsp" description="Click to manage users">
<sidebar name="Users">
<sidebar id="sidebar-users" name="Users">
<item id="user-summary" name="User Summary"
url="user-summary.jsp"
description="Click to see a list of users in the system">
<subsidebar name="User Options">
<sidebar id="sidebar-users-options" name="User Options">
<item id="user-properties" name="User Properties"
url="user-properties.jsp"
......@@ -75,7 +75,7 @@
<item id="user-delete" name="Delete User"
url="user-delete.jsp"
description="Click to delete the user" />
</subsidebar>
</sidebar>
</item>
<item id="user-create" name="Create New User"
......@@ -88,9 +88,9 @@
</sidebar>
</tab>
<tab id="session" name="Sessions" description="Click to manage connected sessions">
<tab id="tab-session" name="Sessions" url="session-summary.jsp" description="Click to manage connected sessions">
<sidebar name="Sessions">
<sidebar id="sidebar-session" name="Sessions">
<item id="session-summary" name="View Current Sessions"
url="session-summary.jsp"
......@@ -102,9 +102,9 @@
</sidebar>
</tab>
<tab id="groupchat" name="Group Chat" description="Click to manage group chat settings">
<tab id="tab-groupchat" name="Group Chat" url="muc-server-props-edit-form.jsp" description="Click to manage group chat settings">
<sidebar name="Group Chat Settings">
<sidebar id="sidebar-groupchat-settings" name="Group Chat Settings">
<item id="muc-server-props" name="Service Properties"
url="muc-server-props-edit-form.jsp"
......
......@@ -15,6 +15,7 @@ import java.util.Iterator;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.jivesoftware.admin.AdminConsole;
import org.dom4j.Element;
public class AdminConsoleTest extends TestCase {
......@@ -27,9 +28,9 @@ public class AdminConsoleTest extends TestCase {
*/
public void tearDown() throws Exception {
Class c = AdminConsole.class;
Method clear = c.getDeclaredMethod("clear", (Class[])null);
clear.setAccessible(true);
clear.invoke((Object)null, (Object[])null);
Method init = c.getDeclaredMethod("init", (Class[])null);
init.setAccessible(true);
init.invoke((Object)null, (Object[])null);
}
public void testGetGlobalProps() throws Exception {
......@@ -44,7 +45,7 @@ public class AdminConsoleTest extends TestCase {
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addXMLSource(in);
AdminConsole.addModel(in);
in.close();
String name = AdminConsole.getAppName();
assertEquals("Foo Bar", name);
......@@ -57,18 +58,18 @@ public class AdminConsoleTest extends TestCase {
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addXMLSource(in);
AdminConsole.addModel(in);
in.close();
Collection items = AdminConsole.getItems();
assertNotNull(items);
assertTrue(items.size() > 0);
Collection tabs = AdminConsole.getModel().selectNodes("//tab");
assertNotNull(tabs);
assertTrue(tabs.size() > 0);
boolean found = false;
for (Iterator iter=items.iterator(); iter.hasNext(); ) {
AdminConsole.Item item = (AdminConsole.Item)iter.next();
if ("foobar".equals(item.getId())) {
for (Iterator iter=tabs.iterator(); iter.hasNext(); ) {
Element tab = (Element)iter.next();
if ("foobar".equals(tab.attributeValue("id"))) {
found = true;
assertEquals("Foo Bar", item.getName());
assertEquals("Click to see foo bar", item.getDescription());
assertEquals("Foo Bar", tab.attributeValue("name"));
assertEquals("Click to see foo bar", tab.attributeValue("description"));
}
}
if (!found) {
......@@ -81,16 +82,15 @@ public class AdminConsoleTest extends TestCase {
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addXMLSource(in);
AdminConsole.addModel(in);
in.close();
Collection items = AdminConsole.getItems();
boolean found = false;
for (Iterator iter=items.iterator(); iter.hasNext(); ) {
AdminConsole.Item item = (AdminConsole.Item)iter.next();
if ("server".equals(item.getId())) {
for (Iterator tabs=AdminConsole.getModel().selectNodes("//tab").iterator(); tabs.hasNext(); ) {
Element tab = (Element)tabs.next();
if ("server".equals(tab.attributeValue("id"))) {
found = true;
assertEquals("New Server Title", item.getName());
assertEquals("Testing 1 2 3", item.getDescription());
assertEquals("New Server Title", tab.attributeValue("name"));
assertEquals("Testing 1 2 3", tab.attributeValue("description"));
}
}
if (!found) {
......
<?xml version="1.0"?>
<adminconsole>
<tab id="foobar" name="Foo Bar" description="Click to see foo bar" />
<tab id="foobar" name="Foo Bar" url="foobar.jsp" description="Click to see foo bar" />
</adminconsole>
\ No newline at end of file
......@@ -3,5 +3,5 @@
<!-- Insert a tab with the same ID to overwrite the tab -->
<adminconsole>
<tab id="server" name="New Server Title" description="Testing 1 2 3" />
<tab id="server" name="New Server Title" url="newurl.jsp" description="Testing 1 2 3" />
</adminconsole>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment