public
Description: My digg interface for java.
Homepage: http://bleu.west.spy.net/~dustin/projects/digg/
Clone URL: git://github.com/dustin/java-digg.git
Search Repo:
Add support for root and level in comments.
dustin (author)
Sat May 17 14:02:12 -0700 2008
commit  5788c034f630271a6dce732f580664712d3c32a5
tree    7b9178f3260c406a16c5a11900b9e27fe8ada51b
parent  255be1e650a5e5dd790dfad51400aa2571846875
...
24
25
26
 
 
 
 
 
 
 
 
 
 
27
28
29
...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
0
@@ -24,6 +24,16 @@ public interface Comment extends Event {
0
   Integer getReplyId();
0
 
0
   /**
0
+ * The root comment ID.
0
+ */
0
+ Integer getRoot();
0
+
0
+ /**
0
+ * The level of the comment within the thread.
0
+ */
0
+ Integer getLevel();
0
+
0
+ /**
0
    * Get the comment text.
0
    */
0
   String getComment();
...
15
16
17
 
 
18
19
20
21
22
23
24
25
26
27
28
 
 
 
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
 
35
36
37
...
48
49
50
 
 
 
 
 
 
 
 
51
52
53
...
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
...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
0
@@ -15,23 +15,33 @@ public class CommentImpl extends EventImpl implements Comment, Serializable {
0
   private final int down;
0
   private final int up;
0
   private final Integer replyId;
0
+ private final Integer root;
0
+ private final Integer level;
0
 
0
   CommentImpl(Node n) {
0
     super(n);
0
     down=Integer.parseInt(BaseParser.getAttr(n, "down"));
0
     up=Integer.parseInt(BaseParser.getAttr(n, "up"));
0
- final String s=BaseParser.getAttr(n, "replyto");
0
- if(s != null && s.length() > 0) {
0
- replyId=new Integer(s);
0
- } else {
0
- replyId=null;
0
- }
0
+ replyId=getIntegerAttr(n, "replyto");
0
+ root=getIntegerAttr(n, "root");
0
+ level=getIntegerAttr(n, "level");
0
     final Node c = n.getFirstChild();
0
     assert c.getNodeType() == Node.CDATA_SECTION_NODE
0
       : "Expected CDATA, got " + c;
0
     comment=c.getNodeValue();
0
   }
0
 
0
+ private Integer getIntegerAttr(Node n, String attr) {
0
+ final String s=BaseParser.getAttr(n, attr);
0
+ final Integer rv;
0
+ if(s != null && s.length() > 0) {
0
+ rv=new Integer(s);
0
+ } else {
0
+ rv=null;
0
+ }
0
+ return rv;
0
+ }
0
+
0
   public String getComment() {
0
     return comment;
0
   }
0
@@ -48,6 +58,14 @@ public class CommentImpl extends EventImpl implements Comment, Serializable {
0
     return replyId;
0
   }
0
 
0
+ public Integer getLevel() {
0
+ return level;
0
+ }
0
+
0
+ public Integer getRoot() {
0
+ return root;
0
+ }
0
+
0
   @Override
0
   public String toString() {
0
     return "{Comment by " + getUser() + "}";
...
5
6
7
8
9
10
11
...
95
96
97
 
 
98
99
100
...
105
106
107
 
 
 
 
 
 
 
 
 
 
108
109
110
...
5
6
7
 
8
9
10
...
94
95
96
97
98
99
100
101
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
0
@@ -5,7 +5,6 @@ import java.net.URL;
0
 import java.util.Iterator;
0
 
0
 import junit.framework.TestCase;
0
-
0
 import net.spy.digg.Comment;
0
 import net.spy.digg.Event;
0
 import net.spy.digg.GalleryPhoto;
0
@@ -95,6 +94,8 @@ public class ParsersTest extends TestCase {
0
     assertEquals(0, ep.getOffset());
0
 
0
     Comment c=(Comment)ep.getItems().iterator().next();
0
+ assertNull(c.getRoot());
0
+ assertNull(c.getLevel());
0
     assertEquals(6273341, c.getEventId());
0
     assertEquals(new Integer(6268248), c.getReplyId());
0
     assertEquals("mikesbaker", c.getUser());
0
@@ -105,6 +106,16 @@ public class ParsersTest extends TestCase {
0
     assertEquals("{Comment by mikesbaker}", String.valueOf(c));
0
   }
0
 
0
+ public void testCommentsParserWithRoot() throws Exception {
0
+ EventsParser ep=doParse("comments_with_root.xml", EventsParser.class);
0
+
0
+ Comment c=(Comment)ep.getItems().iterator().next();
0
+ assertEquals(15042676, c.getEventId());
0
+ assertEquals(new Integer(15042676), c.getRoot());
0
+ assertEquals(new Integer(0), c.getLevel());
0
+ }
0
+
0
+
0
   public void testCommentsParserEmptyReplyTo() throws Exception {
0
     EventsParser ep=doParse("comments_empty_replyto.xml",
0
       EventsParser.class);

Comments

    No one has commented yet.