com.planet_ink.coffee_mud.core
Class Resources

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.Resources

public class Resources
extends java.lang.Object


Constructor Summary
Resources()
          Constructs a new CMLib object for the current thread group.
 
Method Summary
 void _clearResources()
          Instantly and permanently removes all resources.
static boolean _compressed()
          Returns whether resource objects are being compressed
 boolean _findRemoveProperty(CMFile F, java.lang.String match)
          Opens the given CMFile as a properties type file, ignoring comment lines, and looking for a property entry that matches [match]=[whatever], removing it if found, and if found, re-saving the file.
 java.util.Iterator<java.lang.String> _findResourceKeys(java.lang.String srch)
          Returns an iterator of all resource keys that pass a substring search of the given srch string.
 java.lang.StringBuffer _getFileResource(java.lang.String filename, boolean reportErrors)
          Returns the stringbuffer content for the given resource filename.
 java.lang.StringBuffer _getRawFileResource(java.lang.String filename, boolean reportErrors)
          Returns the stringbuffer content for the given resource filename.
 java.lang.Object _getResource(java.lang.String ID)
          Returns the resource object with the given case insensitive ID.
 boolean _isFileResource(java.lang.String filename)
          Returns true if there is a resource file object stored under the given filename OR if there exists a file with the given filename (and is thus potentially a file resource).
 boolean _isResource(java.lang.String ID)
          Checks the resource object with the given case insensitive ID.
 void _removeResource(java.lang.String ID)
          Removes the given resource with the given ID, if found.
 boolean _saveFileResource(java.lang.String filename, MOB whoM, java.lang.StringBuffer myRsc)
          Saves the given stringbuffer of data to the given resource filename, to the filesystem on behalf of the given user/player, without touching the cache.
 java.lang.Object _submitResource(java.lang.String ID, java.lang.Object obj)
          Adds or updates the given resource object at the given resource id/key.
 java.lang.StringBuffer _toStringBuffer(java.lang.Object o)
          Returns the string-like object given as a StringBuffer.
 boolean _updateFileResource(java.lang.String filename, java.lang.Object obj)
          Saves the given stringbuffer of data to the given resource filename, to the filesystem while also updating the internal cache for the resources.
static java.lang.String buildResourcePath(java.lang.String path)
          Adds resources/ before the given path, and always adds a / at the end.
static void clearResources()
          Removes all resources for the current calling thread group
static boolean findRemoveProperty(CMFile F, java.lang.String match)
          Opens the given CMFile as a properties type file, ignoring comment lines, and looking for a property entry that matches [match]=[whatever], removing it if found, and if found, re-saving the file.
static java.util.Iterator<java.lang.String> findResourceKeys(java.lang.String srch)
          Does a case-insensitive instring search of all resources for the current calling thread group and returns an iterator of all FULL keys that match.
static java.util.Map<java.lang.String,java.lang.String> getAllPropResources(java.lang.String section)
          The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK].
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getCachedMultiLists(java.lang.String filename, boolean createIfNot)
          A multi-list is, in code, a string-key map of string lists.
static java.lang.String getEOLineMarker(java.lang.StringBuffer buf)
          Scans the given stringbuffer for the first occurrence of an end-of-line and returns the end of line character(s) encountered.
static java.util.List<java.lang.String> getFileLineVector(java.lang.StringBuffer buf)
          Scans the given stringbuffer for end of line markers, and adds each line encountered to a string list, returning that list object.
static java.lang.StringBuffer getFileResource(java.lang.String filename, boolean reportErrors)
          Returns the stringbuffer content for the given resource filename, from the resources for the current calling thread group.
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getMultiLists(java.lang.String filename)
          A multi-list is, in code, a string-key map of string lists.
static java.util.Map<java.lang.String,java.lang.Object> getPersonalMap(java.lang.Object key, boolean createIfNecc)
          Returns the string/object map assigned to the given object key.
static java.lang.String getPropResource(java.lang.String section, java.lang.String key)
          The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK].
static java.lang.StringBuffer getRawFileResource(java.lang.String filename, boolean reportErrors)
          Returns the stringbuffer content for the given resource filename, from the resources for the current calling thread group.
static java.lang.Object getResource(java.lang.String ID)
          Returns the raw resource object for the given case-insensitive ID, from the resources for the current calling thread group.
static Resources initialize()
          Creates and returns a new Resources object for the current calling thread
static Resources instance()
          Returns the Resources instance tied to this particular thread group, or a new one if not yet created.
static Resources instance(char c)
          Returns the Resources instance tied to the given thread group, or null if not yet created.
