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.dotMedium; 00024 00025 import java.io.BufferedWriter; 00026 import java.io.FileWriter; 00027 import java.util.ArrayList; 00028 import java.util.Hashtable; 00029 import java.util.Iterator; 00030 import org.dbview.addons.output.table.utils.dot.*; 00031 import org.dbview.db.structure.Database; 00032 import org.dbview.db.structure.Table; 00033 import org.dbview.output_addons.AbstractExporter; 00034 import org.jdom.Element; 00035 00036 /** 00037 * @class Exporter 00038 * This class implements the adapter that generates the DOT specification file for the add-on that produces medium DOT (GraphViz) representations. 00039 * @author Denis BEURIVE 00040 */ 00041 public class Exporter extends AbstractExporter 00042 { 00043 /** 00044 * This method produces a detailed DOT representation of the database. 00045 * @param in_db Database to export. 00046 * @param in_cli_conf Configuration parameters for the exporter. 00047 * @param in_tables List of tables to export. 00048 * You may specify all the tables of the database, or a subset of tables. 00049 * @return The exporter returns a string. This string is the DOT's representation of the given set of tables. 00050 * @throws Exception 00051 */ 00052 public Object export(Database in_db, Element in_cli_conf, ArrayList<Table> in_tables) throws Exception 00053 { 00054 // Extract options. 00055 String layout = org.dbview.utils.Jdom.getTextOrCdata(in_cli_conf.getChild(XML.LAYOUT)); // "TB" or "LR" 00056 String path = org.dbview.utils.Jdom.getTextOrCdata(in_cli_conf.getChild(XML.PATH)); 00057 00058 // Get the list of table to zoom at. 00059 org.dbview.databaseExporters.dot.DotMedium e = new org.dbview.databaseExporters.dot.DotMedium(in_tables, in_db); 00060 Hashtable<String, Object> options = new Hashtable<String, Object>(); 00061 options.put("layout", layout); 00062 String dot = e.export(options); // This is a string. 00063 00064 if (path.length() > 0) 00065 { 00066 FileWriter fstream = new FileWriter(path, Boolean.TRUE); 00067 BufferedWriter out = new BufferedWriter(fstream); 00068 out.write(dot); 00069 out.write(System.getProperty("line.separator")); 00070 out.close(); 00071 } 00072 else 00073 { 00074 System.out.println(dot); 00075 } 00076 00077 return null; 00078 } 00079 }