@@ -150,8 +150,9 @@ window.J2S = J2S = (function() {
150150 */
151151 _appletCssClass : "" ,
152152 _appletCssText : "" ,
153- _fileCache : null , // enabled by J2S.setFileCaching(applet,
154- // true/false)
153+ _fileCache : { } , // a simple object used only in J2S._loadFileData and J2S.loadFileAsynchronously
154+ // via J2S._checkCache and only for non-js files and only if Info.cacheFiles == true (which it is not in SwingJS)
155+ _javaFileCache : null , // a Hashtable, for JSUtil and /TEMP/
155156 _jarFile : null , // can be set in URL using _JAR=
156157 _j2sPath : null , // can be set in URL using _J2S=
157158 _use : null , // can be set in URL using _USE=
@@ -300,6 +301,8 @@ window.J2S = J2S = (function() {
300301 }
301302
302303 var fixProtocol = function ( url ) {
304+ if ( url . indexOf ( "file://" ) >= 0 )
305+ url = "http" + url . substring ( 4 ) ;
303306 // force https if page is https
304307 if ( J2S . _httpProto == "https://" && url . indexOf ( "http://" ) == 0 )
305308 url = "https" + url . substring ( 4 ) ;
@@ -710,9 +713,30 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
710713 }
711714 return fileName ;
712715 }
716+
717+ J2S . fixCachePath = function ( uri ) {
718+ if ( uri . startsWith ( "./" ) )
719+ uri = "/" + uri ;
720+ var n = ( uri . startsWith ( "https:/" ) || uri . startsWith ( "file://" ) ? 7
721+ : uri . startsWith ( "http:/" ) || uri . startsWith ( "file:/" ) ? 6
722+ : 0 ) ;
723+ if ( n > 0 )
724+ uri = uri . substring ( n ) ;
725+ uri = uri . replace ( "//" , "/" ) ;
726+ var pt ;
727+ while ( ( pt = uri . indexOf ( "/././" ) ) >= 0 ) {
728+ // https://././xxx --> /./xxx
729+ uri = uri . substring ( 0 , pt ) + uri . substring ( pt + 2 ) ;
730+ }
731+ if ( uri . startsWith ( "/" ) )
732+ uri = uri . substring ( 1 ) ;
733+ if ( uri . startsWith ( "./" ) )
734+ uri = uri . substring ( 2 ) ;
735+ return uri ;
736+ }
713737
714738 J2S . _checkCache = function ( applet , fileName , fSuccess ) {
715- if ( applet . _cacheFiles && J2S . _fileCache && ! fileName . endsWith ( ".js" ) ) {
739+ if ( applet . _cacheFiles && ! fileName . endsWith ( ".js" ) ) {
716740 var data = J2S . _fileCache [ fileName ] ;
717741 if ( data ) {
718742 System . out . println ( "using " + ( data . length )
@@ -730,8 +754,9 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
730754
731755 J2S . getSetJavaFileCache = function ( map ) {
732756 // called by swingjs.JSUtil
733- return ( map == null ? J2S . _javaFileCache
734- : ( J2S . _javaFileCache = map ) ) ;
757+ if ( map == null && ! J2S . _javaFileCache )
758+ J2S . _javaFileCache = Clazz . new_ ( "java.util.Hashtable" ) ;
759+ return ( map == null ? J2S . _javaFileCache : ( J2S . _javaFileCache = map ) ) ;
735760 }
736761
737762 J2S . getCachedJavaFile = function ( key ) {
@@ -845,10 +870,15 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
845870 var isBinary = info . isBinary ;
846871 // swingjs.api.J2SInterface
847872 // use host-server PHP relay if not from this host
848- if ( fileName . indexOf ( "https://./" ) == 0 )
873+
874+ if ( fileName . indexOf ( "/" ) == 0 )
875+ fileName = "." + fileName ;
876+ else if ( fileName . indexOf ( "https://./" ) == 0 )
849877 fileName = fileName . substring ( 10 ) ;
850878 else if ( fileName . indexOf ( "http://./" ) == 0 )
851879 fileName = fileName . substring ( 9 ) ;
880+ else if ( fileName . indexOf ( "file:" ) >= 0 )
881+ fileName = "./" + fileName . substring ( 5 ) ;
852882 isBinary = ( isBinary || J2S . isBinaryUrl ( fileName ) ) ;
853883 var isPDB = ( fileName . indexOf ( "pdb.gz" ) >= 0 && fileName
854884 . indexOf ( "//www.rcsb.org/pdb/files/" ) >= 0 ) ;
@@ -970,9 +1000,7 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
9701000 var fileName0 = fileName ;
9711001 fileName = J2S . _checkFileName ( applet , fileName ) ;
9721002 var fSuccess = function ( data ) {
973- J2S
974- . _setData ( fileLoadThread , fileName , fileName0 , data ,
975- appData )
1003+ J2S . _setData ( fileLoadThread , fileName , fileName0 , data , appData )
9761004 } ;
9771005 fSuccess = J2S . _checkCache ( applet , fileName , fSuccess ) ;
9781006 if ( fileName . indexOf ( "|" ) >= 0 )
@@ -1180,6 +1208,10 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
11801208 // FileSave interface? return true if successful
11811209
11821210 J2S . saveFile = J2S . _saveFile = function ( filename , data , mimetype , encoding ) {
1211+ var isString = ( typeof data == "string" ) ;
1212+ if ( filename . indexOf ( J2S . getGlobal ( "j2s.tmpdir" ) ) == 0 ) {
1213+ return J2S . getSetJavaFileCache ( ) . put$O$O ( J2S . fixCachePath ( filename ) , ( isString ? data . getBytes$S ( "UTF-8" ) : data ) ) ;
1214+ }
11831215 if ( J2S . _localFileSaveFunction
11841216 && J2S . _localFileSaveFunction ( filename , data ) )
11851217 return "OK" ;
@@ -1193,7 +1225,6 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
11931225 | filename
11941226 . indexOf ( ".jpeg" ) >= 0 ? "image/jpg"
11951227 : "" ) ) ;
1196- var isString = ( typeof data == "string" ) ;
11971228 data = Clazz . loadClass ( "javajs.util.Base64" ) . getBase64$BA (
11981229 isString ? data . getBytes$S ( "UTF-8" ) : data ) . toString ( ) ;
11991230 encoding || ( encoding = "base64" ) ;
@@ -1406,7 +1437,6 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
14061437 J2S . View . __init ( obj ) ;
14071438 obj . _currentView = null ;
14081439 }
1409- ! J2S . _fileCache && obj . _cacheFiles && ( J2S . _fileCache = { } ) ;
14101440 if ( ! obj . _console )
14111441 obj . _console = obj . _id + "_infodiv" ;
14121442 if ( obj . _console == "none" || obj . _console == "NONE" )
@@ -2628,6 +2658,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
26282658 console : this . _console ,
26292659 monitorZIndex : J2S . getZ ( this , "monitorZIndex" )
26302660 } ) ;
2661+ J2S . setGlobal ( "j2s.tmpdir" , "/TEMP/" ) ;
26312662 var isFirst = ( __execStack . length == 0 ) ;
26322663 if ( isFirst )
26332664 J2S . _addExec ( [ this , __loadClazz , null , "loadClazz" ] ) ;
@@ -2983,7 +3014,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
29833014
29843015 var $tag = $ ( tag ) ;
29853016 tag = $tag [ 0 ] ;
2986- if ( tag . _isDragger )
3017+ if ( ! tag || tag . _isDragger )
29873018 return ;
29883019
29893020 var target , fDown , fDrag , fUp ;
0 commit comments