commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r149089 - in jakarta/commons/sandbox/feedparser/trunk: . src/java/org/apache/commons/feedparser tests/feeds xdocs
Date Sun, 30 Jan 2005 00:51:59 GMT
Author: burton
Date: Sat Jan 29 16:51:57 2005
New Revision: 149089

URL: http://svn.apache.org/viewcvs?view=rev&rev=149089
Log:
support for RSS 2.0 enclosures...
Added:
   jakarta/commons/sandbox/feedparser/trunk/tests/feeds/rss-2.0-enclosure.rss
Modified:
   jakarta/commons/sandbox/feedparser/trunk/TODO
   jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java
   jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java
   jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java
   jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml

Modified: jakarta/commons/sandbox/feedparser/trunk/TODO
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/TODO?view=diff&rev=149089&p1=jakarta/commons/sandbox/feedparser/trunk/TODO&r1=149088&p2=jakarta/commons/sandbox/feedparser/trunk/TODO&r2=149089
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/TODO	(original)
+++ jakarta/commons/sandbox/feedparser/trunk/TODO	Sat Jan 29 16:51:57 2005
@@ -18,6 +18,10 @@
 
 - (DONE) Remove ALL references to newsmonster IO layer.
 
+- (DONE) Support MetaFeedParser.onCreated() for RSS 2.0 /rss/channel/item/pubdate
+
+- (DONE) Implement RSS 2.0 enclosure linkage ... this should be an onLink handler.
+
 - Atom GUIDs and RSS 2.0 GUIDs
 
 - http://www.ietf.org/internet-drafts/draft-ietf-atompub-format-02.txt
@@ -28,15 +32,13 @@
 
      http://diveintomark.org/tests/client/autodiscovery/
 
-- Support Base64 Atom values and the ability to enable them.
+- Support Base64 Atom values and the ability to enable them to be automatically decoded.
     
 - Atom's xml:base is NOT supported right now.  We NEED to support this.
 
 - Do we support multiple content items in Atom?
 
 - We do not support multipart/alternative in the feedparser.
-
-- Implement RSS 2.0 enclosure linkage ... this should be an onLink handler.
 
 - Rework the factory mechanism to support multiple FeedParsers... should be an
   interface.

Modified: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java?view=diff&rev=149089&p1=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java&r1=149088&p2=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java&r2=149089
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java
(original)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/AtomFeedParser.java
Sat Jan 29 16:51:57 2005
@@ -375,28 +375,5 @@
 
     }
 
-    //FIXME: unify this with RSSFeedParser.getChildElementTextByName
-    private static String selectText( String query, Element element ) throws Exception {
-
-        XPath xpath = new XPath( query );
-        xpath.setNamespaceContext( NS.context );
-        
-        //perform onChannel method...  (title, link, description)
-        Element e = (Element)xpath.selectSingleNode( element );
-
-        if ( e == null )
-            return null;
-
-        String result = e.getText();
-
-        //The normalize method of XML SHOULD take care of this but for some
-        //reason it doesnt.
-        if ( result != null )
-            result = result.trim();
-
-        return result;
-
-    }
-
 }
 

Modified: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java?view=diff&rev=149089&p1=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java&r1=149088&p2=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java&r2=149089
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java
(original)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/BaseParser.java
Sat Jan 29 16:51:57 2005
@@ -38,7 +38,7 @@
  * Basic parser support common between RSS, Atom, and FOAF feed impls.
  * 
  * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
- * @version $Id: BaseParser.java,v 1.2 2004/10/18 00:00:09 burton Exp $
+ * @version $Id$
  */
 public class BaseParser {
 
@@ -102,5 +102,57 @@
         return null;
 
     }
-    
+
+    // **** shared code for all parsers *****************************************
+
+    //FIXME: unify this with RSSFeedParser.getChildElementTextByName
+    protected static String selectText( String query, Element element ) throws Exception
{
+
+        XPath xpath = new XPath( query );
+        xpath.setNamespaceContext( NS.context );
+        
+        //perform onChannel method...  (title, link, description)
+        Element e = (Element)xpath.selectSingleNode( element );
+
+        if ( e == null )
+            return null;
+
+        String result = e.getText();
+
+        //The normalize method of XML SHOULD take care of this but for some
+        //reason it doesnt.
+        if ( result != null )
+            result = result.trim();
+
+        return result;
+
+    }
+
+    /**
+     * Regardless of namespace, get the child node text by name or null if it is not found.
+     *
+     * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
+     */
+    protected static String getChildElementTextByName( FeedParserState state,
+                                                    String name ) throws Exception {
+
+        //FIXME: this can be rewritten to use getChild()
+        
+        XPath xpath = new XPath( "descendant::*[local-name() = '" + name + "']" );
+        Object resultNode = xpath.selectSingleNode( state.current );
+
+        String resultText = null;
+
+        if ( resultNode != null )
+            resultText = ((Element)resultNode).getText();
+
+        //The normalize method of XML SHOULD take care of this but for some
+        //reason it doesnt.
+        if ( resultText != null )
+            resultText = resultText.trim();
+
+        return resultText;
+        
+    }
+
 }

