lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2008年01月2日

为 OpenFire和Spark增加QQTransport–Spark篇

Filed under: Java — 标签:, , — lizongbo @ 13:15

假期温习了一下openfire和以前写的QQTransport,

又调用lumaQQ写了点代码,在spark和openfire中实现支持qq的gateway,经过测试可用。

首先,下载了OpenFire和Spark的源代码:

http://www.igniterealtime.org/downloadServlet?filename=openfire/openfire_src_3_4_3.zip

svn方式下载:
Openfire:
svn co http://svn.igniterealtime.org/svn/repos/openfire/trunk openfire
Spark:
svn co http://svn.igniterealtime.org/svn/repos/spark/trunk spark
Smack:
svn co http://svn.igniterealtime.org/svn/repos/smack/trunk smack
Asterisk-IM:
svn co http://svn.igniterealtime.org/svn/repos/asterisk-im/trunk asterisk-im

svn客户端:

http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe

a.Saprk中,需要修改的地方有:

1.首先找到qq在线和离线的图标:

在线: http://is.qq.com/webpresence/help/help_clip_image007.gif
离线:http://is.qq.com/webpresence/help/help_clip_image008.gif

图标来源:http://is.qq.com/webpresence/help/help.shtml

2.定义资源信息常量和相关字符串信息,
尽量不改动原有代码,因此把扩展的代码写的比较丑。

3.修改org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin.java里的

populateTransports方法。

增加:

import com.lizongbo.spark.plugin.gateways.transports.QQTransport;

else if (entityName.endsWith(“qq.”)) {
QQTransport qqTransport = new QQTransport(item.getEntityID());
TransportUtils.addTransport(item.getEntityID(), qqTransport);
}

4.QQTransport的代码:

[code]

package com.lizongbo.spark.plugin.gateways.transports;

import java.net.URL;
import org.jivesoftware.resource.Res;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.*;

public class QQTransport implements Transport {
//   public static final String QQ_TRANSPORT_ACTIVE_IMAGE =
//           “QQ_TRANSPORT_ACTIVE_IMAGE”;
//   public static final String QQ_TRANSPORT_INACTIVE_IMAGE =
//           “QQ_TRANSPORT_INACTIVE_IMAGE”;

org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin gg;
org.jivesoftware.spark.SparkManager gga;
private String serviceName;

public QQTransport(String serviceName) {
this.serviceName = serviceName;
System.out.println(this.getIcon()); ;
System.out.println(this.getInactiveIcon());

}

public String getTitle() {
return “QQ 账户凭证”;
//  return Res.getString(“title.qq.registration”);
}

public String getInstructions() {
return “请输入你的QQ号码和密码。”;
// return Res.getString(“message.enter.qq”);
}

public Icon getIcon() {
final String iconURI = “/images/qq_online.gif”;
try {
final URL imageURL = //getClass().getClassLoader().
//getSystemClassLoader().getResource(
getClass().getResource(iconURI);
return new ImageIcon(imageURL);
} catch (Exception ex) {
System.out.println(iconURI + ” not found.”);
}
return null;
//return SparkRes.getImageIcon(QQ_TRANSPORT_ACTIVE_IMAGE);
}

public Icon getInactiveIcon() {
final String iconURI = “/images/qq_offline.gif”;
try {
final URL imageURL = //Thread.class.getClassLoader().
// getSystemClassLoader()
getClass().getResource(
iconURI);
return new ImageIcon(imageURL);
} catch (Exception ex) {
System.out.println(iconURI + ” not found.”);
}
return null;
//return SparkRes.getImageIcon(QQ_TRANSPORT_INACTIVE_IMAGE);
}

public String getServiceName() {
return serviceName;
}

public String getName() {
return “QQ”;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public Boolean requiresUsername() {
return true;
}

public Boolean requiresPassword() {
return true;
}

public Boolean requiresNickname() {
return false;
}

}
[/code]

4.打包文件。

将新增文件打包到qqransport.jar,
替换修改后的GatewayPlugin.class

Powered by WordPress