001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.irc; 018 019 import java.util.Map; 020 021 import org.apache.camel.impl.DefaultMessage; 022 023 import org.schwering.irc.lib.IRCUser; 024 025 public class IrcMessage extends DefaultMessage { 026 private String messageType; 027 private String target; 028 private IRCUser user; 029 private String whoWasKickedNick; 030 private String message; 031 032 public IrcMessage() { 033 } 034 035 public IrcMessage(String messageType, IRCUser user, String message) { 036 this.messageType = messageType; 037 this.user = user; 038 this.message = message; 039 } 040 041 public IrcMessage(String messageType, String target, IRCUser user, String message) { 042 this.messageType = messageType; 043 this.target = target; 044 this.user = user; 045 this.message = message; 046 } 047 048 public IrcMessage(String messageType, String target, IRCUser user, String whoWasKickedNick, String message) { 049 this.messageType = messageType; 050 this.target = target; 051 this.user = user; 052 this.whoWasKickedNick = whoWasKickedNick; 053 this.message = message; 054 } 055 056 public IrcMessage(String messageType, String target, IRCUser user) { 057 this.messageType = messageType; 058 this.target = target; 059 this.user = user; 060 } 061 062 public String getMessageType() { 063 return messageType; 064 } 065 066 public void setMessageType(String messageType) { 067 this.messageType = messageType; 068 } 069 070 public String getTarget() { 071 return target; 072 } 073 074 public void setTarget(String target) { 075 this.target = target; 076 } 077 078 public IRCUser getUser() { 079 return user; 080 } 081 082 public void setUser(IRCUser user) { 083 this.user = user; 084 } 085 086 public String getWhoWasKickedNick() { 087 return whoWasKickedNick; 088 } 089 090 public void setWhoWasKickedNick(String whoWasKickedNick) { 091 this.whoWasKickedNick = whoWasKickedNick; 092 } 093 094 public String getMessage() { 095 return message; 096 } 097 098 public void setMessage(String message) { 099 this.message = message; 100 } 101 102 @Override 103 public IrcExchange getExchange() { 104 return (IrcExchange)super.getExchange(); 105 } 106 107 @Override 108 protected Object createBody() { 109 IrcExchange ircExchange = getExchange(); 110 IrcBinding binding = ircExchange.getBinding(); 111 return binding.extractBodyFromIrc(ircExchange, this); 112 } 113 114 @Override 115 public IrcMessage newInstance() { 116 return new IrcMessage(); 117 } 118 119 @Override 120 protected void populateInitialHeaders(Map<String, Object> map) { 121 map.put("irc.messageType", messageType); 122 if (target != null) { 123 map.put("irc.target", target); 124 } 125 if (whoWasKickedNick != null) { 126 map.put("irc.user.kicked", whoWasKickedNick); 127 } 128 if (user != null) { 129 map.put("irc.user.host", user.getHost()); 130 map.put("irc.user.nick", user.getNick()); 131 map.put("irc.user.servername", user.getServername()); 132 map.put("irc.user.username", user.getUsername()); 133 } 134 } 135 136 @Override 137 public String toString() { 138 if (message != null) { 139 return "IrcMessage: " + message; 140 } else { 141 return "IrcMessage: " + getBody(); 142 } 143 } 144 }