Compiere 3.1

org.compiere.util
Class WebUtil

java.lang.Object
  extended by org.compiere.util.WebUtil

public final class WebUtil
extends Object

Servlet Utilities

Version:
$Id: WebUtil.java,v 1.7 2006/09/24 12:11:54 comdivision Exp $
Author:
Jorg Janke

Constructor Summary
WebUtil()
           
 
Method Summary
static void addCookieWebUser(HttpServletRequest request, HttpServletResponse response, String webUser, String COOKIE_NAME)
          Add Cookie with web user
static org.apache.ecs.xhtml.option[] convertToOption(NamePair[] list, String default_ID)
          Convert Array of NamePair to HTTP Option Array.
static org.apache.ecs.xhtml.input createClosePopupButton()
          Get Close PopUp Buton
static void createErrorPage(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet, String message)
          Create Error Message
static org.apache.ecs.xhtml.tr createField(org.apache.ecs.xhtml.tr line, String FORMNAME, String PARAMETER, String labelText, String inputType, Object value, int sizeDisplay, int size, boolean longField, boolean mandatory, String onChange, StringBuffer script)
          Create label/field table row
static void createForwardPage(HttpServletResponse response, String title, String forwardURL, int delaySec)
          Create Forward Page
static void createLoginPage(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet, Ctx ctx, String AD_Message)
          Create Exit Page "Log-off".
static void createResponse(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet, Properties cookieProperties, WebDoc doc, boolean debug)
          Create Standard Response Header with optional Cookie and print document.
static void createTimeoutPage(HttpServletRequest request, HttpServletResponse response, HttpServlet servlet, String message)
          Create Timeout Message
static void deleteCookieWebUser(HttpServletRequest request, HttpServletResponse response, String COOKIE_NAME)
          Remove Cookie with web user by setting user to _
static boolean exists(HttpServletRequest request, String parameter)
          Does Parameter exist
static boolean exists(String test)
          Does Test exist
static org.apache.ecs.xhtml.script getClearFrame(String targetFrame)
          Create Java Script to clear Target frame
static Properties getCookieProperties(HttpServletRequest request)
          Get Cookie Properties
static HtmlCode getForward(String url, int delaySec)
          Return a link and script with new location.
static String getFrom(HttpServletRequest request)
          Get Remote From info
static org.apache.ecs.xhtml.button getLoginButton(Ctx ctx)
          Create Login Button - replace Window
static String getParameter(HttpServletRequest request, String parameter)
          Get String Parameter.
static BigDecimal getParameterAsBD(HttpServletRequest request, String parameter)
          Get numeric Parameter - 0 if not defined
static boolean getParameterAsBoolean(HttpServletRequest request, String parameter)
          Get boolean Parameter.
static boolean getParameterAsBoolean(HttpServletRequest request, String parameter, String expected)
          Get boolean Parameter.
static Timestamp getParameterAsDate(HttpServletRequest request, String parameter)
          Get date Parameter - null if not defined.
static Timestamp getParameterAsDate(HttpServletRequest request, String parameter, Language language)
          Get date Parameter - null if not defined.
static int getParameterAsInt(HttpServletRequest request, String parameter)
          Get integer Parameter - 0 if not defined.
static String[] getParameterValues(HttpServletRequest request, String parameter)
          Get String Parameter.
static String getParamOrNull(HttpServletRequest request, String parameter)
          get Parameter or Null fi empty
static boolean isEmailValid(String email)
          Is EMail address valid
static Properties propertiesDecode(String data)
          Decode data String (URL encoded) into Properties
static String propertiesEncode(Properties pp)
          Decode Properties into String (URL encoded)
static void reload(String logMessage, String jsp, HttpSession session, HttpServletRequest request, HttpServletResponse response, ServletContext thisContext)
          reload
static void resendCode(HttpServletRequest request, WebUser wu)
          Resend Validation Code
static String sendEMail(HttpServletRequest request, WebUser to, String msgType, Object[] parameter)
          Send EMail
static String streamAttachment(HttpServletResponse response, MAttachment attachment, int attachmentIndex)
          Stream Attachment Entry
static String streamFile(HttpServletResponse response, File file)
          Stream File
static boolean updateFields(HttpServletRequest request, WebUser wu, boolean updateEMailPwd)
          Update Web User
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebUtil

public WebUtil()
Method Detail

createTimeoutPage

public static void createTimeoutPage(HttpServletRequest request,
                                     HttpServletResponse response,
                                     HttpServlet servlet,
                                     String message)
                              throws ServletException,
                                     IOException
