svn commit: r550510 - in /activemq/camel/trunk: ./ apache-camel/ apache-camel/src/main/descript
|
|||
![]()
svn commit: r550510 - in /activemq/camel/trunk: ./ apache-camel/ apache-camel/src/main/descript
|
Author: jstrachan
Date: Mon Jun 25 07:24:50 2007 New Revision: 550510 URL: http://svn.apache.org/viewvc?view=rev&rev=550510 Log: added Noah's camel-irc component for CAMEL-55 Added: activemq/camel/trunk/components/camel-irc/ activemq/camel/trunk/components/camel-irc/pom.xml (with props) activemq/camel/trunk/components/camel-irc/src/ activemq/camel/trunk/components/camel-irc/src/main/ activemq/camel/trunk/components/camel-irc/src/main/java/ activemq/camel/trunk/components/camel-irc/src/main/java/org/ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java (with props) activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java (with props) activemq/camel/trunk/components/camel-irc/src/main/resources/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/irc Modified: activemq/camel/trunk/apache-camel/pom.xml activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml activemq/camel/trunk/components/pom.xml activemq/camel/trunk/pom.xml Modified: activemq/camel/trunk/apache-camel/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/pom.xml?view=diff&rev=550510&r1=550509&r2=550510 ============================================================================== --- activemq/camel/trunk/apache-camel/pom.xml (original) +++ activemq/camel/trunk/apache-camel/pom.xml Mon Jun 25 07:24:50 2007 @@ -56,6 +56,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-irc</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-jaxb</artifactId> </dependency> <dependency> @@ -170,8 +174,9 @@ <goal>createbundle</goal> </goals> <configuration> - <includes>camel-activemq,camel-bam,camel-core,camel-cxf,camel-file,camel-http,camel-jaxb, - camel-jbi,camel-jms,camel-josql,camel-jpa,camel-mail,camel-mina,camel-quartz,camel-rmi, + <includes>camel-activemq,camel-bam,camel-core,camel-cxf,camel-file,camel-http, + camel-irc,camel-jaxb,camel-jbi,camel-jms,camel-josql, + camel-jpa,camel-mail,camel-mina,camel-quartz,camel-rmi, camel-saxon,camel-script,camel-spring,camel-xmpp,commons-logging</includes> </configuration> </execution> Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml?view=diff&rev=550510&r1=550509&r2=550510 ============================================================================== --- activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml (original) +++ activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml Mon Jun 25 07:24:50 2007 @@ -73,6 +73,7 @@ <include>org.apache.camel:camel-core</include> <include>org.apache.camel:camel-cxf</include> <include>org.apache.camel:camel-http</include> + <include>org.apache.camel:camel-irc</include> <include>org.apache.camel:camel-jaxb</include> <include>org.apache.camel:camel-jbi</include> <include>org.apache.camel:camel-jms</include> Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml?view=diff&rev=550510&r1=550509&r2=550510 ============================================================================== --- activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml (original) +++ activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml Mon Jun 25 07:24:50 2007 @@ -79,6 +79,7 @@ <include>org.apache.camel:camel-core</include> <include>org.apache.camel:camel-cxf</include> <include>org.apache.camel:camel-http</include> + <include>org.apache.camel:camel-irc</include> <include>org.apache.camel:camel-jaxb</include> <include>org.apache.camel:camel-jbi</include> <include>org.apache.camel:camel-jms</include> Added: activemq/camel/trunk/components/camel-irc/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/pom.xml?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/pom.xml (added) +++ activemq/camel/trunk/components/camel-irc/pom.xml Mon Jun 25 07:24:50 2007 @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-irc</artifactId> + <name>Camel :: IRC</name> + <description>Camel IRC support</description> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>org.schwering</groupId> + <artifactId>irclib</artifactId> + <version>1.04-bsd</version> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> Propchange: activemq/camel/trunk/components/camel-irc/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,24 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +public class IrcBinding { + public Object extractBodyFromIrc(IrcExchange exchange, String message) { + return message; + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,119 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.CamelContext; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.util.IntrospectionSupport; +import org.schwering.irc.lib.IRCConnection; + +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +public class IrcComponent extends DefaultComponent<IrcExchange> { + + private IrcConfiguration configuration; + + public IrcComponent() { + configuration = new IrcConfiguration(); + } + + public IrcComponent(IrcConfiguration configuration) { + this.configuration = configuration; + } + + public IrcComponent(CamelContext context) { + super(context); + configuration = new IrcConfiguration(); + } + + public static IrcComponent ircComponent() { + return new IrcComponent(); + } + + protected IrcEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { + IrcConfiguration config = getConfiguration().copy(); + config.configure(new URI(uri)); + + // lets make sure we copy the configuration as each endpoint can customize its own version + final IrcEndpoint endpoint = new IrcEndpoint(uri, this, config); + + IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters); + return endpoint; + } + + public IrcConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(IrcConfiguration configuration) { + this.configuration = configuration; + } + + final Map<String, IRCConnection> connectionCache = new HashMap<String, IRCConnection>(); + + public synchronized IRCConnection getIRCConnection(IrcConfiguration configuration) { + final IRCConnection connection; + if (connectionCache.containsKey(configuration.getCacheKey())) { + System.out.println("Returning Cached Connection to " + configuration.getHostname() + " " + configuration.getTarget()); + connection = connectionCache.get(configuration.getCacheKey()); + } else { + connection = createConnection(configuration); + connectionCache.put(configuration.getCacheKey(), connection); + } + return connection; + } + + protected IRCConnection createConnection(IrcConfiguration configuration) { + System.out.println("Creating Connection to " + configuration.getHostname() + " " + configuration.getTarget()); + + final IRCConnection conn = new IRCConnection(configuration.getHostname(), configuration.getPorts(), configuration.getPassword(), configuration.getNickname(), configuration.getUsername(), configuration.getRealname()); + conn.setEncoding("UTF-8"); +// conn.setDaemon(true); + conn.setColors(configuration.isColors()); + conn.setPong(true); + + try { + conn.connect(); + } catch (IOException e) { + e.printStackTrace(); + } + return conn; + } + + public void closeConnection(String key, IRCConnection connection) { + try { + connection.doQuit(); + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + connectionCache.remove(key); // TODO this is probably bad in the for each + } + } + + @Override + protected void doStop() throws Exception { + for (Map.Entry<String, IRCConnection> entry : connectionCache.entrySet()) { + closeConnection(entry.getKey(), entry.getValue()); + } + super.doStop(); + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,244 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.RuntimeCamelException; + +import java.net.URI; +import java.net.URISyntaxException; + +public class IrcConfiguration implements Cloneable { + + String target; + String hostname; + String password; + String nickname; + String realname; + String username; + boolean persistent = true; + boolean colors = true; + boolean onNick = true; + boolean onQuit = true; + boolean onJoin = true; + boolean onKick = true; + boolean onMode = true; + boolean onPart = true; + boolean onTopic = true; + boolean onPrivmsg = true; + int[] ports = {6667, 6668, 6669}; + + public IrcConfiguration() { + } + + public IrcConfiguration(String hostname, String nickname, String displayname, String target) { + this.target = target; + this.hostname = hostname; + this.nickname = nickname; + this.username = nickname; + this.realname = displayname; + } + + public IrcConfiguration(String hostname, String username, String password, String nickname, String displayname, String target) { + this.target = target; + this.hostname = hostname; + this.username = username; + this.password = password; + this.nickname = nickname; + this.realname = displayname; + } + + public IrcConfiguration copy() { + try { + return (IrcConfiguration) clone(); + } + catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } + + public String getCacheKey() { + return hostname + ":" + nickname; + } + + public void configure(URI uri) { + setNickname(uri.getUserInfo()); + setUsername(uri.getUserInfo()); + setRealname(uri.getUserInfo()); + setHostname(uri.getHost()); + setTarget(uri.getPath().substring(1)); + + } + + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + public String getRealname() { + return realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public int[] getPorts() { + return ports; + } + + public void setPorts(int[] ports) { + this.ports = ports; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public boolean isPersistent() { + return persistent; + } + + public void setPersistent(boolean persistent) { + this.persistent = persistent; + } + + public boolean isColors() { + return colors; + } + + public void setColors(boolean colors) { + this.colors = colors; + } + + public boolean isOnNick() { + return onNick; + } + + public void setOnNick(boolean onNick) { + this.onNick = onNick; + } + + public boolean isOnQuit() { + return onQuit; + } + + public void setOnQuit(boolean onQuit) { + this.onQuit = onQuit; + } + + public boolean isOnJoin() { + return onJoin; + } + + public void setOnJoin(boolean onJoin) { + this.onJoin = onJoin; + } + + public boolean isOnKick() { + return onKick; + } + + public void setOnKick(boolean onKick) { + this.onKick = onKick; + } + + public boolean isOnMode() { + return onMode; + } + + public void setOnMode(boolean onMode) { + this.onMode = onMode; + } + + public boolean isOnPart() { + return onPart; + } + + public void setOnPart(boolean onPart) { + this.onPart = onPart; + } + + public boolean isOnTopic() { + return onTopic; + } + + public void setOnTopic(boolean onTopic) { + this.onTopic = onTopic; + } + + public boolean isOnPrivmsg() { + return onPrivmsg; + } + + public void setOnPrivmsg(boolean onPrivmsg) { + this.onPrivmsg = onPrivmsg; + } + + public String toString() { + return "IrcConfiguration{" + + "target='" + target + '\'' + + ", hostname='" + hostname + '\'' + + ", password='" + password + '\'' + + ", nickname='" + nickname + '\'' + + ", realname='" + realname + '\'' + + ", username='" + username + '\'' + + ", persistent=" + persistent + + ", colors=" + colors + + ", onNick=" + onNick + + ", onQuit=" + onQuit + + ", onJoin=" + onJoin + + ", onKick=" + onKick + + ", onMode=" + onMode + + ", onPart=" + onPart + + ", onTopic=" + onTopic + + ", onPrivmsg=" + onPrivmsg + + ", ports=" + ports + + '}'; + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,183 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.Processor; +import org.apache.camel.impl.DefaultConsumer; +import org.schwering.irc.lib.IRCConnection; +import org.schwering.irc.lib.IRCEventAdapter; +import org.schwering.irc.lib.IRCModeParser; +import org.schwering.irc.lib.IRCUser; + +public class IrcConsumer extends DefaultConsumer<IrcExchange> { + final private IrcEndpoint endpoint; + final private IRCConnection connection; + final IrcConfiguration configuration; + private FilteredIRCEventAdapter listener = null; + + public IrcConsumer(IrcEndpoint endpoint, Processor processor, IRCConnection connection) { + super(endpoint, processor); + this.endpoint = endpoint; + this.connection = connection; + configuration = endpoint.getConfiguration(); + } + + + @Override + protected void doStop() throws Exception { + connection.doPart(endpoint.getConfiguration().getTarget()); + connection.removeIRCEventListener(listener); + } + + @Override + protected void doStart() throws Exception { + connection.addIRCEventListener(new FilteredIRCEventAdapter(endpoint.getConfiguration().getTarget())); + connection.doJoin(endpoint.getConfiguration().getTarget()); + super.doStart(); + } + + public IRCConnection getConnection() { + return connection; + } + + class FilteredIRCEventAdapter extends IRCEventAdapter { + final String target; + + public FilteredIRCEventAdapter(String target) { + this.target = target; + } + + + @Override + public void onNick(IRCUser user, String newNick) { + if (configuration.isOnNick()) { + IrcExchange exchange = endpoint.createOnNickExchange(user, newNick); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + + @Override + public void onQuit(IRCUser user, String msg) { + if (configuration.isOnQuit()) { + IrcExchange exchange = endpoint.createOnQuitExchange(user, msg); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + + @Override + public void onJoin(String channel, IRCUser user) { + if (configuration.isOnJoin()) { + if (channel.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnJoinExchange(channel, user); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + @Override + public void onKick(String channel, IRCUser user, String passiveNick, String msg) { + if (configuration.isOnKick()) { + if (channel.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnKickExchange(channel, user, passiveNick, msg); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + @Override + public void onMode(String channel, IRCUser user, IRCModeParser modeParser) { + if (configuration.isOnMode()) { + if (channel.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnModeExchange(channel, user, modeParser); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + @Override + public void onPart(String channel, IRCUser user, String msg) { + if (configuration.isOnPart()) { + if (channel.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnPartExchange(channel, user, msg); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + @Override + public void onTopic(String channel, IRCUser user, String topic) { + if (configuration.isOnTopic()) { + if (channel.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnTopicExchange(channel, user, topic); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + @Override + public void onPrivmsg(String target, IRCUser user, String msg) { + if (configuration.isOnPrivmsg()) { + if (target.equals(configuration.getTarget())) { + IrcExchange exchange = endpoint.createOnPrivmsgExchange(target, user, msg); + try { + getProcessor().process(exchange); + } catch (Exception e) { + // TODO: what should we do when a processing failure occurs?? + e.printStackTrace(); + } + } + } + } + + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,198 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.Processor; +import org.apache.camel.impl.DefaultEndpoint; +import org.schwering.irc.lib.IRCConnection; +import org.schwering.irc.lib.IRCModeParser; +import org.schwering.irc.lib.IRCUser; + +import java.io.IOException; + +public class IrcEndpoint extends DefaultEndpoint<IrcExchange> { + + private IrcBinding binding; + private IrcConfiguration configuration; + private IrcComponent component; + + public IrcEndpoint(String endpointUri, IrcComponent component, IrcConfiguration configuration) { + super(endpointUri, component); + this.component = component; + this.configuration = configuration; + } + + public boolean isSingleton() { + return false; + } + + public IrcExchange createExchange() { + return new IrcExchange(getContext(), getBinding()); + } + + public IrcExchange createOnPrivmsgExchange(String target, IRCUser user, String msg) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("PRIVMSG", target, user, msg)); + } + + public IrcExchange createOnNickExchange(IRCUser user, String newNick) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("NICK", user, newNick)); + } + + public IrcExchange createOnQuitExchange(IRCUser user, String msg) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("QUIT", user, msg)); + } + + public IrcExchange createOnJoinExchange(String channel, IRCUser user) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("JOIN", channel, user)); + } + + public IrcExchange createOnKickExchange(String channel, IRCUser user, String whoWasKickedNick, String msg) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("KICK", channel, user, whoWasKickedNick, msg)); + } + + public IrcExchange createOnModeExchange(String channel, IRCUser user, IRCModeParser modeParser) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("MODE", channel, user, modeParser.getLine())); + } + + public IrcExchange createOnPartExchange(String channel, IRCUser user, String msg) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("PART", channel, user, msg)); + } + + public IrcExchange createOnTopicExchange(String channel, IRCUser user, String topic) { + return new IrcExchange(getContext(), getBinding(), new IrcMessage("TOPIC", channel, user, topic)); + } + + public IrcProducer createProducer() throws Exception { + return new IrcProducer(this, component.getIRCConnection(configuration)); + } + + public IrcConsumer createConsumer(Processor processor) throws Exception { + return new IrcConsumer(this, processor, component.getIRCConnection(configuration)); + } + + public IrcComponent getComponent() { + return component; + } + + public void setComponent(IrcComponent component) { + this.component = component; + } + + public IrcBinding getBinding() { + if (binding == null) { + binding = new IrcBinding(); + } + return binding; + } + + public void setBinding(IrcBinding binding) { + this.binding = binding; + } + + public IrcConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(IrcConfiguration configuration) { + this.configuration = configuration; + } + + public static void main(String[] args) throws InterruptedException { + final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-irc", "Camel IRC Component", "#camel-irc"); + final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(), config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname()); +// conn.addIRCEventListener(new IRCEventAdapter() { +// +// @Override +// public void onRegistered() { +// super.onRegistered(); +// System.out.println("onRegistered"); +// } +// +// @Override +// public void onDisconnected() { +// super.onDisconnected(); +// System.out.println("onDisconnected"); +// } +// +// @Override +// public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser) { +// super.onMode(string, ircUser, ircModeParser); +// System.out.println("onMode.string = " + string); +// System.out.println("onMode.ircUser = " + ircUser); +// System.out.println("onMode.ircModeParser = " + ircModeParser); +// } +// +// @Override +// public void onMode(IRCUser ircUser, String string, String string1) { +// super.onMode(ircUser, string, string1); +// System.out.println("onMode.ircUser = " + ircUser); +// System.out.println("onMode.string = " + string); +// System.out.println("onMode.string1 = " + string1); +// } +// +// @Override +// public void onPing(String string) { +// super.onPing(string); +// System.out.println("onPing.string = " + string); +// } +// +// @Override +// public void onError(String string) { +// System.out.println("onError.string = " + string); +// } +// +// @Override +// public void onError(int i, String string) { +// super.onError(i, string); +// System.out.println("onError.i = " + i); +// System.out.println("onError.string = " + string); +// } +// +// @Override +// public void unknown(String string, String string1, String string2, String string3) { +// super.unknown(string, string1, string2, string3); +// System.out.println("unknown.string = " + string); +// System.out.println("unknown.string1 = " + string1); +// System.out.println("unknown.string2 = " + string2); +// System.out.println("unknown.string3 = " + string3); +// } +// }); + conn.setEncoding("UTF-8"); + conn.setDaemon(true); + conn.setColors(false); + conn.setPong(true); + + try { + conn.connect(); + } catch (IOException e) { + e.printStackTrace(); + } +// while (!conn.isConnected()) { +// Thread.sleep(1000); +// System.out.println("Sleeping"); +// } + System.out.println("Connected"); +// conn.send("/JOIN #CAMEL"); +// conn.doPrivmsg("nnordrum", "hi!"); +// System.out.println("Joining Channel"); + conn.doJoin(config.getTarget()); + Thread.sleep(Integer.MAX_VALUE); + } + +} + Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,76 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.CamelContext; +import org.apache.camel.Message; +import org.apache.camel.Exchange; +import org.schwering.irc.lib.IRCUser; + +public class IrcExchange extends DefaultExchange { + private IrcBinding binding; + + public IrcExchange(CamelContext context, IrcBinding binding) { + super(context); + this.binding = binding; + } + + public IrcExchange(CamelContext context, IrcBinding binding, IrcMessage inMessage) { + this(context, binding); + setIn(inMessage); + } + + public IrcBinding getBinding() { + return binding; + } + + public void setBinding(IrcBinding binding) { + this.binding = binding; + } + + @Override + public IrcMessage getIn() { + return (IrcMessage) super.getIn(); + } + + @Override + public IrcMessage getOut() { + return (IrcMessage) super.getOut(); + } + + @Override + public IrcMessage getFault() { + return (IrcMessage) super.getFault(); + } + + @Override + public IrcExchange newInstance() { + return new IrcExchange(getContext(), getBinding()); + } + + @Override + protected IrcMessage createInMessage() { + return new IrcMessage(); + } + + @Override + protected IrcMessage createOutMessage() { + return new IrcMessage(); + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,145 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.impl.DefaultMessage; +import org.schwering.irc.lib.IRCUser; + +import java.util.Map; +import java.util.HashMap; + +public class IrcMessage extends DefaultMessage { + private String messageType; + private String target; + private IRCUser user; + private String whoWasKickedNick; + private String message; + + public IrcMessage() { + } + + public IrcMessage(String messageType, IRCUser user, String message) { + this.messageType = messageType; + this.user = user; + this.message = message; + } + + public IrcMessage(String messageType, String target, IRCUser user, String message) { + this.messageType = messageType; + this.target = target; + this.user = user; + this.message = message; + } + + public IrcMessage(String messageType, String target, IRCUser user, String whoWasKickedNick, String message) { + this.messageType = messageType; + this.target = target; + this.user = user; + this.whoWasKickedNick = whoWasKickedNick; + this.message = message; + } + + public IrcMessage(String messageType, String target, IRCUser user) { + this.messageType = messageType; + this.target = target; + this.user = user; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public IRCUser getUser() { + return user; + } + + public void setUser(IRCUser user) { + this.user = user; + } + + public String getWhoWasKickedNick() { + return whoWasKickedNick; + } + + public void setWhoWasKickedNick(String whoWasKickedNick) { + this.whoWasKickedNick = whoWasKickedNick; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public IrcExchange getExchange() { + return (IrcExchange) super.getExchange(); + } + + @Override + protected Object createBody() { + IrcExchange ircExchange = getExchange(); + IrcBinding binding = ircExchange.getBinding(); + return binding.extractBodyFromIrc(ircExchange, message); + } + + @Override + public IrcMessage newInstance() { + return new IrcMessage(); + } + + @Override + protected void populateInitialHeaders(Map<String, Object> map) { + map.put("irc.messageType", messageType); + if (target != null) { + map.put("irc.target", target); + } + if (whoWasKickedNick != null) { + map.put("irc.user.kicked", whoWasKickedNick); + } + if (user != null) { + map.put("irc.user.host", user.getHost()); + map.put("irc.user.nick", user.getNick()); + map.put("irc.user.servername", user.getServername()); + map.put("irc.user.username", user.getUsername()); + } + } + + @Override + public String toString() { + if (message != null) { + return "IrcMessage: " + message; + } else { + return "IrcMessage: " + getBody(); + } + } +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java (added) +++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java Mon Jun 25 07:24:50 2007 @@ -0,0 +1,66 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.irc; + +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.impl.DefaultProducer; +import org.schwering.irc.lib.IRCConnection; + +public class IrcProducer extends DefaultProducer<IrcExchange> { + private IRCConnection connection; + private IrcEndpoint endpoint; + + public IrcProducer(IrcEndpoint endpoint, IRCConnection connection) { + super(endpoint); + this.endpoint = endpoint; + this.connection = connection; + } + + public void process(Exchange exchange) throws Exception { + try { + final String msg = exchange.getIn().getBody(String.class); + if (isMessageACommand(msg)) { + connection.send(msg); + } else { + final String target = endpoint.getConfiguration().getTarget(); + connection.doPrivmsg(target, msg); + } + } catch (Exception e) { + throw new RuntimeCamelException(e); + } + } + + protected boolean isMessageACommand(String msg) { + for (String command : commands) { + if (msg.startsWith(command)) { + return true; + } + } + return false; + } + + public final String[] commands = new String[]{ + "AWAY", "INVITE", "ISON", "JOIN", + "KICK", "LIST", "NAMES", "PRIVMSG", + "MODE", "NICK", "NOTICE", "PART", + "PONG", "QUIT", "TOPIC", "WHO", + "WHOIS", "WHOWAS", "USERHOST" + }; + +} Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/irc URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/irc?view=auto&rev=550510 ============================================================================== --- activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/irc (added) +++ activemq/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/irc Mon Jun 25 07:24:50 2007 @@ -0,0 +1 @@ +class=org.apache.camel.component.irc.IrcComponent \ No newline at end of file Modified: activemq/camel/trunk/components/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?view=diff&rev=550510&r1=550509&r2=550510 ============================================================================== --- activemq/camel/trunk/components/pom.xml (original) +++ activemq/camel/trunk/components/pom.xml Mon Jun 25 07:24:50 2007 @@ -39,6 +39,7 @@ <module>camel-cxf</module> <module>camel-ftp</module> <module>camel-http</module> + <module>camel-irc</module> <module>camel-jaxb</module> <module>camel-jbi</module> <module>camel-jms</module> Modified: activemq/camel/trunk/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?view=diff&rev=550510&r1=550509&r2=550510 ============================================================================== --- activemq/camel/trunk/pom.xml (original) +++ activemq/camel/trunk/pom.xml Mon Jun 25 07:24:50 2007 @@ -190,6 +190,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-irc</artifactId> + <version>${camel-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-jbi</artifactId> <version>${camel-version}</version> </dependency> |
Free forum by Nabble | Edit this page |