| 1 | |
package net.spy.digg.parsers; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
|
| 5 | |
import net.spy.digg.Comment; |
| 6 | |
|
| 7 | |
import org.w3c.dom.Node; |
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | 3 | public class CommentImpl extends EventImpl implements Comment, Serializable { |
| 13 | |
|
| 14 | |
private final String comment; |
| 15 | |
private final int down; |
| 16 | |
private final int up; |
| 17 | |
private final Integer replyId; |
| 18 | |
private final Integer root; |
| 19 | |
private final Integer level; |
| 20 | |
|
| 21 | |
CommentImpl(Node n) { |
| 22 | 120 | super(n); |
| 23 | 120 | down=Integer.parseInt(BaseParser.getAttr(n, "down")); |
| 24 | 120 | up=Integer.parseInt(BaseParser.getAttr(n, "up")); |
| 25 | 120 | replyId=getIntegerAttr(n, "replyto"); |
| 26 | 120 | root=getIntegerAttr(n, "root"); |
| 27 | 120 | level=getIntegerAttr(n, "level"); |
| 28 | 120 | final Node c = n.getFirstChild(); |
| 29 | |
assert c.getNodeType() == Node.CDATA_SECTION_NODE |
| 30 | 120 | : "Expected CDATA, got " + c; |
| 31 | 120 | comment=c.getNodeValue(); |
| 32 | 120 | } |
| 33 | |
|
| 34 | |
private Integer getIntegerAttr(Node n, String attr) { |
| 35 | 360 | final String s=BaseParser.getAttr(n, attr); |
| 36 | |
final Integer rv; |
| 37 | 360 | if(s != null && s.length() > 0) { |
| 38 | 132 | rv=new Integer(s); |
| 39 | |
} else { |
| 40 | 228 | rv=null; |
| 41 | |
} |
| 42 | 360 | return rv; |
| 43 | |
} |
| 44 | |
|
| 45 | |
public String getComment() { |
| 46 | 6 | return comment; |
| 47 | |
} |
| 48 | |
|
| 49 | |
public int getDiggsDown() { |
| 50 | 6 | return down; |
| 51 | |
} |
| 52 | |
|
| 53 | |
public int getDiggsUp() { |
| 54 | 6 | return up; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public Integer getReplyId() { |
| 58 | 6 | return replyId; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public Integer getLevel() { |
| 62 | 6 | return level; |
| 63 | |
} |
| 64 | |
|
| 65 | |
public Integer getRoot() { |
| 66 | 6 | return root; |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public String toString() { |
| 71 | 3 | return "{Comment by " + getUser() + "}"; |
| 72 | |
} |
| 73 | |
} |