Re: [Cocoa-Java] WebView and HTML string how to ?
Re: [Cocoa-Java] WebView and HTML string how to ?
- Subject: Re: [Cocoa-Java] WebView and HTML string how to ?
- From: Andy Lee <email@hidden>
- Date: Fri, 8 Jul 2005 03:39:10 -0400
On Jul 7, 2005, at 3:48 AM, Yvon Thoraval wrote:
Hey all,
i'm able to build and run a WebView from a Cocoa-Java app using an
external URL by :
<code>
NSSelector selector=new NSSelector("takeStringURLFrom",new Class
[]{NSTextField.class});
NSApplication.sharedApplication().sendActionToTargetFromSender
(selector,browserView,urlField);
</code>
but, in my case, i don't have any URL nor file because the html
string is generated "on the fly" fram database dats.
someone said i have to use :
[[myWebView mainFrame] loadHTMLString:myHTMLString baseURL:[NSURL
fileURLWithPath:@"/path/to/base"];
but, at present time, i'm unable to transalate Obj-C code into java
one.
There is no Java API for WebKit, so you won't be able to do a direct
translation. It would be nice to simply say:
myWebView.mainFrame().loadHTMLStringBaseURL(myHTMLString,
myBaseURL);
...but you can't.
I haven't used Cocoa Java myself, but I'm *guessing* you can achieve
want you want using NSSelector. For example, you have a reference to
an object you know is a WebView, and you want to send it a
"mainFrame" message. It looks like you could do it like this:
Object myWebFrame = NSSelector.invoke("mainFrame", null,
myWebView, null);
This part of the job is relatively simple because "mainFrame" doesn't
take any arguments. The rest of the job should look familiar if
you've used reflection in Java.
Note that the Objective-C expression
[[myWebView mainFrame]
loadHTMLString:myHTMLString
baseURL:[NSURL fileURLWithPath:@"/path/to/base"]];
(which I've indented for clarity) contains three messages:
* A "mainFrame" message, which takes no arguments, is sent to
myWebView, which is presumably an instance of WebView. It returns an
instance of WebFrame.
* A "fileURLWithPath:" message (note the colon) is sent to the
*class* NSURL, and returns an *instance* of NSURL.
* A "loadHTMLString:baseURL:" message is sent to the WebFrame that
was obtained earlier. Note this message name has *two* colons. It
takes two arguments, and its return type is void.
I haven't used Cocoa Java myself, so I may be missing things... maybe
someone else can correct me or expand on these notes.
Good night!
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden