Oracle Fusion Middleware Disc API Reference for Oracle WebLogic Portal
10g Release 3 (10.3.4)
E14257-04

Class UriRewriter


public class UriRewriter

Instances of the UriRewriter class provide the capability to parse a URI string from recognized javascript pseudo-protocol links. Such psuedo-protocol links are the result of client-side URL rewriting done by the DISC framework to support AJAX enabled portlets and desktops. Using a UriRewriter to instantiate a Uri, a user does not need foreknowledge about whether or not the URI has been rewritten by DISC. In this way, the same code can be used to transparently manipulate a URI whether or not it has been rewritten by DISC.

The UriRewriter classes provide a mechanism for manipulating target URIs for recognized proxy URIs, such as proxy URIs for remote portlets. This generic base class UriRewriter returns false for isProxyUri() and has a null proxy URI property but it does have a getTargetUri() method that provides access to the URI. This same method is used by subclasses, including those that really are proxy URIs. Therefore, the UriRewriterFactory can be used to select the proper UriRewriter for transparently rewriting a target URI.

The underlying proxy and target URIs for UriRewriter instances are instances of Uri

Note: URIs with entity-encoded ampersands (&) should not be passed to this API. It should rarely be necessary to handle URIs with entity-encoded ampersands in client code. A URI, such as one that comes from the value of the href attribute of an anchor tag, will contain no evidence of HTML entity-encoding after it is in memory in the client.

This base class is intended to be used as an abstract base class for implementing subclasses that understand how to get/set a target URI from a particular kind of proxy URI. Instead of instantiating this class to work with generic, non-proxy URIs you should use GenericUriRewriter. The class GenericUriRewriter extends this class.

See Also:
bea.wlp.disc.uri.Uri
bea.wlp.disc.uri.UriRewriterFactory

Field Summary
public static object[] JS_PSEUDO_PROTOCOL_REGEXES
            An array of objects containing regular expressions used to parse URIs out of links for all known JavaScript pseudoprotocol links.
public static object SERVICE_UPDATE_REGEX
            An object containing a RegExp property named regex and three integer properties named preBackRef, uriBackRef, and endBackRef.
public static object UPDATE_CONTENTS_REGEX
            An object similar to the UriRewriter.SERVICE_UPDATE_REGEX object.
Initializer Summary
UriRewriter(uriStr, [tmpltMap])
           Initializes this instance.
 
Method Summary
public string getFullUriString()
          Gets the string for the URI associated with this instance, including the prefix and suffix.
public bea.wlp.disc.uri.Uri getProxyUri()
          A Uri instance that represents the proxy URI.
public bea.wlp.disc.uri.Uri getTargetUri()
          Gets the target Uri associated with this instance.
public string getUriPrefix()
          Gets the prefix for the URI associated with this instance.
public string getUriSuffix()
          Gets the suffix for the URI associated with this instance.
public static boolean groksUri(uriStr, [tmpltMap])
          Determines if this class understands the given URI string well enough to work with it.
public boolean isProxyUri()
          Determines if the URI for this instance is a proxy URI that contains a target URI.
public object parseUriStrParts(uriStr)
          Parses the prefix, URI string, and suffix from recognized javascript pseudo-protocol links.
public void refreshTargetOnProxyUri()
          Sets the instance target URI as a parameter (or path or whatever) of the instance proxy URI.
public void setProxyUri(proxyUri)
          Sets the proxy URI for this instance.
public void setTargetUri(targetUri)
          Sets the target Uri associated with this instance.
public void setUriPrefix(prefix)
          Sets the prefix for the URI associated with this instance.
public void setUriSuffix(suffix)
          Sets the suffix for the URI associated with this instance.
public static object staticParseUriStrParts(uriStr)
          Parses the prefix, URI string, and suffix from recognized javascript pseudo-protocol links.
 
Field Detail

JS_PSEUDO_PROTOCOL_REGEXES

public static object[] JS_PSEUDO_PROTOCOL_REGEXES
An array of objects containing regular expressions used to parse URIs out of links for all known JavaScript pseudoprotocol links. The objects in this array are like the bea.wlp.disc.uri.UriRewriter.SERVICE_UPDATE_REGEX object

SERVICE_UPDATE_REGEX

public static object SERVICE_UPDATE_REGEX
An object containing a RegExp property named regex and three integer properties named preBackRef, uriBackRef, and endBackRef. The regex property is a regular expression for parsing javascript psuedo-protocol links that use the bea.wlp.disc.xie._Service.update() method. The three integer properties correspond to the indices of back references (parenthised subexpressions) in regex that contain the URI prefix, the URI string, and the URI suffix, respectively.

Here is an example of how this field could be used to parse a link:

		var match = myUriStr.match(UriRewriter.SERVICE_UPDATE_REGEX.regex);
		var uriPreStr, uriStr, uriEndStr;
		if ( match ) {							
			uriPreStr = match[UriRewriter.SERVICE_UPDATE_REGEX.preBackRef];
			uriStr = match[UriRewriter.SERVICE_UPDATE_REGEX.uriBackRef];
			uriEndStr = match[UriRewriter.SERVICE_UPDATE_REGEX.endBackRef];
		}
		
