From: <jbo...@li...> - 2006-04-19 20:24:27
|
Author: dam...@jb... Date: 2006-04-19 16:24:23 -0400 (Wed, 19 Apr 2006) New Revision: 3804 Removed: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsPortlet.java Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java Log: Removed portal and forge dependencies. Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java 2006-04-19 19:45:21 UTC (rev 3803) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java 2006-04-19 20:24:23 UTC (rev 3804) @@ -25,8 +25,8 @@ import org.jboss.shotoku.cache.ShotokuCacheItem; public class FeedsCache extends ShotokuCacheItem<Pair<String, String>, FeedsDescriptor> { - private FeedsDescriptor getDesc(String portalName, String baseServerAddress) { - return new FeedsDescriptor(portalName, baseServerAddress); + private FeedsDescriptor getDesc(String baseServerAddress) { + return new FeedsDescriptor(baseServerAddress); } public void update(Pair<String, String> key, FeedsDescriptor currentObject) { Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-04-19 19:45:21 UTC (rev 3803) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-04-19 20:24:23 UTC (rev 3804) @@ -42,12 +42,10 @@ import org.apache.velocity.VelocityContext; import org.apache.xerces.parsers.DOMParser; -import org.jboss.forge.common.ForgeHelper; -import org.jboss.forge.common.XmlTools; -import org.jboss.forge.common.projects.ProjectsHelper; -import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; +import org.jboss.shotoku.feeds.FeedsHelper; +import org.jboss.shotoku.tools.XmlTools; +import org.jboss.shotoku.feeds.SiteHelper; import org.jboss.logging.Logger; -import org.jboss.portal.common.context.DelegateContext; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.tools.Pair; import org.jboss.shotoku.aop.CacheItem; @@ -63,6 +61,7 @@ * provides access to them. * * @author adamw + * @author da...@si... */ public class FeedsDescriptor { private static final Logger log = Logger.getLogger(FeedsDescriptor.class); @@ -71,7 +70,7 @@ * <code>FEEDS_DIRECTORY</code> - shotoku directory in which feed * definitions are stored. */ - protected final static String FEEDS_DIRECTORY = "feeds"; + protected final static String FEEDS_DIRECTORY = "descriptors"; /** * <code>FEEDS_NODE_ENDING</code> - node with names ending with this @@ -93,18 +92,19 @@ private final static String TYPE_PARAM = "${type}"; - private final static String PROJECT_PARAM = "${project}"; + private final static String SITE_PARAM = "${site}"; - private final static String PROJECT_NAME_PARAM = "${project-name}"; + private final static String SITE_NAME_PARAM = "${site-name}"; + + private final static String FEEDS_BASEDIR = "shotoku.feeds.basedir"; - protected final static String FEEDS_FILE_PREFIX = "forge-feeds"; + protected final static String FEEDS_FILE_PREFIX = "shotoku-feeds"; @CacheItem private static FeedsCache feedsCache; - static synchronized FeedsDescriptor getInstance(final String portalName, - final String baseServerAddress) { - return feedsCache.get(new Pair<String, String>(portalName, baseServerAddress)); + static synchronized FeedsDescriptor getInstance(final String baseServerAddress) { + return feedsCache.get(baseServerAddress); } /** @@ -128,10 +128,17 @@ private String baseServerAddress; - public FeedsDescriptor(String portalName, String baseServerAddress) { + public FeedsDescriptor(String baseServerAddress) { this.baseServerAddress = baseServerAddress; + String feedsBaseDir = ContentManager.getProperty(FEEDS_BASEDIR); - ContentManager cm = ContentManager.getContentManager(portalName + "/" + if (feedsBaseDir == null) + throw new RuntimeException(FEEDS_BASEDIR" property missing from "+ + "shotoku.properties. Shotoku feeds needs"+ + " this to know where to load the feeds "+ + "descriptor files."); + + ContentManager cm = ContentManager.getContentManager(feedsBaseDir+"/" + FEEDS_DIRECTORY); // Creating the maps that will hold the feeds. @@ -156,7 +163,7 @@ .toList()) { if (feedNode.getName().endsWith(FEEDS_NODE_ENDING)) { try { - addFeedDefinitions(portalName, allFeedDefs, feedNode); + addFeedDefinitions(allFeedDefs, feedNode); } catch (Exception e) { // We just don't add the feeds ... but log a warning. log.warn("Can't add feed definitions.", e); @@ -165,7 +172,7 @@ } // Firstly - the remote feeds. - generateRemoteFeeds(portalName, remoteFeedDefs); + generateRemoteFeeds(remoteFeedDefs); // Then, shotoku feeds - first loading the properties - directive classes. Properties props = new Properties(); @@ -175,10 +182,10 @@ log.warn("Error loading shotoku feeds configuration.", e); } - generateShotokuFeeds(portalName, shotokuFeedDefs, props); + generateShotokuFeeds(shotokuFeedDefs, props); // After that, we can create the aggregated feeds. - generateAggregatedFeeds(portalName, aggregatedFeedDefs); + generateAggregatedFeeds(aggregatedFeedDefs); // Finally, filling the context. fillContext(); @@ -201,30 +208,22 @@ } /** - * 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. + * Gets an array of ids of Sites + * @return An array of site ids for this shotoku feeds instance. */ - private String[] getProjectsIds(String portalName, String projectLevelAttr) { - if (projectLevelAttr != null) { - return ProjectsHelper.getProjects(portalName).getProjectIds( - new NullPermissionsChecker(), - ALL_TOKENS.equals(projectLevelAttr) ? null - : projectLevelAttr).toArray(new String[0]); - } else { + private String[] getSiteIds() { + if (FeedsHelper.getSiteIds() != null) { + return FeedsHelper.getSiteIds(); + else return new String[] { "" }; - } } /** - * @param portalName - * @param projectId - * @return Name of a project with the given id. + * @param siteId + * @return Name of a site with the given id. */ - private String getProjectName(String portalName, String projectId) { - return ProjectsHelper.getProjects(portalName).getProjectName(projectId); + private String getSiteName(String siteId) { + return FeedsHelper.getSiteName(siteId); } /** @@ -264,8 +263,6 @@ * @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 @@ -276,7 +273,7 @@ * @throws ClassNotFoundException */ private SearchParameter generateSearchParameter(Node n, Properties props, - Set<String> parametrized, String portalName, String projectId) + Set<String> parametrized, String siteId) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, @@ -294,13 +291,13 @@ 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. + // ${site} and ${site-name} in them. param = (SearchParameter) Class.forName(paramClass).getConstructor( new Class[] { Map.class }).newInstance( new Object[] { replaceInMapValues(replaceInMapValues( XmlTools.getMapFromNodeAttributes(n), - PROJECT_PARAM, projectId), PROJECT_NAME_PARAM, - getProjectName(portalName, projectId)) }); + SITE_PARAM, siteId), SITE_NAME_PARAM, + getSiteName(siteId)) }); } else { param = (SearchParameter) Class.forName(paramClass).newInstance(); } @@ -315,7 +312,7 @@ // Invoking the function recursively and adding the // resulting parameter. SearchParameter childParam = generateSearchParameter(child, - props, parametrized, portalName, projectId); + props, parametrized, siteId); Method[] methods = param.getClass().getMethods(); for (Method method : methods) { @@ -332,8 +329,8 @@ private final static String RFC_822_DATE = "EEE, d MMM yyyy HH:mm:ss Z"; - private void generateShotokuFeeds(String portalName, - Map<String, Node> feedDefs, Properties props) { + private void generateShotokuFeeds(Map<String, Node> feedDefs, + Properties props) { Set<String> parametrized = new HashSet<String>(Arrays.asList(props.getProperty( "parametrized").split("[,]"))); @@ -344,8 +341,6 @@ String prefixAttr = XmlTools.getAttributeValue(feedNode, "prefix"); String idAttr = XmlTools.getAttributeValue(feedNode, "id"); String typesAttr = XmlTools.getAttributeValue(feedNode, "type"); - String projectLevelAttr = XmlTools.getAttributeValue(feedNode, - "project-level"); String displayNameAttr = XmlTools.getAttributeValue(feedNode, "display-name"); @@ -355,9 +350,9 @@ // Generating the type of feeds that have been requested. String[] types = getTypes(typesAttr); - // Generating the projects for which the feeds have been requested, + // Generating the sites for which the feeds have been requested, // if any. - String[] projects = getProjectsIds(portalName, projectLevelAttr); + String[] siteIds = getSiteIds(); Map<String, String> attributes = XmlTools .getMapFromNodeAttributes(feedNode); @@ -375,9 +370,9 @@ vc.put("baseServerAddress", baseServerAddress); vc.put("escape", new TextEscaping()); - for (String project : projects) { - String feedNameReplaced = feedName.replace(PROJECT_PARAM, - project); + for (String site : siteIds) { + String feedNameReplaced = feedName.replace(SITE_PARAM, + site); NodeList feedNodeChildren = feedNode.getChildNodes(); for (int i = 0; i < feedNodeChildren.getLength(); i++) { @@ -388,8 +383,7 @@ if ("search".equals(searchNode.getNodeName())) { try { Search search = (Search) generateSearchParameter( - searchNode, props, parametrized, - portalName, project); + searchNode, props, parametrized, site); org.jboss.shotoku.NodeList list = cm.search(search); @@ -415,7 +409,7 @@ vc.put("link", generateFeedLink(true, feedNameReplaced, type)); - // Now that we have type and project, we can render the + // Now that we have type and site, we can render the // template. Writer w = newFeed.getWriter(); cm.getVelocityEngine().mergeTemplate(template, vc, w); @@ -431,17 +425,16 @@ } } - // Finally, adding a feed name. We have to replace ${project} - // and ${project-name} in it. + // Finally, adding a feed name. We have to replace ${site} + // and ${site-name} in it. feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( - PROJECT_PARAM, project).replace(PROJECT_NAME_PARAM, - getProjectName(portalName, project))); + SITE_PARAM, site).replace(SITE_NAME_PARAM, + getSiteName(site))); } } } - private void generateRemoteFeeds(String portalName, - Map<String, Node> feedDefs) { + private void generateRemoteFeeds(Map<String, Node> feedDefs) { for (String feedName : feedDefs.keySet()) { Node feedNode = feedDefs.get(feedName); String addressAttr = XmlTools @@ -449,25 +442,23 @@ String typesAttr = XmlTools.getAttributeValue(feedNode, "type"); String displayNameAttr = XmlTools.getAttributeValue(feedNode, "display-name"); - String projectLevelAttr = XmlTools.getAttributeValue(feedNode, - "project-level"); // Generating the type of feeds that have been requested. String[] types = getTypes(typesAttr); - // Generating the projects for which the feeds have been requested, + // Generating the sites for which the feeds have been requested, // if any. - String[] projects = getProjectsIds(portalName, projectLevelAttr); + String[] sites = getSiteIds(); - // For each type, project pair, generating a feed and storing it in + // For each type, site pair generating a feed and storing it in // the feeds map. - for (String project : projects) { - String feedNameReplaced = feedName.replace(PROJECT_PARAM, - project); + for (String siteId : siteIds) { + String feedNameReplaced = feedName.replace(SITE_PARAM, + siteId); for (String type : types) { String address = addressAttr.replace(TYPE_PARAM, type) - .replace(PROJECT_PARAM, project); + .replace(SITE_PARAM, siteId); try { Feed newFeed = FeedFactory.getNewFeed(type); @@ -479,17 +470,16 @@ } } - // Adding a feed name. We have to replace ${project} - // and ${project-name} in it. + // Adding a feed name. We have to replace ${site} + // and ${site-name} in it. feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( - PROJECT_PARAM, project).replace(PROJECT_NAME_PARAM, - getProjectName(portalName, project))); + SITE_PARAM, siteId).replace(SITE_NAME_PARAM, + getSiteName(siteId))); } } } - private void generateAggregatedFeeds(String portalName, - Map<String, Node> feedDefs) { + private void generateAggregatedFeeds(Map<String, Node> feedDefs) { // First building requirements of each feed - that is, whit which // feeds each aggregated feed is built. Map<String, Set<String>> requirements = @@ -517,15 +507,12 @@ n = nodes.item(i); if ("include".equals(n.getNodeName())) { String nameAttr = XmlTools.getAttributeValue(n, "name"); - String projectLevelAttr = XmlTools.getAttributeValue(n, - "project-level"); - String[] projects = getProjectsIds(portalName, - projectLevelAttr); + String[] siteIds = getSiteIds(); - for (String project : projects) { - feedRequirements.add(nameAttr.replace(PROJECT_PARAM, - project)); + for (String siteId : siteIds) { + feedRequirements.add(nameAttr.replace(SITE_PARAM, + siteId)); } } } @@ -657,35 +644,30 @@ /** * 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 + * over many sites). * @param feedGroup * @param feedName * @param node */ - private void addFeedNamesToGroup(String portalName, Set<String> feedGroup, + private void addFeedNamesToGroup(Set<String> feedGroup, String feedName, Node node) { - String projectLevelAttr = XmlTools.getAttributeValue(node, - "project-level"); - String[] projects = getProjectsIds(portalName, projectLevelAttr); + String[] siteIds = getSiteIds(); - for (String project : projects) { - feedGroup.add(feedName.replace(PROJECT_PARAM, project)); + for (String siteId : siteIds) { + feedGroup.add(feedName.replace(SITE_PARAM, siteId)); } } /** * 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, + private void addFeedDefinitions(Map<String, Map<String, Node>> feedDefinitions, org.jboss.shotoku.Node node) throws SAXException, IOException { DOMParser parser = new DOMParser(); parser.parse(new InputSource(node.getContentInputStream())); @@ -702,7 +684,7 @@ n = nodes.item(i); if (feedDefinitions.get(n.getNodeName()) != null) { String feedName = XmlTools.getAttributeValue(n, "name"); - addFeedNamesToGroup(portalName, feedGroup, feedName, n); + addFeedNamesToGroup(feedGroup, feedName, n); feedDefinitions.get(n.getNodeName()).put(feedName, n); } } Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsPortlet.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsPortlet.java 2006-04-19 19:45:21 UTC (rev 3803) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsPortlet.java 2006-04-19 20:24:23 UTC (rev 3804) @@ -1,63 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.shotoku.feeds; - -import java.io.IOException; - -import javax.portlet.PortletException; -import javax.portlet.PortletRequestDispatcher; -import javax.portlet.PortletSecurityException; - -import org.jboss.forge.common.ForgeHelper; -import org.jboss.forge.common.projects.ProjectsHelper; -import org.jboss.portal.common.context.DelegateContext; -import org.jboss.portal.core.servlet.jsp.PortalJsp; -import org.jboss.portlet.JBossPortlet; -import org.jboss.portlet.JBossRenderRequest; -import org.jboss.portlet.JBossRenderResponse; - -public class FeedsPortlet extends JBossPortlet { - private final static String FEEDS_JSP = "feeds.jsp"; - - @Override - protected void doView(JBossRenderRequest request, JBossRenderResponse response) - throws PortletException, PortletSecurityException, IOException { - response.setContentType("text/html"); - - String portalName = ForgeHelper.getPortalName(request); - ProjectsHelper.prepareRequest(request); - - // Getting the feeds context. - DelegateContext feedsContext = FeedsDescriptor.getInstance(portalName, - ForgeHelper.getBaseServerAddress(request)) - .getContext(); - - // Displaying. - request.setAttribute(PortalJsp.CTX_REQUEST, feedsContext); - - PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher( - ForgeHelper.createRepoAccessPath(portalName, - FeedsDescriptor.FEEDS_DIRECTORY + '/' + FEEDS_JSP)); - rd.include(request, response); - } - -} |