Modified: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java?view=diff&rev=149089&p1=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java&r1=149088&p2=jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java&r2=149089
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java
(original)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/RSSFeedParser.java
Sat Jan 29 16:51:57 2005
@@ -36,7 +36,7 @@
  * Handles parsing RSS .
  *
  * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
- * @version $Id: RSSFeedParser.java,v 1.15 2005/01/23 09:49:50 burton Exp $
+ * @version $Id$
  */
 public class RSSFeedParser extends BaseParser {
 
@@ -258,36 +258,39 @@
 
         MetaFeedParser.parse( listener, state );
         TagFeedParser.parse( listener, state );
+
+        doEnclosures( listener, state );
         
         listener.onItemEnd();
         
     }
-    
-    /**
-     * Regardless of namespace, get the child node text by name or null if it is not found.
-     *
-     * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
-     */
-    public static String getChildElementTextByName( FeedParserState state,
-                                                    String name ) throws Exception {
 
-        //FIXME: this can be rewritten to use getChild()
-        
-        XPath xpath = new XPath( "descendant::*[local-name() = '" + name + "']" );
-        Object resultNode = xpath.selectSingleNode( state.current );
+    private static void doEnclosures( FeedParserListener listener,
+                                      FeedParserState state ) throws Exception {
+
+        if ( listener instanceof LinkFeedParserListener == false )
+            return;
 
-        String resultText = null;
+        Element element = state.current.getChild( "enclosure" );
 
-        if ( resultNode != null )
-            resultText = ((Element)resultNode).getText();
+        if ( element == null )
+            return;
 
-        //The normalize method of XML SHOULD take care of this but for some
-        //reason it doesnt.
-        if ( resultText != null )
-            resultText = resultText.trim();
+        LinkFeedParserListener linkFeedParserListener = (LinkFeedParserListener)listener;
 
-        return resultText;
+        String rel = null;
+        String type = element.getAttributeValue( "type" );
+        String href = element.getAttributeValue( "url" );
+        String title = null;
+        long length = Integer.parseInt( element.getAttributeValue( "length" ) );
+
+        linkFeedParserListener.onLink( state,
+                                       rel,
+                                       type,
+                                       href,
+                                       title,
+                                       length );
         
     }
-
+    
 }

Added: jakarta/commons/sandbox/feedparser/trunk/tests/feeds/rss-2.0-enclosure.rss
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/tests/feeds/rss-2.0-enclosure.rss?view=auto&rev=149089
==============================================================================
--- (empty file)
+++ jakarta/commons/sandbox/feedparser/trunk/tests/feeds/rss-2.0-enclosure.rss	Sat Jan 29
16:51:57 2005
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!-- RSS generated by UserLand Frontier v9.0.1 on 10/17/2004; 2:40:35 PM Pacific -->
+<rss version="2.0">
+  <channel>
+	<title>Scripting News</title>
+	<link>http://www.scripting.com/</link>
+	<description>It's even worse than it appears.</description>
+	<language>en-us</language>
+	<copyright>Copyright 1997-2004 Dave Winer</copyright>
+	<pubDate>Sun, 17 Oct 2004 07:00:00 GMT</pubDate>
+	<lastBuildDate>Sun, 17 Oct 2004 21:40:35 GMT</lastBuildDate>
+	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
+	<generator>UserLand Frontier v9.0.1</generator>
+	<managingEditor>dwiner@cyber.law.harvard.edu</managingEditor>
+	<webMaster>dwiner@cyber.law.harvard.edu</webMaster>
+
+	<item>
+	  <description>&lt;a href=&quot;http://static.podcatch.com/manila/gems/un/eps.mp3&quot;&gt;This
is a test&lt;/a&gt;. For the next sixty seconds this station will conduct a test of
the Emergency Podcast System. </description>
+	  <pubDate>Sun, 17 Oct 2004 17:36:38 GMT</pubDate>
+	  <guid>http://archive.scripting.com/2004/10/17#When:10:36:38AM</guid>
+	  <enclosure url="http://static.podcatch.com/manila/gems/un/eps.mp3" length="189455"
type="audio/mpeg" />
+	</item>
+	<item>
+	  <description>&lt;a href=&quot;http://static.podcatch.com/manila/gems/un/anotherTestAudioBlogPost.mp3&quot;&gt;I
got another&lt;/a&gt; test blog post. An audio test blog post. Pay no attention to
the man behind the curtain.</description>
+	  <pubDate>Sun, 17 Oct 2004 19:11:14 GMT</pubDate>
+	  <guid>http://archive.scripting.com/2004/10/17#When:12:11:14PM</guid>
+	  <enclosure url="http://static.podcatch.com/manila/gems/un/anotherTestAudioBlogPost.mp3"
length="106423" type="audio/mpeg" />
+	</item>
+  </channel>
+</rss>

Modified: jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml?view=diff&rev=149089&p1=jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml&r1=149088&p2=jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml&r2=149089
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml	(original)
+++ jakarta/commons/sandbox/feedparser/trunk/xdocs/index.xml	Sat Jan 29 16:51:57 2005
@@ -141,6 +141,10 @@
                     Helps enables tags within RSS feeds
                 </dd>
 
+                <dd>
+                    RSS 2.0 enclosures
+                </dd>
+
             </dl>
 
         </section>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message