Create Timeout Message

Parameters:
request - request
response - response
servlet - servlet
message - - optional message
Throws:
ServletException
IOException

createErrorPage

public static void createErrorPage(HttpServletRequest request,
                                   HttpServletResponse response,
                                   HttpServlet servlet,
                                   String message)
                            throws ServletException,
                                   IOException
Create Error Message

Parameters:
request - request
response - response
servlet - servlet
message - message
Throws:
ServletException
IOException

createLoginPage

public static void createLoginPage(HttpServletRequest request,
                                   HttpServletResponse response,
                                   HttpServlet servlet,
                                   Ctx ctx,
                                   String AD_Message)
                            throws ServletException,
                                   IOException
Create Exit Page "Log-off".

- End Session - Go to start page (e.g. /compiere/index.html)

Parameters:
request - request
response - response
servlet - servlet
ctx - context
AD_Message - messahe
Throws:
ServletException
IOException

getLoginButton

public static org.apache.ecs.xhtml.button getLoginButton(Ctx ctx)
Create Login Button - replace Window

Parameters:
ctx - context
Returns:
Button

getCookieProperties

public static Properties getCookieProperties(HttpServletRequest request)
Get Cookie Properties

Parameters:
request - request
Returns:
Properties

getParameter

public static String getParameter(HttpServletRequest request,
                                  String parameter)
Get String Parameter.

Parameters:
request - request
parameter - parameter
Returns:
string or null

getParameterValues

public static String[] getParameterValues(HttpServletRequest request,
                                          String parameter)
Get String Parameter.

Parameters:
request - request
parameter - parameter
Returns:
string or null

getParameterAsInt

public static int getParameterAsInt(HttpServletRequest request,
                                    String parameter)
Get integer Parameter - 0 if not defined.

Parameters:
request - request
parameter - parameter
Returns:
int result or 0

getParameterAsBD

public static BigDecimal getParameterAsBD(HttpServletRequest request,
                                          String parameter)
Get numeric Parameter - 0 if not defined

Parameters:
request - request
parameter - parameter
Returns:
big decimal result or 0

getParameterAsDate

public static Timestamp getParameterAsDate(HttpServletRequest request,
                                           String parameter)
Get date Parameter - null if not defined. Date portion only

Parameters:
request - request
parameter - parameter
Returns:
timestamp result or null

getParameterAsDate

public static Timestamp getParameterAsDate(HttpServletRequest request,
                                           String parameter,
                                           Language language)
Get date Parameter - null if not defined. Date portion only

Parameters:
request - request
parameter - parameter
language - optional language
Returns:
timestamp result or null

getParameterAsBoolean

public static boolean getParameterAsBoolean(HttpServletRequest request,
                                            String parameter)
Get boolean Parameter.

Parameters:
request - request
parameter - parameter
Returns:
true if found

getParameterAsBoolean

public static boolean getParameterAsBoolean(HttpServletRequest request,
                                            String parameter,
                                            String expected)
Get boolean Parameter.

Parameters:
request - request
parameter - parameter
expected - optional expected value
Returns:
true if found and if optional value matches

getParamOrNull

public static String getParamOrNull(HttpServletRequest request,
                                    String parameter)
get Parameter or Null fi empty

Parameters:
request - request
parameter - parameter
Returns:
Request Value or null

reload

public static void reload(String logMessage,
                          String jsp,
                          HttpSession session,
                          HttpServletRequest request,
                          HttpServletResponse response,
                          ServletContext thisContext)
                   throws ServletException,
                          IOException
reload

Parameters:
logMessage -
jsp -
session -
request -
response -
thisContext -
Throws:
ServletException
IOException

createResponse

public static void createResponse(HttpServletRequest request,
                                  HttpServletResponse response,
                                  HttpServlet servlet,
                                  Properties cookieProperties,
                                  WebDoc doc,
                                  boolean debug)
                           throws IOException
Create Standard Response Header with optional Cookie and print document. D:\j2sdk1.4.0\docs\guide\intl\encoding.doc.html

Parameters:
request - request
response - response
servlet - servlet
cookieProperties - cookie properties
doc - doc
debug - debug
Throws:
IOException

getClearFrame

public static org.apache.ecs.xhtml.script getClearFrame(String targetFrame)
Create Java Script to clear Target frame

Parameters:
targetFrame - target frame
Returns:
Clear Frame Script

getForward

public static HtmlCode getForward(String url,
                                  int delaySec)
