DBVIEW
|
00001 /* 00002 DbView - Graph Visualization 00003 Copyright (C) 2012 Denis BEURIVE 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /** 00020 * @author Denis Beurive 00021 */ 00022 00023 package org.dbview.addons.output.table.dotFull; 00024 00025 import java.util.ArrayList; 00026 import java.util.Hashtable; 00027 import org.dbview.addons.output.table.utils.dot.*; 00028 import org.dbview.db.structure.Database; 00029 import org.dbview.db.structure.Table; 00030 import org.dbview.output_addons.AbstractExporter; 00031 import org.jdom.Element; 00032 import java.io.*; 00033 00034 /** 00035 * @class Exporter 00036 * This class implements the adapter that generates the DOT specification file for the add-on that produces detailed DOT representations. 00037 * @author Denis BEURIVE 00038 */ 00039 public class Exporter extends AbstractExporter 00040 { 00041 /** 00042 * This method produces a detailed DOT representation of the database. 00043 * @param in_db Database to export. 00044 * @param in_cli_conf Configuration parameters for the exporter. 00045 * @param in_tables List of tables to export. 00046 * You may specify all the tables of the database, or a subset of tables. 00047 * @return The exporter returns a string. This string is the DOT's representation of the given set of tables. 00048 * @throws Exception 00049 */ 00050 public Object export(Database in_db, Element in_cli_conf, ArrayList<Table> in_tables) throws Exception 00051 { 00052 // Extract options. 00053 String layout = org.dbview.utils.Jdom.getTextOrCdata(in_cli_conf.getChild(XML.LAYOUT)); // "TB" or "LR" 00054 String path = org.dbview.utils.Jdom.getTextOrCdata(in_cli_conf.getChild(XML.PATH)); 00055 00056 // Export 00057 org.dbview.databaseExporters.dot.DotFull e = new org.dbview.databaseExporters.dot.DotFull(in_tables, in_db); 00058 Hashtable<String, Object> options = new Hashtable<String, Object>(); 00059 options.put("layout", layout); 00060 String dot = e.export(options); // This is a string. 00061 00062 if (path.length() > 0) 00063 { 00064 FileWriter fstream = new FileWriter(path, Boolean.TRUE); 00065 BufferedWriter out = new BufferedWriter(fstream); 00066 out.write(dot); 00067 out.write(System.getProperty("line.separator")); 00068 out.close(); 00069 } 00070 else 00071 { 00072 System.out.println(dot); 00073 } 00074 00075 return null; 00076 } 00077 }