commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Neuberg <b...@columbia.edu>
Subject [feedparser] Attaching patch again
Date Fri, 03 Sep 2004 23:32:48 GMT
It looks like attachments are stripped out of the mailing list; here is the 
patch in unified diff format:

? compile
? feedparser.patch
? lib
Index: src/java/org/apache/commons/feedparser/locate/ProbeLocator.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/ProbeLocator.java,v
retrieving revision 1.10
diff -u -B -r1.10 ProbeLocator.java
--- src/java/org/apache/commons/feedparser/locate/ProbeLocator.java     2 
Sep 2004 00:36:25 -0000       1.10
+++ src/java/org/apache/commons/feedparser/locate/ProbeLocator.java     3 
Sep 2004 23:27:52 -0000
@@ -69,7 +69,7 @@
      /**
       * A regex to find any trailing filename and strip it
       */
-    private static Pattern patternToStrip = Pattern.compile("/\\w*\\.\\w*$");
+    private static Pattern patternToStrip = 
Pattern.compile("[^/](/\\w*\\.\\w*$)");

      /**
       * A regex to extract the user from a Xanga URL
@@ -143,7 +143,8 @@
                new FeedReference("index.rss", FeedReference.RSS_MEDIA_TYPE),
                new FeedReference("rss.xml", FeedReference.RSS_MEDIA_TYPE),
                new FeedReference("index.rdf", FeedReference.RSS_MEDIA_TYPE),
-              new FeedReference("index.xml", FeedReference.XML_MEDIA_TYPE) };
+              new FeedReference("index.xml", FeedReference.RSS_MEDIA_TYPE),
+              new FeedReference("xml/rss.xml", 
FeedReference.RSS_MEDIA_TYPE) };

          probeMapping.put( BlogService.BLOSXOM,        blosxomLocations );

@@ -192,6 +193,7 @@

                  mapping = (FeedReference[])probeMapping.get( blogService );
                  log.info( "mapping = " + mapping );
+                log.info( "baseFeedPath = " + baseFeedPath );

                  // try out each mapping
                  for (int i = 0; i < mapping.length; i++) {
@@ -285,7 +287,9 @@
       *  and gets the path necessary to build up a feed, such as
       *  "http://www.codinginparadise.org/".  Basicly it appends a slash 
to the end if there
       *  is not one, and removes any file names that might be at the end, 
such as
-     *  "myweblog.php".  The one special exception is for some Blosxom blogs,
+     *  "myweblog.php".
+     *
+     *  There is a special exception for some Blosxom blogs,
       *  which have things inside of a cgi-script and 'hang' their RSS files
       *  off of this cgi-bin.  For example,
       *  http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi has its RSS file
@@ -301,20 +305,22 @@
          throws MalformedURLException {

          // strip off any query string or anchors
-        int startStripAt = resource.indexOf("#");
-
-        if ( startStripAt == -1 ) {
-               startStripAt = resource.indexOf("?");
-        }
-        if (startStripAt != -1) {
-            resource = resource.substring(0, startStripAt);
+        if ( resource.indexOf("#") != -1 ) {
+            resource = resource.substring( 0, resource.indexOf("#") );
+        }
+        else if ( resource.indexOf("?") != -1 ) {
+            resource = resource.substring( 0, resource.indexOf("?") );
          }

          if (!resource.endsWith("blosxom.cgi")) {
              Matcher fileMatcher = patternToStrip.matcher(resource);
-            resource = fileMatcher.replaceAll("");
+            if (fileMatcher.find()) {
+                String stringToStrip = fileMatcher.group(1);
+                int startStrip = resource.indexOf(stringToStrip);
+                resource = resource.substring(0, startStrip);
+            }
          }
-
+
          if ( !resource.endsWith( "/" ) ) {
              resource = resource + "/";
          }
@@ -329,13 +335,8 @@
       *  @author Brad Neuberg, bkn3@columbia.edu
       */
      protected static boolean feedExists(String resource) throws Exception {
-
-        log.info( "Inside feedExists, resource = "+resource );
-
          ResourceRequest request = 
ResourceRequestFactory.getResourceRequest( resource );

-        log.info( "request = "+request );
-
          request.setRequestMethod( "HEAD" );
          request.setFollowRedirects( false );

@@ -343,7 +344,7 @@
          request.getContentLength();

          long response = request.getResponseCode();
-        log.info( "response = " + response );
+
          return response == 200;
      }

Index: src/java/org/apache/commons/feedparser/test/TestProbeLocator.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestProbeLocator.java,v
retrieving revision 1.2
diff -u -B -r1.2 TestProbeLocator.java
--- src/java/org/apache/commons/feedparser/test/TestProbeLocator.java   2 
Sep 2004 00:36:25 -0000       1.2
+++ src/java/org/apache/commons/feedparser/test/TestProbeLocator.java   3 
Sep 2004 23:27:53 -0000
@@ -249,81 +249,8 @@
          FeedReference feeds[] = null;
          FeedReference rssFeed, atomFeed;

