FileDocCategorySizeDatePackage
ResourceHandler.javaAPI DocphoneME MR2 API (J2ME)5964Wed May 02 18:00:34 BST 2007com.sun.perseus.platform

ResourceHandler

public final class ResourceHandler extends Object
This class provides a way to securely access platform resources. On some versions of the Java platform, there is a need to specify a security token to access resources. This allows different versions of the security features.
version
$Id: ResourceHandler.java,v 1.5 2006/07/17 00:35:44 st125089 Exp $

Fields Summary
private static final String
DEFAULT_FONT_FACE_FILE
Location of the default font face resource file
private static final String
INITIAL_FONT_FACE_FILE
Location of the intial font face resource file
private static com.sun.midp.security.SecurityToken
securityToken
Constructors Summary
private ResourceHandler()
Don't allow instances to be created.


     
        try {
            securityToken = 
                com.sun.midp.security.SecurityInitializer.requestToken(new SecurityTrusted());
        } catch (SecurityException se) {
            // Just log the error. This may happen in development context
            // when running a midlet which bundles the SVG engine.
            se.printStackTrace();
        } catch (NoClassDefFoundError e) {
            // Just log the error. This may happen in development context
            // when running a midlet which bundles the SVG engine.
            e.printStackTrace();
        }
    
    
Methods Summary
public static final java.io.InputStreamgetDefaultFontResource()

        InputStream is = null;

        try {
            is = getSystemResource(DEFAULT_FONT_FACE_FILE, securityToken);
        } catch (SecurityException se) {
            //log security exceptions
            se.printStackTrace();
        }

        return is;
    
public static final java.io.InputStreamgetInitialFontResource()

        InputStream is = null;
        
        try {
            is = getSystemResource(INITIAL_FONT_FACE_FILE, securityToken);
        } catch (SecurityException se) {
            //log security exceptions
            se.printStackTrace();
        }

        return is;
    
private static java.io.InputStreamgetSystemResource(java.lang.String resourceName, java.lang.Object securityToken)

param
resourceName the name of the resource to be retrieved. This has the same semantic and syntax as the java.lang.Class#getrResourceAsStream's name parameter.
param
securityToken opaque object which the caller must provide to grant access to the system resource. Note that on some platform, this securityToken is ignored because the access to the platform resources are secured through other mechanisms.
return
null if the resource is not found. Otherwise, an stream to the requested resource.

        if (securityToken == null) {
            return ResourceHandler.class.getResourceAsStream(resourceName);
        } else {
            InputStream is = null;
            RandomAccessStream storage =
                new RandomAccessStream((SecurityToken) securityToken);

            try {
                // extract the file name part of the full resource name
                int namePartIdx = resourceName.lastIndexOf('/");
                String namePart = (namePartIdx != -1) ?
                    resourceName.substring(namePartIdx + 1) : resourceName;
                storage.connect(File.getConfigRoot(
                    Constants.INTERNAL_STORAGE_ID) + namePart,
                    Connector.READ);
                byte[] data = new byte[storage.getSizeOf()];
                storage.readBytes(data, 0, data.length);
                is = new ByteArrayInputStream(data);
            } catch (IOException e) {
                System.out.println("Error in getSystemResource");
            } finally {
                try {
                    storage.disconnect();
                } catch (IOException ignored) {
                }
            }
            return is;
        }