net.sf.j2ep.rules
Class RewriteRule

java.lang.Object
  extended by net.sf.j2ep.rules.BaseRule
      extended by net.sf.j2ep.rules.RewriteRule
All Implemented Interfaces:
Rule

public class RewriteRule
extends BaseRule

A rule using regular expressions to rewrite the URI. At first the expression will have to match the URI, after that the groups from the expression can be used to rewrite the URI.

Author:
Anders Nyman

Constructor Summary
RewriteRule()
          Basic constructor.
 
Method Summary
 boolean matches(HttpServletRequest request)
          Will check if the URI matches the pattern we have set up.
 java.lang.String process(java.lang.String uri)
          Will use the pattern and the rewriteTo string to rewrite the URI before using it to connection to the end server.
 java.lang.String revert(java.lang.String uri)
          Returns the reverted URI, this means that if a URI is processed and then reverted it should be the same URI.
 void setFrom(java.lang.String regex)
          Sets the regex we will match incoming URIs on.
 void setRevertFrom(java.lang.String regex)
          Sets the regex we use to match outgoing links found.
 void setRevertTo(java.lang.String to)
          Sets the string we rewrite outgoing links to.
 void setTo(java.lang.String to)
          Sets the string we will rewrite incoming URIs to.
 
Methods inherited from class net.sf.j2ep.rules.BaseRule
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RewriteRule

public RewriteRule()
Basic constructor.

Method Detail

matches

public boolean matches(HttpServletRequest request)
Will check if the URI matches the pattern we have set up.

Parameters:
request - The request
Returns:
true if the request is matched, otherwise false
See Also:
net.sf.j2ep.model.Rule#matches(javax.servlet.http.HttpServletRequest)

process

public java.lang.String process(java.lang.String uri)
Will use the pattern and the rewriteTo string to rewrite the URI before using it to connection to the end server.

Specified by:
process in interface Rule
Overrides:
process in class BaseRule
Parameters:
uri - URI to be processed
Returns:
The final URI
See Also:
Rule.process(java.lang.String)

revert

public java.lang.String revert(java.lang.String uri)
Description copied from interface: Rule
Returns the reverted URI, this means that if a URI is processed and then reverted it should be the same URI. revert(process("some random string")) should return "some random string".

Specified by:
revert in interface Rule
Overrides:
revert in class BaseRule
Parameters:
uri - URI to be reverted
Returns:
The reverted URI
See Also:
Rule.revert(java.lang.String)

setFrom

public void setFrom(java.lang.String regex)
Sets the regex we will match incoming URIs on.

Parameters:
regex - The regex

setTo

public void setTo(java.lang.String to)
Sets the string we will rewrite incoming URIs to.

Parameters:
to - The string we rewrite to

setRevertFrom

public void setRevertFrom(java.lang.String regex)
Sets the regex we use to match outgoing links found.

Parameters:
regex - The regex

setRevertTo

public void setRevertTo(java.lang.String to)
Sets the string we rewrite outgoing links to.

Parameters:
to - The string we rewrite to