Home
Chapter 12. Using JxBrowser with Java Web Start
Contents
1. Mozillalnterfaces jar xulrunner mac jar JxBrowser Programmer s Guide Chapter 3 Browser Engines Internet Explorer browser Windows JDK 32 bit or 64 bit engine ie jar winpack 3 8 jar Safari browser Mac OS X JDK 32 bit or JDK 64 bit engine webkit jar Note library version can be changed in further JxBrowser releases JxBrowser Programmer s Guide Chapter 4 Navigation to URL With JxBrowser you can download a web page or HTML document using the following code Browser browser BrowserFactory createBrowser browser navigate http www google com The Browser navigate method starts document loading but it doesn t guarantee that the document is completely loaded after the method is executed To make sure that the document is loaded completely you can use one of the following ways 1 Use the NavigationListener navigationFinished event This event fires when a navigation oper ation is finished and a document has been completely loaded and initialized In pages with no frames or where multiple frames are loaded this event fires once after loading is complete Ex ample browser addNavigationListener new NavigationAdapter Override public void navigationFinished NavigationFinishedEvent event document is loaded completely D browser navigate http www google com 2 Use the Browser waitReady method This method blocks current thread execution until the document is loaded completel
2. instance browser setUserAgent My UserAgent String To restore a default user agent string please use the following way Browser browser BrowserFactory createBrowser BrowserType Mozilla Restoring a default user agent string for Mozilla browser instance browser setUserAgent null 13 JxBrowser Programmer s Guide Chapter 12 Using JxBrowser with Java Web Start This section describes how you can deploy your application that uses JxBrowser with Java Web Start technology Below you can find what JxBrowserDemo JNLP JxBrowserDemo jnlp file looks like lt jnlp spec 1 5 codebase http enclave 8080 href JxBrowserDemo jnlp gt lt information gt lt title gt JxBrowserDemo lt title gt lt vendor gt TeamDev Ltd lt vendor gt homepage href http www teamdev com jxbrowser gt lt description gt JxBrowser Demo Application lt description gt lt offline allowed gt lt information gt lt security gt lt all permissions gt lt security gt lt application desc main class com teamdev jxbrowser demo JxBrowserDemo gt lt resources gt lt jar href lib jxbrowserdemo jar main true gt lt jar href lib jxbrowser 2 x jar gt lt jar href lib engine gecko jar gt lt jar href lib MozillaGlue jar gt lt jar href lib Mozillalnterfaces jar gt lt jar href lib log4j 1 2 15 jar gt lt jar href lib slf4j api 1 5 8 jar gt lt jar href lib slf4j log4j12 1 5 8
3. packages 3 gtkmm 2 with all dependent packages libsigc 2 x GTK 2 x cairomm 4 Sun Microsystems Inc Java JDK 1 6 0 _12 32 bit or 64 bit version 5 X Server must be started and running 2 3 Mac OS X 1 Mac OS X 10 5 32 bit Apple Java 1 5 1 6 2 Mac OS X 10 6 32 bit or 64 bit Apple Java 1 6 JxBrowser Programmer s Guide Chapter 3 Browser Engines JxBrowser library allows you to use three browser engines in your Java application Mozilla Firefox Internet Explorer and Safari As you may see in Chapter 3 the HelloWorld sample uses the following code to create a Browser instance Browser browser BrowserFactory createBrowser You can use this code when you need to create a default Browser instance for the current platform The BrowserFactory createBrowser method returns the following Browser instance for a specified platform Windows Internet Explorer Linux Mozilla Firefox Mac OS X Apple Safari Please refer to the following chapters to find out how to create a specific Browser engine 3 1 Mozilla Firefox browser To create Mozilla Firefox browser engine you can use following code Browser browser BrowserFactory createBrowser BrowserType Mozilla This browser type can be used on Microsoft Windows Linux and Mac OS X Intel amp PPC platforms This browser type doesn t requires Mozilla FireFox application to be installed on operating system 3 2 Internet Explorer browser To create Intern
4. page For example browser executeScript document write Hello from JxBrowser This method also returns the result of JavaScript code execution as a String value So you can execute JavaScript code like this browser navigate http www google com browser waitReady String title browser executeScript document title System out printin title title 11 JxBrowser Programmer s Guide Chapter 10 Cookie management Each browser engine has its own cookie storage You can get access to the cookie storage of a specified browser engine you can use one of the following ways Browser browser BrowserFactory createBrowser BrowserType Mozilla Get access to the Mozilla engine cookie storage HttpCookieStorage mozillaCookieStorage browser getCookieStorage Get the list of all available cookies List lt HttpCookie gt cookies mozillaCookieStorage getCookies or BrowserServices browserServices BrowserServices getInstance Get access to the Mozilla engine cookie storage HttpCookieStorage mozillaCookieStorage browserServices getCookieStorage BrowserType Mozilla working with cookie storage 12 JxBrowser Programmer s Guide Chapter 11 Change user agent string The user agent string can be changed programatically via Browser setUserAgent method For example Browser browser BrowserFactory createBrowser BrowserType Mozilla Set custom user agent string for Mozilla browser
5. Ce JxBrowser Programmer s Guide Version 2 TeamDev 2000 2010 TeamDev Ltd JxBrowser Programmer s Guide Table of Contents Te LUI ER 1 CT UE tar tn anne tenant an Reda es it naar sa sa nn rss tenus 2 Me tele 2 cee ln CR ER ath apy sh E a E E ET A E A T E 2 lee 2 3 Browser ne UE 3 3 1 Mozilla Firefox BTS ie al ententes dun dena 3 3 2 Internet Explorer DrOWSEr sca csccdecicinniexiegsarsnemesssueieentcendananaedscestannanssnedumetexnenraeuedeeeneanssencede devine 3 3 3 Safari e 3 3 4 Libraries EIERE EIERE eendeitege degen nent 3 4 Navigation t0 URL is esis wesw eh ee canada ne Sudan pecan aie 6 5 Navigation to URL with POST data agence 7 6 Working with Browser EVENIS cs snes ie wisi nnn esit es eae eae gm ee enccnae 8 7 Pop up windows management assess canadensis cnc csesinenncnnaiennnendaansntwessnadeesannasanisscsdnanstnndsceneasaanmnsenndine 9 8 Working With Browser DialogS sssssmannannemnnaasnnennnnnnannnnmenanennnenenannnnnins 10 9 JavaScript Gxe Cut sisiaccicssciesccsiaseccceesectetensantercantecestencceteaseccseetecseacdesentecaseterexcceaceressceuereantocematenuuis 11 10 Cookie management rsssersasiernsrmersbinssntananmsansniensnssnrenanaiemessnsegniecdeannes 12 11 Change User agent String sssrsssssccssssonsonssssrmessancnesnsassanesncesensanensenssareeesaneneeecnut us 13 12 Using JxBrowser with Java Web Start ii snnnrrsserreennenennsnneennennennes 14 13 Using JxBrowser with
6. Java Applet ss sssssnnnennnnnnenennnneneneeennnns 18 14 JxBrowser System Properties nnnnnnnnsnnnneennenennnnes 19 ET iene cede crested ceed cae acme acide a Lea ec dca E 20 iii JxBrowser Programmer s Guide Chapter 1 Introduction All Java programmers who have ever developed a Web site testing tool or desktop Java application with an HTML viewer needed a library that could load display an HTML document and access its content Of course the implementation of such library from scratch may take a lot of programming and testing efforts Therefore integrating an existing browser is a preferable way JxBrowser is a cross platform library that enables seamless integration of Mozilla Firefox web browser into Java AWT Swing applications on Windows Linux Mac OS X platforms Additionally it allows inte gration of Microsoft Internet Explorer on Windows and Apple Safari on Mac OS X platform So using JxBrowser you can define which browser engine your Java application should use on different operating systems You can easily switch between browser engines and work with them via the same API JxBrowser Programmer s Guide Chapter 2 Requirements You can see the list of JxBrowser supported platforms at JxBrowser Support Site 2 1 Windows 1 Microsoft Windows XP Vista 7 or higher with x86 or x64 arch 2 Sun Microsystems Inc Java JDK 1 5 32 bit or 64 bit version 2 2 Linux 1 Linux Kernel 2 6 2 GTK 2 14 with all dependent
7. and another JNLP file included through extension tag which contains only JxBrowser libraries This technique is demonstrated in the example below The first file is an application JNLP file demo jnip lt jnlp spec 1 5 codebase http codebase href demo jnlp gt lt information gt lt title gt Demo Application lt title gt lt vendor gt TeamDev Ltd lt vendor gt lt description gt Demo Application lt description gt lt offline allowed gt lt information gt lt security gt lt all permissions gt lt security gt lt resources gt lt j2se version 1 5 initial heap size 64m max heap size 256m gt lt demo jar is your jar file signed with your own signature gt lt jar href demo jar gt lt extension name jxbrowser href JxBrowser jnlp gt lt resources gt lt application desc main class main_class gt lt jnlp gt The lt extension gt tag above makes the reference to the other jxbrowserjnlp file which has the following structure lt jnlp spec 1 5 codebase http codebase href JxBrowser jnlp gt lt information gt lt title gt JxBrowser resources lt title gt lt vendor gt TeamDev Ltd lt vendor gt homepage href http www teamdev com jxbrowser gt lt offline allowed gt lt information gt lt security gt lt all permissions gt lt security gt lt component desc gt lt resources gt lt jar href lib2 jxbrowser 2 x jar gt lt jar href lib2 engine
8. blems If you have any questions regarding JxBrowser please e mail us at jxbrowser support teamdev com JxBrowser Forum If you would like to discuss any topics related to JxBrowser please visit our support forum at JxBrowser forum 20
9. et Explorer browser engine you can use following code Browser browser BrowserFactory createBrowser Browserlype IE This browser type can be used only on Microsoft Windows platform This browser type requires MS Internet Explorer 6 0 or later application to be installed on operating system 3 3 Safari browser To create Safari browser engine you can use following code Browser browser BrowserFactory createBrowser BrowserType Safari This browser type can be used only on Mac OS X Intel 10 5 platform This browser type requires Safari to be installed on operating system JxBrowser Programmer s Guide Chapter 3 Browser Engines 3 4 Libraries Dependency Installation package of JxBrowser contains jar files for all supported platforms Windows Mac OS X and Linux and Browser engines Below you can find the list of required libraries for each engine for each platform Core libraries are required for all engines and platforms jxbrowser 2 x jar slf4j api 1 5 8 jar slf4j log4j12 1 5 8 jar log4j 1 2 15 jar Mozilla browser Windows only JDK 32 bit engine gecko jar MozillaGlue jar Mozillalnterfaces jar xulrunner windows jar winpack 3 8 jar Mozilla browser Linux JDK 32 bit or 64 bit engine gecko jar MozillaGlue jar Mozillalnterfaces jar xulrunner linux jar xulrunner linux64 jar tuxpack 0 2 jar Mozilla browser Mac OS X only JDK 32 bit or enabled 32 bit mode engine gecko jar MozillaGlue jar
10. gecko jar gt lt jar href lib2 MozillaGlue jar gt lt jar href lib2 Mozillalnterfaces jar gt lt jar href lib2 l0g4j 1 2 15 jar gt lt jar href lib2 slf4j api 1 5 8 jar gt lt jar href lib2 slf4j log4j12 1 5 8 jar gt lt resources gt lt resources os Windows gt lt j2se version 1 5 initial heap size 128m max heap size 512m gt lt jar href lib2 engine ie jar gt 16 JxBrowser Programmer s Guide Chapter 12 Using JxBrowser with Java Web Start lt jar href lib2 winpack 3 8 jar gt lt jar href lib2 xulrunner windows jar gt lt resources gt lt resources os Mac OS X gt lt j2se version 1 5 initial heap size 128m max heap size 512m java vm args d32 gt lt jar href lib2 engine webkitjar gt lt jar href lib2 xulrunner mac jar gt lt resources gt lt resources os Linux gt lt j2se version 1 6 initial heap size 128m max heap size 512m gt lt jar href lib tuxpack 0 2 jar gt lt resources gt lt resources os Linux arch ppc 1386 i686 gt lt jar href lib xulrunner linux jar gt lt resources gt lt resources os Linux arch x86_64 amd64 gt lt jar href lib xulrunner linux64 jar gt lt resources gt lt jnlp gt 17 JxBrowser Programmer s Guide Chapter 13 Using JxBrowser with Java Applet You can use JxBrowser in your Java Applet application in the same way as a standard Java library JxBrowser requires access to t
11. he file system so you should sign all JARs in your Java Applet application including all JxBrowser library JARs By default all JxBrowser JARs are signed with TeamDev signature So you need to remove TeamDev signature before signing with your one To remove TeamDev signatures you should remove the META INF TEAMDEVC RSA and META INF TEAMDEVC SF files from each JAR from JxBrowser distribution package When all your application JARs are signed including all required JxBrowser JARs you can configure your APPLET tag For example lt APPLET code Application class codebase archive applicationjar lt List of required JxBrowser JARs gt WIDTH 800 HEIGHT 400 gt Browser doesn t support Java Applets lt APPLET gt 18 JxBrowser Programmer s Guide Chapter 14 JxBrowser System Properties JxBrowser library uses several System Properties which can be useful for you You should set up these properties before creating a browser instance in the following way System setProperty property_name value Basic properties teamdev license info true false allows enabling or disabling the license information printing in con sole IE specific properties JExplorer runinisolatedProcess true false allows enabling or disabling InlsolatedProcess mode for IE engine In this mode each IE engine instance will be running in a separate native process JExplorer32 2 2 10 exe On JDK 32 bit this mode by default is enabled To disable this m
12. jar gt lt resources gt lt resources os Windows gt lt j2se version 1 5 initial heap size 128m max heap size 512m gt lt jar href lib engine ie jar gt lt jar href lib winpack 3 8 jar gt lt jar href lib xulrunner windows jar gt lt resources gt lt resources os Mac OS X gt lt j2se version 1 5 initial heap size 128m max heap size 512m java vm args d32 gt lt jar href lib engine webkit jar gt lt jar href lib xulrunner mac jar gt lt resources gt lt resources os Linux gt lt j2se version 1 6 initial heap size 128m max heap size 512m gt lt jar href lib tuxpack 0 2 jar gt lt resources gt lt resources os Linux arch ppc i386 i686 gt lt jar href lib xulrunner linux jar gt lt resources gt lt resources os Linux arch x86_64 amd64 gt lt jar href lib xulrunner linux64 jar gt lt resources gt lt jnlp gt Library version can be changed in further JxBrowser releases Important Please note that JNLP file must contain the following options to successfully start JxBrowser library 14 JxBrowser Programmer s Guide Chapter 12 Using JxBrowser with Java Web Start lt security gt lt all permissions gt lt security gt JxBrowser Online Demo JNLP file is configured to use the following libraries jxbrowserdemo jar the JxBrowser demo application library with the main class log4j 1 2 15 jar slf4j api 1 5 8 jar slf4j
13. lder After that you should run following command from command line jar uf demo jar META INF teamdev licenses 3 Sign all your application JAR files Please note that by default all JxBrowser libraries are signed with TeamDev signature For this purpose you can use the following ANT templates lt project name Sample default build basedir gt lt target name demojar gt lt property name demoJarName value demo jar gt lt signjar jar demoJarName alias your_alias keystore your_keystore keypass your_keypass storepass your_storepass gt lt target gt lt project gt 15 JxBrowser Programmer s Guide Chapter 12 Using JxBrowser with Java Web Start where your_alias your_keystore your_keypass your_storepass signjar parameters You can see their description in Apache Ant User Manual at http ant apache org Or you can use the jarsigner tool to sign your application JAR file demo jar jarsigner keystore your_keystore_file storepass your_storepass keypass your_keypass demo jar your_alias 4 Create and configure your application JNLP file 5 Upload your application JAR files JxBrowser JAR files and JNLP file to a Web server Please note that JxBrowser libraries are already signed with TeamDev signature So in order to use already signed JxBrowser libraries with your application JNLP file you can use the lt extension gt tag So the result JNLP file should contain only your application libraries
14. log4j12 1 5 8 jar JxBrowser logging libraries jxbrowser 2 x jar JxBrowser API library engine ie jar Microsoft Internet Explorer engine support engine gecko jar Mozilla Firefox engine support engine webkit jar Apple Safari WebKit engine support winpack 3 8 jar provides access to Microsoft Windows native platform API tuxpack 0 2 jar provides access to Linux native platform API xulrunner windows jar xulrunner linux jar xulrunner linux64 jar xulrunner macjar Mozilla XULRunner packages for Microsoft Windows Linux and Mac OS X MozillaGlue jar MozillaInterfaces jar third party Java libraries required for Mozilla Firefox engine To deploy your application via Java Web Start please use the following steps 1 Pack your application classes into application JAR file s demo jar 2 Put the JxBrowser runtime license file teamdev licenses into META INF folder of your application JAR file For this you can use the following ANT script lt jar destfile demoJarName gt lt fileset dir classes includes gt lt zipfileset dir srcPath lic includes teamdev licenses prefix META INF gt lt jar gt where classes path to class files of demo application srcPath lic path to licence file teamdev licenses Or you can use the jar tool to update your application JAR file demo jar For this you should create META_INF folder and copy license file teamdev licenses to META_INF fo
15. n to open a new pop up window JxBrowser provides functionality that allows handle opening a new pop up window By default JxBrowser handles opening a new pop up window and displays it in a separate Swing frame To change the default behavior you can implement and register your own NewWindowManager The following sample demonstrates how to do this Browser browser BrowserFactory createBrowser browser getServices setNewWindowManager new NewWindowManager public NewWindowContainer evaluateWindow final NewWindowParams params return new NewWindowContainer public void insertBrowser final Browser browser creates JFrame in which browser will be embedded final JFrame popupFrame new JFrame Container contentPane popupFrame getContentPane contentPane add browser getComponent BorderLayout CENTER sets window bounds using popup window params popupFrame setBounds params getBounds popupFrame setVisible true registers window listener to dispose Browser instance on window close popupFrame addWindowListener new WindowAdapter Override public void windowClosing WindowEvent e browser dispose ND registers Browser dispose listener to dispose window when Browser is disposed e g using the window close JavaScript function browser addDisposeListener new DisposeListener public void browserDisposed DisposeEvent event popupFrame dispose p To suppress all pop up windows y
16. ode you can set this property to false Mozilla specific properties jxbrowser xulrunner dir absolute or relative path using this property you can configure the path to the directory where XULRunner will be extracted By default XULRunner will be extracted at first start into the USER_HOME JxBrowser directory jxbrowser xulrunner profile dir absolute or relative path using this property you can configure the path to the profile directory By default profile directory will be created at first start into the USER_HOME JxBrowser directory jxbrowser xulrunner use profile true false allows creating engine with without profile directory By default profile directory will be created GRE_HOME absolute or relative path allows specifying the path to the directory where XULRunner is located By default XULRunner will be extracted at first start into the USER HOME JxBrowser directory XULRunner extraction may take several seconds To avoid extraction you can provide the path to the directory with already extracted XULRunner jxbrowser plugin dir absolute or relative path allows specifying the path to the directory where Mozilla plugins are located 19 JxBrowser Programmer s Guide Chapter 15 Support JxBrowser Support Site You can find more information about how to use JxBrowser library at JxBrowser Support Site JxBrowser Samples You can find JxBrowser samples on the following resource JxBrowser Samples Reporting Pro
17. ou can use the following code browser getServices setNewWindowManager new NewWindowManager public NewWindowContainer evaluateWindow NewWindowParams params return null gt JxBrowser Programmer s Guide Chapter 8 Working with Browser Dialogs By default a Browser component displays all dialogs such as JavaScript Alert Confirmation Prompt or JavaScript Error If you want to change this behavior you should take a look at the com teamdev jxbrowser prompt F interface and the BrowserServices setPromptService PromptService promptService method Sometimes you may need to prevent all dialogs from displaying In this case you just need to set a com teamdev jxbrowser prompt SilentPromptService implementation as a default PromptService For example BrowserServices getInstance setPromptService new SilentPromptService You can also override a default implementation of PromptService and provide your own behavior for a specified dialog For example we need to display all dialogs but all Confirmation dialogs should always return CANCEL value BrowserServices browserServices BrowserServices getInstance browserServices setPromptService new DefaultPromptService Override public CloseStatus confirmationRequested DialogParams params return CloseStatus CANCEL p 10 JxBrowser Programmer s Guide Chapter 9 JavaScript execution With Browser executeScript method you can execute any JavaScript code on a loaded web
18. y Example browser navigate http www google com browser waitReady Also please see the Browser stop Browser refresh Browser goBack and Browser goForward methods JxBrowser Programmer s Guide Chapter 5 Navigation to URL with POST data During navigation to a specified URL you can also pass POST data The following sample demonstrates how to do this browser navigate http www google com name Alex amp product Pizza JxBrowser Programmer s Guide Chapter 6 Working with Browser Events Browser engines send notifications about their various events related to navigation document loading completion document title or status bar text change etc NavigationListener ProgressListener StatusListener and TitleListener provide methods that are called when a browser event occurs The following sample demonstrates how to add a navigation started and finished event listener to the browser Browser browser BrowserFactory createBrowser browser addNavigationListener new NavigationListener public void navigationStarted NavigationEvent event public void navigationFinished NavigationFinishedEvent event p StatusListener handles browser state change event such as changes of the status text navigation button state etc TitleListener handles document title change events JxBrowser Programmer s Guide Chapter 7 Pop up windows management A lot of web pages use the window open JavaScript functio
Download Pdf Manuals
Related Search
Related Contents
Novo espectrógrafo para o OPD - Laboratório Nacional de Astrofísica Manuel d`utilisation de VidOn.me Android Blu 仕様書全体一括ダウンロード Sony Mobile Communications AB Guía de inicio rápido Se détendre - Communauté de communes du Canton de Rumilly Copyright © All rights reserved.
Failed to retrieve file