Package org.jmol.viewer
Class FileManager
- java.lang.Object
-
- org.jmol.viewer.FileManager
-
- All Implemented Interfaces:
javajs.api.BytePoster
public class FileManager extends Object implements javajs.api.BytePoster
-
-
Field Summary
Fields Modifier and Type Field Description private URL
appletDocumentBaseURL
private String
appletProxy
private Map<String,Object>
cache
private static String
DELPHI_BINARY_MAGIC_NUMBER
private String
fileName
private String
fullPathName
static String
JPEG_CONTINUE_STRING
(package private) JmolUtil
jzu
private String
lastFullPathName
private String
lastNameAsGiven
private String
nameAsGiven
private String
pathForAllFiles
static String
PMESH_BINARY_MAGIC_NUMBER
Map<String,Object>
pngjCache
private static String[]
scriptFilePrefixes
static String
SIMULATION_PROTOCOL
Map<String,byte[]>
spardirCache
private SpartanUtil
spartanDoc
Viewer
vwr
-
Constructor Summary
Constructors Constructor Description FileManager(Viewer vwr)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static String
addDirectory(String defaultDirectory, String name)
(package private) void
cacheClear()
int
cacheFileByNameAdd(String fileName, boolean isAdd)
Object
cacheGet(String key, boolean bytesOnly)
Map<String,Integer>
cacheList()
(package private) void
cachePut(String key, Object data)
private boolean
checkSecurity(String f)
(package private) void
clear()
(package private) Object
createAtomSeCollectionFromArrayData(javajs.util.Lst<Object> arrayData, Map<String,Object> htParams, boolean isAppend)
(package private) Object
createAtomSeCollectionFromStrings(String[] arrayModels, javajs.util.SB loadScript, Map<String,Object> htParams, boolean isAppend)
(package private) Object
createAtomSetCollectionFromDOM(Object DOMNode, Map<String,Object> htParams)
(package private) Object
createAtomSetCollectionFromFile(String name, Map<String,Object> htParams, boolean isAppend)
(package private) Object
createAtomSetCollectionFromFiles(String[] fileNames, Map<String,Object> htParams, boolean isAppend)
(package private) Object
createAtomSetCollectionFromReader(String fullPathName, String name, Object reader, Map<String,Object> htParams)
not used in Jmol project -- will close reader(package private) Object
createAtomSetCollectionFromString(String strModel, Map<String,Object> htParams, boolean isAppend)
static String
determineSurfaceFileType(BufferedReader bufferedReader)
static String
determineSurfaceTypeIs(InputStream is)
static String
fixDOSName(String fileName)
Switch \ for / only for DOS names such as C:\temp\t.xyz, not names like http://cactus.nci.nih.gov/chemical/structure/CC/C=C\CCprivate static String
fixPath(String path)
(package private) String
getAppletDocumentBase()
(package private) BufferedInputStream
getBufferedInputStream(String fullPathName)
Object
getBufferedInputStreamOrErrorMessageFromName(String name, String fullName, boolean showMsg, boolean checkOnly, byte[] outputBytes, boolean allowReader, boolean allowCached)
static BufferedReader
getBufferedReaderForResource(Viewer vwr, Object resourceClass, String classPath, String resourceName)
Object
getBufferedReaderOrErrorMessageFromName(String name, String[] fullPathNameReturn, boolean isBinary, boolean doSpecialLoad)
private byte[]
getCachedPngjBytes(String pathName)
String
getCanonicalName(String pathName)
private String[]
getClassifiedName(String name, boolean isFullLoad)
[0] and [2] may return same as [1] in the case of a local unsigned applet.(package private) String
getDefaultDirectory(String name)
String
getEmbeddedFileState(String fileName, boolean allowCached, String sptName)
static String
getEmbeddedScript(String script)
Object
getFileAsBytes(String name, javajs.util.OC out)
Map<String,Object>
getFileAsMap(String name, String type)
boolean
getFileDataAsString(String[] data, int nBytesMax, boolean doSpecialLoad, boolean allowBinary, boolean checkProtected)
String[]
getFileInfo()
String
getFileName()
String
getFilePath(String name, boolean addUrlPrefix, boolean asShortName)
static void
getFileReferences(String script, javajs.util.Lst<String> fileList)
String
getFullPathName(boolean orPrevious)
(package private) Object
getFullPathNameOrError(String filename, boolean getStream, String[] ret)
just check for a file as being readable.JmolUtil
getJzu()
static GenericFileInterface
getLocalDirectory(Viewer vwr, boolean forDialog)
static String
getLocalPathForWritingFile(Viewer vwr, String file)
static String
getManifestScriptPath(String manifest)
check a JmolManifest for a reference to a script file (.spt)String
getPathForAllFiles()
private byte[]
getPngjOrDroppedBytes(String fullName, String name)
Object
getUnzippedReaderOrStreamFromName(String name, Object bytesOrStream, boolean allowZipStream, boolean forceInputStream, boolean isTypeCheckOnly, boolean doSpecialLoad, Map<String,Object> htParams)
String[]
getZipDirectory(String fileName, boolean addManifest, boolean allowCached)
static boolean
isScriptType(String fname)
static boolean
isSurfaceType(String fname)
boolean
loadImage(Object nameOrBytes, String echoName, boolean forceSync)
Load an image(package private) static javajs.util.DataReader
newDataReader(Viewer vwr, Object data)
private JmolFilesReaderInterface
newFilesReader(String[] fullPathNames, String[] namesAsGiven, String[] fileTypes, javajs.util.DataReader[] readers, Map<String,Object> htParams, boolean isAppend)
String
postByteArray(String fileName, byte[] bytes)
void
recachePngjBytes(String fileName, byte[] bytes)
(package private) void
setAppletContext(String documentBase)
(package private) void
setAppletProxy(String appletProxy)
void
setFileInfo(String[] fileInfo)
Set fullPathName, fileName, and nameAsGivenprivate void
setLoadState(Map<String,Object> htParams)
static void
setLocalPath(Viewer vwr, String path, boolean forDialog)
called by getImageFileNameFromDialog called by getOpenFileNameFromDialog called by getSaveFileNameFromDialog called by classifyName for any full file load called from the CD command currentLocalPath is set in all cases and is used specifically for dialogs as a first try defaultDirectoryLocal is set only when not from a dialog and is used only in getLocalPathForWritingFile or from an open/save dialog.(package private) String
setPathForAllFiles(String value)
static String
setScriptFileReferences(String script, String localPath, String remotePath, String scriptPath)
private static String
setScriptFileRefs(String script, String dataPath, boolean isLocal)
Sets all local file references in a script file to point to files within dataPath.SpartanUtil
spartanUtil()
An isolated class to retrieve Spartan file data from compound documents, zip files, and directoriesstatic String
stripPath(String name)
private String
urlEncode(String name)
-
-
-
Field Detail
-
SIMULATION_PROTOCOL
public static String SIMULATION_PROTOCOL
-
vwr
public Viewer vwr
-
spartanDoc
private SpartanUtil spartanDoc
-
jzu
JmolUtil jzu
-
pathForAllFiles
private String pathForAllFiles
-
nameAsGiven
private String nameAsGiven
-
fullPathName
private String fullPathName
-
lastFullPathName
private String lastFullPathName
-
lastNameAsGiven
private String lastNameAsGiven
-
fileName
private String fileName
-
appletDocumentBaseURL
private URL appletDocumentBaseURL
-
appletProxy
private String appletProxy
-
DELPHI_BINARY_MAGIC_NUMBER
private static final String DELPHI_BINARY_MAGIC_NUMBER
- See Also:
- Constant Field Values
-
PMESH_BINARY_MAGIC_NUMBER
public static final String PMESH_BINARY_MAGIC_NUMBER
- See Also:
- Constant Field Values
-
JPEG_CONTINUE_STRING
public static final String JPEG_CONTINUE_STRING
- See Also:
- Constant Field Values
-
scriptFilePrefixes
private static String[] scriptFilePrefixes
-
-
Constructor Detail
-
FileManager
FileManager(Viewer vwr)
-
-
Method Detail
-
spartanUtil
public SpartanUtil spartanUtil()
An isolated class to retrieve Spartan file data from compound documents, zip files, and directories- Returns:
- a SpartanUtil
-
getJzu
public JmolUtil getJzu()
-
clear
void clear()
-
getPathForAllFiles
public String getPathForAllFiles()
-
setFileInfo
public void setFileInfo(String[] fileInfo)
Set fullPathName, fileName, and nameAsGiven- Parameters:
fileInfo
- if null, replace fullPathName and nameAsGiven with last version of such
-
getFileInfo
public String[] getFileInfo()
-
getFullPathName
public String getFullPathName(boolean orPrevious)
-
getFileName
public String getFileName()
-
getAppletDocumentBase
String getAppletDocumentBase()
-
setAppletContext
void setAppletContext(String documentBase)
-
setAppletProxy
void setAppletProxy(String appletProxy)
-
createAtomSetCollectionFromFile
Object createAtomSetCollectionFromFile(String name, Map<String,Object> htParams, boolean isAppend)
-
createAtomSetCollectionFromFiles
Object createAtomSetCollectionFromFiles(String[] fileNames, Map<String,Object> htParams, boolean isAppend)
-
createAtomSetCollectionFromString
Object createAtomSetCollectionFromString(String strModel, Map<String,Object> htParams, boolean isAppend)
-
createAtomSeCollectionFromStrings
Object createAtomSeCollectionFromStrings(String[] arrayModels, javajs.util.SB loadScript, Map<String,Object> htParams, boolean isAppend)
-
createAtomSeCollectionFromArrayData
Object createAtomSeCollectionFromArrayData(javajs.util.Lst<Object> arrayData, Map<String,Object> htParams, boolean isAppend)
-
newFilesReader
private JmolFilesReaderInterface newFilesReader(String[] fullPathNames, String[] namesAsGiven, String[] fileTypes, javajs.util.DataReader[] readers, Map<String,Object> htParams, boolean isAppend)
-
createAtomSetCollectionFromDOM
Object createAtomSetCollectionFromDOM(Object DOMNode, Map<String,Object> htParams)
-
createAtomSetCollectionFromReader
Object createAtomSetCollectionFromReader(String fullPathName, String name, Object reader, Map<String,Object> htParams)
not used in Jmol project -- will close reader- Parameters:
fullPathName
-name
-reader
- could be a Reader, or a BufferedInputStream or byte[]htParams
-- Returns:
- fileData
-
getBufferedInputStream
BufferedInputStream getBufferedInputStream(String fullPathName)
-
getBufferedInputStreamOrErrorMessageFromName
public Object getBufferedInputStreamOrErrorMessageFromName(String name, String fullName, boolean showMsg, boolean checkOnly, byte[] outputBytes, boolean allowReader, boolean allowCached)
-
getBufferedReaderForResource
public static BufferedReader getBufferedReaderForResource(Viewer vwr, Object resourceClass, String classPath, String resourceName) throws IOException
- Throws:
IOException
-
getEmbeddedFileState
public String getEmbeddedFileState(String fileName, boolean allowCached, String sptName)
-
getFullPathNameOrError
Object getFullPathNameOrError(String filename, boolean getStream, String[] ret)
just check for a file as being readable. Do not go into a zip file- Parameters:
filename
-getStream
-ret
-- Returns:
- String[2] where [0] is fullpathname and [1] is error message or null
-
getBufferedReaderOrErrorMessageFromName
public Object getBufferedReaderOrErrorMessageFromName(String name, String[] fullPathNameReturn, boolean isBinary, boolean doSpecialLoad)
-
getUnzippedReaderOrStreamFromName
public Object getUnzippedReaderOrStreamFromName(String name, Object bytesOrStream, boolean allowZipStream, boolean forceInputStream, boolean isTypeCheckOnly, boolean doSpecialLoad, Map<String,Object> htParams)
- Parameters:
name
-bytesOrStream
- cached bytes or a BufferedInputStreamallowZipStream
- if the file is a zip file, allow a return that is a ZipInputStreamforceInputStream
- always return a raw BufferedInputStream, not a BufferedReader, and do not process PNGJ filesisTypeCheckOnly
- when possibly reading a spartan file for content (doSpecialLoad == true), just return the compound document's file listdoSpecialLoad
- check for a Spartan filehtParams
-- Returns:
- String if error or String[] if a type check or BufferedReader or BufferedInputStream
-
getZipDirectory
public String[] getZipDirectory(String fileName, boolean addManifest, boolean allowCached)
- Parameters:
fileName
-addManifest
-allowCached
-- Returns:
- [] if not a zip file;
-
getFileDataAsString
public boolean getFileDataAsString(String[] data, int nBytesMax, boolean doSpecialLoad, boolean allowBinary, boolean checkProtected)
- Parameters:
data
- [0] initially path name, but returned as full path name; [1]file contents (directory listing for a ZIP/JAR file) or error stringnBytesMax
- or -1doSpecialLoad
-allowBinary
-checkProtected
- TODO- Returns:
- true if successful; false on error
-
checkSecurity
private boolean checkSecurity(String f)
-
loadImage
public boolean loadImage(Object nameOrBytes, String echoName, boolean forceSync)
Load an image- Parameters:
nameOrBytes
-echoName
-forceSync
- TODO- Returns:
- true if asynchronous
-
getClassifiedName
private String[] getClassifiedName(String name, boolean isFullLoad)
[0] and [2] may return same as [1] in the case of a local unsigned applet.- Parameters:
name
-isFullLoad
- false only when just checking path- Returns:
- [0] full path name, [1] file name without path, [2] full URL
-
getLocalDirectory
public static GenericFileInterface getLocalDirectory(Viewer vwr, boolean forDialog)
-
setLocalPath
public static void setLocalPath(Viewer vwr, String path, boolean forDialog)
called by getImageFileNameFromDialog called by getOpenFileNameFromDialog called by getSaveFileNameFromDialog called by classifyName for any full file load called from the CD command currentLocalPath is set in all cases and is used specifically for dialogs as a first try defaultDirectoryLocal is set only when not from a dialog and is used only in getLocalPathForWritingFile or from an open/save dialog. In this way, saving a file from a dialog doesn't change the "CD" directory. Neither of these is saved in the state, but- Parameters:
vwr
-path
-forDialog
-
-
getLocalPathForWritingFile
public static String getLocalPathForWritingFile(Viewer vwr, String file)
-
fixDOSName
public static String fixDOSName(String fileName)
Switch \ for / only for DOS names such as C:\temp\t.xyz, not names like http://cactus.nci.nih.gov/chemical/structure/CC/C=C\CC- Parameters:
fileName
-- Returns:
- fixed name
-
determineSurfaceTypeIs
public static String determineSurfaceTypeIs(InputStream is)
-
isScriptType
public static boolean isScriptType(String fname)
-
isSurfaceType
public static boolean isSurfaceType(String fname)
-
determineSurfaceFileType
public static String determineSurfaceFileType(BufferedReader bufferedReader)
-
getManifestScriptPath
public static String getManifestScriptPath(String manifest)
check a JmolManifest for a reference to a script file (.spt)- Parameters:
manifest
-- Returns:
- null, "", or a directory entry in the ZIP file
-
getFileReferences
public static void getFileReferences(String script, javajs.util.Lst<String> fileList)
-
setScriptFileReferences
public static String setScriptFileReferences(String script, String localPath, String remotePath, String scriptPath)
-
setScriptFileRefs
private static String setScriptFileRefs(String script, String dataPath, boolean isLocal)
Sets all local file references in a script file to point to files within dataPath. If a file reference contains dataPath, then the file reference is left with that RELATIVE path. Otherwise, it is changed to a relative file name within that dataPath. Only file references starting with "file://" are changed.- Parameters:
script
-dataPath
-isLocal
-- Returns:
- revised script
-
cacheClear
void cacheClear()
-
cacheFileByNameAdd
public int cacheFileByNameAdd(String fileName, boolean isAdd)
-
recachePngjBytes
public void recachePngjBytes(String fileName, byte[] bytes)
-
getCachedPngjBytes
private byte[] getCachedPngjBytes(String pathName)
-
-