static boolean isFileResource(java.lang.String filename)
          Checks the resources for the current calling thread group for a file resource of the given name.
static boolean isPropResource(java.lang.String section, java.lang.String key)
          The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK].
static boolean isResource(java.lang.String ID)
          Checks the current resources for the current calling thread group for the ID.
static java.lang.String makeFileResourceName(java.lang.String filename)
          Adds resources/ to the beginning of the given filename.
static Resources newResources()
          Creates and returns a new Resources object for the current calling thread
static java.lang.Object prepareObject(java.lang.Object obj)
          Prepares an object for storage in resources by trimming any vectors, and compressing any stringbuffers, if necessary.
static boolean removeMultiLists(java.lang.String filename)
          A multi-list is, in code, a string-key map of string lists.
static void removePersonalMap(java.lang.Object key)
          Removes and Deletes the string/object map assigned to the given object key.
static void removeResource(java.lang.String ID)
          Removes the current resources for the current calling thread group.
static boolean saveFileResource(java.lang.String filename, MOB whom, java.lang.StringBuffer myRsc)
          Saves the given stringbuffer of data to the given resource filename, to the filesystem on behalf of the given user/player, without touching the cache.
static void savePropResources()
          The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK].
static void setCompression(boolean truefalse)
          Turn on or off resource compression.
static void setPropResource(java.lang.String section, java.lang.String key, java.lang.String value)
          The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK].
static void shareWith(char code)
          Forces the current thread group to share a Resources object with the one at the given threadcode.
static void shutdown()
          Saves any cached resource properties for the current calling thread group.
static Resources staticInstance()
          Returns the Resources instance tied to this particular thread group, or null if not yet created.
static void submitResource(java.lang.String ID, java.lang.Object obj)
          Adds or replaces a raw resource object at the given case-insensitive ID, into the resources for the current calling thread group.
static boolean updateCachedMultiLists(java.lang.String filename)
          A multi-list is, in code, a string-key map of string lists.
static boolean updateFileResource(java.lang.String filename, java.lang.Object obj)
          Saves the given stringbuffer of data to the given resource filename, to the filesystem while also updating the internal cache for the resources of the calling threads thread group.
static void updateMultiListFile(java.lang.String filename, java.util.Map<java.lang.String,java.util.List<java.lang.String>> lists)
          A multi-list is, in code, a string-key map of string lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resources

public Resources()
Constructs a new CMLib object for the current thread group.

Method Detail

shareWith

public static void shareWith(char code)
Forces the current thread group to share a Resources object with the one at the given threadcode. The one at the threadcode should already have been created before calling.

Parameters:
code - the threadcode with an existing Resources

initialize

public static final Resources initialize()
Creates and returns a new Resources object for the current calling thread

Returns:
a new Resources object for the current calling thread

instance

public static final Resources instance()
Returns the Resources instance tied to this particular thread group, or a new one if not yet created.

Returns:
the Resources instance tied to this particular thread group, or a new one if if not yet created.

instance

public static final Resources instance(char c)
Returns the Resources instance tied to the given thread group, or null if not yet created.

Parameters:
c - the code for the thread group to return (0-255)
Returns:
the Resources instance tied to the given thread group, or null if not yet created.

staticInstance

public static final Resources staticInstance()
Returns the Resources instance tied to this particular thread group, or null if not yet created.

Returns:
the Resources instance tied to this particular thread group, or null if not yet created.

newResources

public static final Resources newResources()
Creates and returns a new Resources object for the current calling thread

Returns:
a new Resources object for the current calling thread

clearResources

public static final void clearResources()
Removes all resources for the current calling thread group


shutdown

public static final void shutdown()
Saves any cached resource properties for the current calling thread group. Removes all resources for the current calling thread group.


removeResource

public static final void removeResource(java.lang.String ID)
Removes the current resources for the current calling thread group.

Parameters:
ID - the resource ID to remove, case insensitive as always

isResource

public static final boolean isResource(java.lang.String ID)
Checks the current resources for the current calling thread group for the ID.

Parameters:
ID - the resource ID to check for
Returns:
true if found, false otherwise

findResourceKeys

public static final java.util.Iterator<java.lang.String> findResourceKeys(java.lang.String srch)
Does a case-insensitive instring search of all resources for the current calling thread group and returns an iterator of all FULL keys that match.

Parameters:
srch - the instring string to search for
Returns:
an iterator of all matching full keys

getResource

public static final java.lang.Object getResource(java.lang.String ID)
Returns the raw resource object for the given case-insensitive ID, from the resources for the current calling thread group.

Parameters:
ID - the resource ID to return
Returns:
the raw object at that resource ID, or null of not found

submitResource