For example, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a prefix of
		javascript:bea.wlp.disc.xie._Service.update('
		
a URI string of
		http://www.oracle.com
		
and a suffix of
		');
		

UPDATE_CONTENTS_REGEX

public static object UPDATE_CONTENTS_REGEX
An object similar to the UriRewriter.SERVICE_UPDATE_REGEX object. This one is for parsing javascript psuedo-protocol links that use the bea.netuix.ajaxportlet.updateContents() method, e.g. the string
		javascript:bea.netuix.ajaxportlet.updateContents(%22my_portlet_label%22, %22http://www.oracle.com%22)
		
would have a prefix of
		javascript:bea.netuix.ajaxportlet.updateContents(%22my_portlet_label%22, %22
		
a URI string of
		http://www.oracle.com
		
and a suffix of
		%22)
		

Initializer Detail

UriRewriter

public UriRewriter(uriStr, [tmpltMap])
Initializes this instance.

If the constructor is invoked as a no-arg constructor or with a null uriStr then the target URI will be set to an empty Uri instance.

The optional tmpltMap argument must be provided if the uriStr argument is a templatized URI string. This constructor will perform template replacement prior to attempting to parse the URI string. This allows it to more reliably parse the string into a URI.

Template keys are enclosed in curly braces, i.e., {myKey}. A templatized URI string such as:

	{protocol}://www.oracle.com/products?id={productId}
could have its template keys replaced by using a tmpltMap argument such as
	{protocol:'http', productId:'1001'}
This would result in
http://www.oracle.com/products?id=1001
This base class is intended to be used as an abstract base class for implementing subclasses that understand how to get/set a target URI from a particular kind of proxy URI. Instead of instantiating this class to work with generic, non-proxy URIs you should use GenericUriRewriter. The class GenericUriRewriter extends this class.
Parameters:
uriStr - The string form of the URI
[tmpltMap] - An optional map of template key/values, e.g., {protocol:'http', productId:'1001'}. This argument is required if the uriStr argument is templatized.
Method Detail

getFullUriString

public string getFullUriString() 
Gets the string for the URI associated with this instance, including the prefix and suffix. A prefix/suffix are most likely to be used for a javascript psuedo-protocol link that includes a URI string somewhere within a javascript function call, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a prefix of
		javascript:bea.wlp.disc.xie._Service.update('
		
a URI string of
		http://www.oracle.com
		
and a suffix of
		');
		
Returns:
string - The string for the URI associated with this instance, including the prefix and suffix

getProxyUri

public bea.wlp.disc.uri.Uri getProxyUri() 
A Uri instance that represents the proxy URI. The proxy URI contains a target URI, perhaps as a query parameter.
Returns:
bea.wlp.disc.uri.Uri - A Uri instance that represents the proxy URI. The proxy URI contains a target URI, perhaps as a query parameter. Returns null if this instance is not a proxy URI.

getTargetUri

public bea.wlp.disc.uri.Uri getTargetUri() 
Gets the target Uri associated with this instance. If this instance represents a proxy URI then the target URI is contained somewhere in the proxy URI, perhaps as a query parameter. The target URI is extracted from the proxy URI in a manner that is specific to each subclass of the base UriRewriter class.
Returns:
bea.wlp.disc.uri.Uri - The target Uri associated with this instance

getUriPrefix

public string getUriPrefix() 
Gets the prefix for the URI associated with this instance. A prefix is most likely to be used for a javascript psuedo-protocol link that includes a URI string somewhere within a javascript function call, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a prefix of
		javascript:bea.wlp.disc.xie._Service.update('
		
Returns:
string - The prefix for the URI associated with this instance. Returns the empty string, '', if there is no prefix.

getUriSuffix

public string getUriSuffix() 
Gets the suffix for the URI associated with this instance. A suffix is most likely to be used for a javascript psuedo-protocol link that includes a URI string somewhere within a javascript function call, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a suffix of
		');
		
Returns:
string - The suffix for the URI associated with this instance. Returns the empty string, '', if there is no suffix.

groksUri

public static boolean groksUri(uriStr, [tmpltMap]) 
Determines if this class understands the given URI string well enough to work with it.

Subclasses should implement their own static groksUri method for use by the UriRewriterFactory in selecting a UriRewriter.

Parameters:
string uriStr - The URI string
object [tmpltMap] - An optional map of template key/values, e.g., {protocol:'http', productId:'1001'}. This argument is required if the uriStr argument is templatized.
Returns:
boolean - true if this class understands the given URI string well enough to work with it, else false

isProxyUri

public boolean isProxyUri() 
Determines if the URI for this instance is a proxy URI that contains a target URI. If it is not a proxy URI then it is considered to be a target URI and getProxyUri() returns null.
Returns:
boolean - true if the URI for this instance is a proxy URI that contains a target URI, else false and the URI is considered to be a target URI.

parseUriStrParts

public object parseUriStrParts(uriStr) throws Error
Parses the prefix, URI string, and suffix from recognized javascript pseudo-protocol links. A javascript pseudo-protocol link begins with javascript:, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a prefix of
		javascript:bea.wlp.disc.xie._Service.update('
		
a URI string of
		http://www.oracle.com
		
and a suffix of
		');
		

Recognized javascript psuedo-protocol links are strings that can be parsed using the regular expressions in UriRewriter.JS_PSEUDO_PROTOCOL_REGEXES

If the input argument is a string that is not a javascript pseudo-protocol link then the prefix and suffix will be the empty string, '', and the uriStr property is the same as the input argument.

This method can be overriden in subclasses in order to change the parsing of javascript psuedo-protocol links in the constructor. Typically, a user will not use this method. They would use the static staticParseUriStrParts method. This method is intended to behave as a protected method to allow subclasses to override it for use in the constructor.

Parameters:
string uriStr - The string to be parsed for its prefix, URI string, and suffix
Returns:
object - An object with properties uriPreStr, uriStr, and uriEndStr that correspond to the prefix, URI string, and suffix, respectively. If the input argument is a URI string that is not a javascript pseudo-protocol link then the prefix and suffix will be the empty string, '', and the uriStr property is the same as the input argument.
Throws:
Error - Thrown when the uriStr is a javascript pseudo-protocol link that is not recognized. In this case, the URI string cannot be parsed from the given string and the user should parse the URI string out of the javascript themselves.

refreshTargetOnProxyUri

public void refreshTargetOnProxyUri() 
Sets the instance target URI as a parameter (or path or whatever) of the instance proxy URI. In this way, users can manipulate the the target URI instance directly and this rewriter can use this method to ensure the proxy URI instance is kept up to date.

This method is used by getProxyUri and setTargetUri so users of those methods do not need to use this method themselves.

This method is used by getProxyUri and setTargetUri so users of those methods do not need to use this method themselves. This method is intended to serve as a protected method to allow subclasses to override it for use in getProxyUri and setTargetUri. This method should be overridden by subclasses that are used to manipulate proxy URIs.


setProxyUri

public void setProxyUri(proxyUri) 
Sets the proxy URI for this instance. The proxy URI contains a target URI, perhaps as a query parameter. This instance will parse the target URI from the given proxy URI object and set the target URI for this instance at the same time it sets the proxy URI. This is done in a manner that is specific to each subclass of the base UriRewriter class.
Parameters:
bea.wlp.disc.uri.Uri proxyUri - A Uri instance that represents the proxy URI. The proxy URI contains a target URI, perhaps as a query parameter.

setTargetUri

public void setTargetUri(targetUri) 
Sets the target Uri associated with this instance. This method will refresh the proxy Uri by setting the target URI in a manner that is specific to each subclass of the base UriRewriter class.
Parameters:
bea.wlp.disc.uri.Uri targetUri - The target Uri associated with this instance

setUriPrefix

public void setUriPrefix(prefix) 
Sets the prefix for the URI associated with this instance. A prefix is most likely to be used for a javascript psuedo-protocol link that includes a URI string somewhere within a javascript function call, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a prefix of
		javascript:bea.wlp.disc.xie._Service.update('
		
Parameters:
string prefix - The prefix for the URI associated with this instance.

setUriSuffix

public void setUriSuffix(suffix) 
Sets the suffix for the URI associated with this instance. A suffix is most likely to be used for a javascript psuedo-protocol link that includes a URI string somewhere within a javascript function call, e.g, the string
		javascript:bea.wlp.disc.xie._Service.update('http://www.oracle.com');
		
would have a suffix of
		');
		
Parameters:
string suffix - The suffix for the URI associated with this instance.

staticParseUriStrParts

public static object staticParseUriStrParts(uriStr) throws Error
Parses the prefix, URI string, and suffix from recognized javascript pseudo-protocol links. This is a static implementation of the parseUriStrParts method.
Parameters:
string uriStr - The string to be parsed for its prefix, URI string, and suffix
Returns:
object - An object with properties uriPreStr, uriStr, and uriEndStr that correspond to the prefix, URI string, and suffix, respectively. If the input argument is a URI string that is not a javascript pseudo-protocol link then the prefix and suffix will be the empty string, '', and the uriStr property is the same as the input argument.
Throws:
Error - Thrown when the uriStr is a javascript pseudo-protocol link that is not recognized. In this case, the URI string cannot be parsed from the given string and the user should parse the URI string out of the javascript themselves.


Oracle Fusion Middleware Disc API Reference for Oracle WebLogic Portal
10g Release 3 (10.3.4)
E14257-04

Copyright © 2011, Oracle. All rights reserved.