Kaynağa Gözat

Add Twitter Parser.

Change-Id: I3afb4ec125fff7e02bc51296c5546a376fb99b55
Reviewed-on: http://gerrit.dmdirc.com/270
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3
Shane Mc Cormack 14 yıl önce
ebeveyn
işleme
fb475a16cf
26 değiştirilmiş dosya ile 7073 ekleme ve 0 silme
  1. BIN
      lib/commons-codec-1.3.jar
  2. BIN
      lib/signpost-core-1.1-SNAPSHOT.jar
  3. 43
    0
      src/com/dmdirc/addons/parser_twitter/Debug.java
  4. 1423
    0
      src/com/dmdirc/addons/parser_twitter/Twitter.java
  5. 59
    0
      src/com/dmdirc/addons/parser_twitter/TwitterCallbackManager.java
  6. 72
    0
      src/com/dmdirc/addons/parser_twitter/TwitterCallbackObject.java
  7. 79
    0
      src/com/dmdirc/addons/parser_twitter/TwitterCallbackObjectSpecific.java
  8. 164
    0
      src/com/dmdirc/addons/parser_twitter/TwitterChannelClientInfo.java
  9. 281
    0
      src/com/dmdirc/addons/parser_twitter/TwitterChannelInfo.java
  10. 280
    0
      src/com/dmdirc/addons/parser_twitter/TwitterClientInfo.java
  11. 91
    0
      src/com/dmdirc/addons/parser_twitter/TwitterPlugin.java
  12. 57
    0
      src/com/dmdirc/addons/parser_twitter/api/APIAllowed.java
  13. 1690
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterAPI.java
  14. 42
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterErrorHandler.java
  15. 58
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterException.java
  16. 227
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterMessage.java
  17. 46
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterRawHandler.java
  18. 58
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterRuntimeException.java
  19. 287
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterStatus.java
  20. 292
    0
      src/com/dmdirc/addons/parser_twitter/api/TwitterUser.java
  21. 153
    0
      src/com/dmdirc/addons/parser_twitter/api/XMLResponse.java
  22. 1010
    0
      src/com/dmdirc/addons/parser_twitter/api/commons/Entities.java
  23. 364
    0
      src/com/dmdirc/addons/parser_twitter/api/commons/IntHashMap.java
  24. 180
    0
      src/com/dmdirc/addons/parser_twitter/api/commons/StringEscapeUtils.java
  25. 71
    0
      src/com/dmdirc/addons/parser_twitter/api/commons/UnhandledException.java
  26. 46
    0
      src/com/dmdirc/addons/parser_twitter/plugin.config

BIN
lib/commons-codec-1.3.jar Dosyayı Görüntüle


BIN
lib/signpost-core-1.1-SNAPSHOT.jar Dosyayı Görüntüle


+ 43
- 0
src/com/dmdirc/addons/parser_twitter/Debug.java Dosyayı Görüntüle

@@ -0,0 +1,43 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ * 
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ * 
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+/**
26
+ * Debug Info Enums
27
+ *
28
+ * @author shane
29
+ */
30
+enum Debug {
31
+    /** Debug information related to api calls. */
32
+    apiCalls,
33
+    /** Debug information related to sleeping. */
34
+    sleepTime,
35
+    /** Debug information for data input. */
36
+    dataIn,
37
+    /** Debug information for data output. */
38
+    dataOut,
39
+    /** General error info from the twitter parser. */
40
+    twitterError,
41
+    /** More debuggy error info from the twitter parser. */
42
+    twitterErrorMore;
43
+}

