Author: adamw Date: 2006-06-09 11:30:48 -0400 (Fri, 09 Jun 2006) New Revision: 4691 Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/NormalFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2TagFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/TagTools.java Removed: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagTools.java Modified: labs/shotoku/trunk/project.properties labs/shotoku/trunk/shotoku-feeds/project.xml labs/shotoku/trunk/shotoku-feeds/shotoku-feeds.iml labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/AtomFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/InformaBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RdfFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RomeBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2Feed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/ShotokuTag.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagList.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagListImpl.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/WebsiteTag.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-86 Modified: labs/shotoku/trunk/project.properties =================================================================== --- labs/shotoku/trunk/project.properties 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/project.properties 2006-06-09 15:30:48 UTC (rev 4691) @@ -5,7 +5,7 @@ shotoku.sar.dir=shotoku.sar shotoku.subprojects.cms=base,files,jcr,svn -shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,admin,feeds,portal,file-access,tags +shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,admin,tags,feeds,portal,file-access maven.final.name=${pom.artifactId} @@ -33,3 +33,4 @@ maven.jar.shotoku-base=${shotoku.root.dir}shotoku-base/target/shotoku-base.jar maven.jar.shotoku-svn=${shotoku.root.dir}shotoku-svn/target/shotoku-svn.jar maven.jar.shotoku-aop=${shotoku.root.dir}shotoku-aop/target/shotoku-aop.jar +maven.jar.shotoku-tags=${shotoku.root.dir}shotoku-tags/target/shotoku-tags.jar Modified: labs/shotoku/trunk/shotoku-feeds/project.xml =================================================================== --- labs/shotoku/trunk/shotoku-feeds/project.xml 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/project.xml 2006-06-09 15:30:48 UTC (rev 4691) @@ -25,6 +25,12 @@ <dependency> <groupId>shotoku</groupId> + <artifactId>shotoku-tags</artifactId> + <jar>shotoku-tags.jar</jar> + </dependency> + + <dependency> + <groupId>shotoku</groupId> <artifactId>shotoku-aop</artifactId> <jar>shotoku-aop.jar</jar> </dependency> Modified: labs/shotoku/trunk/shotoku-feeds/shotoku-feeds.iml =================================================================== --- labs/shotoku/trunk/shotoku-feeds/shotoku-feeds.iml 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/shotoku-feeds.iml 2006-06-09 15:30:48 UTC (rev 4691) @@ -17,6 +17,7 @@ <orderEntry type="library" name="commons" level="application" /> <orderEntry type="library" name="velocity" level="application" /> <orderEntry type="library" name="junit" level="application" /> + <orderEntry type="module" module-name="shotoku-tags" /> <orderEntryProperties /> </component> </module> Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -1,56 +0,0 @@ -package org.jboss.shotoku.feeds; - -/** - * @author Adam Warski (ad...@as...) - */ -public class Constants { - /** - * Node with names ending with this string are parsed and - * feed definitons are read from them. - */ - public final static String NODE_ENDING = "-feeds.xml"; - - /* - * Tag names. - */ - public final static String REM_FEED_TAG = "remote-feed"; - public final static String AGG_FEED_TAG = "aggregated-feed"; - public final static String SHO_FEED_TAG = "shotoku-feed"; - - /* - * Property name, under which content manager id and name of the - * directory which contains the configuration file can be found. - */ - public final static String CONFIGDIR = "shotoku.internal.feeds.configdir"; - public final static String CONFIGID = "shotoku.internal.feeds.configcmid"; - - /* - * Property name suffixes, under which content manager id and name - * of the directory which contains the feed files can be found. - */ - public final static String FEEDDIR = ".xml.directory"; - public final static String FEEDID = ".xml.cmid"; - - /** - * Property name suffix, under which information about available - * variables can be found. - */ - public final static String ALL_VARS = ".variables"; - /** - * Property name middle, under which informatin about a concerete - * variable can be found (should be prepended with an id and followed - * by a property name). - */ - public final static String ONE_VAR = ".variable."; - - /** - * Variable, for which feed type will be substituted. - */ - public final static String TYPE_VARIABLE = "${type}"; - - /* - * Xml node attributes denoting a feed name and display name. - */ - public static final String NAME_ATTR = "name"; - public static final String DISP_NAME_ATTR = "display-name"; -} Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -21,10 +21,8 @@ */ package org.jboss.shotoku.feeds; -import org.jboss.shotoku.feeds.data.AtomFeed; -import org.jboss.shotoku.feeds.data.Feed; -import org.jboss.shotoku.feeds.data.RdfFeed; -import org.jboss.shotoku.feeds.data.Rss2Feed; +import org.jboss.shotoku.feeds.data.*; +import org.apache.velocity.VelocityContext; import java.io.File; import java.util.HashMap; @@ -36,50 +34,63 @@ * @author adamw */ public class FeedFactory { - /** - * <code>feedClasses</code> - map feed type -> feed class. - */ - private static Map<String, Class> feedClasses; - private static final 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 name, String displayName, String type) { - Class feedClass = feedClasses.get(type); - if (feedClass == null) return null; - - int nextInt; - synchronized(random) { - nextInt = random.nextInt(); - } - - try { - File file = File.createTempFile("shotoku-feeds" + nextInt, type); - return (Feed) feedClass.getConstructor( + /** + * Map feed type -> feed class. + */ + private static Map<String, Class> feedClasses; + private static Map<String, Class> specialFeedClasses; + private static final Random random; + + static { + feedClasses = new HashMap<String, Class>(); + feedClasses.put("rss2", Rss2Feed.class); + feedClasses.put("atom", AtomFeed.class); + feedClasses.put("rdf", RdfFeed.class); + + specialFeedClasses = new HashMap<String, Class>(); + specialFeedClasses.put("rss2", Rss2TagFeed.class); + + random = new Random(); + } + + /** + * Creates a new instance of a normal 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 NormalFeed getNewNormalFeed(String name, String displayName, String type) { + Class feedClass = feedClasses.get(type); + if (feedClass == null) return null; + + int nextInt; + synchronized(random) { + nextInt = random.nextInt(); + } + + try { + File file = File.createTempFile("shotoku-feeds" + nextInt, type); + return (NormalFeed) feedClass.getConstructor( String.class, String.class, String.class, File.class).newInstance( - name, displayName, type, 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]); - } + name, displayName, type, file); + } catch (Exception e) { + return null; + } + } + + /** + * Creates a new instance of a special 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 Class getNewSpecialFeedClass(String type) { + return specialFeedClasses.get(type); + } + + /** + * 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]); + } } 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-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -24,8 +24,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -33,10 +31,13 @@ import org.apache.xerces.parsers.DOMParser; import org.apache.log4j.Logger; import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.feeds.data.NormalFeed; +import org.jboss.shotoku.feeds.data.SpecialFeed; import org.jboss.shotoku.feeds.data.Feed; import org.jboss.shotoku.feeds.variables.VariableResolverManager; import org.jboss.shotoku.feeds.tag.FeedTagHandler; import org.jboss.shotoku.feeds.tag.FeedTagHandlerManager; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.tools.Pair; import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.aop.CacheItem; @@ -68,13 +69,12 @@ /** * Ready feeds: feed name -> (feed type -> feed). */ - private Map<String, Map<String, Feed>> feeds; + private Map<String, Map<String, NormalFeed>> feeds; /** - * Feed group display name -> set of feed - * names. + * Special feeds: feed name prefix -> (feed type -> feed). */ - private Map<String, Set<String>> feedGroups; + private Map<String, Map<String, SpecialFeed>> specialFeeds; private VariableResolverManager vrm; @@ -113,8 +113,8 @@ feedTagHandlers = new HashMap<String, Map<String, FeedTagHandler>>(); // Creating the maps that will hold the feeds. - feeds = new HashMap<String, Map<String, Feed>>(); - feedGroups = new LinkedHashMap<String, Set<String>>(); + feeds = new HashMap<String, Map<String, NormalFeed>>(); + specialFeeds = new HashMap<String, Map<String, SpecialFeed>>(); // Looking for file containing feed definitons and filling the maps. for (org.jboss.shotoku.Node feedNode : @@ -136,8 +136,6 @@ // Trying to generate any feed found in the feed tag handler map. generateFeed(feedTagHandlers.keySet().iterator().next()); } - - // TODO populate the groups } private void addFeedDefinitions(org.jboss.shotoku.Node node) throws SAXException, IOException { @@ -148,11 +146,6 @@ Node root = parser.getDocument().getDocumentElement(); String group = Tools.getAttributeValue(root, "display-name"); - Set<String> feedGroup = new LinkedHashSet<String>(); - // Each feed descriptor file has one feed group. - // Get the name of the feed group for this file. - feedGroups.put(group, feedGroup); - NodeList nodes = root.getChildNodes(); // Iterate through the rest of the feed descriptor @@ -185,10 +178,10 @@ * @param type * @param feed */ - public void addFeed(String name, String type, Feed feed) { - Map<String, Feed> typesMap = feeds.get(name); + public void addFeed(String name, String type, NormalFeed feed) { + Map<String, NormalFeed> typesMap = feeds.get(name); if (typesMap == null) { - typesMap = new HashMap<String, Feed>(); + typesMap = new HashMap<String, NormalFeed>(); feeds.put(name, typesMap); } @@ -196,6 +189,22 @@ } /** + * Adds a ready special feed of the given name and type. + * @param name + * @param type + * @param feed + */ + public void addSpecialFeed(String name, String type, SpecialFeed feed) { + Map<String, SpecialFeed> typesMap = specialFeeds.get(name); + if (typesMap == null) { + typesMap = new HashMap<String, SpecialFeed>(); + specialFeeds.put(name, typesMap); + } + + typesMap.put(type, feed); + } + + /** * Tries to generate a feed with the given name. If the feed is absent, * or is being already generated (this case indicates a loop in feed * definitions), no actions are taken. @@ -225,19 +234,47 @@ } /** - * Gets a feed of the given type and name. + * Gets a normal feed of the given type and name. * @param name Name of the feed to get. * @param type Type of the feed to get. * @return Feed with the given name and type. */ - public Feed getFeed(String name, String type) { - Map<String, Feed> feedTypes = feeds.get(name); - if (feedTypes == null) + public NormalFeed getNormalFeed(String name, String type) { + Map<String, NormalFeed> feedTypes = feeds.get(name); + if (feedTypes == null) { return null; + } return feedTypes.get(type); } + /** + * Gets a feed (any - special or normal) of the given type and name. + * @param name Name of the feed to get. + * @param type Type of the feed to get. + * @return Feed with the given name and type. + */ + public Feed getFeed(String name, String type) { + Feed ret = getNormalFeed(name, type); + if (ret == null) { + // Checking for a special feed. + for (String feedNamePrefix : specialFeeds.keySet()) { + if (name.startsWith(feedNamePrefix)) { + SpecialFeed unconcreteFeed = specialFeeds.get(feedNamePrefix).get(type); + if (unconcreteFeed != null) { + return unconcreteFeed.concretizeFeed(name); + } else { + return null; + } + } + } + + return null; + } + + return ret; + } + public String getBaseServerAddress() { return baseServerAddress; } @@ -250,8 +287,8 @@ * Releases all feeds - deletes temporary files which contain them. */ public void release() { - for (Map<String, Feed> feedTypes : feeds.values()) { - for (Feed feed : feedTypes.values()) { + for (Map<String, NormalFeed> feedTypes : feeds.values()) { + for (NormalFeed feed : feedTypes.values()) { feed.release(); } } Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -38,13 +38,13 @@ } private static String makeAddress(String scheme, String server, int port) { - return scheme + "://" + server + ":" + port; - } + return scheme + "://" + server + ":" + port; + } - public static String getBaseServerAddress(ServletRequest request) { - return makeAddress(request.getScheme(), request.getServerName(), - request.getServerPort()); - } + public static String getBaseServerAddress(ServletRequest request) { + return makeAddress(request.getScheme(), request.getServerName(), + request.getServerPort()); + } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/AtomFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/AtomFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/AtomFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -25,19 +25,20 @@ import java.io.IOException; import com.sun.syndication.feed.synd.SyndFeed; +import org.jboss.shotoku.feeds.tools.Constants; public class AtomFeed extends RomeBasedFeed { - public AtomFeed(String name, String displayName, String type, File file) throws IOException { + public AtomFeed(String name, String displayName, String type, File file) throws IOException { super(name, displayName, type, file); } - @Override - protected void setFeedType(SyndFeed feed) { - feed.setFeedType("atom_0.3"); - } + @Override + protected void setFeedType(SyndFeed feed) { + feed.setFeedType("atom_0.3"); + } - @Override - protected String getContentType() { - return "application/atom+xml"; - } + @Override + protected String getContentType() { + return Constants.ATOM_CONTENT_TYPE; + } } Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,42 @@ +package org.jboss.shotoku.feeds.data; + +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; +import java.io.IOException; + +/** + * @author Adam Warski (ad...@as...) + */ +public class ConcreteTagFeed implements Feed { + private TagFeed tagFeed; + private String fullName; + + public ConcreteTagFeed(TagFeed tagFeed, String fullName) { + this.tagFeed = tagFeed; + this.fullName = fullName; + } + + public void write(OutputStream os) throws IOException { + tagFeed.write(os, fullName); + } + + public void write(HttpServletResponse response) throws IOException { + tagFeed.write(response, fullName); + } + + public String getName() { + return tagFeed.getName(); + } + + public String getDisplayName() { + return tagFeed.getDisplayName(); + } + + public String getType() { + return tagFeed.getType(); + } + + public void release() { + tagFeed.release(); + } +} Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -1,99 +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.data; - -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(); - /** - * Gets the name of this feed. - * @return Name of this feed. - */ - public String getName(); - /** - * Gets the display name of this feed. - * @return Display name of this feed. - */ - public String getDisplayName(); - /** - * Gets the type of this feed. - * @return Type of this feed. - */ - public String getType(); - /** - * Called when this feed is no longer needed, so that any resources can - * be released (like temporary files). - */ - public void release(); -} Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,45 @@ +package org.jboss.shotoku.feeds.data; + +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; +import java.io.IOException; + +/** + * A base interface for feeds. + * @author Adam Warski (ad...@as...) + */ +public interface Feed { + /** + * Writes the feed data to the given output stream. + * @param os Output stream to write to. + * @throws java.io.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; + /** + * Gets the name of this feed. + * @return Name of this feed. + */ + public String getName(); + /** + * Gets the display name of this feed. + * @return Display name of this feed. + */ + public String getDisplayName(); + /** + * Gets the type of this feed. + * @return Type of this feed. + */ + public String getType(); + /** + * Called when this feed is no longer needed, so that any resources can + * be released (like temporary files). + */ + public void release(); +} Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse; -public abstract class FileBasedFeed implements Feed { +public abstract class FileBasedFeed implements NormalFeed { private File file; private String name; private String displayName; Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/InformaBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/InformaBasedFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/InformaBasedFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -12,7 +12,7 @@ import de.nava.informa.impl.basic.ChannelBuilder; import de.nava.informa.parsers.FeedParser; import de.nava.informa.utils.ItemComparator; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.data.NormalFeed; public abstract class InformaBasedFeed extends FileBasedFeed { public InformaBasedFeed(String name, String displayName, String type, File file) { @@ -22,7 +22,7 @@ protected abstract ChannelExporterIF getExporter() throws IOException; @SuppressWarnings("unchecked") - public void generate(Feed[] feeds, String title, String description, + public void generate(NormalFeed[] feeds, String title, String description, String author, String link) throws IllegalArgumentException, IOException { ChannelBuilder builder = new ChannelBuilder(); @@ -37,7 +37,7 @@ long pubDate = 0; - for (Feed feed : feeds) { + for (NormalFeed feed : feeds) { ChannelIF childChannel; try { childChannel = FeedParser.parse(builder, feed.getInputStream()); Copied: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/NormalFeed.java (from rev 4655, labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java) =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-06-07 21:28:18 UTC (rev 4655) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/NormalFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,66 @@ +/* + * 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.data; + +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 normal data feeds. + * @author adamw + */ +public interface NormalFeed extends Feed { + /** + * 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(NormalFeed[] 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(); +} Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RdfFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RdfFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RdfFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -26,18 +26,19 @@ import de.nava.informa.core.ChannelExporterIF; import de.nava.informa.exporters.RSS_1_0_Exporter; +import org.jboss.shotoku.feeds.tools.Constants; public class RdfFeed extends InformaBasedFeed { - public RdfFeed(String name, String displayName, String type, File file) { + public RdfFeed(String name, String displayName, String type, File file) { super(name, displayName, type, file); } - protected ChannelExporterIF getExporter() throws IOException { - return new RSS_1_0_Exporter(getFile()); - } + protected ChannelExporterIF getExporter() throws IOException { + return new RSS_1_0_Exporter(getFile()); + } - @Override - protected String getContentType() { - return "text/xml"; - } + @Override + protected String getContentType() { + return Constants.RDF_CONTENT_TYPE; + } } Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RomeBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RomeBasedFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/RomeBasedFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -45,7 +45,7 @@ protected abstract void setFeedType(SyndFeed feed); @SuppressWarnings("unchecked") - public void generate(Feed[] feeds, String title, String description, + public void generate(NormalFeed[] feeds, String title, String description, String author, String link) throws IllegalArgumentException, IOException { SyndFeed syndFeed = new SyndFeedImpl(); @@ -62,7 +62,7 @@ long pubDate = 0; - for (Feed feed : feeds) { + for (NormalFeed feed : feeds) { SyndFeedInput input = new SyndFeedInput(); SyndFeed inFeed; try { Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2Feed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2Feed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2Feed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -26,6 +26,7 @@ import com.sun.syndication.feed.synd.SyndFeed; import org.jboss.shotoku.feeds.data.RomeBasedFeed; +import org.jboss.shotoku.feeds.tools.Constants; public class Rss2Feed extends RomeBasedFeed { public Rss2Feed(String name, String displayName, String type, File file) throws IOException { @@ -39,6 +40,6 @@ @Override protected String getContentType() { - return "text/xml"; + return Constants.RSS_CONTENT_TYPE; } } Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2TagFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2TagFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Rss2TagFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,20 @@ +package org.jboss.shotoku.feeds.data; + +import org.jboss.shotoku.feeds.tools.Constants; +import org.apache.velocity.VelocityContext; + +import java.util.Map; + +/** + * @author Adam Warski (ad...@as...) + */ +public class Rss2TagFeed extends TagFeed { + public Rss2TagFeed(String name, String type, + Map<String, String> attributes, VelocityContext vc) { + super(name, type, attributes, vc); + } + + public String getContentType() { + return Constants.RSS_CONTENT_TYPE; + } +} Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,9 @@ +package org.jboss.shotoku.feeds.data; + +/** + * A special feed interface, which has to be concretized, to get a full feed. + * @author Adam Warski (ad...@as...) + */ +public interface SpecialFeed extends Feed { + public Feed concretizeFeed(String fullName); +} Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,166 @@ +package org.jboss.shotoku.feeds.data; + +import org.apache.velocity.VelocityContext; +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.tags.Tag; +import org.jboss.shotoku.tags.tools.TagTools; +import org.jboss.shotoku.tags.tools.Constants; +import org.jboss.shotoku.tags.exceptions.TagGetException; + +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.util.*; +import java.net.URLDecoder; + +/** + * @author Adam Warski (ad...@as...) + */ +public abstract class TagFeed implements SpecialFeed { + private String name; + private String type; + Map<String, String> attributes; + private VelocityContext vcOriginal; + + private int limit; + private int nameLength; + private ContentManager cm; + + public TagFeed(String name, String type, + Map<String, String> attributes, VelocityContext vc) { + this.name = name; + this.type = type; + this.attributes = attributes; + this.vcOriginal = vc; + + nameLength = name.length(); + cm = ContentManager.getContentManager(attributes.get("id"), + attributes.get("prefix")); + try { + limit = Integer.parseInt(attributes.get("limit")); + } catch (NumberFormatException e) { + limit = 0; + } + } + + public Feed concretizeFeed(String fullName) { + return new ConcreteTagFeed(this, fullName); + } + + public abstract String getContentType(); + + public Date getYoungestTagDate(List<Tag> tags) { + long youngest = 0; + + for (Tag tag : tags) { + long dateCreated = tag.getDateCreated().getTime(); + if (dateCreated > youngest) { + youngest = dateCreated; + } + } + + return new Date(youngest); + } + + public void write(OutputStream os, String fullName) throws IOException { + // Computing the type of the feed to generate. + if (fullName.length() < nameLength+1) { + throw new IOException("Invalid tag feed request."); + } + + String info = fullName.substring(nameLength+1); + String[] infoTokens = info.split("[/]", 2); + if (infoTokens.length != 2) { + throw new IOException("Invalid tag feed request."); + } + + VelocityContext vc = new VelocityContext(vcOriginal); + + String infoDataDecoded = infoTokens[1]; + infoDataDecoded = URLDecoder.decode(infoDataDecoded, "UTF-8"); + String template = attributes.get("template"); + + List<Tag> tags; + + if (Constants.TAG_FEED_TYPE_RESOURCE.equals(infoTokens[0])) { + vc.put(Constants.TAG_FEED_TYPE_RESOURCE, infoDataDecoded); + + // Getting the list of tags. + try { + tags = TagTools.getService().getTags(infoDataDecoded).getList(); + } catch (TagGetException e) { + throw new IOException(e.getMessage()); + } + + template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE, + Constants.TAG_FEED_TYPE_RESOURCE); + + } else if (Constants.TAG_FEED_TYPE_AUTHOR.equals(infoTokens[0])) { + try { + tags = TagTools.getService().getTagsByAuthor(infoDataDecoded).getList(); + } catch (TagGetException e) { + throw new IOException(e.getMessage()); + } + + template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE, + Constants.TAG_FEED_TYPE_AUTHOR); + + } else if (Constants.TAG_FEED_TYPE_TAGS.equals(infoTokens[0])) { + try { + tags = TagTools.getService().getTags( + Arrays.asList(infoDataDecoded.split("[+]"))).getList(); + } catch (TagGetException e) { + throw new IOException(e.getMessage()); + } + + template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE, + Constants.TAG_FEED_TYPE_TAGS); + + } else { + throw new IOException("Invalid tag feed request."); + } + + // Computing the date of the youngest tag. + vc.put("youngest", getYoungestTagDate(tags)); + vc.put("tags", tags.subList(0, limit)); + + try { + OutputStreamWriter osw = new OutputStreamWriter(os); + cm.getVelocityEngine().mergeTemplate(template, vc, osw); + osw.flush(); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + public void write(HttpServletResponse response, String fullName) throws IOException { + response.setContentType(getContentType()); + write(response.getOutputStream(), fullName); + } + + public void write(OutputStream os) throws IOException { + throw new IOException("Can't write a non-concrete tag feed"); + } + + public void write(HttpServletResponse response) throws IOException { + throw new IOException("Can't write a non-concrete tag feed"); + } + + public String getName() { + return name; + } + + public String getDisplayName() { + return null; + } + + public String getType() { + return type; + } + + public void release() { + + } +} Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -2,10 +2,10 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.variables.Substitution; import org.jboss.shotoku.tools.Tools; import org.apache.log4j.Logger; @@ -34,7 +34,7 @@ // First, getting (and if need be, generating) the feeds to be // aggregated as written in the tag. - Set<Feed> toAggregate = new HashSet<Feed>(); + Set<NormalFeed> toAggregate = new HashSet<NormalFeed>(); NodeList nodes = definition.getChildNodes(); for (int i=0; i<nodes.getLength(); i++) { Node n = nodes.item(i); @@ -52,7 +52,7 @@ for (Substitution s : substitutions) { String name = s.make(nameAttr); - Feed f = fd.getFeed(name, feedType); + NormalFeed f = fd.getNormalFeed(name, feedType); if (f == null) { // Trying to generate the feed. @@ -63,7 +63,7 @@ } // The feeds have been successfully generated. - f = fd.getFeed(name, feedType); + f = fd.getNormalFeed(name, feedType); } toAggregate.add(f); @@ -76,11 +76,11 @@ return false; } - Feed feed = FeedFactory.getNewFeed(feedName, attributes.get(Constants.DISP_NAME_ATTR), + NormalFeed feed = FeedFactory.getNewNormalFeed(feedName, attributes.get(Constants.DISP_NAME_ATTR), feedType); try { - feed.generate(toAggregate.toArray(new Feed[0]), + feed.generate(toAggregate.toArray(new NormalFeed[0]), attributes.get("title"), attributes.get("description"), attributes.get("author"), generateFeedLink(fd, true, feedName, feedType)); } catch (IOException e) { Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -3,7 +3,7 @@ import org.w3c.dom.Node; import org.jboss.shotoku.feeds.variables.Substitution; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; /** * A base class for classes which handle generation of various feed types, Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -1,7 +1,7 @@ package org.jboss.shotoku.feeds.tag; import org.jboss.shotoku.tools.Tools; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.FeedsDescriptor; import org.jboss.shotoku.feeds.variables.VariableResolverManager; import org.jboss.shotoku.feeds.variables.Substitution; @@ -44,6 +44,7 @@ addHandler(Constants.AGG_FEED_TAG, AggregatedFeedTagHandler.class); addHandler(Constants.REM_FEED_TAG, RemoteFeedTagHandler.class); addHandler(Constants.SHO_FEED_TAG, ShotokuFeedTagHandler.class); + addHandler(Constants.TAG_FEED_TAG, TagFeedTagHandler.class); } /** Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -3,9 +3,9 @@ import org.w3c.dom.Node; import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.feeds.variables.Substitution; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.FeedsDescriptor; import org.apache.log4j.Logger; @@ -31,7 +31,7 @@ Constants.DISP_NAME_ATTR)); try { - Feed feed = FeedFactory.getNewFeed(feedName, displayName, feedType); + NormalFeed feed = FeedFactory.getNewNormalFeed(feedName, displayName, feedType); feed.generate(new URL(address)); fd.addFeed(feedName, feedType, feed); } catch (Exception e) { Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -5,19 +5,17 @@ import org.jboss.shotoku.search.*; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.tools.Tools; -import org.jboss.shotoku.feeds.tools.RdfDateFormat; -import org.jboss.shotoku.feeds.tools.TextEscaping; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.tools.FeedsTools; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.variables.Substitution; import org.apache.velocity.VelocityContext; import org.apache.log4j.Logger; import java.util.*; import java.lang.reflect.Constructor; -import java.text.SimpleDateFormat; import java.io.Writer; /** @@ -109,9 +107,6 @@ return param; } - - private final static String RFC_822_DATE = "EEE, d MMM yyyy HH:mm:ss Z"; - public boolean generate(FeedsDescriptor fd) { Node definition = getDefinition(); Substitution s = getSubstitution(); @@ -129,15 +124,8 @@ // Creating a velocity context with parts that won't change in all // generated feeds. VelocityContext vc = new VelocityContext(attributes); + FeedsTools.prepareVelocityContext(attributes, fd, vc); - 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", fd.getBaseServerAddress()); - vc.put("escape", new TextEscaping()); - NodeList feedNodeChildren = definition.getChildNodes(); for (int i = 0; i < feedNodeChildren.getLength(); i++) { // For each search node, generating and performing the @@ -180,7 +168,7 @@ String feedName = getFeedName(); String feedType = getFeedType(); - Feed newFeed = FeedFactory.getNewFeed(feedName, displayName, feedType); + NormalFeed newFeed = FeedFactory.getNewNormalFeed(feedName, displayName, feedType); try { vc.put("link", generateFeedLink(fd, true, feedName, feedType)); Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,55 @@ +package org.jboss.shotoku.feeds.tag; + +import org.apache.log4j.Logger; +import org.apache.velocity.VelocityContext; +import org.jboss.shotoku.feeds.FeedsDescriptor; +import org.jboss.shotoku.feeds.tools.Constants; +import org.jboss.shotoku.feeds.FeedFactory; +import org.jboss.shotoku.feeds.data.SpecialFeed; +import org.jboss.shotoku.feeds.tools.FeedsTools; +import org.jboss.shotoku.feeds.variables.Substitution; +import org.jboss.shotoku.tools.Tools; +import org.w3c.dom.Node; + +import java.util.Map; + +/** + * @author Adam Warski (ad...@as...) + */ +public class TagFeedTagHandler extends FeedTagHandler { + //private static final Logger log = Logger.getLogger(FeedsDescriptor.class); + + public TagFeedTagHandler(String feedName, String group, Node definition, Substitution s) { + super(feedName, group, definition, s); + } + + public boolean generate(FeedsDescriptor fd) { + Node definition = getDefinition(); + Substitution s = getSubstitution(); + + // Reading all attributes and making the substitution on them. + Map<String, String> attributes = Tools.getMapFromNodeAttributes(definition); + s.make(attributes); + + // Creating a velocity context with parts that won't change in all + // generated feeds. + VelocityContext vc = new VelocityContext(attributes); + FeedsTools.prepareVelocityContext(attributes, fd, vc); + + String feedName = getFeedName(); + String feedType = getFeedType(); + + Class feedClass = FeedFactory.getNewSpecialFeedClass(feedType); + + try { + fd.addSpecialFeed(feedName, feedType, + (SpecialFeed) feedClass.getConstructor(String.class, + String.class, Map.class, VelocityContext.class).newInstance(feedName, + feedType, attributes, vc)); + } catch (Exception e) { + return false; + } + + return true; + } +} Copied: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java (from rev 4655, labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java) =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java 2006-06-07 21:28:18 UTC (rev 4655) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,69 @@ +package org.jboss.shotoku.feeds.tools; + +/** + * @author Adam Warski (ad...@as...) + */ +public class Constants { + /** + * Node with names ending with this string are parsed and + * feed definitons are read from them. + */ + public final static String NODE_ENDING = "-feeds.xml"; + + /* + * Tag names. + */ + public final static String REM_FEED_TAG = "remote-feed"; + public final static String AGG_FEED_TAG = "aggregated-feed"; + public final static String SHO_FEED_TAG = "shotoku-feed"; + public final static String TAG_FEED_TAG = "tag-feed"; + + /* + * Date format compatible with RFC822. + */ + public final static String RFC_822_DATE = "EEE, d MMM yyyy HH:mm:ss Z"; + + /* + * Content types. + */ + public static final String ATOM_CONTENT_TYPE = "application/atom+xml"; + public static final String RSS_CONTENT_TYPE = "text/xml"; + public static final String RDF_CONTENT_TYPE = "text/xml"; + + /* + * Property name, under which content manager id and name of the + * directory which contains the configuration file can be found. + */ + public final static String CONFIGDIR = "shotoku.internal.feeds.configdir"; + public final static String CONFIGID = "shotoku.internal.feeds.configcmid"; + + /* + * Property name suffixes, under which content manager id and name + * of the directory which contains the feed files can be found. + */ + public final static String FEEDDIR = ".xml.directory"; + public final static String FEEDID = ".xml.cmid"; + + /** + * Property name suffix, under which information about available + * variables can be found. + */ + public final static String ALL_VARS = ".variables"; + /** + * Property name middle, under which informatin about a concerete + * variable can be found (should be prepended with an id and followed + * by a property name). + */ + public final static String ONE_VAR = ".variable."; + + /** + * Variable, for which feed type will be substituted. + */ + public final static String TYPE_VARIABLE = "${type}"; + + /* + * Xml node attributes denoting a feed name and display name. + */ + public static final String NAME_ATTR = "name"; + public static final String DISP_NAME_ATTR = "display-name"; +} Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -0,0 +1,24 @@ +package org.jboss.shotoku.feeds.tools; + +import org.apache.velocity.VelocityContext; +import org.jboss.shotoku.feeds.FeedsDescriptor; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Map; + +/** + * @author Adam Warski (ad...@as...) + */ +public class FeedsTools { + public static void prepareVelocityContext(Map<String, String> attributes, + FeedsDescriptor fd, VelocityContext vc) { + String dateFormat = attributes.get("dateFormat"); + vc.put("dateFormat", new SimpleDateFormat(dateFormat == null ? "MM/dd/yy" : dateFormat)); + vc.put("rssDateFormat", new SimpleDateFormat(Constants.RFC_822_DATE)); + vc.put("rdfDateFormat", new RdfDateFormat()); + vc.put("now", Calendar.getInstance().getTime()); + vc.put("baseServerAddress", fd.getBaseServerAddress()); + vc.put("escape", new TextEscaping()); + } +} Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java 2006-06-09 15:30:48 UTC (rev 4691) @@ -1,7 +1,5 @@ package org.jboss.shotoku.feeds.variables; -import org.jboss.shotoku.feeds.Constants; - import java.util.Set; import java.util.HashSet; Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java 2006-06-09 09:55:03 UTC (rev 4690) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java 2006-06-09 15:30:48 UTC (rev 4691) @... [truncated message content] |