com.sas.net
Class AppletResourceLocator

java.lang.Object
  |
  +--com.sas.net.BaseResourceLocator
        |
        +--com.sas.net.AppletResourceLocator
All Implemented Interfaces:
ResourceLocatorInterface,

public class AppletResourceLocator
extends BaseResourceLocator
implements ResourceLocatorInterface

The AppletResourceLocator is used to locate any type of resources relative to an applet, whether the resource wanted is an image file or a webEIS document. By default, the applet the resource is relative to is the applet returned from GlobalInfoTable.getApplet() and is relative to the code base of the applet. The resource name should be the relative path and filename of the resource.

Creating a AppletResourceLocator

A valid instance is created by instantiating an object of AppletResourceLocator followed by setting relative resource name.

 AppletResourceLocator appletResourceLocator1 = new AppletResourceLocator();
 appletResourceLocator1.setResourceName("apple.gif"); //assumes apple.gif is in the applet's direcotry
 

If the resource is in a sub-directory of from the applet, then you will need to pass in the sub-directory plus the filename name to the setResourceName call

 AppletResourceLocator appletResourceLocator1 = new AppletResourceLocator();
 appletResourceLocator1.setResourceName("resource\images\apple.gif"); 
 
If the resource is relative to the document base of the applet, then you will need to call setDocumentBaseRelative(true).
 AppletResourceLocator appletResourceLocator1 = new AppletResourceLocator();
 appletResourceLocator1.setDocumentBaseRelative(true);
 appletResourceLocator1.setResourceName("images\apple.gif"); 
 

A call to getResource() will return the URL of the resource if it can be found.

 try {
 	java.net.URL url = appletResourceLocator1.getResource(); 
 } catch (java.net.MalformedURLException ex)
 {
 //an error occurred while forming the URL, handle as needed
 }
 

See Also:
Serialized Form

Field Summary
protected  Applet _applet
          The applet the resource is relative to, null if the applet cannot be found.
protected  boolean _isCodeBaseRelative
          Whether to find the resource relative to the code base that is set on the applet
protected  boolean _isDocumentBaseRelative
          Whether to find the resource relative to the document base that is set on the applet
 
Fields inherited from class com.sas.net.BaseResourceLocator
_pcs, _resource, RUNTIME, WEBAF, WEBEIS
 
Constructor Summary
AppletResourceLocator()
          Default Constructor.
AppletResourceLocator(String resourceName)
          Sets the name of the resource.
 
Method Summary
protected  ResourceLocatorInterface createInstance(String resource)
          Creates a AppletResourceLocator from the string passed in.
static ResourceLocatorInterface decode(String resource)
          Creates a AppletResourceLocator from the string passed in.
 String encode()
          Returns a string representation of the AppletResourceLocator that can be used with decode(String) to create a new AppletResourceLocator with the same resource name and Applet.
 String getAbsolutePath()
          Returns the absolute path of the resource.
 Applet getApplet()
          Returns the applet that the resource is relative to.
 String getProjectDirectory()
          Returns the directory where the applet is located, so that the resource can be found relative to it.
 String getRelativePath()
          Convenience method, returns the resource name.
 URL getResource()
          Returns a URL of the resource.
 boolean isCodeBaseRelative()
          Whether to locate the resource relative to the code base of the applet.
 boolean isDocumentBaseRelative()
          Whether to locate the resource relative to the document base of the applet.
 void setApplet(Applet newValue)
          Sets the applet to locate the resource relative to.
 void setCodeBaseRelative(boolean newValue)
          Sets whether the AppletResourceLocator should try to locate the resource relative to the code base or not.
 void setDocumentBaseRelative(boolean newValue)
          Sets whether the AppletResourceLocator should try to locate the resource relative to the document base or not.
 
Methods inherited from class com.sas.net.BaseResourceLocator
addPropertyChangeListener, addPropertyChangeListener, clone, equals, firePropertyChange, firePropertyChange, getMode, getResourceLocator, getResourceName, removePropertyChangeListener, removePropertyChangeListener, setResourceName, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sas.net.ResourceLocatorInterface
getResourceName, setResourceName
 

Field Detail

_applet

protected Applet _applet
The applet the resource is relative to, null if the applet cannot be found.

_isDocumentBaseRelative

protected boolean _isDocumentBaseRelative
Whether to find the resource relative to the document base that is set on the applet

_isCodeBaseRelative

protected boolean _isCodeBaseRelative
Whether to find the resource relative to the code base that is set on the applet
Constructor Detail

AppletResourceLocator

public AppletResourceLocator()
Default Constructor. Sets the AppletResourceLocator to look for the resource relative to the code base.

AppletResourceLocator

public AppletResourceLocator(String resourceName)
Sets the name of the resource. The resourceName should be a realtive path to the resource. Sets the AppletResourceLocator to look for the resource relative to the code base.
Parameters:
resourceName - the relative path and name of the resource to locate
Method Detail

getApplet

