Java tabled output to file - java

I'm interested in a way of outputting some objects to a table like way the objects. Concrete example would be something like:
-------------------------------------------
| Name | foo | bar |
-------------------------------------------
| asdas | dsfsd |1233.23 |
| adasdasd | fsdfs |3.23 |
| sdasjd | knsdfsd |13.23 |
| lkkkj | dsfsd |2343.23 |
-------------------------------------------
Or an ms office / open office excel file.(is there an api doc for this type of outputting data in specific editors? like how to define a table in OpenPffice)?
I'm asking this because I would like to know the best way doing this.
PS: there is no need to deserialise.

docx4j is a library for creating and manipulating .docx,pptx and excel files.
If you do not feel like using docx4java or it does not fit your needs you can try these
Apache Poi
Open Office API

The easiest is to export to a comma-separated values which you can open in Excel.
You can use the data-exporter library.

Related

Visualise data loaded in memory from databases/tables for doc purposes

I have a set of classes that do load data from some tables from multiple databases and keep the data in memory in specific data structures (Maps etc).
What I want to do is create some visual/documentation of how each structure is loaded by which db/table.
Is there something other than e.g. google doc or Word doc to use for this? Would it be some form of UML diagram or is it some other kind of diagram I should be looking into?
E.g.
HashMap<Integer, Person> is loaded from emp.Employees and personal.People etc
A very typical way to document this it to use UML stereotypes to identify classes that represent database objects (tables, views, ...), and show dependency between the "in-memory" classes and the database objects.
Example:
+------------+ +--------------+
| Person | | <<table>> |
+------------+ <<load>> | Employees |
| ... | - - - - - - - > +--------------+
+------------+ \ | ... |
| ... | +--------------+
+------------+ \
+------------+
\-> | <<table>> |
| People |
+------------+
| ... |
+------------+
You could then show that Person is in a container. Typically in UML you could show this either with a simple association with a container class or, in the case of the hashmap, with a qualifier.
You may also want to use the full name of your tables, or use package notation to group tables in the same schema.
Additional example: visual mapping of classes and tables using <<table>>; use-dependencies to show load/saving relationships

Saving filepath in mysql using java, am i doing it right?

I'm working on a mini-project that can upload certain files to a server. I'm using java and mysql. According to things I read the 'right way' is to save the file to a folder in my server and put the file path in mysql.
A Part of my code:
File source = new File(fileChooser.getSelectedFile().getPath());
File dest = new File(destChooser.getSelectedFile().getPath());
String tempUpdate1 = "Insert into images (ID, file_name, file_path)"
+ "VALUES ('"+ID+"' , '"+fileChooser.getSelectedFile().getName()+"' , '"+destChooser.getSelectedFile().getPath()+"')";
conn = Connect.ConnectDB();
Statement stemt2 = conn.createStatement();
stemt2.executeUpdate(tempUpdate1);
FileUtils.copyFileToDirectory(source, dest);
JOptionPane.showMessageDialog(null, "File Uploaded Successfully!");
then i tried running it. It successfully copied the file to my desired folder. The problem is in my
mysql table where i save the path of the file.
The table's like this:
| ID | file_name | file_path |
| 1 | sample.docx | C:UsersMEDesktopest |
| 2 | sample.jpg | C:UsersMEDesktopest |
I tried seeing the output of the file path myself using JOptionPane it returned normal with the separators, but using the same variable and puting it in mysql, that's what i get as seen above, no separators.
Am i really doing it right? I did what is instructed on the topics related to this but no one seems to be complaining with the path. I'm wondering if did something wrong somewhere.
I'm planning to access the file using the file path as my project progress. Just would like to ask if the path file is accessible since i dont see any separator such as '//', '/' or '\'
it is almost good.
imagine that you have two files named same way. you can have only one of them on your server. I would save file under coded name like time in milis at moment of saving action.
Your table would contain then original name sample.jpg and file name 49473996034732 for example (in separate column of course). This way you can save as many sample.jpg as you like. Request link should point to file name 49473996034732 so you always will know for which file is request.
Then in response, when you set content to proper type you can set user friendly name.
modified table
| ID | file_name | server_file_name | file_path |
| 1 | sample.docx | 49473996034732 | C:UsersMEDesktopest |
| 3 | sample.jpg | 49473996034850| C:UsersMEDesktopest |
| 2 | sample.jpg | 49473996034988 | C:UsersMEDesktopest |
second thing is that i noticed is that you allow user to pick destination folder for containing file. Shouldn't is be fixed location? This way it would be more like server behavior. But im guessing this is just an example code fast codded in Swing

