PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.servlet
Class ServletUtil

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.pagemixer.servlet.ServletUtil

public class ServletUtil
extends java.lang.Object

Ulitiy class for Servlet environment.

Since:
PageMixer 3.0

Constructor Summary
ServletUtil()
           
 
Method Summary
static java.lang.String getBaseHref(ConsumerContext context, boolean useHostHeader, boolean useContextRoot)
          Utility to get href value of base HTML tag.
static java.lang.String getBaseHref(javax.servlet.http.HttpServletRequest request)
          Deprecated. by getBaseHref(ConsumerContext, boolean, boolean)
static java.lang.String getHostName(ConsumerContext context, boolean ensure)
          Utility to get host name of servlet container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletUtil

public ServletUtil()
Method Detail

getBaseHref

public static java.lang.String getBaseHref(ConsumerContext context,
                                           boolean useHostHeader,
                                           boolean useContextRoot)
Utility to get href value of base HTML tag.

This method composes value for "href" of "base" from:

When you specify useHostHeader as false, you should attention that this method composes href value of base tag not from client side information(e.g.: HTTP request headers) but from server side configuration. This may causes unexpected location using in tunneling/port-forwarding environment or virtual hosting.

For example, when port #80 on your local host is forwarded to port #80 of server host via secure channel(e.g.: via SSH), you can not access any related resources from page with base tag, because its href value has not your local host but server host. So, your browser will try to load resources from server host via unexpected channel.


When you specify useContextRoot as true, this method composes href value not from requested URI, but from Servlet context path.

For example, assumption is that your web application is mounted on "/myApp", and requested URL is "http://foo.com/myApp/bar.servlet".

This method returns "http://foo.com/myApp/" if useContextRoot is true, or "http://foo.com/myApp/bar.servlet" otherwise.

Former value allows you to specify resouce location in response HTML page not relatively to request URI, but relatively to Servlet context(= web application).


This uses URL to compose "href" value.

Parameters:
request - of current request context
useHostHeader - as part of URL if it is specified
useContextPath - whether RequestMethodKey.CONTEXT_PATH is used instead of RequestMethodKey.REQUEST_URI or not
Since:
PageMixer 3.1

getBaseHref

public static java.lang.String getBaseHref(javax.servlet.http.HttpServletRequest request)
Deprecated. by getBaseHref(ConsumerContext, boolean, boolean)

Utility to get href value of base HTML tag.

This is equivalent to getBaseHref(context, false, false) .

Parameters:
request - of current request context

getHostName

public static java.lang.String getHostName(ConsumerContext context,
                                           boolean ensure)
Utility to get host name of servlet container.

At first, this tries to get "host name" from context by ReqHeaderKey.HOST. Then, this tries to get by RequestMethodKey.SERVER_NAME, if (1)"ensure" is true and (2)context has no value for ReqHeaderKey.HOST.

In other words, this tries to get host name by HttpServletRequest#getServerName(), when "host" header is not specified in this context.


This may contain port number to which http client tries to connect, because "host" request header may does so.

Parameters:
context - in which information is looked up
ensure - or not non-null return value
Since:
PageMixer 3.1

PageMixer API - 3.1