org.clapper.curn.parser
Class ParserUtil

java.lang.Object
  extended by org.clapper.curn.parser.ParserUtil

public final class ParserUtil
extends java.lang.Object

Common utility routines that can be used by all parser implementations.

Version:
$Revision: 6468 $

Field Summary
static java.lang.String RSS_MIME_TYPE
          Default MIME type for RSS feeds, if we can't figure one out.
 
Method Summary
static RSSLink findMatchingLink(java.util.Collection<RSSLink> links, RSSLink.Type linkType)
          Find the first RSSLink object with a specific link type.
static RSSLink findMatchingLink(java.util.Collection<RSSLink> links, java.lang.String mimeType)
          Find the first RSSLink object with a specific MIME type.
static RSSLink findMatchingLink(java.util.Collection<RSSLink> links, java.lang.String mimeType, RSSLink.Type... linkTypes)
          Find the RSSLink object with a specific MIME type and one of a set of link types.
static java.lang.String getLinkMIMEType(java.net.URL url)
          Get the MIME type for a link from an RSS feed.
static java.lang.String normalizeCharacterData(char[] ch, int start, int length)
          Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines.
static void normalizeCharacterData(char[] ch, int start, int length, java.lang.StringBuffer buf)
          Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines.
static java.lang.String normalizeCharacterData(java.lang.String s)
          Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines.
static java.util.Date parseDate(java.lang.String sDate)
          Try to parse a date using as many methods as possible, until one works.
static java.util.Date parseRFC822Date(java.lang.String sDate)
          Parse an RFC 822-style date string.
static java.util.Date parseW3CDate(java.lang.String sDate)
          Parse a W3C date string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RSS_MIME_TYPE

public static final java.lang.String RSS_MIME_TYPE
Default MIME type for RSS feeds, if we can't figure one out.

See Also:
Constant Field Values
Method Detail

parseDate

public static java.util.Date parseDate(java.lang.String sDate)
Try to parse a date using as many methods as possible, until one works.

Parameters:
sDate - the date string
Returns:
the corresponding date, or null if not parseable or if the date string is empty or null

parseRFC822Date

public static java.util.Date parseRFC822Date(java.lang.String sDate)
Parse an RFC 822-style date string.

Parameters:
sDate - the date string
Returns:
the corresponding date, or null if not parseable or if the date string is empty or null

parseW3CDate

public static java.util.Date parseW3CDate(java.lang.String sDate)
Parse a W3C date string. Not comprehensive.

Parameters:
sDate - the date string
Returns:
the corresponding date, or null if not parseable or if the date string is empty or null

normalizeCharacterData

public static java.lang.String normalizeCharacterData(char[] ch,
                                                      int start,
                                                      int length)
Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines. Embedded newlines are mapped to spaces.

Parameters:
ch - the array of characters to process
start - the start position in the array
length - the number of characters to read from the array
Returns:
the resulting string
See Also:
normalizeCharacterData(char[],int,int,StringBuffer), normalizeCharacterData(String)

normalizeCharacterData

public static java.lang.String normalizeCharacterData(java.lang.String s)
Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines. Embedded newlines are mapped to spaces.

Parameters:
s - the string to process
Returns:
the resulting string
See Also:
normalizeCharacterData(char[],int,int,StringBuffer), normalizeCharacterData(String)

normalizeCharacterData

public static void normalizeCharacterData(char[] ch,
                                          int start,
                                          int length,
                                          java.lang.StringBuffer buf)
Used to process the characters found between two XML elements, this method removes any leading and trailing white space, including newlines. Embedded newlines are mapped to spaces.

Parameters:
ch - the array of characters to process
start - the start position in the array
length - the number of characters to read from the array
buf - where to append the resulting characters
See Also:
normalizeCharacterData(char[],int,int), normalizeCharacterData(String)

findMatchingLink

public static RSSLink findMatchingLink(java.util.Collection<RSSLink> links,
                                       java.lang.String mimeType,
                                       RSSLink.Type... linkTypes)
Find the RSSLink object with a specific MIME type and one of a set of link types.

Parameters:
links - collection of RSSLink objects to search
mimeType - the desired MIME type
linkTypes - one or more link types that are acceptable
Returns:
the link, or null no matches were found

findMatchingLink

public static RSSLink findMatchingLink(java.util.Collection<RSSLink> links,
                                       RSSLink.Type linkType)
Find the first RSSLink object with a specific link type.

Parameters:
links - collection of RSSLink objects to search
linkType - the desired link type
Returns:
the link, or null no matches were found

findMatchingLink

public static RSSLink findMatchingLink(java.util.Collection<RSSLink> links,
                                       java.lang.String mimeType)
Find the first RSSLink object with a specific MIME type.

Parameters:
links - collection of RSSLink objects to search
mimeType - the desired MIME type
Returns:
the link, or null no matches were found

getLinkMIMEType

public static java.lang.String getLinkMIMEType(java.net.URL url)
Get the MIME type for a link from an RSS feed.

Parameters:
url - The URL
Returns:
the MIME type, or a default one


Copyright © 2004-2006 Brian M. Clapper. All Rights Reserved.