You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/09/01 01:57:31 UTC
cvs commit: jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test TestFeedFilter.java TestProbeLocator.java
burton 2004/08/31 16:57:31
Added: feedparser/src/java/org/apache/commons/feedparser/locate
BlogService.java BlogServiceDiscovery.java
feedparser/src/java/org/apache/commons/feedparser/test
TestFeedFilter.java TestProbeLocator.java
Log:
patches from Brad Neuberg to perform more advanced probe location... added some cleanup around new feed refs
Revision Changes Path
1.1 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/BlogService.java
Index: BlogService.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.feedparser.locate;
import java.lang.reflect.*;
/**
* Describes what
* @author BradNeuberg
*/
public class BlogService {
public static BlogService UNKNOWN = new BlogService(0);
public static BlogService DIARYLAND = new BlogService(1);
public static BlogService AOL_JOURNAL = new BlogService(2);
public static BlogService PMACHINE = new BlogService(3);
public static BlogService TEXTPATTERN = new BlogService(4);
/* FIXME: We can't detect Manila sites right now. */
public static BlogService MANILA = new BlogService(5);
public static BlogService TYPEPAD = new BlogService(6);
public static BlogService RADIO_USERLAND = new BlogService(7);
public static BlogService LIVEJOURNAL = new BlogService(8);
public static BlogService WORDPRESS = new BlogService(9);
/* FIXME: We can't detect iBlog sites right now. */
public static BlogService IBLOG = new BlogService(10);
public static BlogService XANGA = new BlogService(11);
public static BlogService BLOSXOM = new BlogService(12);
public static BlogService BLOGGER = new BlogService(13);
public static BlogService MOVABLE_TYPE = new BlogService(14);
/** FIXME: No way to detect Expression Engine weblogs right now. */
public static BlogService EXPRESSION_ENGINE = new BlogService(15);
public static BlogService GREYMATTER = new BlogService(16);
/** The type of BlogService this is, such as BlogService.BLOSXOM. */
private int type;
/** A private constructor to help us do type-safe enumeration. Only called
* from within this class.
*/
private BlogService(int type) {
this.type = type;
}
public int getType() {
return type;
}
public String toString() {
// use reflection to get the type string; useful so we don't have to
// maintain a list of types here. Since this is only used for debugging
// purposes its okay to use reflection.
try {
Field fields[] = getClass().getDeclaredFields();
BlogService compareMe = new BlogService(type);
for (int i = 0; i < fields.length; i++) {
// make sure we are dealing with one of our BlogService constants
if (fields[i].getType().equals(this.getClass())) {
// get the value of this field
Object fieldValue = fields[i].get(this);
// see if we are this type
if (fieldValue.equals(compareMe)) {
return fields[i].getName();
}
}
}
return null;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public boolean equals(Object obj) {
if (obj == null || (obj instanceof BlogService) == false) {
return false;
}
BlogService compareMe = (BlogService)obj;
return compareMe.getType() == this.type;
}
public int hashCode() {
return type;
}
}
1.1 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/BlogServiceDiscovery.java
Index: BlogServiceDiscovery.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.feedparser.locate;
import java.util.regex.*;
/**
*
* Determines what blog provider a given URI is using,
* such as whether it is hosted on Blogspot, Radio Userland, etc.
*
* @author <a href="mailto:bkn3@columbia.edu">Brad Neuberg/a>
*/
public class BlogServiceDiscovery {
/** Locates all the generator meta tags
* (i.e. <meta content="generator" content="someGenerator"/>)
*/
private static Pattern metaTagsPattern =
Pattern.compile("<[\\s]*meta[\\w\\s=\"']*name=['\" ]generator[\"' ][\\w\\s=\"']*[^>]*",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
/** A pattern used to discover PMachine blogs. */
private static Pattern pmachinePattern =
Pattern.compile("pmachine", Pattern.CASE_INSENSITIVE);
/** A pattern used to discover Blosxom blogs. */
private static Pattern blosxomPattern =
Pattern.compile("alt=[\"' ]powered by blosxom[\"' ]",
Pattern.CASE_INSENSITIVE);
/** Uses the given resource and content to determine what blog provider
* a given URI is using.
*/
public static BlogService discover( String resource, String content ) {
return discoverService( resource, content );
}
/** Uses the given resource to determine what blog provider
* a given URI is using; useful if you have no content but still want
* to do a best guess of what blog service is being used.
*/
public static BlogService discover( String resource ) {
return discoverService( resource, null );
}
protected static BlogService discoverService( String resource,
String content ) {
resource = resource.toLowerCase();
// check the weblogs in order of their popularity
if (isBlogger(resource, content)) {
return BlogService.BLOGGER;
}
else if (isLiveJournal(resource, content)) {
return BlogService.LIVEJOURNAL;
}
else if (isDiaryLand(resource, content)) {
return BlogService.DIARYLAND;
}
else if (isMovableType(resource, content)) {
return BlogService.MOVABLE_TYPE;
}
else if (isXanga(resource, content)) {
return BlogService.XANGA;
}
else if (isWordPress(resource, content)) {
return BlogService.WORDPRESS;
}
else if (isAOLJournals(resource, content)) {
return BlogService.AOL_JOURNAL;
}
else if (isTypePad(resource, content)) {
return BlogService.TYPEPAD;
}
else if (isPMachine(resource, content)) {
return BlogService.PMACHINE;
}
/* FIXME: No way to detect Expression Engine weblogs right now
else if (isExpressionEngine(resource, content)) {
return BlogService.EXPRESSION_ENGINE;
}*/
else if (isGreyMatter(resource, content)) {
return BlogService.GREYMATTER;
}
/* FIXME: We can't detect iBlog sites
else if (isIBlog(resource, content)) {
return BlogService.IBLOG;
}*/
else if (isBlosxom(resource, content)) {
return BlogService.BLOSXOM;
}
/* FIXME: We can't detect Manila sites.
else if (isManila(resource, content)) {
return BlogService.MANILA;
}*/
else if (isRadioUserland(resource, content)) {
return BlogService.RADIO_USERLAND;
}
else if (isTextPattern(resource, content)) {
return BlogService.TEXTPATTERN;
}
else {
return BlogService.UNKNOWN;
}
}
protected static boolean isBlogger( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "blogspot.com");
if (results == false) {
results = hasGenerator(content, "blogger");
}
return results;
}
protected static boolean isGreyMatter( String resource, String content ) {
boolean results = false;
results = hasGenerator(content, "greymatter");
return results;
}
/*protected static boolean isExpressionEngine( String resource,
String content ) {
boolean results = false;
return results;
} */
protected static boolean isMovableType( String resource, String content ) {
boolean results = false;
results = hasGenerator(content, "movabletype");
return results;
}
protected static boolean isAOLJournals( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "journals.aol.com");
return results;
}
protected static boolean isDiaryLand( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "diaryland.com");
return results;
}
protected static boolean isPMachine( String resource, String content ) {
boolean results = false;
Matcher pmachineMatcher = pmachinePattern.matcher(resource);
results = pmachineMatcher.find();
return results;
}
protected static boolean isTextPattern( String resource, String content ) {
boolean results = false;
results = hasGenerator(content, "textpattern");
return results;
}
/* FIXME: We can't detect Manila sites.
protected static boolean isManila( String resource, String content ) {
boolean results = false;
return results;
}
*/
protected static boolean isTypePad( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "typepad.com");
if (results == false) {
results = hasGenerator(content, "typepad");
}
return results;
}
protected static boolean isRadioUserland( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "radio.userland.com");
if (results == false) {
results = containsDomain(resource, "radio.weblogs.com");
}
return results;
}
protected static boolean isLiveJournal( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "livejournal.com");
return results;
}
protected static boolean isWordPress( String resource, String content ) {
boolean results = false;
results = hasGenerator(content, "wordpress");
return results;
}
/* FIXME: We can't detect iBlog sites.
protected static boolean isIBlog( String resource, String content ) {
boolean results = false;
return results;
}*/
protected static boolean isXanga( String resource, String content ) {
boolean results = false;
results = containsDomain(resource, "xanga.com");
return results;
}
protected static boolean isBlosxom( String resource, String content ) {
boolean results = false;
// This is the only kind of blog that we need to check for a
// 'Powered by Blosxom'. We do this with the alt= value on the
// Powered By image.
// FIXME: This might be fragile, but it is used across all of the
// Blosxom blogs I have looked at so far. Brad Neuberg, bkn3@columbia.edu
Matcher blosxomMatcher = blosxomPattern.matcher(content);
results = blosxomMatcher.find();
return results;
}
/** Determines if the given resource contains the given domain name
* fragment.
*/
protected static boolean containsDomain(String resource, String domain) {
return (resource.indexOf(domain) != -1);
}
/** Determines if the given content was generated by the given generator
* (i.e. this document contains a meta tag with name="generator" and
* content equal to the generatorType).
*/
protected static boolean hasGenerator(String content, String generatorType) {
if (content == null) {
return false;
}
Matcher metaTagsMatcher = metaTagsPattern.matcher(content);
if (metaTagsMatcher.find()) {
String metaTag = metaTagsMatcher.group(0).toLowerCase();
generatorType = generatorType.toLowerCase();
return (metaTag.indexOf(generatorType) != -1);
}
else {
return false;
}
}
}
1.1 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestFeedFilter.java
Index: TestFeedFilter.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.feedparser.test;
import java.applet.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.security.*;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*;
import org.peerfear.newsmonster.tools.*;
import org.peerfear.newsmonster.network.*;
import junit.framework.*;
import org.apache.commons.feedparser.*;
import org.apache.commons.feedparser.impl.*;
import org.apache.commons.feedparser.locate.*;
/**
*
* @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
* @version $Id: TestFeedFilter.java,v 1.1 2004/08/31 23:57:31 burton Exp $
*/
public class TestFeedFilter extends TestCase {
public TestFeedFilter( String name ) throws Exception {
super( name );
}
private void doTest( String resource ) throws Exception {
System.out.println( "resource: " + resource );
URL url = new URL( resource );
PrintStream out = new PrintStream( new ByteArrayOutputStream() );
DebugFeedParserListener listener = new DebugFeedParserListener( out );
FeedParser.parse( listener, url.openStream(), resource );
}
public void test1() throws Exception {
doTest( "file:tests/filter/entity-atom-1.xml" );
doTest( "file:tests/filter/prolog-atom-1.xml" );
doTest( "file:tests/filter/prolog-atom-2.xml" );
doTest( "file:tests/filter/prolog-opml-1.xml" );
}
public static void main( String[] args ) throws Exception {
TestFeedFilter test = new TestFeedFilter( null );
//test.testGetWeblogLinkForResource();
test.test1();
}
}
1.1 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestProbeLocator.java
Index: TestProbeLocator.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.feedparser.test;
import junit.framework.*;
import org.apache.commons.feedparser.*;
import org.apache.commons.feedparser.locate.*;
import java.net.*;
import java.io.*;
/**
*
* @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
* @version $Id: TestProbeLocator.java,v 1.1 2004/08/31 23:57:31 burton Exp $
*/
public class TestProbeLocator extends TestCase {
public TestProbeLocator( String name ) throws Exception {
super( name );
ProbeLocator.AGGRESIVE_PROBING_ENABLED = true;
ProbeLocator.BLOG_SERVICE_PROBING_ENABLED = true;
}
public void testBlogger() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference atomFeed, rssFeed;
// This site should have one Atom feed
resource = "http://edpro.blogspot.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOGGER);
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.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "atom.xml");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "atom.xml");
// This site should have one Atom feed
resource = "http://carolinascl.blogspot.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOGGER);
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.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "atom.xml");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "atom.xml");
// This site should have one Atom feed
resource = "http://azizindia.blogspot.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOGGER);
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.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "atom.xml");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "atom.xml");
// This site has no blogs
resource = "http://davebarry.blogspot.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOGGER);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 0);
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNull(atomFeed);
assertNull(rssFeed);
}
public void testLiveJournal() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have an Atom feed and an RSS feed
resource = "http://www.livejournal.com/community/indiexiankids/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.LIVEJOURNAL);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "data/atom");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "data/rss");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "data/atom");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "data/rss");
// This site should have an Atom feed and an RSS feed
resource = "http://www.livejournal.com/community/ajoyforever/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.LIVEJOURNAL);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "data/atom");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "data/rss");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "data/atom");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "data/rss");
// This site should have an Atom feed and an RSS feed
resource = "http://www.livejournal.com/users/_jb_/12332.html";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.LIVEJOURNAL);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, "http://www.livejournal.com/users/_jb_/data/atom");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, "http://www.livejournal.com/users/_jb_/data/rss");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, "http://www.livejournal.com/users/_jb_/data/atom");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, "http://www.livejournal.com/users/_jb_/data/rss");
}
public void testDiaryLand() throws Exception {
// FIXME: Test this
}
public void testMovableType() throws Exception {
// FIXME: Test this
}
public void testXanga() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
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");
}
public void testWordPress() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have an Atom feed and two RSS feeds
resource = "http://synflood.at/blog/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.WORDPRESS);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 3);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 3);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "wp-atom.php");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "wp-rss2.php");
assertEquals(feeds[2].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[2].title, null);
assertEquals(feeds[2].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[2].resource, resource + "wp-rss.php");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "wp-atom.php");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "wp-rss2.php");
// This site should have an Atom feed and two RSS feeds
resource = "http://holmes.hgen.pitt.edu/~dweeks/wordpress/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.WORDPRESS);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 3);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 3);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "wp-atom.php");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "wp-rss2.php");
assertEquals(feeds[2].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[2].title, null);
assertEquals(feeds[2].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[2].resource, resource + "wp-rss.php");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "wp-atom.php");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "wp-rss2.php");
}
public void testAOLJournal() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have a single RSS feed
resource = "http://journals.aol.com/redhdka/BrandNewDay/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.AOL_JOURNAL);
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, resource + "rss.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://journals.aol.com/redhdka/brandnewday/rss.xml");
// This site should have a single RSS feed
resource = "http://journals.aol.com/goldenchildnc/GCS/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.AOL_JOURNAL);
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, resource + "rss.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://journals.aol.com/goldenchildnc/gcs/rss.xml");
// This site should have a single RSS feed
resource = "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.AOL_JOURNAL);
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, resource + "rss.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://journals.aol.com/mkgninja/melissasmisunderstandingsoflife/rss.xml");
}
public void testTypePad() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site has no feed that we can link probe for (it's in a different
// location then usual)
resource = "http://lynikers.typepad.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.TYPEPAD);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 0);
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
// we get a feed here, because this site correctly uses autodiscovery
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, "http://lynikers.typepad.com/on_buck_lake/atom.xml");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, "http://lynikers.typepad.com/on_buck_lake/index.rdf");
// This site has no feed that we can link probe for (it's in a different
// location then usual)
resource = "http://emmeke.typepad.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.TYPEPAD);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 0);
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
// we get a feed here, because this site correctly uses autodiscovery
assertNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, "http://emmeke.typepad.com/blog/index.rdf");
// This site should have an Atom feed and one RSS feed
resource = "http://www.prettypolitical.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.TYPEPAD);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "atom.xml");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "index.rdf");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "atom.xml");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "index.rdf");
}
public void testGreyMatter() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// No feeds supported
resource = "http://www.chattbike.com/gilligan/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.GREYMATTER);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 0);
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNull(atomFeed);
assertNull(rssFeed);
// No feeds supported
resource = "http://www.electricedge.com/greymatter/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.GREYMATTER);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 0);
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNull(atomFeed);
assertNull(rssFeed);
}
public void testPMachine() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have a single RSS feed
resource = "http://bucsfishingreport.com/pMachine/weblog.php";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.PMACHINE);
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://bucsfishingreport.com/pMachine/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://bucsfishingreport.com/pMachine/index.xml");
// This site should have a single RSS feed
resource = "http://www.simplekindoflife.com/pMachine/weblog.php";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.PMACHINE);
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.simplekindoflife.com/pMachine/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://www.simplekindoflife.com/pMachine/index.xml");
// This site should have a single RSS feed
resource = "http://www.mondfish.net/pmachine/weblog.php";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.PMACHINE);
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.mondfish.net/pmachine/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://www.mondfish.net/pmachine/index.xml");
}
public void testBlosxom() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have a single RSS feed
resource = "http://mikemason.ca/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOSXOM);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
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, resource + "index.rss20");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "index.rss");
/* 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, resource + "index.rss20");
// This site should have a single RSS feed
resource = "http://www.foobargeek.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOSXOM);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
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, resource + "index.rss20");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "index.rss");
/* 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, resource + "index.rss");
// This site should have a single RSS feed
resource = "http://www.pipetree.com/qmacro/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.BLOSXOM);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
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, resource + "index.rss20");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "index.rss");
/* 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);
// gets a different location
assertEquals(rssFeed.resource, "http://www.pipetree.com/qmacro/xml");
}
public void testRadioUserland() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have a single RSS feed
resource = "http://radio.weblogs.com/0131722/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.RADIO_USERLAND);
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, resource + "rss.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, resource + "rss.xml");
// This site should have a single RSS feed
resource = "http://radio.weblogs.com/0131724/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.RADIO_USERLAND);
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, resource + "rss.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, resource + "rss.xml");
// This site should have a single RSS feed
resource = "http://radio.weblogs.com/0131734/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.RADIO_USERLAND);
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, resource + "rss.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, resource + "rss.xml");
}
public void testTextPattern() throws Exception {
FeedList list = null;
String resource = null, content = null;
BlogService blogService = null;
FeedReference feeds[] = null;
FeedReference rssFeed, atomFeed;
// This site should have an Atom feed and one RSS feed
resource = "http://www.digitalmediaminute.com/";
content = getContent(resource);
assertNotNull(content);
blogService = BlogServiceDiscovery.discover(resource, content);
assertEquals(blogService, BlogService.TEXTPATTERN);
list = new FeedList();
ProbeLocator.locate(resource, content, list);
assertEquals(list.size(), 2);
feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]);
assertEquals(feeds.length, 2);
assertEquals(feeds[0].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[0].title, null);
assertEquals(feeds[0].type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(feeds[0].resource, resource + "?atom=1");
assertEquals(feeds[1].method, FeedReference.METHOD_PROBE_DISCOVERY);
assertNull(feeds[1].title, null);
assertEquals(feeds[1].type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(feeds[1].resource, resource + "?rss=1");
/* test through the FeedLocator */
list = FeedLocator.locate(resource);
atomFeed = list.getAdAtomFeed();
rssFeed = list.getAdRSSFeed();
assertNotNull(atomFeed);
assertNotNull(rssFeed);
assertEquals(atomFeed.type, FeedReference.ATOM_MEDIA_TYPE);
assertEquals(atomFeed.resource, resource + "?atom=1");
assertEquals(rssFeed.type, FeedReference.RSS_MEDIA_TYPE);
assertEquals(rssFeed.resource, resource + "?rss=1");
}
/** Grabs all the content for a weblog for testing purposes. */
protected String getContent(String resource) throws Exception {
//FIXME: use the IO package from NewsMonster forfor this.
URL resourceURL = new URL(resource);
URLConnection con = resourceURL.openConnection();
con.connect();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
StringBuffer results = new StringBuffer();
String line = null;
while ( (line = in.readLine()) != null) {
results.append(line);
}
return results.toString();
}
public static void main( String[] args ) throws Exception {
TestProbeLocator test = new TestProbeLocator( null );
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();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org