Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT HTML browser component
SWT HTML browser component [message #449137] Tue, 18 January 2005 18:52 Go to next message
Eclipse UserFriend
Originally posted by: sylcheung.gmail.com

In SWT, there is a HTML browser component. Can someone please tell me
if I can walk thru the dom in my Java application which uses that HTML
browser component?

Thank you.

Sam
Re: SWT HTML browser component [message #449141 is a reply to message #449137] Tue, 18 January 2005 18:55 Go to previous messageGo to next message
Henning Rogge is currently offline Henning RoggeFriend
Messages: 148
Registered: July 2009
Senior Member
Samuel Cheung wrote:
> In SWT, there is a HTML browser component. Can someone please tell me
> if I can walk thru the dom in my Java application which uses that HTML
> browser component?

Look at
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets

The "browser" snipplets might be usefull for you.

Henning.
Re: SWT HTML browser component [message #449155 is a reply to message #449141] Tue, 18 January 2005 22:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sylcheung.gmail.com

Thanks.
But I am looking for a way to walk thru the dom in my JavaApplication
not just using JavaScript.

Let's say I want my JavaApplication to display all the Forms name in the
html page I load using SWT html browser. How can I achieve that?

Thank you.


Henning Rogge wrote:
> Samuel Cheung wrote:
>
>> In SWT, there is a HTML browser component. Can someone please tell me
>> if I can walk thru the dom in my Java application which uses that HTML
>> browser component?
>
>
> Look at
> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
>
>
> The "browser" snipplets might be usefull for you.
>
> Henning.
Re: SWT HTML browser component [message #449177 is a reply to message #449155] Tue, 18 January 2005 23:55 Go to previous messageGo to next message
Hugo A. Garcia is currently offline Hugo A. GarciaFriend
Messages: 258
Registered: July 2009
Senior Member
You could use JDOM. For more information go to http://www.jdon.org

-H

Samuel Cheung wrote:
> Thanks.
> But I am looking for a way to walk thru the dom in my JavaApplication
> not just using JavaScript.
>
> Let's say I want my JavaApplication to display all the Forms name in the
> html page I load using SWT html browser. How can I achieve that?
>
> Thank you.
>
>
> Henning Rogge wrote:
>
>> Samuel Cheung wrote:
>>
>>> In SWT, there is a HTML browser component. Can someone please tell
>>> me if I can walk thru the dom in my Java application which uses that
>>> HTML browser component?
>>
>>
>>
>> Look at
>> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
>>
>>
>> The "browser" snipplets might be usefull for you.
>>
>> Henning.
Re: SWT HTML browser component [message #449179 is a reply to message #449177] Wed, 19 January 2005 00:05 Go to previous messageGo to next message
Hugo A. Garcia is currently offline Hugo A. GarciaFriend
Messages: 258
Registered: July 2009
Senior Member
http://www.jdom.org sorry for the typo.

Hugo A. Garcia wrote:
> You could use JDOM. For more information go to http://www.jdon.org
>
> -H
>
> Samuel Cheung wrote:
>
>> Thanks.
>> But I am looking for a way to walk thru the dom in my JavaApplication
>> not just using JavaScript.
>>
>> Let's say I want my JavaApplication to display all the Forms name in
>> the html page I load using SWT html browser. How can I achieve that?
>>
>> Thank you.
>>
>>
>> Henning Rogge wrote:
>>
>>> Samuel Cheung wrote:
>>>
>>>> In SWT, there is a HTML browser component. Can someone please tell
>>>> me if I can walk thru the dom in my Java application which uses that
>>>> HTML browser component?
>>>
>>>
>>>
>>>
>>> Look at
>>> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
>>>
>>>
>>> The "browser" snipplets might be usefull for you.
>>>
>>> Henning.
Re: SWT HTML browser component [message #449194 is a reply to message #449155] Wed, 19 January 2005 03:42 Go to previous messageGo to next message
Bernhard Fastenrath is currently offline Bernhard FastenrathFriend
Messages: 10
Registered: July 2009
Junior Member
Samuel Cheung wrote:
> Thanks.
> But I am looking for a way to walk thru the dom in my JavaApplication
> not just using JavaScript.

http://jrex.mozdev.org/ can do that but it's not an SWT widget
and it seemed unstable last time I tried it.

> Let's say I want my JavaApplication to display all the Forms name in the
> html page I load using SWT html browser. How can I achieve that?

You could wrap a minimal JavaScript implementation into your own
Java set/query API. Finding forms and collecting their names could
still be quite efficient while exporting the whole DOM tree this
way might be a bit slow.

> Thank you.
>
> Henning Rogge wrote:
>
>> Samuel Cheung wrote:
>>
>>> In SWT, there is a HTML browser component. Can someone please tell
>>> me if I can walk thru the dom in my Java application which uses that
>>> HTML browser component?
>>
>> Look at
>> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
>>
>>
>> The "browser" snipplets might be usefull for you.
>>
>> Henning.
Re: SWT HTML browser component [message #449195 is a reply to message #449177] Wed, 19 January 2005 03:49 Go to previous messageGo to next message
Bernhard Fastenrath is currently offline Bernhard FastenrathFriend
Messages: 10
Registered: July 2009
Junior Member
Hugo A. Garcia wrote:
> You could use JDOM. For more information go to http://www.jdon.org
>
> -H

That's an XML parsing API which wouldn't even be usable as a
preprocessor for most HTML pages in case you were trying to
suggest to parse the page before feeding it to the browser.

Accessing the DOM tree of the browser is, for example,
possible through
http://www.alphaworks.ibm.com/aw.nsf/html/weblets or
http://jrex.mozdev.org/
Re: SWT HTML browser component [message #449196 is a reply to message #449195] Wed, 19 January 2005 05:06 Go to previous messageGo to next message
Bernhard Fastenrath is currently offline Bernhard FastenrathFriend
Messages: 10
Registered: July 2009
Junior Member
Bernhard Fastenrath wrote:
> Hugo A. Garcia wrote:
>
>> You could use JDOM. For more information go to http://www.jdon.org
>>
>> -H
>
> That's an XML parsing API which wouldn't even be usable as a
> preprocessor for most HTML pages in case you were trying to
> suggest to parse the page before feeding it to the browser.
>
> Accessing the DOM tree of the browser is, for example,
> possible through
> http://www.alphaworks.ibm.com/aw.nsf/html/weblets or
> http://jrex.mozdev.org/

Weblets seem to be obsolete.
Re: SWT HTML browser component [message #449199 is a reply to message #449195] Wed, 19 January 2005 10:45 Go to previous messageGo to next message
Hugo A. Garcia is currently offline Hugo A. GarciaFriend
Messages: 258
Registered: July 2009
Senior Member
yes it is an XML, XHTML procesor that gives you a better document model
than DOM or if you really have to use DOM then you can easily manipute
it using JDOM. In addition, only really misbehaved HTML like that
produced by Word is a problem. You can easily apply JTidy or NekoHTML or
TagSoup to clean up the HTML before creating a DOM.

Actually... this is what I have to do in my app. Haven't implement using
the Browser widget but I still have to go through the above step
before display the documents I deal with since I have to manipulate the
document before dsiplaying. Still building the rest of the GUI so when I
get to integrating the Browser widget I can let you know.

-H

Bernhard Fastenrath wrote:
> Hugo A. Garcia wrote:
>
>> You could use JDOM. For more information go to http://www.jdon.org
>>
>> -H
>
>
> That's an XML parsing API which wouldn't even be usable as a
> preprocessor for most HTML pages in case you were trying to
> suggest to parse the page before feeding it to the browser.
>
> Accessing the DOM tree of the browser is, for example,
> possible through
> http://www.alphaworks.ibm.com/aw.nsf/html/weblets or
> http://jrex.mozdev.org/
Re: SWT HTML browser component [message #449214 is a reply to message #449155] Wed, 19 January 2005 15:38 Go to previous message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
For an example on how to get Form names through a javascript query see
below - it is adapted from snippet 160 (query DOM node value).
Chris

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;

public class PRBrowser {
public static void main(String [] args) {
final String html = "<html><body><form name='my form 1'><input
type='button' value='push me'></form><form name='my form 2'><input
type='button' value='push me 2'></form><h1 id='myid'>HTML
Document</h1></body></html>";
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.NONE);
browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
browser.setData("query", event.text);
}
});
browser.addProgressListener(new ProgressListener() {
public void changed(ProgressEvent event) {
}
public void completed(ProgressEvent event) {
/*
* Use JavaScript to query the list of Form name attributes in the
document that was loaded.
*
* Assign result to the window property status to pass the result to the
StatusTextListener
* This trick is required since <code>execute</code> does not return the
<code>String</code>
* directly.
*/
boolean result =
browser.execute("window.status=document.forms.length;");
if (!result) {
/* Script may fail or may not be supported on certain platforms. */
System.out.println("Script was not executed.");
return;
}
String value = (String)browser.getData("query");
int length = Integer.parseInt(value);
String[] forms = new String[length];
for (int i = 0; i < forms.length; i++) {
browser.execute("window.status=document.forms["+i+"].name; ");
forms[i] = (String)browser.getData("query");
System.out.println("Form name: <"+forms[i]+">");
}
/* results in forms array */
}
});
/* Load an HTML document */
browser.setText(html);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Previous Topic:Traversing out of a Text widget.
Next Topic:How do you use FormLayout on a Composite with a Vertical Scrollbar?
Goto Forum:
  


Current Time: Fri Dec 13 23:44:48 GMT 2019

Powered by FUDForum. Page generated in 0.02209 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top