From: <jbo...@li...> - 2005-12-17 14:53:56
|
Author: wrzep Date: 2005-12-17 09:53:48 -0500 (Sat, 17 Dec 2005) New Revision: 1831 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java Log: displaying only columns listed in the status.xml http://jira.jboss.com/jira/browse/JBLAB-415 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2005-12-17 14:06:00 UTC (rev 1830) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2005-12-17 14:53:48 UTC (rev 1831) @@ -23,6 +23,7 @@ package org.jboss.forge.status; import org.jboss.forge.status.plugins.Plugin; +import org.jboss.portal.common.context.DelegateContext; /** * @author Pawel Wrzeszcz @@ -37,4 +38,13 @@ this.plugin = plugin; System.out.println("Column " + name + " / " + (plugin == null ? "null" : plugin.getId())); } + + public String getName() { + return name; + } + + public void fillProjectContext(DelegateContext projectContext, String projectId) { + DelegateContext entryContext = projectContext.next("entry"); + entryContext.put("value", plugin.getValue(projectId)); + } } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2005-12-17 14:06:00 UTC (rev 1830) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2005-12-17 14:53:48 UTC (rev 1831) @@ -81,15 +81,12 @@ private HashSet<String> pluginsElements; Status(String portalName, Node statusRoot, Node statusPluginsRoot, Node scorePluginsRoot) { + this.portalName = portalName; log = Logger.getLogger(this.getClass()); initPluginElements(); - // Get general properties - mainPageColumns = getPageColumns(statusRoot, MAIN_PAGE_COLLUMNS_TAG); - System.out.println("mainPageColumns: " + mainPageColumns); - // Get the projects projects = ProjectsHelper.getProjects(portalName); @@ -104,9 +101,13 @@ allPlugins = new HashMap<String, Plugin>(); allPlugins.putAll(statusPlugins); allPlugins.putAll(scorePlugins); + + // Get columns to display + mainPageColumns = getPageColumns(statusRoot, MAIN_PAGE_COLLUMNS_TAG); } private List<Column> getPageColumns(Node statusRoot, String nodeTag) { + List<Column> columns = new ArrayList<Column>(); Node pageRoot = XmlTools.getFirstNodeWithName(statusRoot, nodeTag); @@ -115,21 +116,24 @@ for (int i = 0; i < columnsList.getLength(); i++) { Node columnNode = columnsList.item(i); - String name = null; - Node nameNode = XmlTools.getFirstNodeWithName(columnNode, "name"); - if (nameNode != null) { - name = XmlTools.unmarshallText(nameNode); - } - Plugin plugin = null; + if (columnNode.getNodeType() == Node.ELEMENT_NODE) { + Node nameNode = XmlTools.getFirstNodeWithName(columnNode, "name"); + String name = XmlTools.unmarshallText(nameNode); - Column column = new Column(name,plugin); - columns.add(column); + Node pluginNode = XmlTools.getFirstNodeWithName(columnNode, "plugin"); + String pluginId = XmlTools.unmarshallText(pluginNode); + Plugin plugin = allPlugins.get(pluginId); + + Column column = new Column(name,plugin); + columns.add(column); + } } - return null; + return columns; } private Set<Node> getPluginsNodes(Node pluginsRoot) { + HashSet<String> pluginElementSet = new HashSet<String>(); pluginElementSet.add(PLUGIN_ELEMENT); Set<Node> pluginsNodes = getChildNodesSet(pluginsRoot, pluginElementSet); @@ -138,6 +142,7 @@ } private void initPluginElements() { + pluginsElements = new HashSet<String>(); pluginsElements.add(PLUGIN_ID_ELEMENT); @@ -146,47 +151,46 @@ pluginsElements.add(PLUGIN_WEIGHT_ELEMENT); pluginsElements.add(PLUGIN_PROPERTIES_ELEMENT); } - - /** * Fills the given context with podcast information. * * @param context Context to fill. */ public void fillContext(DelegateContext context) { - - // Set collumns names - for (Iterator iter = allPlugins.values().iterator(); iter.hasNext();) { - Plugin plugin = (Plugin) iter.next(); + + fillColumnsNames(context); + fillValues(context); + } + + private void fillColumnsNames(DelegateContext context) { + + for (Iterator iter = mainPageColumns.iterator(); iter.hasNext();) { + Column column = (Column) iter.next(); - DelegateContext collumnContext = new DelegateContext(); - collumnContext.put("name", plugin.getName()); - collumnContext.put("id", plugin.getId()); + DelegateContext columnContext = new DelegateContext(); + columnContext.put("name", column.getName()); - context.append("collumn", collumnContext); + context.append("collumn", columnContext); } + } + + /** Fills the context with appropiate values (from each column) for each project. */ + private void fillValues(DelegateContext context) { + Set<String> projectIds = projects.getProjectIds( + (PermissionsChecker) new NullPermissionsChecker(), null); - /* Fill the context with appropiate values (from each plugin) for each project, */ - /* including final score as well. */ - - PermissionsChecker permissionsChecker = (PermissionsChecker) new NullPermissionsChecker(); - String projectLevel = null; - Set<String> projectIds = projects.getProjectIds(permissionsChecker, projectLevel); - int position = 0; for (Iterator iter = projectIds.iterator(); iter.hasNext();) { String projectId = (String) iter.next(); position++; - DelegateContext projectContext = new DelegateContext(); + DelegateContext projectContext = context.next("project"); fillProjectContext(projectContext, projectId, position); - - context.append("project", projectContext); } } - + private void fillProjectContext(DelegateContext projectContext, String projectId, int position) { @@ -195,17 +199,14 @@ projectContext.put("name", projects.getProjectName(projectId)); projectContext.put("link", projects.getProjectLink(projectId)); - fillEntries(projectContext, allPlugins.values(), projectId); + fillEntries(projectContext, mainPageColumns, projectId); } - private void fillEntries(DelegateContext projectContext, Collection<Plugin> plugins, String projectId) { - for (Iterator iter = plugins.iterator(); iter.hasNext();) { - Plugin plugin = (Plugin) iter.next(); - - DelegateContext entryContext = new DelegateContext(); - entryContext.put("value", plugin.getValue(projectId)); - - projectContext.append("entry", entryContext); + private void fillEntries(DelegateContext projectContext, Collection<Column> columns, String projectId) { + for (Iterator iter = columns.iterator(); iter.hasNext();) { + Column column = (Column) iter.next(); + + column.fillProjectContext(projectContext, projectId); } } @@ -218,7 +219,7 @@ Plugin plugin = getPlugin(pluginNode, scorePlugins); if (plugin != null) { - plugins.put(plugin.getName(), plugin); + plugins.put(plugin.getId(), plugin); } } @@ -228,7 +229,6 @@ private Plugin getPlugin(Node pluginNode, boolean scorePlugin) { // Get plugin info from pluginNode - String pluginType = pluginNode.getNodeName(); Map<String,Node> pluginProperties = getChildNodesMap(pluginNode, pluginsElements); String pluginClassString = XmlTools.unmarshallText(pluginProperties.get(PLUGIN_CLASS_ELEMENT)); @@ -271,22 +271,6 @@ return plugin; } - - - private Map<String,String> getChildNodesStringMap(Node root) { - HashMap<String,String> ret = new HashMap<String,String>(); - NodeList list = root.getChildNodes(); - - for (int i = 0; i < list.getLength(); i++) { - Node n = list.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - ret.put(n.getNodeName(),XmlTools.unmarshallText(n)); - } - } - - return ret; - } - /** * For the given Node, computes Set of it's child Nodes. * Only child Nodes with names included in <code>nodesNames</code> Set @@ -330,20 +314,5 @@ return ret; } - - private Set<String> getStringsFromNode(Node root, String element) { - HashSet<String> s = new HashSet<String>(); - - HashSet<String> nodesNames = new HashSet<String>(); - nodesNames.add(element); - - Set<Node> nodes = getChildNodesSet(root, nodesNames); - - for (Iterator iter = nodes.iterator(); iter.hasNext();) { - Node n = (Node) iter.next(); - s.add(XmlTools.unmarshallText(n)); - } - - return s; - } + } |