java.lang.Object
io.sf.jclf.util.locale.ResourceFactory
- Direct Known Subclasses:
FileResourceFactory
,LoaderResourceFactory
Factory of localized objects.
Loads objects according to basename, extension and locale name.
-
Constructor Summary
ConstructorDescriptionConstructs a ResourceFactory based on a default associator.ResourceFactory
(Associator assoc) Constructs a ResourceFactory based on the given associator. -
Method Summary
Modifier and TypeMethodDescriptionlong
Gets the time (in milliseconds) when the resource just loaded was last modified.protected Object
instantiateObject
(InputStream is, String baseFileName, String localeName, String ext, Locale locale, URL url) abstract InputStream
loadLocalFile
(String baseFileName, String ext, String localeName) Load a resource file.loadLocalObject
(String baseFileName, String ext, String localeName, Locale locale) protected InputStream
protected void
setLastModified
(long time)
-
Constructor Details
-
ResourceFactory
public ResourceFactory()Constructs a ResourceFactory based on a default associator. -
ResourceFactory
Constructs a ResourceFactory based on the given associator.- Parameters:
assoc
- the associator.
-
-
Method Details
-
getLastModified
public long getLastModified()Gets the time (in milliseconds) when the resource just loaded was last modified.- Returns:
- the time (in milliseconds) when the resource just loaded was last modified, or zero if not known.
-
setLastModified
protected void setLastModified(long time) -
readURL
- Throws:
IOException
-
loadLocalObject
public Object loadLocalObject(String baseFileName, String ext, String localeName, Locale locale) throws IOException - Parameters:
baseFileName
- the basename of the pathext
- the extension.localeName
- the name of the locale, including the initial '.', eg. ".es_ES".locale
- the Locale. Both the locale and the locale name are supplied, to avoid the overhead of building the locale name several times.- Returns:
- the newly instantiated object, or the inputstream if could not instantiate the object, or null if no inputstream could be opened
- Throws:
IOException
- if the object cannot be loaded.
-
instantiateObject
protected Object instantiateObject(InputStream is, String baseFileName, String localeName, String ext, Locale locale, URL url) throws IOException - Throws:
IOException
-
loadLocalFile
public abstract InputStream loadLocalFile(String baseFileName, String ext, String localeName) throws IOException Load a resource file.- Parameters:
baseFileName
- the basename of the path.ext
- the extension.localeName
- the name of the locale, eg. es_ES.- Returns:
- the input stream with the file contents.
- Throws:
IOException
- if the file cannot be loaded.
-