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