Don't register the resource: handler by default. It causes problems and we only
want to do it in our clients. Also demoted some log messages to debug and widened. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@134 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -373,7 +373,7 @@ public class ResourceBundle
|
|||||||
_tmpdir = new File(tmpdir, "narcache_" + rando);
|
_tmpdir = new File(tmpdir, "narcache_" + rando);
|
||||||
if (!_tmpdir.exists()) {
|
if (!_tmpdir.exists()) {
|
||||||
if (_tmpdir.mkdirs()) {
|
if (_tmpdir.mkdirs()) {
|
||||||
Log.info("Created narya temp cache directory '" + _tmpdir + "'.");
|
Log.debug("Created narya temp cache directory '" + _tmpdir + "'.");
|
||||||
} else {
|
} else {
|
||||||
Log.warning("Failed to create temp cache directory '" + _tmpdir + "'.");
|
Log.warning("Failed to create temp cache directory '" + _tmpdir + "'.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,29 +52,23 @@ import com.samskivert.util.ResultListener;
|
|||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resource manager is responsible for maintaining a repository of
|
* The resource manager is responsible for maintaining a repository of resources that are
|
||||||
* resources that are synchronized with a remote source. This is
|
* synchronized with a remote source. This is accomplished in the form of sets of jar files
|
||||||
* accomplished in the form of sets of jar files (resource bundles) that
|
* (resource bundles) that contain resources and that are updated from a remote resource repository
|
||||||
* contain resources and that are updated from a remote resource
|
* via HTTP. These resource bundles are organized into resource sets. A resource set contains one
|
||||||
* repository via HTTP. These resource bundles are organized into
|
* or more resource bundles and is defined much like a classpath.
|
||||||
* resource sets. A resource set contains one or more resource bundles and
|
|
||||||
* is defined much like a classpath.
|
|
||||||
*
|
*
|
||||||
* <p> The resource manager can load resources from the default resource
|
* <p> The resource manager can load resources from the default resource set, and can make
|
||||||
* set, and can make available named resource sets to entities that wish
|
* available named resource sets to entities that wish to do their own resource loading. If the
|
||||||
* to do their own resource loading. If the resource manager fails to
|
* resource manager fails to locate a resource in the default resource set, it falls back to
|
||||||
* locate a resource in the default resource set, it falls back to loading
|
* loading the resource via the classloader (which will search the classpath).
|
||||||
* the resource via the classloader (which will search the classpath).
|
|
||||||
*
|
*
|
||||||
* <p> Applications that wish to make use of resource sets and their
|
* <p> Applications that wish to make use of resource sets and their associated bundles must call
|
||||||
* associated bundles must call {@link #initBundles} after constructing
|
* {@link #initBundles} after constructing the resource manager, providing the path to a resource
|
||||||
* the resource manager, providing the path to a resource definition file
|
* definition file which describes these resource sets. The definition file will be loaded and the
|
||||||
* which describes these resource sets. The definition file will be loaded
|
* resource bundles defined within will be loaded relative to the resource directory. The bundles
|
||||||
* and the resource bundles defined within will be loaded relative to the
|
* will be cached in the user's home directory and only reloaded when the source resources have
|
||||||
* resource directory. The bundles will be cached in the user's home
|
* been updated. The resource definition file looks something like the following:
|
||||||
* directory and only reloaded when the source resources have been
|
|
||||||
* updated. The resource definition file looks something like the
|
|
||||||
* following:
|
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* resource.set.default = sets/misc/config.jar: \
|
* resource.set.default = sets/misc/config.jar: \
|
||||||
@@ -89,39 +83,35 @@ import com.samskivert.util.StringUtil;
|
|||||||
* /global/resources/sounds/music.jar
|
* /global/resources/sounds/music.jar
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p> All resource set definitions are prefixed with
|
* <p> All resource set definitions are prefixed with <code>resource.set.</code> and all text
|
||||||
* <code>resource.set.</code> and all text following that string is
|
* following that string is considered to be the name of the resource set. The resource set named
|
||||||
* considered to be the name of the resource set. The resource set named
|
* <code>default</code> is the default resource set and is the one that is searched for resources
|
||||||
* <code>default</code> is the default resource set and is the one that is
|
* is a call to {@link #getResource}.
|
||||||
* searched for resources is a call to {@link #getResource}.
|
|
||||||
*
|
*
|
||||||
* <p> When a resource is loaded from a resource set, the set is searched
|
* <p> When a resource is loaded from a resource set, the set is searched in the order that entries
|
||||||
* in the order that entries are specified in the definition.
|
* are specified in the definition.
|
||||||
*/
|
*/
|
||||||
public class ResourceManager
|
public class ResourceManager
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Provides facilities for notifying an observer of the resource
|
* Provides facilities for notifying an observer of the resource unpacking process.
|
||||||
* unpacking process.
|
|
||||||
*/
|
*/
|
||||||
public interface InitObserver
|
public interface InitObserver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates a percent completion along with an estimated time
|
* Indicates a percent completion along with an estimated time remaining in seconds.
|
||||||
* remaining in seconds.
|
|
||||||
*/
|
*/
|
||||||
public void progress (int percent, long remaining);
|
public void progress (int percent, long remaining);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that there was a failure unpacking our resource
|
* Indicates that there was a failure unpacking our resource bundles.
|
||||||
* bundles.
|
|
||||||
*/
|
*/
|
||||||
public void initializationFailed (Exception e);
|
public void initializationFailed (Exception e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An adapter that wraps an {@link InitObserver} and routes all method
|
* An adapter that wraps an {@link InitObserver} and routes all method invocations to the AWT
|
||||||
* invocations to the AWT thread.
|
* thread.
|
||||||
*/
|
*/
|
||||||
public static class AWTInitObserver implements InitObserver
|
public static class AWTInitObserver implements InitObserver
|
||||||
{
|
{
|
||||||
@@ -149,17 +139,15 @@ public class ResourceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a resource manager which will load resources via the
|
* Constructs a resource manager which will load resources via the classloader, prepending
|
||||||
* classloader, prepending <code>resourceRoot</code> to their path.
|
* <code>resourceRoot</code> to their path.
|
||||||
*
|
*
|
||||||
* @param resourceRoot the path to prepend to resource paths prior to
|
* @param resourceRoot the path to prepend to resource paths prior to attempting to load them
|
||||||
* attempting to load them via the classloader. When resources are
|
* via the classloader. When resources are bundled into the default resource bundle, they don't
|
||||||
* bundled into the default resource bundle, they don't need this
|
* need this prefix, but if they're to be loaded from the classpath, it's likely that they'll
|
||||||
* prefix, but if they're to be loaded from the classpath, it's likely
|
* live in some sort of <code>resources</code> directory to isolate them from the rest of the
|
||||||
* that they'll live in some sort of <code>resources</code> directory
|
* files in the classpath. This is not a platform dependent path (forward slash is always used
|
||||||
* to isolate them from the rest of the files in the classpath. This
|
* to separate path elements).
|
||||||
* is not a platform dependent path (forward slash is always used to
|
|
||||||
* separate path elements).
|
|
||||||
*/
|
*/
|
||||||
public ResourceManager (String resourceRoot)
|
public ResourceManager (String resourceRoot)
|
||||||
{
|
{
|
||||||
@@ -178,9 +166,16 @@ public class ResourceManager
|
|||||||
|
|
||||||
// get our resource directory from resource_dir if possible
|
// get our resource directory from resource_dir if possible
|
||||||
initResourceDir(null);
|
initResourceDir(null);
|
||||||
|
}
|
||||||
|
|
||||||
// set up a URL handler so that things can be loaded via urls
|
/**
|
||||||
// with the 'resource' protocol
|
* Registers a protocol handler with URL to handle <code>resource:</code> URLs. The URLs take
|
||||||
|
* the form: <pre>resource://bundle_name/resource_path</pre> Resources from the default bundle
|
||||||
|
* can be loaded via: <pre>resource:///resource_path</pre>
|
||||||
|
*/
|
||||||
|
public void activateResourceProtocol ()
|
||||||
|
{
|
||||||
|
// set up a URL handler so that things can be loaded via urls with the 'resource' protocol
|
||||||
try {
|
try {
|
||||||
AccessController.doPrivileged(new PrivilegedAction() {
|
AccessController.doPrivileged(new PrivilegedAction() {
|
||||||
public Object run () {
|
public Object run () {
|
||||||
@@ -201,6 +196,16 @@ public class ResourceManager
|
|||||||
_localePrefix = prefix;
|
_localePrefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures whether we unpack our resource bundles or not. This must be called before {@link
|
||||||
|
* #initBundles}. One can also pass the <code>-Dno_unpack_resources=true</code> system property
|
||||||
|
* to disable resource unpacking.
|
||||||
|
*/
|
||||||
|
public void setUnpackResources (boolean unpackResources)
|
||||||
|
{
|
||||||
|
_unpack = unpackResources;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the bundle sets to be made available by this resource
|
* Initializes the bundle sets to be made available by this resource
|
||||||
* manager. Applications that wish to make use of resource bundles
|
* manager. Applications that wish to make use of resource bundles
|
||||||
@@ -221,8 +226,7 @@ public class ResourceManager
|
|||||||
* @exception IOException thrown if we are unable to read our resource
|
* @exception IOException thrown if we are unable to read our resource
|
||||||
* manager configuration.
|
* manager configuration.
|
||||||
*/
|
*/
|
||||||
public void initBundles (
|
public void initBundles (String resourceDir, String configPath, InitObserver initObs)
|
||||||
String resourceDir, String configPath, InitObserver initObs)
|
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// reinitialize our resource dir if it was specified
|
// reinitialize our resource dir if it was specified
|
||||||
@@ -230,11 +234,6 @@ public class ResourceManager
|
|||||||
initResourceDir(resourceDir);
|
initResourceDir(resourceDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if we're in developer mode in which case we won't
|
|
||||||
// unpack our resources
|
|
||||||
_unpack = !"true".equalsIgnoreCase(
|
|
||||||
System.getProperty("no_unpack_resources"));
|
|
||||||
|
|
||||||
// load up our configuration
|
// load up our configuration
|
||||||
Properties config = new Properties();
|
Properties config = new Properties();
|
||||||
try {
|
try {
|
||||||
@@ -331,8 +330,7 @@ public class ResourceManager
|
|||||||
public boolean checkBundle (String path)
|
public boolean checkBundle (String path)
|
||||||
{
|
{
|
||||||
File bfile = getResourceFile(path);
|
File bfile = getResourceFile(path);
|
||||||
return (bfile == null) ? false :
|
return (bfile == null) ? false : new ResourceBundle(bfile, true, _unpack).isUnpacked();
|
||||||
new ResourceBundle(bfile, true, _unpack).isUnpacked();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -667,8 +665,7 @@ public class ResourceManager
|
|||||||
|
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
String path = tok.nextToken().trim();
|
String path = tok.nextToken().trim();
|
||||||
ResourceBundle bundle =
|
ResourceBundle bundle = new ResourceBundle(getResourceFile(path), true, _unpack);
|
||||||
new ResourceBundle(getResourceFile(path), true, _unpack);
|
|
||||||
set.add(bundle);
|
set.add(bundle);
|
||||||
if (bundle.isUnpacked() && bundle.sourceIsReady()) {
|
if (bundle.isUnpacked() && bundle.sourceIsReady()) {
|
||||||
continue;
|
continue;
|
||||||
@@ -740,7 +737,7 @@ public class ResourceManager
|
|||||||
protected String _rootPath;
|
protected String _rootPath;
|
||||||
|
|
||||||
/** Whether or not to unpack our resource bundles. */
|
/** Whether or not to unpack our resource bundles. */
|
||||||
protected boolean _unpack;
|
protected boolean _unpack = Boolean.getBoolean("no_unpack_resources");
|
||||||
|
|
||||||
/** Our default resource set. */
|
/** Our default resource set. */
|
||||||
protected ResourceBundle[] _default = new ResourceBundle[0];
|
protected ResourceBundle[] _default = new ResourceBundle[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user