Author: wrzep Date: 2005-12-16 16:09:02 -0500 (Fri, 16 Dec 2005) New Revision: 1825 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/XmlTools.java trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java Log: completely rearranged code for filling context in Podcast.java to make it more understandable ;-) http://jira.jboss.com/jira/browse/JBLAB-540 Pawel Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/XmlTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/XmlTools.java 2005-12-16 16:46:56 UTC (rev 1824) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/XmlTools.java 2005-12-16 21:09:02 UTC (rev 1825) @@ -104,13 +104,33 @@ for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { - properties.put(n.getNodeName(),XmlTools.unmarshallText(n)); + properties.put(n.getNodeName(), XmlTools.unmarshallText(n)); } } return properties; } + /** + * Reads all child nodes of the given node and returns them as a map. + * + * @param root Node from which to read the child nodes. + * @return A map binding child nodes names with appropriate nodes. + */ + public static Map<String, Node> getNodeMapFromNodeElements(Node root) { + Map<String, Node> properties = new HashMap<String, Node>(); + NodeList list = root.getChildNodes(); + + for (int i = 0; i < list.getLength(); i++) { + Node n = list.item(i); + if (n.getNodeType() == Node.ELEMENT_NODE) { + properties.put(n.getNodeName(), n); + } + } + + return properties; + } + /** * From the given node, gets the value of the specified attribute. * @param root Node to read the attribute from. Modified: trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java =================================================================== --- trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java 2005-12-16 16:46:56 UTC (rev 1824) +++ trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java 2005-12-16 21:09:02 UTC (rev 1825) @@ -125,8 +125,77 @@ allItemsArr = getAllItems(nodes).toArray(); java.util.Arrays.sort((Object[]) allItemsArr, new ItemComparator(true)); } + /** + * Fills the given context with item information + * + * @param nodeContext Context to fill + * @param item ItemIF to get information from + */ + private void fillItemInfo(DelegateContext nodeContext, ItemIF item) { + nodeContext.put("title", item.getTitle()); + nodeContext.put("description", item.getDescription()); + + Date date = item.getDate(); + if (date != null) { + DateFormat dateFormat = DateFormat.getInstance(); + dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); + String dateString = dateFormat.format(date) + " GMT"; + nodeContext.put("date", dateString); + } + + URL link = item.getLink(); + if (link != null) { + nodeContext.put("link", link.toString()); + } + } /** + * Fills the given context with enclosure information + * + * @param nodeContext Context to fill + * @param item ItemEnclosureIF to get information from + */ + private void fillEnclosureInfo(DelegateContext nodeContext, ItemEnclosureIF enclosure) { + URL enclosureLocation = null; + + if (enclosure != null) { + enclosureLocation = enclosure.getLocation(); + } + + if (enclosureLocation != null) { + nodeContext.put("enclosure-link", enclosureLocation.toString()); + nodeContext.put("enclosure-type", enclosure.getType()); + nodeContext.put("enclosure-size", Math.round(enclosure.getLength() / BYTES_IN_MB)); + } + } + + /** + * Fills the given context with channel information + * + * @param nodeContext Context to fill + * @param item ChannelIF to get information from + */ + private void fillChannelInfo(DelegateContext nodeContext, ChannelIF channel) { + nodeContext.put("channel-title", channel.getTitle()); + URL channelLocation = channel.getLocation(); + if (channelLocation != null) { + nodeContext.put("channel-link", channelLocation.toString()); + } + + ImageIF channelImage = channel.getImage(); + + System.out.println("image: " + channelImage); + if (channelImage != null) { + System.out.println("location: " + channelImage.getLocation() + + " / link: " + channelImage.getLink()); + } + + if ((channelImage != null) && (channelImage.getLocation() != null)) { + nodeContext.put("channel-image", channelImage.getLocation().toString()); + } + } + + /** * Fills the given context with podcast information. * * @param context Context to fill. @@ -138,61 +207,21 @@ for (int i = 0; i < iterations; i++) { ItemIF item = (ItemIF) allItemsArr[i]; DelegateContext nodeContext = new DelegateContext(); - - // filling the context with item information nodeContext.put("no", i+1); - nodeContext.put("title", item.getTitle()); - nodeContext.put("description", item.getDescription()); - Date date = item.getDate(); - if (date != null) { - DateFormat dateFormat = DateFormat.getInstance(); - dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); - String dateString = dateFormat.format(date) + " GMT"; - nodeContext.put("date", dateString); - } + fillItemInfo(nodeContext, item); + + fillEnclosureInfo(nodeContext, item.getEnclosure()); - URL link = item.getLink(); - if (link != null) { - nodeContext.put("link", link.toString()); - } + fillChannelInfo(nodeContext, item.getChannel()); - // filling the context with enclosure information - - ItemEnclosureIF enclosure = item.getEnclosure(); - URL enclosureLocation = null; - - if (enclosure != null) { - enclosureLocation = enclosure.getLocation(); - } - - if (enclosureLocation != null) { - nodeContext.put("enclosure-link", enclosureLocation.toString()); - nodeContext.put("enclosure-type", enclosure.getType()); - nodeContext.put("enclosure-size", Math.round(enclosure.getLength() / BYTES_IN_MB)); - } - - // filling the context with channel information - - ChannelIF channel = item.getChannel(); - - nodeContext.put("channel-title", channel.getTitle()); - URL channelLocation = channel.getLocation(); - if (channelLocation != null) { - nodeContext.put("channel-link", channelLocation.toString()); - } - - ImageIF channelImage = channel.getImage(); - if ((channelImage != null) && (channelImage.getLocation() != null)) { - nodeContext.put("channel-image", channelImage.getLocation().toString()); - } - - // TODO itunes tags + // TODO itunes tags parsing /* System.out.println("channel / element value / author = " + channel.getElementValue("itunes:author")); System.out.println("item / element value / image = " + item.getElementValue("itunes:image")); */ + context.append("podcast", nodeContext); } } 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-16 16:46:56 UTC (rev 1824) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2005-12-16 21:09:02 UTC (rev 1825) @@ -61,10 +61,17 @@ private final static String PLUGIN_CLASS_ELEMENT = "class"; private final static String PLUGIN_WEIGHT_ELEMENT = "weight"; private final static String PLUGIN_PROPERTIES_ELEMENT = "properties"; + + private static final String MAIN_PAGE_COLLUMNS_TAG = "main-page"; + private static final String PROJECT_PAGE_COLLUMNS_TAG = "project-page"; private String portalName; private Projects projects; + + private List<String> mainPagePlugins; + private List<String> projectPagePlugins; + private List<Plugin> statusPlugins; private List<Plugin> scorePlugins; private List<Plugin> allPlugins; @@ -76,10 +83,14 @@ Status(String portalName, Node statusRoot, Node statusPluginsRoot, Node scorePluginsRoot) { this.portalName = portalName; - log = Logger.getLogger(this.getClass()); initPluginElements(); + // Get general properties + Map<String,Node> statusNodeMap = XmlTools.getNodeMapFromNodeElements(statusRoot); + mainPagePlugins = getPagePlugins(statusRoot, MAIN_PAGE_COLLUMNS_TAG); + projectPagePlugins = getPagePlugins(statusRoot, PROJECT_PAGE_COLLUMNS_TAG); + // Get the projects projects = ProjectsHelper.getProjects(portalName); @@ -96,6 +107,11 @@ allPlugins.addAll(scorePlugins); } + private List<String> getPagePlugins(Node statusRoot, String nodeTag) { + + return null; + } + private Set<Node> getPluginsNodes(Node pluginsRoot) { HashSet<String> pluginElementSet = new HashSet<String>(); pluginElementSet.add(PLUGIN_ELEMENT); |