Package com.iizix.urn.file
Class FileURN
java.lang.Object
com.iizix.urn.URN
com.iizix.urn.URNResource
com.iizix.urn.file.FileURN
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
ImageURN
File Uniform Resource Naming (URN) instance class, holding a file name referencing a resource type with an identifier. The identifier is a Long or a String value depending on the resource type.
The IIZI file URN's are formatted as:
urn:iz-file:type:[id:]fileName
The types supported without id
parameter, but using the case sensitive fileName
parameter:
common-db
orURNResourceType.COMMON_DATABASE_PERSISTENT
: Common server files stored in database (cached on the server even for starts/stops).common-persist
orURNResourceType.COMMON_PERSISTENT
: Common server files (persists when server starts/stops).common-volatile
orURNResourceType.COMMON_VOLATILE
: Common server files (volatile when server starts/stops).external
orURNResourceType.EXTERNAL_FILES
: External files (typically accessible using the 'file:' protocol). ThefileName
parameter must be a{@link URI}
.
- Author:
- Christopher Mindus
- See Also:
Field Summary
Fields inherited from class com.iizix.urn.URNResource
id, type
Constructor Summary
ModifierConstructorDescriptionprotected
FileURN
(String urnString, URNResourceType type, Object id, String fileName) Constructor for a File URN.Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if another URN is equal to this one.static FileURN
fromExternalFile
(File file) Creates an external File URN from a URI.static FileURN
fromExternalFile
(String fileName) Creates an external File URN from a URI.static FileURN
fromExternalFile
(URI uriFile) Creates an external File URN from a URI.static FileURN
fromFileResource
(URNResourceType type, Object id, String fileName) Creates a File URN from a string.Gets the parameter string for theURN.toString()
method.getURL()
Gets the URL of this resource relative the current web server.int
hashCode()
Gets the hash code of the instance.Methods inherited from class com.iizix.urn.URNResource
asURNResource, getID, getImageTarget, getType, isImageTargetSupported, isURNResource
Methods inherited from class com.iizix.urn.URN
from, getURNString, toString
Constructor Details
FileURN
Constructor for a File URN.- Parameters:
urnString
- The full URN String.type
- The URN resource type.id
- The URN resource ID for the type: a Long or a String depending of thetype
,null
for none.fileName
- The file name.
Method Details
fromExternalFile
Creates an external File URN from a URI.- Parameters:
fileName
- The file name.- Throws:
NullPointerException
- If thefile
is null.FileNotFoundException
- If thefile
is not found or is a directory.IOException
- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries.SecurityException
- If a required system property value cannot be accessed, or if a security manager exists and itsSecurityManager.checkRead(java.io.FileDescriptor)
method denies read access to the file.
fromExternalFile
public static FileURN fromExternalFile(File file) throws MalformedURLException, FileNotFoundException, IOException Creates an external File URN from a URI.- Parameters:
file
- The file.- Throws:
NullPointerException
- If thefile
is null.FileNotFoundException
- If thefile
is not found or is a directory.IOException
- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries.SecurityException
- If a required system property value cannot be accessed, or if a security manager exists and itsSecurityManager.checkRead(java.io.FileDescriptor)
method denies read access to the file.MalformedURLException
fromExternalFile
Creates an external File URN from a URI.- Parameters:
uriFile
- The file URI.- Throws:
NullPointerException
- If theuriFile
is null.IllegalArgumentException
- IfuriFile
as URL is not absolute.MalformedURLException
- IfuriFile
as URL protocol handler could not be found, or if some other error occurred while constructing the URL.
fromFileResource
public static FileURN fromFileResource(URNResourceType type, Object id, String fileName) throws MalformedURLException, MalformedURNException Creates a File URN from a string.- Parameters:
type
- The URN resource type.id
- The ID used for database identification, Long or String,null
when database is not used.This value depends on the URNResourceType. The types are:
Long
:URNResourceType.COMMON_DATABASE_PERSISTENT
: Common database persistent files.String
:URNResourceType.APPLICATION_DATABASE_PERSISTENT
: Application ID database persistent files.Long
:URNResourceType.GROUP_DATABASE_FILES
: Group ID database persistent files.Long
:URNResourceType.USER_DATABASE_FILES
: User ID database persistent files.null
For all other{@link URNResourceType}
's.
fileName
- The file name.- Throws:
NullPointerException
- If thetype
orfileName
is null.IllegalArgumentException
- If the class of theid
parameter does not match thetype
URNResourceType
parameter. Currently, only {code Long} and {code String} values are allowed.MalformedURLException
- If theurl
is malformed.MalformedURNException
- If theurl
is malformed for an IIZI URN URL.
hashCode
public int hashCode()Gets the hash code of the instance. The original URN string is not used for this hash code, rather the URN 'NID' and the parameters.- Overrides:
hashCode
in classURNResource
- Returns:
- A hash code value.
equals
Checks if another URN is equal to this one. The original URN string is not used for this comparison, rather the URN 'NID' and the parameters.- Overrides:
equals
in classURNResource
- Parameters:
obj
- The other object to compare with.- Returns:
- true if the URN's are equal, false otherwise.
getParamString
Gets the parameter string for theURN.toString()
method.- Overrides:
getParamString
in classURNResource
- Returns:
- The parameter string, always
non-null
.
getURL
Gets the URL of this resource relative the current web server.- Overrides:
getURL
in classURNResource
- Returns:
- The URL relative the current server, if based on the current server.
- Throws:
IOException
- If there was a problem retrieving the file or an SQL error.