+ 1423
- 0
src/com/dmdirc/addons/parser_twitter/Twitter.java
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 59
- 0
src/com/dmdirc/addons/parser_twitter/TwitterCallbackManager.java Dosyayı Görüntüle

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.parser.common.CallbackObjectSpecific;
26
+import com.dmdirc.parser.common.CallbackObject;
27
+import com.dmdirc.parser.common.CallbackManager;
28
+import com.dmdirc.parser.interfaces.callbacks.CallbackInterface;
29
+
30
+/**
31
+ * Handles callbacks for the Twitter Parser.
32
+ * 
33
+ * @author chris
34
+ */
35
+public class TwitterCallbackManager extends CallbackManager<Twitter> {
36
+    /**
37
+     * Create a new TwitterCallbackManager
38
+     * 
39
+     * @param parser Parser that owns this callback manager.
40
+     */
41
+    public TwitterCallbackManager(final Twitter parser) {
42
+        super(parser);
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    @Override
47
+    protected CallbackObject getCallbackObject(final Twitter parser, final Class<?> type) {
48
+        return new TwitterCallbackObject(parser, this, type.asSubclass(CallbackInterface.class));
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    protected CallbackObjectSpecific getSpecificCallbackObject(final Twitter parser,
54
+            final Class<?> type) {
55
+        return new TwitterCallbackObjectSpecific(parser, this,
56
+                type.asSubclass(CallbackInterface.class));
57
+    }
58
+
59
+}

+ 72
- 0
src/com/dmdirc/addons/parser_twitter/TwitterCallbackObject.java Dosyayı Görüntüle

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.parser.common.CallbackManager;
26
+import com.dmdirc.parser.common.CallbackObject;
27
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+import com.dmdirc.parser.interfaces.ChannelInfo;
29
+import com.dmdirc.parser.interfaces.ClientInfo;
30
+import com.dmdirc.parser.interfaces.LocalClientInfo;
31
+import com.dmdirc.parser.interfaces.Parser;
32
+import com.dmdirc.parser.interfaces.callbacks.CallbackInterface;
33
+import java.util.HashMap;
34
+import java.util.Map;
35
+
36
+/**
37
+ * A callback object for the Twitter parser.
38
+ *
39
+ * @since 0.6.3m2
40
+ * @author chris
41
+ */
42
+public class TwitterCallbackObject extends CallbackObject {
43
+
44
+    /** A map of interfaces to the classes which should be instansiated for them. */
45
+    protected static Map<Class<?>, Class<?>> IMPL_MAP = new HashMap<Class<?>, Class<?>>();
46
+
47
+    static {
48
+        IMPL_MAP.put(ChannelClientInfo.class, TwitterChannelClientInfo.class);
49
+        IMPL_MAP.put(ChannelInfo.class, TwitterChannelInfo.class);
50
+        IMPL_MAP.put(ClientInfo.class, TwitterClientInfo.class);
51
+        IMPL_MAP.put(LocalClientInfo.class, TwitterClientInfo.class);
52
+    }
53
+
54
+    /**
55
+     * Create a new TwitterCallbackObject.
56
+     *
57
+     * @param parser Parser that owns this object.
58
+     * @param manager Callback Manager that owns this object.
59
+     * @param type Type of callback.
60
+     */
61
+    public TwitterCallbackObject(final Parser parser, final CallbackManager<?> manager,
62
+            final Class<? extends CallbackInterface> type) {
63
+        super(parser, manager, type);
64
+    }
65
+
66
+    /** {@inheritDoc} */
67
+    @Override
68
+    protected Class<?> getImplementation(final Class<?> type) {
69
+        return IMPL_MAP.containsKey(type) ? IMPL_MAP.get(type) : type;
70
+    }
71
+
72
+}

+ 79
- 0
src/com/dmdirc/addons/parser_twitter/TwitterCallbackObjectSpecific.java Dosyayı Görüntüle

@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.parser.common.CallbackManager;
26
+import com.dmdirc.parser.common.CallbackObjectSpecific;
27
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+import com.dmdirc.parser.interfaces.ChannelInfo;
29
+import com.dmdirc.parser.interfaces.ClientInfo;
30
+import com.dmdirc.parser.interfaces.LocalClientInfo;
31
+import com.dmdirc.parser.interfaces.Parser;
32
+import com.dmdirc.parser.interfaces.callbacks.CallbackInterface;
33
+import java.util.HashMap;
34
+import java.util.Map;
35
+
36
+/**
37
+ * A specific callback object for use with the Twitter Parser
38
+ *
39
+ * @since 0.6.3m2
40
+ * @author chris
41
+ */
42
+public class TwitterCallbackObjectSpecific extends CallbackObjectSpecific {
43
+
44
+    /** A map of interfaces to the classes which should be instansiated for them. */
45
+    protected static Map<Class<?>, Class<?>> IMPL_MAP = new HashMap<Class<?>, Class<?>>();
46
+
47
+    static {
48
+        IMPL_MAP.put(ChannelClientInfo.class, TwitterChannelClientInfo.class);
49
+        IMPL_MAP.put(ChannelInfo.class, TwitterChannelInfo.class);
50
+        IMPL_MAP.put(ClientInfo.class, TwitterClientInfo.class);
51
+        IMPL_MAP.put(LocalClientInfo.class, TwitterClientInfo.class);
52
+    }
53
+
54
+    /**
55
+     * Create a new TwitterCallbackObjectSpecific.
56
+     * This is a TwitterCallbackObject that has a specific target.
57
+     *
58
+     * @param parser Parser that owns this object.
59
+     * @param manager Callback Manager that owns this object.
60
+     * @param type Type of callback.
61
+     */
62
+    public TwitterCallbackObjectSpecific(final Parser parser,
63
+            final CallbackManager<?> manager, final Class<? extends CallbackInterface> type) {
64
+        super(parser, manager, type);
65
+    }
66
+
67
+    /** {@inheritDoc} */
68
+    @Override
69
+    protected String translateHostname(final String hostname) {
70
+        return TwitterClientInfo.parseHost(hostname);
71
+    }
72
+
73
+    /** {@inheritDoc} */
74
+    @Override
75
+    protected Class<?> getImplementation(final Class<?> type) {
76
+        return IMPL_MAP.containsKey(type) ? IMPL_MAP.get(type) : type;
77
+    }
78
+
79
+}

+ 164
- 0
src/com/dmdirc/addons/parser_twitter/TwitterChannelClientInfo.java Dosyayı Görüntüle

@@ -0,0 +1,164 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import com.dmdirc.parser.interfaces.ChannelInfo;
27
+import com.dmdirc.parser.interfaces.ClientInfo;
28
+import java.util.Map;
29
+import java.util.HashMap;
30
+
31
+/**
32
+ * ChannelClientInfo class for the Twitter plugin.
33
+ *
34
+ * @author shane
35
+ */
36
+public class TwitterChannelClientInfo implements ChannelClientInfo {
37
+    /** My ChannelInfo.  */
38
+    private TwitterChannelInfo myChannel;
39
+    
40
+    /** My ClientInfo. */
41
+    private TwitterClientInfo myClient;
42
+
43
+    /** Map of random objects. */
44
+    final Map<Object, Object> myMap = new HashMap<Object, Object>();
45
+
46
+    /**
47
+     * Create a new TwitterChannelClientInfo
48
+     *
49
+     * @param channel Channel that this client is in.
50
+     * @param ci Client that we represent.
51
+     */
52
+    public TwitterChannelClientInfo(final TwitterChannelInfo channel, final TwitterClientInfo ci) {
53
+        this.myChannel = channel;
54
+        this.myClient = ci;
55
+
56
+        myClient.addChannelClient(this);
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public ClientInfo getClient() {
62
+        return myClient;
63
+    }
64
+
65
+    /** {@inheritDoc} */
66
+    @Override
67
+    public ChannelInfo getChannel() {
68
+        return myChannel;
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public String getImportantModePrefix() {
74
+        switch (getImportantModeValue()) {
75
+            case 1:
76
+                return "+";
77
+            case 2:
78
+                return "%";
79
+            default:
80
+                return "";
81
+        }
82
+    }
83
+
84
+    /** {@inheritDoc} */
85
+    @Override
86
+    public String getImportantMode() {
87
+        switch (getImportantModeValue()) {
88
+            case 1:
89
+                return "v";
90
+            case 2:
91
+                return "h";
92
+            default:
93
+                return "";
94
+        }
95
+    }
96
+
97
+    /**
98
+     * Get the value for the mode this client has.
99
+     * Used for sorting.
100
+     *
101
+     * @return Value for this clients modes.
102
+     */
103
+    public int getImportantModeValue() {
104
+        if (myClient == null || myClient.isFake()) { return 0; }
105
+        final String ourNickname = ((Twitter) myClient.getParser()).getApi().getDisplayUsername();
106
+        
107
+        if (ourNickname.equalsIgnoreCase(myClient.getNickname())) {
108
+            // Show ourselves as half-op
109
+            return 2;
110
+        } else if (myClient.getUser() != null && myClient.getUser().isFollowingUs()) {
111
+            // Show followers as voiced
112
+            return 1;
113
+        } else {
114
+            // Show everyone else as nothing
115
+            return 0;
116
+        }
117
+    }
118
+
119
+    /** {@inheritDoc} */
120
+    @Override
121
+    public String getAllModes() {
122
+        return getImportantModePrefix();
123
+    }
124
+
125
+    /** {@inheritDoc} */
126
+    @Override
127
+    public Map<Object, Object> getMap() {
128
+        return myMap;
129
+    }
130
+
131
+    /** {@inheritDoc} */
132
+    @Override
133
+    public void kick(final String message) {
134
+        ((Twitter)myClient.getParser()).getApi().delFriend(myClient.getUser().getScreenName());
135
+        myChannel.delChannelClient(this);
136
+        myClient.delChannelClient(this);
137
+    }
138
+
139
+    /**
140
+     * Compare this TwitterChannelClientInfo to another.
141
+     *
142
+     * @param arg0
143
+     * @return
144
+     */
145
+    @Override
146
+    public int compareTo(final ChannelClientInfo arg0) {
147
+        if (arg0 instanceof TwitterChannelClientInfo) {
148
+            final TwitterChannelClientInfo other = (TwitterChannelClientInfo) arg0;
149
+            return (this.getImportantModeValue() - other.getImportantModeValue());
150
+        }
151
+
152
+        return 0;
153
+    }
154
+
155
+    /**
156
+     * String representation of this client.
157
+     *
158
+     * @return a String representation of this client.
159
+     */
160
+    @Override
161
+    public String toString() {
162
+        return getImportantModePrefix() + myClient.getNickname();
163
+    }
164
+}

+ 281
- 0
src/com/dmdirc/addons/parser_twitter/TwitterChannelInfo.java Dosyayı Görüntüle

@@ -0,0 +1,281 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.addons.parser_twitter.api.TwitterUser;
26
+import com.dmdirc.parser.common.ChannelListModeItem;
27
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+import com.dmdirc.parser.interfaces.ChannelInfo;
29
+import com.dmdirc.parser.interfaces.ClientInfo;
30
+import com.dmdirc.parser.interfaces.Parser;
31
+import java.util.ArrayList;
32
+import java.util.Collection;
33
+import java.util.HashMap;
34
+import java.util.Map;
35
+
36
+/**
37
+ * ChannelInfo class for the Twitter plugin.
38
+ *
39
+ * @author shane
40
+ */
41
+public class TwitterChannelInfo implements ChannelInfo {
42
+    /** Name of this channel. */
43
+    private final String myName;
44
+
45
+    /** The Parser that owns this object. */
46
+    private final Twitter myParser;
47
+    
48
+    /** Topic of this channel. */
49
+    private String myTopic = "";
50
+
51
+    /** When was the topic set? */
52
+    private long topicTime = 0;
53
+
54
+    /** Who set the topic? */
55
+    private String topicSetter = "";
56
+
57
+    /** Known clients of this channel. */
58
+    private Map<String, TwitterChannelClientInfo> channelClients = new HashMap<String, TwitterChannelClientInfo>();
59
+
60
+    /** Map to store misc stuff in. */
61
+    private Map<Object, Object> myMap = new HashMap<Object, Object>();
62
+
63
+    /**
64
+     * Create a new TwitterChannelInfo.
65
+     *
66
+     * @param myName Name of this channel
67
+     * @param myParser parser that owns this TwitterChannelInfo
68
+     */
69
+    public TwitterChannelInfo(final String myName, final Twitter myParser) {
70
+        this.myName = myName;
71
+        this.myParser = myParser;
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public String getName() {
77
+        return myName;
78
+    }
79
+
80
+    /** {@inheritDoc} */
81
+    @Override
82
+    public String toString() {
83
+        return getName();
84
+    }
85
+
86
+    /** {@inheritDoc} */
87
+    @Override
88
+    public void setTopic(final String topic) {
89
+        myParser.setStatus(topic);
90
+    }
91
+
92
+    /** {@inheritDoc} */
93
+    @Override
94
+    public String getTopic() {
95
+        return myTopic;
96
+    }
97
+
98
+    /** {@inheritDoc} */
99
+    @Override
100
+    public long getTopicTime() {
101
+        return topicTime;
102
+    }
103
+
104
+    /** {@inheritDoc} */
105
+    @Override
106
+    public String getTopicSetter() {
107
+        return topicSetter;
108
+    }
109
+
110
+    /** {@inheritDoc} */
111
+    @Override
112
+    public String getModes() {
113
+        return "";
114
+    }
115
+
116
+    /** {@inheritDoc} */
117
+    @Override
118
+    public String getMode(final char mode) {
119
+        return "";
120
+    }
121
+
122
+    /** {@inheritDoc} */
123
+    @Override
124
+    public void sendMessage(final String message) {
125
+        myParser.sendMessage(myName, message);
126
+    }
127
+
128
+    /** {@inheritDoc} */
129
+    @Override
130
+    public void sendAction(final String action) {
131
+        myParser.sendAction(myName, action);
132
+    }
133
+
134
+    /** {@inheritDoc} */
135
+    @Override
136
+    public void part(final String reason) {
137
+        myParser.partChannel(this);
138
+    }
139
+
140
+    /** {@inheritDoc} */
141
+    @Override
142
+    public void sendWho() {
143
+        return;
144
+    }
145
+
146
+    /** {@inheritDoc} */
147
+    @Override
148
+    public void alterMode(final boolean add, final Character mode, final String parameter) {
149
+        if (mode == 'b') {
150
+            final String[] bits = parameter.split(" ");
151
+            if (add) {
152
+                myParser.getApi().blockUser(bits[0]);
153
+            } else {
154
+                myParser.getApi().unblockUser(bits[0]);
155
+            }
156
+        }
157
+        return;
158
+    }
159
+
160
+    /** {@inheritDoc} */
161
+    @Override
162
+    public void flushModes() {
163
+        return;
164
+    }
165
+
166
+    /** {@inheritDoc} */
167
+    @Override
168
+    public ChannelClientInfo getChannelClient(final ClientInfo client) {
169
+        return getChannelClient(client.getNickname());
170
+    }
171
+
172
+    /** {@inheritDoc} */
173
+    @Override
174
+    public ChannelClientInfo getChannelClient(final String client) {
175
+        return channelClients.containsKey(client.toLowerCase()) ? channelClients.get(client.toLowerCase()) : null;
176
+    }
177
+
178
+    /** {@inheritDoc} */
179
+    @Override
180
+    public ChannelClientInfo getChannelClient(final String client, final boolean create) {
181
+        ChannelClientInfo cci = getChannelClient(client);
182
+        if (create && cci == null) {
183
+            cci = new TwitterChannelClientInfo(this, (TwitterClientInfo)myParser.getClient(client));
184
+        }
185
+        return cci;
186
+    }
187
+
188
+    /** {@inheritDoc} */
189
+    @Override
190
+    public Collection<ChannelClientInfo> getChannelClients() {
191
+        return new ArrayList<ChannelClientInfo>(channelClients.values());
192
+    }
193
+
194
+    /** {@inheritDoc} */
195
+    protected void clearChannelClients() {
196
+        channelClients.clear();
197
+    }
198
+
199
+    /** {@inheritDoc} */
200
+    @Override
201
+    public int getChannelClientCount() {
202
+        return channelClients.size();
203
+    }
204
+
205
+    /** {@inheritDoc} */
206
+    @Override
207
+    public Parser getParser() {
208
+        return myParser;
209
+    }
210
+
211
+    /**
212
+     * Add a channel client to this channel.
213
+     *
214
+     * @param cci Channel Client to add.
215
+     */
216
+    public void addChannelClient(final TwitterChannelClientInfo cci) {
217
+        synchronized (channelClients) {
218
+            channelClients.put(cci.getClient().getNickname().toLowerCase(), cci);
219
+        }
220
+    }
221
+
222
+    /**
223
+     * Remove a channel client from this channel.
224
+     *
225
+     * @param cci Channel Client to remove.
226
+     */
227
+    public void delChannelClient(final TwitterChannelClientInfo cci) {
228
+        synchronized (channelClients) {
229
+            channelClients.remove(cci.getClient().getNickname().toLowerCase());
230
+        }
231
+    }
232
+
233
+    /** {@inheritDoc} */
234
+    @Override
235
+    public Collection<ChannelListModeItem> getListMode(final char mode) {
236
+        final ArrayList<ChannelListModeItem> items = new ArrayList<ChannelListModeItem>();
237
+
238
+        // Ideally this should be cached somewhere, but for now this will do.
239
+        if (mode == 'b') {
240
+            final long time = System.currentTimeMillis() / 1000;
241
+            for (TwitterUser user : myParser.getApi().getBlocked()) {
242
+                items.add(new ChannelListModeItem(user.getScreenName(), myParser.getApi().getDisplayUsername(), time));
243
+            }
244
+        }
245
+
246
+        return items;
247
+    }
248
+
249
+    /**
250
+     * Set the topic for this channel.
251
+     *
252
+     * @param string Topic to set.
253
+     */
254
+    void setLocalTopic(final String string) {
255
+        myTopic = string;
256
+    }
257
+
258
+    /**
259
+     * Set the topic time for this channel.
260
+     *
261
+     * @param newValue New Time
262
+     */
263
+    public void setTopicTime(final long newValue) {
264
+        topicTime = newValue;
265
+    }
266
+
267
+    /**
268
+     * Set the topic setter for this channel.
269
+     *
270
+     * @param newValue New Setter
271
+     */
272
+    public void setTopicSetter(final String newValue) {
273
+        topicSetter = newValue;
274
+    }
275
+
276
+    /** {@inheritDoc} */
277
+    @Override
278
+    public Map<Object, Object> getMap() {
279
+        return myMap;
280
+    }
281
+}

+ 280
- 0
src/com/dmdirc/addons/parser_twitter/TwitterClientInfo.java Dosyayı Görüntüle

@@ -0,0 +1,280 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.addons.parser_twitter.api.TwitterUser;
26
+import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+import com.dmdirc.parser.interfaces.LocalClientInfo;
29
+import com.dmdirc.parser.interfaces.Parser;
30
+import com.dmdirc.parser.interfaces.callbacks.ChannelNickChangeListener;
31
+import com.dmdirc.parser.interfaces.callbacks.ChannelUserModeChangeListener;
32
+import com.dmdirc.plugins.Plugin;
33
+import java.util.ArrayList;
34
+import java.util.HashMap;
35
+import java.util.List;
36
+import java.util.Map;
37
+
38
+/**
39
+ * ClientInfo class for the Twitter plugin.
40
+ *
41
+ * @author shane
42
+ */
43
+public class TwitterClientInfo implements LocalClientInfo {
44
+    /** This Clients User */
45
+    private String myUser;
46
+
47
+    /** My Parser */
48
+    private Twitter myParser;
49
+
50
+    /** Is this a fake client created just for a callback? */
51
+    private boolean isFake = false;
52
+
53
+    /** Map of random objects. */
54
+    final Map<Object, Object> myMap = new HashMap<Object, Object>();
55
+
56
+    /** List of my channelclients. */
57
+    final List<ChannelClientInfo> channelClients = new ArrayList<ChannelClientInfo>();
58
+
59
+    /**
60
+     * Parse an IRC Hostname into its separate parts.
61
+     *
62
+     * @param hostname Hostname to parse
63
+     * @return String array of nick, ident and host.
64
+     */
65
+    static String[] parseHostFull(final String hostname) {
66
+        return parseHostFull(hostname, null, null);
67
+    }
68
+
69
+    /**
70
+     * Parse an IRC Hostname into its separate parts.
71
+     *
72
+     * @param hostname Hostname to parse.
73
+     * @param plugin Plugin to use to get domain from.
74
+     * @return String array of nick, ident and host.
75
+     */
76
+    static String[] parseHostFull(String hostname, final Plugin plugin, final Twitter parser) {
77
+        boolean hadAt = false;
78
+        if (plugin != null && parser != null && parser.getConfigManager().getOptionBool(plugin.getDomain(), "autoAt")) {
79
+            if (!hostname.isEmpty() && hostname.charAt(0) == '@') {
80
+                hostname = hostname.substring(1);
81
+                hadAt = true;
82
+            }
83
+        }
84
+
85
+        String[] temp = null;
86
+        final String[] result = new String[3];
87
+        if (!hostname.isEmpty() && hostname.charAt(0) == ':') { hostname = hostname.substring(1); }
88
+        temp = hostname.split("@", 2);
89
+        if (temp.length == 1) { result[2] = ""; } else { result[2] = temp[1]; }
90
+        temp = temp[0].split("!", 2);
91
+        if (temp.length == 1) { result[1] = ""; } else { result[1] = temp[1]; }
92
+        result[0] = (hadAt ? "@" : "") + temp[0];
93
+
94
+        return result;
95
+    }
96
+
97
+    /**
98
+     * Return the nickname from an irc hostname.
99
+     *
100
+     * @param hostname host to parse
101
+     * @return nickname
102
+     */
103
+    static String parseHost(final String hostname) {
104
+        return parseHostFull(hostname)[0];
105
+    }
106
+
107
+    /**
108
+     * Create a new TwitterClientInfo
109
+     *
110
+     * @param user User object for this client.
111
+     * @param parser Parser that owns this client.
112
+     */
113
+    public TwitterClientInfo(final String user, final Twitter parser) {
114
+        this.myUser = user;
115
+        this.myParser = parser;
116
+    }
117
+
118
+    /** {@inheritDoc} */
119
+    @Override
120
+    public void setNickname(final String name) {
121
+        if (this == myParser.getLocalClient()) {
122
+            // TODO: throw new UnsupportedOperationException("Not supported yet.");
123
+        } else {
124
+            // TODO: throw new UnsupportedOperationException("Can not set nickname on non-local clients");
125
+        }
126
+    }
127
+
128
+    /**
129
+     * Get the user object for this client.
130
+     *
131
+     * @return User object for this client.
132
+     */
133
+    public TwitterUser getUser() {
134
+        return myParser.getApi().getCachedUser(myUser);
135
+    }
136
+
137
+    /**
138
+    * Check if this is a fake client.
139
+    *
140
+    * @return True if this is a fake client, else false
141
+    */
142
+    public boolean isFake() { return isFake; }
143
+    
144
+    /**
145
+    * Check if this client is actually a server.
146
+    *
147
+    * @return True if this client is actually a server.
148
+    */
149
+    public boolean isServer() { return !(myUser.indexOf(':') == -1); }
150
+    
151
+    /**
152
+    * Set if this is a fake client.
153
+    * This returns "this" and thus can be used in the construction line.
154
+    *
155
+    * @param newValue new value for isFake - True if this is a fake client, else false
156
+    * @return this Object
157
+    */
158
+    public TwitterClientInfo setFake(final boolean newValue) {
159
+        isFake = newValue;
160
+        return this;
161
+    }
162
+
163
+    /** {@inheritDoc} */
164
+    @Override
165
+    public String getModes() {
166
+        return "";
167
+    }
168
+
169
+    /** {@inheritDoc} */
170
+    @Override
171
+    public void setAway(final String reason) {
172
+        return;
173
+    }
174
+
175
+    /** {@inheritDoc} */
176
+    @Override
177
+    public void setBack() {
178
+        return;
179
+    }
180
+
181
+    /** {@inheritDoc} */
182
+    @Override
183
+    public void alterMode(final boolean add, final Character mode) {
184
+        return;
185
+    }
186
+
187
+    /** {@inheritDoc} */
188
+    @Override
189
+    public void flushModes() {
190
+        return;
191
+    }
192
+
193
+    /** {@inheritDoc} */
194
+    @Override
195
+    public String getNickname() {
196
+        return myUser;
197
+    }
198
+
199
+    /** {@inheritDoc} */
200
+    @Override
201
+    public String getUsername() {
202
+        return "user";
203
+    }
204
+
205
+    /** {@inheritDoc} */
206
+    @Override
207
+    public String getHostname() {
208
+        return "twitter.com";
209
+    }
210
+
211
+    /** {@inheritDoc} */
212
+    @Override
213
+    public String toString() {
214
+        return getNickname() + "!" + getUsername() + "@" + getHostname();
215
+    }
216
+
217
+    /** {@inheritDoc} */
218
+    @Override
219
+    public String getRealname() {
220
+        return String.format("%s - http://%s/%s", getUser().getRealName(), getHostname(), getNickname());
221
+    }
222
+
223
+    /** {@inheritDoc} */
224
+    @Override
225
+    public int getChannelCount() {
226
+        synchronized (channelClients) {
227
+            return channelClients.size();
228
+        }
229
+    }
230
+
231
+    /**
232
+     * Get a list of all the channel clients associated with this user.
233
+     * 
234
+     * @return Channel Clients for this Client.
235
+     */
236
+    public List<ChannelClientInfo> getChannelClients() {
237
+        synchronized (channelClients) {
238
+            return new ArrayList<ChannelClientInfo>(channelClients);
239
+        }
240
+    }
241
+
242
+    /** {@inheritDoc} */
243
+    @Override
244
+    public Map<Object, Object> getMap() {
245
+        return myMap;
246
+    }
247
+
248
+    /** {@inheritDoc} */
249
+    @Override
250
+    public Parser getParser() {
251
+        return myParser;
252
+    }
253
+
254
+    /**
255
+     * Add a channelClient to this Client.
256
+     * 
257
+     * @param channelClient channelClient to add as us.
258
+     */
259
+    public void addChannelClient(final TwitterChannelClientInfo channelClient) {
260
+        synchronized (channelClients) {
261
+            if (!channelClients.contains(channelClient)) {
262
+                channelClients.add(channelClient);
263
+            }
264
+        }
265
+    }
266
+
267
+    /**
268
+     * Remove a channelclient from this client..
269
+     *
270
+     * @param channelClient channelClient to remove.
271
+     */
272
+    public void delChannelClient(final TwitterChannelClientInfo channelClient) {
273
+        synchronized (channelClients) {
274
+            if (channelClients.contains(channelClient)) {
275
+                channelClients.remove(channelClient);
276
+            }
277
+        }
278
+    }
279
+
280
+}

+ 91
- 0
src/com/dmdirc/addons/parser_twitter/TwitterPlugin.java Dosyayı Görüntüle

@@ -0,0 +1,91 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter;
24
+
25
+import com.dmdirc.config.prefs.PreferencesCategory;
26
+import com.dmdirc.config.prefs.PreferencesManager;
27
+import com.dmdirc.config.prefs.PreferencesSetting;
28
+import com.dmdirc.config.prefs.PreferencesType;
29
+import com.dmdirc.parser.common.MyInfo;
30
+import com.dmdirc.parser.interfaces.Parser;
31
+import com.dmdirc.plugins.Plugin;
32
+import java.net.URI;
33
+import java.util.ArrayList;
34
+
35
+/**
36
+ *
37
+ * @author shane
38
+ */
39
+public class TwitterPlugin extends Plugin  {
40
+    /** Are we currently unloading? */
41
+    private static boolean unloading = false;
42
+
43
+    /**
44
+     * Create a TwitterPlugin
45
+     */
46
+    public TwitterPlugin() { }
47
+
48
+
49
+    @Override
50
+    public void onLoad() { }
51
+
52
+    @Override
53
+    public void onUnload() {
54
+        unloading = true;
55
+        for (Twitter parser : new ArrayList<Twitter>(Twitter.currentParsers)) {
56
+            parser.disconnect("");
57
+        }
58
+    }
59
+
60
+    /**
61
+     * Get a Twitter parser instance.
62
+     *
63
+     * @param myInfo The client information to use
64
+     * @param address The address of the server to connect to
65
+     * @return An appropriately configured parser
66
+     */
67
+    public Parser getParser(final MyInfo myInfo, final URI address) {
68
+        return (unloading) ? null : new Twitter(myInfo, address, this);
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public void showConfig(final PreferencesManager manager) {
74
+        final PreferencesCategory category = new PreferencesCategory("Twitter Plugin", "Settings related to the twitter plugin");
75
+        final PreferencesCategory advanced = new PreferencesCategory("Advanced", "Advanced Settings related to the twitter plugin");
76
+
77
+        category.addSetting(new PreferencesSetting(PreferencesType.INTEGER, getDomain(), "statuscount", "Statuses to request", "How many statuses to request at a time.?"));
78
+        category.addSetting(new PreferencesSetting(PreferencesType.INTEGER, getDomain(), "apicalls", "API Calls", "Aim to only use how many API Calls per hour? (Twitter has a max of 150)"));
79
+        category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "saveLastIDs", "Remember shown items", "Should previously shown items not be shown again next time?"));
80
+        category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "getSentMessages", "Show own Direct Messages", "Should we try to show our own direct messages to people not just ones to us?"));
81
+
82
+        advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "autoAt", "Prepend nickanmes with @", "Should all nicknmaes be shown with an @ infront of them? (Makes tab competion easier)"));
83
+        advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "replaceOpeningNickname", "Replace opening nickame?", "Should nicknames at the start of the message be replaced? (eg Replace foo: with @foo)"));
84
+        advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "debugEnabled", "Debugging Enabled?", "Should more debugging be enabled on the twitter plugin?"));
85
+        advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(), "hide500Errors", "Hide HTTP 50x Errors", "At times twitter gives a lot of 502/503 errors. Should this be hidden from you?"));
86
+
87
+        category.addSubCategory(advanced);
88
+
89
+        manager.getCategory("Plugins").addSubCategory(category);
90
+    }
91
+}

