Package org.lobobrowser.html.test
Class SimpleHtmlRendererContext
java.lang.Object
org.lobobrowser.html.test.SimpleHtmlRendererContext
- All Implemented Interfaces:
HtmlRendererContext
The
SimpleHtmlRendererContext
class implements
the HtmlRendererContext
interface.
Note that this class provides rudimentary implementations
of most callback methods. Overridding some of the methods
in this class will usually be necessary in a professional application.
A simple way to load a URL into the HtmlPanel
of the
renderer context is to invoke navigate(String)
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected URLConnection
The connection currently opened by openSync() if any. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleHtmlRendererContext
(HtmlPanel contextComponent) Deprecated.SimpleHtmlRendererContext
(HtmlPanel contextComponent, HtmlRendererContext parentRcontext) Constructs a SimpleHtmlRendererContext that is a child of another
.HtmlRendererContext
SimpleHtmlRendererContext
(HtmlPanel contextComponent, UserAgentContext ucontext) Constructs a SimpleHtmlRendererContext. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Opens a simple message dialog.void
back()
It should navigate back one page.void
blur()
It should give up focus on the current browser window.void
close()
It should close the current browser window.boolean
Opens a simple confirmation window.Creates aBrowserFrame
instance.protected HTMLDocumentImpl
createDocument
(InputSource inputSource) Creates a blank document instance.void
void
void
focus()
It should request focus for the current browser window.void
forward()
Goes forward one page.Gets the current URL in history.Should return true if and only if the current browser window is closed.protected String
getDocumentCharset
(URLConnection connection) This method is invoked bysubmitForm(String, URL, String, String, FormInput[])
to determine the charset of a document.Gets a collection of current document frames, by querying the document currently held by the localHtmlPanel
instance.int
Gets the number of pages in the history list.getHtmlObject
(HTMLElement element) Returnsnull
.getName()
It should return the name of the browser window, if this renderer context is for the top frame in the window.Gets the next URL in the history.Gets the opener of the frame/window in the current context.Gets the parent of the frame/window in the current context.Gets the previous URL in the history.protected Proxy
getProxy()
Gets the connection proxy used innavigate(URL, String)
.Gets the source code of the current HTML document.Gets the window status text.getTop()
Gets the top-most browser frame/window.If aUserAgentContext
instance was provided in the constructor, then that instance is returned.void
goToHistoryURL
(String url) Navigates to a URL in the history list.boolean
isClosed()
Should return true if and only if the current browser window is closed.boolean
This method should return true if and only if image loading needs to be enabled.protected boolean
Indicates whether navigation (viasubmitForm(String, URL, String, String, FormInput[])
) should be asynchronous.boolean
isVisitedLink
(HTMLLinkElement link) Should be overridden to return true if the link has been visited.void
linkClicked
(HTMLElement linkNode, URL url, String target) Implements the link click handler by invokingnavigate(URL, String)
.void
moveInHistory
(int offset) Navigates the history according to the given offset.void
Convenience method provided to allow loading a document into the renderer.void
Implements simple navigation with incremental rendering by invokingsubmitForm(String, URL, String, String, FormInput[])
with aGET
request method.boolean
onContextMenu
(HTMLElement element, MouseEvent event) This method must be overridden to implement a context menu.boolean
onDoubleClick
(HTMLElement element, MouseEvent event) This method is called when there's a mouse double-click on an element.boolean
onMouseClick
(HTMLElement element, MouseEvent event) This method is called when there's a mouse click on an element.void
onMouseOut
(HTMLElement element, MouseEvent event) This method can be overridden to receive notifications when the mouse leaves an element.void
onMouseOver
(HTMLElement element, MouseEvent event) This method can be overridden to receive notifications when the mouse first enters an element.final HtmlRendererContext
Deprecated.It should open a new browser window.Shows a simple prompt dialog.void
reload()
Implements reload as navigation to current URL.void
resizeBy
(int byWidth, int byHeight) Resizes the window.void
resizeTo
(int width, int height) Resizes the window.void
scroll
(int x, int y) Changes the origin of the HTML block's scrollable area according to the position given.void
scrollBy
(int x, int y) Scrolls the client area.void
setDefaultStatus
(String message) void
setOpener
(HtmlRendererContext opener) Sets the context that opened the current frame/window.void
Sets the window status text.void
Implements simple navigation and form submission with incremental rendering and target processing, including frame lookup.protected void
Submits a form and/or navigates by making a synchronous request.void
void
-
Field Details
-
currentConnection
The connection currently opened by openSync() if any.
-
-
Constructor Details
-
SimpleHtmlRendererContext
Deprecated.Use constructor that takesHtmlPanel
andUserAgentContext
Constructs a SimpleHtmlRendererContext.- Parameters:
contextComponent
- The component that will render HTML.
-
SimpleHtmlRendererContext
Constructs a SimpleHtmlRendererContext.- Parameters:
contextComponent
- The component that will render HTML.- See Also:
-
SimpleHtmlRendererContext
Constructs a SimpleHtmlRendererContext that is a child of another
.HtmlRendererContext
- Parameters:
contextComponent
- The component that will render HTML.parentRcontext
- The parent's renderer context.
-
-
Method Details
-
getHtmlPanel
-
getSourceCode
Gets the source code of the current HTML document. -
getFrames
Gets a collection of current document frames, by querying the document currently held by the localHtmlPanel
instance.- Specified by:
getFrames
in interfaceHtmlRendererContext
-
reload
public void reload()Implements reload as navigation to current URL. Override to implement a more robust reloading mechanism.- Specified by:
reload
in interfaceHtmlRendererContext
-
linkClicked
Implements the link click handler by invokingnavigate(URL, String)
.- Specified by:
linkClicked
in interfaceHtmlRendererContext
- Parameters:
linkNode
- The HTML node that was clicked.url
- The destination URL.target
- Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
-
getProxy
Gets the connection proxy used innavigate(URL, String)
. This implementation callsSimpleUserAgentContext.getProxy()
ifgetUserAgentContext()
returns an instance assignable toSimpleUserAgentContext
. The method may be overridden to provide a different proxy setting. -
submitForm
public void submitForm(String method, URL action, String target, String enctype, FormInput[] formInputs) Implements simple navigation and form submission with incremental rendering and target processing, including frame lookup. Should be overridden to allow for more robust browser navigation and form submission.Notes:
- Document encoding is defined by
getDocumentCharset(URLConnection)
. - Caching is not implemented.
- Cookies are not implemented.
- Incremental rendering is not optimized for ignorable document change notifications.
- Other HTTP features are not implemented.
- The only form encoding type supported is
application/x-www-form-urlencoded
. - Navigation is normally asynchronous. See
isNavigationAsynchronous()
.
- Specified by:
submitForm
in interfaceHtmlRendererContext
- Parameters:
method
- The request method, GET or POST.action
- The destination URL.target
- Same as the target attribute in the FORM tag, i.e. _blank, _top, etc.enctype
- The encoding type.formInputs
- An array ofFormInput
instances.- See Also:
- Document encoding is defined by
-
submitFormSync
protected void submitFormSync(String method, URL action, String target, String enctype, FormInput[] formInputs) throws IOException, SAXException Submits a form and/or navigates by making a synchronous request. This method is invoked bysubmitForm(String, URL, String, String, FormInput[])
.- Parameters:
method
- The request method.action
- The action URL.target
- The target identifier.enctype
- The encoding type.formInputs
- The form inputs.- Throws:
IOException
SAXException
- See Also:
-
createDocument
Creates a blank document instance. This method is invoked whenever navigation or form submission occur. It is provided so it can be overridden to create specialized document implmentations.- Parameters:
inputSource
- The document input source.- Throws:
IOException
SAXException
-
getDocumentCharset
This method is invoked bysubmitForm(String, URL, String, String, FormInput[])
to determine the charset of a document. The charset is determined by looking at theContent-Type
header.- Parameters:
connection
- A URL connection.
-
alert
Opens a simple message dialog.- Specified by:
alert
in interfaceHtmlRendererContext
- Parameters:
message
- Message shown by the dialog.
-
blur
public void blur()It should give up focus on the current browser window. This implementation does nothing and should be overridden.- Specified by:
blur
in interfaceHtmlRendererContext
-
close
public void close()It should close the current browser window. This implementation does nothing and should be overridden.- Specified by:
close
in interfaceHtmlRendererContext
-
confirm
Opens a simple confirmation window.- Specified by:
confirm
in interfaceHtmlRendererContext
- Parameters:
message
- The message shown by the confirmation dialog.- Returns:
- True if the user selects YES.
-
focus
public void focus()It should request focus for the current browser window. This implementation does nothing and should be overridden.- Specified by:
focus
in interfaceHtmlRendererContext
-
open
public final HtmlRendererContext open(String url, String windowName, String windowFeatures, boolean replace) Deprecated.Description copied from interface:HtmlRendererContext
Opens a separate browser window and renders a URL.- Specified by:
open
in interfaceHtmlRendererContext
- Parameters:
url
- The URL to be rendered.windowName
- The name of the new window.windowFeatures
- The features of the new window (same as in Javascript open method).- Returns:
- A new
HtmlRendererContext
instance.
-
open
It should open a new browser window. This implementation does nothing and should be overridden.- Specified by:
open
in interfaceHtmlRendererContext
- Parameters:
url
- The requested URL.windowName
- A window identifier.windowFeatures
- Window features specified in a format equivalent to that of window.open() in Javascript.replace
- Whether an existing window with the same name should be replaced.- Returns:
- A new
HtmlRendererContext
instance.
-
prompt
Shows a simple prompt dialog.- Specified by:
prompt
in interfaceHtmlRendererContext
- Parameters:
message
- The message shown by the dialog.inputDefault
- The default input value.- Returns:
- The user's input value.
-
scroll
public void scroll(int x, int y) Changes the origin of the HTML block's scrollable area according to the position given.This method may be called outside of the GUI thread. The operation is scheduled immediately in that thread as needed.
- Specified by:
scroll
in interfaceHtmlRendererContext
- Parameters:
x
- The new x coordinate for the origin.y
- The new y coordinate for the origin.
-
scrollBy
public void scrollBy(int x, int y) Description copied from interface:HtmlRendererContext
Scrolls the client area.- Specified by:
scrollBy
in interfaceHtmlRendererContext
- Parameters:
x
- Horizontal pixels to scroll.y
- Vertical pixels to scroll.
-
isClosed
public boolean isClosed()Should return true if and only if the current browser window is closed. This implementation returns false and should be overridden.- Specified by:
isClosed
in interfaceHtmlRendererContext
-
getDefaultStatus
Should return true if and only if the current browser window is closed. This implementation returns false and should be overridden.- Specified by:
getDefaultStatus
in interfaceHtmlRendererContext
-
getName
It should return the name of the browser window, if this renderer context is for the top frame in the window. This implementation returns a blank string, so it should be overridden.- Specified by:
getName
in interfaceHtmlRendererContext
-
getParent
Description copied from interface:HtmlRendererContext
Gets the parent of the frame/window in the current context.- Specified by:
getParent
in interfaceHtmlRendererContext
-
getOpener
Description copied from interface:HtmlRendererContext
Gets the opener of the frame/window in the current context.- Specified by:
getOpener
in interfaceHtmlRendererContext
-
setOpener
Description copied from interface:HtmlRendererContext
Sets the context that opened the current frame/window.- Specified by:
setOpener
in interfaceHtmlRendererContext
- Parameters:
opener
- AHtmlRendererContext
.
-
getStatus
Description copied from interface:HtmlRendererContext
Gets the window status text.- Specified by:
getStatus
in interfaceHtmlRendererContext
-
setStatus
Description copied from interface:HtmlRendererContext
Sets the window status text.- Specified by:
setStatus
in interfaceHtmlRendererContext
- Parameters:
message
- A string.
-
getTop
Description copied from interface:HtmlRendererContext
Gets the top-most browser frame/window.- Specified by:
getTop
in interfaceHtmlRendererContext
-
createBrowserFrame
Description copied from interface:HtmlRendererContext
Creates aBrowserFrame
instance.- Specified by:
createBrowserFrame
in interfaceHtmlRendererContext
-
warn
-
error
-
warn
-
error
-
getHtmlObject
Returnsnull
. This method should be overridden to provide OBJECT, EMBED or APPLET functionality.- Specified by:
getHtmlObject
in interfaceHtmlRendererContext
- Parameters:
element
- The DOM element for the object, which may either represent an OBJECT, EMBED or an APPLET tag.- Returns:
- Implementations of this method must return
null
if they have any problems producing aHtmlObject
instance. This is particularly true of OBJECT tags, where inner HTML of the tag must be rendered if the OBJECT content cannot be handled.
-
setDefaultStatus
- Specified by:
setDefaultStatus
in interfaceHtmlRendererContext
-
getUserAgentContext
If aUserAgentContext
instance was provided in the constructor, then that instance is returned. Otherwise, an instance ofSimpleUserAgentContext
is created and returned.The context returned by this method is used by local request facilities and other parts of the renderer.
- Specified by:
getUserAgentContext
in interfaceHtmlRendererContext
-
isVisitedLink
Should be overridden to return true if the link has been visited.- Specified by:
isVisitedLink
in interfaceHtmlRendererContext
-
onContextMenu
This method must be overridden to implement a context menu.- Specified by:
onContextMenu
in interfaceHtmlRendererContext
- Parameters:
element
- The narrowest element enclosing the mouse location.event
- The mouse event.- Returns:
- The method should return true to continue propagating the event, or false to stop propagating it.
-
onMouseOut
This method can be overridden to receive notifications when the mouse leaves an element.- Specified by:
onMouseOut
in interfaceHtmlRendererContext
- Parameters:
element
- The element that the mouse has just exited.event
- The mouse event.
-
onMouseOver
This method can be overridden to receive notifications when the mouse first enters an element.- Specified by:
onMouseOver
in interfaceHtmlRendererContext
- Parameters:
element
- The element that the mouse has just entered.event
- The mouse event.
-
isImageLoadingEnabled
public boolean isImageLoadingEnabled()Description copied from interface:HtmlRendererContext
This method should return true if and only if image loading needs to be enabled.- Specified by:
isImageLoadingEnabled
in interfaceHtmlRendererContext
-
onDoubleClick
Description copied from interface:HtmlRendererContext
This method is called when there's a mouse double-click on an element.- Specified by:
onDoubleClick
in interfaceHtmlRendererContext
- Parameters:
element
- The narrowest element enclosing the mouse location.event
- The mouse event.- Returns:
- The method should return true to continue propagating the event, or false to stop propagating it.
-
onMouseClick
Description copied from interface:HtmlRendererContext
This method is called when there's a mouse click on an element.- Specified by:
onMouseClick
in interfaceHtmlRendererContext
- Parameters:
element
- The narrowest element enclosing the mouse location.event
- The mouse event.- Returns:
- The method should return true to continue propagating the event, or false to stop propagating it.
-
resizeBy
public void resizeBy(int byWidth, int byHeight) Description copied from interface:HtmlRendererContext
Resizes the window.- Specified by:
resizeBy
in interfaceHtmlRendererContext
- Parameters:
byWidth
- The number of pixels to resize the width by.byHeight
- The number of pixels to resize the height by.
-
resizeTo
public void resizeTo(int width, int height) Description copied from interface:HtmlRendererContext
Resizes the window.- Specified by:
resizeTo
in interfaceHtmlRendererContext
- Parameters:
width
- The new width.height
- The new height.
-
back
public void back()It should navigate back one page. This implementation does nothing and should be overridden.- Specified by:
back
in interfaceHtmlRendererContext
-
forward
public void forward()Description copied from interface:HtmlRendererContext
Goes forward one page.- Specified by:
forward
in interfaceHtmlRendererContext
-
getCurrentURL
Description copied from interface:HtmlRendererContext
Gets the current URL in history.- Specified by:
getCurrentURL
in interfaceHtmlRendererContext
-
getHistoryLength
public int getHistoryLength()Description copied from interface:HtmlRendererContext
Gets the number of pages in the history list.- Specified by:
getHistoryLength
in interfaceHtmlRendererContext
-
getNextURL
Description copied from interface:HtmlRendererContext
Gets the next URL in the history.- Specified by:
getNextURL
in interfaceHtmlRendererContext
-
getPreviousURL
Description copied from interface:HtmlRendererContext
Gets the previous URL in the history.- Specified by:
getPreviousURL
in interfaceHtmlRendererContext
-
goToHistoryURL
Description copied from interface:HtmlRendererContext
Navigates to a URL in the history list.- Specified by:
goToHistoryURL
in interfaceHtmlRendererContext
-
moveInHistory
public void moveInHistory(int offset) Description copied from interface:HtmlRendererContext
Navigates the history according to the given offset.- Specified by:
moveInHistory
in interfaceHtmlRendererContext
- Parameters:
offset
- A positive or negative number. -1 is equivalent toHtmlRendererContext.back()
. +1 is equivalent toHtmlRendererContext.forward()
.
-
HtmlPanel
andUserAgentContext