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" />
......
......@@ -15,6 +15,7 @@ import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.Log;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.DocumentFactory;
import org.dom4j.io.SAXReader;
import java.util.*;
......@@ -22,32 +23,27 @@ import java.io.InputStream;
import java.net.URL;
/**
* <p>A model for admin tab and sidebar info. This class loads in xml definitions of the data and
* produces an in-memory model. There is an internal class, {@link Item} which is the main part
* of the model. Items hold info like name, id, url and description as well as an arbritrary number
* of sub items. Based on this we can make a tree model of the data.</p>
* A model for admin tab and sidebar info. This class loads in xml definitions of the data and
* produces an in-memory model.<p>
*
* <p>This class loads its data from the <tt>admin-sidebar.xml</tt> file which is assumed to be in
* This class loads its data from the <tt>admin-sidebar.xml</tt> file which is assumed to be in
* the main application jar file. In addition, it will load files from
* <tt>META-INF/admin-sidebar.xml</tt> if they're found. This allows developers to extend the
* functionality of the admin console to provide more options. See the main
* <tt>admin-sidebar.xml</tt> file for documentation of its format.</p>
*
* <p>Note: IDs in the XML file must be unique because an internal mapping is kept of IDs to
* nodes.</p>
* <tt>admin-sidebar.xml</tt> file for documentation of its format.<p>
*/
public class AdminConsole {
private static Map<String,Item> items;
private static String appName;
private static String logoImage;
private static Element coreModel;
private static List<Element> overrideModels;
private static Element generatedModel;
static {
init();
}
private static void init() {
items = Collections.synchronizedMap(new LinkedHashMap<String,Item>());
overrideModels = new ArrayList<Element>();
load();
}
......@@ -61,10 +57,10 @@ public class AdminConsole {
* @param in the XML input stream.
* @throws Exception if an error occurs when parsing the XML or adding it to the model.
*/
public static void addXMLSource(InputStream in) throws Exception {
public static void addModel(InputStream in) throws Exception {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(in);
addXMLSource((Element)doc.selectSingleNode("/adminconsole"));
addModel((Element)doc.selectSingleNode("/adminconsole"));
}
/**
......@@ -73,276 +69,60 @@ public class AdminConsole {
* @param element the Element
* @throws Exception if an error occurs.
*/
public static void addXMLSource(Element element) throws Exception {
addToModel(element);
public static void addModel(Element element) throws Exception {
overrideModels.add(element);
rebuildModel();
}
/**
* Returns the name of the application.
*/
public static String getAppName() {
return appName;
}
/**
* Returns the URL (relative or absolute) of the main logo image for the admin console.
*/
public static String getLogoImage() {
return logoImage;
}
/**
* Returns all root items. Getting the iterator from this collection returns
* all root items (should be used as tabs in the admin tool).
*
* @return a collection of all items - the root items are returned by calling the
* <tt>iterator()</tt> method.
*/
public static Collection<Item> getItems() {
List<Item> rootItems = new ArrayList<Item>();
for (Item i : items.values()) {
if (i.getParent() == null) {
rootItems.add(i);
Element appName = (Element)generatedModel.selectSingleNode("/adminconsole/global/appname");
if (appName != null) {
return appName.getText();
}
else {
return null;
}
return rootItems;
}
/**
* Returns an item given its ID or <tt>null</tt> if it can't be found.
*
* @param id the ID of the item.
* @return an item given its ID or <tt>null</tt> if it can't be found.
* Returns the URL (relative or absolute) of the main logo image for the admin console.
*/
public static Item getItem(String id) {
return items.get(id);
public static String getLogoImage() {
Element globalLogoImage = (Element)generatedModel.selectSingleNode(
"/adminconsole/global/logo-image");
if (globalLogoImage != null) {
return globalLogoImage.getText();
}
/**
* Returns the root item given a child item. In other words, a lookup is done on the ID for
* the corresponding item - that item is assumed to be a leaf and this method returns the
* root ancestor of it.
*
* @param id the ID of the child item.
* @return the root ancestor of the specified child item.
*/
public static Item getRootByChildID(String id) {
if (id == null) {
else {
return null;
}
Item child = getItem(id);
Item root = null;
if (child != null) {
Item parent = child.getParent();
root = parent;
while (parent != null) {
parent = parent.getParent();
if (parent != null) {
root = parent;
}
}
}
return root;
}
/**
* Returns <tt>true</tt> if the given item is a sub-menu item.
* Returns the model. The model should be considered read-only.
*
* @param item the item to test.
* @return <tt>true</tt> if the given item is a sub-menu item, <tt>false</tt> otherwise.
*/
public static boolean isSubMenItem(Item item) {
int parentCount = 0;
Item parent = item.getParent();
while (parent != null) {
parentCount++;
parent = parent.getParent();
}
return parentCount >= 3;
}
/**
* Returns the ID of the page ID associated with this sub page ID.
* @param subPageID the subPageID to use to look up the page ID.
* @return the associated pageID or <tt>null</tt> if it can't be found.
*/
public static String lookupPageID(String subPageID) {
String pageID = null;
Item item = getItem(subPageID);
if (item != null) {
Item parent = item.getParent();
if (parent != null) {
parent = parent.getParent();
if (parent != null) {
pageID = parent.getId();
}
}
}
return pageID;
}
/**
* A simple class to model an item. Each item has attributes used by the admin console to
* display it like ID, name, URL and description. Also, from each item you can get its parent
* (because an Item goes in a tree structure) and any children items it has.
*/
public static class Item {
private String id;
private String name;
private String description;
private String url;
private boolean active;
private Map<String,Item> items;
private Item parent;
private static int idSeq = 0;
/**
* Creates a new item given its main attributes.
*/
public Item(String id, String name, String description, String url) {
this.id = id;
this.name = name;
this.description = description;
this.url = url;
init();
}
/**
* Creates a new item given its main attributes and the parent item (this helps set up
* the tree structure).
*/
public Item(String id, String name, String description, String url, Item parent) {
this.id = id;
this.name = name;
this.description = description;
this.url = url;
this.parent = parent;
init();
}
private void init() {
items = Collections.synchronizedMap(new LinkedHashMap<String,Item>());
if (id == null) {
id = String.valueOf(idSeq++);
}
}
/**
* Returns the ID of the item.
*/
public String getId() {
return id;
}
/**
* Returns the name of the item - this is the display name.
*/
public String getName() {
return name;
}
/**
* Sets the name.
*/
void setName(String name) {
this.name = name;
}
/**
* Returns the description of the item.
*/
public String getDescription() {
return description;
}
/**
* Sets the description.
*/
void setDescription(String description) {
this.description = description;
}
/**
* Returns the URL for this item.
*/
public String getUrl() {
return url;
}
/**
* Sets the URL for this item.
*/
public void setUrl(String url) {
this.url = url;
}
/**
* Returns true if this items is active - in the admin console this would mean it's selected.
*/
public boolean isActive() {
return active;
}
/**
* Sets the item as active - in the admin console this would mean it's selected.
*/
public void setActive(boolean active) {
this.active = active;
}
/**
* Returns the parent item or <tt>null</tt> if this is a root item.
* @return the model.
*/
public Item getParent() {
return parent;
public static Element getModel() {
return generatedModel;
}
/**
* Sets the parent item.
*/
public void setParent(Item parent) {
this.parent = parent;
}
public void addItem(Item item) {
items.put(item.getId(), item);
}
/**
* Returns the items as a collection. Use the Collection API to get/set/remove items.
*/
public Collection<Item> getItems() {
return items.values();
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (!(o instanceof Item)) {
return false;
}
Item i = (Item) o;
if (id == null || !id.equals(i.id)) {
return false;
}
return true;
}
/**
* Returns the ID of the item.
* Convenience method to select an element from the model by its ID. If an
* element with a matching ID is not found, <tt>null</tt> will be returned.
*
* @param id the ID.
* @return the element.
*/
public String toString() {
return id;
}
public static Element getElemnetByID(String id) {
return (Element)generatedModel.selectSingleNode("//item[@id='" + id + "']");
}
private static void load() {
// Load the admin-sidebar.xml file from the jiveforums.jar file:
// Load the core model as the admin-sidebar.xml file from the classpath.
InputStream in = ClassUtils.getResourceAsStream("/admin-sidebar.xml");
if (in == null) {
Log.error("Failed to load admin-sidebar.xml file from Jive Messenger classes - admin "
......@@ -350,7 +130,9 @@ public class AdminConsole {
return;
}
try {
addXMLSource(in);
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(in);
coreModel = (Element)doc.selectSingleNode("/adminconsole");
}
catch (Exception e) {
Log.error("Failure when parsing main admin-sidebar.xml file", e);
......@@ -369,15 +151,17 @@ public class AdminConsole {
Enumeration e = classLoaders[i].getResources("/META-INF/admin-sidebar.xml");
while (e.hasMoreElements()) {
url = (URL)e.nextElement();
in = url.openStream();
addXMLSource(in);
try {
in.close();
in = url.openStream();
addModel(in);
}
finally {
try { if (in != null) { in.close(); } }
catch (Exception ignored) {}
}
}
}
}
catch (Exception e) {
String msg = "Failed to load admin-sidebar.xml";
if (url != null) {
......@@ -386,90 +170,115 @@ public class AdminConsole {
Log.warn(msg, e);
}
}
rebuildModel();
}
private static void addToModel(Element element) throws Exception {
// Set any global properties
Element globalEl = (Element)element.selectSingleNode("/adminconsole/global/appname");
if (globalEl != null) {
appName = globalEl.getText();
}
Element globalLogoImageEl = (Element)element.selectSingleNode(
/**
* Rebuilds the generated model.
*/
private static void rebuildModel() {
Document doc = DocumentFactory.getInstance().createDocument();
generatedModel = coreModel.createCopy();
doc.add(generatedModel);
// Add in all overrides.
for (Element element : overrideModels) {
// See if global settings are overriden.
Element appName = (Element)element.selectSingleNode("/adminconsole/global/appname");
if (appName != null) {
Element existingAppName = (Element)generatedModel.selectSingleNode(
"/adminconsole/global/appname");
existingAppName.setText(appName.getText());
}
Element appLogoImage = (Element)element.selectSingleNode("/adminconsole/global/logo-image");
if (appLogoImage != null) {
Element existingLogoImage = (Element)generatedModel.selectSingleNode(
"/adminconsole/global/logo-image");
if (globalLogoImageEl != null) {
logoImage = globalLogoImageEl.getText();
existingLogoImage.setText(appLogoImage.getText());
}
// Get all children of the 'tabs' element - should be 'tab' items:
List tabs = element.elements("tab");
for (int i=0; i<tabs.size(); i++) {
Element tab = (Element)tabs.get(i);
// Create a new top level item with data from the xml file:
// Tabs
for (Iterator i=element.selectNodes("//tab").iterator(); i.hasNext(); ) {
Element tab = (Element)i.next();
String id = tab.attributeValue("id");
String name = tab.attributeValue("name");
String description = tab.attributeValue("description");
Item item = new Item(id, name, description, null);
// Add that item to the item collection
items.put(id, item);
// Delve down into this item's sidebars - build up a model of these then add into
// the item above.
List sidebars = tab.elements("sidebar");
for (int j=0; j<sidebars.size(); j++) {
Element sidebar = (Element)sidebars.get(j);
Element existingTab = getElemnetByID(id);
// Simple case, there is no existing tab with the same id.
if (existingTab == null) {
generatedModel.add(tab.createCopy());
}
// More complex case -- a tab with the same id already exists.
// In this case, we have to overrite only the difference between
// the two elements.
else {
overrideTab(existingTab, tab);
}
}
}
}
name = sidebar.attributeValue("name");
// Create a new item, set its name
Item sidebarItem = new Item(null, name, null, null);
// Get all items of this sidebar:
List subitems = sidebar.elements("item");
for (int k=0; k<subitems.size(); k++) {
Element subitem = (Element)subitems.get(k);
// Get the id, name, descr and url attributes:
String subID = subitem.attributeValue("id");
String subName = subitem.attributeValue("name");
String subDescr = subitem.attributeValue("description");
String subURL = subitem.attributeValue("url");
// Build an item with this, add it to the subItem we made above
Item kItem = new Item(subID, subName, subDescr, subURL, sidebarItem);
items.put(kItem.getId(), kItem);
sidebarItem.addItem(kItem);
// Build any sub-sub menus:
subAddtoModel(subitem, kItem);
// If this is the first item, set the root menu item's URL as this URL:
if (j==0 && k == 0) {
item.setUrl(subURL);
}
}
// Add the subItem to the item created above
sidebarItem.setParent(item);
items.put(sidebarItem.getId(), sidebarItem);
item.addItem(sidebarItem);
private static void overrideTab(Element tab, Element overrideTab) {
// Override name, url, description.
tab.addAttribute("name", overrideTab.attributeValue("name"));
tab.addAttribute("url", overrideTab.attributeValue("url"));
tab.addAttribute("description", overrideTab.attributeValue("description"));
// Override sidebar items.
for (Iterator i=overrideTab.elementIterator(); i.hasNext(); ) {
Element sidebar = (Element)i.next();
String id = sidebar.attributeValue("id");
Element existingSidebar = getElemnetByID(id);
// Simple case, there is no existing sidebar with the same id.
if (existingSidebar == null) {
tab.add(sidebar.createCopy());
}
// More complex case -- a sidebar with the same id already exists.
// In this case, we have to overrite only the difference between
// the two elements.
else {
overrideSidebar(existingSidebar, sidebar);
}
}
}
private static void subAddtoModel(Element parentElement, Item parentItem) {
private static void overrideSidebar(Element sidebar, Element overrideSidebar) {
// Override name.
sidebar.addAttribute("name", overrideSidebar.attributeValue("name"));
// Override entries.
for (Iterator i=overrideSidebar.elementIterator(); i.hasNext(); ) {
Element entry = (Element)i.next();
String id = sidebar.attributeValue("id");
Element existingEntry = getElemnetByID(id);
// Simple case, there is no existing sidebar with the same id.
if (existingEntry == null) {
sidebar.add(entry.createCopy());
}
// More complex case -- a sidebar with the same id already exists.
// In this case, we have to overrite only the difference between
// the two elements.
else {
overrideEntry(existingEntry, entry);
}
}
}
List subsidebars = parentElement.elements("subsidebar");
for (int i=0; i<subsidebars.size(); i++) {
Element subsidebar = (Element)subsidebars.get(i);
String subsidebarName = subsidebar.attributeValue("name");
Item subsidebarItem = new Item(null, subsidebarName, null, null, parentItem);
// Get the items under it
List subitems = subsidebar.elements("item");
for (int j=0; j<subitems.size(); j++) {
Element item = (Element)subitems.get(j);
String id = item.attributeValue("id");
String name = item.attributeValue("name");
String url = item.attributeValue("url");
String descr = item.attributeValue("description");
Item newItem = new Item(id, name, descr, url, subsidebarItem);
subsidebarItem.addItem(newItem);
items.put(id, newItem);
}
parentItem.addItem(subsidebarItem);
private static void overrideEntry(Element entry, Element overrideEntry) {
// Override name.
entry.addAttribute("name", overrideEntry.attributeValue("name"));
entry.addAttribute("url", overrideEntry.attributeValue("url"));
entry.addAttribute("description", overrideEntry.attributeValue("description"));
// Override any sidebars contained in the entry.
for (Iterator i=overrideEntry.elementIterator(); i.hasNext(); ) {
Element sidebar = (Element)i.next();
String id = sidebar.attributeValue("id");
Element existingSidebar = getElemnetByID(id);
// Simple case, there is no existing sidebar with the same id.
if (existingSidebar == null) {
entry.add(sidebar.createCopy());
}
// More complex case -- a sidebar with the same id already exists.
// In this case, we have to overrite only the difference between
// the two elements.
else {
overrideSidebar(existingSidebar, sidebar);
}
}
}
......@@ -483,9 +292,4 @@ public class AdminConsole {
classLoaders[2] = ClassLoader.getSystemClassLoader();
return classLoaders;
}
// Called by test classes to wipe and reload the internal data
private static void clear() {
init();
}
}
\ No newline at end of file
......@@ -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