Browse code

initial import

devnewton authored on 29/08/2014 11:59:33
Showing 18 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+/.classpath
2
+/.settings/org.eclipse.core.resources.prefs
3
+/.settings/org.eclipse.m2e.core.prefs
4
+/.project
5
+/.settings/org.eclipse.jdt.core.prefs
6
+/replopbot.conf
0 7
\ No newline at end of file
1 8
new file mode 100644
... ...
@@ -0,0 +1,50 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+	<modelVersion>4.0.0</modelVersion>
4
+
5
+	<groupId>im.bci</groupId>
6
+	<artifactId>replopbot</artifactId>
7
+	<version>0.0.1-SNAPSHOT</version>
8
+	<packaging>jar</packaging>
9
+
10
+	<name>replop</name>
11
+	<url>http://maven.apache.org</url>
12
+
13
+	<properties>
14
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15
+		<camel.version>2.13.2</camel.version>
16
+	</properties>
17
+
18
+	<dependencies>
19
+		<dependency>
20
+			<groupId>org.apache.camel</groupId>
21
+			<artifactId>camel-irc</artifactId>
22
+			<version>${camel.version}</version>
23
+		</dependency>
24
+		<dependency>
25
+			<groupId>org.apache.camel</groupId>
26
+			<artifactId>camel-xmpp</artifactId>
27
+			<version>${camel.version}</version>
28
+		</dependency>
29
+		<dependency>
30
+			<groupId>org.glassfish.jersey.core</groupId>
31
+			<artifactId>jersey-client</artifactId>
32
+			<version>2.6</version>
33
+		</dependency>
34
+		<dependency>
35
+			<groupId>org.glassfish.jersey.media</groupId>
36
+			<artifactId>jersey-media-json-jackson</artifactId>
37
+			<version>2.6</version>
38
+		</dependency>
39
+		<dependency>
40
+			<groupId>commons-lang</groupId>
41
+			<artifactId>commons-lang</artifactId>
42
+			<version>2.6</version>
43
+		</dependency>
44
+		<dependency>
45
+			<groupId>org.slf4j</groupId>
46
+			<artifactId>slf4j-simple</artifactId>
47
+			<version>1.7.7</version>
48
+		</dependency>
49
+	</dependencies>
50
+</project>
0 51
new file mode 100644
... ...
@@ -0,0 +1,16 @@
1
+{
2
+  "nickname" : "replopbot",
3
+  "xmmp" : {
4
+    "server" : "bci.im",
5
+    "room" : "devnewton@conference.bci.im",
6
+    "user" : "replopbot",
7
+    "password" : "maman"
8
+  },
9
+  "irc" : {
10
+    "chan" : "chat.freenode.net/#devnewton"
11
+  },
12
+  "tribune" : {
13
+    "getUrl" : "http://devnewton.bci.im/fr/chat/xml",
14
+    "postUrl" : "http://devnewton.bci.im/fr/chat/post"
15
+  }
16
+}
0 17
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+package im.bci.camel.tribune;
2
+
3
+import java.util.Map;
4
+
5
+import org.apache.camel.Endpoint;
6
+import org.apache.camel.impl.DefaultComponent;
7
+
8
+public class TribuneComponent extends DefaultComponent {
9
+
10
+    @Override
11
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
12
+        TribuneConfiguration configuration = new TribuneConfiguration();
13
+        setProperties(configuration, parameters);
14
+        TribuneEndPoint endPoint = new TribuneEndPoint(uri, this, configuration);
15
+        return endPoint;
16
+    }
17
+
18
+}
0 19
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+package im.bci.camel.tribune;
2
+
3
+public class TribuneConfiguration {
4
+
5
+    private String postUrl;
6
+    private String getUrl;
7
+
8
+    public String getPostUrl() {
9
+        return postUrl;
10
+    }
11
+
12
+    public void setPostUrl(String postUrl) {
13
+        this.postUrl = postUrl;
14
+    }
15
+
16
+    public String getGetUrl() {
17
+        return getUrl;
18
+    }
19
+
20
+    public void setGetUrl(String getUrl) {
21
+        this.getUrl = getUrl;
22
+    }
23
+
24
+}
0 25
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+package im.bci.camel.tribune;
2
+
3
+public class TribuneConstants {
4
+    public static final String SENDER = "tribune.sender";
5
+}
0 6
new file mode 100644
... ...
@@ -0,0 +1,58 @@
1
+package im.bci.camel.tribune;
2
+
3
+import java.util.Collections;
4
+import java.util.Comparator;
5
+
6
+import im.bci.camel.tribune.backend.Board;
7
+import im.bci.camel.tribune.backend.Post;
8
+
9
+import javax.ws.rs.client.Client;
10
+import javax.ws.rs.client.ClientBuilder;
11
+import javax.ws.rs.client.WebTarget;
12
+
13
+import org.apache.camel.Endpoint;
14
+import org.apache.camel.Exchange;
15
+import org.apache.camel.Processor;
16
+import org.apache.camel.impl.ScheduledPollConsumer;
17
+
18
+public class TribuneConsumer extends ScheduledPollConsumer {
19
+
20
+    private final TribuneConfiguration configuration;
21
+    private Client client;
22
+    private long lastId = -1;
23
+
24
+    public TribuneConsumer(Endpoint endpoint, Processor processor, TribuneConfiguration configuration) {
25
+        super(endpoint, processor);
26
+        this.configuration = configuration;
27
+        this.setDelay(1000);
28
+        client = ClientBuilder.newBuilder().build();
29
+    }
30
+
31
+    @Override
32
+    protected int poll() throws Exception {
33
+        WebTarget target = client.target(configuration.getGetUrl());
34
+        Board board = target.request().get(Board.class);
35
+        int nbPostPolled = 0;
36
+        long maxId = -1;
37
+        Collections.sort(board.getPost(), new Comparator<Post>() {
38
+
39
+            public int compare(Post p1, Post p2) {
40
+                return Long.compare(p1.getId(), p2.getId());
41
+            }
42
+        });
43
+        for (Post post : board.getPost()) {
44
+            if (post.getId() > lastId) {
45
+                if (lastId > 0) {
46
+                    Exchange ex = getEndpoint().createExchange();
47
+                    ex.setIn(new TribuneMessage(post));
48
+                    getProcessor().process(ex);
49
+                    ++nbPostPolled;
50
+                }
51
+                maxId = Math.max(maxId, post.getId());
52
+            }
53
+        }
54
+        lastId = Math.max(maxId, lastId);
55
+        return nbPostPolled;
56
+    }
57
+
58
+}
0 59
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+package im.bci.camel.tribune;
2
+
3
+import org.apache.camel.Component;
4
+import org.apache.camel.Consumer;
5
+import org.apache.camel.Processor;
6
+import org.apache.camel.Producer;
7
+import org.apache.camel.impl.DefaultEndpoint;
8
+
9
+public class TribuneEndPoint extends DefaultEndpoint {
10
+
11
+    private final TribuneConfiguration configuration;
12
+
13
+    public TribuneEndPoint(String endpointuri, Component component, TribuneConfiguration configuration) {
14
+        super(endpointuri, component);
15
+        this.configuration = configuration;
16
+    }
17
+
18
+    public Producer createProducer() throws Exception {
19
+        return new TribuneProducer(this, configuration);
20
+    }
21
+
22
+    public Consumer createConsumer(Processor processor) throws Exception {
23
+        return new TribuneConsumer(this, processor, configuration);
24
+    }
25
+
26
+    public boolean isSingleton() {
27
+        return true;
28
+    }
29
+
30
+}
0 31
new file mode 100644
... ...
@@ -0,0 +1,31 @@
1
+package im.bci.camel.tribune;
2
+
3
+import java.util.Map;
4
+
5
+import im.bci.camel.tribune.backend.Post;
6
+
7
+import org.apache.camel.impl.DefaultMessage;
8
+import org.apache.commons.lang.StringUtils;
9
+
10
+public class TribuneMessage extends DefaultMessage {
11
+
12
+    private Post post;
13
+
14
+    public TribuneMessage(Post post) {
15
+        this.post = post;
16
+    }
17
+    
18
+    @Override
19
+    protected Object createBody() {
20
+        return post.getMessage();
21
+    }
22
+    
23
+    @Override
24
+    protected void populateInitialHeaders(Map<String, Object> map) {
25
+        String sender = post.getLogin();
26
+        if(StringUtils.isEmpty(sender)) {
27
+            sender = post.getInfo();
28
+        }
29
+        map.put(TribuneConstants.SENDER, sender);
30
+    }
31
+}
0 32
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+package im.bci.camel.tribune;
2
+
3
+import javax.ws.rs.client.Client;
4
+import javax.ws.rs.client.ClientBuilder;
5
+import javax.ws.rs.client.Entity;
6
+import javax.ws.rs.client.WebTarget;
7
+import javax.ws.rs.core.Form;
8
+import javax.ws.rs.core.MediaType;
9
+
10
+import org.apache.camel.Endpoint;
11
+import org.apache.camel.Exchange;
12
+import org.apache.camel.impl.DefaultProducer;
13
+import org.apache.commons.lang.ObjectUtils;
14
+
15
+public class TribuneProducer extends DefaultProducer {
16
+
17
+    private TribuneConfiguration configuration;
18
+    private Client client;
19
+
20
+    public TribuneProducer(Endpoint endpoint, TribuneConfiguration configuration) {
21
+        super(endpoint);
22
+        this.configuration = configuration;
23
+        client = ClientBuilder.newBuilder().build();
24
+    }
25
+
26
+    public void process(Exchange exchange) throws Exception {
27
+        String message = exchange.getIn().getBody(String.class);
28
+        WebTarget target = client.target(configuration.getPostUrl());
29
+        Form form = new Form();
30
+        form.param("message", message);
31
+        String sender = ObjectUtils.toString(exchange.getIn().getHeader(TribuneConstants.SENDER));
32
+        if (!sender.isEmpty()) {
33
+            form.param("nickname", sender);
34
+        }
35
+        target.request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
36
+    }
37
+
38
+}
0 39
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+//
2
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
3
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
4
+// Any modifications to this file will be lost upon recompilation of the source schema. 
5
+// Generated on: 2014.08.29 at 09:18:23 AM CEST 
6
+//
7
+
8
+
9
+package im.bci.camel.tribune.backend;
10
+
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+import javax.xml.bind.annotation.XmlAccessType;
14
+import javax.xml.bind.annotation.XmlAccessorType;
15
+import javax.xml.bind.annotation.XmlAttribute;
16
+import javax.xml.bind.annotation.XmlRootElement;
17
+import javax.xml.bind.annotation.XmlSchemaType;
18
+import javax.xml.bind.annotation.XmlType;
19
+
20
+
21
+/**
22
+ * <p>Java class for anonymous complex type.
23
+ * 
24
+ * <p>The following schema fragment specifies the expected content contained within this class.
25
+ * 
26
+ * <pre>
27
+ * &lt;complexType>
28
+ *   &lt;complexContent>
29
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
30
+ *       &lt;sequence>
31
+ *         &lt;element ref="{http://patlenain.dyndns.org/bouchot/tribune-1.0.xsd}post" maxOccurs="unbounded" minOccurs="0"/>
32
+ *       &lt;/sequence>
33
+ *       &lt;attribute name="site" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
34
+ *     &lt;/restriction>
35
+ *   &lt;/complexContent>
36
+ * &lt;/complexType>
37
+ * </pre>
38
+ * 
39
+ * 
40
+ */
41
+@XmlAccessorType(XmlAccessType.FIELD)
42
+@XmlType(name = "", propOrder = {
43
+    "post"
44
+})
45
+@XmlRootElement(name = "board")
46
+public class Board {
47
+
48
+    protected List<Post> post;
49
+    @XmlAttribute(name = "site", required = true)
50
+    @XmlSchemaType(name = "anyURI")
51
+    protected String site;
52
+
53
+    /**
54
+     * Gets the value of the post property.
55
+     * 
56
+     * <p>
57
+     * This accessor method returns a reference to the live list,
58
+     * not a snapshot. Therefore any modification you make to the
59
+     * returned list will be present inside the JAXB object.
60
+     * This is why there is not a <CODE>set</CODE> method for the post property.
61
+     * 
62
+     * <p>
63
+     * For example, to add a new item, do as follows:
64
+     * <pre>
65
+     *    getPost().add(newItem);
66
+     * </pre>
67
+     * 
68
+     * 
69
+     * <p>
70
+     * Objects of the following type(s) are allowed in the list
71
+     * {@link Post }
72
+     * 
73
+     * 
74
+     */
75
+    public List<Post> getPost() {
76
+        if (post == null) {
77
+            post = new ArrayList<Post>();
78
+        }
79
+        return this.post;
80
+    }
81
+
82
+    /**
83
+     * Gets the value of the site property.
84
+     * 
85
+     * @return
86
+     *     possible object is
87
+     *     {@link String }
88
+     *     
89
+     */
90
+    public String getSite() {
91
+        return site;
92
+    }
93
+
94
+    /**
95
+     * Sets the value of the site property.
96
+     * 
97
+     * @param value
98
+     *     allowed object is
99
+     *     {@link String }
100
+     *     
101
+     */
102
+    public void setSite(String value) {
103
+        this.site = value;
104
+    }
105
+
106
+}
0 107
new file mode 100644
... ...
@@ -0,0 +1,166 @@
1
+//
2
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
3
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
4
+// Any modifications to this file will be lost upon recompilation of the source schema. 
5
+// Generated on: 2014.08.29 at 09:18:23 AM CEST 
6
+//
7
+
8
+
9
+package im.bci.camel.tribune.backend;
10
+
11
+import javax.xml.bind.annotation.XmlAccessType;
12
+import javax.xml.bind.annotation.XmlAccessorType;
13
+import javax.xml.bind.annotation.XmlAttribute;
14
+import javax.xml.bind.annotation.XmlElement;
15
+import javax.xml.bind.annotation.XmlRootElement;
16
+import javax.xml.bind.annotation.XmlType;
17
+
18
+
19
+/**
20
+ * <p>Java class for anonymous complex type.
21
+ * 
22
+ * <p>The following schema fragment specifies the expected content contained within this class.
23
+ * 
24
+ * <pre>
25
+ * &lt;complexType>
26
+ *   &lt;complexContent>
27
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
28
+ *       &lt;sequence>
29
+ *         &lt;element ref="{http://patlenain.dyndns.org/bouchot/tribune-1.0.xsd}info"/>
30
+ *         &lt;element ref="{http://patlenain.dyndns.org/bouchot/tribune-1.0.xsd}message"/>
31
+ *         &lt;element ref="{http://patlenain.dyndns.org/bouchot/tribune-1.0.xsd}login"/>
32
+ *       &lt;/sequence>
33
+ *       &lt;attribute name="time" use="required" type="{http://www.w3.org/2001/XMLSchema}long" />
34
+ *       &lt;attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}long" />
35
+ *     &lt;/restriction>
36
+ *   &lt;/complexContent>
37
+ * &lt;/complexType>
38
+ * </pre>
39
+ * 
40
+ * 
41
+ */
42
+@XmlAccessorType(XmlAccessType.FIELD)
43
+@XmlType(name = "", propOrder = {
44
+    "info",
45
+    "message",
46
+    "login"
47
+})
48
+@XmlRootElement(name = "post")
49
+public class Post {
50
+
51
+    @XmlElement(required = true)
52
+    protected String info;
53
+    @XmlElement(required = true)
54
+    protected String message;
55
+    @XmlElement(required = true)
56
+    protected String login;
57
+    @XmlAttribute(name = "time", required = true)
58
+    protected long time;
59
+    @XmlAttribute(name = "id", required = true)
60
+    protected long id;
61
+
62
+    /**
63
+     * Gets the value of the info property.
64
+     * 
65
+     * @return
66
+     *     possible object is
67
+     *     {@link String }
68
+     *     
69
+     */
70
+    public String getInfo() {
71
+        return info;
72
+    }
73
+
74
+    /**
75
+     * Sets the value of the info property.
76
+     * 
77
+     * @param value
78
+     *     allowed object is
79
+     *     {@link String }
80
+     *     
81
+     */
82
+    public void setInfo(String value) {
83
+        this.info = value;
84
+    }
85
+
86
+    /**
87
+     * Gets the value of the message property.
88
+     * 
89
+     * @return
90
+     *     possible object is
91
+     *     {@link Message }
92
+     *     
93
+     */
94
+    public String getMessage() {
95
+        return message;
96
+    }
97
+
98
+    /**
99
+     * Sets the value of the message property.
100
+     * 
101
+     * @param value
102
+     *     allowed object is
103
+     *     {@link Message }
104
+     *     
105
+     */
106
+    public void setMessage(String value) {
107
+        this.message = value;
108
+    }
109
+
110
+    /**
111
+     * Gets the value of the login property.
112
+     * 
113
+     * @return
114
+     *     possible object is
115
+     *     {@link String }
116
+     *     
117
+     */
118
+    public String getLogin() {
119
+        return login;
120
+    }
121
+
122
+    /**
123
+     * Sets the value of the login property.
124
+     * 
125
+     * @param value
126
+     *     allowed object is
127
+     *     {@link String }
128
+     *     
129
+     */
130
+    public void setLogin(String value) {
131
+        this.login = value;
132
+    }
133
+
134
+    /**
135
+     * Gets the value of the time property.
136
+     * 
137
+     */
138
+    public long getTime() {
139
+        return time;
140
+    }
141
+
142
+    /**
143
+     * Sets the value of the time property.
144
+     * 
145
+     */
146
+    public void setTime(long value) {
147
+        this.time = value;
148
+    }
149
+
150
+    /**
151
+     * Gets the value of the id property.
152
+     * 
153
+     */
154
+    public long getId() {
155
+        return id;
156
+    }
157
+
158
+    /**
159
+     * Sets the value of the id property.
160
+     * 
161
+     */
162
+    public void setId(long value) {
163
+        this.id = value;
164
+    }
165
+
166
+}
0 167
new file mode 100644
... ...
@@ -0,0 +1,168 @@
1
+package im.bci.replopbot;
2
+
3
+import im.bci.camel.tribune.TribuneConstants;
4
+import im.bci.replopbot.conf.ReplopbotConfiguration;
5
+import java.io.File;
6
+import java.io.IOException;
7
+import org.apache.camel.CamelContext;
8
+import org.apache.camel.Exchange;
9
+import org.apache.camel.Message;
10
+import org.apache.camel.Predicate;
11
+import org.apache.camel.Processor;
12
+import org.apache.camel.builder.RouteBuilder;
13
+import org.apache.camel.component.irc.IrcConstants;
14
+import org.apache.camel.component.xmpp.XmppConstants;
15
+import org.apache.camel.impl.DefaultCamelContext;
16
+import org.apache.commons.lang.ObjectUtils;
17
+import org.apache.commons.lang.StringUtils;
18
+import org.codehaus.jackson.map.DeserializationConfig;
19
+import org.codehaus.jackson.map.ObjectMapper;
20
+import org.codehaus.jackson.map.SerializationConfig;
21
+
22
+public class Replopbot {
23
+
24
+    public static void main(String[] args) throws Exception {
25
+
26
+        final ReplopbotConfiguration config = loadConfiguration();
27
+
28
+        final String xmppEndPoint = "xmpp://" + config.getXmmp().getServer() + "/?room=" + config.getXmmp().getRoom() + "&nickname=" + config.getNickname() + "&user=" + config.getXmmp().getUser() + "&password=" + config.getXmmp().getPassword();
29
+        final String ircEndPoint = "irc:" + config.getNickname() + "@" + config.getIrc().getChan();
30
+        final String tribuneEndPoint = "tribune:devnewton?getUrl=" + config.getTribune().getGetUrl() + "&postUrl=" + config.getTribune().getPostUrl();
31
+
32
+        final CamelContext context = new DefaultCamelContext();
33
+        context.addRoutes(new RouteBuilder() {
34
+            public void configure() {
35
+
36
+                // xmpp to irc and tribune
37
+                from(xmppEndPoint).filter(new Predicate() {
38
+
39
+                    public boolean matches(Exchange ex) {
40
+                        String sender = ObjectUtils.toString(ex.getIn().getHeader(XmppConstants.FROM));
41
+                        if (StringUtils.contains(sender, config.getNickname())) {
42
+                            return false;
43
+                        }
44
+                        return true;
45
+                    }
46
+                }).process(new Processor() {
47
+
48
+                    public void process(Exchange ex) throws Exception {
49
+                        Message in = ex.getIn();
50
+                        String sender = ObjectUtils.toString(in.getHeader(XmppConstants.FROM));
51
+                        if (!sender.isEmpty()) {
52
+                            in.setHeader(TribuneConstants.SENDER, config.getNickname() + "/" + sender);
53
+                        }
54
+                    }
55
+                }).to(tribuneEndPoint).process(new Processor() {
56
+
57
+                    public void process(Exchange ex) throws Exception {
58
+                        Message in = ex.getIn();
59
+                        String sender = ObjectUtils.toString(in.getHeader(XmppConstants.FROM));
60
+                        if (!sender.isEmpty()) {
61
+                            in.setBody(sender + ": " + in.getBody(String.class));
62
+                        }
63
+                    }
64
+                }).to(ircEndPoint).process(new Processor() {
65
+
66
+                    public void process(Exchange ex) throws Exception {
67
+                        System.out.println(ex.getIn().getHeaders());
68
+                        System.out.println(ex.getIn().getBody(String.class));
69
+                    }
70
+                });
71
+
72
+                // irc to xmpp and tribune
73
+                from(ircEndPoint).filter(new Predicate() {
74
+
75
+                    public boolean matches(Exchange ex) {
76
+                        String sender = ObjectUtils.toString(ex.getIn().getHeader(IrcConstants.IRC_USER_NICK));
77
+                        if (StringUtils.equals(sender, "ChanServ")) {
78
+                            return false;
79
+                        }
80
+                        if (StringUtils.contains(sender, config.getNickname())) {
81
+                            return false;
82
+                        }
83
+                        return true;
84
+                    }
85
+                }).process(new Processor() {
86
+
87
+                    public void process(Exchange ex) throws Exception {
88
+                        Message in = ex.getIn();
89
+                        String sender = ObjectUtils.toString(in.getHeader(IrcConstants.IRC_USER_NICK));
90
+                        if (!sender.isEmpty()) {
91
+                            in.setHeader(TribuneConstants.SENDER, config.getNickname() + "/" + sender);
92
+                        }
93
+                    }
94
+                }).to(tribuneEndPoint).process(new Processor() {
95
+                    public void process(Exchange ex) throws Exception {
96
+                        Message in = ex.getIn();
97
+                        String sender = ObjectUtils.toString(in.getHeader(IrcConstants.IRC_USER_NICK));
98
+                        if (!sender.isEmpty()) {
99
+                            in.setBody(sender + ": " + in.getBody(String.class));
100
+                        }
101
+                    }
102
+                }).to(xmppEndPoint).process(new Processor() {
103
+
104
+                    public void process(Exchange ex) throws Exception {
105
+                        System.out.println(ex.getIn().getHeaders());
106
+                        System.out.println(ex.getIn().getBody(String.class));
107
+                    }
108
+                });
109
+
110
+                // tribune to irc and xmpp
111
+                from(tribuneEndPoint).filter(new Predicate() {
112
+
113
+                    public boolean matches(Exchange ex) {
114
+                        String sender = ObjectUtils.toString(ex.getIn().getHeader(TribuneConstants.SENDER));
115
+                        if (StringUtils.contains(sender, config.getNickname())) {
116
+                            return false;
117
+                        }
118
+                        if (StringUtils.isBlank(sender)) { // probably some
119
+                            // douchebag moules
120
+                            return false;
121
+                        }
122
+                        return true;
123
+                    }
124
+                }).process(new Processor() {
125
+                    public void process(Exchange ex) throws Exception {
126
+                        Message in = ex.getIn();
127
+                        String sender = ObjectUtils.toString(in.getHeader(TribuneConstants.SENDER));
128
+                        if (!sender.isEmpty()) {
129
+                            in.setBody(sender + ": " + in.getBody(String.class));
130
+                        }
131
+                    }
132
+                }).to(xmppEndPoint).to(ircEndPoint).process(new Processor() {
133
+
134
+                    public void process(Exchange ex) throws Exception {
135
+                        System.out.println(ex.getIn().getHeaders());
136
+                        System.out.println(ex.getIn().getBody(String.class));
137
+                    }
138
+                });
139
+            }
140
+        });
141
+
142
+        context.start();
143
+        Runtime.getRuntime().addShutdownHook(new Thread() {
144
+            @Override
145
+            public void run() {
146
+                try {
147
+                    context.stop();
148
+                } catch (Exception e) {
149
+                    System.err.println(e);
150
+                }
151
+            }
152
+        });
153
+
154
+        for (;;) {
155
+            Thread.sleep(1000);
156
+        }
157
+
158
+    }
159
+
160
+    private static ReplopbotConfiguration loadConfiguration() throws IOException {
161
+        final ObjectMapper mapper = new ObjectMapper();
162
+        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
163
+        mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
164
+        mapper.configure(org.codehaus.jackson.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
165
+        mapper.configure(org.codehaus.jackson.JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
166
+        return mapper.readValue(new File("replopbot.conf"), ReplopbotConfiguration.class);
167
+    }
168
+}
0 169
new file mode 100644
... ...
@@ -0,0 +1,45 @@
1
+package im.bci.replopbot.conf;
2
+
3
+public class ReplopbotConfiguration {
4
+
5
+    private String nickname = "replopbot";
6
+
7
+    private ReplopbotXmppConfiguration xmmp = new ReplopbotXmppConfiguration();
8
+
9
+    private ReplopbotIrcConfiguration irc = new ReplopbotIrcConfiguration();
10
+
11
+    private ReplopbotTribuneConfiguration tribune = new ReplopbotTribuneConfiguration();
12
+
13
+    public ReplopbotIrcConfiguration getIrc() {
14
+        return irc;
15
+    }
16
+
17
+    public void setIrc(ReplopbotIrcConfiguration irc) {
18
+        this.irc = irc;
19
+    }
20
+
21
+    public ReplopbotXmppConfiguration getXmmp() {
22
+        return xmmp;
23
+    }
24
+
25
+    public void setXmmp(ReplopbotXmppConfiguration xmmp) {
26
+        this.xmmp = xmmp;
27
+    }
28
+
29
+    public String getNickname() {
30
+        return nickname;
31
+    }
32
+
33
+    public void setNickname(String nickname) {
34
+        this.nickname = nickname;
35
+    }
36
+
37
+    public ReplopbotTribuneConfiguration getTribune() {
38
+        return tribune;
39
+    }
40
+
41
+    public void setTribune(ReplopbotTribuneConfiguration tribune) {
42
+        this.tribune = tribune;
43
+    }
44
+
45
+}
0 46
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+package im.bci.replopbot.conf;
2
+
3
+public class ReplopbotIrcConfiguration {
4
+
5
+    private String chan = "chat.freenode.net/#devnewton";
6
+
7
+    public String getChan() {
8
+        return chan;
9
+    }
10
+
11
+    public void setChan(String ircChan) {
12
+        this.chan = ircChan;
13
+    }
14
+}
0 15
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+package im.bci.replopbot.conf;
2
+
3
+public class ReplopbotTribuneConfiguration {
4
+
5
+    private String getUrl = "http://devnewton.bci.im/fr/chat/xml";
6
+    private String postUrl = "http://devnewton.bci.im/fr/chat/post";
7
+
8
+    public String getGetUrl() {
9
+        return getUrl;
10
+    }
11
+
12
+    public void setGetUrl(String getUrl) {
13
+        this.getUrl = getUrl;
14
+    }
15
+
16
+    public String getPostUrl() {
17
+        return postUrl;
18
+    }
19
+
20
+    public void setPostUrl(String postUrl) {
21
+        this.postUrl = postUrl;
22
+    }
23
+
24
+   
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+package im.bci.replopbot.conf;
2
+
3
+public class ReplopbotXmppConfiguration {
4
+    private String server = "bci.im";
5
+    private String room = "devnewton@conference.bci.im";
6
+    private String user = "replopbot";
7
+    private String password = "re plop plop";
8
+
9
+    public String getServer() {
10
+        return server;
11
+    }
12
+
13
+    public void setServer(String server) {
14
+        this.server = server;
15
+    }
16
+
17
+    public String getRoom() {
18
+        return room;
19
+    }
20
+
21
+    public void setRoom(String room) {
22
+        this.room = room;
23
+    }
24
+
25
+    public String getUser() {
26
+        return user;
27
+    }
28
+
29
+    public void setUser(String user) {
30
+        this.user = user;
31
+    }
32
+
33
+    public String getPassword() {
34
+        return password;
35
+    }
36
+
37
+    public void setPassword(String password) {
38
+        this.password = password;
39
+    }
40
+    
41
+}
0 42
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+class=im.bci.camel.tribune.TribuneComponent