Return a link and script with new location.

Parameters:
url - forward url
delaySec - delay in seconds (default 3)
Returns:
html

createForwardPage

public static void createForwardPage(HttpServletResponse response,
                                     String title,
                                     String forwardURL,
                                     int delaySec)
                              throws ServletException,
                                     IOException
Create Forward Page

Parameters:
response - response
title - page title
forwardURL - url
delaySec - delay in seconds (default 3)
Throws:
ServletException
IOException

exists

public static boolean exists(String test)
Does Test exist

Parameters:
test - string
Returns:
true if String with data

exists

public static boolean exists(HttpServletRequest request,
                             String parameter)
Does Parameter exist

Parameters:
request - request
parameter - string
Returns:
true if String with data

isEmailValid

public static boolean isEmailValid(String email)
Is EMail address valid

Parameters:
email - mail address
Returns:
true if valid

propertiesEncode

public static String propertiesEncode(Properties pp)
Decode Properties into String (URL encoded)

Parameters:
pp - properties
Returns:
Encoded String

propertiesDecode

public static Properties propertiesDecode(String data)
Decode data String (URL encoded) into Properties

Parameters:
data - data
Returns:
Properties

convertToOption

public static org.apache.ecs.xhtml.option[] convertToOption(NamePair[] list,
                                                            String default_ID)
Convert Array of NamePair to HTTP Option Array.

If the ArrayList does not contain NamePairs, the String value is used

Parameters:
list - ArrayList containing NamePair values
default_ID - Sets the default if the key/ID value is found. If the value is null or empty, the first value is selected
Returns:
Option Array
See Also:
NamePair

createField

public static org.apache.ecs.xhtml.tr createField(org.apache.ecs.xhtml.tr line,
                                                  String FORMNAME,
                                                  String PARAMETER,
                                                  String labelText,
                                                  String inputType,
                                                  Object value,
                                                  int sizeDisplay,
                                                  int size,
                                                  boolean longField,
                                                  boolean mandatory,
                                                  String onChange,
                                                  StringBuffer script)
Create label/field table row

Parameters:
line - - null for new line (table row)
FORMNAME - form name
PARAMETER - parameter name
labelText - label
inputType - HTML input type
value - data value
sizeDisplay - display size
size - data size
longField - field spanning two columns
mandatory - mark as mandatory
onChange - onChange call
script - script
Returns:
tr table row

createClosePopupButton

public static org.apache.ecs.xhtml.input createClosePopupButton()
Get Close PopUp Buton

Returns:
button

streamAttachment

public static String streamAttachment(HttpServletResponse response,
                                      MAttachment attachment,
                                      int attachmentIndex)
Stream Attachment Entry

Parameters:
response - response
attachment - attachment
attachmentIndex - logical index
Returns:
error message or null

streamFile

public static String streamFile(HttpServletResponse response,
                                File file)
Stream File

Parameters:
response - response
file - file to stream
Returns:
error message or null

deleteCookieWebUser

public static void deleteCookieWebUser(HttpServletRequest request,
                                       HttpServletResponse response,
                                       String COOKIE_NAME)
Remove Cookie with web user by setting user to _

Parameters:
request - request (for context path)
response - response to add cookie

sendEMail

public static String sendEMail(HttpServletRequest request,
                               WebUser to,
                               String msgType,
                               Object[] parameter)
Send EMail

Parameters:
request - request
to - web user
msgType - see MMailMsg.MAILMSGTYPE_*
parameter - object array with parameters
Returns:
mail EMail.SENT_OK or error message

getFrom

public static String getFrom(HttpServletRequest request)
Get Remote From info

Parameters:
request - request
Returns:
remore info

addCookieWebUser

public static void addCookieWebUser(HttpServletRequest request,
                                    HttpServletResponse response,
                                    String webUser,
                                    String COOKIE_NAME)
Add Cookie with web user

Parameters:
request - request (for context path)
response - response to add cookie
webUser - email address

resendCode

public static void resendCode(HttpServletRequest request,
                              WebUser wu)
Resend Validation Code

Parameters:
request - request
wu - user

updateFields

public static boolean updateFields(HttpServletRequest request,
                                   WebUser wu,
                                   boolean updateEMailPwd)
Update Web User

Parameters:
request - request
wu - user
updateEMailPwd - if true, change email/password
Returns:
true if saved

Compiere 3.1

Compiere® is a registered trademark of ComPiere, Inc. ©2004-2008 HumanFlash.com All rights reserved.