| 1 | |
package net.spy.digg.parsers; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.Serializable; |
| 5 | |
import java.net.URL; |
| 6 | |
|
| 7 | |
import org.w3c.dom.Node; |
| 8 | |
import org.w3c.dom.NodeList; |
| 9 | |
|
| 10 | |
import net.spy.digg.GalleryPhoto; |
| 11 | |
import net.spy.digg.User; |
| 12 | |
|
| 13 | 3 | public class GalleryPhotoImpl implements GalleryPhoto, Serializable { |
| 14 | |
|
| 15 | |
private final int id; |
| 16 | |
private final URL imgHref; |
| 17 | |
private final URL imgSrc; |
| 18 | |
private final int numComments; |
| 19 | |
private final long submitDate; |
| 20 | |
private final String title; |
| 21 | |
private final User user; |
| 22 | |
|
| 23 | |
GalleryPhotoImpl(Node n) throws IOException { |
| 24 | 9 | super(); |
| 25 | |
|
| 26 | 9 | id=Integer.parseInt(BaseParser.getAttr(n, "id")); |
| 27 | 9 | imgHref=new URL(BaseParser.getAttr(n, "href")); |
| 28 | 9 | imgSrc=new URL(BaseParser.getAttr(n, "src")); |
| 29 | 9 | submitDate=1000*Long.parseLong(BaseParser.getAttr(n, "submit_date")); |
| 30 | 9 | numComments=Integer.parseInt(BaseParser.getAttr(n, "comments")); |
| 31 | |
|
| 32 | 9 | String t=null; |
| 33 | 9 | User u=null; |
| 34 | |
|
| 35 | 9 | NodeList nl=n.getChildNodes(); |
| 36 | 54 | for(int i=0; i<nl.getLength(); i++) { |
| 37 | 45 | Node cn=nl.item(i); |
| 38 | 45 | String nm=cn.getNodeName(); |
| 39 | 45 | if(nm.equals("title")) { |
| 40 | 9 | t=cn.getFirstChild().getNodeValue(); |
| 41 | 36 | } else if(nm.equals("user")) { |
| 42 | 9 | u=new UserImpl(cn); |
| 43 | 27 | } else if(cn.getNodeType() == Node.TEXT_NODE) { |
| 44 | |
|
| 45 | |
} else { |
| 46 | 0 | assert false : "Unexpected node: " + cn; |
| 47 | |
} |
| 48 | |
} |
| 49 | |
|
| 50 | 9 | user=u; |
| 51 | 9 | title=t; |
| 52 | |
|
| 53 | 9 | assert user != null; |
| 54 | 9 | assert title != null; |
| 55 | 9 | } |
| 56 | |
|
| 57 | |
public int getId() { |
| 58 | 3 | return id; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public URL getImgHref() { |
| 62 | 3 | return imgHref; |
| 63 | |
} |
| 64 | |
|
| 65 | |
public URL getImgSrc() { |
| 66 | 3 | return imgSrc; |
| 67 | |
} |
| 68 | |
|
| 69 | |
public int getNumComments() { |
| 70 | 3 | return numComments; |
| 71 | |
} |
| 72 | |
|
| 73 | |
public long getSubmitTimestamp() { |
| 74 | 3 | return submitDate; |
| 75 | |
} |
| 76 | |
|
| 77 | |
public String getTitle() { |
| 78 | 3 | return title; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public User getUser() { |
| 82 | 12 | return user; |
| 83 | |
} |
| 84 | |
|
| 85 | |
} |