com.teamdev.jxbrowser
Interface WebBrowser


public interface WebBrowser

Interface to an embedded web browser. Use WebBrowserFactory to create browser instances.

See Also:
RequestListener, StatusChangeListener, TitleChangeListener, ContextMenuListener, ContentHandler, WebBrowserPrinting, ClipboardSupport, BrowserAttributes, BadCertificateHandler

Method Summary
 void activate()
          Make browser component active.
 void addContentHandler(ContentHandler contentHandler)
          Register an object that can observe and intercept document loading based on content type.
 void addContextMenuListener(ContextMenuListener listener)
           
 void addHistoryChangeListener(HistoryChangeListener listener)
          Adds browser history change event listener
 void addRequestListener(RequestListener listener)
          Adds browser progress event listener.
 void addStatusChangeListener(StatusChangeListener listener)
           
 void addTitleChangeListener(TitleChangeListener listener)
           
 void deactivate()
          Make browser component inactive.
 void displayAsSource(boolean asSource)
          Switch browser to display source mode
 void dispose()
          Releases resources associated with this browser.
 java.lang.String evaluateScript(java.lang.String scriptString)
          Evaluate the script
 boolean findString(java.lang.String searchString)
          Search specific string in current document
 AsyncHandlerFactory getAsyncHandler()
          Returns current asynchronous operation handler of this browser object
 BrowserAttributes getAttributes()
          Returns current browser attributes
 boolean getCanGoBack()
          Deprecated. 
 boolean getCanGoForward()
          Deprecated. 
 ClipboardSupport getClipboardSupport()
          Returns interface for interact with the system-wide OS clipboard.
 java.awt.Component getComponent()
          Returns the AWT component that is hosting this web browser.
 org.w3c.dom.Document getDocument()
          Returns the DOM document wrapper for the document that is currently loaded in the browser.
 java.lang.String getDocumentContent(java.lang.String contentType)
          Returns browser document content as a string.
 WebBrowserHistory getHistory()
          Returns the browser navigation history.
 java.lang.String getLocationURL()
          Returns the URL of the resource that Mozilla web browser is currently displaying.
 WebBrowserPrinting getPrinting()
          Return the printing API for this web browser instance
 java.lang.String getTitle()
          Return the title of the browser.
 void goBack()
          Navigates backward one item in the history list.
 void goForward()
          Navigates forward one item in the history list.
 boolean isDisposed()
          Return disposed state
 void navigate(java.lang.String url)
          Navigates to a resource specified by a URL or to the file identified by a full path.
 void navigate(java.lang.String url, java.lang.String postData)
          Navigates to a resource specified by a URL or to the file identified by a full path.
 void pageDown()
          Scroll content down to one page
 void pageUp()
          Scroll content up to one page
 void refresh()
          Reloads the file that is currently displayed in the object.
 void removeContextMenuListener(ContextMenuListener listener)
           
 void removeHistoryChangeListener(HistoryChangeListener listener)
          Removes history change event listener
 void removeRequestListener(RequestListener listener)
          Removes browser progress event listener.
 void removeStatusChangeListener(StatusChangeListener listener)
           
 void removeTitleChangeListener(TitleChangeListener listener)
           
 void resetBadCertificateHandler(BadCertificateHandler newCertificateHandler)
          Reset the default BadCertificateHandler
 void saveCurrentDocument(java.io.File file, RequestListener requestListener)
          Save the current loaded document in to file.
 void saveURLtoFile(java.net.URL url, java.io.File file, RequestListener extendedListener)
          Save URL in to local file
 void setAsyncHandler(AsyncHandlerFactory handler)
          Set a handler that will be used for all asynchronous invocations within this browser object.
 void setAttributes(BrowserAttributes attributes)
          Apply new browser attributes
 void setContent(java.lang.String content, java.lang.String contentType)
          Shows specified content
 void setContent(java.lang.String content, java.lang.String contentType, java.lang.String charset)
          Shows specified content
 void setContentWithContext(java.lang.String content, java.lang.String contentType, java.lang.String contextURI)
          Shows specified content.
 void setFocusAtFirstElement()
          Set focus at first element.
 void setWindowCreator(WindowCreator childWindowCreator)
          Sets the implementation of the window creation for this browser.
 void showOpenFileDialog()
          Show open file dialog, and open the file.
 void showSaveFileDialog()
          Show save file dialog, and save the file.
 void stop()
          Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.
 java.awt.image.BufferedImage toImage()
          Return the image of the currently loaded web page or null when it's impossible to create an image of the web page.
 

Method Detail

navigate

void navigate(java.lang.String url)
Navigates to a resource specified by a URL or to the file identified by a full path.

Parameters:
url - URL to navigate to.

navigate

void navigate(java.lang.String url,
              java.lang.String postData)
Navigates to a resource specified by a URL or to the file identified by a full path. If the URL corresponds to a HTTP request and post data is provided, the Content-Type header will be set to application/x-www-form-urlencoded and the Content-Length header will be set to the post data length.

Parameters:
url - URL to navigate to.
postData - HTTP post data in the form name1=value1&name2=value2.

setContent

void setContent(java.lang.String content,
                java.lang.String contentType)
Shows specified content

Parameters:
content - content. Can be HTML.
contentType - content MIME Type. Should be text/html for HTML content. If null, contentType is set up to the text/html type.

setContent

void setContent(java.lang.String content,
                java.lang.String contentType,
                java.lang.String charset)
Shows specified content

Parameters:
content - content. Can be HTML.
contentType - content MIME Type. Should be text/html for HTML content. If null, contentType is set up to the text/html type.
charset - charset of the content. If null, charset is set up to the UTF-8

setContentWithContext

void setContentWithContext(java.lang.String content,
                           java.lang.String contentType,
                           java.lang.String contextURI)
Shows specified content. This method allows specifying a context for external reference resolution.

Parameters:
content - content. Can be HTML.
contentType - content MIME Type. Should be text/html for HTML content.
contextURI - the URI that is used as a context for external reference resolution.

getLocationURL

java.lang.String getLocationURL()
Returns the URL of the resource that Mozilla web browser is currently displaying.

Returns:
location URL

getTitle

java.lang.String getTitle()
Return the title of the browser.

Returns:
the title of the browser.

goForward

void goForward()
Navigates forward one item in the history list.


goBack

void goBack()
Navigates backward one item in the history list.


getCanGoBack

@Deprecated
boolean getCanGoBack()
Deprecated. 


getCanGoForward

@Deprecated
boolean getCanGoForward()
Deprecated. 


stop

void stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.


refresh

void refresh()
Reloads the file that is currently displayed in the object.


findString

boolean findString(java.lang.String searchString)
Search specific string in current document

Parameters:
searchString - string to find
Returns:
true if string was find

addRequestListener

void addRequestListener(RequestListener listener)
Adds browser progress event listener.

Parameters:
listener - browser event listener.

removeRequestListener

void removeRequestListener(RequestListener listener)
Removes browser progress event listener.

Parameters:
listener - browser event listener.

addStatusChangeListener

void addStatusChangeListener(StatusChangeListener listener)
Parameters:
listener - status change listener

removeStatusChangeListener

void removeStatusChangeListener(StatusChangeListener listener)
Parameters:
listener - status change listener

addTitleChangeListener

void addTitleChangeListener(TitleChangeListener listener)
Parameters:
listener - title change listener

removeTitleChangeListener

void removeTitleChangeListener(TitleChangeListener listener)
Parameters:
listener - title change listener

addContextMenuListener

void addContextMenuListener(ContextMenuListener listener)
Parameters:
listener - context menu listener

removeContextMenuListener

void removeContextMenuListener(ContextMenuListener listener)
Parameters:
listener - context menu listener

addHistoryChangeListener

void addHistoryChangeListener(HistoryChangeListener listener)
Adds browser history change event listener


removeHistoryChangeListener

void removeHistoryChangeListener(HistoryChangeListener listener)
Removes history change event listener

Parameters:
listener - history change listener listener

getComponent

java.awt.Component getComponent()
Returns the AWT component that is hosting this web browser.

Returns:
AWT component that is hosting this web browser

setWindowCreator

void setWindowCreator(WindowCreator childWindowCreator)
Sets the implementation of the window creation for this browser. This implementation will be used to handle all window creation requests made by this browser instance. Most common cases include links that open in new window and XUL-based message boxes.

Parameters:
childWindowCreator - window creator instance

