|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.httpgw.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
Field Summary | |
private static ThreadLocal |
alt_local_server
Thread localized list for the current alt server configuration |
static String |
ALT_SERVER_CODEBASE_PROPERTY
|
private static Hashtable |
cvMappings
Static hashmap of Mapped Properties |
private boolean |
isMapCodebase
cache and use the vailability of alt codebase |
private URL |
ivAltBaseURL
Alternate BaseURL. |
private URLData |
ivAltRefData
The Alternate URLData to the codebase |
private URL |
ivBaseURL
BaseURL. |
private boolean |
ivbFullyQualified
flag for the fully qualified URL setting |
private boolean |
ivbMapped
Whether this URLFactory has mapped settings. |
private EncodingConverter |
ivEncoder
|
private String |
ivEncoding
The string encoding for the URLFactory |
private ArrayList |
ivList
The List of mappings for a particular codebase |
private URLData |
ivRefData
The reference URLData to the codebase |
private URLData |
ivRequestURI
The request URI object |
private static ThreadLocal |
local_encoder
Thread localized encoder |
private static ThreadLocal |
local_server
Thread localized list for the current server configuration |
private static ThreadLocal |
local_servers
Thread localized list of server configurations |
static String |
MAPPING_FILENAME
|
private boolean |
noAltProtocol
whether the Request URL protocol takes precedence |
private static int |
STRINGBUFFER_SIZE
|
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 | |
private URLData |
buildServerURLData(URL aServerCodebase)
Will create a URLData object for the server codebase which is defined by the URL. |
private URLData |
buildURLData(String tvKey,
String tvValue,
URLData aRefData)
This will build an URLData object based on the Mapping String and it's key in coordination with a Reference Object. |
private String |
determineRelativeHREF(URLData aReference,
String aResource)
This method will determine the relative difference between a Reference URLData and a String resource |
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. |
private URLData |
findMapping(ArrayList aList,
String aKey)
Will return an URLData object that maps to a given key if the key or a partial key is found in the mapping list. |
private URLData |
findPartialMapping(ArrayList aList,
String aKey,
int anIndex)
This method will attempt to find a partial mapping for the given key by searching up the list toward the beginning looking for the first partial match. |
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. |
private TreeMap |
getURLMappings(TreeMap aMap,
URL CodebaseURL,
String aMappingFile)
This method will take a Properties Mapping (the server properties) along with an optional codebase and the napping file name to retrieve the mappings from the server (or local codebase) and add the mappings to the Properties Map. |
HashMap |
parseFormData(InputStream in)
Parses data from an HTML form that the client sends to the server using the HTTP POST method and the application/x-www-form-urlencoded MIME type. |
HashMap |
parseFormData(int len,
InputStream in)
Parses data from an HTML form that the client sends to the server using the HTTP POST method and the application/x-www-form-urlencoded MIME type. |
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. |
private String[] |
reverseTransform(String[] aData)
Reverse of the Above Will return the String[] input by replacing the packagepath elements of wt.server.codebase with packagepath elements from the wt.httpgw.mapCodebase |
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. |
private String |
transform(String aData)
Will return the URI input by replacing the packagepath with packagepath from the wt.server.codebase |
private String[] |
transform(String[] aData)
Will return the String[] input by replacing the packagepath elements of wt.httpgw.mapCodebase with packagepath elements from the wt.server.codebase |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static Hashtable cvMappings
private String ivEncoding
private static ThreadLocal local_encoder
private static ThreadLocal local_server
private static ThreadLocal local_servers
private static ThreadLocal alt_local_server
private ArrayList ivList
private URL ivBaseURL
private URL ivAltBaseURL
private URLData ivRefData
private URLData ivAltRefData
private URLData ivRequestURI
private boolean ivbFullyQualified
private boolean ivbMapped
private boolean isMapCodebase
private boolean noAltProtocol
private EncodingConverter ivEncoder
public static final String MAPPING_FILENAME
public static final String ALT_SERVER_CODEBASE_PROPERTY
private static final int STRINGBUFFER_SIZE
Constructor Detail |
public URLFactory() throws WTException
Supported API: true
public URLFactory(URL server_codebase) throws WTException
For example:
http://host.domain:8080/Windchill/
server_codebase
- codebase URL corresponding to the desired system.Method Detail |
private final URLData buildServerURLData(URL aServerCodebase)
protocol://host:port/Document-Root/
- Parameters:
aServerCodebase
- an URL to the codebase to reference
- Returns:
- The URLData for the server codebase.
private final URLData buildURLData(String tvKey, String tvValue, URLData aRefData)
tvKey
- The key to map.tvValue
- The mapping value to map to the keyaRefData
- The reference data object.
private TreeMap getURLMappings(TreeMap aMap, URL CodebaseURL, String aMappingFile) throws IOException
aMap
- The properties map to add the properties too.aMappingFile
- The mapping file name.
IOException
- If there was a problem obtaining the propertiespublic 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 URIpublic 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
private final String determineRelativeHREF(URLData aReference, String aResource)
aReference
- The reference URLData object.aResource
- The resource to look for.
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
public HashMap parseFormData(int len, InputStream in)
The data sent by the POST method contains key-value pairs. A key can appear more than once in the POST data with different values. However, the key appears only once in the hashmap, with its value being an array of strings containing the multiple values sent by the POST method.
The keys and values in the hashmap 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: false
len
- length of the input stream (-1 causes read to EOF or newline)in
- input stream to read
public HashMap parseFormData(InputStream in)
The data sent by the POST method contains key-value pairs. A key can appear more than once in the POST data with different values. However, the key appears only once in the hashmap, with its value being an array of strings containing the multiple values sent by the POST method.
The keys and values in the hashmap 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: false
in
- input stream to read
private URLData findPartialMapping(ArrayList aList, String aKey, int anIndex)
NOTE: As the search is backing off, any element that is a resource, ie. it ends without a '/' will be ignored, as an absolute mapping does not constitute a subset of the desired mapping.
aList
- The list of mappingsaKey
- The key to search foranIndex
- The starting index.
private URLData findMapping(ArrayList aList, String aKey)
aList
- The list of mapped items.aKey
- The key representing the item to search for
private String transform(String aData)
aData
- The input URI.
private String[] transform(String[] aData)
aData
- The input String[].
private String[] reverseTransform(String[] aData)
aData
- The input String[].
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |