From: <jbo...@li...> - 2006-05-25 19:04:26
|
Author: adamw Date: 2006-05-25 15:04:01 -0400 (Thu, 25 May 2006) New Revision: 4428 Added: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/ProjectVariableResolver.java labs/jbosslabs/trunk/portal-extensions/mysql-connector/mysql-connector-java-3.1.12-bin.jar Removed: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/AtomFeed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/Feed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedFactory.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsCache.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsPortlet.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsServlet.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FileBasedFeed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/InformaBasedFeed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/RdfDateFormat.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/RdfFeed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/RomeBasedFeed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/Rss2Feed.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/TextEscaping.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/web/ labs/jbosslabs/trunk/portal-extensions/mysql-connector/mysql-connector-java-3.1.10-bin.jar Modified: labs/jbosslabs/trunk/portal-extensions/build.properties.sample labs/jbosslabs/trunk/portal-extensions/forge-blog/src/java/org/jboss/portlet/blog/BlogConfigurationWatcher.java labs/jbosslabs/trunk/portal-extensions/forge-feeds/forge-feeds.iml labs/jbosslabs/trunk/portal-extensions/forge-feeds/maven.xml labs/jbosslabs/trunk/portal-extensions/forge-feeds/project.xml labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java labs/jbosslabs/trunk/portal-extensions/forge-tagme/ labs/jbosslabs/trunk/portal-extensions/maven.xml labs/jbosslabs/trunk/portal-extensions/mysql-connector/maven.xml labs/jbosslabs/trunk/portal-extensions/project.properties Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-36 Modified: labs/jbosslabs/trunk/portal-extensions/build.properties.sample =================================================================== --- labs/jbosslabs/trunk/portal-extensions/build.properties.sample 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/build.properties.sample 2006-05-25 19:04:01 UTC (rev 4428) @@ -6,6 +6,7 @@ local.deploy.dir=${local.server.dir}/server/all/deploy # Directory on your filesystem where portal-extensions reside. +# The path must end with a /. ext.root.dir= # Path to your local maven repository - you can comment this out if you use Modified: labs/jbosslabs/trunk/portal-extensions/forge-blog/src/java/org/jboss/portlet/blog/BlogConfigurationWatcher.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-blog/src/java/org/jboss/portlet/blog/BlogConfigurationWatcher.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-blog/src/java/org/jboss/portlet/blog/BlogConfigurationWatcher.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -8,37 +8,14 @@ import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.cache.ShotokuResourceWatcher; import org.jboss.shotoku.cache.ChangeType; +import org.jboss.shotoku.cache.ShotokuPropertiesWatcher; import org.jboss.shotoku.exceptions.ResourceDoesNotExist; -public class BlogConfigurationWatcher extends ShotokuResourceWatcher<String, Properties> { - private final static String CONFIG_FILE_NAME = "blog.properties"; - - private Properties getProperties(String portalName) { - try { - Properties ret = new Properties(); - ret.load(getContentManager(portalName).getNode( - CONFIG_FILE_NAME).getContentInputStream()); - return ret; - } catch (IOException e) { - e.printStackTrace(); - } catch (ResourceDoesNotExist e) { - // Well ... - e.printStackTrace(); - } - - return null; +public class BlogConfigurationWatcher extends ShotokuPropertiesWatcher<String> { + protected String getConfigFileName() { + return "blog.properties"; } - - public Properties init(String portalName) { - addWatchedPath(portalName, CONFIG_FILE_NAME); - return getProperties(portalName); - } - protected void update(String portalName, Properties currentObject, - Map<String, ChangeType> changes) { - put(portalName, getProperties(portalName)); - } - protected ContentManager initContentManager(String portalName) { return ContentManager.getContentManager(Tools.concatenatePaths(portalName, "blog")); } Modified: labs/jbosslabs/trunk/portal-extensions/forge-feeds/forge-feeds.iml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/forge-feeds.iml 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/forge-feeds.iml 2006-05-25 19:04:01 UTC (rev 4428) @@ -16,6 +16,7 @@ <orderEntry type="library" name="feeds" level="application" /> <orderEntry type="library" name="velocity" level="application" /> <orderEntry type="library" name="commons" level="application" /> + <orderEntry type="module" module-name="shotoku-feeds" /> <orderEntryProperties /> </component> </module> Modified: labs/jbosslabs/trunk/portal-extensions/forge-feeds/maven.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/maven.xml 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/maven.xml 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,4 +1,4 @@ -<!-- +<!-- JBoss, the OpenSource J2EE webOS Distributable under LGPL license. See terms of license at gnu.org. @@ -11,12 +11,17 @@ </goal> <goal name="build"> - <attainGoal name="prj-war-build" /> + <attainGoal name="jar" /> </goal> - <goal name="deploy"> - <attainGoal name="prj-war-deploy" /> - </goal> + <goal name="deploy"> + <j:set var="jar.to.dir" value="${local.deploy.dir}/shotoku-feeds.war" /> + <attainGoal name="jar-to-dir" /> + <ant:copy todir="${local.deploy.dir}/shotoku-feeds.war/WEB-INF/lib" + overwrite="true" + file="target/forge-feeds-1.0.jar" /> + <attainGoal name="dir-to-jar" /> + </goal> <goal name="clean"> <attainGoal name="prj-clean" /> Modified: labs/jbosslabs/trunk/portal-extensions/forge-feeds/project.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/project.xml 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/project.xml 2006-05-25 19:04:01 UTC (rev 4428) @@ -7,7 +7,7 @@ <project> <pomVersion>3</pomVersion> <extend>../common.xml</extend> - <id>feeds</id> + <id>forge-feeds</id> <name>Forge feeds</name> <currentVersion>1.0</currentVersion> <organization> @@ -17,84 +17,17 @@ <description></description> <dependencies> - <dependency> - <groupId>jboss-forge</groupId> - <artifactId>forge-common</artifactId> - <version>1.0</version> - </dependency> - - <dependency> - <groupId>aslibs</groupId> - <artifactId>javax.servlet</artifactId> - <version>1.0</version> - <jar>javax.servlet.jar</jar> - </dependency> - - <dependency> - <id>jdom</id> - <version>1.0</version> - </dependency> - - <dependency> - <id>rome</id> - <version>0.7</version> - </dependency> - <dependency> - <groupId>informa</groupId> - <artifactId>informa</artifactId> - <version>0.6.5</version> - <jar>informa.jar</jar> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - - <dependency> - <groupId>taglibs</groupId> - <artifactId>jstl</artifactId> + <groupId>jboss-forge</groupId> + <artifactId>forge-common</artifactId> <version>1.0</version> - <jar>jstl.jar</jar> - <properties> - <war.bundle>true</war.bundle> - </properties> </dependency> - - <dependency> - <groupId>taglibs</groupId> - <artifactId>standard</artifactId> - <version>1.0</version> - <jar>standard.jar</jar> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - + <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.1</version> - <properties> - <war.bundle>true</war.bundle> - </properties> - </dependency> - - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - <version>2.6.2</version> + <groupId>shotoku</groupId> + <artifactId>shotoku-feeds</artifactId> + <version>1.0</version> + <jar>shotoku-feeds.jar</jar> </dependency> - - <dependency> - <groupId>xerces</groupId> - <artifactId>xmlParserAPIs</artifactId> - <version>2.6.2</version> - </dependency> - - <dependency> - <groupId>xalan</groupId> - <artifactId>xalan</artifactId> - <version>2.6.0</version> - </dependency> </dependencies> </project> Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/AtomFeed.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/AtomFeed.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/AtomFeed.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,43 +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.forge.feeds; - -import java.io.File; -import java.io.IOException; - -import com.sun.syndication.feed.synd.SyndFeed; - -public class AtomFeed extends RomeBasedFeed { - public AtomFeed(File file) throws IOException { - super(file); - } - - @Override - protected void setFeedType(SyndFeed feed) { - feed.setFeedType("atom_0.3"); - } - - @Override - protected String getContentType() { - return "application/atom+xml"; - } -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/Feed.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/Feed.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/Feed.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,79 +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.forge.feeds; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Writer; -import java.net.URL; - -import javax.servlet.http.HttpServletResponse; - -/** - * An interface that should be implemented by classes representing data feeds. - * @author adamw - */ -public interface Feed { - /** - * Writes the feed data to the given output stream. - * @param os Output stream to write to. - * @throws IOException - */ - public void write(OutputStream os) throws IOException; - /** - * Writes the feed data to the given http servlet response, setting an - * appropriate content type. - * @param response Response to write to. - * @throws IOException - */ - public void write(HttpServletResponse response) throws IOException; - /** - * Generates a feed getting data from the given url. - * @param url Url from which to get the content. - */ - public void generate(URL url) throws IOException; - /** - * Generates a feed getting data from the given input stream. - * @param is Input stream from which to get the content. - * @throws IOException - */ - public void generate(InputStream is) throws IOException; - /** - * Gets a writer to which content of this feed can be written. - * @return A writer for writing content of this feed. - */ - public Writer getWriter() throws IOException; - /** - * Generates a feed using the given feeds. - * @param feeds Feeds which should be aggregated into a single - * feed. - */ - public void generate(Feed[] feeds, String title, - String description, String author, String link) - throws IllegalArgumentException, IOException; - /** - * Gets an input stream of this feed. - * @return Input stream of this feed. - */ - public InputStream getInputStream(); -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedFactory.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedFactory.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedFactory.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,79 +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.forge.feeds; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -/** - * A class which is an access point to specific feed implementations. - * @author adamw - */ -public class FeedFactory { - /** - * <code>feedClasses</code> - map feed type -> feed class. - */ - private static Map<String, Class> feedClasses; - private static Random random; - - static { - feedClasses = new HashMap<String, Class>(); - feedClasses.put("rss2", Rss2Feed.class); - feedClasses.put("atom", AtomFeed.class); - feedClasses.put("rdf", RdfFeed.class); - - random = new Random(); - } - - /** - * Creates a new instance of a feed implementation of the given type. - * @param type Type of feed to create. - * @return A new instance of a feed of the given type. - */ - public static Feed getNewFeed(String type) { - Class feedClass = feedClasses.get(type); - if (feedClass == null) return null; - - int nextInt; - synchronized(random) { - nextInt = random.nextInt(); - } - - try { - File file = File.createTempFile(FeedsDescriptor.FEEDS_FILE_PREFIX + nextInt, type); - return (Feed) feedClass.getConstructor(new Class[] { File.class }). - newInstance(new Object[] { file }); - } catch (Exception e) { - return null; - } - } - - /** - * Gets all feed types that have been defined. - * @return An array of defined feed types. - */ - public static String[] getAllFeedTypes() { - return feedClasses.keySet().toArray(new String[0]); - } -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsCache.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsCache.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsCache.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,39 +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.forge.feeds; - -import org.jboss.shotoku.tools.Pair; -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); - } - - public void update(Pair<String, String> key, FeedsDescriptor currentObject) { - put(key, getDesc(key.getFirst(), key.getSecond())); - } - - public FeedsDescriptor init(Pair<String, String> key) { - return getDesc(key.getFirst(), key.getSecond()); - } -} \ No newline at end of file Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsDescriptor.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,728 +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.forge.feeds; - -import java.io.IOException; -import java.io.Writer; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -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.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; -import org.jboss.shotoku.search.Search; -import org.jboss.shotoku.search.SearchParameter; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Class which handles parsing feed descriptions, generates the feeds and - * provides access to them. - * - * @author adamw - */ -public class FeedsDescriptor { - private static final Logger log = Logger.getLogger(FeedsDescriptor.class); - - /** - * <code>FEEDS_DIRECTORY</code> - shotoku directory in which feed - * definitions are stored. - */ - protected final static String FEEDS_DIRECTORY = "feeds"; - - /** - * <code>FEEDS_NODE_ENDING</code> - node with names ending with this - * string are parsed and feed definitons are read from them. - */ - private final static String FEEDS_NODE_ENDING = "-feeds.xml"; - - private final static String REM_FEED_TAG = "remote-feed"; - - private final static String AGG_FEED_TAG = "aggregated-feed"; - - private final static String SHO_FEED_TAG = "shotoku-feed"; - - private final static String SHOTOKU_CONFIG = "shotoku-config.properties"; - - private final static String ALL_TOKENS = "*"; - - private final static String TOKENS_DELIMITER = ","; - - private final static String TYPE_PARAM = "${type}"; - - private final static String PROJECT_PARAM = "${project}"; - - private final static String PROJECT_NAME_PARAM = "${project-name}"; - - protected final static String FEEDS_FILE_PREFIX = "forge-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)); - } - - /** - * <code>feeds</code> - a map of ready feeds: feed name -> (feed type -> - * feed)). - */ - private Map<String, Map<String, Feed>> feeds; - - /** - * <code>feedGroups</code> - map: feed group display name -> set of feed - * names. - */ - private Map<String, Set<String>> feedGroups; - - /** - * <code>feedDisplayNames</code> - map: feed name -> feed display name. - */ - private Map<String, String> feedDisplayNames; - - private DelegateContext context; - - private String baseServerAddress; - - public FeedsDescriptor(String portalName, String baseServerAddress) { - this.baseServerAddress = baseServerAddress; - - ContentManager cm = ContentManager.getContentManager(portalName + "/" - + FEEDS_DIRECTORY); - - // Creating the maps that will hold the feeds. - feeds = new HashMap<String, Map<String, Feed>>(); - feedGroups = new LinkedHashMap<String, Set<String>>(); - feedDisplayNames = new HashMap<String, String>(); - - // Preparing maps which will hold feed definitions. - Map<String, Node> remoteFeedDefs = new HashMap<String, Node>(); - Map<String, Node> aggregatedFeedDefs = new HashMap<String, Node>(); - Map<String, Node> shotokuFeedDefs = new HashMap<String, Node>(); - - Map<String, Map<String, Node>> allFeedDefs = - new HashMap<String, Map<String, Node>>(); - - allFeedDefs.put(REM_FEED_TAG, remoteFeedDefs); - allFeedDefs.put(AGG_FEED_TAG, aggregatedFeedDefs); - allFeedDefs.put(SHO_FEED_TAG, shotokuFeedDefs); - - // Looking for file containing feed definitons and filling the maps. - for (org.jboss.shotoku.Node feedNode : cm.getRootDirectory().getNodes() - .toList()) { - if (feedNode.getName().endsWith(FEEDS_NODE_ENDING)) { - try { - addFeedDefinitions(portalName, allFeedDefs, feedNode); - } catch (Exception e) { - // We just don't add the feeds ... but log a warning. - log.warn("Can't add feed definitions.", e); - } - } - } - - // Firstly - the remote feeds. - generateRemoteFeeds(portalName, remoteFeedDefs); - - // Then, shotoku feeds - first loading the properties - directive classes. - Properties props = new Properties(); - try { - props.load(cm.getNode(SHOTOKU_CONFIG).getContentInputStream()); - } catch (Exception e) { - log.warn("Error loading shotoku feeds configuration.", e); - } - - generateShotokuFeeds(portalName, shotokuFeedDefs, props); - - // After that, we can create the aggregated feeds. - generateAggregatedFeeds(portalName, aggregatedFeedDefs); - - // Finally, filling the context. - 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) { - typesMap = new HashMap<String, Feed>(); - feeds.put(name, typesMap); - } - - 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( - new NullPermissionsChecker(), - ALL_TOKENS.equals(projectLevelAttr) ? null - : projectLevelAttr).toArray(new String[0]); - } else { - return new String[] { "" }; - } - } - - /** - * @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(); - } else { - return typesAttr.split("[" + TOKENS_DELIMITER + "]"); - } - } - - /** - * 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()) { - map.put(key, map.get(key).replace(replaceWhat, replaceTo)); - } - - 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<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) - throw new RuntimeException("Unknown parameter name: " + paramName - + "."); - - 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( - XmlTools.getMapFromNodeAttributes(n), - PROJECT_PARAM, projectId), PROJECT_NAME_PARAM, - getProjectName(portalName, projectId)) }); - } else { - param = (SearchParameter) Class.forName(paramClass).newInstance(); - } - - NodeList nodeList = n.getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - 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); - - Method[] methods = param.getClass().getMethods(); - for (Method method : methods) { - if ("add".equals(method.getName())) { - method.invoke(param, new Object[] { childParam }); - break; - } - } - } - } - - return param; - } - - 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) { - Set<String> parametrized = new HashSet<String>(Arrays.asList(props.getProperty( - "parametrized").split("[,]"))); - - for (String feedName : feedDefs.keySet()) { - Node feedNode = feedDefs.get(feedName); - String templateAttr = XmlTools.getAttributeValue(feedNode, - "template"); - 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"); - - ContentManager cm = ContentManager.getContentManager(idAttr, - prefixAttr); - - // Generating the type of feeds that have been requested. - String[] types = getTypes(typesAttr); - - // Generating the projects for which the feeds have been requested, - // if any. - String[] projects = getProjectsIds(portalName, projectLevelAttr); - - 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"); - vc.put("dateFormat", new SimpleDateFormat( - dateFormat == null ? "MM/dd/yy" : dateFormat)); - vc.put("rssDateFormat", new SimpleDateFormat(RFC_822_DATE)); - vc.put("rdfDateFormat", new RdfDateFormat()); - vc.put("now", Calendar.getInstance().getTime()); - vc.put("baseServerAddress", baseServerAddress); - vc.put("escape", new TextEscaping()); - - for (String project : projects) { - String feedNameReplaced = feedName.replace(PROJECT_PARAM, - project); - - 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 { - Search search = (Search) generateSearchParameter( - searchNode, props, parametrized, - portalName, project); - - org.jboss.shotoku.NodeList list = cm.search(search); - - String searchNameAttr = XmlTools.getAttributeValue( - searchNode, "name"); - if (searchNameAttr == null) - searchNameAttr = "nodes"; - - vc.put(searchNameAttr, list); - } catch (Exception e) { - log.warn("Error generating shotoku feed " - + feedName + ".", e); - continue; - } - } - } - - for (String type : types) { - String template = templateAttr.replace(TYPE_PARAM, type); - - Feed newFeed = FeedFactory.getNewFeed(type); - try { - 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 " - + feedName + ".", e); - continue; - } - } - - // 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))); - } - } - } - - private void generateRemoteFeeds(String portalName, - Map<String, Node> feedDefs) { - for (String feedName : feedDefs.keySet()) { - Node feedNode = feedDefs.get(feedName); - String addressAttr = XmlTools - .getAttributeValue(feedNode, "address"); - 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, - // if any. - String[] projects = getProjectsIds(portalName, projectLevelAttr); - - // For each type, project pair, generating a feed and storing it in - // the feeds map. - for (String project : projects) { - String feedNameReplaced = feedName.replace(PROJECT_PARAM, - project); - - for (String type : types) { - String address = addressAttr.replace(TYPE_PARAM, type) - .replace(PROJECT_PARAM, project); - - try { - Feed newFeed = FeedFactory.getNewFeed(type); - newFeed.generate(new URL(address)); - addFeed(feedNameReplaced, type, newFeed); - } catch (Exception e) { - log.debug("Can't add feeed " + address + " : " + type - + ".", e); - } - } - - // 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))); - } - } - } - - private void generateAggregatedFeeds(String portalName, - 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 = - 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); - NodeList nodes = feedNode.getChildNodes(); - - Set<String> feedRequirements = new HashSet<String>(); - requirements.put(feedName, feedRequirements); - parameters.put(feedName, new String[] { - XmlTools.getAttributeValue(feedNode, "title"), - XmlTools.getAttributeValue(feedNode, "description"), - XmlTools.getAttributeValue(feedNode, "author") }); - feedDisplayNames.put(feedName, XmlTools.getAttributeValue(feedNode, - "display-name")); - - for (int i = 0; i < nodes.getLength(); i++) { - 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); - - for (String project : projects) { - feedRequirements.add(nameAttr.replace(PROJECT_PARAM, - project)); - } - } - } - } - - while (requirements.size() > 0) { - int sizeBefore = requirements.size(); - - for (Iterator<String> iter = requirements.keySet().iterator(); iter - .hasNext();) { - String feedName = iter.next(); - Set<String> feedRequirements = requirements.get(feedName); - String[] feedParameters = parameters.get(feedName); - Set<String> types = null; - - // Checking if the all of this feed's requirements are met - // and if so, of what types it can consist. - boolean allRequirementsMet = true; - for (String requirement : feedRequirements) { - Map<String, Feed> feedTypes = feeds.get(requirement); - - if (feedTypes == null) { - // Missing feed - cannot create the aggregated one. - allRequirementsMet = false; - break; - } - - // Intersecting the types set with the types of the current - // feed. - if (types == null) { - types = new HashSet<String>(); - types.addAll(feedTypes.keySet()); - } else - types.retainAll(feedTypes.keySet()); - } - - if (!allRequirementsMet) - continue; - - // Gathering the feed parts from which the new feed will be - // composed. - for (String type : types) { - List<Feed> requiredFeeds = new ArrayList<Feed>(); - for (String requirement : feedRequirements) { - requiredFeeds.add(feeds.get(requirement).get(type)); - } - - Feed newFeed = FeedFactory.getNewFeed(type); - try { - newFeed.generate(requiredFeeds.toArray(new Feed[0]), - feedParameters[0], feedParameters[1], - feedParameters[2], generateFeedLink(true, - feedName, type)); - } catch (Exception e) { - log.warn("Can't add aggregated feed " + feedName - + " : " + type + ".", e); - } - - addFeed(feedName, type, newFeed); - } - - iter.remove(); - } - - if (sizeBefore == requirements.size()) { - log.warn("Aggregation feed definitions cycle, or demanded " - + "feeds are not defined; unable to create feeds."); - return; - } - } - } - - /** - * 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(); - - context = new DelegateContext(); - for (String feedGroup : feedGroups.keySet()) { - Set<String> feedsInGroup = feedGroups.get(feedGroup); - - if (feedsInGroup.size() > 0) { - DelegateContext groupContext = context.next("groups"); - groupContext.put("name", feedGroup); - - for (String feedName : feedsInGroup) { - Map<String, Feed> feedTypes = feeds.get(feedName); - - if (feedTypes != null) { - DelegateContext feedContext = groupContext - .next("feeds"); - feedContext.put("name", - feedDisplayNames.get(feedName)); - - Set availableTypes = feedTypes.keySet(); - for (String feedType : allFeedTypes) { - DelegateContext typeContext = feedContext - .next("types"); - - if (availableTypes.contains(feedType)) { - typeContext.next("feed"); - typeContext.put("name", feedType); - typeContext.put("link", generateFeedLink(false, - feedName, feedType)); - } - } - } - } - } - } - } - - /** - * 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, - "project-level"); - - String[] projects = getProjectsIds(portalName, projectLevelAttr); - - for (String project : projects) { - feedGroup.add(feedName.replace(PROJECT_PARAM, project)); - } - } - - /** - * 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 { - DOMParser parser = new DOMParser(); - parser.parse(new InputSource(node.getContentInputStream())); - Node root = parser.getDocument().getDocumentElement(); - - Node n; - NodeList nodes = root.getChildNodes(); - - Set<String> feedGroup = new LinkedHashSet<String>(); - feedGroups.put(XmlTools.getAttributeValue(root, "display-name"), - feedGroup); - - for (int i = 0; i < nodes.getLength(); i++) { - n = nodes.item(i); - if (feedDefinitions.get(n.getNodeName()) != null) { - String feedName = XmlTools.getAttributeValue(n, "name"); - addFeedNamesToGroup(portalName, feedGroup, feedName, n); - feedDefinitions.get(n.getNodeName()).put(feedName, n); - } - } - } - - /** - * 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) - return null; - - return feedTypes.get(type); - } - - public DelegateContext getContext() { - return context; - } -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsPortlet.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsPortlet.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsPortlet.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -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.forge.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); - } - -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsServlet.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsServlet.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FeedsServlet.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,73 +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.forge.feeds; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.jboss.forge.common.ForgeHelper; - -public class FeedsServlet extends HttpServlet { - private void invalidRequest(HttpServletResponse response) throws IOException { - response.setContentType("text/html"); - response.getWriter().println("The feed you requested is not available."); - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - String requestURI = request.getRequestURI(); - - // Getting rid of the /war-name/. - requestURI = requestURI.split("[/]", 3)[2]; - - // Getting rid of the possible '/' at the end of the request. - if (requestURI.endsWith("/")) - requestURI = requestURI.substring(0, requestURI.length()-1); - - // Splitting the URI into name and type. - int lastSlash = requestURI.lastIndexOf('/'); - - if (lastSlash == -1) { - invalidRequest(response); - return; - } - - String type = requestURI.substring(lastSlash+1); - String name = requestURI.substring(0, lastSlash); - - Feed feed = FeedsDescriptor.getInstance(ForgeHelper.LABS_PORTAL, - ForgeHelper.getBaseServerAddress(request)).getFeed(name, type); - - if (feed == null) { - invalidRequest(response); - return; - } - - feed.write(response); - } - -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FileBasedFeed.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FileBasedFeed.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/FileBasedFeed.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,120 +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.forge.feeds; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Writer; -import java.net.URL; - -import javax.servlet.http.HttpServletResponse; - -public abstract class FileBasedFeed implements Feed { - private final static int BUF_SIZE = 32768; - - private File file; - - public FileBasedFeed(File file) { - this.file = file; - } - - private void transfer(InputStream is, OutputStream os) throws IOException { - byte[] buffer = new byte[BUF_SIZE]; - int read; - while ((read = is.read(buffer)) != -1) - os.write(buffer, 0, read); - } - - public void generate(URL url) throws IOException { - InputStream is = null; - - try { - is = url.openStream(); - generate(is); - } finally { - if (is != null) { - is.close(); - } - } - } - - public void generate(InputStream is) throws IOException { - OutputStream os = null; - - try { - file.createNewFile(); - os = new BufferedOutputStream(new FileOutputStream(file)); - transfer(is, os); - } finally { - if (os != null) { - os.close(); - } - } - } - - public void write(OutputStream os) throws IOException { - InputStream is = null; - try { - is = new BufferedInputStream(new FileInputStream(file)); - transfer(is, os); - } finally { - if (is != null) { - is.close(); - } - } - } - - public Writer getWriter() throws IOException { - return new FileWriter(file); - } - - protected abstract String getContentType(); - - public void write(HttpServletResponse response) throws IOException { - response.setContentType(getContentType()); - write(response.getOutputStream()); - } - - protected File getFile() { - return file; - } - - public void finalize() { - file.delete(); - } - - public InputStream getInputStream() { - try { - return new FileInputStream(file); - } catch (FileNotFoundException e) { - return null; - } - } -} Deleted: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/InformaBasedFeed.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/InformaBasedFeed.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/InformaBasedFeed.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -1,65 +0,0 @@ -package org.jboss.forge.feeds; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import de.nava.informa.core.ChannelExporterIF; -import de.nava.informa.core.ChannelIF; -import de.nava.informa.core.ItemIF; -import de.nava.informa.core.ParseException; -import de.nava.informa.impl.basic.ChannelBuilder; -import de.nava.informa.parsers.FeedParser; -import de.nava.informa.utils.ItemComparator; - -public abstract class InformaBasedFeed extends FileBasedFeed { - public InformaBasedFeed(File file) { - super(file); - } - - protected abstract ChannelExporterIF getExporter() throws IOException; - - @SuppressWarnings("unchecked") - public void generate(Feed[] feeds, String title, String description, - String author, String link) throws IllegalArgumentException, - IOException { - ChannelBuilder builder = new ChannelBuilder(); - ChannelIF newChannel = builder.createChannel(title); - newChannel.setTitle(title); - newChannel.setDescription(description); - newChannel.setCreator(author); - newChannel.setPublisher(author); - newChannel.setLocation(new URL(link)); - newChannel.setPubDate(Calendar.getInstance().getTime()); - - List<ItemIF> newItems = new ArrayList<ItemIF>(); - - for (Feed feed : feeds) { - ChannelIF childChannel; - try { - childChannel = FeedParser.parse(builder, feed.getInputStream()); - } catch (ParseException e) { - throw new IOException(e.getMessage()); - } - - for (Iterator iter = childChannel.getItems().iterator(); iter.hasNext();) { - ItemIF nextItem = (ItemIF) iter.next(); - nextItem.setCreator(childChannel.getCreator()); - newItems.add(nextItem); - } - } - - Collections.sort(newItems, new ItemComparator(true)); - - for (ItemIF newItem : newItems) { - newChannel.addItem(newItem); - } - - getExporter().write(newChannel); - } -} Added: labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/ProjectVariableResolver.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/ProjectVariableResolver.java 2006-05-25 18:53:02 UTC (rev 4427) +++ labs/jbosslabs/trunk/portal-extensions/forge-feeds/src/java/org/jboss/forge/feeds/ProjectVariableResolver.java 2006-05-25 19:04:01 UTC (rev 4428) @@ -0,0 +1,69 @@ +package org.jboss.forge.feeds; + +import org.w3c.dom.Node; +import org.jboss.shotoku.tools.Tools; +import org.jboss.shotoku.feeds.variables.VariableResolver; +import org.jboss.shotoku.feeds.variables.Substitution; +import org.jboss.forge.common.projects.ProjectsHelper; +import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; + +import java.util.Set; +import java.util.HashSet; + +/** + * @author Adam Warski (ad...@as...) + */ +public class ProjectVariableResolver implements VariableResolver { + public static final String PROJECTS_ID = "default"; + public static final String PROJECT_VARIABLE = "${project}"; + public static final String PROJECT_NAME_VARIABLE = "${project-name}"; + + private String[] projects; + + public ProjectVariableResolver(Node n) { + String projectLevelAttr = Tools.getAttributeValue(n, "project-level"); + + if (projectLevelAttr == null) { + projects = new String[0]; + return; + } + + Set<String> projectIds = new HashSet<String>(); + + if ("*".equals(projectLevelAttr)) { + projectIds = ProjectsHelper.getProjects(org.jboss.forge.feeds.ProjectVariableResolver.PROJECTS_ID).getProjectIds( + new NullPermissionsChecker(), null); + } else { + String[] projectLevels = projectLevelAttr.split("[,]"); + for (String projectLevel : projectLevels) { + projectIds.addAll(ProjectsHelper.getProjects(org.jboss.forge.feeds.ProjectVariableResolver.PROJECTS_ID).getProjectIds( + new NullPermissionsChecker(), projectLevel)); + } + } + + projects = projectIds.toArray(new String[0]); + } + + public void expandSubstitutionsSet(Set<String> variables, Set<Substitution> substitutions) { + if (!variables.remove(org.jboss.forge.feeds.ProjectVariableResolver.PROJECT_VARIABLE)) { + return; + } + + variables.remove(org.jboss.forge.feeds.ProjectVariableResolver.PROJECT_NAME_VARIABLE); + + Set<Substitution> newSubs = new HashSet<Substitution>(); + + for (Substitution s : substitutions) { + for (String projectId : projects) { + Substitution newSub = s.clone(); + newSub.add(org.jboss.forge.feeds.ProjectVariableResolver.PROJECT_VARIABLE, projectId); + newSub.add(org.jboss.forge.feeds.ProjectVariableResolver.PROJECT_NAME_VARIABLE, ProjectsHelper.getProjects(org.jboss.forge.feeds.ProjectVariableResolver.PROJECTS_ID). + getProjectName(projectId)); + newSubs.add(newSub); + } + } + + substi... [truncated message content] |