Load XWT from a string in memory [message #520669] |
Sat, 13 March 2010 20:00  |
Eclipse User |
|
|
|
I have an application that will be creating XWT on the fly. I'd like to be able to grab the "XWT string" that is created and load it. I've only seen XWT being loaded from a file, using a URL. Is there a way to load it from memory ?
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Load XWT from a string in memory [message #520972 is a reply to message #520960] |
Mon, 15 March 2010 21:45   |
Eclipse User |
|
|
|
In the ElementManager method below,
public Element load(InputStream stream, URL url) throws Exception {
reset();
// Initialize document root
PushbackInputStream pis = null;
if (stream != null) {
if (stream instanceof PushbackInputStream) {
pis = (PushbackInputStream) stream;
} else {
pis = new PushbackInputStream(stream, 4);
}
}
documentRoot.init(pis, url.toString());
InputStream input = pis;
if (pis == null) {
input = documentRoot.openStream();
}
doLoad(input);
input = documentRoot.openStream();
loadXData(input);
input.close();
return rootElement;
}
The url argument can't be null because of
documentRoot.init(pis, url.toString());.
So even if you pass in a valid stream like
ByteArrayInputStream bs = new ByteArrayInputStream(myXwt.getBytes());
to
Control c = XWT.load(aShell, bs, myUrl, contextObject);
the documentRoot.openStream() call requires a valid URL to
keep "new URL(...).openStream();" happy.
So if you have a stream with your XWT spec, I am not sure
how this combination of arguments makes sense to use.
The above post states,
"The second argument indicates the location to find the Java class event
handler. It shouldn't be null."
But I am not sure what an example of a "Java class event handler"
would be especially when you are trying to debug things.
Maybe Yves YANG can elaborate???
WRT the question of where one can get a "context" for the statement,
"You can call XWT.findElementByName(context, "<my name>")"
see the post within
http://www.eclipse.org/forums/index.php?t=msg&goto=50515 3&
|
|
|
Re: Load XWT from a string in memory [message #521019 is a reply to message #520972] |
Tue, 16 March 2010 04:42  |
Eclipse User |
|
|
|
<allygirl@mailinator.com> wrote in message
news:hnmnse$e4m$1@build.eclipse.org...
> In the ElementManager method below,
>
> public Element load(InputStream stream, URL url) throws Exception {
> reset();
> // Initialize document root
> PushbackInputStream pis = null;
> if (stream != null) {
> if (stream instanceof PushbackInputStream) {
> pis = (PushbackInputStream) stream;
> } else {
> pis = new PushbackInputStream(stream, 4);
> }
> }
> documentRoot.init(pis, url.toString());
> InputStream input = pis;
> if (pis == null) {
> input = documentRoot.openStream();
> }
> doLoad(input);
> input = documentRoot.openStream();
> loadXData(input);
> input.close();
> return rootElement;
> }
>
> The url argument can't be null because of
> documentRoot.init(pis, url.toString());.
>
> So even if you pass in a valid stream like
> ByteArrayInputStream bs = new ByteArrayInputStream(myXwt.getBytes());
> to
> Control c = XWT.load(aShell, bs, myUrl, contextObject);
> the documentRoot.openStream() call requires a valid URL to
> keep "new URL(...).openStream();" happy.
> So if you have a stream with your XWT spec, I am not sure how this
> combination of arguments makes sense to use.
>
> The above post states, "The second argument indicates the location to find
> the Java class event
> handler. It shouldn't be null."
>
> But I am not sure what an example of a "Java class event handler"
> would be especially when you are trying to debug things.
we need to develop a snippet. Unfortunately, I'm busy for eclipsecon for
now. I can do it after. Please fill a bug and CC to me.
This feature is used by our XML editor for instant preview of the code in
memory. The class is XWTView in the plugin org.eclipse.e4.xwt.tools.ui.
best regards
Yves YANG
>
> Maybe Yves YANG can elaborate???
>
> WRT the question of where one can get a "context" for the statement,
> "You can call XWT.findElementByName(context, "<my name>")"
> see the post within
> http://www.eclipse.org/forums/index.php?t=msg&goto=50515 3&
|
|
|
Re: Load XWT from a string in memory [message #570549 is a reply to message #520767] |
Mon, 15 March 2010 05:31  |
Eclipse User |
|
|
|
Sorry, I would liek to say: "There is an API in the class XWT using
InputStream, instead of URL".
yves
"Yves YANG" <yves.yang@soyatec.com> wrote in message
news:hnkumd$q9o$1@build.eclipse.org...
> There is a API in the class API of XWT using InputStream, instead of URL.
> But we need more tests.
>
> Best regards
> Yves YANG
> "Frank Gualtieri" <fgualtieri@promia.com> wrote in message
> news:hnhcf4$hdc$1@build.eclipse.org...
>>I have an application that will be creating XWT on the fly. I'd like to
>>be able to grab the "XWT string" that is created and load it. I've only
>>seen XWT being loaded from a file, using a URL. Is there a way to load it
>>from memory ?
>
>
|
|
|
Re: Load XWT from a string in memory [message #570559 is a reply to message #520768] |
Mon, 15 March 2010 06:41  |
Eclipse User |
|
|
|
Is there an API for XWT on line somewhere 'cause I wasn't able to find it ? Is the method you mentioned available or when you say it needs more testing do you mean it is not yet available ? If it is available, can you give me a quick example of how it would be called ?
|
|
|
Re: Load XWT from a string in memory [message #570569 is a reply to message #570559] |
Mon, 15 March 2010 07:58  |
Eclipse User |
|
|
|
I use following code to render XWT document.
String content = m_context.getContent();
Map<String, Object> options = Maps.newHashMap();
XWT.loadWithOptions(IOUtils.toInputStream(content), url, options);
Where IOUtils is org.apache.commons.io.IOUtils is from Jakarta Commons.
--
Konstantin Scheglov,
Instantiations, Inc.
|
|
|
Re: Load XWT from a string in memory [message #570588 is a reply to message #520794] |
Mon, 15 March 2010 08:17  |
Eclipse User |
|
|
|
Konstantin,
Thanks for the quick response. I am new to XWT so I'll ask the questions, although they may seem ridiculous.
In your example:
String content = m_context.getContent();
Map<String, Object> options = Maps.newHashMap();
XWT.loadWithOptions(IOUtils.toInputStream(content), url, options);
1) is the value of url null ?
2) once the "load" is done how do I get the Control that is returned from the call to XWT.load... to display ?
Frank
|
|
|
Re: Load XWT from a string in memory [message #570633 is a reply to message #570588] |
Mon, 15 March 2010 17:11  |
Eclipse User |
|
|
|
"Frank Gualtieri" <fgualtieri@promia.com> wrote in message
news:hnl8h6$vbm$1@build.eclipse.org...
> Konstantin,
>
> Thanks for the quick response. I am new to XWT so I'll ask the questions,
> although they may seem ridiculous.
>
> In your example:
> String content = m_context.getContent();
> Map<String, Object> options = Maps.newHashMap();
> XWT.loadWithOptions(IOUtils.toInputStream(content), url, options);
>
> 1) is the value of url null ?
The second argument indicates the location to find the Java class event
handler It shouldn't be null.
> 2) once the "load" is done how do I get the Control that is returned from
> the call to XWT.load... to display ?
You can call XWT.findElementByName(context, "<my name>")
There are a lot of examples in org.eclipse.e4.xwt.tests. I recommand to take
a look.
Best regards
Yves YANG
>
> Frank
>
>
|
|
|
Re: Load XWT from a string in memory [message #570648 is a reply to message #520937] |
Mon, 15 March 2010 17:13  |
Eclipse User |
|
|
|
"Yves YANG" <yves.yang@soyatec.com> wrote in message
news:hnm7pb$j4l$1@build.eclipse.org...
> "Frank Gualtieri" <fgualtieri@promia.com> wrote in message
> news:hnl8h6$vbm$1@build.eclipse.org...
>> Konstantin,
>>
>> Thanks for the quick response. I am new to XWT so I'll ask the
>> questions, although they may seem ridiculous.
>>
>> In your example:
>> String content = m_context.getContent();
>> Map<String, Object> options = Maps.newHashMap();
>> XWT.loadWithOptions(IOUtils.toInputStream(content), url, options);
>>
>> 1) is the value of url null ?
>
> The second argument indicates the location to find the Java class event
> handler It shouldn't be null.
>
>> 2) once the "load" is done how do I get the Control that is returned from
>> the call to XWT.load... to display ?
>
> You can call XWT.findElementByName(context, "<my name>")
I suppose I misunderstood the question. The load() return a root element,
you can use it to display.
Best regards
Yves YANG
>
> There are a lot of examples in org.eclipse.e4.xwt.tests. I recommand to
> take a look.
>
> Best regards
> Yves YANG
>>
>> Frank
>>
>>
>
>
|
|
|
|
|
Re: Load XWT from a string in memory [message #570703 is a reply to message #570670] |
Mon, 15 March 2010 19:36  |
Eclipse User |
|
|
|
OK... I checked out the e4 xwt tests and didn't find one that used the loadWithOptions method that takes the stream, url, and Map as parms.
Can you tell me where another example might be or can you write something a bit more informative ?
|
|
|
Re: Load XWT from a string in memory [message #570715 is a reply to message #570703] |
Mon, 15 March 2010 21:45  |
Eclipse User |
|
|
|
In the ElementManager method below,
public Element load(InputStream stream, URL url) throws Exception {
reset();
// Initialize document root
PushbackInputStream pis = null;
if (stream != null) {
if (stream instanceof PushbackInputStream) {
pis = (PushbackInputStream) stream;
} else {
pis = new PushbackInputStream(stream, 4);
}
}
documentRoot.init(pis, url.toString());
InputStream input = pis;
if (pis == null) {
input = documentRoot.openStream();
}
doLoad(input);
input = documentRoot.openStream();
loadXData(input);
input.close();
return rootElement;
}
The url argument can't be null because of
documentRoot.init(pis, url.toString());.
So even if you pass in a valid stream like
ByteArrayInputStream bs = new ByteArrayInputStream(myXwt.getBytes());
to
Control c = XWT.load(aShell, bs, myUrl, contextObject);
the documentRoot.openStream() call requires a valid URL to
keep "new URL(...).openStream();" happy.
So if you have a stream with your XWT spec, I am not sure
how this combination of arguments makes sense to use.
The above post states,
"The second argument indicates the location to find the Java class event
handler. It shouldn't be null."
But I am not sure what an example of a "Java class event handler"
would be especially when you are trying to debug things.
Maybe Yves YANG can elaborate???
WRT the question of where one can get a "context" for the statement,
"You can call XWT.findElementByName(context, "<my name>")"
see the post within
http://www.eclipse.org/forums/index.php?t=msg&goto=50515 3&
|
|
|
Re: Load XWT from a string in memory [message #570764 is a reply to message #570715] |
Tue, 16 March 2010 04:42  |
Eclipse User |
|
|
|
<allygirl@mailinator.com> wrote in message
news:hnmnse$e4m$1@build.eclipse.org...
> In the ElementManager method below,
>
> public Element load(InputStream stream, URL url) throws Exception {
> reset();
> // Initialize document root
> PushbackInputStream pis = null;
> if (stream != null) {
> if (stream instanceof PushbackInputStream) {
> pis = (PushbackInputStream) stream;
> } else {
> pis = new PushbackInputStream(stream, 4);
> }
> }
> documentRoot.init(pis, url.toString());
> InputStream input = pis;
> if (pis == null) {
> input = documentRoot.openStream();
> }
> doLoad(input);
> input = documentRoot.openStream();
> loadXData(input);
> input.close();
> return rootElement;
> }
>
> The url argument can't be null because of
> documentRoot.init(pis, url.toString());.
>
> So even if you pass in a valid stream like
> ByteArrayInputStream bs = new ByteArrayInputStream(myXwt.getBytes());
> to
> Control c = XWT.load(aShell, bs, myUrl, contextObject);
> the documentRoot.openStream() call requires a valid URL to
> keep "new URL(...).openStream();" happy.
> So if you have a stream with your XWT spec, I am not sure how this
> combination of arguments makes sense to use.
>
> The above post states, "The second argument indicates the location to find
> the Java class event
> handler. It shouldn't be null."
>
> But I am not sure what an example of a "Java class event handler"
> would be especially when you are trying to debug things.
we need to develop a snippet. Unfortunately, I'm busy for eclipsecon for
now. I can do it after. Please fill a bug and CC to me.
This feature is used by our XML editor for instant preview of the code in
memory. The class is XWTView in the plugin org.eclipse.e4.xwt.tools.ui.
best regards
Yves YANG
>
> Maybe Yves YANG can elaborate???
>
> WRT the question of where one can get a "context" for the statement,
> "You can call XWT.findElementByName(context, "<my name>")"
> see the post within
> http://www.eclipse.org/forums/index.php?t=msg&goto=50515 3&
|
|
|
Powered by
FUDForum. Page generated in 1.51255 seconds