-//         // This site should have an RSS feed
-//         resource = "http://www.xanga.com/home.aspx?user=lithium98";
-//         content = getContent(resource);
-//         assertNotNull(content);
-//         blogService = BlogServiceDiscovery.discover(resource, content);
-//         assertEquals(blogService, BlogService.XANGA);
-//         list = new FeedList();
-//         ProbeLocator.locate(resource, content, list);
-//         assertEquals(list.size(), 1);
-//         feeds = (FeedReference[])list.toArray(new 
FeedReference[list.size()]);
-//         assertEquals(feeds.length, 1);
-//         assertEquals(feeds[0].method, 
FeedReference.METHOD_PROBE_DISCOVERY);
-//         assertNull(feeds[0].title, null);
-//         assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=lithium98");
-//         /* test through the FeedLocator */
-//         list = FeedLocator.locate(resource);
-//         atomFeed = list.getAdAtomFeed();
-//         rssFeed = list.getAdRSSFeed();
-//         assertNull(atomFeed);
-//         assertNotNull(rssFeed);
-//         assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=lithium98");
-
-//         //  This site should have an RSS feed
-//         resource = "http://www.xanga.com/home.aspx?user=ChUnSA_86";
-//         content = getContent(resource);
-//         assertNotNull(content);
-//         blogService = BlogServiceDiscovery.discover(resource, content);
-//         assertEquals(blogService, BlogService.XANGA);
-//         list = new FeedList();
-//         ProbeLocator.locate(resource, content, list);
-//         assertEquals(list.size(), 1);
-//         feeds = (FeedReference[])list.toArray(new 
FeedReference[list.size()]);
-//         assertEquals(feeds.length, 1);
-//         assertEquals(feeds[0].method, 
FeedReference.METHOD_PROBE_DISCOVERY);
-//         assertNull(feeds[0].title, null);
-//         assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=ChUnSA_86");
-//         /* test through the FeedLocator */
-//         list = FeedLocator.locate(resource);
-//         atomFeed = list.getAdAtomFeed();
-//         rssFeed = list.getAdRSSFeed();
-//         assertNull(atomFeed);
-//         assertNotNull(rssFeed);
-//         assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=ChUnSA_86");
-
-//         //  This site should have an RSS feed
-//         resource = "http://www.xanga.com/home.aspx?user=wdfphillz";
-//         content = getContent(resource);
-//         assertNotNull(content);
-//         blogService = BlogServiceDiscovery.discover(resource, content);
-//         assertEquals(blogService, BlogService.XANGA);
-//         list = new FeedList();
-//         ProbeLocator.locate(resource, content, list);
-//         assertEquals(list.size(), 1);
-//         feeds = (FeedReference[])list.toArray(new 
FeedReference[list.size()]);
-//         assertEquals(feeds.length, 1);
-//         assertEquals(feeds[0].method, 
FeedReference.METHOD_PROBE_DISCOVERY);
-//         assertNull(feeds[0].title, null);
-//         assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=wdfphillz");
-//         /* test through the FeedLocator */
-//         list = FeedLocator.locate(resource);
-//         atomFeed = list.getAdAtomFeed();
-//         rssFeed = list.getAdRSSFeed();
-//         assertNull(atomFeed);
-//         assertNotNull(rssFeed);
-//         assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
-//         assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=wdfphillz");
-
          // This site should have an RSS feed
-
-        resource = "http://xanga.com/home.aspx?user=joe";
+        resource = "http://www.xanga.com/home.aspx?user=lithium98";
          content = getContent(resource);
          assertNotNull(content);
          blogService = BlogServiceDiscovery.discover(resource, content);
@@ -336,7 +263,7 @@
          assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
          assertNull(feeds[0].title, null);
          assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
-        assertEquals(feeds[0].resource, "http://xanga.com/rss.aspx?user=joe");
+        assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=lithium98");
          /* test through the FeedLocator */
          list = FeedLocator.locate(resource);
          atomFeed = list.getAdAtomFeed();
@@ -344,7 +271,82 @@
          assertNull(atomFeed);
          assertNotNull(rssFeed);
          assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
