BaseUtils class
The BaseUtils class provides a set of convenience methods similar to those in the GX class. The methods of this class apply to user-written AppLogics.
Although anyone developing a NAS application can use BaseUtils, this class is typically used in components generated by Netscape Application Builder.
Package
com.netscape.server.servlet.extension
Constructor
public BaseUtils( )
Methods
convertITemplateDataToResultSet( )
Creates a ResultSet wrapper for an ITemplateData object.
Syntax
public static ResultSet convertITemplateDataToResultSet(
String groupName,
ITemplateData templateData)
groupName.
The group name of the specified ITemplateData.
templateData.
The ITemplateData to be wrapped.
Usage
The convertITemplateDataToResultSet( ) method takes an ITemplateData object and wraps it so that it conforms to the specifications of a JDBC ResultSet object.
Rules
Hierarchical ITemplateData objects are not supported, so do not specify one as a parameter.
Return Value
A ResultSet object.
createListRowSet( )
Creates a RowSet object that conforms to the IListRowSet interface.
Syntax
public static IListRowSet createListRowSet(
HttpServletRequest request,
HttpServletResponse response,
String listName)
request.
The request object.
response.
The response object.
listName.
The name of the RowSet to pass in.
Usage
The createListRowSet( ) method creates a RowSet object that conforms to the IListRowSet interface. IListRowSet objects are useful for dynamically populating a pop-up list. The listName parameter is used to add the RowSet name as an attribute of the specified request.
Return Value
An IListRowSet object.
Related Topics
IListRowSet interface
createMethodHash( )
Creates a method hash.
Syntax
public static final MethodHash createMethodHash()
Usage
Method hashes are used to cache method lookups but are hidden from the user. createMethodHash( ) allows for the construction of method hashes. This construction is necessary when subclasses of DBRowSet are created.
Return Value
A method hash.
Related Topics
getStaticMethodCache( ) in the DBRowSet class
createStringFromBuffer( )
Creates a string from an IBuffer object.
Syntax
public static final String createStringFromBuffer(
IBuffer buff)
buff.
IBuffer object containing the value to convert.
Usage
This method creates a String from an IBuffer object. Use createStringFromBuffer( ) instead of the toString( ) method of the Util class. Unlike toString( ), the createStringFromBuffer( ) method accounts for null terminators. Ignoring null terminators in an IBuffer object causes incorrect Strings.
Tip
createStringFromBuffer( ) does not perform character conversion. You may want to write your own method if character conversion is important.
Return Value
String representing the data in an IBuffer object.
Example
ITemplateMap map = (ITemplateMap) request.getAttribute("GX_MAP");
IBuffer buff;
buff = map.get("foo",null,null);
Related Topics
Util class, IBuffer interface
doubleQuote( )
Converts each occurrence of one single quote to two successive single quotes.
Syntax
public static final String doubleQuote(
String input)
input.
The input string whose single quotes are to be affected.
Usage
Use doubleQuote( ) for input bindings to queries. Suppose there is a query that takes one input parameter, NameInput:
select *
from emp
where (ename = ':NameInput')
If the name is O'Reilly, then the following query would be loaded:
select *
from emp
where (ename ='O'Reilly')
Normally, an attempt to execute this query results in a syntax error. The correct query should be as follows:
select *
from emp
where (ename ='O''Reilly')
To produce this query, any single quotes in the input binding for NameInput must be doubled up. The doubleQuote( ) method performs this doubling up.
Return Value
The converted string.
Example
// Create a DBRowSet from a query in a query file for output.
DBRowSet ds = new DBRowSet(this, "main", "query_filename.gxq",
"connection_name");
bindLoadValue("NameInput",
BaseUtils.doubleQuote(request.getParameter("NameInput")));
ds.setQueryName("query_name");
request.setAttribute(ds.getName(),ds); // Ready for output!
Related Topics
DBRowSet class, GX class
includeJSP( )
A convenience method for streaming a JSP file.
Syntax
public static void includeJSP(
HttpServletRequest request,
HttpServletResponse response,
String name) throws ServletException, IOException
request.
The request object.
response.
The response object.
name.
The name of the JSP or servlet to include.
Usage
The includeJSP( ) method provides a shortcut for streaming a JSP file (or a servlet file). This method also sets the response object's ContentType to "text/html". If an error occurs when including the file, a ServletException is thrown.
initRowSets( )
Initializes RowSet objects specified in a servlet's configuration file.
Syntax
public static int initRowSets(
HttpServletRequest request,
HttpServletResponse response)
request.
The request object.
response.
The response object.
Usage
Use the initRowSets( ) method to instantiate and initialize all RowSet objects from the metadata in a servlet's configuration file. The initRowSets( ) method also stores the RowSets into the specified request object.
A servlet's configuration file has a "RowSets" entry under the ServletData key. The "RowSets" entry identifies each RowSet that the application designer knew about at design-time.
For each RowSet, the initRowSets( ) method first checks the value of the autoCreate variable. If autoCreate is set to true or is not set, then initRowSets( ) instantiates the RowSet identified by the className variable.
The initRowSets( ) method next initializes each RowSet in either of two ways:
If the RowSet is an instance of IRowSet2, then initRowSets( ) initializes the RowSet by calling the setName( ), setRequest( ), setResponse( ) and initMetaInfo( ) methods of the IRowSet2 interface.
If the RowSet is not an instance of IRowSet2, then the properties in the metadata are assumed to be settable on the RowSet by a call to its setProperty( ) method. The initRowSets( ) method will look up the setProperty( ) method and call it if it's available.
When RowSets are instantiated, the null constructor is used. If a null constructor is not available, the server takes the first constructor defined for that class and calls it with null parameters.
The initRowSets( ) method also creates a new DefaultTemplateMap and adds it into the request object. The DefaultTemplateMap is added as an attribute under the name GX_MAP.
Rule
Do not call initRowSets( ) from an EJB. No provision yet exists for instantiating RowSets from an EJB.
Return Value
Return codes defined in the IServletErrorHandler interface: SUCCESS if the method succeeds; otherwise, FAIL_DONT_STREAM_ERROR or FAIL_STREAM_ERROR.
Related Topics
IRowSet2 interface, IServletErrorHandler interface, DefaultTemplateMap class
log( )
Calls the log( ) method in the AppLogic class and logs an error to the error output.
Syntax 1
Logs a message (type = GXLOG.GXEVENTTYPE_INFORMATION and category = 0).
public static int log(
HttpServletRequest request,
String message)
Syntax 2
Logs an exception instead of a message:
public static int log(
HttpServletRequest request,
String message, // message is currently unused
Throwable t)
Syntax 3
Logs an event with a message, specifying the type and category of event:
public static int log(
HttpServletRequest request,
int type,
int category,
String message)
message.
The message text to log.
request.
The request object that contains the pointer to the AppLogic.
t.
The Throwable that caused the problem.
type.
The type of message to log. Use one of the following variables:
category.
User-defined message category. Do not use the range of values reserved for the Netscape Application Server systems, which is 0 to 65535, inclusive.
Usage
Use log( ) as a convenience method for calling the AppLogic's log( ) method and logging an error to the error output.
In Syntax 2, the request's streamError( ) method is called with a null response object. The IServletErrorHandler object is responsible for converting the exception to a string and then calling:
log(HttpServletRequest request, String message)
which is the log( ) method defined by Syntax 1.
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
log( ) in the AppLogic class, IServletErrorHandler interface
|