aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl
diff options
context:
space:
mode:
authorEmil Ivov <emcho@jitsi.org>2008-07-11 23:58:06 +0000
committerEmil Ivov <emcho@jitsi.org>2008-07-11 23:58:06 +0000
commit7fc0bdc1e4ed324b6442e4e7d70b5be81cb368cb (patch)
tree8275eec33d79dc9538b3ce660e187a296ee0f076 /src/net/java/sip/communicator/impl
parent2660062eb4bb2994e35fd5e8be9d55cc8f8f05d5 (diff)
downloadjitsi-7fc0bdc1e4ed324b6442e4e7d70b5be81cb368cb.zip
jitsi-7fc0bdc1e4ed324b6442e4e7d70b5be81cb368cb.tar.gz
jitsi-7fc0bdc1e4ed324b6442e4e7d70b5be81cb368cb.tar.bz2
Added support for formatted messags in XMPP. Introduced a HTML_MIME_TYPE static field in OpSetBasicInstantMessaging
Diffstat (limited to 'src/net/java/sip/communicator/impl')
-rw-r--r--src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java4
-rw-r--r--src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java11
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java87
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java9
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java2
-rw-r--r--src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java4
-rw-r--r--src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java9
-rw-r--r--src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java11
8 files changed, 97 insertions, 40 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java
index c395464..626dda0 100644
--- a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java
@@ -227,7 +227,7 @@ public class OperationSetBasicInstantMessagingDictImpl
{
if(contentType.equals(DEFAULT_MIME_TYPE))
return true;
- else if(contentType.equals("text/html"))
+ else if(contentType.equals(HTML_MIME_TYPE))
return true;
else
return false;
@@ -299,7 +299,7 @@ public class OperationSetBasicInstantMessagingDictImpl
{
fctResult = dictAdapter.define(database, word);
msg = this.createMessage(this.retrieveDefine(fctResult, word).getBytes()
- , "text/html"
+ , HTML_MIME_TYPE
, DEFAULT_MIME_ENCODING,
null);
}
diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java
index 494cf10..d58fe3a 100644
--- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java
@@ -36,11 +36,6 @@ public class OperationSetBasicInstantMessagingIcqImpl
Logger.getLogger(OperationSetBasicInstantMessagingIcqImpl.class);
/**
- * HTML content type
- */
- private static final String CONTENT_TYPE_HTML = "text/html";
-
- /**
* A list of listeneres registered for message events.
*/
private Vector messageListeners = new Vector();
@@ -227,7 +222,7 @@ public class OperationSetBasicInstantMessagingIcqImpl
new Screenname(to.getAddress()));
String messageContent = null;
- if (message.getContentType().equals(CONTENT_TYPE_HTML)
+ if (message.getContentType().equals(HTML_MIME_TYPE)
&& !message.getContent().startsWith(defaultHtmlStartTag))
{
messageContent = defaultHtmlStartTag
@@ -403,7 +398,7 @@ public class OperationSetBasicInstantMessagingIcqImpl
public boolean isContentTypeSupported(String contentType)
{
if(contentType.equals(DEFAULT_MIME_TYPE) ||
- (contentType.equals(CONTENT_TYPE_HTML)))
+ (contentType.equals(HTML_MIME_TYPE)))
return true;
else
return false;
@@ -595,7 +590,7 @@ public class OperationSetBasicInstantMessagingIcqImpl
msgContent = msgBody;
Message newMessage = createMessage(msgContent.getBytes(),
- CONTENT_TYPE_HTML, DEFAULT_MIME_ENCODING, null);
+ HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, null);
Contact sourceContact =
opSetPersPresence.findContactByID( conversation.getBuddy()
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
index 3da1781..47c9695 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java
@@ -23,6 +23,7 @@ import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smack.util.*;
import org.jivesoftware.smackx.*;
+import org.jivesoftware.smackx.packet.XHTMLExtension;
/**
* A straightforward implementation of the basic instant messaging operation
@@ -78,6 +79,22 @@ public class OperationSetBasicInstantMessagingJabberImpl
* to match incoming messages to <tt>Contact</tt>s and vice versa.
*/
private OperationSetPersistentPresenceJabberImpl opSetPersPresence = null;
+
+ /**
+ * The opening BODY HTML TAG: &ltbody&gt
+ */
+ private static final String OPEN_BODY_TAG = "<body>";
+
+ /**
+ * The closing BODY HTML TAG: &ltbody&gt
+ */
+ private static final String CLOSE_BODY_TAG = "</body>";
+
+ /**
+ * The instance of the html2Txt converter that we use to send messages in
+ * both the text/html and text/plain content types.
+ */
+ private Html2Text html2Txt = new Html2Text();
/**
* Creates an instance of this operation set.
@@ -145,6 +162,18 @@ public class OperationSetBasicInstantMessagingJabberImpl
return new MessageJabberImpl(new String(content), contentType
, contentEncoding, subject);
}
+
+ /**
+ * Create a Message instance for sending arbitrary MIME-encoding content.
+ *
+ * @param content content value
+ * @param contentType the MIME-type for <tt>content</tt>
+ * @return the newly created message.
+ */
+ public Message createMessage(byte[] content, String contentType)
+ {
+ return createMessage(content, contentType, DEFAULT_MIME_ENCODING, null);
+ }
/**
* Create a Message instance for sending a simple text messages with
@@ -155,7 +184,7 @@ public class OperationSetBasicInstantMessagingJabberImpl
*/
public Message createMessage(String messageText)
{
- return new MessageJabberImpl(messageText, DEFAULT_MIME_TYPE
+ return createMessage(messageText.getBytes(), DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
}
@@ -187,7 +216,8 @@ public class OperationSetBasicInstantMessagingJabberImpl
*/
public boolean isContentTypeSupported(String contentType)
{
- if(contentType.equals(DEFAULT_MIME_TYPE))
+ if(contentType.equals(DEFAULT_MIME_TYPE)
+ || contentType.equals(HTML_MIME_TYPE))
return true;
else
return false;
@@ -218,23 +248,38 @@ public class OperationSetBasicInstantMessagingJabberImpl
org.jivesoftware.smack.MessageListener msgListener =
new org.jivesoftware.smack.MessageListener() {
- public void processMessage(Chat arg0, org.jivesoftware.smack.packet.Message arg1) {
- }
+ public void processMessage(
+ Chat arg0,
+ org.jivesoftware.smack.packet.Message arg1) {}
};
Chat chat = jabberProvider.getConnection().getChatManager().createChat(
- to.getAddress(), msgListener
- );
+ to.getAddress(), msgListener);
org.jivesoftware.smack.packet.Message msg =
- new org.jivesoftware.smack.packet.Message();
+ new org.jivesoftware.smack.packet.Message();
- msg.setBody(message.getContent());
- msg.addExtension(new Version());
+ String content = message.getContent();
+
+ if(message.getContentType().equals(HTML_MIME_TYPE))
+ {
+ msg.setBody(html2Txt.extractText(content));
+
+ // Add the XHTML text to the message
+ XHTMLManager.addBody(msg,
+ OPEN_BODY_TAG + content + CLOSE_BODY_TAG);
+ }
+ else
+ {
+ // this is plain text so keep it as it is.
+ msg.setBody(content);
+ }
+ msg.addExtension(new Version());
+
MessageEventManager.
addNotificationsRequests(msg, true, false, false, true);
-
+
chat.sendMessage(msg);
MessageDeliveredEvent msgDeliveredEvt
@@ -374,6 +419,28 @@ public class OperationSetBasicInstantMessagingJabberImpl
}
Message newMessage = createMessage(msg.getBody());
+
+ //check if the message is available in xhtml
+ PacketExtension ext = msg.getExtension("http://jabber.org/protocol/xhtml-im");
+
+ if(ext != null)
+ {
+ XHTMLExtension xhtmlExt
+ = (XHTMLExtension)ext;
+
+ //parse all bodies
+ Iterator bodies = xhtmlExt.getBodies();
+ StringBuffer messageBuff = new StringBuffer();
+ while (bodies.hasNext())
+ {
+ String body = (String)bodies.next();
+ messageBuff.append(body);
+ }
+
+ if(messageBuff.length() > 0)
+ newMessage = createMessage(messageBuff.toString().getBytes(),
+ HTML_MIME_TYPE);
+ }
Contact sourceContact =
opSetPersPresence.findContactByID(fromUserID);
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java
index 3c15843..ab986fd 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java
@@ -266,10 +266,12 @@ public class OperationSetTypingNotificationsJabberImpl
implements MessageEventNotificationListener
{
public void deliveredNotification(String from, String packetID)
- {}
+ {
+ }
public void displayedNotification(String from, String packetID)
- {}
+ {
+ }
public void composingNotification(String from, String packetID)
{
@@ -287,7 +289,8 @@ public class OperationSetTypingNotificationsJabberImpl
}
public void offlineNotification(String from, String packetID)
- {}
+ {
+ }
public void cancelledNotification(String from, String packetID)
{
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java
index 73dd56d..a1a37bd 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java
@@ -569,6 +569,8 @@ public class ProtocolProviderServiceJabberImpl
// TODO: add the feature, if any, corresponding to IM if someone
// knows
// supportedFeatures.add(_IM_);
+ //XHTML-IM
+ supportedFeatures.add("http://jabber.org/protocol/xhtml-im");
//initialize the Whiteboard operation set
OperationSetWhiteboardingJabberImpl whiteboard =
diff --git a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java
index 15d4009..9d65977 100644
--- a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java
@@ -114,7 +114,7 @@ public class OperationSetBasicInstantMessagingRssImpl
public Message createMessage(String messageText)
{
return new MessageRssImpl(messageText,
- "text/html",
+ HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING,
null);
}
@@ -400,7 +400,7 @@ public class OperationSetBasicInstantMessagingRssImpl
{
if(contentType.equals(DEFAULT_MIME_TYPE))
return true;
- else if(contentType.equals("text/html"))
+ else if(contentType.equals(HTML_MIME_TYPE))
return true;
else
return false;
diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java
index 5479e9d..ae5a924 100644
--- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java
@@ -33,11 +33,6 @@ public class OperationSetBasicInstantMessagingSipImpl
Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class);
/**
- * HTML content type
- */
- private static final String CONTENT_TYPE_HTML = "text/html";
-
- /**
* A list of listeners registered for message events.
*/
private Vector messageListeners = new Vector();
@@ -228,8 +223,8 @@ public class OperationSetBasicInstantMessagingSipImpl
*/
public boolean isContentTypeSupported(String contentType)
{
- if(contentType.equals(DEFAULT_MIME_TYPE) ||
- contentType.equals(CONTENT_TYPE_HTML))
+ if(contentType.equals(DEFAULT_MIME_TYPE)
+ || contentType.equals(HTML_MIME_TYPE))
return true;
else
return false;
diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java
index 9e54276..dc48fc7 100644
--- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java
@@ -34,11 +34,6 @@ public class OperationSetBasicInstantMessagingYahooImpl
Logger.getLogger(OperationSetBasicInstantMessagingYahooImpl.class);
/**
- * HTML content type
- */
- private static final String CONTENT_TYPE_HTML = "text/html";
-
- /**
* Yahoo has limit of message length. If exceeded
* message is not delivered and no notification is received for that.
*/
@@ -148,7 +143,7 @@ public class OperationSetBasicInstantMessagingYahooImpl
public boolean isContentTypeSupported(String contentType)
{
if(contentType.equals(DEFAULT_MIME_TYPE) ||
- contentType.equals(CONTENT_TYPE_HTML))
+ contentType.equals(HTML_MIME_TYPE))
return true;
else
return false;
@@ -451,7 +446,7 @@ public class OperationSetBasicInstantMessagingYahooImpl
Message newMailMessage = new MessageYahooImpl(
newMail,
- CONTENT_TYPE_HTML,
+ HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING,
null);
@@ -520,7 +515,7 @@ public class OperationSetBasicInstantMessagingYahooImpl
//to set all messages html - doesn't affect the appearance of the gui
Message newMessage = createMessage(
formattedMessage.getBytes(),
- CONTENT_TYPE_HTML,
+ HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING,
null);