jet.server.api.http
Class BaseHttpUtil

java.lang.Object
  extended by jet.server.api.http.BaseHttpUtil
Direct Known Subclasses:
HttpUtil

public class BaseHttpUtil
extends java.lang.Object

Class BaseHttpUtil provides some static methods to operate on request/response, sending message to client and changing password etc.


Field Summary
static java.lang.String CONTENT_LOCATION
          Property used to specify content location.
static java.lang.String PROP_OUTPUT_ENCODING
          Property used to specify output encoding.
 
Method Summary
static java.lang.String changePassword(Authenticator authenticator, java.lang.String realm, java.lang.String submiter, boolean isJRClient, java.util.Hashtable ht)
          Changes the password of a user.
static java.lang.String decodeEsc(java.lang.String str)
          Decodes the URL-encoded string i.e.
static java.lang.String decodeEscapeEx(java.lang.String str)
           
static boolean dirIncludeCatalog(HttpRptServer httpRptServer, java.lang.String user, java.lang.String path)
          Judges if the resource directory includes catalog.
static boolean dirIncludeReport(HttpRptServer httpRptServer, java.lang.String user, java.lang.String path)
          Checks if the resource directory includes report.
static java.lang.String encodeEsc(java.lang.String str)
          Encodes the URL string i.e.
static java.lang.String encodeEsc(java.lang.String str, boolean encodeSlash)
          Encodes the URL string i.e.
static java.util.Properties getParameters(javax.servlet.http.HttpServletRequest req)
          Gets the parameter values from the HttpServletRequest object.
static int getResultType(java.lang.String strResultType, int defaultType)
          Gets the int value of result type.
static java.lang.String getTempResultKey(java.lang.String tempResult)
          Gets the key of a temp result to register the owner of the temp result.
static boolean hasPageSecurity(java.lang.String resultVersionFile)
          Checks if the specified result version file has page level security.
static boolean isClientAPI(javax.servlet.http.HttpServletRequest req, java.util.Hashtable ht)
          Checks if the request comes from a JRClient API.
static boolean isJRClient(javax.servlet.http.HttpServletRequest req, java.util.Hashtable ht)
          Checks if the request comes from a JReport client such as the JRViewerBean, JReport Desktop Viewer and JRClient API.
static java.lang.String makeQuery(java.util.Hashtable ht)
          Returns query string by the keys and values in the specified hashtable without a question mark (?).
static java.lang.String makeQueryWithout(java.util.Hashtable ht, java.util.Map withoutSessionParameters)
          Returns query string by the keys and values in the specified hashtable without session parameters.
static void outputHtmlTableHeader(java.io.PrintWriter writer, java.lang.String title, java.lang.String[] colNames)
          Deprecated.  
static java.util.Properties parseQuery(java.lang.String query)
          Parses an HTTP query string into a Properties object.
static void redirect(javax.servlet.http.HttpServletResponse res, java.io.PrintWriter writer, java.lang.String location, java.lang.String locationPrompt)
          Sends a redirection page to the client.
static void sendMessage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int retcode, java.lang.String msg)
          Sends a response including a message to the client.
static void sendMessage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int retcode, java.lang.Throwable thrwb)
          Sends a response including information of a Throwable object to the client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_OUTPUT_ENCODING

public static final java.lang.String PROP_OUTPUT_ENCODING
Property used to specify output encoding.

See Also:
Constant Field Values

CONTENT_LOCATION

public static final java.lang.String CONTENT_LOCATION
Property used to specify content location.

See Also:
Constant Field Values
Method Detail

makeQuery

public static java.lang.String makeQuery(java.util.Hashtable ht)
Returns query string by the keys and values in the specified hashtable without a question mark (?). The query ends with a '&'.

Parameters:
ht - keys and values' hashtable.
Returns:
query

parseQuery

public static java.util.Properties parseQuery(java.lang.String query)
Parses an HTTP query string into a Properties object.

Parameters:
query - the HTTP query string.
Returns:
the Properties object that contains the parameter values in the HTTP query string.

makeQueryWithout

public static java.lang.String makeQueryWithout(java.util.Hashtable ht,
                                                java.util.Map withoutSessionParameters)
Returns query string by the keys and values in the specified hashtable without session parameters.

Parameters:
ht - keys and values' hashtable.
Returns:
query

getParameters

public static java.util.Properties getParameters(javax.servlet.http.HttpServletRequest req)
Gets the parameter values from the HttpServletRequest object.

Parameters:
req - the HttpRequest object.
Returns:
the Properties object that contains the parameter values from the HttpServletRequest object.

decodeEsc

public static java.lang.String decodeEsc(java.lang.String str)
Decodes the URL-encoded string i.e. replace all the "%HexHex" with its ascii characters.

Parameters:
str - the URL-encoded string.
Returns:
the decoded URL string.

decodeEscapeEx

public static java.lang.String decodeEscapeEx(java.lang.String str)

encodeEsc

public static java.lang.String encodeEsc(java.lang.String str)
Encodes the URL string i.e. replace the special characters with "%HexHex".

