view software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/util/ServletUtil.java @ 19:4a3641ae14d2

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 09 Nov 2011 15:32:05 +0100
parents
children
line wrap: on
line source

package de.mpg.mpiwg.berlin.mpdl.servlets.util;

import javax.servlet.http.HttpServletRequest;

import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;

public class ServletUtil {
  private static ServletUtil instance;

  public static ServletUtil getInstance() throws ApplicationException {
    if (instance == null) {
      instance = new ServletUtil();
    }
    return instance;
  }

  public ServletUtil() {
  }

  public String getBaseUrl( HttpServletRequest request ) {
    if (request.getServerPort() == 80 || request.getServerPort() == 443)
      return request.getScheme() + "://" + request.getServerName() + request.getContextPath();
    else
      return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
  }
  
}