Tuple t = new Tuple(rs.getString("SCHEMA"),
rs.getString("TABELLA"),
rs.getString("COLONNA"),
rs.getString("TIPO"),
rs.getString("NULLABLE"),
rs.getString("DESCRIZIONE"),
rs.getString("OWNER"),
rs.getString("REF") );
tuples.add(t);
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* write
*/
protected void write() {
try {
File f= new File(PATH);
if ( !f.exists() )
f.mkdirs();
// stylesheet file //
writeCSS();
// main file //
writeMain();
// index file //
writeIndex();
// tables file //
writeTables();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* writeCSS
* @throws Exception
*/
protected void writeCSS() throws Exception {
Writer w = new FileWriter(PATH+"style.css");
BufferedWriter bw = new BufferedWriter(w);
writeLine(bw, "TH {text-align: left; background: black; color: white; font: 12pt bold serif}");
writeLine(bw, "TD {text-align: left; background: white; color: black; font: 10pt serif}");
writeLine(bw, "A:visited,A:link {font-style: italic bold; color: blue; text-decoration: none}");
writeLine(bw, "A:hover {font-style: italic bold; background: black; color: white; text-decoration: none}");
writeLine(bw, "UL {text-align: center; font-size: 70%; }");
writeLine(bw, "LI {text-align: left; }");
bw.flush();
bw.close();
w.close();
}
/**
* writeMain
* @throws Exception
*/
protected void writeMain() throws Exception {
Writer w = new FileWriter(PATH+USR+".html");
BufferedWriter bw = new BufferedWriter(w);
writeLine(bw, "<HTML>");
writeLine(bw, "<FRAMESET name=\"frameset\" cols=\"25%,75%\">");
writeLine(bw, " <FRAME name=\"index\" src=\""+USR+"-index.html\">");
writeLine(bw, " <FRAME name=\"tables\" src=\""+USR+"-tables.html\">");
writeLine(bw, "</FRAMESET>");
writeLine(bw, "</HTML>");
bw.flush();
bw.close();
w.close();
}
/**
* writeIndex
* @throws Exception
*/
protected void writeIndex() throws Exception {
Writer w = new FileWriter(PATH+USR+"-index.html");
BufferedWriter bw = new BufferedWriter(w);
writeLine(bw, "<HTML>");
writeLine(bw, "<BODY>");
writeLine(bw, "<LINK REL=StyleSheet HREF=\"style.css\" TYPE=\"text/css\" MEDIA=screen>");
// index
writeLine(bw, "<UL><H1>INDEX</H1>");
Iterator iter = tuples.iterator();
while (iter.hasNext()) {
Tuple item = (Tuple) iter.next();
if ( item.isTable() ) {
writeLine(bw, "<LI><A href=\""+USR+"-tables.html#"+item.tabella+"\" target=\"tables\">"+item.tabella+"</A><br>");
}
}
writeLine(bw, "</BODY>");
writeLine(bw, "</HTML>");
bw.flush();
bw.close();
w.close();
}
/**
* writeTables
* @throws Exception
*/
protected void writeTables() throws Exception {
boolean firstTime = true;
Writer w = new FileWriter(PATH+USR+"-tables.html");
BufferedWriter bw = new BufferedWriter(w);
writeLine(bw, "<HTML>");
writeLine(bw, "<BODY>");
writeLine(bw, "<LINK REL=StyleSheet HREF=\"style.css\" TYPE=\"text/css\" MEDIA=screen>");
writeLine(bw, "<H1><A name=\"TABLES\">TABLES</A></H1>");
Iterator iter = tuples.iterator();
while (iter.hasNext()) {
Tuple item = (Tuple) iter.next();
if ( item.isTable() ) {
if (!firstTime) {
writeLine(bw, "</TABLE><br>");
writeLink(bw);
writeLine(bw, "<TABLE rules=\"all\" frame=\"box\" width=100%>");
}
else {
writeLine(bw, "<TABLE rules=\"all\" frame=\"box\" width=100%>");
}
firstTime = false;
}
writeLine(bw, item.toString());
}
writeLine(bw, "</TABLE><br>");
writeLink(bw);
writeLine(bw, "</BODY>");
writeLine(bw, "</HTML>");
bw.flush();
bw.close();
w.close();
}
/**
* writeLine
* @param bw BufferedWriter
* @param line String
* @throws Exception
*/
private void writeLine(BufferedWriter bw, String line) throws Exception {
bw.write(line);
bw.newLine();
}
/**
* writeLink
* @param bw BufferedWriter
* @throws Exception
*/
private void writeLink(BufferedWriter bw) throws Exception{
writeLine(bw, "<center><small>- ");
bw.write("<A href=\"javascript:;\" ONCLICK=\"top.index.history.back(); top.tables.history.back(); \">prev</A>");
bw.write(" | ");
bw.write("<A href=\"#TABLES\">top</A>");
bw.write(" | ");
bw.write("<A href=\"javascript:;\" ONCLICK=\"top.index.history.forward(); top.tables.history.forward(); \">next</A>");
writeLine(bw, " -</small></center><br>");
}
/**
* main
* @param args String[]
*/
public static void main(String[] args) {
if ( args.length<3 ) {
System.err.println("UTILIZZO:");
System.err.println("db2html utente password url [percorso]");
System.err.println(" utente: nome dell'utente Oracle.");
System.err.println(" password: password dell'utente Oracle.");
System.err.println(" url: url del db Oracle [formato jdbc:oracle:thin:@$host$:1521:$sid$].");
System.err.println(" [percorso]: path della cartella $utente$ dell'export [di default il desktop].");
System.exit(-1);
}
db2html d2h = new db2html( args[0],
args[1],
args[2],
args.length>3 ? args[3] : System.getProperty("user.home")+"\\desktop\\");
d2h.export();
}
/**********************
* INNER CLASS TUPLE
**********************/
class Tuple {
public String schema;
public String tabella;
public String colonna;
public String tipo;
public String nullable;
public String descrizione;
public String owner;
public String ref;
public Tuple( String schema,
String tabella,
String colonna,
String tipo,
String nullable,
String descrizione,
String owner,
String ref ) {
this.schema=schema;
this.tabella=tabella;
this.colonna=colonna;
this.tipo=tipo;
this.nullable=nullable;
this.descrizione=descrizione;
this.owner=owner;
this.ref=ref;
}
// toString
public String toString() {
if ( isTable() )
return "<TR>"+
"<TH colspan=3 width=40%><A name=\""+tabella+"\">"+tabella+"</A></TH>"+
"<TH><i>"+(descrizione==null ?"" :descrizione)+"</i></TH>"+
"</TR>";
else
return "<TR>" +
"<TD width=29%>" + getColonna() + "</TD>" +
"<TD width=10%>" + tipo + "</TD>" +
"<TD width=1%>" + ("N".equals(nullable) ?"<B>NN</B>" :"") + "</TD>" +
"<TD><i>" + (descrizione==null ?"" :descrizione) + "</i></TD>" +
"</TR>";
}
// getColonna
private String getColonna() {
if ( "OID".equals(colonna) )
return "<b>"+colonna+"</b>";
else if ( ref!=null )
if ( schema.equals(owner) )
return "<A href=\"#"+ref+"\""+
" onClick=\"top.index.location='../"+schema+"/"+schema+"-index.html';\""+
">"+colonna+"</A>";
else
return "<A href=\"../"+owner+"/"+owner+"-tables.html"+"#"+ref+"\""+
" onClick=\"top.index.location='../"+owner+"/"+owner+"-index.html';\""+
">"+colonna+"</A>";
else
return colonna;
}
// isTable
public boolean isTable() {
return colonna.startsWith("-");
}
}
}