Jiffie: Java InterFace For Internet Explorer

net.sf.jiffie
Class JiffieUtility

Package class diagram package JiffieUtility
java.lang.Object
  extended by net.sf.jiffie.JiffieUtility

public final class JiffieUtility
extends java.lang.Object

This class contains utility methods used within jiffie.


Constructor Summary
JiffieUtility()
           
 
Method Summary
static Variant executeScript(IHTMLDocument2 doc, java.lang.String jsCode)
          Executes the jsCode in the context of m_explorer.
static ElementFactory getElementFactory()
          Retrieve the element factory used by this instance of Jiffie.
static EventHandlerFactory getEventHandlerFactory()
          Retrieve the event handler factory used by this instance of Jiffie.
static boolean getEventHandlingEnabled()
          Retrieves a flag indicating if event handling is enabled by default.
static int getMaxPollCount()
          Retrieves the maximum poll count
static int getPollTime()
          Retrieves the poll time.
static void sendKeys(java.lang.String title, java.lang.String keys)
          This method is used to send keystrokes to an arbitrary application.
static void sendKeys(java.lang.String title, java.lang.String keys, IHTMLDocument2 document)
          As per the sendKeys method this method sends keystrokes to an application.
static ElementFactory setElementFactory(ElementFactory factory)
          Sets the element factory used by this instance of Jiffie.
static EventHandlerFactory setEventHandlerFactory(EventHandlerFactory factory)
          Sets the event handler factory used by this instance of Jiffie.
static void setEventHandlingEnabled(boolean enabled)
          Sets a flag indicating if event handling is enabled by default.
static void setMaxPollCount(int maxPollCount)
          In order to allow Internet Explorer to finish whatever operation Jiffie has just asked it to do, we need to be able to poll the application's status.
static void setPollTime(int pollTime)
          In order to allow Internet Explorer to finish whatever operation Jiffie has just asked it to do, we need to be able to poll the application's status.