public static final void submitResource(java.lang.String ID,
                                        java.lang.Object obj)
Adds or replaces a raw resource object at the given case-insensitive ID, into the resources for the current calling thread group.

Parameters:
ID - the resource ID to store the given object at
obj - the object to store at the given ID

isFileResource

public static final boolean isFileResource(java.lang.String filename)
Checks the resources for the current calling thread group for a file resource of the given name.

Parameters:
filename - the resource filename to check for (/resources/[FILENAME])
Returns:
true if the file exists as a current resource, and false otherwise

getFileResource

public static final java.lang.StringBuffer getFileResource(java.lang.String filename,
                                                           boolean reportErrors)
Returns the stringbuffer content for the given resource filename, from the resources for the current calling thread group. This method will normalize text data line endings for mud display.

Parameters:
filename - the resource filename (/resources/[FILENAME])
reportErrors - if true, file errors will be logged
Returns:
the StringBuffer of the file at that resource filename, or null of not found

getRawFileResource

public static final java.lang.StringBuffer getRawFileResource(java.lang.String filename,
                                                              boolean reportErrors)
Returns the stringbuffer content for the given resource filename, from the resources for the current calling thread group. This method returns the raw file text, with unnormalized line endings.

Parameters:
filename - the resource filename (/resources/[FILENAME])
reportErrors - if true, file errors will be logged
Returns:
the StringBuffer of the file at that resource filename, or null of not found

saveFileResource

public static final boolean saveFileResource(java.lang.String filename,
                                             MOB whom,
                                             java.lang.StringBuffer myRsc)
Saves the given stringbuffer of data to the given resource filename, to the filesystem on behalf of the given user/player, without touching the cache. Returns false if the user was not permitted to save files at that location.

Parameters:
filename - the resource filename to save to (/resources/[FILENAME])
whom - the mob whose permissions to check, or null to always save
myRsc - the string data to store in the file
Returns:
true if the file was saved, or false if there were permission or other problems

updateFileResource

public static final boolean updateFileResource(java.lang.String filename,
                                               java.lang.Object obj)
Saves the given stringbuffer of data to the given resource filename, to the filesystem while also updating the internal cache for the resources of the calling threads thread group. Returns false if there was a filesystem error.

Parameters:
filename - the resource filename to save to (/resources/[FILENAME])
obj - the string data to store in the file, stringbuffer, byte array, etc
Returns:
true if the file was saved, or false if there were problems

findRemoveProperty

public static final boolean findRemoveProperty(CMFile F,
                                               java.lang.String match)
Opens the given CMFile as a properties type file, ignoring comment lines, and looking for a property entry that matches [match]=[whatever], removing it if found, and if found, re-saving the file.

Parameters:
F - the properties file to potentially modify
match - the property file entry to remove
Returns:
true if the property was removed, and false if nothing was done

getEOLineMarker

public static final java.lang.String getEOLineMarker(java.lang.StringBuffer buf)
Scans the given stringbuffer for the first occurrence of an end-of-line and returns the end of line character(s) encountered. This could be \n, \r, \n\r, or \r\n

Parameters:
buf - the stringbuffer to scan
Returns:
the end of line market

getFileLineVector

public static final java.util.List<java.lang.String> getFileLineVector(java.lang.StringBuffer buf)
Scans the given stringbuffer for end of line markers, and adds each line encountered to a string list, returning that list object.

Parameters:
buf - the stringbuffer to scan for lines
Returns:
a list of all the lines in the buffer

buildResourcePath

public static final java.lang.String buildResourcePath(java.lang.String path)
Adds resources/ before the given path, and always adds a / at the end.

Parameters:
path - a path string
Returns:
resources/ before the given path, and always adds a / at the end

updateMultiListFile

public static final void updateMultiListFile(java.lang.String filename,
                                             java.util.Map<java.lang.String,java.util.List<java.lang.String>> lists)
A multi-list is, in code, a string-key map of string lists. In a file, it is represented by a string key on one line, followed by the list entries, followed by a blank line. Obviously, no blank list entries are permitted. This method will build a stringbuffer from the multi-list object, and then save it to the given resource filename. This method does nothing to the cache.

Parameters:
filename - the resource filename to save to
lists - the multi-list

getPersonalMap

public static final java.util.Map<java.lang.String,java.lang.Object> getPersonalMap(java.lang.Object key,
                                                                                    boolean createIfNecc)
Returns the string/object map assigned to the given object key. If createIfNecc is set, then a missing map will be created and returned. Otherwise this returns false. The internal object map is Weak, so no worries about leaving behind unused garbage. Just be careful with the returned map, which is NOT weak.

