日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

永中office插件适配详解

發布時間:2023/12/20 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 永中office插件适配详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近項目中需要將weboffice改成永中office,然后花了幾天功夫做好了適配工作,下面來講講如何進行適配。
weboffice應用面比較窄,Windows 下 IE適用,Linux不適用。
yozooffice有Windows版也有Linux版本,能兼容兩個操作系統,使用火狐瀏覽器(51-52)版本可以使用。
話不多說,開始適配。
首先準備環境:
1.安裝永中office

2.安裝火狐瀏覽器

版本為51,安裝完了之后設置不自動更新


3.閱讀文檔(永中接口文檔)

初始化會判斷操作系統

主要應用的是打開遠程文檔,保存遠程文檔方法,方法都封裝好了,通過APPLET標簽,調用外部應用去實現。

codebase的值也有說明,可以訪問靜態資源,也可以是網絡資源,這的值可以是一個請求,去服務器下載資源。

服務端:

讀取網絡資源返回一個FileRenderer對象,初始化之后會返回一個office對象。
其中調用的方法都是yozoapplet.jar中的方法。

實際應用中基本上都是調用兩個方法保存遠程和打開遠程。

4.保存遠程方法

兩個參數,url和filename,調用saveURL方法。
public boolean saveURL(String URL, String fileName) {
try {
int type = false;
System.out.println(“fileName==” + fileName);
fileName = fileName.toLowerCase();
byte type;
if (fileName.endsWith(“eio”)) {
type = 0;
} else if (!fileName.endsWith(“doc”) && !fileName.endsWith(“xls”) && !fileName.endsWith(“ppt”)) {
if (fileName.endsWith(“pdf”)) {
type = 2;
} else if (fileName.endsWith(“uof”)) {
type = 3;
} else if (fileName.endsWith(“rtf”)) {
type = 4;
} else if (fileName.endsWith(“txt”)) {
type = 5;
} else if (!fileName.endsWith(“docx”) && !fileName.endsWith(“xlsx”) && !fileName.endsWith(“pptx”)) {
if (!fileName.endsWith(“uot”) && !fileName.endsWith(“uos”) && !fileName.endsWith(“uop”)) {
if (fileName.endsWith(“ofd”)) {
type = 8;
} else {
type = 7;
}
} else {
type = 7;
}
} else {
type = 6;
}
} else {
type = 1;
}
return this.doSaveURL(URL, type) != null;
} catch (Exception var4) {
var4.printStackTrace();
return false;
}
}
private String doSaveURL(String serverURL, int type) {
try {
URL url = null;
serverURL = serverURL.replace(" “, “%20”);
if (serverURL.toLowerCase().startsWith(“http”)) {
url = new URL(serverURL);
} else {
url = new URL(this.getCodeBase(), serverURL);
}
Object connection;
if (this.connectionType == 0) {
connection = (HttpURLConnection)url.openConnection();
} else {
connection = (HttpsURLConnection)url.openConnection();
}
((HttpURLConnection)connection).setDoInput(true);
((HttpURLConnection)connection).setDoOutput(true);
((HttpURLConnection)connection).setRequestMethod(“POST”);
((HttpURLConnection)connection).setUseCaches(false);
((HttpURLConnection)connection).setRequestProperty(“Connection”, “Keep-Alive”);
((HttpURLConnection)connection).setRequestProperty(“Accept”, “/”);
((HttpURLConnection)connection).setRequestProperty(“Content-Type”, “multipart/form-data”);
DataOutputStream dos = new DataOutputStream(((HttpURLConnection)connection).getOutputStream());
Workbook book = this.app.getWorkbooks().getActiveWorkbook();
byte[] content = this.app.getWorkbooks().getWorkbookAsByteArray(book, type);
int len = 0;
if (content != null) {
len = content.length;
}
dos.write(content, 0, len);
dos.flush();
dos.close();
InputStream inStream = ((HttpURLConnection)connection).getInputStream();
int result = inStream.read();
System.out.println(“result====” + result);
inStream.close();
((HttpURLConnection)connection).disconnect();
book.setSaved(true);
return result == 0 ? null : “”;
} catch (Exception var11) {
var11.printStackTrace();
System.out.println(“保存失敗!”);
return null;
}
}
jar包中的方法,模擬客戶端發送serverlet請求,包含文件流。
服務端就按照正常serverlet請求接收

獲取文件流,獲取參數。
5.打開遠程文檔

發送請求,去服務器上獲取文件,flg=123&sadf=12屬于參數,寫到一起,會當成一個String傳到后臺
public boolean openDocumentRemote(final String URL, final boolean readOnly) {
try {
(new Thread(this.threadGroup, new Runnable() {
public void run() {
Workbook workbook = YOZODTApplet.this.app.getWorkbooks().openWorkbook(URL);
if (workbook != null) {
Document doc = workbook.getDocuments().getActiveDocument();
if (readOnly) {
if (!doc.isProtected()) {
doc.protect(new TextRange[0], “6TFCKaTeX parse error: Expected 'EOF', got '}' at position 42: … }? …RGB”);
}
}
}
})).start();
return true;
} catch (Exception var4) {
var4.printStackTrace();
System.out.println(“異?!?;
return false;
}
}
服務端獲取
也是返回一個FileRenderer對象
public static Map<String, String> ConvertToMap(String parms) {
Map<String, String> formValue = new HashMap<String, String>();
if(!StringUtils.isEmpty(parms)){
String[] dataTemp = parms.split(”&");
for(String parmTemp : dataTemp){
String[] StrParmTemp = parmTemp.split("=");
if(StrParmTemp.length > 0){
formValue.put(StrParmTemp[0], StrParmTemp[1]);
}
}
}
return formValue;
}

可能沒個系統差異,會導致適配的問題不同,有什么疑問,可以在下方留言一起討論,交流。

總結

以上是生活随笔為你收集整理的永中office插件适配详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。