Package org.lobobrowser.html.test
Class SimpleHtmlRendererContext
- java.lang.Object
-
- org.lobobrowser.html.test.SimpleHtmlRendererContext
-
- All Implemented Interfaces:
HtmlRendererContext
public class SimpleHtmlRendererContext extends java.lang.Object implements HtmlRendererContext
TheSimpleHtmlRendererContextclass implements theHtmlRendererContextinterface. 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
HtmlPanelof the renderer context is to invokenavigate(String).
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.URLConnectioncurrentConnectionThe connection currently opened by openSync() if any.
-
Constructor Summary
Constructors Constructor Description SimpleHtmlRendererContext(HtmlPanel contextComponent)Deprecated.Use constructor that takesHtmlPanelandUserAgentContextSimpleHtmlRendererContext(HtmlPanel contextComponent, HtmlRendererContext parentRcontext)Constructs a SimpleHtmlRendererContext that is a child of another.HtmlRendererContextSimpleHtmlRendererContext(HtmlPanel contextComponent, UserAgentContext ucontext)Constructs a SimpleHtmlRendererContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidalert(java.lang.String message)Opens a simple message dialog.voidback()It should navigate back one page.voidblur()It should give up focus on the current browser window.voidclose()It should close the current browser window.booleanconfirm(java.lang.String message)Opens a simple confirmation window.BrowserFramecreateBrowserFrame()Creates aBrowserFrameinstance.protected HTMLDocumentImplcreateDocument(org.xml.sax.InputSource inputSource)Creates a blank document instance.voiderror(java.lang.String message)voiderror(java.lang.String message, java.lang.Throwable throwable)voidfocus()It should request focus for the current browser window.voidforward()Goes forward one page.java.lang.StringgetCurrentURL()Gets the current URL in history.java.lang.StringgetDefaultStatus()Should return true if and only if the current browser window is closed.protected java.lang.StringgetDocumentCharset(java.net.URLConnection connection)This method is invoked bysubmitForm(String, URL, String, String, FormInput[])to determine the charset of a document.HTMLCollectiongetFrames()Gets a collection of current document frames, by querying the document currently held by the localHtmlPanelinstance.intgetHistoryLength()Gets the number of pages in the history list.HtmlObjectgetHtmlObject(HTMLElement element)Returnsnull.HtmlPanelgetHtmlPanel()java.lang.StringgetName()It should return the name of the browser window, if this renderer context is for the top frame in the window.java.lang.StringgetNextURL()Gets the next URL in the history.HtmlRendererContextgetOpener()Gets the opener of the frame/window in the current context.HtmlRendererContextgetParent()Gets the parent of the frame/window in the current context.java.lang.StringgetPreviousURL()Gets the previous URL in the history.protected java.net.ProxygetProxy()Gets the connection proxy used innavigate(URL, String).java.lang.StringgetSourceCode()Gets the source code of the current HTML document.java.lang.StringgetStatus()Gets the window status text.HtmlRendererContextgetTop()Gets the top-most browser frame/window.UserAgentContextgetUserAgentContext()If aUserAgentContextinstance was provided in the constructor, then that instance is returned.voidgoToHistoryURL(java.lang.String url)Navigates to a URL in the history list.booleanisClosed()Should return true if and only if the current browser window is closed.booleanisImageLoadingEnabled()This method should return true if and only if image loading needs to be enabled.protected booleanisNavigationAsynchronous()Indicates whether navigation (viasubmitForm(String, URL, String, String, FormInput[])) should be asynchronous.booleanisVisitedLink(HTMLLinkElement link)Should be overridden to return true if the link has been visited.voidlinkClicked(HTMLElement linkNode, java.net.URL url, java.lang.String target)Implements the link click handler by invokingnavigate(URL, String).voidmoveInHistory(int offset)Navigates the history according to the given offset.voidnavigate(java.lang.String fullURL)Convenience method provided to allow loading a document into the renderer.voidnavigate(java.net.URL href, java.lang.String target)Implements simple navigation with incremental rendering by invokingsubmitForm(String, URL, String, String, FormInput[])with aGETrequest method.booleanonContextMenu(HTMLElement element, java.awt.event.MouseEvent event)This method must be overridden to implement a context menu.booleanonDoubleClick(HTMLElement element, java.awt.event.MouseEvent event)This method is called when there's a mouse double-click on an element.booleanonMouseClick(HTMLElement element, java.awt.event.MouseEvent event)This method is called when there's a mouse click on an element.voidonMouseOut(HTMLElement element, java.awt.event.MouseEvent event)This method can be overridden to receive notifications when the mouse leaves an element.voidonMouseOver(HTMLElement element, java.awt.event.MouseEvent event)This method can be overridden to receive notifications when the mouse first enters an element.HtmlRendererContextopen(java.lang.String url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)Deprecated.HtmlRendererContextopen(java.net.URL url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)It should open a new browser window.java.lang.Stringprompt(java.lang.String message, java.lang.String inputDefault)Shows a simple prompt dialog.voidreload()Implements reload as navigation to current URL.voidresizeBy(int byWidth, int byHeight)Resizes the window.voidresizeTo(int width, int height)Resizes the window.voidscroll(int x, int y)Changes the origin of the HTML block's scrollable area according to the position given.voidscrollBy(int x, int y)Scrolls the client area.voidsetDefaultStatus(java.lang.String message)voidsetOpener(HtmlRendererContext opener)Sets the context that opened the current frame/window.voidsetStatus(java.lang.String message)Sets the window status text.voidsubmitForm(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 voidsubmitFormSync(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.voidwarn(java.lang.String message)voidwarn(java.lang.String message, java.lang.Throwable throwable)
-
-
-
Constructor Detail
-
SimpleHtmlRendererContext
public SimpleHtmlRendererContext(HtmlPanel contextComponent)
Deprecated.Use constructor that takesHtmlPanelandUserAgentContextConstructs a SimpleHtmlRendererContext.- Parameters:
contextComponent- The component that will render HTML.
-
SimpleHtmlRendererContext
public SimpleHtmlRendererContext(HtmlPanel contextComponent, UserAgentContext ucontext)
Constructs a SimpleHtmlRendererContext.- Parameters:
contextComponent- The component that will render HTML.- See Also:
SimpleUserAgentContext
-
SimpleHtmlRendererContext
public SimpleHtmlRendererContext(HtmlPanel contextComponent, HtmlRendererContext parentRcontext)
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 Detail
-
getHtmlPanel
public HtmlPanel getHtmlPanel()
-
getSourceCode
public java.lang.String getSourceCode()
Gets the source code of the current HTML document.
-
getFrames
public HTMLCollection getFrames()
Gets a collection of current document frames, by querying the document currently held by the localHtmlPanelinstance.- Specified by:
getFramesin interfaceHtmlRendererContext
-
reload
public void reload()
Implements reload as navigation to current URL. Override to implement a more robust reloading mechanism.- Specified by:
reloadin interfaceHtmlRendererContext
-
linkClicked
public void linkClicked(HTMLElement linkNode, java.net.URL url, java.lang.String target)
Implements the link click handler by invokingnavigate(URL, String).- Specified by:
linkClickedin 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
protected java.net.Proxy 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.
-
navigate
public void navigate(java.net.URL href, java.lang.String target)Implements simple navigation with incremental rendering by invokingsubmitForm(String, URL, String, String, FormInput[])with aGETrequest method.- Specified by:
navigatein interfaceHtmlRendererContext- Parameters:
href- The destination URL.target- Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
-
navigate
public void navigate(java.lang.String fullURL) throws java.net.MalformedURLExceptionConvenience method provided to allow loading a document into the renderer.- Parameters:
fullURL- The absolute URL of the document.- Throws:
java.net.MalformedURLException- See Also:
navigate(URL, String)
-
submitForm
public 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. 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:
submitFormin 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 ofFormInputinstances.- See Also:
navigate(URL, String)
- Document encoding is defined by
-
isNavigationAsynchronous
protected boolean isNavigationAsynchronous()
Indicates whether navigation (viasubmitForm(String, URL, String, String, FormInput[])) should be asynchronous. This overridable implementation returnstrue.
-
submitFormSync
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.SAXExceptionSubmits 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:
java.io.IOExceptionorg.xml.sax.SAXException- See Also:
submitForm(String, URL, String, String, FormInput[])
-
createDocument
protected HTMLDocumentImpl createDocument(org.xml.sax.InputSource inputSource) throws java.io.IOException, org.xml.sax.SAXException
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:
java.io.IOExceptionorg.xml.sax.SAXException
-
getDocumentCharset
protected java.lang.String getDocumentCharset(java.net.URLConnection connection)
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-Typeheader.- Parameters:
connection- A URL connection.
-
alert
public void alert(java.lang.String message)
Opens a simple message dialog.- Specified by:
alertin 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:
blurin interfaceHtmlRendererContext
-
close
public void close()
It should close the current browser window. This implementation does nothing and should be overridden.- Specified by:
closein interfaceHtmlRendererContext
-
confirm
public boolean confirm(java.lang.String message)
Opens a simple confirmation window.- Specified by:
confirmin 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:
focusin interfaceHtmlRendererContext
-
open
public final HtmlRendererContext open(java.lang.String url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)
Deprecated.Description copied from interface:HtmlRendererContextOpens a separate browser window and renders a URL.- Specified by:
openin 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
HtmlRendererContextinstance.
-
open
public HtmlRendererContext open(java.net.URL url, java.lang.String windowName, java.lang.String windowFeatures, boolean replace)
It should open a new browser window. This implementation does nothing and should be overridden.- Specified by:
openin 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
HtmlRendererContextinstance.
-
prompt
public java.lang.String prompt(java.lang.String message, java.lang.String inputDefault)Shows a simple prompt dialog.- Specified by:
promptin 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:
scrollin 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:HtmlRendererContextScrolls the client area.- Specified by:
scrollByin 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:
isClosedin interfaceHtmlRendererContext
-
getDefaultStatus
public java.lang.String getDefaultStatus()
Should return true if and only if the current browser window is closed. This implementation returns false and should be overridden.- Specified by:
getDefaultStatusin interfaceHtmlRendererContext
-
getName
public 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. This implementation returns a blank string, so it should be overridden.- Specified by:
getNamein interfaceHtmlRendererContext
-
getParent
public HtmlRendererContext getParent()
Description copied from interface:HtmlRendererContextGets the parent of the frame/window in the current context.- Specified by:
getParentin interfaceHtmlRendererContext
-
getOpener
public HtmlRendererContext getOpener()
Description copied from interface:HtmlRendererContextGets the opener of the frame/window in the current context.- Specified by:
getOpenerin interfaceHtmlRendererContext
-
setOpener
public void setOpener(HtmlRendererContext opener)
Description copied from interface:HtmlRendererContextSets the context that opened the current frame/window.- Specified by:
setOpenerin interfaceHtmlRendererContext- Parameters:
opener- AHtmlRendererContext.
-
getStatus
public java.lang.String getStatus()
Description copied from interface:HtmlRendererContextGets the window status text.- Specified by:
getStatusin interfaceHtmlRendererContext
-
setStatus
public void setStatus(java.lang.String message)
Description copied from interface:HtmlRendererContextSets the window status text.- Specified by:
setStatusin interfaceHtmlRendererContext- Parameters:
message- A string.
-
getTop
public HtmlRendererContext getTop()
Description copied from interface:HtmlRendererContextGets the top-most browser frame/window.- Specified by:
getTopin interfaceHtmlRendererContext
-
createBrowserFrame
public BrowserFrame createBrowserFrame()
Description copied from interface:HtmlRendererContextCreates aBrowserFrameinstance.- Specified by:
createBrowserFramein interfaceHtmlRendererContext
-
warn
public void warn(java.lang.String message, java.lang.Throwable throwable)
-
error
public void error(java.lang.String message, java.lang.Throwable throwable)
-
warn
public void warn(java.lang.String message)
-
error
public void error(java.lang.String message)
-
getHtmlObject
public HtmlObject getHtmlObject(HTMLElement element)
Returnsnull. This method should be overridden to provide OBJECT, EMBED or APPLET functionality.- Specified by:
getHtmlObjectin 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
nullif they have any problems producing aHtmlObjectinstance. This is particularly true of OBJECT tags, where inner HTML of the tag must be rendered if the OBJECT content cannot be handled.
-
setDefaultStatus
public void setDefaultStatus(java.lang.String message)
- Specified by:
setDefaultStatusin interfaceHtmlRendererContext
-
getUserAgentContext
public UserAgentContext getUserAgentContext()
If aUserAgentContextinstance was provided in the constructor, then that instance is returned. Otherwise, an instance ofSimpleUserAgentContextis created and returned.The context returned by this method is used by local request facilities and other parts of the renderer.
- Specified by:
getUserAgentContextin interfaceHtmlRendererContext
-
isVisitedLink
public boolean isVisitedLink(HTMLLinkElement link)
Should be overridden to return true if the link has been visited.- Specified by:
isVisitedLinkin interfaceHtmlRendererContext
-
onContextMenu
public boolean onContextMenu(HTMLElement element, java.awt.event.MouseEvent event)
This method must be overridden to implement a context menu.- Specified by:
onContextMenuin 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
public void onMouseOut(HTMLElement element, java.awt.event.MouseEvent event)
This method can be overridden to receive notifications when the mouse leaves an element.- Specified by:
onMouseOutin interfaceHtmlRendererContext- Parameters:
element- The element that the mouse has just exited.event- The mouse event.
-
onMouseOver
public void onMouseOver(HTMLElement element, java.awt.event.MouseEvent event)
This method can be overridden to receive notifications when the mouse first enters an element.- Specified by:
onMouseOverin interfaceHtmlRendererContext- Parameters:
element- The element that the mouse has just entered.event- The mouse event.
-
isImageLoadingEnabled
public boolean isImageLoadingEnabled()
Description copied from interface:HtmlRendererContextThis method should return true if and only if image loading needs to be enabled.- Specified by:
isImageLoadingEnabledin interfaceHtmlRendererContext
-
onDoubleClick
public boolean onDoubleClick(HTMLElement element, java.awt.event.MouseEvent event)
Description copied from interface:HtmlRendererContextThis method is called when there's a mouse double-click on an element.- Specified by:
onDoubleClickin 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
public boolean onMouseClick(HTMLElement element, java.awt.event.MouseEvent event)
Description copied from interface:HtmlRendererContextThis method is called when there's a mouse click on an element.- Specified by:
onMouseClickin 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:HtmlRendererContextResizes the window.- Specified by:
resizeByin 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:HtmlRendererContextResizes the window.- Specified by:
resizeToin 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:
backin interfaceHtmlRendererContext
-
forward
public void forward()
Description copied from interface:HtmlRendererContextGoes forward one page.- Specified by:
forwardin interfaceHtmlRendererContext
-
getCurrentURL
public java.lang.String getCurrentURL()
Description copied from interface:HtmlRendererContextGets the current URL in history.- Specified by:
getCurrentURLin interfaceHtmlRendererContext
-
getHistoryLength
public int getHistoryLength()
Description copied from interface:HtmlRendererContextGets the number of pages in the history list.- Specified by:
getHistoryLengthin interfaceHtmlRendererContext
-
getNextURL
public java.lang.String getNextURL()
Description copied from interface:HtmlRendererContextGets the next URL in the history.- Specified by:
getNextURLin interfaceHtmlRendererContext
-
getPreviousURL
public java.lang.String getPreviousURL()
Description copied from interface:HtmlRendererContextGets the previous URL in the history.- Specified by:
getPreviousURLin interfaceHtmlRendererContext
-
goToHistoryURL
public void goToHistoryURL(java.lang.String url)
Description copied from interface:HtmlRendererContextNavigates to a URL in the history list.- Specified by:
goToHistoryURLin interfaceHtmlRendererContext
-
moveInHistory
public void moveInHistory(int offset)
Description copied from interface:HtmlRendererContextNavigates the history according to the given offset.- Specified by:
moveInHistoryin interfaceHtmlRendererContext- Parameters:
offset- A positive or negative number. -1 is equivalent toHtmlRendererContext.back(). +1 is equivalent toHtmlRendererContext.forward().
-
-