Interface BrowserApplication
public interface BrowserApplication
Browser application interface to open and control an integrated browser instance.
Example:
Example:
appService =servicesBroker
.getService
(ApplicationService
.class); browser =appService
.openApplication
(BrowserApplication
.TYPE, null).getApplication()
.getApplication()
; browser.openUrl
("www.e-spirit.de");
- Since:
- 4.2.416
- Example:
- Example how to create a browser application
import de.espirit.firstspirit.client.gui.applications.browser.*; import de.espirit.firstspirit.access.ServicesBroker; import de.espirit.firstspirit.client.gui.applications.ApplicationService; import de.espirit.firstspirit.client.gui.applications.ApplicationTab; /** * Examples how to create a browser application. * * @since 4.2.416 */ public class BrowserApplicationExample { /** * Opens a browser application tab with the given title and opens the given url. * * @since 4.2.416 */ public BrowserApplication createBrowserApplication(final ServicesBroker serviceBroker, final String title) { final ApplicationService appService = serviceBroker.getService(ApplicationService.class); // new browser configuration final BrowserApplicationConfiguration config = BrowserApplicationConfiguration.GENERATOR.invoke() // the title for the application tab .title(title) // use chrome as engine type for the browser application .engineType(EngineType.CHROME); // open an application tab of type browser final ApplicationTab<BrowserApplication> browserTab = appService.openApplication(BrowserApplication.TYPE, config); // get the browser application final BrowserApplication browserApplication = browserTab.getApplication(); // open www.e-spirit.de in the created browser application browserApplication.openUrl("www.e-spirit.de"); return browserApplication; } }
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ApplicationType<BrowserApplication,
BrowserApplicationConfiguration> Application type toopen
this browser application.
Example: -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBrowserListener
(@NotNull BrowserListener listener) Adds the givenbrowser listener
to be notified on browser change events.@Nullable String
convertToScript
(Object object) Converts specified java object into JavaScript code.
The conversion of the given object is based upon some basic java/javascript object conversion mechanism: Conversions from Java to JavaScript JavaJavaScript Number, Boolean(related toString mechanism) String"stringcontent"(escapes newline and ") List<Object>[entry0,entry1,entry2,...] Map<String,Object>{'key0':value0,'key1':value1,...}<T> BrowserNodeHandlerBuilder<T>
Provides a builder for constructing and binding aBrowserNodeHandler
.@Nullable Object
evaluateScript
(String script) Executes given JavaScript code and evaluates return value.
Ensure document is loadedcompletely
before calling this method.
The evaluation of the return value is based upon some basic java/javascript object conversion mechanism: Conversions from JavaScript to Java JavaScriptJava numberDouble stringString booleanBoolean arrayList<Object> objectMap<String,Object>@Nullable Object
evaluateScriptMethod
(String methodIdentifier, Object... arguments) Generates JavaScript code for the specified JavaScript method call, executes it in currently opened document and evaluates the return value of the method call.
Ensure document is loadedcompletely
before calling this method.void
executeScript
(String script) Executes given JavaScript code in the currently opened document.
Ensure document is loadedcompletely
before calling this method.void
executeScriptMethod
(String methodIdentifier, Object... arguments) Generates JavaScript code for the specified JavaScript method call and executes it in currently opened document.
Ensure document is loadedcompletely
before calling this method.void
focus()
Requests that the related browser component get the input focus.Returns accessor for the document in the currently loaded page.Returns the type of the browser engine that is currently used by this BrowserApplication.@Nullable String
Returns the version string of the browser engine that is currently used by this BrowserApplication.@Nullable String
getUrl()
Returns the url of this browser application ornull
if no url requested yet.
If necessary to ensure, that the url is completly loaded usebrowser listener
.void
Creates a javascript proxy for the given object instance.void
Opens the givenurl
.
Attenttion: This call will be executed asynchronous.void
removeBrowserListener
(@NotNull BrowserListener listener) Removes the givenbrowser listener
.void
saveTo
(String url, File file, ProgressListener listener) Requests the specified url and save content to specified file.void
setHtmlContent
(String html) Sets the specified HTML content to the current Browser document.
-
Field Details
-
TYPE
Application type toopen
this browser application.
Example:openApplication
(BrowserApplication.TYPE
, config).getApplication()
;- Since:
- 4.2.416
-
-
Method Details
-
getEngineVersion
Returns the version string of the browser engine that is currently used by this BrowserApplication.- Returns:
- the version string of browser engine.
- Since:
- 5.0.100
-
getEngineType
EngineType getEngineType()Returns the type of the browser engine that is currently used by this BrowserApplication.- Returns:
- the type of browser engine.
- Since:
- 5.0.100
-
openUrl
Opens the givenurl
.
Attenttion: This call will be executed asynchronous. Register abrowser listener
beforecalling this method, if you need to be informed of the location change calling this method will lead to.- Parameters:
url
- to open- Since:
- 4.2.416
- See Also:
-
getUrl
Returns the url of this browser application ornull
if no url requested yet.
If necessary to ensure, that the url is completly loaded usebrowser listener
.- Returns:
- the current url of this browser application or
null
if no url requested yet. - Since:
- 4.2.416
- See Also:
-
addBrowserListener
Adds the givenbrowser listener
to be notified on browser change events.- Parameters:
listener
- the listener to be notified- Since:
- 4.2.416
- See Also:
-
removeBrowserListener
Removes the givenbrowser listener
.- Parameters:
listener
- the listener to be removed.- Since:
- 4.2.416
-
saveTo
Requests the specified url and save content to specified file. Based on the current engine type the progress listening may not be supported.- Parameters:
url
- url to loadfile
- the target filelistener
- a listener for download progress or null- Throws:
IOException
- when an error occurs during download process- Since:
- 4.2.436
-
focus
void focus()Requests that the related browser component get the input focus.- Since:
- 4.2.436
-
setHtmlContent
Sets the specified HTML content to the current Browser document. This method is executing asynchronously. To make sure that the new HTML content was applied to the document completely register abrowser listener
.- Parameters:
html
- a string that represents HTML content to set to the current document.- Since:
- 4.2.416
-
getCurrentDocument
Document getCurrentDocument()Returns accessor for the document in the currently loaded page. Each node of typeElement
of the returneddocument will also be of typeBrowserNode
.
Ensure document is loadedcompletely
before calling this method.
During accessing elements of the returned elements aDocumentGoneException
will be thrown if the belonging nodes aren't accessible any more (e.g. cause browser navigated to a different url)- Returns:
- accessor for browser dom document
- Since:
- 4.2.416
- See Also:
-
executeScript
Executes given JavaScript code in the currently opened document.
Ensure document is loadedcompletely
before calling this method.- Parameters:
script
- script code to execute- Since:
- 4.2.416
-
executeScriptMethod
Generates JavaScript code for the specified JavaScript method call and executes it in currently opened document.
Ensure document is loadedcompletely
before calling this method.- Parameters:
methodIdentifier
- method identifier (for example: "window.methodName")arguments
- arguments the javascript method should be called with- Since:
- 4.2.426
- See Also:
-
evaluateScript
Executes given JavaScript code and evaluates return value.
Ensure document is loadedcompletely
before calling this method.
The evaluation of the return value is based upon some basic java/javascript object conversion mechanism:Conversions from JavaScript to Java JavaScript Java number Double string String boolean Boolean array List<Object> object Map<String,Object> - Parameters:
script
- script code to be executed- Returns:
- the evaluated return value of the script execution.
- Since:
- 4.2.416
-
evaluateScriptMethod
Generates JavaScript code for the specified JavaScript method call, executes it in currently opened document and evaluates the return value of the method call.
Ensure document is loadedcompletely
before calling this method.- Parameters:
methodIdentifier
- method identifier (for example: "window.methodName")arguments
- arguments the javascript method should be called with- Returns:
- the evaluated return value of the script execution.
- Since:
- 4.2.426
- See Also:
-
convertToScript
Converts specified java object into JavaScript code.
The conversion of the given object is based upon some basic java/javascript object conversion mechanism:Conversions from Java to JavaScript Java JavaScript Number, Boolean (related toString mechanism) String "stringcontent"(escapes newline and ") List<Object> [entry0,entry1,entry2,...] Map<String,Object> {'key0':value0,'key1':value1,...} - Parameters:
object
- javaobject that should be converted to JavaScript code- Returns:
- the generated javascript code. returns null if object is null or unsupported
- Since:
- 4.2.426
-
inject
Creates a javascript proxy for the given object instance. The new javascript object would be injected into the current web page with given name as an attribute of the window object. (Usage: window.{name})
Ensure document is loadedcompletely
before calling this method.
Example:
public class Test {
public void call() {...}
public void set(String parameter) {...}
public String get() {...}
}
browserApp.inject(new Test(), "myTest");
Methods can be called in javascript like the following (Object registered with name 'myTest'):
window.myTest.call();
window.myTest.set("value");
window.Test.get(function(value){alert(value);});
The execution of related object methods is done asynchronously. Because of that any return value is given to an additional javascript callback function at the end of parameters.
LikeevaluateScript(String)
the method parameters and return values are converted underthe same conversion pattern.
Bear in mind that all types ofNumber
are equal in javascript and would be convertedto javascript type 'number'.- Parameters:
object
- the object that should be injected into web pagename
- the name of the new javascript proxy object- Since:
- 4.2.416
-
createNodeHandlerBuilder
Provides a builder for constructing and binding aBrowserNodeHandler
.- Type Parameters:
T
- Type of node to be bound.- Returns:
- A builder on a node handler.
- Since:
- 4.2.426
-