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, send message to client and change password etc.


Field Summary
static java.lang.String CONTENT_LOCATION
           
static java.lang.String PROP_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)
          Change the password of a user.
static java.lang.String decodeEsc(java.lang.String str)
          Decode the URL-encoded string(i.e.
static boolean dirIncludeCatalog(HttpRptServer httpRptServer, java.lang.String user, java.lang.String path)
          judge if the resource dir includ catalog.
static boolean dirIncludeReport(HttpRptServer httpRptServer, java.lang.String user, java.lang.String path)
          judge if the resource dir includ report.
static java.lang.String encodeEsc(java.lang.String str)
          Encode the URL string(i.e.
static java.lang.String encodeEsc(java.lang.String str, boolean encodeSlash)
          Encode the URL string(i.e.
static java.util.Properties getParameters(HttpServletRequest req)
          Gets the parameter values from the HttpServletRequest object.
static int getResultType(java.lang.String strResultType, int defaultType)
           
static java.lang.String getTempResultKey(java.lang.String tempResult)
          Get the key of a temp result to register the owner of the temp result.
static boolean hasPageSecurity(java.lang.String resultVersionFile)
           
static boolean isClientAPI(HttpServletRequest req, java.util.Hashtable ht)
          Check if the request comes from a JRClient API.
static boolean isJRClient(HttpServletRequest req, java.util.Hashtable ht)
          Check if the request comes from a JReport client(i.e.
static java.lang.String makeQuery(java.util.Hashtable ht)
          return query string by the keys, and values in the specified hashtable without a question mark(?).
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)
          Parse a HTTP query string into a Properties object.
static void redirect(HttpServletResponse res, java.io.PrintWriter writer, java.lang.String location, java.lang.String locationPrompt)
          Send a redirection page to the client.
static void sendMessage(HttpServletRequest req, HttpServletResponse res, int retcode, java.lang.String msg)
          Send a response including a message to the client.
static void sendMessage(HttpServletRequest req, HttpServletResponse res, int retcode, java.lang.Throwable thrwb)
          Send a response including infomation 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
See Also:
Constant Field Values

CONTENT_LOCATION

public static final java.lang.String CONTENT_LOCATION
See Also:
Constant Field Values
Method Detail

makeQuery

public static java.lang.String makeQuery(java.util.Hashtable ht)
return 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.

parseQuery

public static java.util.Properties parseQuery(java.lang.String query)
Parse a 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.

getParameters

public static java.util.Properties getParameters(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)
Decode the URL-encoded string(i.e. replace all the "%HexHex" with its characters).

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

encodeEsc

public static java.lang.String encodeEsc(java.lang.String str)
Encode the URL string(i.e. replace the invalid 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)
judge if the resource dir includ catalog.

Parameters:
path - is the path of resource dir.
Returns:
true if including catalog, else false.

dirIncludeReport

public static boolean dirIncludeReport(HttpRptServer httpRptServer,
                                       java.lang.String user,
                                       java.lang.String path)
judge if the resource dir includ report.

Parameters:
path - is the path of resource dir.
Returns:
true if including report, else false.

encodeEsc

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

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

sendMessage

public static void sendMessage(HttpServletRequest req,
                               HttpServletResponse res,
                               int retcode,
                               java.lang.String msg)
Send 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(HttpServletRequest req,
                               HttpServletResponse res,
                               int retcode,
                               java.lang.Throwable thrwb)
Send a response including infomation 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
Change 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(HttpServletRequest req,
                                 java.util.Hashtable ht)
Check if the request comes from a JReport client(i.e. the JRViewerBean, JREntViewer and JRClient API).

Parameters:
req - the HttpServletRequest.
ht - the HTTP query fields. return if the request comes from a JReport client(i.e. the JRViewerBean, JREntViewer and JRClient API).

isClientAPI

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

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

getTempResultKey

public static java.lang.String getTempResultKey(java.lang.String tempResult)
Get 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(HttpServletResponse res,
                            java.io.PrintWriter writer,
                            java.lang.String location,
                            java.lang.String locationPrompt)
                     throws java.io.IOException
Send a redirection page to the client.

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

outputHtmlTableHeader

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

Output a 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 a IOException occurs.

getResultType

public static int getResultType(java.lang.String strResultType,
                                int defaultType)

hasPageSecurity

public static boolean hasPageSecurity(java.lang.String resultVersionFile)