|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ptc.windchill.cadx.common.preference.URLUtilities
Purpose: URLUtilities is a utility class for opening Web Server-based data streams from applets and / or applications. Its four main methods are newInputStream(String), newInputStream(URL), newReader(String) and newReader(URL). This provides the developer with access to input streams or readers (as desired) from either a URL or a String representation of a URL.
The utility setup methods in this class allow the developer to control the open behaviors. The developer can choose to allow the class to cache all userIDs and passwords for future use (setDefaultUseCache and setUseCache). The devloper can choose to allow a popup dialog to be used whenever an HTTP 401 error occurs (setDefaultAllowUserInteraction and setAllowUserInteraction). The difference between setX and setDefaultX is that setX will only apply to the next use of any of the main methods. Before terminating, the default settings are restored to the class instance. The final utility setup method is setPersistCache. This allows the developer to have the cache stored for future use. Note that cache persistence is not yet implemented so this method has no effect.
It is intended that this class be used with a particular user's session (as in a servlet or an application), so it does not implement anything as static to insure separate URLUtilities instances can be generated for each desired session. In an application, it would be expected that the developer would instantiate only one copy of this class to insure that the user only authenticates to a given host:port combination only one time. Note, that if cache persistence is implemented and used, it is possible that no authentication would be needed at all.
When used with application code, this class will allow authentication dialogs to be presented to the user. When used with server-side behavior, like a servlet, the developer can suppress the dialog and instead, use the connection utility methods to set the authorization string for the connection. These connection utility methods include setUserID(String), setPassword(String) and setAuthorization(String). The developer can either use setAuthorization to copy existing credentials to the web server or generate new ones via setUserID and setPassword. Note that the use of either setUserID or setPassword will destroy the current credentials set via setAuthorization. Note also, that the use of any of these routines will cancel the use of cached information for that particular main method call. Note that this class is marked final to insure that no one extends it for the specific purpose of retrieving the set of cached passwords.
Field Summary | |
protected URL |
absoluteBase
|
private boolean |
allowUserInteraction
|
private String |
authorization
|
private Hashtable |
connectionCache
|
private boolean |
defaultAllowUserInteraction
|
private boolean |
defaultUseCache
|
private URLAuthenticateDialog |
dlg
|
private static int |
maxTries
|
private String |
password
|
private boolean |
persistCache
|
protected URL |
relativeBase
|
private boolean |
useCache
|
private String |
userID
|
Constructor Summary | |
URLUtilities()
URLUtilities constructor comment. |
Method Summary | |
private void |
checkCache(URL url)
Purpose: retrieves the ID and password for a given host:port combination from the cache. |
private void |
cleanup()
Purpose: resets internal values after each use of a newXXX method call. |
private String |
generateCacheKey(URL url)
Purpose: Generates a cacheID string based on the URL's host and port number. |
URL |
getAbsoluteBase()
Purpose: |
boolean |
getAllowUserInteraction()
Purpose: Returns the current main method setting for whether the popup dialogs are allowed (true) or not (false). |
boolean |
getDefaultAllowUserInteraction()
Purpose: Shows the default value for user interactions. |
boolean |
getDefaultUseCache()
Purpose: Shows the default for the use of the class' internal cache. |
boolean |
getPersistCache()
Purpose: Shows whether this class will update a local copy of the cache (true) or not (false). |
URL |
getRelativeBase()
Purpose: |
boolean |
getUseCache()
Purpose: Shows whether caching is in effect (true) or not (false) for the next newXXX call. |
private void |
loadCache()
Purpose: Creates a cache when needed. |
static void |
main(String[] args)
Starts the application. |
InputStream |
newInputStream(String urlName)
Purpose: Creates a new InputStream object for the URL represented by the urlName String argument. |
InputStream |
newInputStream(URL url)
Purpose: Creates an InputStream object from a URL. |
Reader |
newReader(String urlName)
Purpose: Creates a new Reader object from the URL represented by the string argument. |
Reader |
newReader(URL url)
Purpose: Creates a new Reader object from the URL specified. |
void |
setAllowUserInteraction(boolean newValue)
Purpose: Sets the User Interaction behavior. |
void |
setAuthorization(String newValue)
Purpose: This routine will set a specific Basic authentication string for the next newXXX call. |
void |
setDefaultAllowUserInteraction(boolean newValue)
Purpose: When set to true, all future uses of newXXX will allow (true) or disallow (false) the use of any dialogs to acquire authentication information from the user. |
void |
setDefaultUseCache(boolean newValue)
Purpose: Sets the default caching behavior for this class. |
void |
setDocumentBase(String newValue)
Purpose: |
void |
setDocumentBase(URL newValue)
Purpose: |
void |
setPassword(String newValue)
Purpose: Sets the password for the upcoming newXXX method call. |
void |
setPersistCache(boolean newValue)
Purpose: Enables or disables the use of cache persistence. |
void |
setUseCache(boolean newValue)
Purpose: Enables or disables the use of the ID / password cache for the next newXXX method call. |
void |
setUserID(String newValue)
Purpose: Sets the user ID for the upcoming newXXX method call. |
private void |
updateAuthorization()
Purpose: Creates the Basic Authentication string from the already existing userID and password fields. |
private void |
updateCache(URL url)
Purpose: Updates the cache if it is permitted by the setting in getUseCache(). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private String userID
private String password
private String authorization
private URLAuthenticateDialog dlg
private static final int maxTries
private boolean allowUserInteraction
private boolean defaultAllowUserInteraction
private boolean useCache
private boolean defaultUseCache
private boolean persistCache
private Hashtable connectionCache
protected URL absoluteBase
protected URL relativeBase
Constructor Detail |
public URLUtilities()
Method Detail |
private void checkCache(URL url)
url
- java.net.URLprivate void cleanup()
private String generateCacheKey(URL url)
url
- java.net.URL
public URL getAbsoluteBase()
public boolean getAllowUserInteraction()
public boolean getDefaultAllowUserInteraction()
public boolean getDefaultUseCache()
public boolean getPersistCache()
This currently does nothing. No cache persistence has been implemented.
public URL getRelativeBase()
public boolean getUseCache()
private void loadCache()
public static void main(String[] args)
args
- an array of command-line argumentspublic InputStream newInputStream(String urlName) throws MalformedURLException, IOException
urlName
- java.lang.String
MalformedURLException
- when the string does not represent a valid URL
IOException
- on any error from the web server. Note that the exception will include the response
code as well as the response message from the web server in the exception data.newInputStream(String urlName)
public InputStream newInputStream(URL url) throws IOException, UnauthenticatedURLException
This is the primary main method call. newInputStream(String), newReader(URL) and newReader(String) are convenience wrappers around this method call.
url
- java.net.URL
IOException
- on any error from the web server. Note that the exception will include the response
code as well as the response message from the web server in the exception data.
UnauthenticatedURLException
public Reader newReader(String urlName) throws MalformedURLException, IOException
urlName
- java.lang.String
MalformedURLException
- when the string does not represent a valid URL
IOException
- on any error from the web server. Note that the exception will include the response
code as well as the response message from the web server in the exception data.newInputStream(String urlName)
public Reader newReader(URL url) throws IOException
url
- java.net.URL
IOException
- on any error from the web server. Note that the exception will include the response
code as well as the response message from the web server in the exception data.newInputStream(String urlName)
public void setAllowUserInteraction(boolean newValue)
newValue
- booleanpublic void setAuthorization(String newValue)
newValue
- java.lang.Stringpublic void setDefaultAllowUserInteraction(boolean newValue)
newValue
- booleanpublic void setDefaultUseCache(boolean newValue)
newValue
- booleanpublic void setDocumentBase(String newValue)
newValue
- java.lang.Stringpublic void setDocumentBase(URL newValue)
newValue
- java.lang.Stringpublic void setPassword(String newValue)
setPassword
in interface URLAuthenticationListener
newValue
- java.lang.Stringpublic void setPersistCache(boolean newValue)
Note that this currently has no effect as the actual read / write of the cache is not yet implemented.
newValue
- booleanpublic void setUseCache(boolean newValue)
newValue
- booleanpublic void setUserID(String newValue)
setUserID
in interface URLAuthenticationListener
newValue
- java.lang.Stringprivate void updateAuthorization()
private void updateCache(URL url)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |