|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface WebBrowser
The WebBrowser
defines the base web browser
interface and its various capabilities. This interface provides
functionality that allows working with WebBrowser Control.
WebBrowser
instance you
should destroy it by invoking its close()
method.
- Java component that implements this interface and can be
embedded in a Swing UI
,
- UI-less implementation of this interface
,
- an Automation-based browser component which
you can use without embedding in a Swing UI
Nested Class Summary | |
---|---|
static class |
WebBrowser.Properties
Represents a set of event names that can be handled in the PropertyChangeListener listener. |
Method Summary | |
---|---|
void |
addBrowserWindowListener(BrowserWindowListener listener)
Adds window listener. |
void |
addDisposeListener(DisposeListener listener)
Registers the listener for the current Browser instance
that will receive events when the current Browser instance
is disposed. |
void |
addNavigationListener(NavigationEventListener listener)
Adds browser navigation event listener. |
void |
addNewWindowListener(NewWindowEventListener listener)
Adds new window listener. |
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Adds a new property change listener. |
void |
addStatusListener(StatusEventListener listener)
Adds browser status event listener. |
void |
close()
Closes and disposes the current WebBrowser instance. |
void |
execute(BrowserCommand command)
Executes the specified WebBrowser command. |
java.lang.Object |
executeScript(java.lang.String javaScript)
Executes specified JavaScript code in a currently opened document. |
AuthenticationHandler |
getAuthenticationHandler()
Returns the current browser authentication handler or null if it's was not specified. |
java.lang.Object |
getBrowserPeer()
Returns an instance of the native WebBrowser peer as an instance of the IWebBrowser2 interface. |
java.lang.String |
getContent()
Returns the string that represents HTML content of a currently loaded document in WebBrowser. |
java.lang.String |
getContent(boolean original)
Returns the string that represents HTML content of a currently loaded document in WebBrowser. |
java.util.Set<Cookie> |
getCookies(java.lang.String url)
Returns cookies, that are associated with the specified URL. |
java.util.Set<Cookie> |
getCookies(java.net.URL url)
Returns cookies, that are associated with the specified URL. |
DialogEventHandler |
getDialogEventHandler()
Returns the dialog events handler or null if it's
was not specified. |
DisposeListener[] |
getDisposeListeners()
Returns an array of all registered listeners for the current Browser instance. |
org.w3c.dom.html.HTMLDocument |
getDocument()
Returns an instance of HTMLDocument that
represents the HTML document currently loaded into
the WebBrowser and provides access to the contents of
the HTML Document Object Model (DOM). |
WebBrowserEventsHandler |
getEventHandler()
Returns browser event handler. |
HttpSecurityHandler |
getHttpSecurityHandler()
Returns http security handler that allows processing any security problems or null if it's not present. |
KeyFilter |
getKeyFilter()
Returns key filter. |
java.lang.String |
getLocationURL()
Returns the string that represents a URL of the resource that WebBrowser component is currently displayed. |
java.util.List |
getNavigationListeners()
Returns browser navigation event listeners. |
NewWindowEventHandler |
getNewWindowHandler()
Returns new window handler. |
java.util.List |
getNewWindowListeners()
Returns new window listeners. |
com.jniwrapper.win32.automation.OleMessageLoop |
getOleMessageLoop()
Returns the OleMessageLoop thread in which executes all WebBrowser component operations. |
WebBrowser |
getParentBrowser()
Returns the parent of the current WebBrowser instance or null if it hasn't parent. |
WebBrowser.Properties |
getProperties()
Returns extended browser properties. |
ProxyConfiguration |
getProxy()
Returns the proxy settings for the current WebBrowser control and all its children. |
ReadyState |
getReadyState()
Returns the current ReadyState of the WebBrowser Control. |
ScriptErrorListener |
getScriptErrorListener()
Returns script error listener for current page. |
java.util.List |
getStatusListeners()
Returns browser status event listeners. |
int |
getZoomValue()
|
void |
goBack()
Navigates backward one item in the history list. |
void |
goForward()
Navigates forward one item in the history list. |
void |
goHome()
Navigates to the current home or start page. |
boolean |
isClosed()
Returns true if the WebBrowser instance is closed and disposed. |
boolean |
isSilent()
Return true if alert, confirmation and error dialogs are disabled else returns false. |
void |
navigate(java.lang.String location)
Navigates to a resource identified by a URL or to a file identified by a full path. |
void |
navigate(java.lang.String location,
java.lang.String postData)
Navigates to a web resource specified by a HTTP URL with HTTP post data. |
void |
navigate(java.lang.String location,
java.lang.String targetName,
java.lang.String postData)
Navigates to an entire web resource specified by a HTTP URL with HTTP post data into a specified window defined by targetName. |
void |
navigate(java.lang.String location,
java.lang.String targetName,
java.lang.String postData,
java.lang.String headers)
Navigates to an entire web resource specified by a HTTP URL with HTTP post data into a specified window defined by targetName. |
void |
refresh()
Reloads the file that is currently displayed in the object. |
void |
removeBrowserWindowListener(BrowserWindowListener listener)
Removes window listener. |
void |
removeDisposeListener(DisposeListener listener)
Removes the listener so that it will not receive events
when the current Browser instance is disposed. |
void |
removeNavigationListener(NavigationEventListener listener)
Removes browser navigation event listener. |
void |
removeNewWindowListener(NewWindowEventListener listener)
Removes new window listener. |
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Removes a specified property change listener. |
void |
removeStatusListener(StatusEventListener listener)
Removes browser status event listener. |
void |
setAuthenticationHandler(AuthenticationHandler handler)
Sets the specified browser authentication handler. |
void |
setContent(java.lang.String htmlContent)
Sets the specified HTML content to the current WebBrowser document. |
void |
setCookie(java.lang.String url,
Cookie cookie)
Creates a new cookie for the specified URL using WinINet API. |
void |
setCookies(java.net.URL url,
java.util.Set<Cookie> cookies)
Creates a new cookies for the specified URL using WinINet API. |
void |
setDialogEventHandler(DialogEventHandler handler)
Sets the listener interface for receiving show dialog events. |
void |
setEventHandler(WebBrowserEventsHandler handler)
Sets browser event handler. |
void |
setHttpSecurityHandler(HttpSecurityHandler h)
Sets the specified HTTP security handler that allows processing any security problems such as Invalid Certificate error, Invalid Certificate Name, Invalid Certificate Date, Moving from a non-SSL to an SSL connection because of a redirect or The redirection requires user confirmation problems. |
void |
setKeyFilter(KeyFilter keyFilter)
Sets key filter. |
void |
setNewWindowHandler(NewWindowEventHandler newWindowHandler)
Sets new window handler. |
void |
setParentBrowser(WebBrowser webBrowser)
Sets the parent of the WebBrowser instance. |
void |
setProxy(ProxyConfiguration conf)
Sets the specified proxy settings for the current WebBrowser control and all its children. |
void |
setScriptErrorListener(ScriptErrorListener listener)
Setups javascript error listener for current page. |
void |
setSilent(boolean isSilent)
Disables or enables alert, confirmation and error dialogs. |
void |
setZoomValue(int value)
|
void |
stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations. |
void |
waitReady()
Causes a current thread to wait for the completion of the current operation in the browser. |
void |
waitReady(long timeout)
Causes a current thread to wait for the completion of a current operation in the browser for a specified amount of milliseconds. |
Methods inherited from interface com.jniwrapper.win32.ie.ParentWindow |
---|
getRecentChild, trackChildren, waitChildCreation, waitChildCreation |
Method Detail |
---|
void navigate(java.lang.String location)
location
- the URL of the resource to display or
the full path to the file location. The
parameter cannot be null
.
java.lang.IllegalArgumentException
- when location parameter is null.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String, String)
,
navigate(String, String, String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
void navigate(java.lang.String location, java.lang.String postData)
location
- the URL of the resource to display or
the full path to the file location. The
parameter cannot be null
.postData
- HTTP post data (for example, "name=Alex&product=Pizza"),
can be null
.
java.lang.IllegalArgumentException
- when location parameter is null.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String)
,
navigate(String, String, String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
void navigate(java.lang.String location, java.lang.String targetName, java.lang.String postData)
location
- the URL of the resource to display or
the full path to the file location. The
parameter cannot be null
.targetName
- The string that contains the name of the
frame in which to display the resource.
The possible values for this parameter are.
postData
- HTTP post data (for example, "name=Alex&product=Pizza").
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String)
,
navigate(String, String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
void navigate(java.lang.String location, java.lang.String targetName, java.lang.String postData, java.lang.String headers)
location
- the URL of the resource to display or
the full path to the file location. The
parameter cannot be null
.targetName
- The string that contains the name of the
frame in which to display the resource.
The possible values for this parameter are.
postData
- HTTP post data (for example, "name=Alex&product=Pizza").headers
- The string that contains additional HTTP headers to send
to the server. These headers are added to the default
Windows Internet Explorer headers. For example, headers
can specify the action required of the server, the type
of data being passed to the server, or a status code.
This parameter is ignored if the URL is not an HTTP
(or HTTPS) URL.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String)
,
navigate(String, String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
java.lang.String getLocationURL()
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
org.w3c.dom.html.HTMLDocument getDocument()
HTMLDocument
that
represents the HTML document currently loaded into
the WebBrowser and provides access to the contents of
the HTML Document Object Model (DOM).
Before receiving an instance of HTMLDocument
make sure that the entire document is loaded completely.
For this you can use the
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
event.
java.lang.IllegalStateException
- when WebBrowser.waitReady()
method isn't called after last call of
WebBrowser.navigate()
or
WebBrowser.setContent()
methods;
or when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.waitReady()
,
navigate(String)
,
setContent(String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
WebBrowser getParentBrowser()
null
if it hasn't parent. If the WebBrowser
control is in a frame, this method returns the WebBrowser
instance of the main document that contains this frame.
Otherwise, it delegates to the top-level WebBrowser control,
if there is one.
null
if the browser hasn't parent.Browser.getParentBrowser()
,
HeadlessBrowser.getParentBrowser()
,
IEAutomation.getParentBrowser()
void setParentBrowser(WebBrowser webBrowser)
webBrowser
- the parent of the browser.void goForward()
StatusEventListener.forwardButtonEnabled
event to check the enabled state of forward navigation.
To manage WebBrowser's history use the BrowserHistory
class.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.goBack()
,
goHome()
,
BrowserHistory
void goBack()
StatusEventListener.backButtonEnabled
event to check the enabled state of back navigation.
To manage WebBrowser's history use the BrowserHistory
class.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.goForward()
,
goHome()
,
BrowserHistory
void goHome()
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.goForward()
,
goBack()
void stop()
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.refresh()
,
navigate(String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
void refresh()
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.void execute(BrowserCommand command)
BrowserCommand
abstract class.
For example, to print currently loaded web page, the following
command should be executed:
WebBrowser browser = new HeadlessBrowser();
browser.execute(new PrintCommand());
command
- the specified WebBrowser command.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.PrintCommand
,
PrintPreviewCommand
,
SaveAsCommand
void setContent(java.lang.String htmlContent)
NavigationEventListener.entireDocumentCompleted
event.
It may be necessary when the document contains some resources
(such as images or JavaScript files) that require some time to
download.
htmlContent
- a string that represents HTML content
to set to the current document.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String)
,
navigate(String, String)
,
navigate(String, String, String)
,
getContent()
,
getContent(boolean)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
java.lang.String getContent()
NavigationEventListener.entireDocumentCompleted
event.
Note: the outerHTML propertry of the document HTML element
is used in this method. So, it always returns the actual HTML of
the document. To get the HTML that was downloaded from the server
use the getContent(true)
method.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.setContent(String)
,
getContent(boolean)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
java.lang.String getContent(boolean original)
NavigationEventListener.entireDocumentCompleted
event.
original
- if true
then returns the original
HTML content (like View Source command in context
menu of Internet Explorer browser), otherwise this method
returns the actual content of a document according to its DOM.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.getContent()
,
setContent(String)
,
NavigationEventListener.entireDocumentCompleted(WebBrowser, String)
java.lang.Object executeScript(java.lang.String javaScript)
IHTMLWindow2.execScript
method
can access all global variables available to the calling script.
javaScript
- the string that specifies the code to be executed.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.ReadyState getReadyState()
ReadyState
of the WebBrowser Control.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
WebBrowser.Properties
class.
propertyName
- property name.listener
- listener instance.void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
WebBrowser.Properties
class.
propertyName
- property name.listener
- listener instance.void waitReady()
Important: successful call of this method guaranties that you
can get DOM document of loaded page.
Please see typical usage of this method in the code below:
// navigate to Google page
browser.navigate("google.com");
// wait until page completely loaded
browser.waitReady();
// DOM document is available
Document document = browser.getDocument();
WebBrowser.waitReady()
call after navigation call
then IllegalStateException is thrown in WebBrowser.getDocument()
call.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.navigate(String)
,
setContent(String)
,
getDocument()
void waitReady(long timeout)
timeout
- the number of milliseconds to wait.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.java.lang.Object getBrowserPeer()
IWebBrowser2
interface. The
returned value can be casted to IWebBrowser2
interface.
java.lang.IllegalStateException
- when the passed browser does not have
a native peer or WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.void addNavigationListener(NavigationEventListener listener)
listener
- browser event listener.void removeNavigationListener(NavigationEventListener listener)
listener
- browser event listener.java.util.List getNavigationListeners()
void addStatusListener(StatusEventListener listener)
listener
- browser event listener.void removeStatusListener(StatusEventListener listener)
listener
- browser event listener.java.util.List getStatusListeners()
void setEventHandler(WebBrowserEventsHandler handler)
handler
- event handlerWebBrowserEventsHandler getEventHandler()
void setAuthenticationHandler(AuthenticationHandler handler)
handler
- the authentication handler
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.getAuthenticationHandler()
AuthenticationHandler getAuthenticationHandler()
null
if it's was not specified. The
authentication handler allows handling the authenticate
events from the browser object. Currently supported the
basic, digest and NTLM authentication schemes.
By default this method always returns null
.
null
.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.setAuthenticationHandler(AuthenticationHandler)
void setDialogEventHandler(DialogEventHandler handler)
DialogEventHandler
. Please see the
Browser.setDialogEventHandler(com.jniwrapper.win32.ie.event.DialogEventHandler)
and
HeadlessBrowser.setDialogEventHandler(com.jniwrapper.win32.ie.event.DialogEventHandler)
method.
handler
- dialog event handler
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.getDialogEventHandler()
,
setSilent(boolean)
,
isSilent()
,
Browser.setDialogEventHandler(com.jniwrapper.win32.ie.event.DialogEventHandler)
,
HeadlessBrowser.setDialogEventHandler(com.jniwrapper.win32.ie.event.DialogEventHandler)
DialogEventHandler getDialogEventHandler()
null
if it's
was not specified.
By default this method returns the default implementation of
the DialogEventHandler
which is different for each
implementation of the WebBrowser
interface.
Please see the Browser.getDialogEventHandler()
and
HeadlessBrowser.getDialogEventHandler()
method.
null
if it's
was not specified.
java.lang.IllegalStateException
- when WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.setDialogEventHandler(DialogEventHandler)
,
setSilent(boolean)
,
isSilent()
,
Browser.getDialogEventHandler()
,
HeadlessBrowser.getDialogEventHandler()
void setScriptErrorListener(ScriptErrorListener listener)
listener
- javascript error listenerScriptErrorListener getScriptErrorListener()
void close()
IllegalStateException
error. Use this method when
you don't need the WebBrowser instance anymore.
You should invoke this method to destroy all not daemon threads which
are Browser instance is used. If you do not invoke this method, then
your Java application will not exit as expected - without invoking
System.exit(0)
method.
isClosed()
boolean isClosed()
true
if the WebBrowser instance is closed and disposed.
Use this method when you need to make sure that the WebBrowser instance
is alive and you can invoke its methods.
true
if the WebBrowser instance is closed and disposed.close()
void setSilent(boolean isSilent)
This method call modifies dialog event handler through
setDialogEventHandler()
call.
isSilent
- if true then enter to silent mode else leave silent mode.boolean isSilent()
void setCookie(java.lang.String url, Cookie cookie)
InternetSetCookie
native function.
url
- specifies an URL, a new cookie will be associated with.cookie
- specifies a new cookie.java.util.Set<Cookie> getCookies(java.lang.String url)
InternetGetCookie
native function.
url
- specifies an URL.
void setNewWindowHandler(NewWindowEventHandler newWindowHandler)
newWindowHandler
- new window handlerNewWindowEventHandler getNewWindowHandler()
void addNewWindowListener(NewWindowEventListener listener)
listener
- new window listenervoid removeNewWindowListener(NewWindowEventListener listener)
listener
- new window listenerjava.util.List getNewWindowListeners()
void setKeyFilter(KeyFilter keyFilter)
keyFilter
- key filterKeyFilter getKeyFilter()
WebBrowser.Properties getProperties()
void addBrowserWindowListener(BrowserWindowListener listener)
listener
- the window listenervoid removeBrowserWindowListener(BrowserWindowListener listener)
listener
- the window listenercom.jniwrapper.win32.automation.OleMessageLoop getOleMessageLoop()
void setProxy(ProxyConfiguration conf)
Browsers.setProxy(ProxyConfiguration)
method.
conf
- the proxy settings. This parameter cannot be
null
.
java.lang.IllegalStateException
- when the passed browser does not have
a native peer or WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.getProxy()
,
Browsers.setProxy(ProxyConfiguration)
ProxyConfiguration getProxy()
Browsers.getProxy()
method.
java.lang.IllegalStateException
- when the passed browser does not have
a native peer or WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.setProxy(ProxyConfiguration)
,
Browsers.getProxy()
java.util.Set<Cookie> getCookies(java.net.URL url)
It checks in the windows\cookies directory for persistent cookies that have an expiration date set sometime in the future.
It also searches memory for any session cookies, that is, cookies that do not have an expiration date that were created in the same process by CookieManager.setCookie(), because these cookies are not written to any files. Rules for creating cookie files are internal to the system and can change in the future.
Note: The method does not return cookies that the server marked as non-scriptable with the "HttpOnly" attribute in the Set-Cookie header.
url
- specifies an URL.
void setCookies(java.net.URL url, java.util.Set<Cookie> cookies)
Cookies created by this method without an expiration date are stored in memory and are available only in the same process that created them. Cookies that include an expiration date are stored in the windows\cookies directory.
url
- specifies an URL, a new cookie will be associated with.cookies
- the collection of Cookie
objects.void setHttpSecurityHandler(HttpSecurityHandler h)
h
- the specified HTTP security handler.
java.lang.IllegalStateException
- when the passed browser does not have
a native peer or WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.getHttpSecurityHandler()
HttpSecurityHandler getHttpSecurityHandler()
null
if it's not present. By default this
method always returns null
and all security problems are
processing by default Internet Explorer security handler.
null
if it's not present
java.lang.IllegalStateException
- when the passed browser does not have
a native peer or WebBrowser component was
disposed by invoking WebBrowser.close()
method or for some unknown reasons.setHttpSecurityHandler(com.jniwrapper.win32.ie.event.HttpSecurityHandler)
void addDisposeListener(DisposeListener listener)
listener
for the current Browser instance
that will receive events when the current Browser instance
is disposed.
listener
- the listener to receive browser dispose events.void removeDisposeListener(DisposeListener listener)
listener
so that it will not receive events
when the current Browser instance is disposed.
listener
- the listener to remove.DisposeListener[] getDisposeListeners()
int getZoomValue()
void setZoomValue(int value)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |