From: <jbo...@li...> - 2005-11-10 22:41:45
|
Author: adamw Date: 2005-11-10 17:41:31 -0500 (Thu, 10 Nov 2005) New Revision: 1552 Modified: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java trunk/forge/portal-extensions/forge-status/ trunk/forge/portal-extensions/jbosswiki/ Log: Some comments Modified: trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2005-11-10 20:16:39 UTC (rev 1551) +++ trunk/forge/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2005-11-10 22:41:31 UTC (rev 1552) @@ -172,7 +172,7 @@ // Firstly - the remote feeds. generateRemoteFeeds(portalName, remoteFeedDefs); - // Then, shotoku feeds. + // Then, shotoku feeds - first loading the properties - directive classes. Properties props = new Properties(); try { props.load(cm.getNode(SHOTOKU_CONFIG).getContentInputStream()); @@ -189,6 +189,12 @@ fillContext(); } + /** + * Adds a feed of the given name and type. + * @param name + * @param type + * @param feed + */ private void addFeed(String name, String type, Feed feed) { Map<String, Feed> typesMap = feeds.get(name); if (typesMap == null) { @@ -199,6 +205,13 @@ typesMap.put(type, feed); } + /** + * Gets an array of ids of projects basing on the given project level attribute + * (the level can be a *). + * @param portalName + * @param projectLevelAttr + * @return An array of project ids that are on the specified level. + */ private String[] getProjectsIds(String portalName, String projectLevelAttr) { if (projectLevelAttr != null) { return ProjectsHelper.getProjects(portalName).getProjectIds( @@ -210,10 +223,20 @@ } } + /** + * @param portalName + * @param projectId + * @return Name of a project with the given id. + */ private String getProjectName(String portalName, String projectId) { return ProjectsHelper.getProjects(portalName).getProjectName(projectId); } + /** + * Gets an array of types basing on the given type attribute (the attribute can be a *). + * @param typesAttr + * @return An array of types. + */ private String[] getTypes(String typesAttr) { if (ALL_TOKENS.equals(typesAttr)) { return FeedFactory.getAllFeedTypes(); @@ -222,6 +245,14 @@ } } + /** + * In the given <code>map</code>, in its values, replaces each occurence of + * <code>replaceWhat</code> with <code>replaceTo</code>. + * @param map + * @param replaceWhat + * @param replaceTo + * @return <code>map</code> + */ private Map<String, String> replaceInMapValues(Map<String, String> map, String replaceWhat, String replaceTo) { for (String key : map.keySet()) { @@ -231,13 +262,33 @@ return map; } + /** + * Recursively generates a search parameter basing on its description that is + * contained in the given node. + * @param n Node from which to read the search parameters. + * @param props Properties with directives classes. + * @param parametrized Set of directive names that accept a parameter map + * in their constructor. + * @param portalName + * @param projectId + * @return A search parameter that is described in the given node. + * @throws IllegalArgumentException + * @throws SecurityException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws InvocationTargetException + * @throws NoSuchMethodException + * @throws ClassNotFoundException + */ private SearchParameter generateSearchParameter(Node n, Properties props, - Set parametrized, String portalName, String projectId) + Set<String> parametrized, String portalName, String projectId) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { String paramName = n.getNodeName(); + + // Looking for a corresponding class. String paramClass = props.getProperty(paramName); if (paramClass == null) @@ -246,6 +297,9 @@ SearchParameter param; if (parametrized.contains(paramName)) { + // Instatiating the class, it should have a constructor accepting a + // map. We take the map from node attributes, and replace + // ${project} and ${project-name} in them. param = (SearchParameter) Class.forName(paramClass).getConstructor( new Class[] { Map.class }).newInstance( new Object[] { replaceInMapValues(replaceInMapValues( @@ -261,6 +315,10 @@ Node child = nodeList.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { + // If the search paramater has child nodes, then the + // corresponding class should have an "add" method. + // Invoking the function recursively and adding the + // resulting parameter. SearchParameter childParam = generateSearchParameter(child, props, parametrized, portalName, projectId); @@ -279,7 +337,7 @@ private void generateShotokuFeeds(String portalName, Map<String, Node> feedDefs, Properties props) { - Set parametrized = new HashSet<String>(Arrays.asList(props.getProperty( + Set<String> parametrized = new HashSet<String>(Arrays.asList(props.getProperty( "parametrized").split("[,]"))); for (String feedName : feedDefs.keySet()) { @@ -307,6 +365,8 @@ Map<String, String> attributes = XmlTools .getMapFromNodeAttributes(feedNode); + // Creating a velcoity context with parts that won't change in all + // generated feeds. VelocityContext vc = new VelocityContext(attributes); String dateFormat = attributes.get("dateFormat"); @@ -320,6 +380,9 @@ NodeList feedNodeChildren = feedNode.getChildNodes(); for (int i = 0; i < feedNodeChildren.getLength(); i++) { + // For each search node, generating and performing the + // search, placing it under the demanded attribute in + // velocity's context. Node searchNode = feedNodeChildren.item(i); if ("search".equals(searchNode.getNodeName())) { try { @@ -351,11 +414,14 @@ vc.put("link", generateFeedLink(true, feedNameReplaced, type)); + // Now that we have type and project, we can render the + // template. Writer w = newFeed.getWriter(); cm.getVelocityEngine().mergeTemplate(template, vc, w); w.flush(); w.close(); + // And add the feed. addFeed(feedNameReplaced, type, newFeed); } catch (Exception e) { log.warn("Cannot merge template " + template + " for " @@ -364,6 +430,8 @@ } } + // Finally, adding a feed name. We have to replace ${project} + // and ${project-name} in it. feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( PROJECT_PARAM, project).replace(PROJECT_NAME_PARAM, getProjectName(portalName, project))); @@ -410,6 +478,8 @@ } } + // Adding a feed name. We have to replace ${project} + // and ${project-name} in it. feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( PROJECT_PARAM, project).replace(PROJECT_NAME_PARAM, getProjectName(portalName, project))); @@ -425,6 +495,9 @@ new HashMap<String, Set<String>>(); Map<String, String[]> parameters = new HashMap<String, String[]>(); + // Gathering information about defined feeds, their requirements + // (that is, from which other feeds they are composed) and their + // parameters. for (String feedName : feedDefs.keySet()) { Node n; Node feedNode = feedDefs.get(feedName); @@ -524,12 +597,24 @@ } } + /** + * Generates a link to a specified feed. If the link is to be full, an + * absolute address is returned. Otherwise, a relative one. + * @param full + * @param feedName + * @param feedType + * @return + */ private String generateFeedLink(boolean full, String feedName, String feedType) { return (full ? baseServerAddress : "") + "/feeds/" + feedName + "/" + feedType; } + /** + * Fills the <code>context</code> variable with feed information that is + * to be shown in the portlet. + */ private void fillContext() { String[] allFeedTypes = FeedFactory.getAllFeedTypes(); @@ -568,6 +653,15 @@ } } + /** + * To the given feed group, adds feeds names that are defined by the given + * node and feed name (this can be more then one, as we can have iteration + * over many projects). + * @param portalName + * @param feedGroup + * @param feedName + * @param node + */ private void addFeedNamesToGroup(String portalName, Set<String> feedGroup, String feedName, Node node) { String projectLevelAttr = XmlTools.getAttributeValue(node, @@ -580,6 +674,15 @@ } } + /** + * Adds definitions of feeds to the given map, placing child nodes of + * the given node in the appropriate map. + * @param portalName + * @param feedDefinitions + * @param node + * @throws SAXException + * @throws IOException + */ private void addFeedDefinitions(String portalName, Map<String, Map<String, Node>> feedDefinitions, org.jboss.shotoku.Node node) throws SAXException, IOException { @@ -604,6 +707,12 @@ } } + /** + * Gets a feed of the given type and name. + * @param name + * @param type + * @return + */ public Feed getFeed(String name, String type) { Map<String, Feed> feedTypes = feeds.get(name); if (feedTypes == null) Property changes on: trunk/forge/portal-extensions/forge-status ___________________________________________________________________ Name: svn:ignore + target Property changes on: trunk/forge/portal-extensions/jbosswiki ___________________________________________________________________ Name: svn:ignore - target + target wiki.ear |