Hi,

I have a problem with saving and loading PNGJ state files to and from a web 
server. I load a pdb from the web server (http://host/path?getParams=pdb) and 
save it via the ?POST?_PNGJBIN_ request feature. For the zip file collection 
the pdb file name gets translated to "http___host_path_getParams_pdb". The I 
load the PNGJ from the server (http://host/path?getParams=pngj1). The pdb file 
is loaded from the zip inside the pngj as 
"http://host/path?getParams=pngj1|http___host_path_getParams_pdb". When I again 
save it (http://host/path?getParams=pngj2) the pdb file name gets now 
translated to 
"http___host_path_getParams_pngj1|http___host_path_getParams_pdb". Upon loading 
pngj2 Jmol chokes on the new path, presumably because of the "|", at least when 
I added the "|" to the characters that get replace when creating the new file 
name (see below), loading of pngj2 works. Also of note is that the pdb file 
name gets longer every time the pngj is loaded/saved. The root problem is that 
the special case of getParams ("?" character) plus loading from within a zip 
file ("|" character) is not handled. I have a solution below.

I haven't experienced it yet but how I understand the code, files with the same 
name are presumed identical and only the first is added to the zip file. I 
suggest to append the file index to the file name to make it unique and test 
for identical files with a hash function.


jmol.viewer.FileManager.java::createZipSet()

String newName = name;
if (newName.indexOf("?") > 0) // I guess this is to catch urls which do not 
have something like a file name but get params
  newName = TextFormat.replaceAllCharacters(newName, "/:?\"'=&", "_");
  // newName = TextFormat.replaceAllCharacters(newName, "|/:?\"'=&", "_"); // 
quick fix by adding "|", see above, no solution
else
  newName = stripPath(name);

where stripPath is:

private static String stripPath(String name) {
  int pt = Math.max(name.lastIndexOf("|"), name.lastIndexOf("/"));
  return name.substring(pt + 1);
}



// suggested replacement to ensure filename uniqueness and fix growing filenames
String newName = name;
if (newName.indexOf("?") > 0 && !(newName.indexOf("|") > 0))
  newName = TextFormat.replaceAllCharacters(newName, "/:?\"'=&", "_");
else
  newName = stripPath(name);

newName = TextFormat.replaceAllCharacters(newName, "#", "_");
if (newName.indexOf(".") >= 0)
  newName = newName.substring(0, newName.lastIndexOf(".")) + "#" + iFile + 
newName.substring(newName.lastIndexOf("."));
else
  newName = newName + "#" + iFile


with that we have
- unique file names
- non growing file names
- good preserving of original file names or info where it came from


I also started testing for unique files based on the CRC value, but sort of 
forgot that it had to be decide before replacing the new file names in the 
state... tomorrow. I'll wait for comments, then create a patch.


Best
Alexander

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to