PAJES 2.3.9

org.pajes.servlet
Class Browser

java.lang.Object
  extended byorg.pajes.servlet.Browser

public class Browser
extends java.lang.Object

The Browser class is an abstraction of a Web browser.


Field Summary
static java.lang.String DEFAULT_CONTENT_TYPE_ATTRIBUTE
          Context attribute to set the default Content-Type header on the servlet response, if one has not already been set on the response when the Browser is instantiated.
static java.lang.String MAX_FILE_UPLOAD_SIZE_ATTRIBUTE
          Context attribute to set the default maximum number of bytes that can be uploaded to a servlet.
static java.lang.String USE_CLIENT_VALIDATION_ATTRIBUTE
          Context attribute to set whether JavaScript client validation will be generated or not.
static java.lang.String USE_COMPRESSION_ATTRIBUTE
          Context attribute to set whether compression of HTML documents is turned on or off by default.
static java.lang.String USE_DEFAULT_BASE_HREF_ATTRIBUTE
          Context attribute to set whether the base tag href= attribute in the document Head will be automatically generated or not.
static java.lang.String USE_ENCRYPTED_QUERY_PARAMETERS_ATTRIBUTE
          Context attribute to set whether automatic encryption of query parameters is turned on or off by default.
static java.lang.String USE_URL_ENCODING_ATTRIBUTE
          Context attribute to set whether URLs should be automatically encoded using HttpServletResponse.encodeURL by those objects that contain or represent a URL, such as Anchor or Form.
static java.lang.String USE_XHTML_ATTRIBUTE
          Context attribute to set whether the document written back to the browser should be XHTML compliant or not.
 
Constructor Summary
Browser()
          Creates a logical browser object.
