com.openedit.util
Class URLUtilities

java.lang.Object
  extended by com.openedit.util.URLUtilities

public class URLUtilities
extends java.lang.Object

Utility class for building URLs.

Author:
Anthony Eden

Field Summary
static java.lang.String URL_PATH_SEPARATOR
          The URL path separator.
 
Constructor Summary
URLUtilities(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 
Method Summary
 java.lang.String buildAppRoot()
          This is the server name and webapp returns http://www.acme.com/webapp
 java.lang.String buildBasePath(java.lang.String path)
          This includes the webapp name but not the page name
 java.lang.String buildRoot()
          This is the server name only returns http://www.acme.com/
 java.lang.String buildSecure(java.lang.String path)
          Build an HTTPS (Secure Socket Layer) method relative to the application context using the given path.
 java.lang.String buildSecure(java.lang.String path, int port)
          Build an HTTPS (Secure Socket Layer) method relative to the application context using the given path.
 java.lang.String buildStandard(java.lang.String path)
          Build an HTTP URL relative to the application context using the given path.
 java.lang.String buildStandard(java.lang.String path, int port)
          Build an HTTP URL relative to the application context using the given path.
 java.lang.String decode(java.lang.String s)
           
 java.lang.String encode(java.lang.String s)
          Percent-encode the given String.
 java.lang.String getOriginalPath()
          This is the path that the browser is on.
 java.lang.String getOriginalUrl()
          Build an HTTP URL relative to the application context using the given path.
 PathUtilities getPathUtilities()
           
static java.lang.String getPathWithoutContext(java.lang.String inContext, java.lang.String fullpath, java.lang.String inDefault)
          The only non-buggy way to get a file name is to look at the full URL then chop off the context to make it a relative URL
 javax.servlet.http.HttpServletRequest getRequest()
           
 javax.servlet.http.HttpServletResponse getResponse()
           
 java.lang.String relativeHomePrefix()
          If I am located in /webapp/demo/test.html my prefix would be /demo/ to get back to the base /webapp level The rule is you can tack on $home + "/somepage.html" without getting //somepage.html
 java.lang.String requestPath()
          Build an HTTP URL relative to the application context using the given path.
 java.lang.String requestPathWithArguments()
          Is the full path with arguments included /webappname/sub/index.html?test=1234
 java.lang.String requestPathWithArgumentsNoContext()
          Is the full path with arguments included /sub/index.html?test=1234
 void setRequest(javax.servlet.http.HttpServletRequest inRequest)
           
 void setResponse(javax.servlet.http.HttpServletResponse inResponse)
           
 java.lang.String siteRoot()
          Report the site name, e.g.
static java.lang.String textEscape(java.lang.String inStr)
           
static java.lang.String xmlEscape(java.lang.String inStr)
          A simple hack to escape XML, stolen from Jakarta commons XmlUtils
static java.lang.String xmlEscapeWithWrap(java.lang.String inStr)
           
static java.lang.String xmlEscapeWithWrap(java.lang.String inStr, int inWrap)
           
static java.lang.String xmlUnescape(java.lang.String inStr)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_PATH_SEPARATOR

public static final java.lang.String URL_PATH_SEPARATOR
The URL path separator.

See Also:
Constant Field Values
Constructor Detail

URLUtilities

public URLUtilities(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
Method Detail

getPathWithoutContext

public static java.lang.String getPathWithoutContext(java.lang.String inContext,
                                                     java.lang.String fullpath,
                                                     java.lang.String inDefault)
The only non-buggy way to get a file name is to look at the full URL then chop off the context to make it a relative URL

Returns:
/index.html

buildBasePath

public java.lang.String buildBasePath(java.lang.String path)
This includes the webapp name but not the page name

Returns:
http://www.acme.com/webapp/

buildRoot

public java.lang.String buildRoot()
This is the server name only returns http://www.acme.com/


buildAppRoot

public java.lang.String buildAppRoot()
This is the server name and webapp returns http://www.acme.com/webapp


buildSecure

public java.lang.String buildSecure(java.lang.String path)
Build an HTTPS (Secure Socket Layer) method relative to the application context using the given path.


buildSecure

public java.lang.String buildSecure(java.lang.String path,
                                    int port)
Build an HTTPS (Secure Socket Layer) method relative to the application context using the given path. This version of the buildSecure method allows you to specify the port number. A port number of 0 will cause the port argument to be ignored.

Parameters:
path - The path
port - The port
Returns:
DOCME

buildStandard

public java.lang.String buildStandard(java.lang.String path)
Build an HTTP URL relative to the application context using the given path.

Parameters:
path - The path
Returns:
DOCME

buildStandard

public java.lang.String buildStandard(java.lang.String path,
                                      int port)
Build an HTTP URL relative to the application context using the given path. This version of the buildStandard method allows you to specify the port number. A port number of 0 will cause the port argument to be ignored.

Parameters:
path - The path
port - The port
Returns:
DOCME

encode

public java.lang.String encode(java.lang.String s)
Percent-encode the given String. This method delegates to the URLEncoder.encode() method.

Parameters:
s - The String to encode
Returns:
The encoded String
See Also:
URLEncoder

decode

public java.lang.String decode(java.lang.String s)

getOriginalUrl

public java.lang.String getOriginalUrl()
Build an HTTP URL relative to the application context using the given path. This is a path such as /path/myfile.html but is encoded If you want to unencoded path use $content.path or getOriginalPath()

Returns:
/webapp/path/myfile.html

getOriginalPath

public java.lang.String getOriginalPath()
This is the path that the browser is on. /sub/index page.html

Returns:

requestPath

public java.lang.String requestPath()
Build an HTTP URL relative to the application context using the given path. This is a path such as http://servername/webapp/path/myfile.html

Returns:
/webapp/path/myfile.html

requestPathWithArguments

public java.lang.String requestPathWithArguments()
Is the full path with arguments included /webappname/sub/index.html?test=1234


requestPathWithArgumentsNoContext

public java.lang.String requestPathWithArgumentsNoContext()
Is the full path with arguments included /sub/index.html?test=1234


siteRoot

public java.lang.String siteRoot()
Report the site name, e.g. http://www.openeditpro.com

Returns:
The site's root URL

xmlEscapeWithWrap

public static java.lang.String xmlEscapeWithWrap(java.lang.String inStr)

xmlEscapeWithWrap

public static java.lang.String xmlEscapeWithWrap(java.lang.String inStr,
                                                 int inWrap)

xmlEscape

public static java.lang.String xmlEscape(java.lang.String inStr)
A simple hack to escape XML, stolen from Jakarta commons XmlUtils

Parameters:
inStr -
Returns:
String

textEscape

public static java.lang.String textEscape(java.lang.String inStr)

xmlUnescape

public static java.lang.String xmlUnescape(java.lang.String inStr)

relativeHomePrefix

public java.lang.String relativeHomePrefix()
If I am located in /webapp/demo/test.html my prefix would be /demo/ to get back to the base /webapp level The rule is you can tack on $home + "/somepage.html" without getting //somepage.html

Returns:
Object

getPathUtilities

public PathUtilities getPathUtilities()

getResponse

public javax.servlet.http.HttpServletResponse getResponse()

setResponse

public void setResponse(javax.servlet.http.HttpServletResponse inResponse)

getRequest

public javax.servlet.http.HttpServletRequest getRequest()

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest inRequest)