diff --git a/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java b/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java new file mode 100755 index 0000000..fbf18d0 --- /dev/null +++ b/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java @@ -0,0 +1,98 @@ +package net.sourceforge.schemaspy.view; + +import java.io.*; +import java.util.*; +import net.sourceforge.schemaspy.model.*; +import net.sourceforge.schemaspy.util.*; + +public class HtmlOrphansPage extends HtmlGraphFormatter { + private static HtmlOrphansPage instance = new HtmlOrphansPage(); + + private HtmlOrphansPage() { + } + + public static HtmlOrphansPage getInstance() { + return instance; + } + + public boolean write(Database db, List orphanTables, boolean hasRelationships, File graphDir, LineWriter html) throws IOException { + Dot dot = getDot(); + if (dot == null) + return false; + + Set orphansWithImpliedRelationships = new HashSet(); + Iterator iter = orphanTables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + if (!table.isOrphan(true)){ + orphansWithImpliedRelationships.add(table); + } + } + + writeHeader(db, "Utility Tables Graph", hasRelationships, !orphansWithImpliedRelationships.isEmpty(), html); + + html.writeln(""); + try { + iter = orphanTables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + String dotBaseFilespec = table.getName(); + + File dotFile = new File(graphDir, dotBaseFilespec + ".1degree.dot"); + File graphFile = new File(graphDir, dotBaseFilespec + ".1degree.png"); + + LineWriter dotOut = new LineWriter(new FileOutputStream(dotFile)); + DotFormatter.getInstance().writeOrphan(table, dotOut); + dotOut.close(); + try { + dot.generateGraph(dotFile, graphFile); + } catch (Dot.DotFailure dotFailure) { + System.err.println(dotFailure); + return false; + } + + html.write(" "); + } + + iter = orphanTables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + String dotBaseFilespec = table.getName(); + + File dotFile = new File(graphDir, dotBaseFilespec + ".1degree.dot"); + dot.writeMap(dotFile, html); + } + + return true; + } finally { + html.writeln(""); + writeFooter(html); + } + } + + private void writeHeader(Database db, String title, boolean hasRelationships, boolean hasImpliedRelationships, LineWriter html) throws IOException { + writeHeader(db, null, title, hasRelationships, true, html); + html.writeln(""); + html.writeln(""); + html.writeln(""); + html.writeln("
"); + writeGeneratedBy(db.getConnectTime(), html); + html.writeln(""); + writeLegend(false, html); + html.writeln("
"); + if (hasImpliedRelationships) { + html.writeln("
"); + html.writeln(" "); + html.writeln(" Hide tables with implied relationships"); + html.writeln("
"); + } + html.writeln("
"); + } + + protected boolean isOrphansPage() { + return true; + } +}