ilog.cpl.service
Class IlpDefaultURLAccessService

java.lang.Object
  extended by ilog.cpl.service.IlpDefaultURLAccessService
All Implemented Interfaces:
IlpService, IlpURLAccessService
Direct Known Subclasses:
IltDefaultURLAccessService

public class IlpDefaultURLAccessService
extends Object
implements IlpURLAccessService

This service is used for deploying applications and applets without hardcoding pathnames or URLs. It allows you to define a set of paths and jar files that will be searched when you want to access a file using a relative URL. It is used as an addition to Class.Loader.getResource to allow the use of an explicit search path as well as the Java classpath when deploying an application using CPL.

A possible use of this service is for accessing icons and configuration files.

This default implementation uses one base URL that is usually defined according to the deployment mode. Applets use setDocumentBase to register their base URL. Applications can use setDocumentBase as well, but do not need to; by default, the current directory is used instead.

Additional paths can be added to the locations where a given filename will be searched for:

To retrieve the absolute URL of a file, call getFileLocation with a relative URL. This function will locate the file relative to the registered base URLs. For example, consider the following code:

 IlpDefaultURLAccessService accessService = new IltDefaultURLAccessService();
 accessService.setDocumentBase(new URL("file:C:/myfiles/"));
 accessService.addRelative("myname/");
 acesssService.addAbsolute(new URL("file://nfs/shared/resources/"));
 accessService.addRelative("my.jar");
 accessService.addAbsolute(new URL("file://nfs/shared/resources.jar"));
 
A call to getFileLocation("myresource") will return one of the following URLs:
 file:C:/myfiles/myname/myresource
 file://nfs/shared/resources/myresource
 jar:file:C:/myfiles/my.jar!/myresource
 jar:file://nfs/shared/resources.jar!/myresource
 

Since:
JTGO 3.0

Constructor Summary
IlpDefaultURLAccessService()
          Creates the service.
 
Method Summary
 void addAbsolute(URL pathOrJar)
          Adds an absolute directory or jar file specification to the search path.
 void addRelative(String pathOrJar)
          Adds a relative directory or jar file specification to the search path.
 List getBases()
          Returns the list of base URLs, ignoring syntactically invalid URLs.
static String getCurrentDirectory()
          Returns the current directory, or null if unavailable.
 URL getDocumentBase()
          Returns the document base.
 URL getFileLocation(String filename)
          Returns the URL of a file in the path or null if it is not found.
 URL getFileLocation(String filename, boolean searchClassPathFirst, boolean searchClassPathLast)
          Returns the URL of a file in the path, or null if it is not found.
static boolean isIgnoreSyntheticHttpURLs()
          Returns true if synthetic HTTP URLs are ignored by this service.
 void setDocumentBase(URL baseURL)
          Sets the document base.
static void setIgnoreSyntheticHttpURLs(boolean ignoreThem)
          Specifies whether synthetic HTTP URLs are ignored by this service.
 void setVerbose(boolean flag)
          Sets the verbosity of the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlpDefaultURLAccessService

public IlpDefaultURLAccessService()
Creates the service. By default, there is no document base and the current directory will be used as base for relative URLs.

Method Detail

getDocumentBase

public URL getDocumentBase()
Returns the document base.


setDocumentBase

public void setDocumentBase(URL baseURL)
Sets the document base.

The typical use in an applet is: context.setDocumentBase(getDocumentBase()). Applications do not need to call this function; by default, the current directory is used instead.


getCurrentDirectory

public static String getCurrentDirectory()
Returns the current directory, or null if unavailable.


addRelative

public void addRelative(String pathOrJar)
Adds a relative directory or jar file specification to the search path.

The empty string stands for the document base or, if none is set, in applications, for the current directory.

If the document base points into a jar file, a string starting with "!" denotes a pathname relative to the directory containing the jar file.

Parameters:
pathOrJar - A relative pathname to a directory or jar file. It uses '/' as directory separator, as in URLs. A prefix of "!" can be used to escape from the jar file containing the document base.

addAbsolute

public void addAbsolute(URL pathOrJar)
Adds an absolute directory or jar file specification to the search path.

Note: URLs that represent directories usually end with a slash (for the http: protocol) or in the directory separator character (for the file: protocol).


getBases

public List getBases()
Returns the list of base URLs, ignoring syntactically invalid URLs.


getFileLocation

public URL getFileLocation(String filename)
Returns the URL of a file in the path or null if it is not found. Each element of the file location path is tried in turn with the given relative filename. The first one that refers to an existing URL is returned.

Specified by:
getFileLocation in interface IlpURLAccessService
Parameters:
filename - A relative URL or pathname.

getFileLocation

public URL getFileLocation(String filename,
                           boolean searchClassPathFirst,
                           boolean searchClassPathLast)
Returns the URL of a file in the path, or null if it is not found.

First, if searchClassPathFirst is true, the CLASSPATH is searched. Then, in turn, each element of the file location path is tried with the given relative filename.

Finally, if searchClassPathLast is true, the CLASSPATH is searched. The first one that refers to an existing URL is returned.

Specified by:
getFileLocation in interface IlpURLAccessService
Parameters:
filename - A relative URL or pathname.
searchClassPathFirst - If true, the file shall be searched in the CLASSPATH (directories and jars) before the usual path.
searchClassPathLast - If true, the file shall be searched in the CLASSPATH (directories and jars) after the usual path.

isIgnoreSyntheticHttpURLs

public static boolean isIgnoreSyntheticHttpURLs()
Returns true if synthetic HTTP URLs are ignored by this service.


setIgnoreSyntheticHttpURLs

public static void setIgnoreSyntheticHttpURLs(boolean ignoreThem)
Specifies whether synthetic HTTP URLs are ignored by this service.

These are URLs that are not backed by a file, but are synthesized by the HTTP server on demand. Some HTTP servers synthesize some default HTML, containing an error message, for all URLs that do not correspond to existing files.

The default value of this setting is true.


setVerbose

public void setVerbose(boolean flag)
Sets the verbosity of the service.

Since:
JViews 7.5


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.