getDocument

org.w3c.dom.Document getDocument()
Returns the DOM document wrapper for the document that is currently loaded in the browser. The returned document is live - it reflects all the changes to the current document.

NOTE: it is recommended to perform all operations on this object from within the XPCOM event dispatching thread.

Returns:
Mozilla's DOM object wrapper.

getHistory

WebBrowserHistory getHistory()
Returns the browser navigation history.

Returns:
browser navigation history

dispose

void dispose()
Releases resources associated with this browser. This object becomes unusable after this method is called.


isDisposed

boolean isDisposed()
Return disposed state


activate

void activate()
Make browser component active. After activation the component will be processing input events such as keyboard input and mouse wheel. Active component may "steal" focus after certain operations.


deactivate

void deactivate()
Make browser component inactive. Inactive component will not process some input event and is less likely to "steal" focus.


evaluateScript

java.lang.String evaluateScript(java.lang.String scriptString)
Evaluate the script

Parameters:
scriptString -
Returns:
evaluate result

setAsyncHandler

void setAsyncHandler(AsyncHandlerFactory handler)
Set a handler that will be used for all asynchronous invocations within this browser object.


getAsyncHandler

AsyncHandlerFactory getAsyncHandler()
Returns current asynchronous operation handler of this browser object


saveURLtoFile

void saveURLtoFile(java.net.URL url,
                   java.io.File file,
                   RequestListener extendedListener)
Save URL in to local file

Parameters:
url - URL to object what you want to save;
file - local file where object can be saved;
extendedListener - - this listener can be used to notify any GUI object (as JProgress bar), or something else different object, to saving data progress. This parameter is optional if you did't need any notification of saving progress (for example if file size is to little and load very fast) you can set this parameter to null. Otherwise you need implement this interface yourself ( for example see the realization of SaveImageAction class in com.teamdev.xpcom.mozilla.demo.JxBrowserDemo.java).

saveCurrentDocument

void saveCurrentDocument(java.io.File file,
                         RequestListener requestListener)
Save the current loaded document in to file.

Parameters:
file - local file where object can be saved;
requestListener - - this listener can be used to notify any GUI object (as JProgress bar), or something else different object, to saving data progress. This parameter is optional if you did't need any notification of saving progress (for example if file size is to little and load very fast) you can set this parameter to null. Otherwise you need implement this interface yourself

showOpenFileDialog

void showOpenFileDialog()
Show open file dialog, and open the file.


showSaveFileDialog

void showSaveFileDialog()
Show save file dialog, and save the file.


addContentHandler

void addContentHandler(ContentHandler contentHandler)
Register an object that can observe and intercept document loading based on content type.

Parameters:
contentHandler - content handler implementation

resetBadCertificateHandler

void resetBadCertificateHandler(BadCertificateHandler newCertificateHandler)
Reset the default BadCertificateHandler

Parameters:
newCertificateHandler - new BadCertificateHandler

getClipboardSupport

ClipboardSupport getClipboardSupport()
Returns interface for interact with the system-wide OS clipboard.

Returns:
clipboard manager interface.

getPrinting

WebBrowserPrinting getPrinting()
Return the printing API for this web browser instance


setFocusAtFirstElement

void setFocusAtFirstElement()
Set focus at first element.


setAttributes

void setAttributes(BrowserAttributes attributes)
Apply new browser attributes

Parameters:
attributes - the attributes structure

getAttributes

BrowserAttributes getAttributes()
Returns current browser attributes


displayAsSource

void displayAsSource(boolean asSource)
Switch browser to display source mode

Parameters:
asSource - TODO

getDocumentContent

java.lang.String getDocumentContent(java.lang.String contentType)
Returns browser document content as a string.

Parameters:
contentType - content type specification or null for default

pageUp

void pageUp()
Scroll content up to one page


pageDown

void pageDown()
Scroll content down to one page


toImage

java.awt.image.BufferedImage toImage()
Return the image of the currently loaded web page or null when it's impossible to create an image of the web page. Before invoking this method please make sure that the web page is loaded completely. To make sure that the web page is loaded completely use the StateEvent.isLoadingCompleted property in the RequestListener.stateChanged event.

Returns:
the image of the currently loaded web page or null.
See Also:
StateEvent, RequestListener