Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generate non text files
Generate non text files [message #1698157] Thu, 11 June 2015 17:19 Go to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Hey,

I created a dsl that needs to generate a doc file as result. All examples that I found are text based like the following:

	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		fsa.generateFile('greetings.txt', 'People to greet: ' + 
			resource.allContents
				.filter(typeof(Greeting))
				.map[name]
				.join(', '))
	}


Can I use the IFileSystemAccess to write the doc files to the file system? So I could use the in-memory IFileSystemAccess for unit testing as shown in this by blog post Unittesting Xtend Generators.

Thank you!

Kon

[Updated on: Thu, 11 June 2015 19:18]

Report message to a moderator

Re: Generate non text files [message #1698161 is a reply to message #1698157] Thu, 11 June 2015 18:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

is this one how to create a doc or on how to persist it? the IFileSystemAccess might be actually a IFileSystemAccessExtension3 as well and thus offers org.eclipse.xtext.generator.IFileSystemAccessExtension3.generateFile(String, InputStream)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generate non text files [message #1698167 is a reply to message #1698161] Thu, 11 June 2015 19:28 Go to previous messageGo to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Hey Christian,

I'm trying to persist a doc file. I'll have a look tomorrow if the declared interface IFileSystemAccess is implemented by IFileSystemAccessExtension3.

How is the implementation type determined for the IFileSystemAccess interface? Apparently, IFileSystemAccessExtension3 is not always present since this blog post also uses a if statement.

Thank you!

Kon
Re: Generate non text files [message #1698171 is a reply to message #1698167] Thu, 11 June 2015 19:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes this is what i meant: it may be that your IFileSystemAccess is an instanceof IFileSystemAccessExtension3 as well. thus the if check.
and yes it may not be always resent (for backwords comp.) but it always should if you use a recent version of xtext.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generate non text files [message #1698195 is a reply to message #1698171] Fri, 12 June 2015 05:41 Go to previous message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Thank you Smile This works ... just in case someone else is trying Smile

	override void doGenerate(Resource resource, IFileSystemAccess fsa) {

		if(!(fsa instanceof IFileSystemAccessExtension3)){
			throw new RuntimeException("Please update your xtext version being able to use IFileSystemAccessExtension3!")
		}

		var fsa3  = fsa as IFileSystemAccessExtension3
                var file = new File("empty_template_doc_file")
                // add content to file
		fsa3.generateFile("test.docx", new FileInputStream(file))
	}
Previous Topic:Strict grammar vs Relax grammar
Next Topic:Dependencies between myDsl - Files
Goto Forum:
  


Current Time: Tue Mar 19 06:03:51 GMT 2024

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

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

Back to the top