Module org.xmlpull.v1
Class ChannelPullHandler
- java.lang.Object
-
- ChannelPullHandler
-
public class ChannelPullHandler extends java.lang.ObjectThis class will parse a rss or rdf document and build a Map consisting of - attributes of a channel - and a one attribute "items" which is a list with items, where each item consists of a Map with attributes.
NOTE: this class does not use namespaces and instead is based on heuristics
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classChannelPullHandler.KeyValueAttributes
-
Field Summary
Fields Modifier and Type Field Description private java.util.Mapchannelprivate java.lang.String[]channelIdentifiersprivate java.lang.String[][]channelSynonymesThe channelSynonymes consists of an array of identifiers.private java.lang.String[]itemIdentifiersprivate java.util.Listitemsprivate java.lang.String[][]itemSynonymesThe channelSynonymes consists of an array of identifiers.private XmlPullParserxmlPullParser
-
Constructor Summary
Constructors Constructor Description ChannelPullHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(java.lang.String[] args)java.util.Mapparse(java.io.Reader in)This method will parse the input reader and return a Map.private java.util.ListparseFirst(int type)This method will recursively parse the document, returning a List build of Key-Value pairs.private voidparseSecond(java.util.List values)This method will loop over the found values and set the values for a channel, and set the values for each item.private voidworkOnChannel(java.util.List list)This method will set the attributes for a channel.private voidworkOnItem(java.util.List list)This method will set the item attributes.
-
-
-
Field Detail
-
items
private java.util.List items
-
xmlPullParser
private XmlPullParser xmlPullParser
-
channel
private java.util.Map channel
-
channelIdentifiers
private java.lang.String[] channelIdentifiers
-
itemIdentifiers
private java.lang.String[] itemIdentifiers
-
channelSynonymes
private java.lang.String[][] channelSynonymes
The channelSynonymes consists of an array of identifiers. The first element of the array is the name that you want filled. The others names are synonymes that might be filled. These are all synonymes for channel attributes, for instance, you need the title attribute. If this isnt found initially, this class will look for an rss:title attribute. If found, it will copy the value of rss:title to title. These values could be moved out into a properties kind of file, e.g. url=link,dc:indentifier,rss:link
-
itemSynonymes
private java.lang.String[][] itemSynonymes
The channelSynonymes consists of an array of identifiers. The first element of the array is the name that you want filled. The others names are synonymes that might be filled. These are all synonymes for item attributes
-
-
Constructor Detail
-
ChannelPullHandler
public ChannelPullHandler() throws XmlPullParserException- Throws:
XmlPullParserException
-
-
Method Detail
-
parseFirst
private java.util.List parseFirst(int type) throws java.io.IOException, XmlPullParserExceptionThis method will recursively parse the document, returning a List build of Key-Value pairs. A value can be a List again, indicating a nested element inside an element.- Parameters:
type-- Returns:
- Throws:
java.io.IOExceptionXmlPullParserException
-
parseSecond
private void parseSecond(java.util.List values)
This method will loop over the found values and set the values for a channel, and set the values for each item. If other elements need to be supported, this is where you should check for these (e.g. images).- Parameters:
values-
-
workOnItem
private void workOnItem(java.util.List list)
This method will set the item attributes.- Parameters:
list-
-
workOnChannel
private void workOnChannel(java.util.List list)
This method will set the attributes for a channel.- Parameters:
list-
-
parse
public java.util.Map parse(java.io.Reader in) throws XmlPullParserException, java.io.IOExceptionThis method will parse the input reader and return a Map. This map consists of : - the attributes of a channel - and a List with items, where each item is a Map again.- Parameters:
in-- Returns:
- Throws:
XmlPullParserExceptionjava.io.IOException
-
main
public static void main(java.lang.String[] args) throws XmlPullParserException, java.io.IOException- Throws:
XmlPullParserExceptionjava.io.IOException
-
-