+ 57
- 0
src/com/dmdirc/addons/parser_twitter/api/APIAllowed.java Dosyayı Görüntüle

@@ -0,0 +1,57 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+/**
26
+ *
27
+ * @author shane
28
+ */
29
+public enum APIAllowed {
30
+    /** It is not known if we are allowed or not. */
31
+    UNKNOWN(false),
32
+    /** We are not allowed. */
33
+    FALSE(false),
34
+    /** We are allowed. */
35
+    TRUE(true);
36
+
37
+    /** Boolean value of this APIAllowed */
38
+    final boolean value;
39
+
40
+    /**
41
+     * Create an APIAllowed
42
+     *
43
+     * @param booleanValue boolean value for this if needed.
44
+     */
45
+    private APIAllowed(final boolean booleanValue) {
46
+        value = booleanValue;
47
+    }
48
+
49
+    /**
50
+     * Get the boolean value of this object.
51
+     *
52
+     * @return the boolean value of this object.
53
+     */
54
+    public boolean getBooleanValue() {
55
+        return value;
56
+    }
57
+}

+ 1690
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterAPI.java
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 42
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterErrorHandler.java Dosyayı Görüntüle

@@ -0,0 +1,42 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ * 
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ * 
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+/**
26
+ * Errors from the twitter API will be passed to this callback.
27
+ *
28
+ * @author shane
29
+ */
30
+public interface TwitterErrorHandler {
31
+    /**
32
+     * Handle an error from the Twitter API.
33
+     *
34
+     * @param api the TwitterAPI that raised this error.
35
+     * @param t The throwable that caused the error.
36
+     * @param source Source of exception.
37
+     * @param twitterInput The input to the API that caused this error.
38
+     * @param twitterOutput The output from the API that caused this error.
39
+     * @param message If more information should be relayed to the user, it comes here
40
+     */
41
+     void handleTwitterError(final TwitterAPI api, final Throwable t, final String source, final String twitterInput, final String twitterOutput, final String message);
42
+}