Parameters:
key - the key to look for
createIfNecc - true to create the missing map
Returns:
the map, or null
See Also:
getPersonalMap(Object, boolean)

removePersonalMap

public static final void removePersonalMap(java.lang.Object key)
Removes and Deletes the string/object map assigned to the given object key.

Parameters:
key - the key to look for
See Also:
getPersonalMap(Object, boolean)

removeMultiLists

public static final boolean removeMultiLists(java.lang.String filename)
A multi-list is, in code, a string-key map of string lists. In a file, it is represented by a string key on one line, followed by the list entries, followed by a blank line. Obviously, no blank list entries are permitted. This method Removes the parsed multi-list object from the memory cache for this thread group.

Parameters:
filename - the filename of the parsed multi-list file
Returns:
true

getCachedMultiLists

public static final java.util.Map<java.lang.String,java.util.List<java.lang.String>> getCachedMultiLists(java.lang.String filename,
                                                                                                         boolean createIfNot)
A multi-list is, in code, a string-key map of string lists. In a file, it is represented by a string key on one line, followed by the list entries, followed by a blank line. Obviously, no blank list entries are permitted. This method retrieves the parsed multi-list object from the memory cache of this thread group if found. If not found, it attempts to load it from the given resource filename.

Parameters:
filename - the filename of the parsed multi-list file
createIfNot - true to create a multilist object if not loaded, false if not
Returns:
the multi-list map object

updateCachedMultiLists

public static final boolean updateCachedMultiLists(java.lang.String filename)
A multi-list is, in code, a string-key map of string lists. In a file, it is represented by a string key on one line, followed by the list entries, followed by a blank line. Obviously, no blank list entries are permitted. This method re-saves the cached multi-list object in this thread groups resource cache to the given resource filename.

Parameters:
filename - the filename of the parsed multi-list file
Returns:
the multi-list map object, full or empty

getMultiLists

public static final java.util.Map<java.lang.String,java.util.List<java.lang.String>> getMultiLists(java.lang.String filename)
A multi-list is, in code, a string-key map of string lists. In a file, it is represented by a string key on one line, followed by the list entries, followed by a blank line. Obviously, no blank list entries are permitted. This method retrieves the parsed multi-list object from the given resource filename.

Parameters:
filename - the filename of the parsed multi-list file
Returns:
the multi-list map object, full or empty

makeFileResourceName

public static final java.lang.String makeFileResourceName(java.lang.String filename)
Adds resources/ to the beginning of the given filename. Just a way to normalize all resource filenames.

Parameters:
filename - the filename to resource normalize
Returns:
the filename, resource normalized

setCompression

public static final void setCompression(boolean truefalse)
Turn on or off resource compression.

Parameters:
truefalse - true to turn on compression, false to turn it off

_compressed

public static final boolean _compressed()
Returns whether resource objects are being compressed

Returns:
true if they are being compressed, false otherwise

_clearResources

public final void _clearResources()
Instantly and permanently removes all resources.


_findResourceKeys

public final java.util.Iterator<java.lang.String> _findResourceKeys(java.lang.String srch)
Returns an iterator of all resource keys that pass a substring search of the given srch string.

Parameters:
srch - the substring srch string
Returns:
an iterator of the resource keys that pass the search

_getResource

public final java.lang.Object _getResource(java.lang.String ID)
Returns the resource object with the given case insensitive ID. If the stringbuffer resource is compressed, it uncompresses it first.

Parameters:
ID - the key of the object to return
Returns:
the object found, or null

_isResource

public final boolean _isResource(java.lang.String ID)
Checks the resource object with the given case insensitive ID.

Parameters:
ID - the key of the object to look for
Returns:
true if found, false otherwise

prepareObject

public static final java.lang.Object prepareObject(java.lang.Object obj)
Prepares an object for storage in resources by trimming any vectors, and compressing any stringbuffers, if necessary.

Parameters:
obj - the object to prepare for storage
Returns:
the prepared object

_submitResource

public final java.lang.Object _submitResource(java.lang.String ID,
                                              java.lang.Object obj)
Adds or updates the given resource object at the given resource id/key.

Parameters:
ID - the key to store the resource as
obj - the object to store
Returns:
the object as stored.

_removeResource

public final void _removeResource(java.lang.String ID)
Removes the given resource with the given ID, if found.

Parameters:
ID - the key the resource is stored as

_isFileResource

public final boolean _isFileResource(java.lang.String filename)
Returns true if there is a resource file object stored under the given filename OR if there exists a file with the given filename (and is thus potentially a file resource).

Parameters:
filename - the filename to look in the cache or filesystem for
Returns:
true if the cache entry or file is found, false otherwise

