burton 2004/08/31 14:00:32
Modified: feedparser/src/java/org/apache/commons/feedparser
AtomFeedParser.java FeedParser.java
feedparser/src/java/org/apache/commons/feedparser/impl
DebugFeedParserListener.java
feedparser/src/java/org/apache/commons/feedparser/locate
AnchorParser.java EntityDecoder.java
feedparser/src/java/org/apache/commons/feedparser/test
TestAtom.java TestFeedLocator.java
Added: feedparser/src/java/org/apache/commons/feedparser
ChangesFeedParser.java
feedparser/src/java/org/apache/commons/feedparser/post
MetaWeblogPostAgent.java PostAgent.java
PostEntry.java
Log:
blogger changes.xml support
Revision Changes Path
1.12 +28 -3
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/AtomFeedParser.java
Index: AtomFeedParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/AtomFeedParser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AtomFeedParser.java 18 Aug 2004 18:39:10 -0000 1.11
+++ AtomFeedParser.java 31 Aug 2004 21:00:32 -0000 1.12
@@ -35,6 +35,10 @@
/**
* http://www.mnot.net/drafts/draft-nottingham-atom-format-02.html
*
+ * http://www.ietf.org/html.charters/atompub-charter.html
+ *
+ * http://www.ietf.org/internet-drafts/draft-ietf-atompub-format-01.txt
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton (burtonator)</a>
* @version $Id$
*/
@@ -80,6 +84,7 @@
String link = selectSingleAttribute( "/atom:feed/atom:[EMAIL
PROTECTED]'alternate'[EMAIL PROTECTED]'text/html']/@href", root );
//String description = selectText( "/atom:feed/atom:[EMAIL
PROTECTED]'text/plain']", doc );
+
String tagline = selectText( "/atom:feed/atom:tagline", root );
//state.current = title;
@@ -121,14 +126,34 @@
// atom:entry elements MAY contain additional atom:link elements
// beyond those described above.
- String link = selectSingleAttribute( "atom:[EMAIL
PROTECTED]'alternate'[EMAIL PROTECTED]'text/html']/@href", child );
+ String link = selectSingleAttribute( "atom:[EMAIL
PROTECTED]'alternate'[EMAIL PROTECTED]'text/html']/@href",
+ child );
// The "atom:summary" element is a Content construct that conveys a
// short summary, abstract or excerpt of the entry. atom:entry
// elements MAY contain an atom:created element, but MUST NOT
// contain more than one.
+
+ //FIXME: what if there is no type attribute specified? Whats the
default?
+
+ // Content constructs MAY have a "type" attribute, whose value
+ // indicates the media type of the content. When present, this
+ // attribute's value MUST be a media type [RFC2045]. If this
+ // attribute is not present, processors MUST behave as if it were
+ // present with a value of "text/ plain".
+
+ String description = null;
+
+ Element summary = child.getChild( "summary", NS.ATOM );
+
+ if ( summary != null ) {
+
+ String type = summary.getAttributeValue( "type", NS.ATOM );
+
+ if ( type == null || "text/plain".equals( type ) )
+ description = summary.getText();
- String description = selectText( "atom:[EMAIL PROTECTED]'text/plain']",
child );
+ }
state.current = child;
1.9 +11 -4
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FeedParser.java
Index: FeedParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/FeedParser.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FeedParser.java 27 Aug 2004 18:07:01 -0000 1.8
+++ FeedParser.java 31 Aug 2004 21:00:32 -0000 1.9
@@ -118,14 +118,21 @@
try {
+ String root = doc.getRootElement().getName();
+
//Handle OPML
- if ( "opml".equals( doc.getRootElement().getName() ) ) {
+ if ( "opml".equals( root ) ) {
OPMLFeedParser.parse( listener, doc );
return;
}
-
+
+ if ( "weblogUpdates".equals( root ) ) {
+ ChangesFeedParser.parse( listener, doc );
+ return;
+ }
+
//Handle ATOM
- if ( "feed".equals( doc.getRootElement().getName() ) ) {
+ if ( "feed".equals( root ) ) {
AtomFeedParser.parse( listener, doc );
return;
}
1.1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/ChangesFeedParser.java
Index: ChangesFeedParser.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;
import java.io.*;
import java.net.*;
import java.util.*;
import org.jdom.Element;
import org.jdom.Attribute;
import org.jdom.CDATA;
import org.jdom.Text;
import org.jdom.Comment;
import org.jdom.output.*;
import org.jdom.input.*;
import org.jaxen.jdom.*;
/**
* Handles parsing Blogger.com changes.xml files.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton (burtonator)</a>
* @version $Id: ChangesFeedParser.java,v 1.1 2004/08/31 21:00:32 burton Exp $
*/
public class ChangesFeedParser {
/**
* Parse this feed.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
*/
public static void parse( FeedParserListener listener,
org.jdom.Document doc ) throws FeedParserException {
try {
FeedParserState state = new FeedParserState();
//will result in an incorrect interface if the caller isn't using the
//system correctly.
listener.init();
FeedDirectoryParserListener fdpl = (FeedDirectoryParserListener)listener;
//this should be the root directory.
XPath xpath = new XPath( "/weblogUpdates/weblog" );
List list = xpath.selectNodes( doc );
Iterator i = list.iterator();
while ( i.hasNext() ) {
Element child = (Element)i.next();
onWeblog( fdpl, state, child );
}
listener.finished();
} catch ( Throwable t ) { throw new FeedParserException( t ); }
}
private static void onWeblog( FeedDirectoryParserListener listener,
FeedParserState state,
Element current ) throws Exception {
String weblog = current.getAttributeValue( "url" );
String description = current.getAttributeValue( "name" );
String title = description;
String feed = null;
if ( weblog == null )
weblog = feed;
listener.onItem( state, title, weblog, description, feed );
}
}
1.8 +3 -1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/impl/DebugFeedParserListener.java
Index: DebugFeedParserListener.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/impl/DebugFeedParserListener.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DebugFeedParserListener.java 27 Aug 2004 18:07:01 -0000 1.7
+++ DebugFeedParserListener.java 31 Aug 2004 21:00:32 -0000 1.8
@@ -36,6 +36,8 @@
PrintStream out = System.out;
+ public DebugFeedParserListener() { }
+
public DebugFeedParserListener( PrintStream out ) {
this.out = out;
}
1.3 +11 -2
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/AnchorParser.java
Index: AnchorParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/AnchorParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AnchorParser.java 15 Apr 2004 16:57:20 -0000 1.2
+++ AnchorParser.java 31 Aug 2004 21:00:32 -0000 1.3
@@ -29,10 +29,18 @@
*/
public class AnchorParser {
- public static final String LINK_REGEXP = "<a
[^>]*href=[\"']?([^\">']+)[\"']?[^>]*>([^<]+)";
+ public static final String LINK_REGEXP = "<a [^>]*href=[\"']?([^\">'
]+)[\"']?[^>]*>([^<]+)";
static Pattern pattern = Pattern.compile( LINK_REGEXP,
Pattern.CASE_INSENSITIVE |
Pattern.MULTILINE );
+
+ public static void parse( String content,
+ AnchorParserListener listener ) {
+
+ parseAnchors( content, listener );
+
+ }
+
/**
* Get links from the given html with included titles and other metainfo.
@@ -40,7 +48,8 @@
* @deprecated use HTParser
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
*/
- public static void parseAnchors( String content, AnchorParserListener listener
) {
+ public static void parseAnchors( String content,
+ AnchorParserListener listener ) {
int index = 0;
1.2 +3 -1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/EntityDecoder.java
Index: EntityDecoder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/locate/EntityDecoder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EntityDecoder.java 15 Apr 2004 00:58:44 -0000 1.1
+++ EntityDecoder.java 31 Aug 2004 21:00:32 -0000 1.2
@@ -44,6 +44,8 @@
entities.put( "apos", ">" );
entities.put( "lt", "<" );
entities.put( "amp", "&" );
+
+ //FIXME:
entities.put( "raquo", "" );
entities.put( "laquo", "" );
1.1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/post/MetaWeblogPostAgent.java
Index: MetaWeblogPostAgent.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;
import org.apache.commons.feedparser.tools.*;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.xmlrpc.*;
/**
* A PostAgent allows a developer to post to a given weblog.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton (burtonator)</a>
* @version $Id: MetaWeblogPostAgent.java,v 1.1 2004/08/31 21:00:32 burton Exp $
*/
public class MetaWeblogPostAgent {
public void newPost( String router,
String weblog,
String username,
String password,
PostEntry entry ) throws Exception {
XmlRpcClient xmlrpc = new XmlRpcClient( router );
Vector params = new Vector();
params.add( weblog);
params.add( username );
params.add( password );
Hashtable struct = new Hashtable();
struct.put( "title", entry.title );
struct.put( "description", entry.description );
params.add( struct );
params.add( new Boolean( true ) );
Vector v = (Vector)xmlrpc.execute( "metaWeblog.newPost", params );
}
}
1.1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/post/PostAgent.java
Index: PostAgent.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;
import org.apache.commons.feedparser.tools.*;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* A PostAgent allows a developer to post to a given weblog.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton (burtonator)</a>
* @version $Id: PostAgent.java,v 1.1 2004/08/31 21:00:32 burton Exp $
*/
public interface PostAgent {
public void newPost( String router,
String weblog,
String username,
String password,
PostEntry entry );
}
1.1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/post/PostEntry.java
Index: PostEntry.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;
import org.apache.commons.feedparser.tools.*;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* A PostAgent allows a developer to post to a given weblog.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton (burtonator)</a>
* @version $Id: PostEntry.java,v 1.1 2004/08/31 21:00:32 burton Exp $
*/
public class PostEntry {
public String title = null;
public String description = null;
}
1.5 +12 -4
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestAtom.java
Index: TestAtom.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestAtom.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestAtom.java 28 Feb 2004 03:35:22 -0000 1.4
+++ TestAtom.java 31 Aug 2004 21:00:32 -0000 1.5
@@ -48,10 +48,8 @@
super( name );
}
- public void test1() throws Exception {
+ public void doTest( String resource ) throws Exception {
- String resource =
"file:///projects/feedparser/src/java/org/apache/commons/feedparser/test/TestAtom.xml";
-
FeedParser parser = FeedParserFactory.newFeedParser();
FeedParserListener listener = new DefaultFeedParserListener() {
@@ -63,6 +61,7 @@
String permalink ) throws FeedParserException {
System.out.println( "title: " + title );
+ System.out.println( "description: " + description );
System.out.println( "permalink: " + permalink );
}
@@ -102,6 +101,15 @@
parser.parse( listener, request.getInputStream() );
}
+
+ public void test1() throws Exception {
+
+ //String resource =
"file:///projects/feedparser/src/java/org/apache/commons/feedparser/test/TestAtom.xml";
+
+ //doTest( resource );
+ doTest( "file:tests/feeds/atom-1.xml" );
+
+ }
public static void main( String[] args ) throws Exception {
1.5 +3 -1
jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestFeedLocator.java
Index: TestFeedLocator.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/test/TestFeedLocator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestFeedLocator.java 27 Aug 2004 18:07:01 -0000 1.4
+++ TestFeedLocator.java 31 Aug 2004 21:00:32 -0000 1.5
@@ -69,6 +69,8 @@
public void test1() throws Exception {
+ doTest( "file:tests/locate/locate10.html" );
+
doTest( "file:tests/locate/locate1.html" );
doTest( "file:tests/locate/locate2.html" );
doTest( "file:tests/locate/locate3.html" );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]