Skip to content

Commit 6f53c3f

Browse files
author
jossonsmith
committed
Refactor SimpleRPCHttpServlet into a container servlet so that developers
have no more need to extend servlet for every SimpleRPCRunnable.
1 parent aeac59f commit 6f53c3f

File tree

3 files changed

+108
-61
lines changed

3 files changed

+108
-61
lines changed

tests/net.sf.j2s.test.ajax/src/com/ognize/lz77js/servlet/LZ77JSServlet.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/net.sf.j2s.test.ajax/src/com/ognize/lz77js/ui/LZ77JS.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,37 @@ public void widgetSelected(SelectionEvent e) {
8080
MessageBox messageBox = new MessageBox(shell, SWT.RESIZE | SWT.ICON_INFORMATION);
8181
messageBox.setMessage("Source JavaScript can not be empty!");
8282
messageBox.open();
83-
return ;
8483
} else if (trimJS.length() < 832 * 4 / 3) {
8584
MessageBox messageBox = new MessageBox(shell, SWT.RESIZE | SWT.ICON_INFORMATION);
8685
messageBox.setMessage("It's unnecessary to compress raw source that is less than 1k.");
8786
messageBox.open();
88-
return ;
87+
} else {
88+
ratioLabel.setText("Start JavaScript lz77 compressing to server, please wait ...");
89+
/*
90+
* Local Java Thread mode is already the default mode for Java client
91+
*/
92+
SimpleRPCRequest.switchToLocalJavaThreadMode();
93+
/*
94+
* AJAX mode is only mode for Java2Script client.
95+
* You can uncomment the follow line to call a LZ77JS RPC of bl.ognize.com.
96+
* In JavaScript mode, you should modify LZ77JSSimpleRPCRunnable#url so there
97+
* is no cross site script for XMLHttpRequest.
98+
*/
99+
//AJAXServletRequest.switchToAJAXMode();
100+
SimpleRPCSWTRequest.swtRequest(new LZ77JSSimpleRPCRunnable() {
101+
public void ajaxIn() {
102+
jsContent = sourceText.getText();
103+
toRegExpCompress = regExpButton.getSelection();
104+
addLZ77Header = lz77HeaderButton.getSelection();
105+
}
106+
107+
public void ajaxOut() {
108+
resultText.setText(result);
109+
ratioLabel.setText("Compressed Ratio: " + result.length() + " / " + sourceText.getText().length() + " = " + (100.0 * result.length() / sourceText.getText().length()) + "%");
110+
}
111+
112+
});
89113
}
90-
ratioLabel.setText("Start JavaScript lz77 compressing to server, please wait ...");
91-
/*
92-
* Local Java Thread mode is already the default mode for Java client
93-
*/
94-
SimpleRPCRequest.switchToLocalJavaThreadMode();
95-
/*
96-
* AJAX mode is only mode for Java2Script client.
97-
* You can uncomment the follow line to call a LZ77JS RPC of bl.ognize.com.
98-
* In JavaScript mode, you should modify LZ77JSSimpleRPCRunnable#url so there
99-
* is no cross site script for XMLHttpRequest.
100-
*/
101-
//AJAXServletRequest.switchToAJAXMode();
102-
SimpleRPCSWTRequest.swtRequest(new LZ77JSSimpleRPCRunnable() {
103-
public void ajaxIn() {
104-
jsContent = sourceText.getText();
105-
toRegExpCompress = regExpButton.getSelection();
106-
addLZ77Header = lz77HeaderButton.getSelection();
107-
}
108-
109-
public void ajaxOut() {
110-
resultText.setText(result);
111-
ratioLabel.setText("Compressed Ratio: " + result.length() + " / " + sourceText.getText().length() + " = " + (100.0 * result.length() / sourceText.getText().length()) + "%");
112-
}
113-
114-
});
115114
}
116115
});
117116

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package net.sf.j2s.test.ajax;
15+
16+
import java.io.UnsupportedEncodingException;
17+
import junit.framework.TestCase;
18+
import net.sf.j2s.ajax.SimpleSerializable;
19+
20+
/**
21+
* @author zhou renjian
22+
*
23+
* 2006-12-16
24+
*/
25+
public class HTMLChineseSimpleRPCTest extends TestCase {
26+
public class StringSerialize extends SimpleSerializable {
27+
public String s = "青藏线:从青海省的格尔木开始,到拉萨约1083千米。有格尔木乘至拉萨的长途汽车,运行30~40小时,2天即到。路线如下:<br>格木尔--289--五道梁--150--雁石坪--100--唐古拉山口--89--安多--138--那曲--164--当雄--75--羊八井--78--拉萨 (其中数字的单位是千米)";
28+
}
29+
public class SSerialize extends SimpleSerializable {
30+
public String content = "千米)";
31+
}
32+
public void testString() {
33+
SSerialize ds2 = new SSerialize();
34+
ds2.deserialize("IcontentuVMeW3nTLol48z57q/NDU=");
35+
System.out.println(ds2.content);
36+
}
37+
public void xtestSimpleString() {
38+
StringSerialize ss = new StringSerialize();
39+
String serialize = ss.serialize();
40+
String expected = "Csu@E4406Z2S6JeP57q/77ya5LuO6Z2S5rW355yB55qE5qC85bCU5pyo5byA5aeL77yM5Yiw5ouJ6JCo57qmMTA4M+WNg+exs+OAguacieagvOWwlOacqOS5mOiHs+aLieiQqOeahOmVv+mAlOaxvei9pu+8jOi/kOihjDMwfjQw5bCP5pe277yMMuWkqeWNs+WIsOOAgui3r+e6v+WmguS4i++8mjxicj7moLzmnKjlsJQtLTI4OS0t5LqU6YGT5qKBLS0xNTAtLembgeefs+Wdqi0tMTAwLS3llJDlj6Tmi4nlsbHlj6MtLTg5LS3lronlpJotLTEzOC0t6YKj5puyLS0xNjQtLeW9k+mbhC0tNzUtLee+iuWFq+S6lS0tNzgtLeaLieiQqCDvvIjlhbbkuK3mlbDlrZfnmoTljZXkvY3mmK/ljYPnsbPvvIk=";
41+
42+
System.out.println();
43+
// System.out.println("233,157,146,232,151,143,231,186,191,239,188,154,228,187,142,233,157,146,230,181,183,231,156,129,231,154,132,230,160,188,229,176,148,230,156,168,229,188,128,229,167,139,239,188,140,229,136,176,230,139,137,232,144,168,231,186,166,49,48,56,51,229,141,131,231,177,179,227,128,130,230,156,137,230,160,188,229,176,148,230,156,168,228,185,152,232,135,179,230,139,137,232,144,168,231,154,132,233,149,191,233,128,148,230,177,189,232,189,166,239,188,140,232,191,144,232,161,140,51,48,126,52,48,229,176,143,230,151,182,239,188,140,50,229,164,169,229,141,179,229,136,176,227,128,130,232,183,175,231,186,191,229,166,130,228,184,139,239,188,154,60,98,114,62,230,160,188,230,156,168,229,176,148,45,45,50,56,57,45,45,228,186,148,233,129,147,230,162,129,45,45,49,53,48,45,45,233,155,129,231,159,179,229,157,170,45,45,49,48,48,45,45,229,148,144,229,143,164,230,139,137,229,177,177,229,143,163,45,45,56,57,45,45,229,174,137,229,164,154,45,45,49,51,56,45,45,233,130,163,230,155,178,45,45,49,54,52,45,45,229,189,147,233,155,132,45,45,55,53,45,45,231,190,138,229,133,171,228,186,149,45,45,55,56,45,45,230,139,137,232,144,168,32,239,188,136,229,133,182,228,184,173,230,149,176,229,173,151,231,154,132,229,141,149,228,189,141,230,152,175,229,141,131,231,177,179,239,188,137,");
44+
// try {
45+
// byte[] bytes = ss.s.getBytes("UTF-8");
46+
// System.out.println(bytes[60]);
47+
// System.out.println(bytes[61]);
48+
// for (int i = 0; i < bytes.length; i++) {
49+
// System.out.print((bytes[i] < 0 ? 256 + bytes[i] : bytes[i]) + ",");
50+
// }
51+
// System.out.println();
52+
// } catch (UnsupportedEncodingException e) {
53+
// // TODO Auto-generated catch block
54+
// e.printStackTrace();
55+
// }
56+
System.out.println(expected);
57+
System.out.println(serialize);
58+
System.out.println(expected.length());
59+
System.out.println(serialize.length());
60+
//int i =
61+
assertEquals(expected, serialize);
62+
63+
StringSerialize ds = new StringSerialize();
64+
ds.deserialize(serialize);
65+
System.out.println(ds.s);
66+
67+
assertEquals(ds.s, ss.s);
68+
69+
70+
StringSerialize ds2 = new StringSerialize();
71+
ds2.deserialize(expected);
72+
System.out.println(ds2.s);
73+
System.out.println(ss.s);
74+
75+
System.out.println(ds2.s.length());
76+
System.out.println(ss.s.length());
77+
78+
assertEquals(ds2.s, ss.s);
79+
80+
}
81+
82+
}

0 commit comments

Comments
 (0)