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/06/28 03:04:37 UTC
cvs commit: jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/tools ISO8601DateParser.java
burton 2004/06/27 18:04:37
Modified: feedparser/src/java/org/apache/commons/feedparser
AtomFeedParser.java RSSFeedParser.java
feedparser/src/java/org/apache/commons/feedparser/tools
ISO8601DateParser.java
Log:
Support for Atom dates and zulu timezone
Revision Changes Path
1.8 +5 -1 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AtomFeedParser.java 24 May 2004 22:46:50 -0000 1.7
+++ AtomFeedParser.java 28 Jun 2004 01:04:37 -0000 1.8
@@ -128,11 +128,15 @@
String description = selectText( "atom:summary[@type='text/plain']", child );
+ state.current = child;
+
listener.onItem( state, title, link, description, link );
doMeta( state, listener, child );
doContent( state, listener, child );
+
+ MetaFeedParser.parse( listener, state );
listener.onItemEnd();
1.8 +2 -41 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/RSSFeedParser.java
Index: RSSFeedParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/RSSFeedParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RSSFeedParser.java 26 Jun 2004 22:46:27 -0000 1.7
+++ RSSFeedParser.java 28 Jun 2004 01:04:37 -0000 1.8
@@ -226,49 +226,10 @@
}
- doMetaFeedParserListener( listener, state );
+ MetaFeedParser.parse( listener, state );
listener.onItemEnd();
- }
-
- /**
- *
- */
- private static void doMetaFeedParserListener( FeedParserListener listener,
- FeedParserState state ) throws FeedParserException {
-
- //FIXME: this should be refactored into a new class called
- //MetaFeedParser to be used by both Atom and RSS. Also the date
- //handling below needs to be generic.
-
- if ( listener instanceof MetaFeedParserListener ) {
-
- MetaFeedParserListener mfp = (MetaFeedParserListener)listener;
-
- //ok. Support dc:date
- String dc_date = state.current.getChildText( "date", NS.DC );
-
- if ( dc_date != null ) {
-
- try {
-
- Date d = ISO8601DateParser.parse( dc_date );
-
- mfp.onCreated( state, d );
- mfp.onCreatedEnd();
-
- //if it fails to parse we can just move on.
- } catch ( Throwable t ) { }
-
- }
-
- //FIXME: support atom:created
-
- //FIXME: support RSS 2.0 and RSS 0.9x dates.
-
- }
-
}
/**
1.3 +29 -8 jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/tools/ISO8601DateParser.java
Index: ISO8601DateParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/feedparser/src/java/org/apache/commons/feedparser/tools/ISO8601DateParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ISO8601DateParser.java 2 Mar 2004 08:32:07 -0000 1.2
+++ ISO8601DateParser.java 28 Jun 2004 01:04:37 -0000 1.3
@@ -30,9 +30,18 @@
*/
public class ISO8601DateParser {
+ // 2004-06-14T19:GMT20:30Z
+ // 2004-06-20T06:GMT22:01Z
+
private static SimpleDateFormat df
= new SimpleDateFormat( "yyyy-MM-dd'T'hh:mm:ssz" );
+ // http://www.cl.cam.ac.uk/~mgk25/iso-time.html
+ //
+ // http://www.intertwingly.net/wiki/pie/DateTime
+ //
+ // http://www.w3.org/TR/NOTE-datetime
+ //
// Different standards may need different levels of granularity in the date and
// time, so this profile defines six levels. Standards that reference this
// profile should specify one or more of these granularities. If a given
@@ -69,19 +78,23 @@
// ss = two digits of second (00 through 59)
// s = one or more digits representing a decimal fraction of a second
// TZD = time zone designator (Z or +hh:mm or -hh:mm)
-
public static Date parse( String input ) throws java.text.ParseException {
//NOTE: SimpleDateFormat uses GMT[-+]hh:mm for the TZ which breaks
//things a bit. Before we go on we have to repair this.
- int inset = 6;
+ //this is zero time so we need to add that TZ indicator for
+ if ( input.endsWith( "Z" ) ) {
+ input = input.substring( 0, input.length() - 1) + "GMT-00:00";
+ } else {
+ int inset = 6;
- String s0 = input.substring( 0, input.length() - inset );
- String s1 = input.substring( input.length() - inset, input.length() );
-
- input = s0 + "GMT" + s1;
+ String s0 = input.substring( 0, input.length() - inset );
+ String s1 = input.substring( input.length() - inset, input.length() );
+ input = s0 + "GMT" + s1;
+ }
+
return df.parse( input );
}
@@ -101,6 +114,14 @@
return s0 + s1;
}
-
+
+ public static void main( String[] args ) throws Exception {
+
+ System.out.println( parse( "2004-05-31T09:19:31-06:00" ) );
+ System.out.println( parse( "2004-06-23T17:25:31-00:00" ) );
+ System.out.println( parse( "2004-06-23T17:25:31Z" ) );
+
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org