+ 58
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterException.java Dosyayı Görüntüle

@@ -0,0 +1,58 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+/**
26
+ * Exception in the twitter API!
27
+ *
28
+ * @author shane
29
+ */
30
+public class TwitterException extends Exception {
31
+
32
+    /**
33
+     * A version number for this class. It should be changed whenever the class
34
+     * structure is changed (or anything else that would prevent serialized
35
+     * objects being unserialized with the new class).
36
+     */
37
+    private static final long serialVersionUID = 1;
38
+
39
+    /**
40
+     * Create a new Twitter Exception!
41
+     *
42
+     * @param reason Reason for this exception.
43
+     */
44
+    public TwitterException(final String reason) {
45
+        super(reason);
46
+    }
47
+
48
+    /**
49
+     * Create a new Twitter Exception with a cause.
50
+     *
51
+     * @param reason Reason for this exception.
52
+     * @param cause Cause of this exception
53
+     */
54
+    public TwitterException(final String reason, final Throwable cause) {
55
+        super(reason, cause);
56
+    }
57
+
58
+}

+ 227
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterMessage.java Dosyayı Görüntüle

@@ -0,0 +1,227 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+import java.text.ParseException;
26
+import java.text.SimpleDateFormat;
27
+import org.w3c.dom.Element;
28
+import org.w3c.dom.Node;
29
+import org.w3c.dom.NodeList;
30
+
31
+/**
32
+ * Used for direct messages.
33
+ *
34
+ * @author shane
35
+ */
36
+public class TwitterMessage implements Comparable<TwitterMessage> {
37
+    /** ID of this message. */
38
+    final long id;
39
+
40
+    /** Contents of this message. */
41
+    final String message;
42
+
43
+    /** Owner of this message. */
44
+    final String sender;
45
+    
46
+    /** Target of this message. */
47
+    final String target;
48
+
49
+    /** API Object that owns this. */
50
+    private final TwitterAPI myAPI;
51
+
52
+    /** Time this message was sent. */
53
+    private final long time;
54
+
55
+    /**
56
+     * Create a new TwitterMessage
57
+     *
58
+     * @param api
59
+     * @param message Message contents
60
+     */
61
+    protected TwitterMessage(final TwitterAPI api, final String message) {
62
+        this(api, message, -1, "", "", System.currentTimeMillis());
63
+    }
64
+
65
+    /**
66
+     * Create a new TwitterMessage
67
+     *
68
+     * @param api
69
+     * @param message Message contents
70
+     * @param id ID of message
71
+     * @param sender User who send this.
72
+     * @param time Time this message was sent
73
+     */
74
+    protected TwitterMessage(final TwitterAPI api, final String message, final long id, final String sender, final String target, final Long time) {
75
+        this.myAPI = api;
76
+        this.id = id;
77
+        this.message = message;
78
+        this.sender = sender;
79
+        this.target = target;
80
+        this.time = time;
81
+    }
82
+
83
+    /**
84
+     * Create a twitter status from a node!
85
+     *
86
+     * @param api API that owns this.
87
+     * @param node Node to use.
88
+     */
89
+    protected TwitterMessage(final TwitterAPI api, final Node node) {
90
+        if (!(node instanceof Element)) { throw new TwitterRuntimeException("Can only use Element type nodes for message creation."); }
91
+        this.myAPI = api;
92
+        final Element element = (Element) node;
93
+
94
+        this.message = TwitterAPI.getElementContents(element, "text", "");
95
+
96
+        final TwitterUser senderUser;
97
+
98
+        final NodeList senderNodes = element.getElementsByTagName("sender");
99
+        if (senderNodes != null && senderNodes.getLength() > 0) {
100
+            senderUser = new TwitterUser(api, senderNodes.item(0), null);
101
+            this.sender = senderUser.getScreenName();
102
+            myAPI.updateUser(senderUser);
103
+        } else {
104
+            senderUser = new TwitterUser(api, "unknown", -1, "realname", false);
105
+            this.sender = senderUser.getScreenName();
106
+        }
107
+
108
+        final TwitterUser targetUser;
109
+        final NodeList recipientNodes = element.getElementsByTagName("recipient");
110
+        if (recipientNodes != null && recipientNodes.getLength() > 0) {
111
+            targetUser = new TwitterUser(api, recipientNodes.item(0), null);
112
+            this.target = targetUser.getScreenName();
113
+            myAPI.updateUser(targetUser);
114
+        } else {
115
+            targetUser = new TwitterUser(api, "unknown", -1, "realname", false);
116
+            this.target = targetUser.getScreenName();
117
+        }
118
+
119
+        this.id = TwitterAPI.parseLong(TwitterAPI.getElementContents(element, "id", ""), -1);
120
+        this.time = TwitterAPI.timeStringToLong(TwitterAPI.getElementContents(element, "created_at", ""), 0);
121
+    }
122
+
123
+    /**
124
+     * Get the screen name of the user who sent this message.
125
+     *
126
+     * @return Screen name of the user who sent this message.
127
+     */
128
+    public String getSenderScreenName() {
129
+        return sender;
130
+    }
131
+
132
+    /**
133
+     * Get the user who sent this message.
134
+     *
135
+     * @return The user who sent this message.
136
+     */
137
+    public TwitterUser getSender() {
138
+        return myAPI.getCachedUser(sender);
139
+    }
140
+
141
+    /**
142
+     * Get the screen name of the user who received this message.
143
+     *
144
+     * @return Screen name of the user who received this message.
145
+     */
146
+    public String getTargetScreenName() {
147
+        return target;
148
+    }
149
+
150
+    /**
151
+     * Get the user who received this message.
152
+     *
153
+     * @return The user who received this message.
154
+     */
155
+    public TwitterUser getTarget() {
156
+        return myAPI.getCachedUser(target);
157
+    }
158
+    
159
+    /**
160
+     * Get the ID of this message.
161
+     *
162
+     * @return ID of this message.
163
+     */
164
+    public long getID() {
165
+        return id;
166
+    }
167
+
168
+    /**
169
+     * What time was this message sent?
170
+     *
171
+     * @return Time this message was sent.
172
+     */
173
+    public long getTime() {
174
+        return this.time;
175
+    }
176
+
177
+    /**
178
+     * Get the contents of this message.
179
+     *
180
+     * @return contents of this message.
181
+     */
182
+    public String getText() {
183
+        return message;
184
+    }
185
+
186
+    /**
187
+     * Is this equal to the given Status?
188
+     * @param message
189
+     * @return
190
+     */
191
+    @Override
192
+    public boolean equals(final Object message) {
193
+        if (message instanceof TwitterMessage) {
194
+            return ((TwitterMessage)message).getID() == this.id;
195
+        } else {
196
+            return false;
197
+        }
198
+    }
199
+
200
+    /**
201
+     * Generate hashCode for this object.
202
+     * @return
203
+     */
204
+    @Override
205
+    public int hashCode() {
206
+        int hash = 5;
207
+        hash = 53 * hash + (int) (this.id ^ (this.id >>> 32));
208
+        return hash;
209
+    }
210
+
211
+    /**
212
+     * Compare the given object to this one.
213
+     *
214
+     * @param arg0
215
+     * @return Comparison
216
+     */
217
+    @Override
218
+    public int compareTo(final TwitterMessage arg0) {
219
+        if (this.time < arg0.getTime()) {
220
+            return -1;
221
+        } else if (this.time > arg0.getTime()) {
222
+            return 1;
223
+        } else {
224
+            return 0;
225
+        }
226
+    }
227
+}

+ 46
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterRawHandler.java Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ * 
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ * 
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+/**
26
+ * Raw output from the twitter API will be passed to this callback.
27
+ *
28
+ * @author shane
29
+ */
30
+public interface TwitterRawHandler {
31
+    /**
32
+     * Handle input from twitter.
33
+     *
34
+     * @param api the TwitterAPI that recieved this input.
35
+     * @param data The raw data to handle.
36
+     */
37
+     void handleRawTwitterInput(final TwitterAPI api, final String data);
38
+
39
+    /**
40
+     * Handle an output to twitter.
41
+     *
42
+     * @param api the TwitterAPI that sent this output.
43
+     * @param data The raw data to handle.
44
+     */
45
+     void handleRawTwitterOutput(final TwitterAPI api, final String data);
46
+}

+ 58
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterRuntimeException.java Dosyayı Görüntüle

@@ -0,0 +1,58 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+/**
26
+ * Exception in the twitter API!
27
+ *
28
+ * @author shane
29
+ */
30
+public class TwitterRuntimeException extends RuntimeException {
31
+
32
+    /**
33
+     * A version number for this class. It should be changed whenever the class
34
+     * structure is changed (or anything else that would prevent serialized
35
+     * objects being unserialized with the new class).
36
+     */
37
+    private static final long serialVersionUID = 1;
38
+
39
+    /**
40
+     * Create a new Twitter Exception!
41
+     *
42
+     * @param reason Reason for this exception.
43
+     */
44
+    public TwitterRuntimeException(final String reason) {
45
+        super(reason);
46
+    }
47
+
48
+    /**
49
+     * Create a new Twitter Exception with a cause.
50
+     *
51
+     * @param reason Reason for this exception.
52
+     * @param cause Cause of this exception
53
+     */
54
+    public TwitterRuntimeException(final String reason, final Throwable cause) {
55
+        super(reason, cause);
56
+    }
57
+
58
+}

