Class FileStorageHelper
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.filestorage.impl.FileStorageHelper
-
public class FileStorageHelper extends Object
A collection of utility routines used by the file storage system. Routines exist to:- encode filenames for safe storage
- decode filenames to their original values
- convert an ID (with namespaces) to a path, relative to the root directory
- convert an ID (with namespaces) to an absolute path
- convert an ID (with namespaces) and a filename to a full path for storing the file
-
-
Field Summary
Fields Modifier and Type Field Description static StringHEX_ENCODE_SOURCESstatic charHEX_ESCAPE_CHARstatic char[]NAME_SINGLE_CHARACTER_SOURCESSame as for path, except that a period is not translated.static char[]NAME_SINGLE_CHARACTER_TARGETSSame as for path, except that a period is not translated.static char[]PATH_SINGLE_CHARACTER_SOURCESstatic char[]PATH_SINGLE_CHARACTER_TARGETSstatic String[]WINDOWS_RESERVED_NAMESWindows reserves these names (case-insensitive), so they can't be used for directories or files.
-
Constructor Summary
Constructors Constructor Description FileStorageHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdecodeName(String stored)Restore the filename to its original form, removing the encoding.static StringencodeName(String filename)Encode the filename as needed to guard against illegal characters.static FilegetFullPath(File rootDir, String id, String filename, Map<Character,String> namespacesMap)Translate the object ID, the file storage root directory and the filename into a full path to where the file would be stored.static FilegetPathToIdDirectory(String id, Map<Character,String> namespacesMap, File rootDir)Translate the object ID and the file storage root directory into a full path to the directory that would represent that ID.static Stringid2Path(String id, Map<Character,String> namespacesMap)Translate the object ID to a relative directory path.
-
-
-
Field Detail
-
HEX_ESCAPE_CHAR
public static final char HEX_ESCAPE_CHAR
- See Also:
- Constant Field Values
-
HEX_ENCODE_SOURCES
public static final String HEX_ENCODE_SOURCES
- See Also:
- Constant Field Values
-
PATH_SINGLE_CHARACTER_SOURCES
public static final char[] PATH_SINGLE_CHARACTER_SOURCES
-
PATH_SINGLE_CHARACTER_TARGETS
public static final char[] PATH_SINGLE_CHARACTER_TARGETS
-
NAME_SINGLE_CHARACTER_SOURCES
public static final char[] NAME_SINGLE_CHARACTER_SOURCES
Same as for path, except that a period is not translated.
-
NAME_SINGLE_CHARACTER_TARGETS
public static final char[] NAME_SINGLE_CHARACTER_TARGETS
Same as for path, except that a period is not translated.
-
WINDOWS_RESERVED_NAMES
public static final String[] WINDOWS_RESERVED_NAMES
Windows reserves these names (case-insensitive), so they can't be used for directories or files.
-
-
Method Detail
-
encodeName
public static String encodeName(String filename)
Encode the filename as needed to guard against illegal characters.
-
decodeName
public static String decodeName(String stored)
Restore the filename to its original form, removing the encoding.
-
id2Path
public static String id2Path(String id, Map<Character,String> namespacesMap)
Translate the object ID to a relative directory path. A recognized namespace is translated to its prefix, and illegal characters are encoded. The resulting string is broken up into 3-character directory names (or less). Windows reserved words are prefixed with tilde.
-
getPathToIdDirectory
public static File getPathToIdDirectory(String id, Map<Character,String> namespacesMap, File rootDir)
Translate the object ID and the file storage root directory into a full path to the directory that would represent that ID.
-
-