Filename extension on CSV export -- change to .csv from .txt

107 views
Skip to first unread message

j.e.frank

unread,
Oct 19, 2011, 11:41:21 AM10/19/11
to jmesa_forum
I would like my CSV export files to be named with the .csv extension,
rather than the .txt extension. The reason is, I want it to open with
Excel and in some cases with .txt it opens in Notepad.

I've looked at the source code for JMesa and don't see a way to change
this behavior in the usual manner (namely, making my own custom class
for something and plugging it into the framework). The reason is, the
TableFacade directly instantiates a new CsvViewExporter, so I don't
have a chance to tell it to use my version of that class. I suppose I
could try subclassing the TableFacade, but I am not really sure I
understand all the interactions between a TableFacade, TableModel,
various factories, etc.

I guess my question boils down to: what is the recommended way to make
the CSV export file have a .csv extension, instead of .txt?

Jeff Johnston

unread,
Oct 19, 2011, 4:39:00 PM10/19/11
to jmesa...@googlegroups.com
This is a use case that needs to be addressed. Honestly it just has not come up like I expected it would and so I have not done the steps to expose it. Your right though that with JMesa what you would typically do is find the right class to extend and plug it in. But there is nothing difficult about doing that as we would just need to make it easy to plug in the ViewExporter the same way that we allow everything else to be plugged in.

That said if you were really motivated you could hack it in there a few ways...but none of which would be all that great given the new TableModel abstraction. Here is a link to the way you could have done it when we worked directly with the TableFacade.

http://code.google.com/p/jmesa/wiki/ManualTableExport

But really what I would do is either change the CsvViewExporter's getExtensionName() and recompile the project....or, better yet improve the API so that the we can plug in ViewExporter so that it works like everything else. If you wanted to do that feel free to email me at jeff.joh...@gmail.com and I can explain how I would go about doing that. Incidently I do not think it would be that tough. I just have not gotten around to doing it yet.

-Jeff
Johnston

j.e.frank

unread,
Oct 19, 2011, 6:57:02 PM10/19/11
to jmesa_forum
Thanks for the reply. I considered changing the source code and
recompiling JMesa, but I didn't want to go through the hoops of
getting the dependencies straightened out (I don't use Maven). Plus
then I would be on my own fork and couldn't upgrade easily if / when a
new release comes out.

What I did instead was to make 3 subclasses, one each for
CsvViewExporter (to change the suffix), TableFacade (to instantiate my
new CsvViewExporter) and TableModel (to use my new TableFacade). It
was not exactly elegant, but it got the job done. So in my
controller, I instantiate the custom MyTableFacade first, then pass
that in the constructor to my custom MyTableModel class (calling the
protected setTableFacade method from the constructor). I think
another regular TableFacade also gets created and then immediately
replaced by my custom one.

On Oct 19, 4:39 pm, Jeff Johnston <jeff.johnston...@gmail.com> wrote:
> This is a use case that needs to be addressed. Honestly it just has not come
> up like I expected it would and so I have not done the steps to expose it.
> Your right though that with JMesa what you would typically do is find the
> right class to extend and plug it in. But there is nothing difficult about
> doing that as we would just need to make it easy to plug in the ViewExporter
> the same way that we allow everything else to be plugged in.
>
> That said if you were really motivated you could hack it in there a few
> ways...but none of which would be all that great given the new TableModel
> abstraction. Here is a link to the way you could have done it when we worked
> directly with the TableFacade.
>
> http://code.google.com/p/jmesa/wiki/ManualTableExport
>
> But really what I would do is either change the CsvViewExporter's
> getExtensionName() and recompile the project....or, better yet improve the
> API so that the we can plug in ViewExporter so that it works like everything
> else. If you wanted to do that feel free to email me at
> jeff.johnston...@gmail.com and I can explain how I would go about doing

Jeff Johnston

unread,
Oct 20, 2011, 10:08:07 AM10/20/11
to jmesa...@googlegroups.com
Yes, that would be the correct way to do it manually right now.

At the beginning of next year I am moving JMesa to version 4.0. Basically what that will mean is that all the deprecated methods will be removed and I will clean up some things such as having a way to plug in the ViewExporter. In addition I need to get all the dependencies up to date.

-Jeff
Reply all
Reply to author
Forward
0 new messages