Loads of fixes, TODOs and comments.

fix-message-formatting
Danny van Heumen 11 years ago
parent 6059ab6164
commit 148df2d18b

@ -121,8 +121,8 @@ public class ChatRoomIrcImpl
* @param chatRoomName the name of the chat room
* @param parentProvider the protocol provider
*/
public ChatRoomIrcImpl(String chatRoomName,
ProtocolProviderServiceIrcImpl parentProvider)
public ChatRoomIrcImpl(final String chatRoomName,
final ProtocolProviderServiceIrcImpl parentProvider)
{
this(chatRoomName, parentProvider, false);
}
@ -135,25 +135,30 @@ public ChatRoomIrcImpl(String chatRoomName,
* @param chatRoomName the name of the chat room (cannot be null or empty
* string)
* @param parentProvider the protocol provider
* @param isPrivate indicates if this chat room is a private one
* @param isSystem indicates if this chat room is a system room
*/
public ChatRoomIrcImpl( String chatRoomName,
ProtocolProviderServiceIrcImpl parentProvider,
boolean isSystem)
public ChatRoomIrcImpl(final String chatRoomName,
final ProtocolProviderServiceIrcImpl parentProvider,
final boolean isSystem)
{
if (parentProvider == null)
{
throw new IllegalArgumentException("parentProvider cannot be null");
}
this.parentProvider = parentProvider;
if (chatRoomName == null || chatRoomName.isEmpty())
{
throw new IllegalArgumentException(
"chatRoomName cannot be null or empty string");
}
this.chatRoomName = chatRoomName;
this.isSystem = isSystem;
}
/**
* hashCode implementation for Chat Room.
*
* @return returns hash code for this instance
*/
@Override
public int hashCode()
@ -171,9 +176,12 @@ public int hashCode()
/**
* equals implementation for Chat Room.
*
* @param obj other instance
* @return returns true if equal or false if not
*/
@Override
public boolean equals(Object obj)
public boolean equals(final Object obj)
{
if (this == obj)
return true;
@ -198,7 +206,7 @@ public String getName()
{
return chatRoomName;
}
/**
* Returns the identifier of this <tt>ChatRoom</tt>.
*
@ -209,15 +217,15 @@ public String getIdentifier()
{
return chatRoomName;
}
/**
* Adds a <tt>ChatRoomMember</tt> to the list of members of this chat room.
*
* @param memberID the identifier of the member
* @param member the <tt>ChatRoomMember</tt> to add.
*/
protected void addChatRoomMember(String memberID, ChatRoomMember member)
protected void addChatRoomMember(final String memberID,
final ChatRoomMember member)
{
chatRoomMembers.put(memberID, member);
}
@ -228,7 +236,7 @@ protected void addChatRoomMember(String memberID, ChatRoomMember member)
*
* @param memberID the name of the <tt>ChatRoomMember</tt> to remove.
*/
protected void removeChatRoomMember(String memberID)
protected void removeChatRoomMember(final String memberID)
{
chatRoomMembers.remove(memberID);
}
@ -243,14 +251,17 @@ protected void removeChatRoomMember(String memberID)
public void join() throws OperationFailedException
{
if (!parentProvider.getIrcStack().isConnected())
{
throw new OperationFailedException(
"We are currently not connected to the server.",
OperationFailedException.NETWORK_FAILURE);
}
if (parentProvider.getIrcStack().isJoined(this))
throw new OperationFailedException(
"Channel is already joined.",
{
throw new OperationFailedException("Channel is already joined.",
OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS);
}
parentProvider.getIrcStack().join(this);
}
@ -264,7 +275,7 @@ public void join() throws OperationFailedException
* @throws OperationFailedException with the corresponding code if an error
* occurs while joining the room.
*/
public void join(byte[] password) throws OperationFailedException
public void join(final byte[] password) throws OperationFailedException
{
parentProvider.getIrcStack().join(this, password.toString());
}
@ -279,7 +290,7 @@ public void join(byte[] password) throws OperationFailedException
* @throws OperationFailedException with the corresponding code if an error
* occurs while joining the room.
*/
public void joinAs(String nickname) throws OperationFailedException
public void joinAs(final String nickname) throws OperationFailedException
{
this.setUserNickname(nickname);
this.join();
@ -297,7 +308,7 @@ public void joinAs(String nickname) throws OperationFailedException
* @throws OperationFailedException with the corresponding code if an error
* occurs while joining the room.
*/
public void joinAs(String nickname, byte[] password)
public void joinAs(final String nickname, final byte[] password)
throws OperationFailedException
{
this.setUserNickname(nickname);
@ -350,8 +361,8 @@ public Iterator<ChatRoomMember> getBanList()
* @throws OperationFailedException if we are not joined or we don't have
* enough privileges to ban a participant.
*/
public void banParticipant(ChatRoomMember chatRoomMember, String reason)
throws OperationFailedException
public void banParticipant(final ChatRoomMember chatRoomMember,
final String reason) throws OperationFailedException
{
this.parentProvider.getIrcStack().banParticipant(this,
chatRoomMember, reason);
@ -365,8 +376,8 @@ public void banParticipant(ChatRoomMember chatRoomMember, String reason)
* @throws OperationFailedException if we are not joined or we don't have
* enough privileges to kick a participant.
*/
public void kickParticipant(ChatRoomMember chatRoomMember, String reason)
throws OperationFailedException
public void kickParticipant(final ChatRoomMember chatRoomMember,
final String reason) throws OperationFailedException
{
this.parentProvider.getIrcStack().kickParticipant(this,
chatRoomMember, reason);
@ -399,12 +410,14 @@ public ChatRoomConfigurationForm getConfigurationForm()
* @param listener ChatRoomChangeListener
*/
public void addPropertyChangeListener(
ChatRoomPropertyChangeListener listener)
final ChatRoomPropertyChangeListener listener)
{
synchronized (propertyChangeListeners)
{
if (!propertyChangeListeners.contains(listener))
{
propertyChangeListeners.add(listener);
}
}
}
@ -415,7 +428,7 @@ public void addPropertyChangeListener(
* @param listener the <tt>ChatRoomChangeListener</tt> to remove.
*/
public void removePropertyChangeListener(
ChatRoomPropertyChangeListener listener)
final ChatRoomPropertyChangeListener listener)
{
synchronized (propertyChangeListeners)
{
@ -432,12 +445,14 @@ public void removePropertyChangeListener(
* that is to be registered for <tt>ChatRoomMemberPropertyChangeEvent</tt>s.
*/
public void addMemberPropertyChangeListener(
ChatRoomMemberPropertyChangeListener listener)
final ChatRoomMemberPropertyChangeListener listener)
{
synchronized(memberPropChangeListeners)
synchronized (memberPropChangeListeners)
{
if (!memberPropChangeListeners.contains(listener))
{
memberPropChangeListeners.add(listener);
}
}
}
@ -449,9 +464,9 @@ public void addMemberPropertyChangeListener(
* remove.
*/
public void removeMemberPropertyChangeListener(
ChatRoomMemberPropertyChangeListener listener)
final ChatRoomMemberPropertyChangeListener listener)
{
synchronized(memberPropChangeListeners)
synchronized (memberPropChangeListeners)
{
memberPropChangeListeners.remove(listener);
}
@ -463,12 +478,14 @@ public void removeMemberPropertyChangeListener(
*
* @param listener a member role listener.
*/
public void addMemberRoleListener(ChatRoomMemberRoleListener listener)
public void addMemberRoleListener(final ChatRoomMemberRoleListener listener)
{
synchronized (memberRoleListeners)
{
if (!memberRoleListeners.contains(listener))
{
memberRoleListeners.add(listener);
}
}
}
@ -478,12 +495,15 @@ public void addMemberRoleListener(ChatRoomMemberRoleListener listener)
*
* @param listener a member role listener.
*/
public void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
public void removeMemberRoleListener(
final ChatRoomMemberRoleListener listener)
{
synchronized (memberRoleListeners)
{
if (memberRoleListeners.contains(listener))
{
memberRoleListeners.remove(listener);
}
}
}
@ -493,12 +513,15 @@ public void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
*
* @param listener a local user role listener.
*/
public void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
public void addLocalUserRoleListener(
final ChatRoomLocalUserRoleListener listener)
{
synchronized (localUserRoleListeners)
{
if (!localUserRoleListeners.contains(listener))
{
localUserRoleListeners.add(listener);
}
}
}
@ -509,12 +532,14 @@ public void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
* @param listener a local user role listener.
*/
public void removelocalUserRoleListener(
ChatRoomLocalUserRoleListener listener)
final ChatRoomLocalUserRoleListener listener)
{
synchronized (localUserRoleListeners)
{
if (localUserRoleListeners.contains(listener))
{
localUserRoleListeners.remove(listener);
}
}
}
@ -547,7 +572,7 @@ public String getSubject()
* channel or if he/she doesn't have enough privileges to change the
* topic or if the topic is null.
*/
public void setSubject(String subject)
public void setSubject(final String subject)
throws OperationFailedException
{
parentProvider.getIrcStack().setSubject(this, subject);
@ -576,7 +601,7 @@ public String getUserNickname()
* @throws OperationFailedException if the setting the new nickname changes
* for some reason.
*/
public void setUserNickname(String nickName)
public void setUserNickname(final String nickName)
throws OperationFailedException
{
parentProvider.getIrcStack().setUserNickname(nickName);
@ -589,12 +614,14 @@ public void setUserNickname(String nickName)
* @param listener a participant status listener.
*/
public void addMemberPresenceListener(
ChatRoomMemberPresenceListener listener)
final ChatRoomMemberPresenceListener listener)
{
synchronized (memberListeners)
{
if (!memberListeners.contains(listener))
{
memberListeners.add(listener);
}
}
}
@ -606,7 +633,7 @@ public void addMemberPresenceListener(
* @param listener a participant status listener.
*/
public void removeMemberPresenceListener(
ChatRoomMemberPresenceListener listener)
final ChatRoomMemberPresenceListener listener)
{
synchronized (memberListeners)
{
@ -621,12 +648,14 @@ public void removeMemberPresenceListener(
* @param listener a <tt>MessageListener</tt> that would be notified every
* time a new message is received on this chat room.
*/
public void addMessageListener(ChatRoomMessageListener listener)
public void addMessageListener(final ChatRoomMessageListener listener)
{
synchronized (messageListeners)
{
if (!messageListeners.contains(listener))
{
messageListeners.add(listener);
}
}
}
@ -636,12 +665,14 @@ public void addMessageListener(ChatRoomMessageListener listener)
*
* @param listener the <tt>MessageListener</tt> to remove from this room
*/
public void removeMessageListener(ChatRoomMessageListener listener)
public void removeMessageListener(final ChatRoomMessageListener listener)
{
synchronized (messageListeners)
{
if (messageListeners.contains(listener))
{
messageListeners.remove(messageListeners.indexOf(listener));
}
}
}
@ -653,7 +684,7 @@ public void removeMessageListener(ChatRoomMessageListener listener)
* @param memberID the identifier of the member
* @return the <tt>ChatRoomMember</tt> corresponding to the given member id.
*/
public ChatRoomMember getChatRoomMember(String memberID)
public ChatRoomMember getChatRoomMember(final String memberID)
{
return chatRoomMembers.get(memberID);
}
@ -679,7 +710,7 @@ protected void clearChatRoomMemberList()
* the user why they are being invited.
*/
@Override
public void invite(String userAddress, String reason)
public void invite(final String userAddress, final String reason)
{
// TODO Check if channel status is invite-only (+i). If this is the
// case, user has to be channel operator in order to be able to invite
@ -720,15 +751,12 @@ public int getMembersCount()
* subject.
* @return the newly created message.
*/
public Message createMessage( byte[] content,
String contentType,
String contentEncoding,
String subject)
public Message createMessage(final byte[] content, final String contentType,
final String contentEncoding, final String subject)
{
Message msg = new MessageIrcImpl( new String(content),
contentType,
contentEncoding,
subject);
Message msg =
new MessageIrcImpl(new String(content), contentType,
contentEncoding, subject);
return msg;
}
@ -740,7 +768,7 @@ public Message createMessage( byte[] content,
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
public Message createMessage(final String messageText)
{
Message mess = new MessageIrcImpl(
messageText,
@ -759,22 +787,24 @@ public Message createMessage(String messageText)
* @throws OperationFailedException if the underlying stack is not
* registered or initialized or if the chat room is not joined.
*/
public void sendMessage(Message message) throws OperationFailedException
public void sendMessage(final Message message)
throws OperationFailedException
{
assertConnected();
String[] splitMessages = message.getContent().split("\n");
String messagePortion = null;
for (int i = 0; i < splitMessages.length; i ++)
for (int i = 0; i < splitMessages.length; i++)
{
messagePortion = splitMessages[i];
// As we only send one message per line, we ignore empty lines in
// the incoming multi line message.
if(messagePortion.equals("\n")
|| messagePortion.matches("[\\ ]*"))
if (messagePortion.equals("\n") || messagePortion.matches("[\\ ]*"))
{
continue;
}
if (((MessageIrcImpl) message).isCommand())
{
@ -785,11 +815,9 @@ public void sendMessage(Message message) throws OperationFailedException
parentProvider.getIrcStack().message(this, messagePortion);
}
this.fireMessageDeliveredEvent(
new MessageIrcImpl( messagePortion,
message.getContentType(),
message.getEncoding(),
message.getSubject()));
this.fireMessageDeliveredEvent(new MessageIrcImpl(messagePortion,
message.getContentType(), message.getEncoding(), message
.getSubject()));
}
}
@ -806,19 +834,24 @@ public ProtocolProviderService getParentProvider()
/**
* Utility method throwing an exception if the stack is not properly
* initialized.
* @throws java.lang.IllegalStateException if the underlying stack is
* not registered and initialized.
*
* @throws java.lang.IllegalStateException if the underlying stack is not
* registered and initialized.
*/
private void assertConnected() throws IllegalStateException
{
if (parentProvider == null)
{
throw new IllegalStateException(
"The provider must be non-null and signed on the "
+"service before being able to communicate.");
+ "service before being able to communicate.");
}
if (!parentProvider.isRegistered())
{
throw new IllegalStateException(
"The provider must be signed on the service before "
+"being able to communicate.");
+ "being able to communicate.");
}
}
/**
@ -827,7 +860,7 @@ private void assertConnected() throws IllegalStateException
*
* @param message the delivered message
*/
private void fireMessageDeliveredEvent(Message message)
private void fireMessageDeliveredEvent(final Message message)
{
int eventType
= ChatRoomMessageDeliveredEvent.CONVERSATION_MESSAGE_DELIVERED;
@ -839,9 +872,11 @@ private void fireMessageDeliveredEvent(Message message)
eventType = ChatRoomMessageDeliveredEvent.ACTION_MESSAGE_DELIVERED;
if (msg.getContent().indexOf(' ') != -1)
{
msg.setContent(
msg.getContent()
.substring(message.getContent().indexOf(' ')));
}
}
ChatRoomMessageDeliveredEvent msgDeliveredEvt
@ -858,7 +893,9 @@ private void fireMessageDeliveredEvent(Message message)
}
for (ChatRoomMessageListener listener : listeners)
{
listener.messageDelivered(msgDeliveredEvt);
}
}
/**
@ -873,17 +910,12 @@ private void fireMessageDeliveredEvent(Message message)
* XXX_MESSAGE_RECEIVED constants declared in the
* <tt>ChatRoomMessageReceivedEvent</tt> class.
*/
public void fireMessageReceivedEvent( Message message,
ChatRoomMember fromMember,
Date date,
int eventType)
public void fireMessageReceivedEvent(final Message message,
final ChatRoomMember fromMember, final Date date, final int eventType)
{
ChatRoomMessageReceivedEvent event
= new ChatRoomMessageReceivedEvent( this,
fromMember,
date,
message,
eventType);
ChatRoomMessageReceivedEvent event =
new ChatRoomMessageReceivedEvent(this, fromMember, date, message,
eventType);
Iterable<ChatRoomMessageListener> listeners;
synchronized (messageListeners)
@ -893,7 +925,9 @@ public void fireMessageReceivedEvent( Message message,
}
for (ChatRoomMessageListener listener : listeners)
{
listener.messageReceived(event);
}
}
/**
@ -902,9 +936,8 @@ public void fireMessageReceivedEvent( Message message,
* @param evt the <tt>PropertyChangeEvent</tt> that we'd like delivered to
* all registered property change listeners.
*/
public void firePropertyChangeEvent(PropertyChangeEvent evt)
public void firePropertyChangeEvent(final PropertyChangeEvent evt)
{
Iterable<ChatRoomPropertyChangeListener> listeners;
synchronized (propertyChangeListeners)
{
@ -935,7 +968,7 @@ else if (evt instanceof ChatRoomPropertyChangeFailedEvent)
* deliver to all registered member property change listeners.
*/
public void fireMemberPropertyChangeEvent(
ChatRoomMemberPropertyChangeEvent evt)
final ChatRoomMemberPropertyChangeEvent evt)
{
Iterable<ChatRoomMemberPropertyChangeListener> listeners;
synchronized (memberPropChangeListeners)
@ -946,7 +979,9 @@ public void fireMemberPropertyChangeEvent(
}
for (ChatRoomMemberPropertyChangeListener listener : listeners)
{
listener.chatRoomPropertyChanged(evt);
}
}
/**
@ -960,10 +995,9 @@ public void fireMemberPropertyChangeEvent(
* @param eventID the identifier of the event
* @param eventReason the reason of the event
*/
public void fireMemberPresenceEvent(ChatRoomMember member,
ChatRoomMember actorMember,
String eventID,
String eventReason)
public void fireMemberPresenceEvent(final ChatRoomMember member,
final ChatRoomMember actorMember, final String eventID,
final String eventReason)
{
// First update local state w.r.t. member presence change
if (eventID == ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED)
@ -974,17 +1008,23 @@ public void fireMemberPresenceEvent(ChatRoomMember member,
{
removeChatRoomMember(member.getContactAddress());
}
ChatRoomMemberPresenceChangeEvent evt;
if(actorMember != null)
if (actorMember != null)
{
evt = new ChatRoomMemberPresenceChangeEvent(
this, member, actorMember, eventID, eventReason);
}
else
{
evt = new ChatRoomMemberPresenceChangeEvent(
this, member, eventID, eventReason);
}
if (LOGGER.isTraceEnabled())
{
LOGGER.trace("Will dispatch the following ChatRoom event: " + evt);
}
Iterable<ChatRoomMemberPresenceListener> listeners;
synchronized (memberListeners)
@ -994,7 +1034,9 @@ public void fireMemberPresenceEvent(ChatRoomMember member,
memberListeners);
}
for (ChatRoomMemberPresenceListener listener : listeners)
{
listener.memberPresenceChanged(evt);
}
}
/**
@ -1005,8 +1047,8 @@ public void fireMemberPresenceEvent(ChatRoomMember member,
* @param member the <tt>ChatRoomMember</tt> that this event is about
* @param newRole the new role of the given member
*/
public void fireMemberRoleEvent( ChatRoomMember member,
ChatRoomMemberRole newRole)
public void fireMemberRoleEvent(final ChatRoomMember member,
final ChatRoomMemberRole newRole)
{
member.setRole(newRole);
ChatRoomMemberRole previousRole = member.getRole();
@ -1018,7 +1060,9 @@ public void fireMemberRoleEvent( ChatRoomMember member,
newRole);
if (LOGGER.isTraceEnabled())
{
LOGGER.trace("Will dispatch the following ChatRoom event: " + evt);
}
Iterable<ChatRoomMemberRoleListener> listeners;
synchronized (memberRoleListeners)
@ -1029,17 +1073,19 @@ public void fireMemberRoleEvent( ChatRoomMember member,
}
for (ChatRoomMemberRoleListener listener : listeners)
{
listener.memberRoleChanged(evt);
}
}
/**
* Notify all <tt>ChatRoomLocalUserRoleListener</tt>s that the local user's
* role has been changed in this <tt>ChatRoom</tt>.
*
*
* @param event the event that describes the local user's role change
*/
public void fireLocalUserRoleChangedEvent(
ChatRoomLocalUserRoleChangeEvent event)
final ChatRoomLocalUserRoleChangeEvent event)
{
ArrayList<ChatRoomLocalUserRoleListener> listeners;
synchronized (localUserRoleListeners)
@ -1074,7 +1120,7 @@ public boolean isSystem()
* @param isSystem <code>true</code> to indicate that this chat room is
* corresponding to a server channel, <code>false</code> - otherwise.
*/
protected void setSystem(boolean isSystem)
protected void setSystem(final boolean isSystem)
{
this.isSystem = isSystem;
}
@ -1084,7 +1130,7 @@ protected void setSystem(boolean isSystem)
*
* @param subject the subject to set
*/
protected void setSubjectFromServer(String subject)
protected void setSubjectFromServer(final String subject)
{
this.chatSubject = subject;
}
@ -1117,13 +1163,13 @@ public ChatRoomMemberRole getUserRole()
}
return this.user.getRole();
}
/**
* Method for setting chat room member instance representing the user.
*
*
* @param user instance representing the user. This instance cannot be null.
*/
void setLocalUser(ChatRoomMemberIrcImpl user)
void setLocalUser(final ChatRoomMemberIrcImpl user)
{
if (user == null)
{
@ -1134,23 +1180,25 @@ void setLocalUser(ChatRoomMemberIrcImpl user)
/**
* Sets the local user role.
*
* No implementation is necessary for this. IRC server manages permissions.
* If a new chat room is created then user will automatically receive the
* appropriate role.
*
* @param role the role to set
* @throws OperationFailedException if the operation don't succeed
*/
@Override
public void setLocalUserRole(ChatRoomMemberRole role)
public void setLocalUserRole(final ChatRoomMemberRole role)
throws OperationFailedException
{
// No implementation necessary. IRC server manages permissions. If a new
// chat room is created then user will automatically receive the
// appropriate role.
}
/**
* Grants admin role to the participant given by <tt>address</tt>.
* @param address the address of the participant to grant admin role to
*/
public void grantAdmin(String address)
public void grantAdmin(final String address)
{
this.parentProvider.getIrcStack().grant(this, address, Mode.OPERATOR);
}
@ -1159,7 +1207,7 @@ public void grantAdmin(String address)
* Grants membership role to the participant given by <tt>address</tt>.
* @param address the address of the participant to grant membership role to
*/
public void grantMembership(String address)
public void grantMembership(final String address)
{
// TODO currently Voice == Membership.
this.parentProvider.getIrcStack().grant(this, address, Mode.VOICE);
@ -1169,7 +1217,7 @@ public void grantMembership(String address)
* Grants moderator role to the participant given by <tt>address</tt>.
* @param address the address of the participant to grant moderator role to
*/
public void grantModerator(String address)
public void grantModerator(final String address)
{
this.parentProvider.getIrcStack().grant(this, address, Mode.HALFOP);
}
@ -1178,7 +1226,7 @@ public void grantModerator(String address)
* Grants ownership role to the participant given by <tt>address</tt>.
* @param address the address of the participant to grant ownership role to
*/
public void grantOwnership(String address)
public void grantOwnership(final String address)
{
this.parentProvider.getIrcStack().grant(this, address, Mode.OWNER);
}
@ -1187,7 +1235,7 @@ public void grantOwnership(String address)
* Grants voice to the participant given by <tt>address</tt>.
* @param address the address of the participant to grant voice to
*/
public void grantVoice(String address)
public void grantVoice(final String address)
{
// TODO currently Voice == Membership.
this.parentProvider.getIrcStack().grant(this, address, Mode.VOICE);
@ -1197,7 +1245,7 @@ public void grantVoice(String address)
* Revokes the admin role for the participant given by <tt>address</tt>.
* @param address the address of the participant to revoke admin role for
*/
public void revokeAdmin(String address)
public void revokeAdmin(final String address)
{
this.parentProvider.getIrcStack().revoke(this, address, Mode.OPERATOR);
}
@ -1205,11 +1253,11 @@ public void revokeAdmin(String address)
/**
* Revokes the membership role for the participant given by <tt>address</tt>
* .
*
*
* @param address the address of the participant to revoke membership role
* for
*/
public void revokeMembership(String address)
public void revokeMembership(final String address)
{
this.parentProvider.getIrcStack().revoke(this, address, Mode.VOICE);
}
@ -1219,7 +1267,7 @@ public void revokeMembership(String address)
* @param address the address of the participant to revoke moderator role
* for
*/
public void revokeModerator(String address)
public void revokeModerator(final String address)
{
this.parentProvider.getIrcStack().revoke(this, address, Mode.HALFOP);
}
@ -1229,7 +1277,7 @@ public void revokeModerator(String address)
* @param address the address of the participant to revoke ownership role
* for
*/
public void revokeOwnership(String address)
public void revokeOwnership(final String address)
{
this.parentProvider.getIrcStack().revoke(this, address, Mode.OWNER);
}
@ -1238,7 +1286,7 @@ public void revokeOwnership(String address)
* Revokes the voice for the participant given by <tt>address</tt>.
* @param address the address of the participant to revoke voice for
*/
public void revokeVoice(String address)
public void revokeVoice(final String address)
{
this.parentProvider.getIrcStack().revoke(this, address, Mode.VOICE);
}
@ -1248,17 +1296,23 @@ public void revokeVoice(String address)
*
* Not implemented.
*/
public ConferenceDescription publishConference(ConferenceDescription cd,
String name)
public ConferenceDescription publishConference(
final ConferenceDescription cd, final String name)
{
return null;
}
/**
* {@inheritDoc}
* Find the Contact instance corresponding to the specified chat room
* member. Since every chat room member is also a private contact, we will
* create an instance if it cannot be found.
*
* @param name nick name of the chat room member
* @return returns Contact instance corresponding to specified chat room
* member
*/
@Override
public Contact getPrivateContactByNickname(String name)
public Contact getPrivateContactByNickname(final String name)
{
LOGGER.debug("Getting private contact for nick name '" + name + "'.");
return this.parentProvider.getPersistentPresence()
@ -1266,40 +1320,44 @@ public Contact getPrivateContactByNickname(String name)
}
/**
* {@inheritDoc}
* IRC does not provide continuous presence status updates, so no
* implementation is necessary.
*
* @param nickname nick name to look up
*/
@Override
public void updatePrivateContactPresenceStatus(String nickname)
public void updatePrivateContactPresenceStatus(final String nickname)
{
// IRC does not provide continuous presence status updates.
}
/**
* {@inheritDoc}
* IRC does not provide continuous presence status updates, so no
* implementation is necessary.
*
* @param sourceContact contact to look up
*/
@Override
public void updatePrivateContactPresenceStatus(Contact sourceContact)
public void updatePrivateContactPresenceStatus(final Contact sourceContact)
{
// IRC does not provide continuous presence status updates.
}
/**
* Destroys the chat room.
*
* IRC chat rooms cannot be destroyed. That is the way IRC works and there
* is no need to cause a panic, so just return true.
*
* @param reason the reason for destroying.
* @param alternateAddress the alternate address
* @return <tt>true</tt> if the room is destroyed.
*/
public boolean destroy(String reason, String alternateAddress)
public boolean destroy(final String reason, final String alternateAddress)
{
// IRC chat rooms cannot be destroyed
return true;
}
/**
* Returns the ids of the users that has the member role in the room. When
* the room is member only, this are the users allowed to join.
*
*
* @return the ids of the users that has the member role in the room.
*/
@Override
@ -1314,15 +1372,16 @@ public List<String> getMembersWhiteList()
* @param members the ids of user to have member role.
*/
@Override
public void setMembersWhiteList(List<String> members)
{}
public void setMembersWhiteList(final List<String> members)
{
}
/**
* Update the subject for this chat room.
*
*
* @param subject the subject
*/
public void updateSubject(String subject)
public void updateSubject(final String subject)
{
if (!this.chatSubject.equals(subject))
{
@ -1333,22 +1392,24 @@ public void updateSubject(String subject)
firePropertyChangeEvent(topicChangeEvent);
}
}
/**
* Update the ChatRoomMember instance. When the nick changes, the chat room
* member is still stored under the old nick. Find the instance under its
* old nick and reinsert it into the map according to the current nick name.
*
*
* @param oldName The old nick name under which the member instance is
* currently stored.
*/
public void updateChatRoomMemberName(String oldName)
public void updateChatRoomMemberName(final String oldName)
{
synchronized(this.chatRoomMembers)
synchronized (this.chatRoomMembers)
{
ChatRoomMember member = this.chatRoomMembers.remove(oldName);
if (member != null)
{
this.chatRoomMembers.put(member.getContactAddress(), member);
}
}
}
}

@ -1,7 +1,8 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc;
@ -9,6 +10,11 @@
import net.java.sip.communicator.service.protocol.*;
/**
* Contact group for IRC.
*
* @author Danny van Heumen
*/
public class ContactGroupIrcImpl
implements ContactGroup
{
@ -16,58 +22,65 @@ public class ContactGroupIrcImpl
* The protocol provider service instance.
*/
private final ProtocolProviderServiceIrcImpl provider;
/**
* Group name.
*/
private final String name;
private String name;
/**
* Subgroups
* Subgroups.
*/
private final List<ContactGroupIrcImpl> subgroups = new ArrayList<ContactGroupIrcImpl>();
private final List<ContactGroupIrcImpl> subgroups =
new ArrayList<ContactGroupIrcImpl>();
/**
* Contacts in this group.
*/
private final List<ContactIrcImpl> contacts = new ArrayList<ContactIrcImpl>();
private final List<ContactIrcImpl> contacts =
new ArrayList<ContactIrcImpl>();
/**
* Parent contact group.
*/
private ContactGroup parent;
/**
* Contact Group IRC implementation.
*
*
* @param provider IRC protocol provider service instance.
*/
public ContactGroupIrcImpl(ProtocolProviderServiceIrcImpl provider)
public ContactGroupIrcImpl(final ProtocolProviderServiceIrcImpl provider)
{
this(provider, null, "root");
}
/**
* Contact Group IRC implementation.
*
*
* @param provider IRC protocol provider service instance.
* @param parentGroup Parent group
* @param name Group name
*/
public ContactGroupIrcImpl(ProtocolProviderServiceIrcImpl provider,
ContactGroupIrcImpl parentGroup, String name)
public ContactGroupIrcImpl(final ProtocolProviderServiceIrcImpl provider,
final ContactGroupIrcImpl parentGroup, final String name)
{
if (provider == null)
{
throw new IllegalArgumentException("provider cannot be null");
}
this.provider = provider;
this.parent = parentGroup;
if (name == null)
{
throw new IllegalArgumentException("name cannot be null");
}
this.name = name;
}
/**
* Get subgroups of this group.
*
*
* @return returns subgroups iterator
*/
@Override
@ -78,7 +91,7 @@ public Iterator<ContactGroup> subgroups()
/**
* Get number of subgroups.
*
*
* @return returns number of subgroups
*/
@Override
@ -89,27 +102,29 @@ public int countSubgroups()
/**
* Get subgroup by index.
*
*
* @param index index of subgroup
* @return returns subgroup
*/
@Override
public ContactGroup getGroup(int index)
public ContactGroup getGroup(final int index)
{
return this.subgroups.get(index);
}
/**
* Get subgroup by name.
*
*
* @param groupName Name of subgroup.
* @return returns subgroup or null if no group exists with that name
*/
@Override
public ContactGroup getGroup(String groupName)
public ContactGroup getGroup(final String groupName)
{
if (groupName == null)
{
return null;
}
for (ContactGroupIrcImpl group : this.subgroups)
{
if (groupName.equals(group.getGroupName()))
@ -122,7 +137,7 @@ public ContactGroup getGroup(String groupName)
/**
* Get contacts in group.
*
*
* @return returns group's contacts
*/
@Override
@ -133,7 +148,7 @@ public Iterator<Contact> contacts()
/**
* Get number of contacts in group.
*
*
* @return returns number of contacts in group
*/
@Override
@ -144,15 +159,17 @@ public int countContacts()
/**
* Get group contact by id.
*
*
* @param id contact ID
* @return returns contact or null if contact cannot be found
*/
@Override
public Contact getContact(String id)
public Contact getContact(final String id)
{
if (id == null)
{
return null;
}
for (ContactIrcImpl contact : this.contacts)
{
if (id.equals(contact.getAddress()))
@ -165,7 +182,7 @@ public Contact getContact(String id)
/**
* Check if group can contain subgroups.
*
*
* @return returns true if group can contain subgroups, or false otherwise.
*/
@Override
@ -176,7 +193,7 @@ public boolean canContainSubgroups()
/**
* Get name of the group.
*
*
* @return returns group name
*/
@Override
@ -185,9 +202,23 @@ public String getGroupName()
return this.name;
}
/**
* Set name of the group.
*
* @param name new name
*/
public void setGroupName(final String name)
{
if (name == null)
{
throw new IllegalArgumentException("name cannot be null");
}
this.name = name;
}
/**
* Get protocol provider service implementation.
*
*
* @return returns protocol provider service implementation
*/
@Override
@ -198,7 +229,7 @@ public ProtocolProviderServiceIrcImpl getProtocolProvider()
/**
* Get parent contact group.
*
*
* @return returns parent contact group or null if no parent group exists
*/
@Override
@ -209,7 +240,7 @@ public ContactGroup getParentContactGroup()
/**
* Is persistent group.
*
*
* @return returns true if group is persistent, or false if not.
*/
@Override
@ -220,18 +251,19 @@ public boolean isPersistent()
/**
* Get group UUID.
*
*
* @return returns group UUID
*/
@Override
public String getUID()
{
// FIXME Generate unique ID for contact group.
return null;
}
/**
* Is group resolved.
*
*
* @return returns true if group is resolved, or false otherwise
*/
@Override
@ -242,7 +274,7 @@ public boolean isResolved()
/**
* Get group persistent data.
*
*
* @return returns persistent data
*/
@Override
@ -253,25 +285,29 @@ public String getPersistentData()
/**
* Add contact to the group.
*
*
* @param contact Contact to be added.
*/
public void addContact(ContactIrcImpl contact)
public void addContact(final ContactIrcImpl contact)
{
if (contact == null)
{
throw new IllegalArgumentException("contact cannot be null");
}
this.contacts.add(contact);
}
/**
* Add group as subgroup to this group.
*
*
* @param group the group
*/
public void addSubGroup(ContactGroupIrcImpl group)
public void addSubGroup(final ContactGroupIrcImpl group)
{
if (group == null)
{
throw new IllegalArgumentException("group cannot be null");
}
this.subgroups.add(group);
}
}

@ -1,13 +1,14 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc;
/**
* Enum with available IRC control characters.
*
* Available IRC control characters.
*
* @author Danny van Heumen
*/
public abstract class ControlChar
@ -19,17 +20,17 @@ public abstract class ControlChar
/**
* Constructor.
*
* @param code the control code
*
* @param htmlTag the control code
*/
private ControlChar(final String htmlTag)
{
this.tag = htmlTag;
}
/**
* The specified HTML tag.
*
*
* @return returns the HTML tag.
*/
public String getTag()
@ -39,7 +40,7 @@ public String getTag()
/**
* Get the HTML start tag.
*
*
* @return returns HTML start tag.
*/
public String getHtmlStart()
@ -49,44 +50,105 @@ public String getHtmlStart()
/**
* Get the HTML end tag.
*
*
* @return returns the HTML end tag
*/
public String getHtmlEnd()
{
return "</" + this.tag + ">";
}
/**
* Control char representation for 'bold' formatting.
*
* @author Danny van Heumen
*/
static class Bold extends ControlChar
{
/**
* IRC control code.
*/
public static final char CODE = '\u0002';
/**
* Constructor.
*/
Bold()
{
super("b");
}
}
/**
* Control char representation for 'italics' formatting.
*
* @author Danny van Heumen
*/
static class Italics extends ControlChar
{
/**
* IRC control code.
*/
public static final char CODE = '\u0016';
/**
* Constructor.
*/
Italics()
{
super("i");
}
}
/**
* Control char representation for underlining.
*
* @author Danny van Heumen
*/
static class Underline extends ControlChar
{
/**
* IRC control code.
*/
public static final char CODE = '\u001F';
/**
* Constructor.
*/
Underline()
{
super("u");
}
}
/**
* Control char representation for colored text.
*
* @author Danny van Heumen
*/
static class ColorFormat extends ControlChar
{
/**
* IRC control code.
*/
public static final char CODE = '\u0003';
/**
* Foreground color.
*/
private final Color foreground;
/**
* Background color.
*/
private final Color background;
/**
* Constructor.
*
* @param foreground foreground color
* @param background background color
*/
ColorFormat(final Color foreground, final Color background)
{
super("font");
@ -94,6 +156,13 @@ static class ColorFormat extends ControlChar
this.background = background;
}
/**
* Get HTML start tag with foreground and background color codes
* embedded.
*
* @return Returns string containing html start tag including foreground
* and background colors.
*/
public String getHtmlStart()
{
StringBuilder result = new StringBuilder("<");
@ -114,4 +183,30 @@ public String getHtmlStart()
return result.toString();
}
}
/**
* Control char representation for the cancellation of all active formatting
* options, i.e. return to normal.
*
* In the current implementation, you cannot instantiate this control char.
* Its use is purely symbolic, since it doesn't actually translate in
* additional HTML formatting tags.
*
* @author Danny van Heumen
*/
abstract static class Normal extends ControlChar
{
/**
* IRC control code.
*/
public static final char CODE = '\u000F';
/**
* Private constructor since it should not be instantiated.
*/
private Normal()
{
super(null);
}
}
}

@ -1,7 +1,8 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc;
@ -9,79 +10,80 @@
/**
* Builder for constructing a formatted text.
*
*
* @author Danny van Heumen
*/
public class FormattedTextBuilder
{
/**
* stack with formatting control chars
* stack with formatting control chars.
*/
private final Stack<ControlChar> formatting = new Stack<ControlChar>();
/**
* formatted text container
* formatted text container.
*/
private final StringBuilder text = new StringBuilder();
/**
* Append a string of text.
*
* @param text
*
* @param text string of text
*/
public void append(String text)
public void append(final String text)
{
this.text.append(text);
}
/**
* Append a character.
*
*
* @param c character
*/
public void append(char c)
public void append(final char c)
{
this.text.append(c);
}
/**
* Apply a control char for formatting.
*
* TODO Explicitly deny handling ControlChar.NORMAL?
*
*
* @param c the control char
*/
public void apply(ControlChar c)
public void apply(final ControlChar c)
{
// start control char formatting
this.formatting.add(c);
this.text.append(c.getHtmlStart());
}
/**
* Test whether or not a control character is already active.
*
* @param c the control char
* @return returns true if control char's kind of formatting is active, or
*
* @param controlClass the class of control char
* @return returns true if control char's class of formatting is active, or
* false otherwise.
*/
public boolean isActive(Class<? extends ControlChar> controlClass)
public boolean isActive(final Class<? extends ControlChar> controlClass)
{
for (ControlChar c : this.formatting)
{
if (c.getClass() == controlClass)
{
return true;
}
}
return false;
}
/**
* Cancel the specified control char.
*
* @param c the control char
* Cancel the active control char of the specified class.
*
* @param controlClass the class of control char
* @param stopAfterFirst stop after the first occurrence
*/
public void cancel(Class<? extends ControlChar> controlClass,
boolean stopAfterFirst)
public void cancel(final Class<? extends ControlChar> controlClass,
final boolean stopAfterFirst)
{
final Stack<ControlChar> rewind = new Stack<ControlChar>();
while (!this.formatting.empty())
@ -92,7 +94,9 @@ public void cancel(Class<? extends ControlChar> controlClass,
if (current.getClass() == controlClass)
{
if (stopAfterFirst)
{
break;
}
}
else
{
@ -118,10 +122,12 @@ public void cancelAll()
this.text.append(c.getHtmlEnd());
}
}
/**
* Finish building the text string. Close outstanding control char
* formatting and returns the result.
*
* @return returns the complete string as it is built
*/
public String done()
{
@ -133,6 +139,8 @@ public String done()
* Return the formatted string in its current state. (This means that if
* {@link #done()} was not yet called, it will print an intermediate state
* of the formatted text.)
*
* @return returns current state of the formatted text
*/
public String toString()
{

@ -24,11 +24,12 @@ public class IrcAccountID
* IRC account server host.
*/
private final String host;
/**
* IRC account server port.
*/
private final int port;
/**
* Creates an account id from the specified id and account properties.
*
@ -54,16 +55,34 @@ public class IrcAccountID
this.port = Integer.parseInt(port);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + host.hashCode();
result = prime * result + port;
return result;
}
/**
* Equality extended with checking IRC server host and port, since different
* IRC networks can have users with similar names.
*
* @param obj other object
* @return returns true if equal or false otherwise
*/
@Override
public boolean equals(Object obj)
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
// TODO if available, base equality on NETWORK=<identifier> in
// RPL_ISUPPORT.
@ -71,10 +90,10 @@ public boolean equals(Object obj)
&& this.host.equals(((IrcAccountID) obj).host)
&& this.port == ((IrcAccountID) obj).port;
}
/**
* Get the IRC server host.
*
*
* @return returns IRC server host
*/
public String getHost()
@ -84,7 +103,7 @@ public String getHost()
/**
* Get the IRC server port.
*
*
* @return returns IRC server port
*/
public int getPort()
@ -96,12 +115,13 @@ public int getPort()
* Returns the service name - the server we are logging to if it is null
* which is not supposed to be - we return for compatibility the string we
* used in the first release for creating AccountID (Using this string is
* wrong, but used for compatibility for now)
* wrong, but used for compatibility for now).
*
* @param accountProperties Map the properties table configuring the account
* @return String the service name
*/
private static String getServiceName(Map<String, String> accountProperties)
private static String getServiceName(
final Map<String, String> accountProperties)
{
String serviceName =
accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
@ -119,7 +139,7 @@ private static String getServiceName(Map<String, String> accountProperties)
/**
* Get display name for this account instance.
*
*
* @return returns the display name for this AccountID instance
*/
@Override

@ -53,7 +53,7 @@ public class IrcActivator
/**
* Certificate Service instance.
*/
private static CertificateService certiticateService;
private static CertificateService certificateService;
/**
* MultiUserChat Service instance.
@ -191,18 +191,11 @@ public static UIService getUIService()
*/
public static CertificateService getCertificateService()
{
if (certiticateService == null)
if (certificateService == null)
{
ServiceReference<?> guiVerifyReference
= IrcActivator.getBundleContext().getServiceReference(
CertificateService.class.getName());
if (guiVerifyReference != null)
{
certiticateService = (CertificateService)
IrcActivator.getBundleContext().getService(
guiVerifyReference);
}
certificateService =
ServiceUtils.getService(bundleContext, CertificateService.class);
}
return certiticateService;
return certificateService;
}
}

@ -1259,7 +1259,7 @@ public void onError(final ErrorMessage msg)
public void onUserPrivMessage(final UserPrivMsg msg)
{
final String user = msg.getSource().getNick();
final String text = Utils.formatMessage(Utils.parse(msg.getText()));
final String text = Utils.formatMessage(Utils.parseIrcMessage(msg.getText()));
final MessageIrcImpl message =
new MessageIrcImpl(text,
OperationSetBasicInstantMessaging.HTML_MIME_TYPE,
@ -1302,7 +1302,7 @@ public void onUserNotice(final UserNotice msg)
// Jitsi set up.
final String user = msg.getSource().getNick();
final String text =
Utils.formatNotice(Utils.parse(msg.getText()), user);
Utils.formatNotice(Utils.parseIrcMessage(msg.getText()), user);
final MessageIrcImpl message =
new MessageIrcImpl(text,
OperationSetBasicInstantMessaging.HTML_MIME_TYPE,
@ -1326,7 +1326,7 @@ public void onUserAction(final UserActionMsg msg)
{
final String user = msg.getSource().getNick();
final String text =
Utils.formatAction(Utils.parse(msg.getText()), user);
Utils.formatAction(Utils.parseIrcMessage(msg.getText()), user);
final MessageIrcImpl message =
new MessageIrcImpl(text,
OperationSetBasicInstantMessaging.HTML_MIME_TYPE,
@ -1707,7 +1707,7 @@ public void onChannelMessage(final ChannelPrivMsg msg)
return;
}
String text = Utils.formatMessage(Utils.parse(msg.getText()));
String text = Utils.formatMessage(Utils.parseIrcMessage(msg.getText()));
MessageIrcImpl message =
new MessageIrcImpl(text, "text/html", "UTF-8", null);
ChatRoomMemberIrcImpl member =
@ -1736,7 +1736,7 @@ public void onChannelAction(final ChannelActionMsg msg)
new ChatRoomMemberIrcImpl(IrcStack.this.provider,
this.chatroom, userNick, ChatRoomMemberRole.MEMBER);
String text =
Utils.formatAction(Utils.parse(msg.getText()), userNick);
Utils.formatAction(Utils.parseIrcMessage(msg.getText()), userNick);
MessageIrcImpl message =
new MessageIrcImpl(text, "text/html", "UTF-8", null);
this.chatroom.fireMessageReceivedEvent(message, member, new Date(),
@ -1761,7 +1761,7 @@ public void onChannelNotice(final ChannelNotice msg)
new ChatRoomMemberIrcImpl(IrcStack.this.provider,
this.chatroom, userNick, ChatRoomMemberRole.MEMBER);
final String text =
Utils.formatNotice(Utils.parse(msg.getText()), userNick);
Utils.formatNotice(Utils.parseIrcMessage(msg.getText()), userNick);
final MessageIrcImpl message =
new MessageIrcImpl(text, "text/html", "UTF-8", null);
this.chatroom.fireMessageReceivedEvent(message, member, new Date(),

@ -17,8 +17,9 @@
* @author Stephane Remy
* @author Loic Kempf
* @author Lubomir Marinov
* @author Danny van Heumen
*/
public class IrcStatusEnum
public final class IrcStatusEnum
extends PresenceStatus
{
@ -54,13 +55,15 @@ public class IrcStatusEnum
/**
* Initialize the list of supported status states.
*/
private static final List<IrcStatusEnum> supportedStatusSet
private static final List<IrcStatusEnum> SUPPORTED_STATUS_SET
= new LinkedList<IrcStatusEnum>();
static
{
supportedStatusSet.add(OFFLINE);
supportedStatusSet.add(AWAY);
supportedStatusSet.add(ONLINE);
SUPPORTED_STATUS_SET.add(OFFLINE);
// TODO implement support for presence status AWAY
//supportedStatusSet.add(AWAY);
SUPPORTED_STATUS_SET.add(ONLINE);
}
/**
@ -70,9 +73,8 @@ public class IrcStatusEnum
* @param statusName the name of the presence status.
* @param statusIcon the icon associated with this status
*/
private IrcStatusEnum(int status,
String statusName,
byte[] statusIcon)
private IrcStatusEnum(final int status, final String statusName,
final byte[] statusIcon)
{
super(status, statusName, statusIcon);
}
@ -85,7 +87,7 @@ private IrcStatusEnum(int status,
*/
static Iterator<IrcStatusEnum> supportedStatusSet()
{
return supportedStatusSet.iterator();
return SUPPORTED_STATUS_SET.iterator();
}
/**
@ -96,7 +98,7 @@ static Iterator<IrcStatusEnum> supportedStatusSet()
* @return the byte representation of the image corresponding to the given
* identifier.
*/
private static byte[] getImageInBytes(String imageID)
private static byte[] getImageInBytes(final String imageID)
{
return ProtocolIconIrcImpl.getImageInBytes(imageID);
}

@ -53,7 +53,7 @@ public class OperationSetMultiUserChatIrcImpl
* ProtocolProviderServiceIrcImpl.
*/
public OperationSetMultiUserChatIrcImpl(
ProtocolProviderServiceIrcImpl provider)
final ProtocolProviderServiceIrcImpl provider)
{
this.ircProvider = provider;
}
@ -83,7 +83,7 @@ public List<String> getExistingChatRooms() throws OperationFailedException
*/
public List<ChatRoom> getCurrentlyJoinedChatRooms()
{
synchronized(chatRoomCache)
synchronized (chatRoomCache)
{
List<ChatRoom> joinedRooms
= new LinkedList<ChatRoom>(this.chatRoomCache.values());
@ -93,7 +93,9 @@ public List<ChatRoom> getCurrentlyJoinedChatRooms()
while (joinedRoomsIter.hasNext())
{
if (!joinedRoomsIter.next().isJoined())
{
joinedRoomsIter.remove();
}
}
return joinedRooms;
@ -110,25 +112,25 @@ public List<ChatRoom> getCurrentlyJoinedChatRooms()
* and is currently active in.
*/
public List<String> getCurrentlyJoinedChatRooms(
ChatRoomMember chatRoomMember)
final ChatRoomMember chatRoomMember)
{
// Implement "who is" for the IRC stack.
// (currently not in use)
/*
* According to the RFC:
*
*
* 311 RPL_WHOISUSER "<nick> <user> <host> * :<real name>"
*
*
* 312 RPL_WHOISSERVER "<nick> <server> :<server info>"
*
*
* 313 RPL_WHOISOPERATOR "<nick> :is an IRC operator"
*
*
* 317 RPL_WHOISIDLE "<nick> <integer> :seconds idle"
*
*
* 318 RPL_ENDOFWHOIS "<nick> :End of /WHOIS list"
*
*
* 319 RPL_WHOISCHANNELS "<nick> :{[@|+]<channel><space>}"
*
*
* - Replies 311 - 313, 317 - 319 are all replies generated in response
* to a WHOIS message. Given that there are enough parameters present,
* the answering server must either formulate a reply out of the above
@ -141,7 +143,7 @@ public List<String> getCurrentlyJoinedChatRooms(
* moderated channel. The RPL_ENDOFWHOIS reply is used to mark the end
* of processing a WHOIS message.
*/
return null;
return Collections.emptyList();
}
/**
@ -163,8 +165,8 @@ public List<String> getCurrentlyJoinedChatRooms(
* @return the newly created <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoom createChatRoom(
String roomName,
Map<String, Object> roomProperties)
final String roomName,
final Map<String, Object> roomProperties)
throws OperationFailedException,
OperationNotSupportedException
{
@ -173,28 +175,28 @@ public ChatRoom createChatRoom(
/**
* Returns a reference to a chatRoom named <tt>roomName</tt>.
*
*
* Originally, this method would create the room if it doesn't exist. This
* is not acceptable anymore, since rebuilding the chat room list would
* create new instances without the IRC stack being prepared for this or
* having corresponding instances.
*
*
* @param roomName the name of the <tt>ChatRoom</tt> that we're looking for.
* @return the <tt>ChatRoom</tt> named <tt>roomName</tt>.
*/
public ChatRoomIrcImpl findRoom(String roomName)
public ChatRoomIrcImpl findRoom(final String roomName)
{
return chatRoomCache.get(roomName);
}
/**
* Find an existing room with the provided name, or create a new room with
* this name.
*
*
* @param roomName name of the chat room
* @return returns a chat room
*/
public ChatRoomIrcImpl findOrCreateRoom(String roomName)
public ChatRoomIrcImpl findOrCreateRoom(final String roomName)
{
synchronized (this.chatRoomCache)
{
@ -213,9 +215,10 @@ public ChatRoomIrcImpl findOrCreateRoom(String roomName)
* @param invitation the invitation we are rejecting.
* @param reason the reason of rejecting
*/
public void rejectInvitation(ChatRoomInvitation invitation, String reason)
public void rejectInvitation(final ChatRoomInvitation invitation,
final String reason)
{
//TODO: Implement reject invitation.
//TODO Implement reject invitation.
}
/**
@ -226,7 +229,7 @@ public void rejectInvitation(ChatRoomInvitation invitation, String reason)
* @return a boolean indicating whether <tt>contact</tt> supports chat
* rooms.
*/
public boolean isMultiChatSupportedByContact(Contact contact)
public boolean isMultiChatSupportedByContact(final Contact contact)
{
return true;
}
@ -240,21 +243,22 @@ public boolean isMultiChatSupportedByContact(Contact contact)
* @return the <tt>ChatRoomJabberImpl</tt> instance that has been cached
* for <tt>chatRoomName</tt> or null if no such room has been cached so far.
*/
protected ChatRoomIrcImpl getChatRoom(String chatRoomName)
protected ChatRoomIrcImpl getChatRoom(final String chatRoomName)
{
return (ChatRoomIrcImpl)this.chatRoomCache.get(chatRoomName);
return (ChatRoomIrcImpl) this.chatRoomCache.get(chatRoomName);
}
/**
* Creates a <tt>ChatRoom</tt> from the specified chat room name.
*
*
* Must be used in SYNCHRONIZED context.
*
* @param chatRoomName the name of the chat room to add
*
* @return ChatRoom the chat room that we've just created.
*/
private ChatRoomIrcImpl createLocalChatRoomInstance(String chatRoomName)
private ChatRoomIrcImpl createLocalChatRoomInstance(
final String chatRoomName)
{
ChatRoomIrcImpl chatRoom =
new ChatRoomIrcImpl(chatRoomName, ircProvider);
@ -263,13 +267,13 @@ private ChatRoomIrcImpl createLocalChatRoomInstance(String chatRoomName)
return chatRoom;
}
/**
* Register chat room instance in case it is not yet registered.
*
*
* @param chatroom the chatroom
*/
public void registerChatRoomInstance(ChatRoomIrcImpl chatroom)
public void registerChatRoomInstance(final ChatRoomIrcImpl chatroom)
{
synchronized (this.chatRoomCache)
{
@ -286,10 +290,10 @@ public void registerChatRoomInstance(ChatRoomIrcImpl chatroom)
* @param reason the reason why the inviter sent the invitation
* @param password the password to use when joining the room
*/
protected void fireInvitationEvent(ChatRoom targetChatRoom,
String inviter,
String reason,
byte[] password)
protected void fireInvitationEvent(final ChatRoom targetChatRoom,
final String inviter,
final String reason,
final byte[] password)
{
ChatRoomInvitationIrcImpl invitation
= new ChatRoomInvitationIrcImpl(targetChatRoom,
@ -307,7 +311,7 @@ protected void fireInvitationEvent(ChatRoom targetChatRoom,
*/
protected ChatRoomIrcImpl findSystemRoom()
{
if(serverChatRoom == null)
if (serverChatRoom == null)
{
serverChatRoom = new ChatRoomIrcImpl(
ircProvider.getAccountID().getService(),
@ -331,13 +335,17 @@ protected ChatRoomIrcImpl findSystemRoom()
protected ChatRoomMemberIrcImpl findSystemMember()
{
if (serverChatRoom.getMembers().size() > 0)
{
return (ChatRoomMemberIrcImpl) serverChatRoom.getMembers().get(0);
}
else
{
return new ChatRoomMemberIrcImpl(
ircProvider,
serverChatRoom,
ircProvider.getAccountID().getService(),
ChatRoomMemberRole.GUEST);
}
}
/**
@ -346,22 +354,22 @@ protected ChatRoomMemberIrcImpl findSystemMember()
* Always returns <tt>true</tt>.
*/
@Override
public boolean isPrivateMessagingContact(String contactAddress)
public boolean isPrivateMessagingContact(final String contactAddress)
{
return true;
}
/**
* Open a chat room window.
*
*
* In IRC a situation may occur where the user gets joined to a channel
* without Jitsi initiating the joining activity. This "unannounced" join
* event, must also be handled and we should display the chat room window in
* that case, to alert the user that this happened.
*
*
* @param chatRoom the chat room
*/
void openChatRoomWindow(ChatRoomIrcImpl chatRoom)
void openChatRoomWindow(final ChatRoomIrcImpl chatRoom)
{
MUCService mucService = IrcActivator.getMUCService();
UIService uiService = IrcActivator.getUIService();

@ -110,70 +110,126 @@ public ContactGroup getRootGroup()
return rootGroup;
}
/**
* IRC currently does not implement subscribing.
*
* @param contactIdentifier contact
* @throws OperationFailedException if not implemented
*/
@Override
public void subscribe(final String contactIdentifier)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
System.out.println("subscribe(\"" + contactIdentifier + "\") called");
// TODO Auto-generated method stub
LOGGER.trace("subscribe(\"" + contactIdentifier + "\") called");
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* IRC currently does not implement subscribing.
*
* @param parent contact group
* @param contactIdentifier contact
* @throws OperationFailedException if not implemented
*/
@Override
public void subscribe(ContactGroup parent, String contactIdentifier)
public void subscribe(final ContactGroup parent,
final String contactIdentifier)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
System.out.println("subscribe(\"" + parent.getGroupName() + "\", \""
LOGGER.trace("subscribe(\"" + parent.getGroupName() + "\", \""
+ contactIdentifier + "\") called");
// TODO Auto-generated method stub
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* IRC currently does not implement unsubscribing.
*
* @param contact contact to unsubscribe
* @throws OperationFailedException if not implemented
*/
@Override
public void unsubscribe(Contact contact)
public void unsubscribe(final Contact contact)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
System.out.println("unsubscribe(\"" + contact.getAddress()
+ "\") called");
// TODO Auto-generated method stub
LOGGER.trace("unsubscribe(\"" + contact.getAddress() + "\") called");
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Creating a contact group is currently not implemented.
*
* @param parent parent contact group
* @param groupName new group's name
* @throws OperationFailedException if not implemented
*/
@Override
public void createServerStoredContactGroup(ContactGroup parent,
String groupName) throws OperationFailedException
public void createServerStoredContactGroup(final ContactGroup parent,
final String groupName) throws OperationFailedException
{
// TODO Auto-generated method stub
LOGGER.trace("createServerStoredContactGroup(...) called");
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Removing a contact group is currently not implemented.
*
* @param group contact group to remove
* @throws OperationFailedException if not implemented
*/
@Override
public void removeServerStoredContactGroup(ContactGroup group)
public void removeServerStoredContactGroup(final ContactGroup group)
throws OperationFailedException
{
// TODO Auto-generated method stub
LOGGER.trace("removeServerStoredContactGroup called");
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Rename contact group.
*
* @param group contact group to rename
* @param newName new name
*/
@Override
public void renameServerStoredContactGroup(ContactGroup group,
String newName)
public void renameServerStoredContactGroup(final ContactGroup group,
final String newName)
{
// TODO Auto-generated method stub
LOGGER.trace("renameServerStoredContactGroup called");
((ContactGroupIrcImpl) group).setGroupName(newName);
}
/**
* Moving contacts to a different group is currently not implemented.
*
* @param contactToMove contact to move
* @param newParent new parent group
* @throws OperationFailedException if not implemented
*/
@Override
public void moveContactToGroup(Contact contactToMove, ContactGroup newParent)
throws OperationFailedException
public void moveContactToGroup(final Contact contactToMove,
final ContactGroup newParent) throws OperationFailedException
{
// TODO Auto-generated method stub
LOGGER.trace("moveContactToGroup called");
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Get group of contacts that have been discovered while using IRC.
*
* @return returns root contact group
*/
@Override
public ContactGroup getServerStoredContactListRoot()
{
@ -184,43 +240,77 @@ public ContactGroup getServerStoredContactListRoot()
}
@Override
public Contact createUnresolvedContact(String address,
String persistentData, ContactGroup parentGroup)
public Contact createUnresolvedContact(final String address,
final String persistentData, final ContactGroup parentGroup)
{
LOGGER.warn("Unresolved contact: " + address + " " + persistentData
+ " group: " + parentGroup.getGroupName());
// TODO Auto-generated method stub
// FIXME implement createUnresolvedContact
return null;
}
@Override
public ContactGroup createUnresolvedContactGroup(String groupUID,
String persistentData, ContactGroup parentGroup)
public Contact createUnresolvedContact(final String address,
final String persistentData)
{
LOGGER.warn("Unresolved contact: " + address + " " + persistentData);
// FIXME implement createUnresolvedContact
return null;
}
@Override
public ContactGroup createUnresolvedContactGroup(final String groupUID,
final String persistentData, final ContactGroup parentGroup)
{
LOGGER.warn("Unresolved contactgroup: " + groupUID + " "
+ persistentData + " parent: " + parentGroup.getGroupName());
// TODO Auto-generated method stub
// TODO implement createUnresolvedContactGroup
return null;
}
/**
* Get current IRC presence status.
*
* The presence status currently is ONLINE if we are connected or OFFLINE if
* we aren't connected.
*
* @return returns status ONLINE if connected or OFFLINE if not connected
*/
@Override
public PresenceStatus getPresenceStatus()
{
// TODO determine current Presence Status
return null;
// TODO implement AWAY presence if available in irc-api
if (this.parentProvider.getIrcStack().isConnected())
{
return IrcStatusEnum.ONLINE;
}
else
{
return IrcStatusEnum.OFFLINE;
}
}
/**
* "Publishing" presence status in IRC is currently not implemented.
*/
@Override
public void publishPresenceStatus(PresenceStatus status,
String statusMessage)
public void publishPresenceStatus(final PresenceStatus status,
final String statusMessage)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
// TODO Auto-generated method stub
// TODO implement publishPresenceStatus (we might be able to do
// something with modes invisible and away (IIRC) in IRC.
throw new OperationFailedException("Not implemented.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Get set of statuses supported in IRC.
*
* @return returns iterator for supported statuses
*/
@Override
public Iterator<PresenceStatus> getSupportedStatusSet()
{
@ -235,10 +325,11 @@ public Iterator<PresenceStatus> getSupportedStatusSet()
}
/**
* {@inheritDoc}
* IRC currently does not implement querying presence status.
*
* @param contactIdentifier contact id
* @return returns current presence status
* @throws OperationFailedException for not supporting this feature
*/
@Override
public PresenceStatus queryContactStatus(final String contactIdentifier)
@ -246,52 +337,71 @@ public PresenceStatus queryContactStatus(final String contactIdentifier)
IllegalStateException,
OperationFailedException
{
return IrcStatusEnum.ONLINE;
// TODO implement querying presence status of contact
throw new OperationFailedException("Not supported.",
OperationFailedException.NOT_SUPPORTED_OPERATION);
}
/**
* Find a contact by its ID.
*
* @param contactID ID to look up
* @return contact instance if found or null if nothing found
*/
@Override
public Contact findContactByID(String contactID)
public Contact findContactByID(final String contactID)
{
LOGGER.trace("Finding contact for nick name '" + contactID + "'");
if (contactID == null)
{
return null;
}
Contact contact = this.rootGroup.getContact(contactID);
if (contact != null)
{
return contact;
}
Iterator<ContactGroup> groups = this.rootGroup.subgroups();
while (groups.hasNext())
{
ContactGroup group = groups.next();
contact = group.getContact(contactID);
if (contact != null)
{
return contact;
}
}
LOGGER.trace("No contact found for nick name '" + contactID + "'");
return null;
}
/**
* IRC does not support authorization handling, so this is not supported.
*
* @param handler authorization handler
*/
@Override
public void setAuthorizationHandler(AuthorizationHandler handler)
public void setAuthorizationHandler(final AuthorizationHandler handler)
{
}
/**
* IRC does not have a status message, so it will always return an empty
* string.
*
* @return returns empty string
*/
@Override
public String getCurrentStatusMessage()
{
return null;
}
@Override
public Contact createUnresolvedContact(String address, String persistentData)
{
return null;
return "";
}
/**
* Find or create contact by ID.
*
* Try to find a contact by its ID. If a contact cannot be found, then
* create one.
* In IRC every chat room member is also a contact. Try to find a contact by
* its ID. If a contact cannot be found, then create one.
*
* @param id id of the contact
* @return returns instance of contact

@ -41,7 +41,7 @@ private Utils()
* @return returns the processed message or null if text message was null,
* since there is nothing to modify there
*/
public static String parse(final String text)
public static String parseIrcMessage(final String text)
{
if (text == null)
{
@ -54,7 +54,7 @@ public static String parse(final String text)
char val = text.charAt(i);
switch (val)
{
case '\u0002':
case ControlChar.Bold.CODE:
if (builder.isActive(ControlChar.Bold.class))
{
builder.cancel(ControlChar.Bold.class, true);
@ -64,7 +64,7 @@ public static String parse(final String text)
builder.apply(new ControlChar.Bold());
}
break;
case '\u0016':
case ControlChar.Italics.CODE:
if (builder.isActive(ControlChar.Italics.class))
{
builder.cancel(ControlChar.Italics.class, true);
@ -74,7 +74,7 @@ public static String parse(final String text)
builder.apply(new ControlChar.Italics());
}
break;
case '\u001F':
case ControlChar.Underline.CODE:
if (builder.isActive(ControlChar.Underline.class))
{
builder.cancel(ControlChar.Underline.class, true);
@ -84,30 +84,27 @@ public static String parse(final String text)
builder.apply(new ControlChar.Underline());
}
break;
case '\u0003':
Color background = null;
case ControlChar.ColorFormat.CODE:
// first parse foreground color code
Color foreground = parseForegroundColor(text.substring(i + 1));
if (foreground != null)
{
i += 2;
background = parseBackgroundColor(text.substring(i + 1));
Color background =
parseBackgroundColor(text.substring(i + 1));
if (background != null)
{
i += INDEX_END_COLOR_CODE;
}
}
if (foreground == null && background == null)
{
builder.cancel(ControlChar.ColorFormat.class, false);
builder.apply(new ControlChar.ColorFormat(foreground,
background));
}
else
{
builder.apply(new ControlChar.ColorFormat(foreground,
background));
builder.cancel(ControlChar.ColorFormat.class, false);
}
break;
case '\u000F':
case ControlChar.Normal.CODE:
builder.cancelAll();
break;
default:
@ -191,6 +188,7 @@ private static Color parseForegroundColor(final String text)
*/
public static String formatMessage(final String message)
{
// FIXME html entity encoding
return message;
}
@ -203,6 +201,7 @@ public static String formatMessage(final String message)
*/
public static String formatNotice(final String message, final String user)
{
// FIXME html entity encoding
return "<i>" + user + "</i>: " + message;
}
@ -215,6 +214,7 @@ public static String formatNotice(final String message, final String user)
*/
public static String formatAction(final String message, final String user)
{
// FIXME html entity encoding
return "<b>*" + user + "</b> " + message;
}
}

@ -21,4 +21,4 @@ Import-Package: org.osgi.framework,
com.ircclouds.irc.api.domain.messages,
com.ircclouds.irc.api.domain.messages.interfaces,
com.ircclouds.irc.api.listeners,
com.ircclouds.irc.api.state
com.ircclouds.irc.api.state

@ -39,8 +39,10 @@ public class FirstWizardPage
*/
public static final String FIRST_PAGE_IDENTIFIER = "FirstPageIdentifier";
// FIXME create resource string
public static final String USER_NAME_EXAMPLE = "Ex: ircuser";
// FIXME create resource string
public static final String SERVER_EXAMPLE = "Ex: chat.freenode.net";
private static final String DEFAULT_PLAINTEXT_PORT = "6667";

@ -24,19 +24,29 @@ public class IrcAccRegWizzActivator
{
private static Logger logger = Logger.getLogger(
IrcAccRegWizzActivator.class.getName());
/**
* OSGi bundle context.
*/
static BundleContext bundleContext;
private static UIService uiService;
private static WizardContainer wizardContainer;
private IrcAccountRegistrationWizard ircWizard;
public void start(Object dependentService)
/**
* Start the IRC account registration wizard.
*
* @param dependentService dependent service
*/
public void start(final Object dependentService)
{
if (logger.isInfoEnabled())
{
logger.info("Loading irc account wizard.");
}
uiService = (UIService) dependentService;
@ -54,26 +64,44 @@ public void start(Object dependentService)
containerFilter);
if (logger.isInfoEnabled())
{
logger.info("IRC account registration wizard [STARTED].");
}
}
/**
* Returns dependent service class.
*
* @return returns dependent service class
*/
public Class<?> getDependentServiceClass()
{
return UIService.class;
}
/**
* Set the bundle context.
*
* @param context bundle context
*/
@Override
public void setBundleContext(BundleContext context)
public void setBundleContext(final BundleContext context)
{
bundleContext = context;
this.bundleContext = context;
}
public void stop(BundleContext bundleContext)
/**
* Stop the IRC account registration wizard.
*
* @param bundleContext bundle context
*/
public void stop(final BundleContext bundleContext)
{
}
/**
* Returns the <tt>ProtocolProviderFactory</tt> for the IRC protocol.
*
* @return the <tt>ProtocolProviderFactory</tt> for the IRC protocol
*/
public static ProtocolProviderFactory getIrcProtocolProviderFactory()
@ -96,7 +124,12 @@ public static ProtocolProviderFactory getIrcProtocolProviderFactory()
return (ProtocolProviderFactory) bundleContext.getService(serRefs[0]);
}
/**
* Get UI Service instance.
*
* @return returns UIService instance
*/
public static UIService getUIService()
{
return uiService;

@ -26,18 +26,18 @@ protected void tearDown() throws Exception
public void testNullText()
{
Assert.assertEquals(null, Utils.parse(null));
Assert.assertEquals(null, Utils.parseIrcMessage(null));
}
public void testParseEmptyString()
{
Assert.assertEquals("", Utils.parse(""));
Assert.assertEquals("", Utils.parseIrcMessage(""));
}
public void testParseStringWithoutControlCodes()
{
final String message = "My normal message without any control codes.";
Assert.assertEquals(message, Utils.parse(message));
Assert.assertEquals(message, Utils.parseIrcMessage(message));
}
public void testParseStringWithBoldCode()
@ -45,7 +45,7 @@ public void testParseStringWithBoldCode()
final String ircMessage =
"My \u0002bold\u0002 message \u0002BOLD!\u0002.";
final String htmlMessage = "My <b>bold</b> message <b>BOLD!</b>.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithItalicsCode()
@ -53,7 +53,7 @@ public void testParseStringWithItalicsCode()
final String ircMessage =
"My \u0016italics\u0016 message \u0016ITALICS!\u0016.";
final String htmlMessage = "My <i>italics</i> message <i>ITALICS!</i>.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithUnderlineCode()
@ -62,14 +62,14 @@ public void testParseStringWithUnderlineCode()
"My \u001Funderlined\u001F message \u001FUNDERLINED!!!\u001F.";
final String htmlMessage =
"My <u>underlined</u> message <u>UNDERLINED!!!</u>.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithForegroundColorCode()
{
final String ircMessage = "My \u000304RED\u0003 message.";
final String htmlMessage = "My <font color=\"Red\">RED</font> message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithForegroundAndBackgroundColorCode()
@ -78,7 +78,7 @@ public void testParseStringWithForegroundAndBackgroundColorCode()
"My \u000304,12RED on Light Blue\u0003 message.";
final String htmlMessage =
"My <font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue</font> message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithInvalidBgColorCode()
@ -87,7 +87,7 @@ public void testParseStringWithInvalidBgColorCode()
"My \u000304,BRIGHT RED on Light Blue\u0003 message.";
final String htmlMessage =
"My <font color=\"Red\">,BRIGHT RED on Light Blue</font> message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithInvalidColorControlCode()
@ -96,7 +96,7 @@ public void testParseStringWithInvalidColorControlCode()
"My \u0003BRIGHT RED on Light Blue\u0003 message.";
final String htmlMessage =
"My BRIGHT RED on Light Blue message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithInvalidSecondControlCode()
@ -105,21 +105,21 @@ public void testParseStringWithInvalidSecondControlCode()
"My \u000304,12RED on Light Blue\u000304,12 message.";
final String htmlMessage =
"My <font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue<font color=\"Red\" bgcolor=\"RoyalBlue\"> message.</font></font>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithIncompleteForegroundColorControlCode()
{
final String ircMessage = "My \u0003";
final String htmlMessage = "My ";
Assert.assertTrue(Utils.parse(ircMessage).startsWith(htmlMessage));
Assert.assertTrue(Utils.parseIrcMessage(ircMessage).startsWith(htmlMessage));
}
public void testParseStringWithIncompleteBackgroundColorControlCode()
{
final String ircMessage = "My \u000310,";
final String htmlMessage = "My <font color=\"Teal\">,";
Assert.assertTrue(Utils.parse(ircMessage).startsWith(htmlMessage));
Assert.assertTrue(Utils.parseIrcMessage(ircMessage).startsWith(htmlMessage));
}
public void testParseSringAndNeutralizeWithNormalControlCode()
@ -128,7 +128,7 @@ public void testParseSringAndNeutralizeWithNormalControlCode()
"My \u0002\u0016\u001F\u000304,12RED on Light Blue\u000F message.";
final String htmlMessage =
"My <b><i><u><font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue</font></u></i></b> message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseStringWithUnclosedFormattingI()
@ -137,14 +137,14 @@ public void testParseStringWithUnclosedFormattingI()
"My \u0002\u0016\u001F\u000304,12RED on Light Blue message.";
final String htmlMessage =
"My <b><i><u><font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue message.</font></u></i></b>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseUnknownForegroundColor()
{
final String ircMessage = "\u000399TEST";
final String htmlMessage = "<font color=\"Green\">TEST</font>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testParseUnknownBackgroundColor()
@ -152,21 +152,21 @@ public void testParseUnknownBackgroundColor()
final String ircMessage = "\u000300,99TEST";
final String htmlMessage =
"<font color=\"White\" bgcolor=\"Green\">TEST</font>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testStackIncompatibleFormatToggling()
{
final String ircMessage = "\u0002\u0016\u001FHello\u0002 W\u0016orld\u001F!";
final String htmlMessage = "<b><i><u>Hello</u></i></b><i><u> W</u></i><u>orld</u>!";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testColorSwitch()
{
final String ircMessage = "\u000302,03Hello \u000308,09World\u000F!";
final String htmlMessage = "<font color=\"Navy\" bgcolor=\"Green\">Hello <font color=\"Yellow\" bgcolor=\"Lime\">World</font></font>!";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testForegroundColorChange()
@ -174,7 +174,14 @@ public void testForegroundColorChange()
// If only a foreground color is specified, leave the background color active/as is.
final String ircMessage = "\u000302,03Hello \u000308World\u000F!";
final String htmlMessage = "<font color=\"Navy\" bgcolor=\"Green\">Hello <font color=\"Yellow\">World</font></font>!";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testCancelColorFormat()
{
final String ircMessage = "\u000302With color\u0003 and without color.";
final String htmlMessage = "<font color=\"Navy\">With color</font> and without color.";
Assert.assertEquals(htmlMessage, Utils.parseIrcMessage(ircMessage));
}
public void testFormatMessage()

Loading…
Cancel
Save