Menu

[r376]: / trunk / php-java-bridge / server / test / Utf8.java  Maximize  Restore  History

Download this file

59 lines (45 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*-*- mode: Java; tab-width:8 -*-*/
package test;
import java.io.StringReader;
import javax.script.Invocable;
import javax.script.ScriptException;
import php.java.script.PhpScriptEngine;
/**
* @author jostb
*
* Call this example with -Dfile.encoding=UTF-8
*/
public class Utf8 {
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
int result = 0;
System.setProperty("php.java.bridge.default_log_level", "4");
System.setProperty("php.java.bridge.default_log_file", "");
System.setProperty("php.java.bridge.php_exec", "php-cgi");
String utf8 =
"Cześć! -- שלום -- Grüß Gott -- Dobrý deň -- Dobrý den -- こんにちは, コンニチハ";
String phpCode =
"<?php \n" +
"function toString() { \n" +
" $str=new java('java.lang.String','"+utf8+"'); \n" +
" echo $str; echo '\n'; \n" +
" return (string)$str; \n" +
"} \n" +
"java_context()->call(java_closure()); \n"+
"?>";
PhpScriptEngine engine = new PhpScriptEngine();
StringReader reader = new StringReader(phpCode);
engine.eval(reader);
Invocable i = (Invocable)engine;
String utf82 = i.getInterface(null).toString();
if(!utf82.equals(utf8)) {
System.out.println("ERROR");
System.out.println(utf82);
System.out.println(utf8);
result = 1;
} else {
System.out.println("test okay");
}
engine.release();
System.exit(result);
}
}