java本地化jacob使用

来源:互联网 发布:关键字排名优化工具 编辑:程序博客网 时间:2024/05/22 07:09

需要jacob.jar、jacob.dll放置在java-jre-bin中

 

package com.bjrl.callcenter;import java.io.*;import java.sql.*;import java.text.*;import java.util.*;import java.util.Date;import javax.servlet.*;import com.bjrl.util.*;import com.jacob.activeX.ActiveXComponent;import com.jacob.com.*;public class CallCONNListener implements ServletContextListener {/** * @Fields serialVersionUID : */private static final long serialVersionUID = 1L;public static Dispatch dispatch = null;public static ActiveXComponent activeXComponent = null;public static EventCall eventCall = null;public static DispatchEvents event = null;public static String callCenterIP = null;public static String callCenterPort = null;public static Map<String, String> codeMap = new HashMap<String, String>();public void contextDestroyed(ServletContextEvent servletContextEvent) {if (ConstString.callControl) {Dispatch.call(dispatch, ConstString.ATDISCONN);}}public void contextInitialized(ServletContextEvent servletContextEvent) {File file = new File(ConstString.ocxfilePath);String str = System.getProperty("java.home") + "\\bin\\jacob.dll";File f = new File(str);File calldll = new File("C:\\WINDOWS\\system32\\CallClient.ocx");if (!calldll.exists()) {InputStream callocx = this.getClass().getClassLoader().getResourceAsStream("CallClient.ocx");int tempocx;try {OutputStream ocx = new FileOutputStream(calldll);while ((tempocx = callocx.read()) != -1) {ocx.write(tempocx);}callocx.close();ocx.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}try {Runtime.getRuntime().exec("regsvr32 /s CallClient.ocx");Thread.sleep(5000);} catch (Exception e) {// TODO Auto-generated catch blockConstString.callControl = false;}if (file.exists() && f.exists()) {ConstString.callControl = true;} else {InputStream fi = this.getClass().getClassLoader().getResourceAsStream("jacob.dll");int temp;try {OutputStream o = new FileOutputStream(file);OutputStream oa = new FileOutputStream(f);while ((temp = fi.read()) != -1) {o.write(temp);oa.write(temp);}o.close();oa.close();ConstString.callControl = true;} catch (Exception e) {ConstString.callControl = false;System.out.println("warn: ocx is not in project,please check......");}}if (ConstString.callControl) {InputStream i = this.getClass().getClassLoader().getResourceAsStream("config.properties");Properties properties = new Properties();try {properties.load(i);} catch (IOException e) {ConstString.callControl = false;}callCenterIP = properties.getProperty("CallIP");callCenterPort = properties.getProperty("CallCenterPort");activeXComponent = new ActiveXComponent(ConstString.ATOCXID);dispatch = activeXComponent.getObject();eventCall = new EventCall();event = new DispatchEvents(dispatch, eventCall);Dispatch.call(dispatch, ConstString.ATCONN, new Variant(callCenterIP), new Variant(callCenterPort));Connection conn = DBTools.getConnection();try {Statement stat = conn.createStatement();ResultSet rs = stat.executeQuery(ConstString.sqlQuery);while (rs.next()) {String num = rs.getString(1);String memo = rs.getString(2);codeMap.put(num, memo);}stat.close();rs.close();conn.close();} catch (SQLException e1) {e1.printStackTrace();}Timer timer = new Timer();//SimpleDateFormat sid = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//Date date = null;//try {//date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")//.parse(sid.format(new Date().getTime()//+ ConstString.dateFirtInit));//} catch (ParseException e) {//e.printStackTrace();//}TimerTask timerTask = new TimerTask() {public void run() {new CallSocketServer().run();// Dispatch.call(dispatch, "ATConnect", new Variant(// callCenterIP), new Variant(callCenterPort));System.out.println("reconnect..............");}};timer.schedule(timerTask,ConstString.dateInter);}}}

原创粉丝点击