org.jmol.viewer
Class FileManager

java.lang.Object
  extended by org.jmol.viewer.FileManager

public class FileManager
extends Object


Nested Class Summary
(package private)  class FileManager.ArrayDataReader
          ArrayDataReader subclasses BufferedReader and overrides its read, readLine, mark, and reset methods so that JmolAdapter works with String[] arrays without any further adaptation.
(package private)  class FileManager.DataReader
          Just a simple abstract class to join a String reader and a String[] reader under the same BufferedReader umbrella.
private  class FileManager.DOMReader
           
private  class FileManager.FileReader
           
private  class FileManager.FilesReader
          open a set of models residing in different files
(package private)  class FileManager.StringDataReader
           
(package private)  class FileManager.VectorDataReader
          VectorDataReader subclasses BufferedReader and overrides its read, readLine, mark, and reset methods so that JmolAdapter works with Vector arrays without any further adaptation.
 
Field Summary
private  URL appletCodeBase
           
private  URL appletDocumentBase
           
private  String appletProxy
           
(package private)  String fileName
           
(package private)  String fullPathName
           
(package private)  String nameAsGiven
           
private static String[] scriptFilePrefixes
           
private static int URL_LOCAL
           
private static String[] urlPrefixes
           
private static String[] urlPrefixPairs
           
protected  Viewer viewer
           
 
Constructor Summary
FileManager(Viewer viewer)
           
 
Method Summary
private static String addDirectory(String defaultDirectory, String name)
           
private  String[] classifyName(String name, boolean isFullLoad)
           
(package private)  void clear()
           
(package private)  Object createAtomSeCollectionFromArrayData(List arrayData, Hashtable htParams, boolean isAppend)
           
(package private)  Object createAtomSeCollectionFromStrings(String[] arrayModels, StringBuffer loadScript, Hashtable htParams, boolean isAppend)
           
(package private)  Object createAtomSetCollectionFromDOM(Object DOMNode, Hashtable htParams)
           
(package private)  Object createAtomSetCollectionFromFile(String name, Hashtable htParams, StringBuffer loadScript, boolean isAppend)
           
(package private)  Object createAtomSetCollectionFromFiles(String[] fileNames, Hashtable htParams, boolean isAppend)
           
(package private)  Object createAtomSetCollectionFromReader(String fullPathName, String name, Reader reader, Hashtable htParams)
          not used in Jmol project -- will close reader
(package private)  Object createAtomSetCollectionFromString(String strModel, StringBuffer loadScript, Hashtable htParams, boolean isAppend, boolean isLoadVariable)
           
(package private)  String createZipSet(String fileName, String script, boolean includeRemoteFiles)
           
static String fixFileNameVariables(String format, String fname)
           
private static String fixPath(String path)
           
(package private)  String getAppletDocumentBase()
           
(package private)  BufferedInputStream getBufferedInputStream(String fullPathName)
           
private static BufferedReader getBufferedReaderForString(String string)
           
(package private)  Object getBufferedReaderOrErrorMessageFromName(String name, String[] fullPathNameReturn, boolean isBinary, boolean doSpecialLoad)
           
(package private)  String getDefaultDirectory(String name)
           
(package private)  Object getFileAsBytes(String name, OutputStream os)
           
(package private)  Object getFileAsImage(String name, Hashtable htParams)
           
(package private)  boolean getFileDataOrErrorAsString(String[] data, int nBytesMax, boolean doSpecialLoad)
           
(package private)  String[] getFileInfo()
           
(package private)  String getFileName()
           
 String getFilePath(String name, boolean addUrlPrefix, boolean asShortName)
           
static void getFileReferences(String script, List fileList)
           
(package private)  String getFileTypeName(String fileName)
           
(package private)  String getFullPathName()
           
(package private)  String[] getFullPathNameOrError(String filename)
          just check for a file as being readable.
(package private)  Object getInputStreamOrErrorMessageFromName(String name, boolean showMsg, boolean checkOnly)
           
private static Object getInputStreamOrPost(String name, boolean showMsg, byte[] bytes, boolean checkOnly, URL appletDocumentBase, String appletProxy)
           
static File getLocalDirectory(JmolViewer viewer, boolean forDialog)
           
static String getLocalPathForWritingFile(JmolViewer viewer, String file)
           
static String getLocalUrl(File file)
           
