org.lobobrowser.html.test
public class SimpleHtmlRendererContext extends java.lang.Object implements HtmlRendererContext
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)
.
Modifier and Type | Field and Description |
---|---|
protected java.net.URLConnection |
currentConnection
The connection currently opened by openSync() if any.
|
Constructor and Description |
---|
SimpleHtmlRendererContext(HtmlPanel contextComponent)
Deprecated.
Use constructor that takes
HtmlPanel and UserAgentContext |
SimpleHtmlRendererContext(HtmlPanel contextComponent,
HtmlRendererContext parentRcontext)
Constructs a SimpleHtmlRendererContext that is a child of another
. |
SimpleHtmlRendererContext(HtmlPanel contextComponent,
UserAgentContext ucontext)
Constructs a SimpleHtmlRendererContext.
|
Modifier and Type | Method and Description |
---|---|
void |
alert(java.lang.String message)
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 |
confirm(java.lang.String message)
Opens a simple confirmation window.
|
BrowserFrame |
createBrowserFrame()
Creates a
BrowserFrame instance. |
protected HTMLDocumentImpl |
createDocument(org.xml.sax.InputSource inputSource)
Creates a blank document instance.
|
void |
error(java.lang.String message) |
void |
error(java.lang.String message,
java.lang.Throwable throwable) |
void |
focus()
It should request focus for the current browser window.
|
void |
forward()
Goes forward one page.
|
java.lang.String |
getCurrentURL()
Gets the current URL in history.
|
java.lang.String |
getDefaultStatus()
Should return true if and only if the current browser window is closed.
|
protected java.lang.String |
getDocumentCharset(java.net.URLConnection connection)
This method is invoked by
submitForm(String, URL, String, String, FormInput[])
to determine the charset of a document. |
HTMLCollection |
getFrames()
Gets a collection of current document frames, by querying
the document currently held by the local
HtmlPanel
instance. |
int |
getHistoryLength()
Gets the number of pages in the history list.
|
HtmlObject |
getHtmlObject(HTMLElement element)
Returns
null . |
HtmlPanel |
getHtmlPanel() |
java.lang.String |
getName()
It should return the name of the browser window, if this
renderer context is for the top frame in the window.
|
java.lang.String |
getNextURL()
Gets the next URL in the history.
|
HtmlRendererContext |
getOpener()
Gets the opener of the frame/window in the current context.
|
HtmlRendererContext |
getParent()
Gets the parent of the frame/window in the current context.
|
java.lang.String |
getPreviousURL()
Gets the previous URL in the history.
|
protected java.net.Proxy |
getProxy()
Gets the connection proxy used in
navigate(URL, String) . |
java.lang.String |
getSourceCode()
Gets the source code of the current HTML document.
|
java.lang.String |
getStatus()
Gets the window status text.
|
HtmlRendererContext |
getTop()
Gets the top-most browser frame/window.
|
UserAgentContext |
getUserAgentContext()
If a
UserAgentContext instance
was provided in the constructor, then that instance is returned. |
void |
goToHistoryURL(java.lang.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 |
isImageLoadingEnabled()
This method should return true if and only if image loading
needs to be enabled.
|
protected boolean |
isNavigationAsynchronous()
Indicates whether navigation (via
submitForm(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,
java.net.URL url,
java.lang.String target)
Implements the link click handler by invoking
navigate(URL, String) . |
void |
moveInHistory(int offset)
Navigates the history according to the given offset.
|
void |
navigate(java.lang.String fullURL)
Convenience method provided to allow loading a document into
the renderer.
|
void |
navigate(java.net.URL href,
java.lang.String target)
Implements simple navigation with incremental
rendering by invoking
submitForm(String, URL, String, String, FormInput[])
with a GET request method. |
boolean |
onContextMenu(HTMLElement element,
java.awt.event.MouseEvent event)
This method must be overridden to implement a context menu.
|
boolean |
onDoubleClick(HTMLElement element,
java.awt.event.MouseEvent event)
This method is called when there's a mouse double-click on an element.
|
boolean |
onMouseClick(HTMLElement element,
java.awt.event.MouseEvent event)
This method is called when there's a mouse click on an element.
|
void |
onMouseOut(HTMLElement element,
java.awt.event.MouseEvent event)
This method can be overridden to receive notifications when the
mouse leaves an element.
|
void |
onMouseOver(HTMLElement element,
java.awt.event.MouseEvent event)
This method can be overridden to receive notifications when the
mouse first enters an element.
|
HtmlRendererContext |
open(java.lang.String url,
java.lang.String windowName,
java.lang.String windowFeatures,
boolean replace)
Deprecated.
|
HtmlRendererContext |
open(java.net.URL url,
java.lang.String windowName,
java.lang.String windowFeatures,
boolean replace)
It should open a new browser window.
|
java.lang.String |
prompt(java.lang.String message,
java.lang.String inputDefault)
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(java.lang.String message) |
void |
setOpener(HtmlRendererContext opener)
Sets the context that opened the current frame/window.
|
void |
setStatus(java.lang.String message)
Sets the window status text.
|
void |
submitForm(java.lang.String method,
java.net.URL action,
java.lang.String target,
java.lang.String enctype,
FormInput[] formInputs)
Implements simple navigation and form submission with incremental
rendering and target processing, including
frame lookup.
|
protected void |
submitFormSync(java.lang.String method,
java.net.URL action,
java.lang.String target,
java.lang.String enctype,
FormInput[] formInputs)
Submits a form and/or navigates by making
a synchronous request.
|
void |
warn(java.lang.String message) |
void |
warn(java.lang.String message,
java.lang.Throwable throwable) |
protected java.net.URLConnection currentConnection
public SimpleHtmlRendererContext(HtmlPanel contextComponent)
HtmlPanel
and UserAgentContext
contextComponent
- The component that will render HTML.public SimpleHtmlRendererContext(HtmlPanel contextComponent, UserAgentContext ucontext)
contextComponent
- The component that will render HTML.SimpleUserAgentContext
public SimpleHtmlRendererContext(HtmlPanel contextComponent, HtmlRendererContext parentRcontext)
HtmlRendererContext
.contextComponent
- The component that will render HTML.parentRcontext
- The parent's renderer context.public HtmlPanel getHtmlPanel()
public java.lang.String getSourceCode()
public HTMLCollection getFrames()
HtmlPanel
instance.getFrames
in interface HtmlRendererContext
public void reload()
reload
in interface HtmlRendererContext
public void linkClicked(HTMLElement linkNode, java.net.URL url, java.lang.String target)
navigate(URL, String)
.linkClicked
in interface HtmlRendererContext
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.protected java.net.Proxy getProxy()
navigate(URL, String)
.
This implementation calls SimpleUserAgentContext.getProxy()
if getUserAgentContext()
returns an instance assignable to SimpleUserAgentContext
.
The method may be overridden to provide a different proxy setting.public void navigate(java.net.URL href, java.lang.String target)
submitForm(String, URL, String, String, FormInput[])
with a GET
request method.navigate
in interface HtmlRendererContext
href
- The destination URL.target
- Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.public void navigate(java.lang.String fullURL) throws java.net.MalformedURLException
fullURL
- The absolute URL of the document.java.net.MalformedURLException
navigate(URL, String)
public void submitForm(java.lang.String method, java.net.URL action, java.lang.String target, java.lang.String enctype, FormInput[] formInputs)
Notes:
getDocumentCharset(URLConnection)
.
application/x-www-form-urlencoded
.
isNavigationAsynchronous()
.
submitForm
in interface HtmlRendererContext
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 of FormInput
instances.navigate(URL, String)
protected boolean isNavigationAsynchronous()
submitForm(String, URL, String, String, FormInput[])
) should be asynchronous.
This overridable implementation returns true
.protected void submitFormSync(java.lang.String method, java.net.URL action, java.lang.String target, java.lang.String enctype, FormInput[] formInputs) throws java.io.IOException, org.xml.sax.SAXException
submitForm(String, URL, String, String, FormInput[])
.method
- The request method.action
- The action URL.target
- The target identifier.enctype
- The encoding type.formInputs
- The form inputs.java.io.IOException
org.xml.sax.SAXException
submitForm(String, URL, String, String, FormInput[])
protected HTMLDocumentImpl createDocument(org.xml.sax.InputSource inputSource) throws java.io.IOException, org.xml.sax.SAXException
inputSource
- The document input source.java.io.IOException
org.xml.sax.SAXException
protected java.lang.String getDocumentCharset(java.net.URLConnection connection)
submitForm(String, URL, String, String, FormInput[])
to determine the charset of a document. The charset is determined by looking
at the Content-Type
header.connection
- A URL connection.public void alert(java.lang.String message)
alert
in interface HtmlRendererContext
message
- Message shown by the dialog.public void blur()
blur
in interface HtmlRendererContext
public void close()
close
in interface HtmlRendererContext
public boolean confirm(java.lang.String message)
confirm
in interface HtmlRendererContext
message
- The message shown by the confirmation dialog.public void focus()
focus
in interface HtmlRendererContext
public final HtmlRendererContext open(java.lang.String url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)
open(URL, String, String, boolean)
.HtmlRendererContext
open
in interface HtmlRendererContext
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).HtmlRendererContext
instance.public HtmlRendererContext open(java.net.URL url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)
open
in interface HtmlRendererContext
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.HtmlRendererContext
instance.public java.lang.String prompt(java.lang.String message, java.lang.String inputDefault)
prompt
in interface HtmlRendererContext
message
- The message shown by the dialog.inputDefault
- The default input value.public void scroll(int x, int y)
This method may be called outside of the GUI thread. The operation is scheduled immediately in that thread as needed.
scroll
in interface HtmlRendererContext
x
- The new x coordinate for the origin.y
- The new y coordinate for the origin.public void scrollBy(int x, int y)
HtmlRendererContext
scrollBy
in interface HtmlRendererContext
x
- Horizontal pixels to scroll.y
- Vertical pixels to scroll.public boolean isClosed()
isClosed
in interface HtmlRendererContext
public java.lang.String getDefaultStatus()
getDefaultStatus
in interface HtmlRendererContext
public java.lang.String getName()
getName
in interface HtmlRendererContext
public HtmlRendererContext getParent()
HtmlRendererContext
getParent
in interface HtmlRendererContext
public HtmlRendererContext getOpener()
HtmlRendererContext
getOpener
in interface HtmlRendererContext
public void setOpener(HtmlRendererContext opener)
HtmlRendererContext
setOpener
in interface HtmlRendererContext
opener
- A HtmlRendererContext
.public java.lang.String getStatus()
HtmlRendererContext
getStatus
in interface HtmlRendererContext
public void setStatus(java.lang.String message)
HtmlRendererContext
setStatus
in interface HtmlRendererContext
message
- A string.public HtmlRendererContext getTop()
HtmlRendererContext
getTop
in interface HtmlRendererContext
public BrowserFrame createBrowserFrame()
HtmlRendererContext
BrowserFrame
instance.createBrowserFrame
in interface HtmlRendererContext
public void warn(java.lang.String message, java.lang.Throwable throwable)
public void error(java.lang.String message, java.lang.Throwable throwable)
public void warn(java.lang.String message)
public void error(java.lang.String message)
public HtmlObject getHtmlObject(HTMLElement element)
null
. This method should be overridden
to provide OBJECT, EMBED or APPLET functionality.getHtmlObject
in interface HtmlRendererContext
element
- The DOM element for the object, which may
either represent an OBJECT, EMBED or an APPLET tag.null
if they have any problems producing a HtmlObject
instance.
This is particularly true of OBJECT tags, where inner HTML of
the tag must be rendered if the OBJECT content cannot be handled.public void setDefaultStatus(java.lang.String message)
setDefaultStatus
in interface HtmlRendererContext
public UserAgentContext getUserAgentContext()
UserAgentContext
instance
was provided in the constructor, then that instance is returned.
Otherwise, an instance of SimpleUserAgentContext
is
created and returned.
The context returned by this method is used by local request facilities and other parts of the renderer.
getUserAgentContext
in interface HtmlRendererContext
public boolean isVisitedLink(HTMLLinkElement link)
isVisitedLink
in interface HtmlRendererContext
public boolean onContextMenu(HTMLElement element, java.awt.event.MouseEvent event)
onContextMenu
in interface HtmlRendererContext
element
- The narrowest element enclosing the mouse location.event
- The mouse event.public void onMouseOut(HTMLElement element, java.awt.event.MouseEvent event)
onMouseOut
in interface HtmlRendererContext
element
- The element that the mouse has just exited.event
- The mouse event.public void onMouseOver(HTMLElement element, java.awt.event.MouseEvent event)
onMouseOver
in interface HtmlRendererContext
element
- The element that the mouse has just entered.event
- The mouse event.public boolean isImageLoadingEnabled()
HtmlRendererContext
isImageLoadingEnabled
in interface HtmlRendererContext
public boolean onDoubleClick(HTMLElement element, java.awt.event.MouseEvent event)
HtmlRendererContext
onDoubleClick
in interface HtmlRendererContext
element
- The narrowest element enclosing the mouse location.event
- The mouse event.public boolean onMouseClick(HTMLElement element, java.awt.event.MouseEvent event)
HtmlRendererContext
onMouseClick
in interface HtmlRendererContext
element
- The narrowest element enclosing the mouse location.event
- The mouse event.public void resizeBy(int byWidth, int byHeight)
HtmlRendererContext
resizeBy
in interface HtmlRendererContext
byWidth
- The number of pixels to resize the width by.byHeight
- The number of pixels to resize the height by.public void resizeTo(int width, int height)
HtmlRendererContext
resizeTo
in interface HtmlRendererContext
width
- The new width.height
- The new height.public void back()
back
in interface HtmlRendererContext
public void forward()
HtmlRendererContext
forward
in interface HtmlRendererContext
public java.lang.String getCurrentURL()
HtmlRendererContext
getCurrentURL
in interface HtmlRendererContext
public int getHistoryLength()
HtmlRendererContext
getHistoryLength
in interface HtmlRendererContext
public java.lang.String getNextURL()
HtmlRendererContext
getNextURL
in interface HtmlRendererContext
public java.lang.String getPreviousURL()
HtmlRendererContext
getPreviousURL
in interface HtmlRendererContext
public void goToHistoryURL(java.lang.String url)
HtmlRendererContext
goToHistoryURL
in interface HtmlRendererContext
public void moveInHistory(int offset)
HtmlRendererContext
moveInHistory
in interface HtmlRendererContext
offset
- A positive or negative number. -1 is
equivalent to HtmlRendererContext.back()
. +1 is
equivalent to HtmlRendererContext.forward()
.