public Applet getApplet()
Returns the applet that the resource is relative to. This method calls GlobalInfoTable.getObject() to find the applet, unless the user has set the applet themselves.
Returns:
the applet the resource is relative to, by default, it is relative to GlobalInfoTable.getObject(). The applet is only set on the GlobalInfoTable when the applet is running. At design-time, the applet will not be set on the GlobalInfoTable.
See Also:
GlobalInfoTable.getObject(), setApplet(Applet)

setApplet

public void setApplet(Applet newValue)
Sets the applet to locate the resource relative to. If this method is called, the AppletResourceLocator will not use the applet returned from GlobalInfoTable.getApplet() to locate the resource.
Parameters:
newValue - the applet the resource is relative to
See Also:
GlobalInfoTable.getApplet(), getApplet()

isDocumentBaseRelative

public boolean isDocumentBaseRelative()
Whether to locate the resource relative to the document base of the applet. The AppletResourceLocator can only be document base relative or code base relative, not both.
Returns:
true if the resource is relative to the document base of the applet, false otherwise
See Also:
setDocumentBaseRelative(boolean), isCodeBaseRelative()

setDocumentBaseRelative

public void setDocumentBaseRelative(boolean newValue)
Sets whether the AppletResourceLocator should try to locate the resource relative to the document base or not. If true is passed in, a call to setCodeBaseRelative(false) will be made as the AppletResourceLocator cannot be both relative to the document base and code base.
Parameters:
true - if the resource is relative to the document base of the applet, false otherwise
See Also:
isDocumentBaseRelative(), setCodeBaseRelative(boolean)

isCodeBaseRelative

public boolean isCodeBaseRelative()
Whether to locate the resource relative to the code base of the applet. The AppletResourceLocator can only be code base relative or document base relative, not both.
Returns:
true if the resource is relative to the code base of the applet, false otherwise
See Also:
setCodeBaseRelative(boolean), isDocumentBaseRelative()

setCodeBaseRelative

public void setCodeBaseRelative(boolean newValue)
Sets whether the AppletResourceLocator should try to locate the resource relative to the code base or not. If true is passed in, a call to setDocumentBaseRelative(false) will be made as the AppletResourceLocator cannot be both relative to the code base and document base.
Parameters:
true - if the resource is relative to the code base of the applet, false otherwise
See Also:
isCodeBaseRelative(), setDocumentBaseRelative(boolean)

getResource

public URL getResource()
                throws MalformedURLException
Returns a URL of the resource. A null URL will be returned if the resource cannot be found relative to the applet or if an error occurs. A MalformedURLException will be thrown if the construction of the URL fails.
Specified by:
getResource in interface ResourceLocatorInterface
Overrides:
getResource in class BaseResourceLocator
Returns:
the url of the resource, or null if an error occurred or the resource cold not be found
See Also:
URL, MalformedURLException

encode

public String encode()
Returns a string representation of the AppletResourceLocator that can be used with decode(String) to create a new AppletResourceLocator with the same resource name and Applet.
Overrides:
encode in class BaseResourceLocator
Returns:
a string formatted "Applet: ~~ ~~ ~~", where the resource name is a path relative to the resource. The Applet is the applet the resource is relative to. The "code, document, or neither" tells whether the resource is relative based on code base, document base, or neither.
See Also:
decode(String), URL

decode

public static ResourceLocatorInterface decode(String resource)
Creates a AppletResourceLocator from the string passed in. The string should in the same format as the the string returned from encode().
Parameters:
resource - a string the should be in the format "Applet: ~~ ~~ ~~", where the resource name is a path relative to the resource. The Applet is the applet the resource is relative to. The "code, document, or neither" tells whether the resource is relative based on code base, document base, or neither.
Returns:
an instance of a ResourceLocatorInterface if one can be created, null otherwise
See Also:
encode(), URL

createInstance

protected ResourceLocatorInterface createInstance(String resource)
Creates a AppletResourceLocator from the string passed in. The string should in the same format as the the string returned from encode(). This method just calls the static method decode(Strng).
Overrides:
createInstance in class BaseResourceLocator
Parameters:
resource - a string the should be in the format "Applet: ~~ ~~ ~~", where the resource name is a path relative to the resource. The Applet is the applet the resource is relative to. The "code, document, or neither" tells whether the resource is relative based on code base, document base, or neither.
Returns:
an instance of a ResourceLocatorInterface if one can be created, null otherwise
See Also:
encode(), decode(String)

getRelativePath

public String getRelativePath()
Convenience method, returns the resource name. Will return the same value as getResource().
Returns:
the relative path to the resource

getAbsolutePath

public String getAbsolutePath()
Returns the absolute path of the resource. This method will create the full path to the resource. It calls getProjectDirectory() to determine where the resource is.
Returns:
the absolute file path to the resource
See Also:
getProjectDirectory()

getProjectDirectory

public String getProjectDirectory()
Returns the directory where the applet is located, so that the resource can be found relative to it.
Overrides:
getProjectDirectory in class BaseResourceLocator
Returns:
a string representation of the directory where the applet is located. Used to find the resource relative to the directory this method returns.




Copyright © 2005 SAS Institute Inc. All Rights Reserved.
javadoc generated Thu, 16 Feb 2006 02:04:12