private  String getObjectAsSections(String name, String header, Hashtable fileData)
          delivers file contents and directory listing for a ZIP/JAR file into sb
(package private)  String getState(StringBuffer sfunc)
           
private static Object getStreamAsBytes(BufferedInputStream bis, OutputStream os)
           
(package private)  Object getUnzippedBufferedReaderOrErrorMessageFromName(String name, boolean allowZipStream, boolean asInputStream, boolean isTypeCheckOnly, boolean doSpecialLoad)
           
(package private)  String[] getZipDirectory(String fileName, boolean addManifest)
           
private  String getZipDirectoryAsString(String fileName)
           
private static String postByteArray(String outFileName, byte[] bytes)
           
(package private)  void setAppletContext(URL documentBase, URL codeBase, String jmolAppletProxy)
           
(package private)  void setAppletProxy(String appletProxy)
           
(package private)  void setFileInfo(String[] fileInfo)
           
private  void setLoadState(Hashtable htParams)
           
static void setLocalPath(JmolViewer viewer, String path, boolean forDialog)
           
private static String setScriptFileReferences(String script, String dataPath, boolean isLocal)
          Sets all local file references in a script file to point to files within dataPath.
static String setScriptFileReferences(String script, String localPath, String remotePath, String scriptPath)
           
private static int urlTypeIndex(String name)
           
private static String writeZipFile(String outFileName, List fileNamesAndByteArrays, boolean preservePath, String msg)
          generic method to create a zip file based on http://www.exampledepot.com/egs/java.util.zip/CreateZip.html
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewer

protected Viewer viewer

nameAsGiven

String nameAsGiven

fullPathName

String fullPathName

fileName

String fileName

appletDocumentBase

private URL appletDocumentBase

appletCodeBase

private URL appletCodeBase

appletProxy

private String appletProxy

URL_LOCAL

private static final int URL_LOCAL
See Also:
Constant Field Values

urlPrefixes

private static final String[] urlPrefixes

urlPrefixPairs

private static final String[] urlPrefixPairs

scriptFilePrefixes

private static String[] scriptFilePrefixes
Constructor Detail

FileManager

FileManager(Viewer viewer)
Method Detail

clear

void clear()

setLoadState

private void setLoadState(Hashtable htParams)

setFileInfo

void setFileInfo(String[] fileInfo)

getFileInfo

String[] getFileInfo()

getFullPathName

String getFullPathName()

getFileName

String getFileName()

getAppletDocumentBase

String getAppletDocumentBase()

setAppletContext

void setAppletContext(URL documentBase,
                      URL codeBase,
                      String jmolAppletProxy)

setAppletProxy

void setAppletProxy(String appletProxy)

getState

String getState(StringBuffer sfunc)

getFileTypeName

String getFileTypeName(String fileName)

getBufferedReaderForString

private static BufferedReader getBufferedReaderForString(String string)

getZipDirectoryAsString

private String getZipDirectoryAsString(String fileName)

createAtomSetCollectionFromFile

Object createAtomSetCollectionFromFile(String name,
                                       Hashtable htParams,
                                       StringBuffer loadScript,
                                       boolean isAppend)

createAtomSetCollectionFromFiles

Object createAtomSetCollectionFromFiles(String[] fileNames,
                                        Hashtable htParams,
                                        boolean isAppend)

createAtomSetCollectionFromString

Object createAtomSetCollectionFromString(String strModel,
                                         StringBuffer loadScript,
                                         Hashtable htParams,
                                         boolean isAppend,
                                         boolean isLoadVariable)

createAtomSeCollectionFromStrings

Object createAtomSeCollectionFromStrings(String[] arrayModels,
                                         StringBuffer loadScript,
                                         Hashtable htParams,
                                         boolean isAppend)

createAtomSeCollectionFromArrayData

Object createAtomSeCollectionFromArrayData(List arrayData,
                                           Hashtable htParams,
                                           boolean isAppend)

createAtomSetCollectionFromDOM

Object createAtomSetCollectionFromDOM(Object DOMNode,
                                      Hashtable htParams)

createAtomSetCollectionFromReader

Object createAtomSetCollectionFromReader(String fullPathName,
                                         String name,
                                         Reader reader,
                                         Hashtable htParams)
not used in Jmol project -- will close reader

