Esempio n. 1
0
  /**
   * Gets the request URI relative to the current context path.
   *
   * <p>As an example:
   *
   * <pre>
   * requestURI = "/webapp/index.jsp"
   * contextPath = "/webapp"
   * </pre>
   *
   * The method will return {@code "/index.jsp"}.
   *
   * @param pRequest the current HTTP request
   * @return the request URI relative to the current context path.
   */
  public static String getContextRelativeURI(final HttpServletRequest pRequest) {
    String context = pRequest.getContextPath();

    if (!StringUtil.isEmpty(context)) { // "" for root context
      return pRequest.getRequestURI().substring(context.length());
    }

    return pRequest.getRequestURI();
  }
Esempio n. 2
0
 /**
  * Gets the value of the given parameter from the request converted to a {@code Date}.&nbsp;If the
  * parameter is not set or not parseable, the default value is returned.
  *
  * @param pReq the servlet request
  * @param pName the parameter name
  * @param pDefault the default value
  * @return the value of the parameter converted to a {@code Date}, or the default value, if the
  *     parameter is not set.
  * @see com.twelvemonkeys.lang.StringUtil#toDate(String)
  */
 public static long getDateParameter(
     final ServletRequest pReq, final String pName, final long pDefault) {
   String str = pReq.getParameter(pName);
   try {
     return str != null ? StringUtil.toDate(str).getTime() : pDefault;
   } catch (IllegalArgumentException iae) {
     return pDefault;
   }
 }
Esempio n. 3
0
    static String readPascalString(final DataInput pInput) throws IOException {
      int length = pInput.readUnsignedByte();

      if (length == 0) {
        return "";
      }

      byte[] bytes = new byte[length];
      pInput.readFully(bytes);

      return StringUtil.decode(bytes, 0, bytes.length, "ASCII");
    }
Esempio n. 4
0
 public PSDEntry(final int resourceId, String name, final Object value) {
   super(resourceId, value);
   this.name = StringUtil.isEmpty(name) ? null : name;
 }
Esempio n. 5
0
 /**
  * Gets the name of the servlet or the script that generated the servlet.
  *
  * @param pRequest The HTTP servlet request object.
  * @return the script name.
  * @todo Read the spec, seems to be a mismatch with the Servlet API...
  * @see javax.servlet.http.HttpServletRequest#getServletPath()
  */
 static String getScriptName(final HttpServletRequest pRequest) {
   String requestURI = pRequest.getRequestURI();
   return StringUtil.getLastElement(requestURI, "/");
 }