-        assertEquals(rssFeed.resource, "http://xanga.com/rss.aspx?user=joe");
+        assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=lithium98");
+
+        // This site should have an RSS feed
+        resource = "http://www.xanga.com/home.aspx?user=ChUnSA_86";
+        content = getContent(resource);
+        assertNotNull(content);
+        blogService = BlogServiceDiscovery.discover(resource, content);
+        assertEquals(blogService, BlogService.XANGA);
+        list = new FeedList();
+        ProbeLocator.locate(resource, content, list);
+        assertEquals(list.size(), 1);
+        feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
+        assertEquals(feeds.length, 1);
+        assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
+        assertNull(feeds[0].title, null);
+        assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=ChUnSA_86");
+        /* test through the FeedLocator */
+        list = FeedLocator.locate(resource);
+        atomFeed = list.getAdAtomFeed();
+        rssFeed = list.getAdRSSFeed();
+        assertNull(atomFeed);
+        assertNotNull(rssFeed);
+        assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=ChUnSA_86");
+
+        // This site should have an RSS feed
+        resource = "http://www.xanga.com/home.aspx?user=wdfphillz";
+        content = getContent(resource);
+        assertNotNull(content);
+        blogService = BlogServiceDiscovery.discover(resource, content);
+        assertEquals(blogService, BlogService.XANGA);
+        list = new FeedList();
+        ProbeLocator.locate(resource, content, list);
+        assertEquals(list.size(), 1);
+        feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
+        assertEquals(feeds.length, 1);
+        assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
+        assertNull(feeds[0].title, null);
+        assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(feeds[0].resource, 
"http://www.xanga.com/rss.aspx?user=wdfphillz");
+        /* test through the FeedLocator */
+        list = FeedLocator.locate(resource);
+        atomFeed = list.getAdAtomFeed();
+        rssFeed = list.getAdRSSFeed();
+        assertNull(atomFeed);
+        assertNotNull(rssFeed);
+        assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(rssFeed.resource, 
"http://www.xanga.com/rss.aspx?user=wdfphillz");
+
+        // This site should have an RSS feed
+        // FIXME: We should be able to pass this test when we
+        // expand resources inside of the Feed Parser; we don't
+        // currently do this yet, Brad Neuberg, bkn3@columbia.edu
+        /*resource = "http://xanga.com/home.aspx?user=joe";
+        content = getContent(resource);
+        assertNotNull(content);
+        blogService = BlogServiceDiscovery.discover(resource, content);
+        assertEquals(blogService, BlogService.XANGA);
+        list = new FeedList();
+        ProbeLocator.locate(resource, content, list);
+        assertEquals(list.size(), 1);
+        feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
+        assertEquals(feeds.length, 1);
+        assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
+        assertNull(feeds[0].title, null);
+        assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(feeds[0].resource, 
"http://xanga.com/rss.aspx?user=joe");*/
+        /* test through the FeedLocator */
+        /*list = FeedLocator.locate(resource);
+        atomFeed = list.getAdAtomFeed();
+        rssFeed = list.getAdRSSFeed();
+        assertNull(atomFeed);
+        assertNotNull(rssFeed);
+        assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(rssFeed.resource, 
"http://xanga.com/rss.aspx?user=joe");*/
      }

      public FeedList test( String resource,
@@ -375,33 +377,6 @@

      }

-    public static void main( String[] args ) throws Exception {
-
-        TestProbeLocator test = new TestProbeLocator( null );
-
-        test.test( "http://xanga.com/home.aspx?user=joe",
-                   BlogService.XANGA,
-                   1 );
-
-        test.test( "http://www.xanga.com/home.aspx?user=joe",
-                   BlogService.XANGA,
-                   1 );
-
-        /*test.testBlogger();
-        test.testLiveJournal();
-        test.testDiaryLand();
-        test.testMovableType();*/
-        //test.testXanga();
-        /*test.testWordPress();
-        test.testAOLJournal();
-        test.testTypePad();
-        test.testGreyMatter();
-        test.testPMachine();
-        test.testBlosxom();
-        test.testRadioUserland();
-        test.testTextPattern();*/
-    }
-
      public void testWordPress() throws Exception {
          FeedList list = null;
          String resource = null, content = null;
@@ -756,6 +731,30 @@
          assertNotNull(rssFeed);
          assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
          assertEquals(rssFeed.resource, 
"http://www.mondfish.net/pmachine/index.xml");
+
+        // This site should have a single RSS feed
+        resource = "http://bamph.com";
+        content = getContent(resource);
+        assertNotNull(content);
+        blogService = BlogServiceDiscovery.discover(resource, content);
+        assertEquals(blogService, BlogService.UNKNOWN);
+        list = new FeedList();
+        ProbeLocator.locate(resource, content, list);
+        assertEquals(list.size(), 1);
+        feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
+        assertEquals(feeds.length, 1);
+        assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
+        assertNull(feeds[0].title, null);
+        assertEquals(feeds[0].type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(feeds[0].resource, "http://bamph.com/index.xml");
+        /* test through the FeedLocator */
+        list = FeedLocator.locate(resource);
+        atomFeed = list.getAdAtomFeed();
+        rssFeed = list.getAdRSSFeed();
+        assertNull(atomFeed);
+        assertNotNull(rssFeed);
+        assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
+        assertEquals(rssFeed.resource, "http://bamph.com/index.xml");
      }

      public void testBlosxom() throws Exception {
@@ -1002,5 +1001,31 @@
          return results.toString();
      }

+    public static void main( String[] args ) throws Exception {
+
+        TestProbeLocator test = new TestProbeLocator( null );
+
+        /*test.test( "http://xanga.com/home.aspx?user=joe",
+                   BlogService.XANGA,
+                   1 );
+
+        test.test( "http://www.xanga.com/home.aspx?user=joe",
+                   BlogService.XANGA,
+                   1 );*/
+
+        test.testBlogger();
+        test.testLiveJournal();
+        test.testDiaryLand();
+        test.testMovableType();
+        test.testXanga();
+        test.testWordPress();
+        test.testAOLJournal();
+        test.testTypePad();
+        test.testGreyMatter();
+        test.testPMachine();
+        test.testBlosxom();
+        test.testRadioUserland();
+        test.testTextPattern();
+    }
  }



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message