Parameters:
fullPathName -
name -
reader -
htParams -
Returns:
fileData

getBufferedInputStream

BufferedInputStream getBufferedInputStream(String fullPathName)

getInputStreamOrErrorMessageFromName

Object getInputStreamOrErrorMessageFromName(String name,
                                            boolean showMsg,
                                            boolean checkOnly)

getInputStreamOrPost

private static Object getInputStreamOrPost(String name,
                                           boolean showMsg,
                                           byte[] bytes,
                                           boolean checkOnly,
                                           URL appletDocumentBase,
                                           String appletProxy)

getFullPathNameOrError

String[] getFullPathNameOrError(String filename)
just check for a file as being readable. Do not go into a zip file

Parameters:
filename -
Returns:
String[2] where [0] is fullpathname and [1] is error message or null

getBufferedReaderOrErrorMessageFromName

Object getBufferedReaderOrErrorMessageFromName(String name,
                                               String[] fullPathNameReturn,
                                               boolean isBinary,
                                               boolean doSpecialLoad)

getUnzippedBufferedReaderOrErrorMessageFromName

Object getUnzippedBufferedReaderOrErrorMessageFromName(String name,
                                                       boolean allowZipStream,
                                                       boolean asInputStream,
                                                       boolean isTypeCheckOnly,
                                                       boolean doSpecialLoad)

getZipDirectory

String[] getZipDirectory(String fileName,
                         boolean addManifest)

getObjectAsSections

private String getObjectAsSections(String name,
                                   String header,
                                   Hashtable fileData)
delivers file contents and directory listing for a ZIP/JAR file into sb

Parameters:
name -
header -
fileData -
Returns:
name of entry

getFileAsBytes

Object getFileAsBytes(String name,
                      OutputStream os)

getStreamAsBytes

private static Object getStreamAsBytes(BufferedInputStream bis,
                                       OutputStream os)
                                throws IOException
Throws:
IOException

getFileDataOrErrorAsString

boolean getFileDataOrErrorAsString(String[] data,
                                   int nBytesMax,
                                   boolean doSpecialLoad)
Parameters:
data - [0] initially path name, but returned as full path name; [1]file contents (directory listing for a ZIP/JAR file) or error string
nBytesMax -
doSpecialLoad -
Returns:
true if successful; false on error

getFileAsImage

Object getFileAsImage(String name,
                      Hashtable htParams)

urlTypeIndex

private static int urlTypeIndex(String name)

classifyName

private String[] classifyName(String name,
                              boolean isFullLoad)
Parameters:
name -
isFullLoad -
Returns:
[0] full path name, [1] file name without path, [2] full URL

addDirectory

private static String addDirectory(String defaultDirectory,
                                   String name)

getDefaultDirectory

String getDefaultDirectory(String name)

fixPath

private static String fixPath(String path)

getFilePath

public String getFilePath(String name,
                          boolean addUrlPrefix,
                          boolean asShortName)

getLocalUrl

public static String getLocalUrl(File file)

getLocalDirectory

public static File getLocalDirectory(JmolViewer viewer,
                                     boolean forDialog)

setLocalPath

public static void setLocalPath(JmolViewer viewer,
                                String path,
                                boolean forDialog)

getLocalPathForWritingFile

public static String getLocalPathForWritingFile(JmolViewer viewer,
                                                String file)

setScriptFileReferences

public static String setScriptFileReferences(String script,
                                             String localPath,
                                             String remotePath,
                                             String scriptPath)

setScriptFileReferences

private static String setScriptFileReferences(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

getFileReferences

public static void getFileReferences(String script,
                                     List fileList)

createZipSet

String createZipSet(String fileName,
                    String script,
                    boolean includeRemoteFiles)

writeZipFile

private static String writeZipFile(String outFileName,
                                   List fileNamesAndByteArrays,
                                   boolean preservePath,
                                   String msg)
generic method to create a zip file based on http://www.exampledepot.com/egs/java.util.zip/CreateZip.html

Parameters:
outFileName -
fileNamesAndByteArrays - List of [filename1, bytes|null, filename2, bytes|null, ...]
preservePath -
msg -
Returns:
msg bytes filename or errorMessage

postByteArray

private static String postByteArray(String outFileName,
                                    byte[] bytes)

fixFileNameVariables

public static String fixFileNameVariables(String format,
                                          String fname)