@@ -13,14 +13,13 @@ public class Item {
1313
1414 private String title ;
1515 private String description ;
16- private String author = null ;
17- private String creator = null ;
18- private String category = null ;
19- private java .net .URL link = null ;
20- private java .net .URL origLink = null ; //<--FeedBurner
21- private java .util .Date date = null ;
22- private Location location = null ;
23- private NodeList nodeList = null ;
16+ private String author ;
17+ private String creator ;
18+ private String category ;
19+ private java .net .URL link ;
20+ private java .net .URL origLink ; //<--FeedBurner
21+ private java .util .Date date ;
22+ private Location location ;
2423 private java .util .ArrayList <Media > media = new java .util .ArrayList <Media >();
2524
2625
@@ -45,7 +44,7 @@ public Item(String title, java.net.URL link, java.util.Date date){
4544 //**************************************************************************
4645 /** Creates a new instance of this class using an XML node from an RSS Feed.
4746 */
48- protected Item (org . w3c . dom . Node node , java .util .HashMap <String , String > namespaces ) {
47+ protected Item (Node item , java .util .HashMap <String , String > namespaces ) {
4948
5049 String mediaNS = namespaces .get ("http://search.yahoo.com/mrss" );
5150 if (mediaNS ==null ) mediaNS = "media" ;
@@ -54,15 +53,23 @@ protected Item(org.w3c.dom.Node node, java.util.HashMap<String, String> namespac
5453 if (geoNS ==null ) geoNS = "geo" ;
5554
5655
57- nodeList = node .getChildNodes ();
5856 String pubDate = null ;
5957 String dcDate = null ;
58+ String updated = null ;
59+
60+ String description = null ;
61+ String subtitle = null ;
62+ String summary = null ;
63+
6064 String lat = null ;
6165 String lon = null ;
62- java .util .ArrayList <org .w3c .dom .Node > mediaNodes = new java .util .ArrayList <org .w3c .dom .Node >();
6366
67+ java .util .ArrayList <Node > mediaNodes = new java .util .ArrayList <Node >();
68+
69+
70+ NodeList nodeList = item .getChildNodes ();
6471 for (int i =0 ; i <nodeList .getLength (); i ++){
65- node = nodeList .item (i );
72+ Node node = nodeList .item (i );
6673 if (node .getNodeType ()==1 ){
6774 String nodeName = node .getNodeName ().toLowerCase ();
6875 String nodeValue = Parser .getNodeValue (node ).trim ();
@@ -72,26 +79,30 @@ protected Item(org.w3c.dom.Node node, java.util.HashMap<String, String> namespac
7279 if (nodeName .equals ("title" )) title = nodeValue ;
7380 else if (nodeName .equals ("author" )) author = nodeValue ;
7481 else if (nodeName .endsWith ("creator" )) creator = nodeValue ;
82+
7583 else if (nodeName .equalsIgnoreCase ("pubDate" )) pubDate = nodeValue ;
7684 else if (nodeName .equalsIgnoreCase ("dc:date" )) dcDate = nodeValue ;
77- else if (nodeName .equals ("description" ) || nodeName .equals ("subtitle" )){
78- if (description ==null || description .length ()==0 ){
79- description = nodeValue ;
80- }
81- }
85+ else if (nodeName .equalsIgnoreCase ("updated" )) updated = nodeValue ;
86+
87+ else if (nodeName .endsWith ("description" )) description = nodeValue ;
88+ else if (nodeName .endsWith ("subtitle" )) subtitle = nodeValue ;
89+ else if (nodeName .endsWith ("summary" )) summary = nodeValue ;
90+
8291
8392 //Parse Link
8493 else if (nodeName .equals ("link" )){
94+ String url = "" ;
8595 if (nodeValue !=null ){
86- String url = nodeValue .replace ("\" " , "" );
87- if (url .length ()==0 ){
88- //get href attribute
89- url = Parser .getAttributeValue (node ,"href" ).trim ();
90- }
91- if (url .length ()>0 ){
92- try { link = new java .net .URL (url ); }
93- catch (Exception e ){}
94- }
96+ url = nodeValue .replace ("\" " , "" ).trim ();
97+ }
98+
99+ if (url .length ()==0 ){
100+ //get href attribute
101+ url = Parser .getAttributeValue (node ,"href" ).trim ();
102+ }
103+ if (url .length ()>0 ){
104+ try { link = new java .net .URL (url ); }
105+ catch (Exception e ){}
95106 }
96107 }
97108
@@ -131,9 +142,10 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
131142 }
132143
133144
134- //Parse date
145+ //Set date
135146 String date = pubDate ;
136147 if (date ==null || date .length ()==0 ) date = dcDate ;
148+ if (date ==null || date .length ()==0 ) date = updated ;
137149 if (date !=null && date .length ()>0 ){
138150 try {
139151 this .date = Parser .getDate (date );
@@ -143,18 +155,25 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
143155 }
144156
145157
158+ //Set description
159+ String desc = description ;
160+ if (desc ==null || desc .length ()==0 ) desc = subtitle ;
161+ if (desc ==null || desc .length ()==0 ) desc = summary ;
162+ this .description = desc ;
163+
164+
165+
146166 //Parse media nodes
147167 if (!mediaNodes .isEmpty ()){
148168
149169 //Check if there are any content nodes and if those nodes have children (e.g. The Guardian News Feed)
150- for (org . w3c . dom . Node mediaNode : mediaNodes ){
170+ for (Node mediaNode : mediaNodes ){
151171 String nodeName = mediaNode .getNodeName ().toLowerCase ();
152172 if (nodeName .equals (mediaNS + ":content" )){
153173
154-
155- org .w3c .dom .NodeList nodeList = mediaNode .getChildNodes ();
156- for (int i =0 ; i <nodeList .getLength (); i ++){
157- node = nodeList .item (i );
174+ NodeList nodes = mediaNode .getChildNodes ();
175+ for (int i =0 ; i <nodes .getLength (); i ++){
176+ Node node = nodes .item (i );
158177 if (node .getNodeType ()==1 ){
159178 addMedia (new Media (mediaNode ));
160179 break ;
@@ -167,7 +186,7 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
167186
168187 //If none of the of the content nodes have children (standard use case)
169188 if (media .isEmpty ()){
170- addMedia (new Media (mediaNodes .toArray (new org . w3c . dom . Node [mediaNodes .size ()])));
189+ addMedia (new Media (mediaNodes .toArray (new Node [mediaNodes .size ()])));
171190 }
172191 }
173192
@@ -296,16 +315,13 @@ public Media[] getMedia(){
296315 public Location getLocation (){
297316 return location ;
298317 }
299-
318+
300319
301320 //**************************************************************************
302- //** getNodeList
321+ //** setLocation
303322 //**************************************************************************
304- /** Returns the NodeList used to instantiate this class via the RSS Parser.
305- * @deprecated This method will be removed in future releases.
306- */
307- public NodeList getNodeList (){
308- return nodeList ;
323+ public void setLocation (Location location ){
324+ this .location = location ;
309325 }
310326
311327
0 commit comments