Is there a quick way to print the Textual representation of file structure?

I'm working on a large project in Eclipse, and I'd like to quickly print out the file structure for various reasons, one of them being that I'd like to ask a question about it here on Stackoverflow.
For example, I'd like to print something like
my_proj
|--src
| |-java
| | |-Hello.java
| | |-Goodbye.java
| |
| |-xml
|--res
| |-html
| |-css
....
etc....
Is there a quick way to generate this sort of representation?

Any framework for customizing different view for different vendor?

We have integration with several vendor for showing our product catalouge. Every-time, we have to customizing the view according to the provided templates by Vendor.
I have find following points after analyzing all the templates i.e. as follows:
Commonly, i have found out there are total 6 different type of blocks. Let's suppose A,B,C,D,E,F.
Vendor John templates contains A,C,E. And the layout of the template is
----------------------
| A |
----------------------
| C | E |
----------------------
Vendor Micheal templates contains B,D,E,F. And the layout of the template is
----------------------
| B | F |
----------------------
| D | E |
----------------------
Vendor Shane templates contains A,B,C,D,E,F. And the layout of the template is
----------------------
| B | F |
----------------------
| D | E |
----------------------
| A | C |
----------------------
Business logic for A,B,C,D,E,F is same in all the above case.
CSS, Image File and Html structure is different in all the above case.
I am trying to find out a generic solution where i can customize the view and prepare the presentation. Is there any framework in java who can help to solve my problem or any suggestion.
Apache tiles or Sitemesh might suit your needs. They're frameworks designed for "tiling" your view however you desire.
I have to suggest Symfony for this purpose.
A single project contains several apps on a single data model where each app can be viewed as a view for somebody, a vendor or an administrator.
Plus, you can store some reusable pieces of templates at the root and re-use them inside each app the way you want.
You dont have to switch to Symfony, you can use just a part of it, and keep your data model at it is today.
http://www.symfony-project.org/

Hierarchical table column in Java

Is there any Java library that supports hierarchical column?
For example (the first three row are columns) :
------------------------------------------------
2008 |
------------------------------------------------
January | February |
------------------------------------------------
Week1 | Week2 | Week3 | Week 1 | Week2 | Week3 |
------------------------------------------------
10 | 20 | 14 | 12 | 15 | 3 |
------------------------------------------------
May be a JXTree from SwingLab could approach what you are looking for.
Illustration here, from the Swingx project
http://avatar21.superihost.com/images/JXTableJXTreeTable.png
Infragistics WebGrid for JSF:
alt text http://www.infragistics.com/uploadedImages/Products/NetAdvantage_for_JSF/Features/WebGrid/Gallery/WebGrid_Hierarchical.png
Thanks for your answers. Actually I need it for my desktop-based application. Currently I'm evaluating SWT table, but seems it does not support hierarchical table column. Maybe I'll take a look at Swing JTable.
Or just follow this tutorial to use native JTable and JTree together:
java_sun_articles_treetable1
Estima Visual Java/SWING Components Library 4.0:
(source: eltima.com)
If you are looking for a JavaEE solution you might want to have a look at [fleXive], an open source (LGPL for the framework and GPL for the optional backend with visual editors).
Please feel free to ask any questions on the forums.
(source: flexive.org)

Categories