Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Load XWT from a string in memory(Loading XWT from a string in memory)
Load XWT from a string in memory [message #520669] Sun, 14 March 2010 01:00 Go to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 #520767 is a reply to message #520669] Mon, 15 March 2010 09:29 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
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 #520768 is a reply to message #520767] Mon, 15 March 2010 09:31 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
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 #520785 is a reply to message #520768] Mon, 15 March 2010 10:41 Go to previous messageGo to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 #520794 is a reply to message #520785] Mon, 15 March 2010 11:58 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
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,
Google, Inc.
Re: Load XWT from a string in memory [message #520796 is a reply to message #520794] Mon, 15 March 2010 12:17 Go to previous messageGo to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 #520937 is a reply to message #520796] Mon, 15 March 2010 21:11 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
"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 #520939 is a reply to message #520937] Mon, 15 March 2010 16:24 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
"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 #520947 is a reply to message #520939] Mon, 15 March 2010 21:47 Go to previous messageGo to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
I still cannot get the load the work.

Your suggestion to look at some fo the examples in org.eclipse.e4.xwt.tests sounds like it would be good BUT where do I find that ?
Re: Load XWT from a string in memory [message #520958 is a reply to message #520947] Mon, 15 March 2010 22:59 Go to previous messageGo to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
OK... I found the repository and am checking out the project. I hope to find an example that will make things clearer.
Re: Load XWT from a string in memory [message #520960 is a reply to message #520947] Mon, 15 March 2010 23:36 Go to previous messageGo to next message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 #520972 is a reply to message #520960] Tue, 16 March 2010 01:45 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 17
Registered: March 2010
Junior Member
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 08:42 Go to previous message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
<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 09:31 Go to previous message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
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 10:41 Go to previous message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 11:58 Go to previous message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
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.


Konstantin Scheglov,
Google, Inc.
Re: Load XWT from a string in memory [message #570588 is a reply to message #520794] Mon, 15 March 2010 12:17 Go to previous message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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 21:11 Go to previous message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
"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 21:13 Go to previous message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
"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 #570670 is a reply to message #570648] Mon, 15 March 2010 21:47 Go to previous message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
I still cannot get the load the work.

Your suggestion to look at some fo the examples in org.eclipse.e4.xwt.tests sounds like it would be good BUT where do I find that ?
Re: Load XWT from a string in memory [message #570688 is a reply to message #570670] Mon, 15 March 2010 22:59 Go to previous message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
OK... I found the repository and am checking out the project. I hope to find an example that will make things clearer.
Re: Load XWT from a string in memory [message #570703 is a reply to message #570670] Mon, 15 March 2010 23:36 Go to previous message
Frank Gualtieri is currently offline Frank GualtieriFriend
Messages: 20
Registered: February 2010
Junior Member
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] Tue, 16 March 2010 01:45 Go to previous message
No real name is currently offline No real nameFriend
Messages: 17
Registered: March 2010
Junior Member
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 08:42 Go to previous message
Yves YANG is currently offline Yves YANGFriend
Messages: 687
Registered: July 2009
Senior Member
<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&
Previous Topic:Model components should be displayed directly after application start
Next Topic:XWT and JFace UpdateValueStrategies
Goto Forum:
  


Current Time: Mon Nov 24 22:52:19 GMT 2014

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

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