+ 287
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterStatus.java Dosyayı Görüntüle

@@ -0,0 +1,287 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+import com.dmdirc.addons.parser_twitter.api.commons.StringEscapeUtils;
26
+import org.w3c.dom.Element;
27
+import org.w3c.dom.Node;
28
+import org.w3c.dom.NodeList;
29
+
30
+/**
31
+ * Used for status messages.
32
+ *
33
+ * @author shane
34
+ */
35
+public class TwitterStatus implements Comparable<TwitterStatus> {
36
+    /** The ID this message was in reply to. */
37
+    private long replyID;
38
+
39
+    /** The ID of this message */
40
+    private final long id;
41
+
42
+    /** The time of this message */
43
+    private final long time;
44
+
45
+    /** The user who owns this message
46
+     * (In the case of a retweet, this will be the retweeter)
47
+     */
48
+    private final String user;
49
+
50
+    /**
51
+     * The contents of this message.
52
+     * (In the case of a retweet, this will be the retweeted message)
53
+     */
54
+    private final String message;
55
+
56
+    /** API Object that owns this. */
57
+    private final TwitterAPI myAPI;
58
+
59
+    /** Is this a retweet? */
60
+    private final boolean retweet;
61
+
62
+    /** The original tweet of this message */
63
+    private final TwitterStatus originalStatus;
64
+
65
+    /**
66
+     * Create a new TwitterStatus.
67
+     * (Used for creating new status updates.)
68
+     *
69
+     * @param api API that owns this.
70
+     * @param message Message for this status.
71
+     * @param replyID Id to reply to (or -1);
72
+     */
73
+    protected TwitterStatus(final TwitterAPI api, final String message, final long replyID) {
74
+        this(api, message, replyID, -1, null, System.currentTimeMillis());
75
+    }
76
+
77
+    /**
78
+     * Create a new TwitterStatus.
79
+     *
80
+     * @param api API that owns this.
81
+     * @param replyID ID this is in reply to
82
+     * @param id ID of this message
83
+     * @param user User for this message
84
+     * @param message Message!
85
+     * @param time
86
+     */
87
+    protected TwitterStatus(final TwitterAPI api, final String message, final long replyID, final long id, final String user, final long time) {
88
+        this.myAPI = api;
89
+        this.replyID = replyID;
90
+        this.id = id;
91
+        this.user = user;
92
+        this.message = message;
93
+        this.time = time;
94
+        this.retweet = false;
95
+        this.originalStatus = null;
96
+
97
+        api.updateStatus(this);
98
+    }
99
+
100
+    /**
101
+     * Create a twitter status from an element!
102
+     *
103
+     * @param api API that owns this.
104
+     * @param node Node to use.
105
+     */
106
+    protected TwitterStatus(final TwitterAPI api, final Node node) {
107
+        this(api, node, null);
108
+    }
109
+
110
+    /**
111
+     * Create a twitter status from a node!
112
+     *
113
+     * @param api API that owns this.
114
+     * @param node Node to use.
115
+     * @param user User who this status belongs to.
116
+     */
117
+    protected TwitterStatus(final TwitterAPI api, final Node node, final String user) {
118
+        if (!(node instanceof Element)) { throw new TwitterRuntimeException("Can only use Element type nodes for status creation."); }
119
+        this.myAPI = api;
120
+        final Element element = (Element) node;
121
+
122
+        // Get retweet status if it exists
123
+        final NodeList retweetNodes = element.getElementsByTagName("retweeted_status");
124
+        if (retweetNodes != null && retweetNodes.getLength() > 0) {
125
+            this.retweet = true;
126
+            this.originalStatus = new TwitterStatus(api, retweetNodes.item(0));
127
+            element.removeChild(retweetNodes.item(0));
128
+        } else {
129
+            this.retweet = false;
130
+            this.originalStatus = null;
131
+        }
132
+
133
+        this.message = StringEscapeUtils.unescapeHtml(TwitterAPI.getElementContents(element, "text", "").replace('\n', ' '));
134
+
135
+        this.id = TwitterAPI.parseLong(TwitterAPI.getElementContents(element, "id", ""), -1);
136
+        this.replyID = TwitterAPI.parseLong(TwitterAPI.getElementContents(element, "in_reply_to_status_id", ""), -1);
137
+        
138
+        this.time = TwitterAPI.timeStringToLong(TwitterAPI.getElementContents(element, "created_at", ""), 0);
139
+
140
+        final TwitterUser userUser;
141
+        if (user == null) {
142
+            final NodeList nodes = element.getElementsByTagName("user");
143
+            if (nodes != null && nodes.getLength() > 0) {
144
+                userUser = new TwitterUser(api, nodes.item(0), this);
145
+                this.user = userUser.getScreenName();
146
+                myAPI.updateUser(userUser);
147
+            } else {
148
+                userUser = new TwitterUser(api, "name", -1, "realname", false);
149
+                this.user = userUser.getScreenName();
150
+            }
151
+        } else {
152
+            this.user = user;
153
+        }
154
+
155
+        api.updateStatus(this);
156
+    }
157
+
158
+
159
+    /**
160
+     * Get the ID of this message
161
+     *
162
+     * @return ID of this message. (-1 if not known)
163
+     */
164
+    public long getID() {
165
+        return (this.retweet) ? this.originalStatus.getID() : this.id;
166
+    }
167
+
168
+    /**
169
+     * Get the owner of this message
170
+     *
171
+     * @return owner of this message. (null if not known)
172
+     */
173
+    public TwitterUser getUser() {
174
+        return (this.retweet) ? this.originalStatus.getUser() : myAPI.getUser(this.user);
175
+    }
176
+
177
+    /**
178
+     * Get the contents of this message
179
+     *
180
+     * @return contents of this message.
181
+     */
182
+    public String getText() {
183
+        return (this.retweet) ? this.originalStatus.getText() : this.message;
184
+    }
185
+
186
+    /**
187
+     * What message is this in reply to?
188
+     *
189
+     * @return reply ID or -1 if this message isn't replying to anything.
190
+     */
191
+    public long getReplyTo() {
192
+        return this.replyID;
193
+    }
194
+
195
+    /**
196
+     * What time was this message sent?
197
+     *
198
+     * @return Time this message was sent.
199
+     */
200
+    public long getTime() {
201
+        return this.time;
202
+    }
203
+
204
+    /**
205
+     * Is this status a retweet?
206
+     *
207
+     * @return true is this is a retweet.
208
+     */
209
+    public boolean isRetweet() {
210
+        return this.retweet;
211
+    }
212
+
213
+    /**
214
+     * Get the user who retweeted this message.
215
+     * If this is not a retweet, this will return the same as getUser();
216
+     *
217
+     * @return user who retweeted this message. (null if not known)
218
+     *         If this is not a retweet, this will return the same as getUser();
219
+     */
220
+    public TwitterUser getRetweetUser() {
221
+        return myAPI.getUser(this.user);
222
+    }
223
+
224
+    /**
225
+     * Get the retweed version of this message
226
+     * If this is not a retweet, this will return the same as getText();
227
+     *
228
+     * @return retweeted version of this message.
229
+     *         If this is not a retweet, this will return the same as getText();
230
+     */
231
+    public String getRetweetText() {
232
+        return this.message;
233
+    }
234
+
235
+    /**
236
+     * Get the retweed ID of this message.
237
+     * If this is not a retweet, this will return the same as getID();
238
+     *
239
+     * @return retweeted ID of this message.
240
+     *         If this is not a retweet, this will return the same as getID();
241
+     */
242
+    public long getRetweetId() {
243
+        return this.id;
244
+    }
245
+
246
+    /**
247
+     * Is this equal to the given Status?
248
+     * @param status
249
+     * @return 
250
+     */
251
+    @Override
252
+    public boolean equals(final Object status) {
253
+        if (status instanceof TwitterStatus) {
254
+            return ((TwitterStatus)status).getID() == this.id;
255
+        } else {
256
+            return false;
257
+        }
258
+    }
259
+
260
+    /**
261
+     * Generate hashCode for this object.
262
+     * @return
263
+     */
264
+    @Override
265
+    public int hashCode() {
266
+        int hash = 5;
267
+        hash = 53 * hash + (int) (this.id ^ (this.id >>> 32));
268
+        return hash;
269
+    }
270
+
271
+    /**
272
+     * Compare the given object to this one.
273
+     *
274
+     * @param arg0
275
+     * @return Comparison
276
+     */
277
+    @Override
278
+    public int compareTo(final TwitterStatus arg0) {
279
+        if (this.time < arg0.getTime()) {
280
+            return -1;
281
+        } else if (this.time > arg0.getTime()) {
282
+            return 1;
283
+        } else {
284
+            return 0;
285
+        }
286
+    }
287
+}

+ 292
- 0
src/com/dmdirc/addons/parser_twitter/api/TwitterUser.java Dosyayı Görüntüle

