Author: adamw Date: 2006-05-16 19:10:59 -0400 (Tue, 16 May 2006) New Revision: 4257 Added: labs/shotoku/trunk/lib/jboss/activation.jar labs/shotoku/trunk/lib/jboss/javax.servlet.jar labs/shotoku/trunk/lib/jboss/javax.servlet.jsp.jar labs/shotoku/trunk/lib/jboss/jboss-annotations-ejb3.jar labs/shotoku/trunk/lib/jboss/jboss-aop.jar labs/shotoku/trunk/lib/jboss/jboss-common.jar labs/shotoku/trunk/lib/jboss/jboss-ejb3.jar labs/shotoku/trunk/lib/jboss/jboss-ejb3x.jar labs/shotoku/trunk/lib/jboss/jboss-j2ee.jar labs/shotoku/trunk/lib/jboss/jboss-jmx.jar labs/shotoku/trunk/lib/jboss/jboss-system.jar labs/shotoku/trunk/lib/portal/ labs/shotoku/trunk/lib/portal/portal-cms-lib.jar labs/shotoku/trunk/lib/portal/portal-common-lib.jar labs/shotoku/trunk/lib/portal/portal-core-lib.jar labs/shotoku/trunk/lib/taglibs/jstl.jar labs/shotoku/trunk/lib/taglibs/standard.jar labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/cache/ShotokuPropertiesWatcher.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/KeyValue.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsConfigurationWatcher.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ 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/Feed.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/tools/ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/RdfDateFormat.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/TextEscaping.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueMultiVariableResolver.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/NullVariableResolver.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java labs/shotoku/trunk/shotoku-svn/lib/javasvn.jar Removed: labs/shotoku/trunk/lib/jboss/jars/ labs/shotoku/trunk/lib/taglibs/jars/ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/AtomFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Feed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FileBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/InformaBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfDateFormat.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RomeBasedFeed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Rss2Feed.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/TextEscaping.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/TypeVariableResolver.java labs/shotoku/trunk/shotoku-portal/lib/ labs/shotoku/trunk/shotoku-svn/lib/tmate/ Modified: labs/shotoku/trunk/maven.xml labs/shotoku/trunk/project.properties labs/shotoku/trunk/shotoku-base/src/etc/shotoku.properties.sample labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.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/Substitution.java labs/shotoku/trunk/shotoku-feeds/src/web/WEB-INF/web.xml labs/shotoku/trunk/shotoku-portal/project.properties labs/shotoku/trunk/shotoku-svn/maven.xml labs/shotoku/trunk/shotoku-svn/project.properties Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-36 Added: labs/shotoku/trunk/lib/jboss/activation.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/activation.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/javax.servlet.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/javax.servlet.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/javax.servlet.jsp.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/javax.servlet.jsp.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-annotations-ejb3.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-annotations-ejb3.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-aop.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-aop.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-common.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-common.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-ejb3.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-ejb3.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-ejb3x.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-ejb3x.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-j2ee.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-j2ee.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-jmx.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-jmx.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/jboss/jboss-system.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/jboss/jboss-system.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/portal/portal-cms-lib.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/portal/portal-cms-lib.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/portal/portal-common-lib.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/portal/portal-common-lib.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/portal/portal-core-lib.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/portal/portal-core-lib.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/taglibs/jstl.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/taglibs/jstl.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: labs/shotoku/trunk/lib/taglibs/standard.jar =================================================================== (Binary files differ) Property changes on: labs/shotoku/trunk/lib/taglibs/standard.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: labs/shotoku/trunk/maven.xml =================================================================== --- labs/shotoku/trunk/maven.xml 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/maven.xml 2006-05-16 23:10:59 UTC (rev 4257) @@ -60,7 +60,7 @@ </ant:fileset> </ant:copy> - <!-- Copying the ear to the deploy directory. --> + <!-- Copying the sar to the deploy directory. --> <ant:copy todir="${local.deploy.dir}"> <ant:fileset dir="target" flatten="true" overwrite="true"> <ant:filename name="${shotoku.sar.dir}/**" /> Modified: labs/shotoku/trunk/project.properties =================================================================== --- labs/shotoku/trunk/project.properties 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/project.properties 2006-05-16 23:10:59 UTC (rev 4257) @@ -11,21 +11,25 @@ maven.jar.override=on -maven.jar.activation=${shotoku.root.dir}lib/jboss/jars/activation.jar -maven.jar.javax.servlet=${shotoku.root.dir}lib/jboss/jars/javax.servlet.jar -maven.jar.javax.servlet.jsp=${shotoku.root.dir}lib/jboss/jars/javax.servlet.jsp.jar -maven.jar.jboss-aop=${shotoku.root.dir}lib/jboss/jars/jboss-aop.jar -maven.jar.jboss-annotations-ejb3=${shotoku.root.dir}lib/jboss/jars/jboss-annotations-ejb3.jar -maven.jar.jboss-ejb3=${shotoku.root.dir}lib/jboss/jars/jboss-ejb3.jar -maven.jar.jboss-ejb3x=${shotoku.root.dir}lib/jboss/jars/jboss-ejb3x.jar -maven.jar.jboss-j2ee=${shotoku.root.dir}lib/jboss/jars/jboss-j2ee.jar -maven.jar.jboss-jmx=${shotoku.root.dir}lib/jboss/jars/jboss-jmx.jar -maven.jar.jboss-system=${shotoku.root.dir}lib/jboss/jars/jboss-system.jar -maven.jar.jboss-common=${shotoku.root.dir}lib/jboss/jars/jboss-common.jar +maven.jar.activation=${shotoku.root.dir}lib/jboss/activation.jar +maven.jar.javax.servlet=${shotoku.root.dir}lib/jboss/javax.servlet.jar +maven.jar.javax.servlet.jsp=${shotoku.root.dir}lib/jboss/javax.servlet.jsp.jar +maven.jar.jboss-aop=${shotoku.root.dir}lib/jboss/jboss-aop.jar +maven.jar.jboss-annotations-ejb3=${shotoku.root.dir}lib/jboss/jboss-annotations-ejb3.jar +maven.jar.jboss-ejb3=${shotoku.root.dir}lib/jboss/jboss-ejb3.jar +maven.jar.jboss-ejb3x=${shotoku.root.dir}lib/jboss/jboss-ejb3x.jar +maven.jar.jboss-j2ee=${shotoku.root.dir}lib/jboss/jboss-j2ee.jar +maven.jar.jboss-jmx=${shotoku.root.dir}lib/jboss/jboss-jmx.jar +maven.jar.jboss-system=${shotoku.root.dir}lib/jboss/jboss-system.jar +maven.jar.jboss-common=${shotoku.root.dir}lib/jboss/jboss-common.jar -maven.jar.standard=${shotoku.root.dir}lib/taglibs/jars/standard.jar -maven.jar.jstl=${shotoku.root.dir}lib/taglibs/jars/jstl.jar +maven.jar.standard=${shotoku.root.dir}lib/taglibs/standard.jar +maven.jar.jstl=${shotoku.root.dir}lib/taglibs/jstl.jar +maven.jar.portal-cms=${shotoku.root.dir}lib/portal/portal-cms-lib.jar +maven.jar.portal-core=${shotoku.root.dir}lib/portal/portal-core-lib.jar +maven.jar.portal-common=${shotoku.root.dir}lib/portal/portal-common-lib.jar + 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 Modified: labs/shotoku/trunk/shotoku-base/src/etc/shotoku.properties.sample =================================================================== --- labs/shotoku/trunk/shotoku-base/src/etc/shotoku.properties.sample 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-base/src/etc/shotoku.properties.sample 2006-05-16 23:10:59 UTC (rev 4257) @@ -24,6 +24,12 @@ shotoku.embedded = false +# Feeds configuration + +# Content manager and directory in which feeds.properties is placed in shotoku +shotoku.internal.feeds.configcmid = +shotoku.internal.feeds.configdir = + # Internal properties (best leave intact) shotoku.transfer.buffer.size = 1024 Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -746,7 +746,7 @@ /** * Gets a property of this content manager, as it is written in the * configuration file (helper method for implementations). Only internal - * properties! (long parameter value). + * properties! (int parameter value). * * @param name * Name of the property to get. Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/cache/ShotokuPropertiesWatcher.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/cache/ShotokuPropertiesWatcher.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/cache/ShotokuPropertiesWatcher.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -0,0 +1,40 @@ +package org.jboss.shotoku.cache; + +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +import java.util.Properties; +import java.util.Map; +import java.io.IOException; + +/** + * @author Adam Warski (ad...@as...) + */ +public abstract class ShotokuPropertiesWatcher<K> extends ShotokuResourceWatcher<K, Properties> { + protected abstract String getConfigFileName(); + + private Properties getProperties(K key) { + try { + Properties ret = new Properties(); + ret.load(getContentManager(key).getNode( + getConfigFileName()).getContentInputStream()); + return ret; + } catch (IOException e) { + e.printStackTrace(); + } catch (ResourceDoesNotExist e) { + // Well ... + e.printStackTrace(); + } + + return null; + } + + public Properties init(K key) { + addWatchedPath(key, getConfigFileName()); + return getProperties(key); + } + + protected void update(K key, Properties currentObject, + Map<String, ChangeType> changes) { + put(key, getProperties(key)); + } +} Added: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/KeyValue.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/KeyValue.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/KeyValue.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -0,0 +1,39 @@ +package org.jboss.shotoku.tools; + +/** + * A pair of objects, but only the first one is considered in the equals() + * and hashCode() methods. + * @param <T1> + * @param <T2> + * @author Adam Warski (ad...@as...) + */ +public class KeyValue<T1, T2> { + private T1 obj1; + private T2 obj2; + + public KeyValue(T1 obj1, T2 obj2) { + this.obj1 = obj1; + this.obj2 = obj2; + } + + public T1 getFirst() { + return obj1; + } + + public T2 getSecond() { + return obj2; + } + + public boolean equals(Object o) { + if (o instanceof KeyValue) { + KeyValue p = (KeyValue) o; + return p.getFirst().equals(obj1); + } + + return false; + } + + public int hashCode() { + return obj1.hashCode(); + } +} Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/AtomFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/AtomFeed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/AtomFeed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -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.shotoku.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/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Feed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Feed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Feed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -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.shotoku.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(); -} 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-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -21,6 +21,11 @@ */ 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 java.io.File; import java.util.HashMap; import java.util.Map; @@ -35,7 +40,7 @@ * <code>feedClasses</code> - map feed type -> feed class. */ private static Map<String, Class> feedClasses; - private static Random random; + private static final Random random; static { feedClasses = new HashMap<String, Class>(); @@ -51,7 +56,7 @@ * @param type Type of feed to create. * @return A new instance of a feed of the given type. */ - public static Feed getNewFeed(String type) { + public static Feed getNewFeed(String name, String displayName, String type) { Class feedClass = feedClasses.get(type); if (feedClass == null) return null; @@ -61,9 +66,10 @@ } try { - File file = File.createTempFile(FeedsDescriptor.FEEDS_FILE_PREFIX + nextInt, type); - return (Feed) feedClass.getConstructor(new Class[] { File.class }). - newInstance(new Object[] { file }); + File file = File.createTempFile("shotoku-feeds" + nextInt, type); + return (Feed) feedClass.getConstructor( + String.class, String.class, String.class, File.class).newInstance( + name, displayName, type, file); } catch (Exception e) { return null; } Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsCache.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -31,6 +31,7 @@ public void update(Pair<String, String> key, FeedsDescriptor currentObject) { put(key, getDesc(key.getFirst(), key.getSecond())); + currentObject.release(); } public FeedsDescriptor init(Pair<String, String> key) { Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsConfigurationWatcher.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsConfigurationWatcher.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsConfigurationWatcher.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -0,0 +1,18 @@ +package org.jboss.shotoku.feeds; + +import org.jboss.shotoku.cache.ShotokuPropertiesWatcher; +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.tools.Pair; + +/** + * @author Adam Warski (ad...@as...) + */ +public class FeedsConfigurationWatcher extends ShotokuPropertiesWatcher<Pair<String, String>> { + protected String getConfigFileName() { + return "feeds.properties"; + } + + protected ContentManager initContentManager(Pair<String, String> key) { + return ContentManager.getContentManager(key.getFirst(), key.getSecond()); + } +} 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-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -25,6 +25,7 @@ import java.io.Writer; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Constructor; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -39,18 +40,28 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.regex.Pattern; +import java.util.regex.Matcher; import org.apache.velocity.VelocityContext; import org.apache.xerces.parsers.DOMParser; import org.jboss.shotoku.tools.XmlTools; import org.jboss.logging.Logger; import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.tools.RdfDateFormat; +import org.jboss.shotoku.feeds.tools.TextEscaping; +import org.jboss.shotoku.feeds.variables.VariableResolver; +import org.jboss.shotoku.feeds.variables.NullVariableResolver; +import org.jboss.shotoku.feeds.variables.Substitution; import org.jboss.shotoku.tools.Pair; +import org.jboss.shotoku.tools.Tools; 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.w3c.dom.NamedNodeMap; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -62,115 +73,160 @@ * @author da...@si... */ public class FeedsDescriptor { - private static final Logger log = Logger.getLogger(FeedsDescriptor.class); +/* +# Shotoku feeds properites - search parameters classes +search.shotoku-feed = org.jboss.shotoku.search.Search - /** - * <code>FEEDS_DIRECTORY</code> - shotoku directory in which feed - * definitions are stored. - */ - protected final static String FEEDS_DIRECTORY = "descriptors"; +search.and = org.jboss.shotoku.search.AndNodeFilter +search.or = org.jboss.shotoku.search.OrNodeFilter +search.property-value = org.jboss.shotoku.search.PropertyValueParameter - /** - * <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"; +search.directory = org.jboss.shotoku.search.DirectoryIncludeParameter +search.history = org.jboss.shotoku.search.HistoryIncludeParameter +search.limit = org.jboss.shotoku.search.LimitParameter +search.property-sort = org.jboss.shotoku.search.PropertySortParameter +search.date-sort = org.jboss.shotoku.search.DateSortParameter - private final static String REM_FEED_TAG = "remote-feed"; +search.search = org.jboss.shotoku.search.Search - private final static String AGG_FEED_TAG = "aggregated-feed"; +search.parametrized = directory,history,limit,property-sort,property-value +*/ - private final static String SHO_FEED_TAG = "shotoku-feed"; + private class FeedDefinition { + FeedDefinition(String group, Node definition) { + this.group = group; + this.definition = definition; + } - private final static String SHOTOKU_CONFIG = "shotoku-config.properties"; + String group; + Node definition; + } - private final static String ALL_TOKENS = "*"; + private static final Logger log = Logger.getLogger(FeedsDescriptor.class); - private final static String TOKENS_DELIMITER = ","; + /** + * Node with names ending with this string are parsed and + * feed definitons are read from them. + */ + private final static String NODE_ENDING = "-feeds.xml"; - private final static String TYPE_PARAM = "${type}"; + /* + * Tag names. + */ + 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 SITE_PARAM = "${site}"; + /* + * Property name, under which content manager id and name of the + * directory which contains the configuration file can be found. + */ + private final static String CONFIGDIR = "shotoku.internal.feeds.configdir"; + private final static String CONFIGID = "shotoku.internal.feeds.configcmid"; - private final static String SITE_NAME_PARAM = "${site-name}"; - - private final static String FEEDS_BASEDIR = "shotoku.feeds.basedir"; + /* + * Property name suffixes, under which content manager id and name + * of the directory which contains the feed files can be found. + */ + private final static String FEEDDIR = ".xml.directory"; + private final static String FEEDID = ".xml.cmid"; - protected final static String FEEDS_FILE_PREFIX = "shotoku-feeds"; + /** + * Property name suffix, under which information about available + * variables can be found. + */ + private 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). + */ + private final static String ONE_VAR = ".variable."; + /** + * Variable, for which feed type will be substituted. + */ + public final static String TYPE_VARIABLE = "${type}"; + @CacheItem private static FeedsCache feedsCache; + @CacheItem + private static FeedsConfigurationWatcher conf; + static synchronized FeedsDescriptor getInstance(String id, String baseServerAddress) { return feedsCache.get(new Pair<String, String>(id, baseServerAddress)); } /** - * <code>feeds</code> - a map of ready feeds: feed name -> (feed type -> - * feed)). + * 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 + * 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; + /** + * Map variable name -> variable resolver class (read from properties). + */ + private Map<String, Class> varResolvers; - /** - * <code>siteDisplayNames</code> - map: site name -> site display name. - */ - private Map<String, String> siteDisplayNames; + private String baseServerAddress; - private DelegateContext context; - - private String baseServerAddress; - public FeedsDescriptor(String id, String baseServerAddress) { this.baseServerAddress = baseServerAddress; - String feedsBaseDir = ContentManager.getProperty(FEEDS_BASEDIR); + Properties props = conf.get(new Pair<String, String>( + ContentManager.getProperty(CONFIGID, ""), + ContentManager.getProperty(CONFIGDIR, "") + )); - if (feedsBaseDir == null) - throw new RuntimeException(FEEDS_BASEDIR+" property missing from "+ - "shotoku.properties. Shotoku Feeds needs"+ - " this to know where to load the feeds "+ - "descriptor files."); + ContentManager cm = ContentManager.getContentManager( + props.getProperty(id + FEEDID), + props.getProperty(id + FEEDDIR) + ); - ContentManager cm = ContentManager.getContentManager(feedsBaseDir+"/" - + FEEDS_DIRECTORY); + // Creating maps of available variable resolver classes + varResolvers = new HashMap<String, Class>(); + for (String variable : props.getProperty(id + ALL_VARS, "").split("[,]")) { + try { + varResolvers.put(variable, + Class.forName(props.getProperty(id + ONE_VAR + variable))); + } catch (ClassNotFoundException e) { + log.error("Variable resolver class " + props.getProperty(id + + ONE_VAR + variable) + " for variable " + variable + + " not found", e); + } + } - // Creating the maps that will hold the feeds. + // 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>(); - siteDisplayNames = 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, FeedDefinition> remoteFeedDefs = new HashMap<String, FeedDefinition>(); + Map<String, FeedDefinition> aggregatedFeedDefs = new HashMap<String, FeedDefinition>(); + Map<String, FeedDefinition> shotokuFeedDefs = new HashMap<String, FeedDefinition>(); - Map<String, Map<String, Node>> allFeedDefs = - new HashMap<String, Map<String, Node>>(); + Map<String, Map<String, FeedDefinition>> allFeedDefs = + new HashMap<String, Map<String, FeedDefinition>>(); 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)) { + for (org.jboss.shotoku.Node feedNode : + cm.getRootDirectory().getNodes().toList()) { + if (feedNode.getName().endsWith(NODE_ENDING)) { try { addFeedDefinitions(allFeedDefs, feedNode); } catch (Exception e) { - // We just don't add the feeds ... but log a warning. - log.warn("Can't add feed definitions.", e); + // We just don't add the feeds ... and log a warning. + log.warn("Can't add feed definitions from node " + + feedNode.getFullName() + ".", e); } } } @@ -178,24 +234,65 @@ // Firstly - the remote feeds. generateRemoteFeeds(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); - } + // Later, shotoku feeds. + generateShotokuFeeds(shotokuFeedDefs, props); - generateShotokuFeeds(shotokuFeedDefs, props); - // After that, we can create the aggregated feeds. generateAggregatedFeeds(aggregatedFeedDefs); - - // Finally, filling the context. - fillContext(); } - /** + /** + * A pattern which matcher variables of the form "${text with numbers}". + */ + private final static Pattern variablesPattern = Pattern.compile( + Pattern.quote("${") + "[a-zA-Z0-9]*" + Pattern.quote("}")); + + /** + * From the given node's attributes, reads all variables (that is, strings + * which match <code>vairablesPattern</code> and adds them to the given + * set. + * @param toFill Set to which found variables should be added. + * @param n Node from which to read the attributes. + */ + private void addVariablesFromNode(Set<String> toFill, Node n) { + NamedNodeMap nnm = n.getAttributes(); + + for (int i=0; i<nnm.getLength(); i++) { + String text = Tools.unmarshallText(nnm.item(i)); + Matcher m = variablesPattern.matcher(text); + + while (m.find()) { + toFill.add(text.substring(m.start(), m.end()+1)); + } + } + } + + private VariableResolver instantiateVariableResolver(String variable, Node n) { + Class varResolverClass = varResolvers.get(variable); + if (varResolverClass == null) { + log.error("Unsupported variable found: " + variable + "."); + return new NullVariableResolver(); + } + + try { + Constructor c = varResolverClass.getConstructor(Node.class); + try { + return (VariableResolver) c.newInstance(n); + } catch (Exception e) { + log.error("Error instatiating variable resolver " + varResolverClass + ".", e); + } + } catch (NoSuchMethodException e) { + try { + return (VariableResolver) varResolverClass.getConstructor().newInstance(); + } catch (Exception e2) { + log.error("Error instatiating variable resolver " + varResolverClass + ".", e2); + } + } + + return new NullVariableResolver(); + } + + /** * Adds a feed of the given name and type. * @param name * @param type @@ -212,38 +309,6 @@ } /** - * Gets an array of ids of Sites - * @return An array of site ids for this shotoku feeds instance. - */ - private String[] getSiteIds() { - if (FeedsHelper.getSiteIds() != null) - return FeedsHelper.getSiteIds(); - else - return new String[] { "" }; - } - - /** - * @param siteId - * @return Name of a site with the given id. - */ - private String getSiteName(String siteId) { - return FeedsHelper.getSiteName(siteId); - } - - /** - * 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 @@ -428,58 +493,49 @@ continue; } } - - // Finally, adding a feed name. We have to replace ${site} - // and ${site-name} in it. - feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( - SITE_PARAM, site).replace(SITE_NAME_PARAM, - getSiteName(site))); } } } - private void generateRemoteFeeds(Map<String, Node> feedDefs) { + private void generateRemoteFeeds(Map<String, FeedDefinition> 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"); + FeedDefinition feedDefinition = feedDefs.get(feedName); + Node feedNode = feedDefinition.definition; - // Generating the type of feeds that have been requested. - String[] types = getTypes(typesAttr); + String addressAttr = XmlTools.getAttributeValue(feedNode, "address"); + String displayNameAttr = XmlTools.getAttributeValue(feedNode, "display-name"); - // Generating the sites for which the feeds have been requested, - // if any. - String[] sites = getSiteIds(); + Set<String> variables = new HashSet<String>(); + // We always have to substitute the type variable. + variables.add(TYPE_VARIABLE); + addVariablesFromNode(variables, feedNode); - // For each type, site pair generating a feed and storing it in - // the feeds map. - for (String siteId : siteIds) { - String feedNameReplaced = feedName.replace(SITE_PARAM, - siteId); + Set<Substitution> substitutions = Substitution.newEmptySubstitionsSet(); - for (String type : types) { - String address = addressAttr.replace(TYPE_PARAM, type) - .replace(SITE_PARAM, siteId); + for (String variable : new HashSet<String>(variables)) { + instantiateVariableResolver(variable, feedNode). + expandSubstitutionsSet(variables, substitutions); + } - try { - Feed newFeed = FeedFactory.getNewFeed(type); - newFeed.generate(new URL(address)); - addFeed(feedNameReplaced, type, newFeed); - } catch (Exception e) { - log.debug("Can't add feed " + address + " : " + type - + ".", e); - } - } + if (variables.size() > 0) { + log.warn("Unresolved variables left: " + variables.toString() + " in feed " + + feedName + "."); + continue; + } - // Adding a feed name. We have to replace ${site} - // and ${site-name} in it. - feedDisplayNames.put(feedNameReplaced, displayNameAttr.replace( - SITE_PARAM, siteId).replace(SITE_NAME_PARAM, - getSiteName(siteId))); - } + for (Substitution s : substitutions) { + String feedNameSub = s.make(feedName); + String feedType = s.getSubstitutionFor(TYPE_VARIABLE); + try { + Feed feed = FeedFactory.getNewFeed(feedNameSub, + s.make(displayNameAttr), feedType); + feed.generate(new URL(s.make(addressAttr))); + addFeed(feedNameSub, feedType, feed); + } catch (Exception e) { + log.debug("Can't add feed " + s.make(addressAttr) + " : " + feedType + + ".", e); + } + } } } @@ -646,24 +702,6 @@ } /** - * 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 sites). - * @param feedGroup - * @param feedName - * @param node - */ - private void addFeedNamesToGroup(Set<String> feedGroup, - String feedName, Node node) { - - String[] siteIds = getSiteIds(); - - for (String siteId : siteIds) { - feedGroup.add(feedName.replace(SITE_PARAM, siteId)); - } - } - - /** * Adds definitions of feeds to the given map, placing child nodes of * the given node in the appropriate map. * @param feedDefinitions A map into which feeds will be added. @@ -671,33 +709,31 @@ * @throws SAXException * @throws IOException */ - private void addFeedDefinitions(Map<String, Map<String, Node>> feedDefinitions, + private void addFeedDefinitions(Map<String, Map<String, FeedDefinition>> feedDefinitions, org.jboss.shotoku.Node node) throws SAXException, IOException { DOMParser parser = new DOMParser(); // Parse the descriptor at the given Shotoku node. parser.parse(new InputSource(node.getContentInputStream())); // Get the XML document element of the feed descriptor file. Node root = parser.getDocument().getDocumentElement(); + String groupName = XmlTools.getAttributeValue(root, "display-name"); - Node n; - NodeList nodes = root.getChildNodes(); - - Set<String> feedGroup = new LinkedHashSet<String>(); + 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(XmlTools.getAttributeValue(root, "display-name"), - feedGroup); + feedGroups.put(groupName, feedGroup); + NodeList nodes = root.getChildNodes(); + // Iterate through the rest of the feed descriptor // file to load all feeds for a given feed group. for (int i = 0; i < nodes.getLength(); i++) { - n = nodes.item(i); + Node n = nodes.item(i); if (feedDefinitions.get(n.getNodeName()) != null) { // Get the name of the feed. String feedName = XmlTools.getAttributeValue(n, "name"); - // Add the feeds in the file to the group. - addFeedNamesToGroup(feedGroup, feedName, n); - feedDefinitions.get(n.getNodeName()).put(feedName, n); + feedDefinitions.get(n.getNodeName()).put(feedName, + new FeedDefinition(groupName, n)); } } } @@ -716,7 +752,10 @@ return feedTypes.get(type); } - public DelegateContext getContext() { - return context; - } + /** + * Releases all feeds - deletes temporary files which contain them. + */ + public void 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-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -29,45 +29,46 @@ import javax.servlet.http.HttpServletResponse; import org.jboss.forge.common.ForgeHelper; +import org.jboss.shotoku.feeds.data.Feed; 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); + private void invalidRequest(HttpServletResponse response) throws IOException { + response.setContentType("text/html"); + response.getWriter().println("The feed you requested is not available."); + } - Feed feed = FeedsDescriptor.getInstance(ForgeHelper.LABS_PORTAL, - ForgeHelper.getBaseServerAddress(request)).getFeed(name, type); - - if (feed == null) { - invalidRequest(response); - return; - } - - feed.write(response); - } + @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/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FileBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FileBasedFeed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FileBasedFeed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -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.shotoku.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/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/InformaBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/InformaBasedFeed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/InformaBasedFeed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -1,65 +0,0 @@ -package org.jboss.shotoku.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 (Object o : childChannel.getItems()) { - ItemIF nextItem = (ItemIF) o; - nextItem.setCreator(childChannel.getCreator()); - newItems.add(nextItem); - } - } - - Collections.sort(newItems, new ItemComparator(true)); - - for (ItemIF newItem : newItems) { - newChannel.addItem(newItem); - } - - getExporter().write(newChannel); - } -} Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfDateFormat.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfDateFormat.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfDateFormat.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -1,23 +0,0 @@ -package org.jboss.shotoku.feeds; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * This is a class that formats dates according to RFC 3399. Standard java date - * formats are insufficient, becuase they format timezones incorrectly, for - * ex. as "-0100", whereas as stated in RFC 3399, Atom 0.3 specification, and - * as accepted by Rome, it should be "-01:00". - * @author Adam Warski (ad...@as...) - */ -public class RdfDateFormat { - private final static String RFC_3339_DATE = "yyyy-MM-dd'T'HH:mm:ss"; - private final static String ZONE = "Z"; - - public String format(Date date) { - String noZoneDate = new SimpleDateFormat(RFC_3339_DATE).format(date); - String zone = new SimpleDateFormat(ZONE).format(date); - - return noZoneDate + zone.substring(0, 3) + ":" + zone.substring(3, 5); - } -} Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfFeed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RdfFeed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -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.shotoku.feeds; - -import java.io.File; -import java.io.IOException; - -import de.nava.informa.core.ChannelExporterIF; -import de.nava.informa.exporters.RSS_1_0_Exporter; - -public class RdfFeed extends InformaBasedFeed { - public RdfFeed(File file) throws IOException { - super(file); - } - - protected ChannelExporterIF getExporter() throws IOException { - return new RSS_1_0_Exporter(getFile()); - } - - @Override - protected String getContentType() { - return "text/xml"; - } -} Deleted: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RomeBasedFeed.java =================================================================== --- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RomeBasedFeed.java 2006-05-16 20:46:01 UTC (rev 4256) +++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/RomeBasedFeed.java 2006-05-16 23:10:59 UTC (rev 4257) @@ -1,103 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.shotoku.feeds; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import j... [truncated message content] |