static void waitWhileIncomplete(IDispatch dispatch)
          This method waits until the dispatch interface indicates that it is "complete" (i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JiffieUtility

public JiffieUtility()
Method Detail

waitWhileIncomplete

public static void waitWhileIncomplete(IDispatch dispatch)
                                throws JiffieException
This method waits until the dispatch interface indicates that it is "complete" (i.e. it has finished loading, rendering etc.). The default is to time out after 30 seconds and throw an exception.

Parameters:
dispatch - dispatch interface
Throws:
JiffieException
See Also:
setPollTime(int), setMaxPollCount(int)

sendKeys

public static void sendKeys(java.lang.String title,
                            java.lang.String keys)
                     throws JiffieException
This method is used to send keystrokes to an arbitrary application. It uses the Windows Scripting Host to achieve this. This is used in Jiffie to allow users of the library to deal with modal dialog boxes. If for example a user clicks a link which causes a Javascript dialog to be displayed, the click method will block until the dialog is dismissed. To get around this, the click method must be called from a separate thread (see the BlockingClickThread class), and the main thread can then use this method to send keystrokes to the modal dialog to perform the appropriated actions. Details of the keystrokes that can be sent using this method can be found at the following URL: http://msdn.microsoft.com/library/en-us/script56/html/wsmthsendkeys.asp Note that if the call to "AppActivate" fails, i.e. we have not been able to set focus to the expected window, this method will poll to repeat the operation, and eventually time out and throw an exception. This will indicate to the caller that the keystrokes have not been successfully sent to the named window.

Parameters:
title - expected dialog title
keys - keystrokes to send to the dialog
Throws:
JiffieException

sendKeys

public static void sendKeys(java.lang.String title,
                            java.lang.String keys,
                            IHTMLDocument2 document)
                     throws JiffieException
As per the sendKeys method this method sends keystrokes to an application. In this case we assume that the application is the parent browser of the supplied document object, and we wait for the document object to be marked as complete before we return control back to the caller.

Parameters:
title - expected dialog title
keys - keystrokes to send to the dialog
document - document object
Throws:
JiffieException

setPollTime

public static void setPollTime(int pollTime)
In order to allow Internet Explorer to finish whatever operation Jiffie has just asked it to do, we need to be able to poll the application's status. Jiffie achieves this by testing the state of Internet Explorer, and if it is not ready, sleeping for a period, then testing again. This polling operation repeats for a number of iterations, and if Internet Explorer is still not in the desired state, Jiffie throws an exception. This method allows the sleep time between testing Internet Explorer's state to be set. The default setting is to test the status every 500ms for 60 attempts (i.e. a total of 30 seconds) then abort if the desired status has not been achieved. This method is not designed to be thread safe, when using Jiffie from multiple threads, this method should be called before the threads are launched.

Parameters:
pollTime - sleep time between status tests in milliseconds

setMaxPollCount

public static void setMaxPollCount(int maxPollCount)
In order to allow Internet Explorer to finish whatever operation Jiffie has just asked it to do, we need to be able to poll the application's status. Jiffie achieves this by testing the state of Internet Explorer, and if it is not ready, sleeping for a period, then testing again. This polling operation repeats for a number of iterations, and if Internet Explorer is still not in the desired state, Jiffie throws an exception. This method allows the number of attempts made to test Internet Explorer's state to be set. The default setting is to test the status 60 times, once every 500ms (i.e. a total of 30 seconds) then abort if the desired status has not been achieved. This method is not designed to be thread safe, when using Jiffie from multiple threads, this method should be called before the threads are launched.

Parameters:
maxPollCount - maximum number of status tests before aborting

getPollTime

public static int getPollTime()
Retrieves the poll time.

Returns:
poll time

getMaxPollCount

public static int getMaxPollCount()
Retrieves the maximum poll count

Returns:
maximum poll count

getEventHandlingEnabled

public static boolean getEventHandlingEnabled()
Retrieves a flag indicating if event handling is enabled by default.

Returns:
boolean flag

setEventHandlingEnabled

public static void setEventHandlingEnabled(boolean enabled)
Sets a flag indicating if event handling is enabled by default. If you do not require event handling then disabling event handling by setting this flag to false will improve Jiffie's performance and stability. Note that if you want to handle any new browser windows launched when using Jiffie, you'll need to leave this flag set to true.

Parameters:
enabled - event handling enabled flag

getEventHandlerFactory

public static EventHandlerFactory getEventHandlerFactory()
Retrieve the event handler factory used by this instance of Jiffie.

Returns:
event handler factory

setEventHandlerFactory

public static EventHandlerFactory setEventHandlerFactory(EventHandlerFactory factory)
Sets the event handler factory used by this instance of Jiffie.

Parameters:
factory - event handler factory
Returns:
returns the previous event handler factory instance

getElementFactory

public static ElementFactory getElementFactory()
Retrieve the element factory used by this instance of Jiffie.

Returns:
element factory

setElementFactory

public static ElementFactory setElementFactory(ElementFactory factory)
Sets the element factory used by this instance of Jiffie.

Parameters:
factory - element factory
Returns:
returns the previous element factory instance

executeScript

public static Variant executeScript(IHTMLDocument2 doc,
                                    java.lang.String jsCode)
                             throws JiffieException
Executes the jsCode in the context of m_explorer.

It does this by creating the following html in the body of the document:

<script> function jiffieUnitExecuteScript() { var code = document.getElementById("jiffie_jscode").value; var d=document.getElementById("jiffie_result"); d.retVal = eval(code); } document.getElementById("jiffie_result").onclick=jiffieUnitExecuteScript;"); </script> <input id="jiffie.jscode" type="text"/> <DIV id="jiffie.retVal"/> The value of the input box is set with the jsCode, and executed by triggering an onclick event on the div. The return value is then obtained from the div element and returned.

Parameters:
doc - target document for javascript execution
jsCode - Javascript code to be executed.
Returns:
The object (dispatch if it is a dom element) returned by the javascript.
Throws:
JiffieException


Copyright © 2004-2009 Packwood Software. All Rights Reserved.