@@ -0,0 +1,292 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ *
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ *
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+import org.w3c.dom.Element;
26
+import org.w3c.dom.Node;
27
+import org.w3c.dom.NodeList;
28
+
29
+/**
30
+ *
31
+ * @author shane
32
+ */
33
+public class TwitterUser {
34
+    /** What is the screen name of this user? */
35
+    private final String screenName;
36
+
37
+    /** What is the user id of this user? */
38
+    private final long userID;
39
+    
40
+    /** What is the real name of this user? */
41
+    private final String realName;
42
+
43
+    /** Are we following the user? */
44
+    private final boolean following;
45
+
46
+    /** Is the user following us? */
47
+    private boolean followingUs = false;
48
+
49
+    /** What was the last status of this user? */
50
+    private final TwitterStatus lastStatus;
51
+
52
+    /** API Object that owns this. */
53
+    private final TwitterAPI myAPI;
54
+
55
+    /** URL to users profile picture. */
56
+    private String myProfilePicture;
57
+
58
+    /** URL from users profile. */
59
+    private String myURL;
60
+
61
+    /** Location of user */
62
+    private String myLocation;
63
+
64
+    /** Description of user */
65
+    private String myDescription;
66
+
67
+    /** Time user registered with twitter. */
68
+    private Long myRegisteredTime;
69
+
70
+    /**
71
+     * Create a unknown TwitterUser
72
+     *
73
+     * @param api 
74
+     * @param screenName Screen name for the user.
75
+     */
76
+    protected TwitterUser(final TwitterAPI api, final String screenName) {
77
+        this(api, screenName, -1, "", false);
78
+    }
79
+
80
+    /**
81
+     * Create a new TwitterUser
82
+     *
83
+     * @param api
84
+     * @param screenName Screen name for the user.
85
+     * @param userID User ID for the user.
86
+     * @param realName Realname for the user.
87
+     * @param following Are we following the user?
88
+     */
89
+    protected TwitterUser(final TwitterAPI api, final String screenName, final long userID, final String realName, final boolean following) {
90
+        this.myAPI = api;
91
+        this.screenName = screenName;
92
+        this.userID = userID;
93
+        this.realName = realName;
94
+        this.following = following;
95
+        this.lastStatus = null;
96
+        this.myProfilePicture = "";
97
+        this.myURL = "";
98
+        this.myLocation = "";
99
+        this.myDescription = "";
100
+        this.myRegisteredTime = 0L;
101
+    }
102
+
103
+    /**
104
+     * Create a twitter user from a node!
105
+     *
106
+     * @param api
107
+     * @param node Node to use.
108
+     */
109
+    protected TwitterUser(final TwitterAPI api, final Node node) {
110
+        this(api, node, null);
111
+    }
112
+
113
+    /**
114
+     * Create a twitter user from a node, with a pre-defined status.
115
+     *
116
+     * @param api
117
+     * @param node Node to use.
118
+     * @param status Status to use
119
+     */
120
+    protected TwitterUser(final TwitterAPI api, final Node node, final TwitterStatus status) {
121
+        if (!(node instanceof Element)) { throw new TwitterRuntimeException("Can only use Element type nodes for user creation."); }
122
+
123
+        final Element element = (Element) node;
124
+        this.myAPI = api;
125
+
126
+        this.realName = TwitterAPI.getElementContents(element, "name", "");
127
+        this.screenName = (api.autoAt() ? "@" : "") + TwitterAPI.getElementContents(element, "screen_name", "");
128
+        
129
+        this.myProfilePicture = TwitterAPI.getElementContents(element, "profile_image_url", "");
130
+        this.myURL = TwitterAPI.getElementContents(element, "url", "");
131
+        this.myLocation = TwitterAPI.getElementContents(element, "location", "");
132
+        this.myDescription = TwitterAPI.getElementContents(element, "description", "");
133
+
134
+        this.myRegisteredTime = TwitterAPI.timeStringToLong(TwitterAPI.getElementContents(element, "created_at", ""), 0);
135
+
136
+        this.userID = TwitterAPI.parseLong(TwitterAPI.getElementContents(element, "id", ""), -1);
137
+        this.following = TwitterAPI.parseBoolean(TwitterAPI.getElementContents(element, "following", ""));
138
+
139
+        // Check to see if a cached user object for us exists that we can
140
+        // take some information from.
141
+        final TwitterUser oldUser = api.getCachedUser(this.screenName);
142
+
143
+        // First, are they following us back do we know?
144
+        if (oldUser != null) {
145
+            this.followingUs = oldUser.isFollowingUs();
146
+        }
147
+
148
+        TwitterStatus newStatus = null;
149
+        boolean useOldStatus = true;
150
+
151
+        // Now set the status, using either the oldStatus, the given status or null!
152
+        if (status == null) {
153
+            final TwitterStatus proposedStatus;
154
+            final NodeList nodes = element.getElementsByTagName("status");
155
+            if (nodes != null && nodes.getLength() > 0) {
156
+                proposedStatus = new TwitterStatus(api, nodes.item(0), this.getScreenName());
157
+                if (oldUser == null || oldUser.getStatus() == null || oldUser.getStatus().getID() < proposedStatus.getID()) {
158
+                    useOldStatus = false;
159
+                    newStatus = proposedStatus;
160
+                }
161
+            } else if (oldUser == null || oldUser.getStatus() == null) {
162
+                useOldStatus = false;
163
+                newStatus = new TwitterStatus(api, "", -1, -1, this.getScreenName(), System.currentTimeMillis());
164
+            }
165
+        } else {
166
+            // Keep the status from the old version of this user if it has a
167
+            // higher ID, regardless of the fact we were given a specific
168
+            // status to use.
169
+            if (oldUser == null || oldUser.getStatus() == null || oldUser.getStatus().getRetweetId() < status.getRetweetId()) {
170
+                useOldStatus = false;
171
+                newStatus = status;
172
+            }
173
+        }
174
+
175
+        if (useOldStatus && oldUser != null && oldUser.getStatus() != null) {
176
+            newStatus = oldUser.getStatus();
177
+        }
178
+
179
+        this.lastStatus = newStatus;
180
+    }
181
+
182
+
183
+    /**
184
+     * Get the screen name for this user.
185
+     *
186
+     * @return this users screen name.
187
+     */
188
+    public String getScreenName() {
189
+        return screenName;
190
+    }
191
+    
192
+    /**
193
+     * Get the id for this user.
194
+     * 
195
+     * @return this users id.
196
+     */
197
+    public long getID() {
198
+        return userID;
199
+    }
200
+
201
+    /**
202
+     * Get the real name for this user.
203
+     * 
204
+     * @return this users real name.
205
+     */
206
+    public String getRealName() {
207
+        return realName;
208
+    }
209
+
210
+    /**
211
+     * Are we following this user?
212
+     * 
213
+     * @return True if we are following this user, else false.
214
+     */
215
+    public boolean isFollowing() {
216
+        return following;
217
+    }
218
+
219
+    /**
220
+     * Get the last known status of this user
221
+     *
222
+     * @return Last known status.
223
+     */
224
+    public TwitterStatus getStatus() {
225
+        return lastStatus;
226
+    }
227
+
228
+    /**
229
+     * Are we being followed by this user?
230
+     *
231
+     * @return True if we are being followed by this user, else false.
232
+     */
233
+    public boolean isFollowingUs() {
234
+        return followingUs;
235
+    }
236
+
237
+    /**
238
+     * Change if this user is following us.
239
+     *
240
+     * @param followingUs The new value for this setting.
241
+     */
242
+    public void setFollowingUs(final boolean followingUs) {
243
+        this.followingUs = followingUs;
244
+    }
245
+
246
+    /**
247
+     * URL for users profile pic.
248
+     *
249
+     * @return URL for users profile pic.
250
+     */
251
+    public String getProfilePicture() {
252
+        return myProfilePicture;
253
+    }
254
+
255
+    /**
256
+     * URL for user.
257
+     *
258
+     * @return URL for user.
259
+     */
260
+    public String getURL() {
261
+        return myURL;
262
+    }
263
+
264
+    /**
265
+     * Description for user.
266
+     *
267
+     * @return Description for user.
268
+     */
269
+    public String getDescription() {
270
+        return myDescription;
271
+    }
272
+
273
+    /**
274
+     * Location for user.
275
+     *
276
+     * @return Location for user.
277
+     */
278
+    public String getLocation() {
279
+        return myLocation;
280
+    }
281
+
282
+    /**
283
+     * Time user registered at.
284
+     *
285
+     * @return Time user registered at.
286
+     */
287
+    public Long getRegisteredTime() {
288
+        return myRegisteredTime;
289
+    }
290
+
291
+
292
+}

+ 153
- 0
src/com/dmdirc/addons/parser_twitter/api/XMLResponse.java Dosyayı Görüntüle

@@ -0,0 +1,153 @@
1
+/*
2
+ *  Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ *  of this software and associated documentation files (the "Software"), to deal
6
+ *  in the Software without restriction, including without limitation the rights
7
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ *  copies of the Software, and to permit persons to whom the Software is
9
+ *  furnished to do so, subject to the following conditions:
10
+ * 
11
+ *  The above copyright notice and this permission notice shall be included in
12
+ *  all copies or substantial portions of the Software.
13
+ * 
14
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ *  SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_twitter.api;
24
+
25
+import java.io.IOException;
26
+import java.net.HttpURLConnection;
27
+import org.w3c.dom.Document;
28
+import org.w3c.dom.Element;
29
+import org.w3c.dom.NodeList;
30
+
31
+/**
32
+ *
33
+ * @author shane
34
+ */
35
+public class XMLResponse {
36
+    /** The HttpURLConnection that was used. */
37
+    private final HttpURLConnection request;
38
+
39
+    /** The Document that was returned (if any). */
40
+    private final Document document;
41
+
42
+    /**
43
+     * Create a new XMLResponse
44
+     *
45
+     * @param request Request of response
46
+     * @param doc Document for response.
47
+     */
48
+    public XMLResponse(final HttpURLConnection request, final Document doc) {
49
+        this.request = request;
50
+        this.document = doc;
51
+    }
52
+
53
+    /**
54
+     * Get the Document for this response.
55
+     *
56
+     * @return the Document for this response.
57
+     */
58
+    public Document getDocument() {
59
+        return document;
60
+    }
61
+
62
+    /**
63
+     * Get the HttpURLConnection for this response.
64
+     *
65
+     * @return the HttpURLConnection for this response.
66
+     */
67
+    public HttpURLConnection getRequest() {
68
+        return request;
69
+    }
70
+
71
+    /**
72
+     * Was this an error?
73
+     *
74
+     * @return True if an error element exists in the document, there is no
75
+     *         document, or a non-200 status code was returned.
76
+     */
77
+    public boolean isError() {
78
+        return !(getError().isEmpty());
79
+    }
80
+
81
+    /**
82
+     * Get the contents of this error.
83
+     * If an error element is found then the contents will be returned, else
84
+     * a description of the status code if non-200, or "" if no error.
85
+     *
86
+     * @return The contents of this error.
87
+     */
88
+    public String getError() {
89
+        if (document == null || request == null) {
90
+            return "No document or request found.";
91
+        } else {
92
+            final String error = TwitterAPI.getElementContents(getDocumentElement(), "error", "");
93
+            if (error.isEmpty()) {
94
+                try {
95
+                    if (request.getResponseCode() != 200) {
96
+                        return "(" + request.getResponseCode() + ") " + request.getResponseMessage();
97
+                    }
98
+                } catch (IOException ex) {
99
+                    return "Error obtaining response code: "+ex;
100
+                }
101
+            } else {
102
+                return error;
103
+            }
104
+        }
105
+
106
+        return "";
107
+    }
108
+
109
+    /**
110
+     * Get the Document Element from the Document or null on error.
111
+     *
112
+     * @return The Document Element from the Document or null on error.
113
+     */
114
+    public Element getDocumentElement() {
115
+        return (document == null) ? null : document.getDocumentElement();
116
+    }
117
+
118
+    /**
119
+     * Return the elements that match the given name, or null on error.
120
+     *
121
+     * @param name The element name to look for.
122
+     * @return The elements that match the given name, or null on error.
123
+     */
124
+    public NodeList getElementsByTagName(final String name) {
125
+        return (document == null) ? null : document.getElementsByTagName(name);
126
+    }
127
+
128
+    /**
129
+     * Get the response code from the request.
130
+     * 
131
+     * @return The response code, or 0 on error.
132
+     */
133
+    public int getResponseCode() {
134
+        if (request != null) {
135
+            try {
136
+                return request.getResponseCode();
137
+            } catch (IOException ex) { }
138
+        }
139
+
140
+        return 0;
141
+    }
142
+
143
+    /**
144
+     * Checks to see if the response code was 200, the document is not null
145
+     * and no error element is in the document.
146
+     * 
147
+     * @return true if the response code was 200, the document is not null
148
+     * and no error element is in the document.
149
+     */
150
+    public boolean isGood() {
151
+        return getResponseCode() == 200 && getDocument() != null && !isError();
152
+    }
153
+}

+ 1010
- 0
src/com/dmdirc/addons/parser_twitter/api/commons/Entities.java
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 364
- 0
src/com/dmdirc/addons/parser_twitter/api/commons/IntHashMap.java Dosyayı Görüntüle

