-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedia.java
More file actions
123 lines (102 loc) · 4.07 KB
/
Media.java
File metadata and controls
123 lines (102 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package javaxt.rss;
//******************************************************************************
//** RSS Media
//******************************************************************************
/**
* Used to represent media associated with an RSS Item.
*
******************************************************************************/
public class Media {
private String type;
private java.net.URL url;
private String credit;
private String description;
//**************************************************************************
//** Constructor
//**************************************************************************
protected Media(org.w3c.dom.Node[] nodes){
java.net.URL thumbnail = null;
String thumbnailType = null;
java.net.URL content = null;
String contentType = null;
for (org.w3c.dom.Node node : nodes){
String nodeName = node.getNodeName();
if (nodeName.endsWith("credit")){
credit = Parser.getNodeValue(node).trim();
}
else if (nodeName.endsWith("description")){
description = Parser.getNodeValue(node).trim();
}
else if (nodeName.endsWith("thumbnail")){
String link = Parser.getAttributeValue(node,"url").trim();
if (link.length()>0){
try{
thumbnail = new java.net.URL(link);
thumbnailType = Parser.getAttributeValue(node,"type").trim();
}
catch(Exception e){}
}
}
else if (nodeName.endsWith("content")){
String link = Parser.getAttributeValue(node,"url").trim();
if (link.length()>0){
try{
content = new java.net.URL(link);
contentType = Parser.getAttributeValue(node,"type").trim();
}
catch(Exception e){}
}
}
}
if (content!=null){
url = content;
type = contentType;
}
else{
url = thumbnail;
type = thumbnailType;
}
}
//**************************************************************************
//** Constructor
//**************************************************************************
/** Used to parse a media content node associated with an RSS entry.
*/
protected Media(org.w3c.dom.Node node) {
type = Parser.getAttributeValue(node,"type").trim();
//Parse url
String link = Parser.getAttributeValue(node,"url").trim();
if (link.length()>0){
try{ url = new java.net.URL(link); }
catch(Exception e){}
}
org.w3c.dom.NodeList nodeList = node.getChildNodes();
for (int i=0; i<nodeList.getLength(); i++){
node = nodeList.item(i);
if (node.getNodeType()==1){
String nodeName = node.getNodeName();
if (nodeName.endsWith("credit")){
credit = Parser.getNodeValue(node).trim();
}
else if (nodeName.endsWith("description")){
description = Parser.getNodeValue(node).trim();
}
}
}
}
public String getType(){ return type; }
public String getCredit(){ return credit; }
public String getDescription(){ return description; }
public java.net.URL getLink(){ return url; }
public String toString(){
StringBuffer out = new StringBuffer();
String br = "\r\n";
String mimeType = getType();
if (mimeType.contains("/")) mimeType = mimeType.substring(0, mimeType.indexOf("/"));
mimeType = mimeType.substring(0,1).toUpperCase() + mimeType.substring(1);
out.append(mimeType + ": " + getLink() + br);
out.append("Description: " + getDescription() + br);
out.append("Credit: " + getCredit() + br);
return out.toString();
}
}