Browser(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Creates a browser object.
Browser(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session)
          Creates a browser object.
 
Method Summary
 void close()
          Closes the output stream to complete sending the results back to the browser.
 java.lang.String getAppName()
          Returns the browser application name.
 javax.servlet.ServletContext getContext()
          Returns the ServletContext object.
static int getDefaultMaxFileUploadSize(javax.servlet.ServletContext context)
          Returns the default maximum number of bytes that can be uploaded to a servlet.
 double getIEVersion()
          Returns the version of Internet Explorer.
 double getNavigatorVersion()
          Returns the version of Netscape Navigator
 javax.servlet.ServletOutputStream getOutputStream()
          Returns the output stream to the browser.
 java.lang.String getPlatform()
          Returns the operating system platform the on which the browser is running.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the HttpServletRequest object that this Browser object wrappers.
 java.lang.String getRequestURL()
          Returns the HttpServletRequest URL.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the HttpServletResponse object that this Browser object wrappers.
 javax.servlet.http.HttpSession getSession()
          Returns the HttpSession object that this Browser object wrappers.
 UploadedFile getUploadedFile(java.lang.String sourceFileName)
          Returns the specified uploaded file instance.
 java.util.Enumeration getUploadedFileNames()
          Returns an Enumeration of String objects containing the names of the files uploaded in this request.
 java.lang.String getUserAgent()
          Returns the HTTP_USER_AGENT HTTP header.
 java.lang.String getVersion()
          Returns the full browser version string.
 boolean isClientValidationEnabled()
          Determines whether JavaScript client validation will be generated or not.
 boolean isDefaultBaseHREFEnabled()
          Returns whether or not automatic generation of the base tag href= attribute in the document Head is enabled.
 boolean isIE()
          Returns whether or not the browser is Internet Explorer.
 boolean isNavigator()
          Returns whether or not the browser is Netscape Navigator.
 boolean isQueryParameterEncryptionEnabled()
          Returns whether or not query parameter encryption is enabled.
 boolean isURLEncodingEnabled()
          Returns whether or not automatic URL encoding is enabled.
 boolean isXHTMLEnabled()
          Returns whether or not XHTML encoding is enabled.
 void parseUserAgent(java.lang.String userAgentHeader)
          Parses the USER-AGENT header and sets the associated internal variables.
 Browser setExpirationDate(long date)
          Sets the expiration date of the content to be returned to the browser.
 Browser setFilename(java.lang.String name)
          Sets the suggested filename of a downloadable attachment.
 Browser setLastModifiedDate(long date)
          Sets the last modified date of the content to be returned to the browser.
 Browser setNoCacheHeaders()
          Sets the appropriate headers to ensure the response will not be cached by the browser.
 Browser useClientValidation(boolean on)
          Determines whether JavaScript client validation will be generated or not.
 Browser useCompression(boolean compress)
          Determines whether the document should be written back to the browser using compression if the browser supports it.
 Browser useDefaultBaseHREF(boolean on)
          Determines whether the base tag href= attribute in the document Head will be automatically generated or not.
 Browser useEncryptedQueryParameters(boolean encrypt)
          Determines whether query parameters in, for example, anchors should be encrypted before being returned to the browser.
 Browser usePersistentConnection(boolean keepAlive)
          Deprecated. 2.3.2
 Browser useURLEncoding(boolean encode)
          Determines whether URLs should be automatically encoded using HttpServletResponse.encodeURL by those objects that contain or represent a URL, such as Anchor or Form.
 Browser useXHTML(boolean compliant)
          Determines whether the document written back to the browser should be XHTML compliant or not.
 Browser write(byte[] bytes)
          Sends an array of bytes to the browser.
 Browser write(java.lang.String text)
          Prints a line of formatted HTML to the browser, without a carriage return-line feed (CRLF) character.
 Browser writeln()
          Prints a carriage return-line feed (CRLF) character to the browser.
 Browser writeln(java.lang.String text)
          Prints a line of formatted HTML to the browser, followed by a carriage return-line feed (CRLF) character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE_ATTRIBUTE

public static final java.lang.String DEFAULT_CONTENT_TYPE_ATTRIBUTE
Context attribute to set the default Content-Type header on the servlet response, if one has not already been set on the response when the Browser is instantiated.

The value of this parameter defaults to "text/html" if not specified.

See Also:
Constant Field Values

MAX_FILE_UPLOAD_SIZE_ATTRIBUTE

public static final java.lang.String MAX_FILE_UPLOAD_SIZE_ATTRIBUTE
Context attribute to set the default maximum number of bytes that can be uploaded to a servlet.

See Also:
getDefaultMaxFileUploadSize(javax.servlet.ServletContext), Constant Field Values

USE_COMPRESSION_ATTRIBUTE

public static final java.lang.String USE_COMPRESSION_ATTRIBUTE
Context attribute to set whether compression of HTML documents is turned on or off by default.

See Also:
useCompression(boolean), Constant Field Values

USE_ENCRYPTED_QUERY_PARAMETERS_ATTRIBUTE

public static final java.lang.String USE_ENCRYPTED_QUERY_PARAMETERS_ATTRIBUTE
Context attribute to set whether automatic encryption of query parameters is turned on or off by default.

See Also:
useEncryptedQueryParameters(boolean), Constant Field Values

USE_URL_ENCODING_ATTRIBUTE

public static final java.lang.String USE_URL_ENCODING_ATTRIBUTE
Context attribute to set whether URLs should be automatically encoded using HttpServletResponse.encodeURL by those objects that contain or represent a URL, such as Anchor or Form.

See Also:
useURLEncoding(boolean), Constant Field Values

USE_XHTML_ATTRIBUTE

public static final java.lang.String USE_XHTML_ATTRIBUTE
Context attribute to set whether the document written back to the browser should be XHTML compliant or not.

See Also:
useXHTML(boolean), Constant Field Values

USE_DEFAULT_BASE_HREF_ATTRIBUTE

public static final java.lang.String USE_DEFAULT_BASE_HREF_ATTRIBUTE
Context attribute to set whether the base tag href= attribute in the document Head will be automatically generated or not.

See Also:
useDefaultBaseHREF(boolean), Constant Field Values

USE_CLIENT_VALIDATION_ATTRIBUTE

public static final java.lang.String USE_CLIENT_VALIDATION_ATTRIBUTE
Context attribute to set whether JavaScript client validation will be generated or not.

See Also:
useClientValidation(boolean), Constant Field Values
Constructor Detail

Browser

public Browser()
Creates a logical browser object.

This constructor is only used when the formatted HTML is required to be returned in a string or character array, rather then sent back to a physical browser.


Browser

public Browser(javax.servlet.ServletContext context,
               javax.servlet.http.HttpServletRequest request,
               javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException,
               javax.servlet.ServletException
Creates a browser object.

Parameters:
context - the servlet context.
request - the servlet request object.
response - the servlet response object.
Throws:
java.io.IOException - if an I/O error occurs.
javax.servlet.ServletException - if an unrecoverable exception occurs.

Browser

public Browser(javax.servlet.ServletContext context,
               javax.servlet.http.HttpServletRequest request,
               javax.servlet.http.HttpServletResponse response,
               javax.servlet.http.HttpSession session)
        throws java.io.IOException,
               javax.servlet.ServletException
Creates a browser object.

Parameters:
context - the servlet context.
request - the servlet request object.
response - the servlet response object.
session - the session object.
Throws:
java.io.IOException - if an I/O error occurs.
javax.servlet.ServletException - if an unrecoverable exception occurs.
Method Detail

getAppName

public java.lang.String getAppName()
Returns the browser application name.

Returns:
"Mozilla" for Netscape Navigator and Microsoft Internet Explorer, or the the same as getUserAgent() for any other browser.

isClientValidationEnabled

public boolean isClientValidationEnabled()
Determines whether JavaScript client validation will be generated or not.

Returns:
true if JavaScript client validation will be generated.

getContext

public javax.servlet.ServletContext getContext()
Returns the ServletContext object.

Returns:
the ServletContext object.

isDefaultBaseHREFEnabled

public boolean isDefaultBaseHREFEnabled()
Returns whether or not automatic generation of the base tag href= attribute in the document Head is enabled.

Returns:
true if automatic generation is enabled.
See Also:
useDefaultBaseHREF(boolean)

getDefaultMaxFileUploadSize

public static int getDefaultMaxFileUploadSize(javax.servlet.ServletContext context)
Returns the default maximum number of bytes that can be uploaded to a servlet.

This default value is determined from the web application deployment descriptor. To set the default value, create a <context-param> with a <param-name> of org.pajes.servlet.Browser.maxFileUploadSize, and a <param-value> containing the maximum number of bytes. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.maxFileUploadSize</param-name>
       <param-value>1048510</param-value>
   </context-param>
 

If the <context-param> does not exist, or the <param-value> does not contain a valid number, the default value of 1048510 will be used.

Parameters:
context - the servlet context from which the default value can be determined
Returns:
the maximum number of bytes that can be uploaded.
See Also:
PajeServlet.setMaxFileUploadSize(int)

setExpirationDate

public Browser setExpirationDate(long date)
Sets the expiration date of the content to be returned to the browser. Use -1 to expire the content immediately. If the header has already been set, the new value over-writes the previous one. Headers should always be set BEFORE sending any content.

Parameters:
date - the expiration date.
Returns:
the modified Browser object.

setFilename

public Browser setFilename(java.lang.String name)
Sets the suggested filename of a downloadable attachment.

Parameters:
name - the suggested file name.
Returns:
the modified Browser object.

isIE

public boolean isIE()
Returns whether or not the browser is Internet Explorer.

Returns:
true if the browser is Microsoft Internet Explorer.

getIEVersion

public double getIEVersion()
Returns the version of Internet Explorer.

Returns:
the Microsoft Internet Explorer version number, or zero for all other browsers or if the version number coud not be parsed.
See Also:
getVersion()

setLastModifiedDate

public Browser setLastModifiedDate(long date)
Sets the last modified date of the content to be returned to the browser. If the header has already been set, the new value over-writes the previous one. Headers should always be set BEFORE sending any content.

Parameters:
date - the last modified date.
Returns:
the modified Browser object.

isNavigator

public boolean isNavigator()
Returns whether or not the browser is Netscape Navigator.

Returns:
true if the browser is Netscape Navigator.

getNavigatorVersion

public double getNavigatorVersion()
Returns the version of Netscape Navigator

Returns:
the Netscape Navigator version number, or zero for all other browsers or if the version number coud not be parsed.
See Also:
getVersion()

setNoCacheHeaders

public Browser setNoCacheHeaders()
Sets the appropriate headers to ensure the response will not be cached by the browser.

Returns:
the modified Browser object.

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Returns the output stream to the browser.

Returns:
the output stream to send data back to the browser.
Throws:
java.io.IOException - if an I/O error occurs.

getPlatform

public java.lang.String getPlatform()
Returns the operating system platform the on which the browser is running.

Returns:
a string containing the platform on which either Netscape Navigator or Microsoft Internet Explorer is running, or and empty string for any other browser.

isQueryParameterEncryptionEnabled

public boolean isQueryParameterEncryptionEnabled()
Returns whether or not query parameter encryption is enabled.

Returns:
true if query parameter encryption is enabled.
See Also:
useEncryptedQueryParameters(boolean)

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the HttpServletRequest object that this Browser object wrappers.

Returns:
the underlying HttpServletRequest instance.

getRequestURL

public java.lang.String getRequestURL()
Returns the HttpServletRequest URL.

Returns:
the URL of this request.

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the HttpServletResponse object that this Browser object wrappers.

Returns:
the underlying HttpServletResponse instance.

getSession

public javax.servlet.http.HttpSession getSession()
Returns the HttpSession object that this Browser object wrappers.

Returns:
the HttpSession object.

isURLEncodingEnabled

public boolean isURLEncodingEnabled()
Returns whether or not automatic URL encoding is enabled.

Returns:
true if automatic URL encoding is enabled.
See Also:
useURLEncoding(boolean)

getUploadedFile

public UploadedFile getUploadedFile(java.lang.String sourceFileName)
Returns the specified uploaded file instance.

Parameters:
sourceFileName - the file name of the uploaded file to be retrieved.
Returns:
the uploaded file definition.
See Also:
getUploadedFileNames()

getUploadedFileNames

public java.util.Enumeration getUploadedFileNames()
Returns an Enumeration of String objects containing the names of the files uploaded in this request. If the request has no uploaded files, returns an empty Enumeration.

Returns:
an Enumeration of String objects, each String containing the source file name of an uploaded file; or an empty Enumeration if the request has no uploaded files.
See Also:
getUploadedFile(java.lang.String)

getUserAgent

public java.lang.String getUserAgent()
Returns the HTTP_USER_AGENT HTTP header.

Returns:
the full string from the HTTP header "HTTP_USER_AGENT".

getVersion

public java.lang.String getVersion()
Returns the full browser version string.

Returns:
the full version string (after "Mozilla") for Netscape Navigator and Microsoft Internet Explorer, or an empty string for any other browser.
See Also:
getIEVersion(), getNavigatorVersion()

isXHTMLEnabled

public boolean isXHTMLEnabled()
Returns whether or not XHTML encoding is enabled.

Returns:
true if XHTML encoding is enabled.
See Also:
useXHTML(boolean)

close

public void close()
           throws java.io.IOException
Closes the output stream to complete sending the results back to the browser. The OutputStream must always be closed, to ensure compression trailers are written correctly.

Throws:
java.io.IOException - if an I/O error occurs.

parseUserAgent

public void parseUserAgent(java.lang.String userAgentHeader)
Parses the USER-AGENT header and sets the associated internal variables.

Parameters:
userAgentHeader - the USER-AGENT header string.

useClientValidation

public Browser useClientValidation(boolean on)
Determines whether JavaScript client validation will be generated or not.

By default, generation is enabled. To disable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useClientValidation, and a <param-value> of false. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useClientValidation</param-name>
       <param-value>false</param-value>
   </context-param>
 

Parameters:
on - if false, suppreses the generation of JavaScript client validation.
Returns:
the modified Browser.

useCompression

public Browser useCompression(boolean compress)
Determines whether the document should be written back to the browser using compression if the browser supports it. This setting is ignored for logical browser objects, or if the OutputStream has already been opened.

By default, compression is disabled. To enable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useCompression, and a <param-value> of true. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useCompression</param-name>
       <param-value>true</param-value>
   </context-param>
 

WARNING! If compression is enabled, the output stream MUST be closed to correctly write the compression trailer.

Parameters:
compress - if true, the document will be written to the browser using an appropriate compression encoding, based on the "Accept-Encoding" HTTP header.
Returns:
the modified Browser.

useDefaultBaseHREF

public Browser useDefaultBaseHREF(boolean on)
Determines whether the base tag href= attribute in the document Head will be automatically generated or not.

By default, automatic generation is enabled. To disable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useDefaultBaseHREF, and a <param-value> of false. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useDefaultBaseHREF</param-name>
       <param-value>false</param-value>
   </context-param>
 

Parameters:
on - if false, suppreses the automatic generation of thebase tag href= attribute in the document Head.
Returns:
the modified Browser.

useEncryptedQueryParameters

public Browser useEncryptedQueryParameters(boolean encrypt)
Determines whether query parameters in, for example, anchors should be encrypted before being returned to the browser. This setting is ignored for logical browser objects, or if the OutputStream has already been opened.

By default, query parameter encryption is disabled. To enable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useEncryptedQueryParameters, and a <param-value> of true. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useEncryptedQueryParameters</param-name>
       <param-value>true</param-value>
   </context-param>
 

Parameters:
encrypt - if true, an URL encoded with Browser.getResponse().encodeURL(String) or Browser.getResponse().encodeRedirectURL(String) will have the any query parameters encrypted.
Returns:
the modified Browser.

usePersistentConnection

public Browser usePersistentConnection(boolean keepAlive)
Deprecated. 2.3.2

Deprecated.

Parameters:
keepAlive - the keep alive setting.
Returns:
the modified Browser.

useURLEncoding

public Browser useURLEncoding(boolean encode)
Determines whether URLs should be automatically encoded using HttpServletResponse.encodeURL by those objects that contain or represent a URL, such as Anchor or Form.

By default, encoding is disabled. To enable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useURLEncoding, and a <param-value> of true. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useURLEncoding</param-name>
       <param-value>true</param-value>
   </context-param>
 

Parameters:
encode - if true, those objects that contain or represent a URL, such as Anchor or Form, will automatically call HttpServletResponse.encodeURL.
Returns:
the modified Browser.

useXHTML

public Browser useXHTML(boolean compliant)
Determines whether the document written back to the browser should be XHTML compliant or not.

By default, XHTML compliance is enabled. To disable it as the default, the web application deployment descriptor must have a <context-param> with a <param-name> of org.pajes.servlet.Browser.useXHTML, and a <param-value> of false. For example:

   <context-param>
       <param-name>org.pajes.servlet.Browser.useXHTML</param-name>
       <param-value>false</param-value>
   </context-param>
 

Parameters:
compliant - if true, adds XHTML compliant headers to the document and does some basic XHTML compliance checking.
Returns:
the modified Browser.

write

public Browser write(java.lang.String text)
              throws java.io.IOException
Prints a line of formatted HTML to the browser, without a carriage return-line feed (CRLF) character.

Parameters:
text - the text to be sent to the browser.
Returns:
the modified Browser object.
Throws:
java.io.IOException - if an I/O error occurs.

write

public Browser write(byte[] bytes)
              throws java.io.IOException
Sends an array of bytes to the browser.

Parameters:
bytes - an array of bytes to be written to the output stream.
Returns:
the modified Browser object.
Throws:
java.io.IOException - if an I/O error occurs.

writeln

public Browser writeln()
                throws java.io.IOException
Prints a carriage return-line feed (CRLF) character to the browser.

Returns:
the modified Browser object.
Throws:
java.io.IOException - if an I/O error occurs.

writeln

public Browser writeln(java.lang.String text)
                throws java.io.IOException
Prints a line of formatted HTML to the browser, followed by a carriage return-line feed (CRLF) character.

Parameters:
text - the text to be sent to the browser.
Returns:
the modified Browser object.
Throws:
java.io.IOException - if an I/O error occurs.

PAJES 2.3.9

Copyright © 2002-2003 Viridian Pty Limited. All Rights Reserved.