@@ -0,0 +1,364 @@
1
+/*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements.  See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License.  You may obtain a copy of the License at
8
+ * 
9
+ *      http://www.apache.org/licenses/LICENSE-2.0
10
+ * 
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+/*
19
+ * Note: originally released under the GNU LGPL v2.1, 
20
+ * but rereleased by the original author under the ASF license (above).
21
+ */
22
+package com.dmdirc.addons.parser_twitter.api.commons;
23
+
24
+/**
25
+ * <p>A hash map that uses primitive ints for the key rather than objects.</p>
26
+ *
27
+ * <p>Note that this class is for internal optimization purposes only, and may
28
+ * not be supported in future releases of Apache Commons Lang.  Utilities of
29
+ * this sort may be included in future releases of Apache Commons Collections.</p>
30
+ *
31
+ * @author Justin Couch
32
+ * @author Alex Chaffee (alex@apache.org)
33
+ * @author Stephen Colebourne
34
+ * @since 2.0
35
+ * @version $Revision$
36
+ * @see java.util.HashMap
37
+ */
38
+class IntHashMap {
39
+
40
+    /**
41
+     * The hash table data.
42
+     */
43
+    private transient Entry table[];
44
+
45
+    /**
46
+     * The total number of entries in the hash table.
47
+     */
48
+    private transient int count;
49
+
50
+    /**
51
+     * The table is rehashed when its size exceeds this threshold.  (The
52
+     * value of this field is (int)(capacity * loadFactor).)
53
+     *
54
+     * @serial
55
+     */
56
+    private int threshold;
57
+
58
+    /**
59
+     * The load factor for the hashtable.
60
+     *
61
+     * @serial
62
+     */
63
+    private float loadFactor;
64
+
65
+    /**
66
+     * <p>Innerclass that acts as a datastructure to create a new entry in the
67
+     * table.</p>
68
+     */
69
+    private static class Entry {
70
+        int hash;
71
+//        int key;    // not used currently
72
+        Object value;
73
+        Entry next;
74
+
75
+        /**
76
+         * <p>Create a new entry with the given values.</p>
77
+         *
78
+         * @param hash The code used to hash the object with
79
+         * @param key The key used to enter this in the table
80
+         * @param value The value for this key
81
+         * @param next A reference to the next entry in the table
82
+         */
83
+        protected Entry(int hash, int key, Object value, Entry next) {
84
+            this.hash = hash;
85
+//            this.key = key;
86
+            this.value = value;
87
+            this.next = next;
88
+        }
89
+    }
90
+
91
+    /**
92
+     * <p>Constructs a new, empty hashtable with a default capacity and load
93
+     * factor, which is <code>20</code> and <code>0.75</code> respectively.</p>
94
+     */
95
+    public IntHashMap() {
96
+        this(20, 0.75f);
97
+    }
98
+
99
+    /**
100
+     * <p>Constructs a new, empty hashtable with the specified initial capacity
101
+     * and default load factor, which is <code>0.75</code>.</p>
102
+     *
103
+     * @param  initialCapacity the initial capacity of the hashtable.
104
+     * @throws IllegalArgumentException if the initial capacity is less
105
+     *   than zero.
106
+     */
107
+    public IntHashMap(int initialCapacity) {
108
+        this(initialCapacity, 0.75f);
109
+    }
110
+
111
+    /**
112
+     * <p>Constructs a new, empty hashtable with the specified initial
113
+     * capacity and the specified load factor.</p>
114
+     *
115
+     * @param initialCapacity the initial capacity of the hashtable.
116
+     * @param loadFactor the load factor of the hashtable.
117
+     * @throws IllegalArgumentException  if the initial capacity is less
118
+     *             than zero, or if the load factor is nonpositive.
119
+     */
120
+    public IntHashMap(int initialCapacity, float loadFactor) {
121
+        super();
122
+        if (initialCapacity < 0) {
123
+            throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
124
+        }
125
+        if (loadFactor <= 0) {
126
+            throw new IllegalArgumentException("Illegal Load: " + loadFactor);
127
+        }
128
+        if (initialCapacity == 0) {
129
+            initialCapacity = 1;
130
+        }
131
+
132
+        this.loadFactor = loadFactor;
133
+        table = new Entry[initialCapacity];
134
+        threshold = (int) (initialCapacity * loadFactor);
135
+    }
136
+
137
+    /**
138
+     * <p>Returns the number of keys in this hashtable.</p>
139
+     *
140
+     * @return  the number of keys in this hashtable.
141
+     */
142
+    public int size() {
143
+        return count;
144
+    }
145
+
146
+    /**
147
+     * <p>Tests if this hashtable maps no keys to values.</p>
148
+     *
149
+     * @return  <code>true</code> if this hashtable maps no keys to values;
150
+     *          <code>false</code> otherwise.
151
+     */
152
+    public boolean isEmpty() {
153
+        return count == 0;
154
+    }
155
+
156
+    /**
157
+     * <p>Tests if some key maps into the specified value in this hashtable.
158
+     * This operation is more expensive than the <code>containsKey</code>
159
+     * method.</p>
160
+     *
161
+     * <p>Note that this method is identical in functionality to containsValue,
162
+     * (which is part of the Map interface in the collections framework).</p>
163
+     *
164
+     * @param      value   a value to search for.
165
+     * @return     <code>true</code> if and only if some key maps to the
166
+     *             <code>value</code> argument in this hashtable as
167
+     *             determined by the <tt>equals</tt> method;
168
+     *             <code>false</code> otherwise.
169
+     * @throws  NullPointerException  if the value is <code>null</code>.
170
+     * @see        #containsKey(int)
171
+     * @see        #containsValue(Object)
172
+     * @see        java.util.Map
173
+     */
174
+    public boolean contains(Object value) {
175
+        if (value == null) {
176
+            throw new NullPointerException();
177
+        }
178
+
179
+        Entry tab[] = table;
180
+        for (int i = tab.length; i-- > 0;) {
181
+            for (Entry e = tab[i]; e != null; e = e.next) {
182
+                if (e.value.equals(value)) {
183
+                    return true;
184
+                }
185
+            }
186
+        }
187
+        return false;
188
+    }
189
+
190
+    /**
191
+     * <p>Returns <code>true</code> if this HashMap maps one or more keys
192
+     * to this value.</p>
193
+     *
194
+     * <p>Note that this method is identical in functionality to contains
195
+     * (which predates the Map interface).</p>
196
+     *
197
+     * @param value value whose presence in this HashMap is to be tested.
198
+     * @return boolean <code>true</code> if the value is contained
199
+     * @see    java.util.Map
200
+     * @since JDK1.2
201
+     */
202
+    public boolean containsValue(Object value) {
203
+        return contains(value);
204
+    }
205
+
206
+    /**
207
+     * <p>Tests if the specified object is a key in this hashtable.</p>
208
+     *
209
+     * @param  key  possible key.
210
+     * @return <code>true</code> if and only if the specified object is a
211
+     *    key in this hashtable, as determined by the <tt>equals</tt>
212
+     *    method; <code>false</code> otherwise.
213
+     * @see #contains(Object)
214
+     */
215
+    public boolean containsKey(int key) {
216
+        Entry tab[] = table;
217
+        int hash = key;
218
+        int index = (hash & 0x7FFFFFFF) % tab.length;
219
+        for (Entry e = tab[index]; e != null; e = e.next) {
220
+            if (e.hash == hash) {
221
+                return true;
222
+            }
223
+        }
224
+        return false;
225
+    }
226
+
227
+    /**
228
+     * <p>Returns the value to which the specified key is mapped in this map.</p>
229
+     *
230
+     * @param   key   a key in the hashtable.
231
+     * @return  the value to which the key is mapped in this hashtable;
232
+     *          <code>null</code> if the key is not mapped to any value in
233
+     *          this hashtable.
234
+     * @see     #put(int, Object)
235
+     */
236
+    public Object get(int key) {
237
+        Entry tab[] = table;
238
+        int hash = key;
239
+        int index = (hash & 0x7FFFFFFF) % tab.length;
240
+        for (Entry e = tab[index]; e != null; e = e.next) {
241
+            if (e.hash == hash) {
242
+                return e.value;
243
+            }
244
+        }
245
+        return null;
246
+    }
247
+
248
+    /**
249
+     * <p>Increases the capacity of and internally reorganizes this
250
+     * hashtable, in order to accommodate and access its entries more
251
+     * efficiently.</p>
252
+     *
253
+     * <p>This method is called automatically when the number of keys
254
+     * in the hashtable exceeds this hashtable's capacity and load
255
+     * factor.</p>
256
+     */
257
+    protected void rehash() {
258
+        int oldCapacity = table.length;
259
+        Entry oldMap[] = table;
260
+
261
+        int newCapacity = oldCapacity * 2 + 1;
262
+        Entry newMap[] = new Entry[newCapacity];
263
+
264
+        threshold = (int) (newCapacity * loadFactor);
265
+        table = newMap;
266
+
267
+        for (int i = oldCapacity; i-- > 0;) {
268
+            for (Entry old = oldMap[i]; old != null;) {
269
+                Entry e = old;
270
+                old = old.next;
271
+
272
+                int index = (e.hash & 0x7FFFFFFF) % newCapacity;
273
+                e.next = newMap[index];
274
+                newMap[index] = e;
275
+            }
276
+        }
277
+    }
278
+
279
+    /**
280
+     * <p>Maps the specified <code>key</code> to the specified
281
+     * <code>value</code> in this hashtable. The key cannot be
282
+     * <code>null</code>. </p>
283
+     *
284
+     * <p>The value can be retrieved by calling the <code>get</code> method
285
+     * with a key that is equal to the original key.</p>
286
+     *
287
+     * @param key     the hashtable key.
288
+     * @param value   the value.
289
+     * @return the previous value of the specified key in this hashtable,
290
+     *         or <code>null</code> if it did not have one.
291
+     * @throws  NullPointerException  if the key is <code>null</code>.
292
+     * @see     #get(int)
293
+     */
294
+    public Object put(int key, Object value) {
295
+        // Makes sure the key is not already in the hashtable.
296
+        Entry tab[] = table;
297
+        int hash = key;
298
+        int index = (hash & 0x7FFFFFFF) % tab.length;
299
+        for (Entry e = tab[index]; e != null; e = e.next) {
300
+            if (e.hash == hash) {
301
+                Object old = e.value;
302
+                e.value = value;
303
+                return old;
304
+            }
305
+        }
306
+
307
+        if (count >= threshold) {
308
+            // Rehash the table if the threshold is exceeded
309
+            rehash();
310
+
311
+            tab = table;
312
+            index = (hash & 0x7FFFFFFF) % tab.length;
313
+        }
314
+
315
+        // Creates the new entry.
316
+        Entry e = new Entry(hash, key, value, tab[index]);
317
+        tab[index] = e;
318
+        count++;
319
+        return null;
320
+    }
321
+
322
+    /**
323
+     * <p>Removes the key (and its corresponding value) from this
324
+     * hashtable.</p>
325
+     *
326
+     * <p>This method does nothing if the key is not present in the
327
+     * hashtable.</p>
328
+     *
329
+     * @param   key   the key that needs to be removed.
330
+     * @return  the value to which the key had been mapped in this hashtable,
331
+     *          or <code>null</code> if the key did not have a mapping.
332
+     */
333
+    public Object remove(int key) {
334
+        Entry tab[] = table;
335
+        int hash = key;
336
+        int index = (hash & 0x7FFFFFFF) % tab.length;
337
+        for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
338
+            if (e.hash == hash) {
339
+                if (prev != null) {
340
+                    prev.next = e.next;
341
+                } else {
342
+                    tab[index] = e.next;
343
+                }
344
+                count--;
345
+                Object oldValue = e.value;
346
+                e.value = null;
347
+                return oldValue;
348
+            }
349
+        }
350
+        return null;
351
+    }
352
+
353
+    /**
354
+     * <p>Clears this hashtable so that it contains no keys.</p>
355
+     */
356
+    public synchronized void clear() {
357
+        Entry tab[] = table;
358
+        for (int index = tab.length; --index >= 0;) {
359
+            tab[index] = null;
360
+        }
361
+        count = 0;
362
+    }
363
+    
364
+}