_toStringBuffer

public final java.lang.StringBuffer _toStringBuffer(java.lang.Object o)
Returns the string-like object given as a StringBuffer.

Parameters:
o - the string, stringbuffer, or stringbuilder to convert to stringbuffer
Returns:
the stringbuffer, or null if it could not be converted.

_getFileResource

public final java.lang.StringBuffer _getFileResource(java.lang.String filename,
                                                     boolean reportErrors)
Returns the stringbuffer content for the given resource filename. Will normalize line endings for mud display.

Parameters:
filename - the resource filename (/resources/[FILENAME])
reportErrors - if true, file errors will be logged
Returns:
the StringBuffer of the file at that resource filename, or null of not found

_getRawFileResource

public final java.lang.StringBuffer _getRawFileResource(java.lang.String filename,
                                                        boolean reportErrors)
Returns the stringbuffer content for the given resource filename. Will NOT normalize line endings for mud display.

Parameters:
filename - the resource filename (/resources/[FILENAME])
reportErrors - if true, file errors will be logged
Returns:
the StringBuffer of the file at that resource filename, or null of not found

_updateFileResource

public final boolean _updateFileResource(java.lang.String filename,
                                         java.lang.Object obj)
Saves the given stringbuffer of data to the given resource filename, to the filesystem while also updating the internal cache for the resources. Returns false if there was a filesystem error.

Parameters:
filename - the resource filename to save to (/resources/[FILENAME])
obj - the string data to store in the file, stringbuffer, byte array, etc
Returns:
true if the file was saved, or false if there were problems

_saveFileResource

public final boolean _saveFileResource(java.lang.String filename,
                                       MOB whoM,
                                       java.lang.StringBuffer myRsc)
Saves the given stringbuffer of data to the given resource filename, to the filesystem on behalf of the given user/player, without touching the cache. Returns false if the user was not permitted to save files at that location.

Parameters:
filename - the resource filename to save to (/resources/[FILENAME])
whoM - the mob whose permissions to check, or null to always save
myRsc - the string data to store in the file
Returns:
true if the file was saved, or false if there were permission or other problems

_findRemoveProperty

public final boolean _findRemoveProperty(CMFile F,
                                         java.lang.String match)
Opens the given CMFile as a properties type file, ignoring comment lines, and looking for a property entry that matches [match]=[whatever], removing it if found, and if found, re-saving the file.

Parameters:
F - the properties file to potentially modify
match - the property file entry to remove
Returns:
true if the property was removed, and false if nothing was done

getAllPropResources

public static final java.util.Map<java.lang.String,java.lang.String> getAllPropResources(java.lang.String section)
The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK]. The filename is ::/coffeemud_properties.ini. These properties tend to be internal data maintained by the system for internal use, and resaved as necessary. This method retrieves all properties in a given section into a string map. If they are not cached, this method will cache all properties of all sections.

Parameters:
section - the section in the resource properties to get entries from
Returns:
a map of the entries in the given section

isPropResource

public static final boolean isPropResource(java.lang.String section,
                                           java.lang.String key)
The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK]. The filename is ::/coffeemud_properties.ini. These properties tend to be internal data maintained by the system for internal use, and resaved as necessary. This method checks for a given property key in a given section and returns whether it was found.

Parameters:
section - the section to look in
key - the property key to look for in that section
Returns:
true if the key was found, false otherwise

getPropResource

public static final java.lang.String getPropResource(java.lang.String section,
                                                     java.lang.String key)
The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK]. The filename is ::/coffeemud_properties.ini. These properties tend to be internal data maintained by the system for internal use, and resaved as necessary. This method returns the value of the given property key in the given section, or "" if it was not found.

Parameters:
section - the section of the resource properties to look in
key - the key in the section to look for
Returns:
the value of the property key, or ""

setPropResource

public static final void setPropResource(java.lang.String section,
                                         java.lang.String key,
                                         java.lang.String value)
The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK]. The filename is ::/coffeemud_properties.ini. These properties tend to be internal data maintained by the system for internal use, and resaved as necessary. This method sets or removes the value of the given property key in the given section. It does not re-save. If the value is null or "", the property key is removed.

Parameters:
section - the section of the resource properties to add the key to
key - the key in the section to set
value - the new value of the key, or "" to remove

savePropResources

public static final void savePropResources()
The "Resource Properties" is a special VFS file containing normal properties divided into sections headed by a bracketed [BLOCK]. The filename is ::/coffeemud_properties.ini. These properties tend to be internal data maintained by the system for internal use, and resaved as necessary. This method re-saves the cached resource properties object back to the filesystem.