Parameters:
str - the URL address string.
Returns:
the URL-encoded URL string.

dirIncludeCatalog

public static boolean dirIncludeCatalog(HttpRptServer httpRptServer,
                                        java.lang.String user,
                                        java.lang.String path)
Judges if the resource directory includes catalog.

Parameters:
httpRptServer - an HttpRptServer object.
user - the user of the server.
path - the path of the resource directory.
Returns:
true if the resource directory includes catalog, or else false.

dirIncludeReport

public static boolean dirIncludeReport(HttpRptServer httpRptServer,
                                       java.lang.String user,
                                       java.lang.String path)
Checks if the resource directory includes report.

Parameters:
httpRptServer - an HttpRptServer object.
user - the specified user.
path - the path of resource directory.
Returns:
true if the resource directory includes report, or else false.

encodeEsc

public static java.lang.String encodeEsc(java.lang.String str,
                                         boolean encodeSlash)
Encodes the URL string i.e. replace the special characters with "%HexHex".

Parameters:
str - the URL address string.
encodeSlash - indicates whether to convert the slash '/' character.
Returns:
the URL-encoded URL string.

sendMessage

public static void sendMessage(javax.servlet.http.HttpServletRequest req,
                               javax.servlet.http.HttpServletResponse res,
                               int retcode,
                               java.lang.String msg)
Sends a response including a message to the client.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
retcode - the HTTP status code.
msg - the message in the response.

sendMessage

public static void sendMessage(javax.servlet.http.HttpServletRequest req,
                               javax.servlet.http.HttpServletResponse res,
                               int retcode,
                               java.lang.Throwable thrwb)
Sends a response including information of a Throwable object to the client.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
retcode - the HTTP status code.
thrwb - the Throwable object.

changePassword

public static java.lang.String changePassword(Authenticator authenticator,
                                              java.lang.String realm,
                                              java.lang.String submiter,
                                              boolean isJRClient,
                                              java.util.Hashtable ht)
                                       throws java.io.IOException
Changes the password of a user.

Parameters:
authenticator - the Authenticator object(can get by using rptServer.getUserSessionManager().getAuthenticator()).
realm - the realm.
submiter - changes by the user ID.
isJRClient - if come from JRClient.
ht - properties about passwords info. The properties are:
  • CSUtil.TAG_UID : the user ID.
  • CSUtil.TAG_PASSWORD : the current password.
  • CSUtil.TAG_NEW_PASSWORD : the new password.
  • CSUtil.TAG_CONFIRM_NEW_PASSWORD : the new password to confirm.
Returns:
the error message or null if no error.
Throws:
java.io.IOException - if an IOException occurs.

isJRClient

public static boolean isJRClient(javax.servlet.http.HttpServletRequest req,
                                 java.util.Hashtable ht)
Checks if the request comes from a JReport client such as the JRViewerBean, JReport Desktop Viewer and JRClient API.

Parameters:
req - the HttpServletRequest.
ht - the HTTP query fields.
Returns:
true if the request comes from a JReport client.

isClientAPI

public static boolean isClientAPI(javax.servlet.http.HttpServletRequest req,
                                  java.util.Hashtable ht)
Checks if the request comes from a JRClient API.

Parameters:
req - the HttpServletRequest.
ht - the HTTP query fields.
Returns:
true if the request comes from a JRClient API.

getTempResultKey

public static java.lang.String getTempResultKey(java.lang.String tempResult)
Gets the key of a temp result to register the owner of the temp result.

Parameters:
tempResult - the temp result.
Returns:
the key of a temp result to register the owner of the temp result.

redirect

public static void redirect(javax.servlet.http.HttpServletResponse res,
                            java.io.PrintWriter writer,
                            java.lang.String location,
                            java.lang.String locationPrompt)
                     throws java.io.IOException
Sends a redirection page to the client.

Parameters:
res - the HttpServletResponse.
writer - the PrintWriter.
location - the location that is redirected to.
locationPrompt - the location prompt in the page.
Throws:
java.io.IOException - if an IOException occurs.

outputHtmlTableHeader

public static void outputHtmlTableHeader(java.io.PrintWriter writer,
                                         java.lang.String title,
                                         java.lang.String[] colNames)
                                  throws java.io.IOException
Deprecated. 

Outputs an HTML table header with the title and column names.

Parameters:
writer - the PrintWriter.
title - the title of the HTML table.
colNames - the column names of the HTML table.
Throws:
java.io.IOException - if an IOException occurs.

getResultType

public static int getResultType(java.lang.String strResultType,
                                int defaultType)
Gets the int value of result type.

Parameters:
strResultType - the type of the result.
defaultType - the default type.
Returns:
the int value of result type

hasPageSecurity

public static boolean hasPageSecurity(java.lang.String resultVersionFile)
Checks if the specified result version file has page level security.

Parameters:
resultVersionFile - the result version file that needs to check.
Returns:
true if the file has page level security, otherwise return false.