Skip to content

Commit 773fd2a

Browse files
author
jossonsmith
committed
Add Java2Script' Simple RPC tests and an example of SWT's LZ77JS compressor
1 parent 1bd1081 commit 773fd2a

File tree

17 files changed

+1411
-0
lines changed

17 files changed

+1411
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6+
<classpathentry kind="var" path="AJAX_SWT"/>
7+
<classpathentry sourcepath="/AJAX_RPC_SRC" kind="var" path="AJAX_RPC"/>
8+
<classpathentry kind="var" path="JAVAX_SERVLET"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

tests/net.sf.j2s.test.ajax/.j2s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Java2Script Configuration
2+
#Fri Oct 13 02:11:44 CST 2006
3+
j2s.resources.list=../../plugins/net.sf.j2s.lib_1.0.0/j2slib/java.runtime.j2x,../../plugins/net.sf.j2s.lib_1.0.0/j2slib/junit.j2x,bin/net/sf/j2s/ajax/test/LoadingRSS.js,bin/net/sf/j2s/ajax/test/TestSerialize.js,bin/net/sf/j2s/ajax/test/SerializeTest.js,bin/net/sf/j2s/ajax/test/DeserializeTest.js,bin/net/sf/j2s/ajax/test/ArraySerializeTest.js,bin/net/sf/j2s/ajax/test/ArrayDeserializeTest.js,bin/net/sf/j2s/ajax/test/BigTest.js,bin/net/sf/j2s/test/ajax/ArrayDeserializeTest.js,bin/net/sf/j2s/test/ajax/ArraySerializeTest.js,bin/net/sf/j2s/test/ajax/BigTest.js,bin/net/sf/j2s/test/ajax/DeserializeTest.js,bin/net/sf/j2s/test/ajax/LoadingRSS.js,bin/net/sf/j2s/test/ajax/SerializeTest.js,bin/net/sf/j2s/test/ajax/TestSerialize.js,bin/net/sf/j2s/test/lz77js/LZ77ServletRunnable.js,bin/net/sf/j2s/test/lz77js/client/LZ77JS.js,bin/net/sf/j2s/test/lz77js/server/LZ77JSServlet.js,bin/com/ognize/lz77js/LZ77JSSimpleRPCRunnable.js,bin/com/ognize/lz77js/servlet/LZ77JSServlet.js,bin/com/ognize/lz77js/ui/LZ77JS.js
4+
j2s.output.path=bin
5+
j2s.abandoned.resources.list=
6+
j2s.compiler.status=enable
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>net.sf.j2s.test.ajax</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>net.sf.j2s.core.java2scriptbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.ManifestBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.pde.SchemaBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.jdt.core.javanature</nature>
31+
<nature>org.eclipse.pde.PluginNature</nature>
32+
</natures>
33+
</projectDescription>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Ajax
4+
Bundle-SymbolicName: net.sf.j2s.test.ajax
5+
Bundle-Version: 1.0.0
6+
Bundle-Localization: plugin
7+
Require-Bundle: org.eclipse.swt,
8+
org.junit

tests/net.sf.j2s.test.ajax/all.xml