+ 180
- 0
src/com/dmdirc/addons/parser_twitter/api/commons/StringEscapeUtils.java Dosyayı Görüntüle

@@ -0,0 +1,180 @@
1
+/*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements.  See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License.  You may obtain a copy of the License at
8
+ * 
9
+ *      http://www.apache.org/licenses/LICENSE-2.0
10
+ * 
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+package com.dmdirc.addons.parser_twitter.api.commons;
18
+
19
+import java.io.IOException;
20
+import java.io.StringWriter;
21
+import java.io.Writer;
22
+import java.util.Locale;
23
+
24
+/**
25
+ * <p>Escapes and unescapes <code>String</code>s for
26
+ * Java, Java Script, HTML, XML, and SQL.</p>
27
+ *
28
+ * @author Apache Jakarta Turbine
29
+ * @author Purple Technology
30
+ * @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
31
+ * @author Antony Riley
32
+ * @author Helge Tesgaard
33
+ * @author <a href="sean@boohai.com">Sean Brown</a>
34
+ * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
35
+ * @author Phil Steitz
36
+ * @author Pete Gieser
37
+ * @since 2.0
38
+ * @version $Id$
39
+ */
40
+public class StringEscapeUtils {
41
+    // HTML and XML
42
+    //--------------------------------------------------------------------------
43
+    /**
44
+     * <p>Escapes the characters in a <code>String</code> using HTML entities.</p>
45
+     *
46
+     * <p>
47
+     * For example:
48
+     * </p> 
49
+     * <p><code>"bread" & "butter"</code></p>
50
+     * becomes:
51
+     * <p>
52
+     * <code>&amp;quot;bread&amp;quot; &amp;amp; &amp;quot;butter&amp;quot;</code>.
53
+     * </p>
54
+     *
55
+     * <p>Supports all known HTML 4.0 entities, including funky accents.
56
+     * Note that the commonly used apostrophe escape character (&amp;apos;)
57
+     * is not a legal entity and so is not supported). </p>
58
+     *
59
+     * @param str  the <code>String</code> to escape, may be null
60
+     * @return a new escaped <code>String</code>, <code>null</code> if null string input
61
+     * 
62
+     * @see #unescapeHtml(String)
63
+     * @see <a href="http://hotwired.lycos.com/webmonkey/reference/special_characters/">ISO Entities</a>
64
+     * @see <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2 Character Entities for ISO Latin-1</a>
65
+     * @see <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">HTML 4.0 Character entity references</a>
66
+     * @see <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">HTML 4.01 Character References</a>
67
+     * @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a>
68
+     */
69
+    public static String escapeHtml(String str) {
70
+        if (str == null) {
71
+            return null;
72
+        }
73
+        try {
74
+            StringWriter writer = new StringWriter ((int)(str.length() * 1.5));
75
+            escapeHtml(writer, str);
76
+            return writer.toString();
77
+        } catch (IOException ioe) {
78
+            //should be impossible
79
+            throw new UnhandledException(ioe);
80
+        }
81
+    }
82
+
83
+    /**
84
+     * <p>Escapes the characters in a <code>String</code> using HTML entities and writes
85
+     * them to a <code>Writer</code>.</p>
86
+     *
87
+     * <p>
88
+     * For example:
89
+     * </p> 
90
+     * <code>"bread" & "butter"</code>
91
+     * <p>becomes:</p>
92
+     * <code>&amp;quot;bread&amp;quot; &amp;amp; &amp;quot;butter&amp;quot;</code>.
93
+     *
94
+     * <p>Supports all known HTML 4.0 entities, including funky accents.
95
+     * Note that the commonly used apostrophe escape character (&amp;apos;)
96
+     * is not a legal entity and so is not supported). </p>
97
+     *
98
+     * @param writer  the writer receiving the escaped string, not null
99
+     * @param string  the <code>String</code> to escape, may be null
100
+     * @throws IllegalArgumentException if the writer is null
101
+     * @throws IOException when <code>Writer</code> passed throws the exception from
102
+     *                                       calls to the {@link Writer#write(int)} methods.
103
+     * 
104
+     * @see #escapeHtml(String)
105
+     * @see #unescapeHtml(String)
106
+     * @see <a href="http://hotwired.lycos.com/webmonkey/reference/special_characters/">ISO Entities</a>
107
+     * @see <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2 Character Entities for ISO Latin-1</a>
108
+     * @see <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">HTML 4.0 Character entity references</a>
109
+     * @see <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">HTML 4.01 Character References</a>
110
+     * @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a>
111
+     */
112
+    public static void escapeHtml(Writer writer, String string) throws IOException {
113
+        if (writer == null ) {
114
+            throw new IllegalArgumentException ("The Writer must not be null.");
115
+        }
116
+        if (string == null) {
117
+            return;
118
+        }
119
+        Entities.HTML40.escape(writer, string);
120
+    }
121
+
122
+    //-----------------------------------------------------------------------
123
+    /**
124
+     * <p>Unescapes a string containing entity escapes to a string
125
+     * containing the actual Unicode characters corresponding to the
126
+     * escapes. Supports HTML 4.0 entities.</p>
127
+     *
128
+     * <p>For example, the string "&amp;lt;Fran&amp;ccedil;ais&amp;gt;"
129
+     * will become "&lt;Fran&ccedil;ais&gt;"</p>
130
+     *
131
+     * <p>If an entity is unrecognized, it is left alone, and inserted
132
+     * verbatim into the result string. e.g. "&amp;gt;&amp;zzzz;x" will
133
+     * become "&gt;&amp;zzzz;x".</p>
134
+     *
135
+     * @param str  the <code>String</code> to unescape, may be null
136
+     * @return a new unescaped <code>String</code>, <code>null</code> if null string input
137
+     * @see #escapeHtml(Writer, String)
138
+     */
139
+    public static String unescapeHtml(String str) {
140
+        if (str == null) {
141
+            return null;
142
+        }
143
+        try {
144
+            StringWriter writer = new StringWriter ((int)(str.length() * 1.5));
145
+            unescapeHtml(writer, str);
146
+            return writer.toString();
147
+        } catch (IOException ioe) {
148
+            //should be impossible
149
+            throw new UnhandledException(ioe);
150
+        }
151
+    }
152
+
153
+    /**
154
+     * <p>Unescapes a string containing entity escapes to a string
155
+     * containing the actual Unicode characters corresponding to the
156
+     * escapes. Supports HTML 4.0 entities.</p>
157
+     *
158
+     * <p>For example, the string "&amp;lt;Fran&amp;ccedil;ais&amp;gt;"
159
+     * will become "&lt;Fran&ccedil;ais&gt;"</p>
160
+     *
161
+     * <p>If an entity is unrecognized, it is left alone, and inserted
162
+     * verbatim into the result string. e.g. "&amp;gt;&amp;zzzz;x" will
163
+     * become "&gt;&amp;zzzz;x".</p>
164
+     *
165
+     * @param writer  the writer receiving the unescaped string, not null
166
+     * @param string  the <code>String</code> to unescape, may be null
167
+     * @throws IllegalArgumentException if the writer is null
168
+     * @throws IOException if an IOException occurs
169
+     * @see #escapeHtml(String)
170
+     */
171
+    public static void unescapeHtml(Writer writer, String string) throws IOException {
172
+        if (writer == null ) {
173
+            throw new IllegalArgumentException ("The Writer must not be null.");
174
+        }
175
+        if (string == null) {
176
+            return;
177
+        }
178
+        Entities.HTML40.unescape(writer, string);
179
+    }
180
+}

+ 71
- 0
src/com/dmdirc/addons/parser_twitter/api/commons/UnhandledException.java Dosyayı Görüntüle

@@ -0,0 +1,71 @@
1
+/*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements.  See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License.  You may obtain a copy of the License at
8
+ * 
9
+ *      http://www.apache.org/licenses/LICENSE-2.0
10
+ * 
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+package com.dmdirc.addons.parser_twitter.api.commons;
18
+
19
+/**
20
+ * <p>Thrown when it is impossible or undesirable to consume or throw a checked exception.</p>
21
+ * This exception supplements the standard exception classes by providing a more
22
+ * semantically rich description of the problem.</p>
23
+ * 
24
+ * <p><code>UnhandledException</code> represents the case where a method has to deal
25
+ * with a checked exception but does not wish to.
26
+ * Instead, the checked exception is rethrown in this unchecked wrapper.</p>
27
+ * 
28
+ * <pre>
29
+ * public void foo() {
30
+ *   try {
31
+ *     // do something that throws IOException
32
+ *   } catch (IOException ex) {
33
+ *     // don't want to or can't throw IOException from foo()
34
+ *     throw new UnhandledException(ex);
35
+ *   }
36
+ * }
37
+ * </pre>
38
+ *
39
+ * @author Matthew Hawthorne
40
+ * @since 2.0
41
+ * @version $Id$
42
+ */
43
+public class UnhandledException extends RuntimeException {
44
+
45
+    /**
46
+     * Required for serialization support.
47
+     * 
48
+     * @see java.io.Serializable
49
+     */
50
+    private static final long serialVersionUID = 1832101364842773720L;
51
+
52
+    /**
53
+     * Constructs the exception using a cause.
54
+     *
55
+     * @param cause  the underlying cause
56
+     */
57
+    public UnhandledException(Throwable cause) {
58
+        super(cause);
59
+    }
60
+
61
+    /**
62
+     * Constructs the exception using a message and cause.
63
+     *
64
+     * @param message  the message to use
65
+     * @param cause  the underlying cause
66
+     */
67
+    public UnhandledException(String message, Throwable cause) {
68
+        super(message, cause);
69
+    }
70
+
71
+}

+ 46
- 0
src/com/dmdirc/addons/parser_twitter/plugin.config Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+  version
10
+  defaults
11
+
12
+metadata:
13
+  author=Shane <shane@dmdirc.com>
14
+  mainclass=com.dmdirc.addons.parser_twitter.TwitterPlugin
15
+  description=Provides twitter access for DMDirc.
16
+  name=twitter
17
+  nicename=Twitter Plugin
18
+
19
+updates:
20
+  id=49
21
+
22
+version:
23
+  number=27
24
+  friendly=2.7
25
+
26
+defaults:
27
+  statuscount=20
28
+  apicalls=60
29
+  debugEnabled=false
30
+  hide500Errors=true
31
+  saveLastIDs=false
32
+  getSentMessages=false
33
+  replaceOpeningNickname=false
34
+  autoAt=false
35
+  # Pre-configured support for twitter api
36
+  api.address.twitter.com=api.twitter.com
37
+  api.versioned.twitter.com=true
38
+  # Pre-configured support for identi.ca twitter-ish api
39
+  api.address.identi.ca=identi.ca/api
40
+  api.versioned.identi.ca=false
41
+
42
+provides:
43
+  twitter parser
44
+
45
+exports:
46
+  getParser in com.dmdirc.addons.parser_twitter.TwitterPlugin as getParser

Loading…
İptal
Kaydet