@@ -13,14 +13,13 @@ public class Item {
13
13
14
14
private String title ;
15
15
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 ;
24
23
private java .util .ArrayList <Media > media = new java .util .ArrayList <Media >();
25
24
26
25
@@ -45,7 +44,7 @@ public Item(String title, java.net.URL link, java.util.Date date){
45
44
//**************************************************************************
46
45
/** Creates a new instance of this class using an XML node from an RSS Feed.
47
46
*/
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 ) {
49
48
50
49
String mediaNS = namespaces .get ("http://search.yahoo.com/mrss" );
51
50
if (mediaNS ==null ) mediaNS = "media" ;
@@ -54,15 +53,23 @@ protected Item(org.w3c.dom.Node node, java.util.HashMap<String, String> namespac
54
53
if (geoNS ==null ) geoNS = "geo" ;
55
54
56
55
57
- nodeList = node .getChildNodes ();
58
56
String pubDate = null ;
59
57
String dcDate = null ;
58
+ String updated = null ;
59
+
60
+ String description = null ;
61
+ String subtitle = null ;
62
+ String summary = null ;
63
+
60
64
String lat = null ;
61
65
String lon = null ;
62
- java .util .ArrayList <org .w3c .dom .Node > mediaNodes = new java .util .ArrayList <org .w3c .dom .Node >();
63
66
67
+ java .util .ArrayList <Node > mediaNodes = new java .util .ArrayList <Node >();
68
+
69
+
70
+ NodeList nodeList = item .getChildNodes ();
64
71
for (int i =0 ; i <nodeList .getLength (); i ++){
65
- node = nodeList .item (i );
72
+ Node node = nodeList .item (i );
66
73
if (node .getNodeType ()==1 ){
67
74
String nodeName = node .getNodeName ().toLowerCase ();
68
75
String nodeValue = Parser .getNodeValue (node ).trim ();
@@ -72,26 +79,30 @@ protected Item(org.w3c.dom.Node node, java.util.HashMap<String, String> namespac
72
79
if (nodeName .equals ("title" )) title = nodeValue ;
73
80
else if (nodeName .equals ("author" )) author = nodeValue ;
74
81
else if (nodeName .endsWith ("creator" )) creator = nodeValue ;
82
+
75
83
else if (nodeName .equalsIgnoreCase ("pubDate" )) pubDate = nodeValue ;
76
84
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
+
82
91
83
92
//Parse Link
84
93
else if (nodeName .equals ("link" )){
94
+ String url = "" ;
85
95
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 ){}
95
106
}
96
107
}
97
108
@@ -131,9 +142,10 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
131
142
}
132
143
133
144
134
- //Parse date
145
+ //Set date
135
146
String date = pubDate ;
136
147
if (date ==null || date .length ()==0 ) date = dcDate ;
148
+ if (date ==null || date .length ()==0 ) date = updated ;
137
149
if (date !=null && date .length ()>0 ){
138
150
try {
139
151
this .date = Parser .getDate (date );
@@ -143,18 +155,25 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
143
155
}
144
156
145
157
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
+
146
166
//Parse media nodes
147
167
if (!mediaNodes .isEmpty ()){
148
168
149
169
//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 ){
151
171
String nodeName = mediaNode .getNodeName ().toLowerCase ();
152
172
if (nodeName .equals (mediaNS + ":content" )){
153
173
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 );
158
177
if (node .getNodeType ()==1 ){
159
178
addMedia (new Media (mediaNode ));
160
179
break ;
@@ -167,7 +186,7 @@ else if (nodeName.equals("long") || nodeName.equals(geoNS + ":long")){
167
186
168
187
//If none of the of the content nodes have children (standard use case)
169
188
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 ()])));
171
190
}
172
191
}
173
192
@@ -296,16 +315,13 @@ public Media[] getMedia(){
296
315
public Location getLocation (){
297
316
return location ;
298
317
}
299
-
318
+
300
319
301
320
//**************************************************************************
302
- //** getNodeList
321
+ //** setLocation
303
322
//**************************************************************************
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 ;
309
325
}
310
326
311
327
0 commit comments