Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Importing dynamic content from a resource
Importing dynamic content from a resource [message #1857804] Mon, 27 February 2023 03:35 Go to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

I have a case where I import a clients text elements from a resource, piping them into the output. I am using something like the below, but it seems quite ugly and clunky. Is there a solution for this in EGL?

		final InputStream inputStream = URI.create(path).toURL().openStream();
		new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);



[Updated on: Wed, 01 March 2023 02:39]

Report message to a moderator

Re: Importing dynamic content from a resource [message #1857823 is a reply to message #1857804] Mon, 27 February 2023 21:17 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

What is your use case? Use the string inside EGL, or use EGL to read the InputStream and generate the string?

Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Importing dynamic content from a resource [message #1857825 is a reply to message #1857823] Tue, 28 February 2023 02:02 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

provide the path from a model to retrieve and print the content of the URI in egl.

[Updated on: Tue, 28 February 2023 02:03]

Report message to a moderator

Re: Importing dynamic content from a resource [message #1857827 is a reply to message #1857825] Tue, 28 February 2023 02:47 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

Actually, the code above does not even work, because the String constructor is hidden by EOL's String semantic. So I have now resorted to the monster below.

		var URI = Native("java.net.URI");
		var inputStream = URI.create(uri).toURL().openStream();
		var bytes = inputStream.readAllBytes();
		
		var baos = new Native("java.io.ByteArrayOutputStream");
		var Array = Native("java.lang.reflect.Array");
		baos.write(bytes,0,Array.getLength(bytes));
		
		var Charset = Native("java.nio.charset.Charset");
		return baos.toString(Charset.forName("UTF-8"));
Re: Importing dynamic content from a resource [message #1857834 is a reply to message #1857827] Tue, 28 February 2023 11:41 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Would it be possible to wrap this code into a tool?

Thanks,
Dimitris

[Updated on: Tue, 28 February 2023 11:41]

Report message to a moderator

Re: Importing dynamic content from a resource [message #1857840 is a reply to message #1857834] Wed, 01 March 2023 00:16 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

Yes, that is no issue. I just thought that it might already be present in one. Given that there is no `EglModule` tool, maybe that would be a good namespace for it.

Attached is a working tool, but it is crude, in that it does not cover handling of typical exceptions or setting of base URLs.

[Updated on: Wed, 01 March 2023 02:39]

Report message to a moderator

Re: Importing dynamic content from a resource [message #1857848 is a reply to message #1857840] Wed, 01 March 2023 14:27 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Thanks for sharing this! Given that this functionality can be implemented with a handful of lines of code that can be tucked away into an EOL operation, I think I'd prefer that over a tool, but of course if one starts needing richer support (e.g. for different encodings, types of sources) this can tip the scale.

Thanks,
Dimitris

Previous Topic:Best practive for prototyping tools in Eclipse
Next Topic:Collect vs Select
Goto Forum:
  


Current Time: Sat Apr 27 10:33:38 GMT 2024

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

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

Back to the top