Package org.compiere.util
Class WebUtil
- java.lang.Object
-
- 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
Constructors Constructor Description WebUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCookieWebUser(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String webUser, String COOKIE_NAME)
Add Cookie with web userstatic 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(Properties ctx)
Get Close PopUp Butonstatic 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 rowstatic void
createForwardPage(javax.servlet.http.HttpServletResponse response, String title, String forwardURL, int delaySec)
Create Forward Pagestatic void
createLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServlet servlet, Properties ctx, String AD_Message)
Create Exit Page "Log-off".static void
createResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServlet servlet, Properties cookieProperties, WebDoc doc, boolean debug)
Create Standard Response Header with optional Cookie and print document.static void
deleteCookieWebUser(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String COOKIE_NAME)
Remove Cookie with web user by setting user to _static boolean
exists(String test)
Does Test existstatic boolean
exists(javax.servlet.http.HttpServletRequest request, String parameter)
Does Parameter existstatic org.apache.ecs.xhtml.script
getClearFrame(String targetFrame)
Create Java Script to clear Target framestatic Properties
getCookieProprties(javax.servlet.http.HttpServletRequest request)
Get Cookie Propertiesstatic HtmlCode
getForward(String url, int delaySec)
Return a link and script with new location.static String
getFrom(javax.servlet.http.HttpServletRequest request)
Get Remote From infostatic String
getHostIP()
static org.apache.ecs.xhtml.input
getLoginButton(Properties ctx)
Create Login Button - replace Windowstatic String
getParameter(javax.servlet.http.HttpServletRequest request, String parameter)
Get String Parameter.static BigDecimal
getParameterAsBD(javax.servlet.http.HttpServletRequest request, String parameter)
Get numeric Parameter - 0 if not definedstatic boolean
getParameterAsBoolean(javax.servlet.http.HttpServletRequest request, String parameter)
Get boolean Parameter.static boolean
getParameterAsBoolean(javax.servlet.http.HttpServletRequest request, String parameter, String expected)
Get boolean Parameter.static Timestamp
getParameterAsDate(javax.servlet.http.HttpServletRequest request, String parameter)
Get date Parameter - null if not defined.static Timestamp
getParameterAsDate(javax.servlet.http.HttpServletRequest request, String parameter, Language language)
Get date Parameter - null if not defined.static int
getParameterAsInt(javax.servlet.http.HttpServletRequest request, String parameter)
Get integer Parameter - 0 if not defined.static String
getParamOrNull(javax.servlet.http.HttpServletRequest request, String parameter)
get Parameter or Null fi emptystatic String
getServerName()
static boolean
isEmailValid(String email)
Is EMail address validstatic Properties
propertiesDecode(String data)
Decode data String (URL encoded) into Propertiesstatic String
propertiesEncode(Properties pp)
Decode Properties into String (URL encoded)static String
streamAttachment(javax.servlet.http.HttpServletResponse response, MAttachment attachment, int attachmentIndex)
Stream Attachment Entrystatic String
streamFile(javax.servlet.http.HttpServletResponse response, File file)
Stream Filestatic boolean
updateFields(javax.servlet.http.HttpServletRequest request, WebUser wu, boolean updateEMailPwd)
Update Web User
-
-
-
Method Detail
-
createLoginPage
public static void createLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServlet servlet, Properties ctx, String AD_Message) throws javax.servlet.ServletException, IOException
Create Exit Page "Log-off".- End Session - Go to start page (e.g. /adempiere/index.html)
- Parameters:
request
- requestresponse
- responseservlet
- servletctx
- contextAD_Message
- messahe- Throws:
javax.servlet.ServletException
IOException
-
getLoginButton
public static org.apache.ecs.xhtml.input getLoginButton(Properties ctx)
Create Login Button - replace Window- Parameters:
ctx
- context- Returns:
- Button
-
getCookieProprties
public static Properties getCookieProprties(javax.servlet.http.HttpServletRequest request)
Get Cookie Properties- Parameters:
request
- request- Returns:
- Properties
-
getParameter
public static String getParameter(javax.servlet.http.HttpServletRequest request, String parameter)
Get String Parameter.- Parameters:
request
- requestparameter
- parameter- Returns:
- string or null
-
getParameterAsInt
public static int getParameterAsInt(javax.servlet.http.HttpServletRequest request, String parameter)
Get integer Parameter - 0 if not defined.- Parameters:
request
- requestparameter
- parameter- Returns:
- int result or 0
-
getParameterAsBD
public static BigDecimal getParameterAsBD(javax.servlet.http.HttpServletRequest request, String parameter)
Get numeric Parameter - 0 if not defined- Parameters:
request
- requestparameter
- parameter- Returns:
- big decimal result or 0
-
getParameterAsDate
public static Timestamp getParameterAsDate(javax.servlet.http.HttpServletRequest request, String parameter)
Get date Parameter - null if not defined. Date portion only- Parameters:
request
- requestparameter
- parameter- Returns:
- timestamp result or null
-
getParameterAsDate
public static Timestamp getParameterAsDate(javax.servlet.http.HttpServletRequest request, String parameter, Language language)
Get date Parameter - null if not defined. Date portion only- Parameters:
request
- requestparameter
- parameterlanguage
- optional language- Returns:
- timestamp result or null
-
getParameterAsBoolean
public static boolean getParameterAsBoolean(javax.servlet.http.HttpServletRequest request, String parameter)
Get boolean Parameter.- Parameters:
request
- requestparameter
- parameter- Returns:
- true if found
-
getParameterAsBoolean
public static boolean getParameterAsBoolean(javax.servlet.http.HttpServletRequest request, String parameter, String expected)
Get boolean Parameter.- Parameters:
request
- requestparameter
- parameterexpected
- optional expected value- Returns:
- true if found and if optional value matches
-
getParamOrNull
public static String getParamOrNull(javax.servlet.http.HttpServletRequest request, String parameter)
get Parameter or Null fi empty- Parameters:
request
- requestparameter
- parameter- Returns:
- Request Value or null
-
createResponse
public static void createResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.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
- requestresponse
- responseservlet
- servletcookieProperties
- cookie propertiesdoc
- docdebug
- 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 urldelaySec
- delay in seconds (default 3)- Returns:
- html
-
createForwardPage
public static void createForwardPage(javax.servlet.http.HttpServletResponse response, String title, String forwardURL, int delaySec) throws javax.servlet.ServletException, IOException
Create Forward Page- Parameters:
response
- responsetitle
- page titleforwardURL
- urldelaySec
- delay in seconds (default 3)- Throws:
javax.servlet.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(javax.servlet.http.HttpServletRequest request, String parameter)
Does Parameter exist- Parameters:
request
- requestparameter
- 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 valuesdefault_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 namePARAMETER
- parameter namelabelText
- labelinputType
- HTML input typevalue
- data valuesizeDisplay
- display sizesize
- data sizelongField
- field spanning two columnsmandatory
- mark as mandatoryonChange
- onChange callscript
- script- Returns:
- tr table row
-
createClosePopupButton
public static org.apache.ecs.xhtml.input createClosePopupButton(Properties ctx)
Get Close PopUp Buton- Returns:
- button
-
streamAttachment
public static String streamAttachment(javax.servlet.http.HttpServletResponse response, MAttachment attachment, int attachmentIndex)
Stream Attachment Entry- Parameters:
response
- responseattachment
- attachmentattachmentIndex
- logical index- Returns:
- error message or null
-
streamFile
public static String streamFile(javax.servlet.http.HttpServletResponse response, File file)
Stream File- Parameters:
response
- responsefile
- file to stream- Returns:
- error message or null
-
deleteCookieWebUser
public static void deleteCookieWebUser(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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
-
getFrom
public static String getFrom(javax.servlet.http.HttpServletRequest request)
Get Remote From info- Parameters:
request
- request- Returns:
- remore info
-
addCookieWebUser
public static void addCookieWebUser(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String webUser, String COOKIE_NAME)
Add Cookie with web user- Parameters:
request
- request (for context path)response
- response to add cookiewebUser
- email address
-
updateFields
public static boolean updateFields(javax.servlet.http.HttpServletRequest request, WebUser wu, boolean updateEMailPwd)
Update Web User- Parameters:
request
- requestwu
- userupdateEMailPwd
- if true, change email/password- Returns:
- true if saved
-
getServerName
public static String getServerName()
- Returns:
- Servername including host name: IP : instance name
-
getHostIP
public static String getHostIP()
-
-