|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectwt.httpgw.URLFactory
public final class URLFactory
A URL and HREF factory for Windchill application resources.
Instances are capable of generating URL objects or HREF strings to resources in a particular Windchill system. Each instance corresponds to one Windchill system from which URL mappings are obtained. Each factory instance has an optional request URI from which relative HREF strings are generated. If no request URI is set, only absolute HREFs are returned. Each system has a base URL corresponding to the application's virtual directory root. Resources are requested using paths relative to this base URL (e.g. wt/clients/images/myimage.jpg).
Instances are constructed given a codebase URL for a Windchill system. This URL is any URL that can be used to download configuration files corresponding to the desired system. Configuration files (e.g. wt.properties, urlmap.properties) from the server codebase are used to determine the system's base URL and any URL mappings that may apply to certain resources. The base URL for a system may be different than the server codebase URL used to construct the factory.
URL mappings allow Windchill administrators to override the location of specific resources such as files, directories, or servlets which are otherwise located relative to the system's base URL. Mappings may override the entire URL or just specific components such as protocol, host, port, or path.
Typiccal usage in a JSP is to instantiate using the no-arg constructor, set the
requestURI property from the servlet request, generate a HTML getBaseHREF() method,
then reset the factory's request URI to the application root using the
setRequestUri method with the same value.
Resource-specific helper methods can be created which encapsulate the URL and HREF generating methods within methods that are more meaningful to the target resource. For example, a servlet that uses path info elements and/or query string parameters in a well defined way can be exposed factory methods that have more meaningful arguments. These helper methods should accept an instance of a URL factory as input along with the resource-specific arguments.
NOTE: Instances of a URL factory are not thread safe. Each instance contains buffers that may be reused when encoding URLs.
Mapping File
(UL)The mapping file will consist of a series of key/value pairs separated by the '=' character.
Further '=' characters will be left as part of the value part of the pair. Comments may be
inserted into the file by using the '#' character and blank lines will be ignored. The default
Windchill file for URL Mappings is the file urlmap.properties located in the
Windchill codebase directory.
Mapping Rules
Protocol://hostname:port/windchill-codebase/package-path/resource | Will map the resource to a specific resource, located in a Windchill codebase and package path on the hostname's server, through a specified protocol and port. |
Protocol://hostname:port/windchill-codebase/package-path/ | will map the package to a specific package path and Windchill codebase, located on hostname's server, through a specified protocol and port. |
Protocol://hostname/windchill-codebase/package-path/resource | will map the resource to a specific windchill codeebase and package path, located on a hostname's server, through a specified protocol. The port will be retrieved from URLFactory. |
Protocol://hostname/windchill-codebase/package-path/ | will map the package path to a specific windchill codebase and package path, located on hostname's server, through a specified protocol. The port will be retrieved from the URLFactory. |
://hostname | Will map the resource to a new hostname maintaining the same protocol, port windchill codebase and package path. |
://hostname:port | Will map the resource to a new hostname and port maintaining the same protocol codebase and package path. |
://hostname/windchill-codebase/package-path/ | Will map the resource to a new hostname, Windchill codebase and package path using the same port and protocol |
://hostname:port/windchill-codebase/package-path/ | Will map the resource to a new hostname port and windchill codebase/package path using the same protocol |
://:port/windchill-codebase/package-path/ | Will map the resource to a new port on the same host with a new path to the Windchill codebase and package path. |
://:port/windchill-codebase/package-path/resource | Will map the resource to a new port and resource path (including Windchill codebase) |
/package-path/ | Will remap a given package path to new package path including the Windchill codebase, while maintaining the same protocol, port and hostname of the current Windchill server. (se examples below) |
package-path/ | Will remap a given package path to a new package path using the current Windchill codebase, while maintaining the same protocol, port and hostname of the current Windchill server. (see examples below) |
/package-path/resource | Will remap a given resource to a new Windchill codebase and package path as defined while maintaining the same protocol, port and hostname of the current Windchill server. |
package-path/resource | Will remap a given resource to a new package path utilizing the same Windchill codebase while maintaining the same protocol, port and hostname of the current Windchill server. |
Supported API: true
Extendable: false
| Constructor Summary | |
|---|---|
URLFactory()
Construct a URL factory for the default (local) server system. |
|
URLFactory(URL server_codebase)
Construct a URL factory for a specified server system. |
|
| Method Summary | |
|---|---|
String |
determineResource(String aRequestPath)
This method will take a request resource path which may start with a '/' and determine from this the Windchill resource path based on the Windchill codebase being common between the URLFactory, and the requested resource path. |
String |
getBaseHREF()
This method will return the fully qualified path to the Windchill Codebase. |
String |
getBaseHREFFromRequestURI()
Get the HREF which represents the path from the current Request URI to the Windchill codebase. |
URL |
getBaseURL()
Get base URL for the referenced Windchill system as a URL object. |
String |
getEncoding()
Get the character encoding used to encode character to octets before the are hex escaped into generated URLs or HREFs. |
String |
getFullyQualifiedRequestURI()
This method will get the Fully Qualified Request URI returning the Protocol://Hostname[:Port]/[PackagePath/][Resource][?QueryString]
. |
String |
getHREF(String resource)
Generate a HREF string to the identified resource. |
String |
getHREF(String resource,
boolean fullyQualified)
Generate a HREF string to the identified resource. |
String |
getHREF(String resource,
HashMap params)
Generate a HREF string to the identified resource. |
String |
getHREF(String resource,
HashMap params,
boolean fullyQualified)
Generate a HREF string to the identified resource. |
String |
getHREF(String resource,
String query_string)
Generate a HREF string to the identified resource. |
String |
getHREF(String resource,
String params,
boolean fullyQualified)
Generate a HREF string to the identified resource. |
String |
getRequestURI()
Get the request URI of this factory. |
URL |
getURL(String resource)
Generate a URL to the identified resource. |
URL |
getURL(String resource,
HashMap params)
Generate a URL object to the identified resource. |
URL |
getURL(String resource,
String query_string)
Generate a URL to the identified resource. |
HashMap |
parseQueryString(String query_string)
Parses a query string passed from the client to the server and builds a HashMap object with key-value pairs. |
void |
setEncoding(String encoding)
Set the character encoding used to encode characters to octets before they are hex escaped into generated URLs or HREFs. |
void |
setRequestURI(String request_uri)
Set the request URI of this factory. |
void |
setRequestURIFromURL(URL request_uri)
Set the request URI of this factory. |
String |
setRequestURItoBase()
Set the request URI for this factory to the Windchill Codebase of the URLFactory's Windchill system. |
void |
setRequestURL(String aScheme,
String aHostname,
String aRequest_URI)
Set the request URL for this factory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public URLFactory()
throws WTException
Supported API: true
WTException
public URLFactory(URL server_codebase)
throws WTException
For example:
http://host.domain:8080/Windchill/
server_codebase - codebase URL corresponding to the desired system.
WTException| Method Detail |
|---|
public void setRequestURIFromURL(URL request_uri)
Setting to a request URI will cause all generated HREFs to be relative to the
given request URI. Setting to null will force all generated HREFs to be fully
qualified.
Supported API: true
request_uri - request URI
public void setRequestURL(String aScheme,
String aHostname,
String aRequest_URI)
aScheme - The scheme for the URL ( for example https )aHostname - The hostname of the request. Some browsers may include
the port in this string. This method will accept this form
and parse the port successfully.aRequest_URI - The request uri for the request. This may be
relative or absolute.public String setRequestURItoBase()
public void setRequestURI(String request_uri)
throws NullPointerException
Setting to a request URI will cause all generated HREFs to be relative to the given request URI. Setting to null will force all generated HREFs to be fully qualified. The specified request URI may be fully qualified or relative to the current request URI. The rules follow those which are defined in the HTTP Specification for valid HREF formats. If there is no current request URI, relative URIs will be interpreted relative to the Windhcill codebase URL.
Notes: If a relative request_uri is passed in as an argument to
this method with the form
../[../]newpath/[resource][?query_string] the
../ much be a valid pathing relative to the current
Request URI. For example, if the current Request URI is equal to
/Windchill/wt/httpgw and this method is called with
../../../../directory this would be invalid and the Request
URI will not be changed. A NullPointerException will be thrown by the
method which can be used in the client to trap this exception.
Supported API: true
request_uri - request URI in string form to allow relative URI syntax
NullPointerException - Optional exception used to catch invalid
relative Request URI paths, or if a relative Request URI is desired and
the current Request URI is null.public String getRequestURI()
getFullyQualifiedRequestURI()public String getFullyQualifiedRequestURI()
Protocol://Hostname[:Port]/[PackagePath/][Resource][?QueryString]
. If the Request URI is null, null will be returned.
getRequestURI()public void setEncoding(String encoding)
encoding - character encoding namepublic String getEncoding()
public final URL getBaseURL()
public final String getBaseHREF()
getFullyQualifiedRequestURI()
should be used where possible to set the base tag relative to the current
Request URI and not the Windchill codebase.
@return The fully qualified base to the Windchill codebase.
public final String getBaseHREFFromRequestURI()
Note: This value should NOT be used to set HTML <BASE> tags. Use
getFullyQualifiedRequestURI() to get a fully qualified base
tag for the current Request URI.
Supported API: true
@see getFullyQualifiedRequestURI()
public final URL getURL(String resource)
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
resource - The resource path
public String determineResource(String aRequestPath)
request.getRequestURI( ) which will return an absolute resource
path, but there is a need to utilize the mapping file on the system.
aRequestPath - The request URI to resolve. If it does not start
with a '/' the the String will be returned.
public String getHREF(String resource,
boolean fullyQualified)
Path elements containing non-ASCII characters are encoded into bytes
and then URL encoded.
If request URI is set, this may return a relative HREF.
This method will return a fully qualified HREF. This should only is cases where a fully qualified HREF is required. For example, opening a new window using javascript.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param path resource path
fullyQualified - whether the HREF is to be fully qualified
(independent of URLFactory configuration)
public String getHREF(String resource)
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Path elements containing non-ASCII characters are encoded into bytes
and then URL encoded.
If request URI is set, this may return a relative HREF.
NOTE: This method is not thread safe. Do not share factory instances between threads.
Supported API: true
@param path resource path
public URL getURL(String resource,
String query_string)
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param resource The resource path
query_string - The query string to add to the URL
public String getHREF(String resource,
String params,
boolean fullyQualified)
Path elements and request parameters containing non-ASCII characters
that are already encoded.
If request URI is set, this may return a relative HREF.
This method will return a fully qualified HREF if the flag is true. This should only is cases where a fully qualified HREF is required. For example, opening a new window using javascript.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param path resource path
params - The list of Parameters already encodedfullyQualified - whether the HREF is to be fully qualified
(independent of URLFactory configuration)
public String getHREF(String resource,
String query_string)
Path elements and request parameters containing non-ASCII characters
that are already encoded.
If request URI is set, this may return a relative HREF.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param path resource path
query_string - The list of Parameters already encoded
public URL getURL(String resource,
HashMap params)
Path elements and request parameters containing non-ASCII characters
that are encoded within this method before returning.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param resource resource path
params - The hashmap on un-encoded parameters.
public String getHREF(String resource,
HashMap params,
boolean fullyQualified)
Path elements and request parameters containing non-ASCII characters
are encoded into bytes and then URL encoded. Parameter values should be strings
or arrays of strings for multi-valued parameters.
If request URI is set, this may return a relative HREF.
This method will return a fully qualified HREF if the flag is true. This should only is cases where a fully qualified HREF is required. For example, opening a new window using javascript.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param path resource path
params - The Hashmap of ParametersfullyQualified - whether the HREF is to be fully qualified
(independent of URLFactory configuration)
public String getHREF(String resource,
HashMap params)
Path elements and request parameters containing non-ASCII characters
are encoded into bytes and then URL encoded. Parameter values should be strings
or arrays of strings for multi-valued parameters.
If request URI is set, this may return a relative HREF.
NOTE: If usage of request.getRequestURI( ) is required, make sure
to pass the request through
determineResource(request.getRequestURI()); first, so that
the resource path relative to the Windchill System can be determined.
Failure to do so will not allow proper usage of the mapping file.
Thread Safe: true (Do not share factory instances between threads)
Supported API: true
@param path resource path
params - The hashmap of parameters.public HashMap parseQueryString(String query_string)
getURL and getHREF methods.
A key can appear more than once in the query string with different values. However, the key appears only once in the hashtable, with its value being an array of strings containing the multiple values sent by the query string.
The keys and values in the hashtable are stored in their decoded form, so an + characters are converted to spaces and any hex escaped octets are converted to bytes before the octet sequence is decoded into characters using the factory's current character encoding.
NOTE: This method is not thread safe. Do not share factory instances between threads.
Supported API: true
query_string - string containing encoded query string
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||