@@ -53,10 +53,13 @@ var python2crazy_backend_script = 'web_exec_py2-crazy.py';
5353// crazy custom py2crazy CPython interpreter to get 2crazy mode
5454//var python2crazy_backend_script = 'exec';
5555
56+ // empty dummy just to do logging on the Apache's server
5657var js_backend_script = 'web_exec_js.py' ;
58+ var java_backend_script = 'web_exec_java.py' ;
5759
60+ // these are the REAL endpoints, accessed via jsonp. code is in ../../v4-cokapi/
5861var JS_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_js_jsonp' ; // for deployment
59- // var JS_JSONP_ENDPOINT = 'http://localhost :3000/exec_js_jsonp '; // for local testing
62+ var JAVA_JSONP_ENDPOINT = 'http://104.237.139.253 :3000/exec_java_jsonp ' ; // for deployment
6063
6164var domain = "http://pythontutor.com/" ; // for deployment
6265
@@ -135,8 +138,18 @@ function setAceMode() {
135138 var mod = 'python' ;
136139 if ( $ ( '#pythonVersionSelector' ) . val ( ) === 'js' ) {
137140 mod = 'javascript' ;
141+ } else if ( $ ( '#pythonVersionSelector' ) . val ( ) === 'java' ) {
142+ mod = 'java' ;
143+
144+ // if empty, initialize to a Java skeleton:
145+ if ( $ . trim ( pyInputGetValue ( ) ) == '' ) {
146+ pyInputSetValue ( 'public class YourClassNameHere {\n\
147+ public static void main(String[] args) {\n\
148+ \n\
149+ }\n\
150+ }' ) ;
151+ }
138152 }
139- assert ( mod === 'python' || mod === 'javascript' ) ;
140153 var s = pyInputAceEditor . getSession ( ) ;
141154 s . setMode ( "ace/mode/" + mod ) ;
142155}
@@ -1285,6 +1298,8 @@ function executePythonCode(pythonSourceCode,
12851298 frontendOptionsObj . lang = 'py3' ;
12861299 } else if ( backendScript === js_backend_script ) {
12871300 frontendOptionsObj . lang = 'js' ;
1301+ } else if ( backendScript === java_backend_script ) {
1302+ frontendOptionsObj . lang = 'java' ;
12881303 }
12891304
12901305 if ( backendScript === js_backend_script ) {
@@ -1307,7 +1322,26 @@ function executePythonCode(pythonSourceCode,
13071322 data : { user_script : pythonSourceCode } ,
13081323 success : execCallback ,
13091324 } ) ;
1325+ } else if ( backendScript === java_backend_script ) {
1326+ // hack for Java execution! should just be a dummy script for logging only
1327+ $ . get ( backendScript ,
1328+ { user_script : pythonSourceCode ,
1329+ user_uuid : supports_html5_storage ( ) ? localStorage . getItem ( 'opt_uuid' ) : undefined ,
1330+ // if we don't have any deltas, then don't bother sending deltaObj:
1331+ diffs_json : deltaObj && ( deltaObj . deltas . length > 0 ) ? JSON . stringify ( deltaObj ) : null } ,
1332+ function ( dat ) { } /* don't do anything since this is a dummy call */ , "text" ) ;
13101333
1334+ // the REAL call uses JSONP
1335+ // some JSONP action!
1336+ // http://learn.jquery.com/ajax/working-with-jsonp/
1337+ $ . ajax ( {
1338+ url : JAVA_JSONP_ENDPOINT ,
1339+ // The name of the callback parameter, as specified by the YQL service
1340+ jsonp : "callback" ,
1341+ dataType : "jsonp" ,
1342+ data : { user_script : pythonSourceCode } ,
1343+ success : execCallback ,
1344+ } ) ;
13111345 } else {
13121346 $ . get ( backendScript ,
13131347 { user_script : pythonSourceCode ,
0 commit comments