Lines changed: 193 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin.includes = META-INF/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4+
<head>
5+
<title>net.sf.j2s.ajax.test.LoadingRSS</title>
6+
<link rel="stylesheet" href="j2slib/console.css"/>
7+
<script type="text/javascript" src="j2slib/j2s-core-more.jz"></script>
8+
<script type="text/javascript" src="j2slib/j2s-ajax-core.jz"></script>
9+
<script type="text/javascript" src="bin/net/sf/j2s/ajax/test/LoadingRSS.js"></script>
10+
</head>
11+
<body>
12+
<div id="_console_" class="consolewindow"></div>
13+
<script type="text/javascript">
14+
net.sf.j2s.ajax.test.LoadingRSS.main([]);
15+
</script>
16+
</body>
17+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 com.ognize.lz77js;
15+
16+
import net.sf.j2s.ajax.SimpleRPCRunnable;
17+
18+
/**
19+
* @author josson smith
20+
*
21+
* 2006-10-10
22+
*/
23+
public class LZ77JSSimpleRPCRunnable extends SimpleRPCRunnable {
24+
public String jsContent;
25+
public boolean toRegExpCompress;
26+
public boolean addLZ77Header;
27+
public String result;
28+
29+
public String url() {
30+
/*
31+
* In JavaScript, this url must NOT be cross site URL!
32+
*/
33+
return "http://bl.ognize.com/lz77js/j2s-lz77js";
34+
}
35+
36+
public void ajaxRun() {
37+
/*
38+
if (toRegExpCompress) {
39+
jsContent = RegExCompress.regexCompress(jsContent);
40+
}
41+
J2SGZipUtil.PACK_WITH_DECODER = addLZ77Header;
42+
StringBuffer buf = new StringBuffer();
43+
J2SGZipEncode.zipping(jsContent, buf, toRegExpCompress);
44+
result = buf.toString();
45+
jsContent = null;
46+
*/
47+
result = "/* local lz77js call */\r\n" + jsContent;
48+
jsContent = null;
49+
}
50+
51+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 com.ognize.lz77js.servlet;
15+
16+
import javax.servlet.http.HttpServletRequest;
17+
import javax.servlet.http.HttpServletResponse;
18+
import net.sf.j2s.ajax.SimpleRPCHttpServlet;
19+
import com.ognize.lz77js.LZ77JSSimpleRPCRunnable;
20+
21+
/**
22+
* @author josson smith
23+
*
24+
* 2006-9-3
25+
*/
26+
public class LZ77JSServlet extends SimpleRPCHttpServlet {
27+
28+
private static final long serialVersionUID = 183900982866458122L;
29+
30+
public void initSimpleRPC(final HttpServletRequest req, HttpServletResponse resp) {
31+
this.runnable = new LZ77JSSimpleRPCRunnable();
32+
}
33+
34+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package com.ognize.lz77js.ui;
2+
3+
import net.sf.j2s.ajax.AJAXServletRequest;
4+
import net.sf.j2s.ajax.AJAXServletSWTRequest;
5+
import org.eclipse.swt.SWT;
6+
import org.eclipse.swt.custom.SashForm;
7+
import org.eclipse.swt.events.SelectionAdapter;
8+
import org.eclipse.swt.events.SelectionEvent;
9+
import org.eclipse.swt.layout.FillLayout;
10+
import org.eclipse.swt.layout.GridData;
11+
import org.eclipse.swt.layout.GridLayout;
12+
import org.eclipse.swt.widgets.Button;
13+
import org.eclipse.swt.widgets.Composite;
14+
import org.eclipse.swt.widgets.Display;
15+
import org.eclipse.swt.widgets.Label;
16+
import org.eclipse.swt.widgets.MessageBox;
17+
import org.eclipse.swt.widgets.Shell;
18+
import org.eclipse.swt.widgets.Text;
19+
import com.ognize.lz77js.LZ77JSSimpleRPCRunnable;
20+
21+
public class LZ77JS {
22+
23+
final static String LZ77_JS_URL = "http://bl.ognize.com/lz77js/lz77js";
24+
25+
/**
26+
* @param args
27+
*/
28+
public static void main(String[] args) {
29+
final Display display = new Display();
30+
final Shell shell = new Shell(display);
31+
//shell.setMaximized(true);
32+
shell.setText("LZ77 JavaScript Compressor");
33+
shell.setLayout(new FillLayout());
34+
35+
SashForm form = new SashForm(shell, SWT.VERTICAL);
36+
form.setLayout(new FillLayout());
37+
38+
Composite outlinePanel = new Composite(form, SWT.NONE);
39+
outlinePanel.setLayout(new GridLayout());
40+
new Label(outlinePanel, SWT.NONE).setText("JavaScript Source:");
41+
final Text sourceText = new Text(outlinePanel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
42+
sourceText.setLayoutData(new GridData(GridData.FILL_BOTH));
43+
44+
Composite optionPanel = new Composite(outlinePanel, SWT.NONE);
45+
optionPanel.setLayout(new GridLayout(3, true));
46+
optionPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
47+
final Button regExpButton = new Button(optionPanel, SWT.CHECK);
48+
regExpButton.setSelection(true);
49+
regExpButton.setText("RegExp trimming before LZ77");
50+
regExpButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
51+
52+
final Button lz77HeaderButton = new Button(optionPanel, SWT.CHECK);
53+
lz77HeaderButton.setSelection(true);
54+
lz77HeaderButton.setText("Output with LZ77 decoder");
55+
lz77HeaderButton.setAlignment(SWT.CENTER);
56+
lz77HeaderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
57+
58+
Button lz77Button = new Button(optionPanel, SWT.PUSH);
59+
lz77Button.setText("LZ77 Compress");
60+
lz77Button.setAlignment(SWT.RIGHT);
61+
lz77Button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
62+
63+
final Composite contentPanel = new Composite(form, SWT.NONE);
64+
contentPanel.setLayout(new GridLayout());
65+
new Label(contentPanel, SWT.NONE).setText("LZ77 Compressed JavaScript:");
66+
final Text resultText = new Text(contentPanel, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
67+
resultText.setLayoutData(new GridData(GridData.FILL_BOTH));
68+
69+
final Label ratioLabel = new Label(contentPanel, SWT.BORDER);
70+
ratioLabel.setText("Input source JavaScript and then press \"LZ77 Compress\" button.");
71+
ratioLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
72+
73+
form.setWeights(new int[] { 68, 32 });
74+
75+
lz77Button.addSelectionListener(new SelectionAdapter () {
76+
public void widgetSelected(SelectionEvent e) {
77+
String jsContent = sourceText.getText();
78+
String trimJS = jsContent.trim();
79+
if (trimJS.length() == 0) {
80+
MessageBox messageBox = new MessageBox(shell, SWT.RESIZE | SWT.ICON_INFORMATION);
81+
messageBox.setMessage("Source JavaScript can not be empty!");
82+
messageBox.open();
83+
return ;
84+
} else if (trimJS.length() < 832 * 4 / 3) {
85+
MessageBox messageBox = new MessageBox(shell, SWT.RESIZE | SWT.ICON_INFORMATION);
86+
messageBox.setMessage("It's unnecessary to compress raw source that is less than 1k.");
87+
messageBox.open();
88+
return ;
89+
}
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+
AJAXServletRequest.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+
AJAXServletSWTRequest.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+
});
115+
}
116+
});
117+
118+
shell.open();
119+
while (!shell.isDisposed()) {
120+
if (!display.readAndDispatch())
121+
display.sleep();
122+
}
123+
display.dispose();
124+
}
125+
126+
}

0 commit comments

Comments
 (0)