アットウィキロゴ
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
 
/**
 * HTMLManager.java -
 * @author naito
 */
public class HTMLManager {
	private static String _windowTitle = "Generated by Oradoc.java";
	private static String _generatedTime = null;
	private static String _destDir = null;
	private static String _sepa = System.getProperty( "file.separator" );
	private static boolean _verbose = false;
	private static String _encoding = null;
	// リンク用プロシージャリスト
	private static String[] _procedures = null;
	private static String[] _functions = null;
	private static HashMap _package = null;
 
	private static final String FILE_INDEX = "index.html";
	private static final String FILE_OVERVIEW_FRAME = "overview-frame.html";
	private static final String FILE_OVERVIEW_SUMMARY = "overview-summary.html";
	private static final String FILE_ALL_FRAME = "allclasses-frame.html";
	private static final String FILE_PACKAGE_FRME = "package-frame.html";
	private static final String FILE_PACKAGE_SUMMARY = "package-summary.html";
	private static final String FILE_STYLESHEET = "stylesheet.css";
 
	private static final String BODYTAG = "<BODY BGCOLOR = \"white\" onload = \"asd();\" >";
 
	static {
		Date date = new Date( System.currentTimeMillis() );
		_generatedTime = date.toString();
	}
 
	/**
     * destDir を設定します。
     * @param destDir
     */
	public static void setDestDir( String destDir ) {
		if( destDir.charAt( destDir.length() -1 ) != _sepa.charAt(0) ) {
			_destDir = destDir + _sepa;
		} else {
			_destDir = destDir;
		}
		File tmpDir = new File( _destDir );
		if( !tmpDir.exists() ) {
			tmpDir.mkdirs();
		}
	}
 
	/**
     * windowTilte を設定します。
     * @param windowTitle
     */
	public static void setWindowTitle( String windowTitle ) {
		_windowTitle = windowTitle;
	}
 
	/**
     * ログ出力フラグを設定します。
     * @param verbose
     */
	public static void setVerbose( boolean verbose ) {
		_verbose = verbose;
	}
 
	/**
     * エンコードを設定します。
     * @param encoding
     */
	public static void setEncoding( String encoding ) {
		_encoding = encoding;
	}
 
	/**
     * トップページを生成します。
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createIndexHTML() throws UnsupportedEncodingException, FileNotFoundException {
		File file = new File( _destDir + FILE_INDEX );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( null, 0, out );
 
		out.println( "FRAMESET cols=\"20%,80%\" >" );
		out.println( "FRAMESET rows=\"30%,70%\">" );
		out.println( "FRAME src=\"" + FILE_OVERVIEW_FRAME + "\" name=\"packageListFrame\">" );
		out.println( "FRAME src=\"" + FILE_ALL_FRAME + "\" name=\"packageFrame\">" );
		out.println( "</FRAMESET>" );
		out.println( "<FRAME src=\"" + FILE_OVERVIEW_SUMMARY + "\" name=\"classFrame\">" );
		out.println( "</FRAMESET>" );
 
		out.println( "<NOFRAMES>" );
		out.println( "<H2>フレーム関連の警告</H2>" );
		out.println( "<P>このドキュメントはフレーム機能を使って表示するように作られています。フレームを表示できない Web クライアントの場合にこのメッセージが表示されます。" );
		out.println( "<BR>" );
		out.println( "リンク先<A HREF=\"" + FILE_OVERVIEW_SUMMARY + "\">フレームなしのバージョン</A></NOFRAMES>" );
 
		printFooter( out );
 
		out.close();
	}
 
	/**
     * 概要ページ( フレーム左上 )を生成します
     * @param objectTypes
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createOverviewFrameHTML( String[] objectTypes ) throws UnsupportedEncodingException, FileNotFoundException {
		File file = new File( _desDir + FILE_OVER_FRAME );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( "概要", 0, out );
 
		out.println( BODYTAG );
 
		out.println( "<TABLE BORDER=\"0\">\N<TR>\N<TD NOWRAP><FONT size=\"+1\" CLASS=\"FrameTitleFont\">\n<B></B></FONT></TD>\n</TR>\n</TABLE>" );
		out.println( "<TABLE BORDER=\"0\">\n<TR>" );
		out.println( "<TD NOWRAP><FONT CLASS=\"FrameItemFont\"><A HREF=\"" + FILE_ALL_FRAME + "\" TARGET=\"packageFrame\">すべてのオブジェクト</A></FONT>" );
		out.println( "<P>\n<FONT size=\"+1\" CLASS=\"FrameHeadingFont\">\nタイプ別</FONT>" );
 
		// objectType ループ
		for( int i = 0; i < objectTypes.length; i++ ) {
			out.println( "<BR>" );
			out.println( "<FONT CLASS=\"FrameItemFont\"><A HREF=\"" + getDirectoryName( objectTypes[ i ] ) + "/" + FILE_PACKAGE_FRAME + "\" TARGET=\"packageFrame\">" + objectTypes[ i ] + "</A></FONT>" );
		}
 
		out.println( "<BR>\n</TD>\n</TR>\n</TABLE>\n\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * 概要ページ( フレーム右側 )を生成します。
     * @param objectTypes
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createOverviewSummaryHTML( String[] objectTypes ) throws UnSupportedEncodingException, FileNotFoundException {
		File file = new File( _destDir + FILE_OVERVIEW_SUMMARY );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( "概要", 0, out );
 
		out.println( BODYTAG );
 
		out.println( "<HR>\n<CENTER>\n<H2>" + _windowTitle + "</H2>\n</CENTER>"
 
		out.println("<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		out.println("<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">" );
		out.println("<TD COLSPAN=2><FONT SIZE \"+2\">\n<B>タイプ別</B></FONT></TD>\n</TR>" );
 
		// objectType ループ
		for( int i = 0; i < objectTypes.length; i++ ) {
			String rowTitle = "<A HREF=\"" + getDirectoryName( objectTypes[i] ) + "/" + FILE_PACKAGE_SUMMARY + "\">" + objectTYpes[i] + "</A>";
			String rowData = objectTypes[i] + "の一覧を表示します。";
			printTableRow( rowTitle, rowData, out );
		}
 
		out.println( "</TABLE>\n<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * オブジェクトリストページ( フレーム左下 )を生成します。
     * @param objectType オブジェクトタイプ( 表示用 ) null -> すべて
     * @param objectItems オブジェクトのリスト
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createPackageFrameHTML( String objectType, ObjectItem[] objectItems ) throws UnsupportedEncodingException, FileNotFoundException {
		File file = null;
		String title = null;
		int depth;
		if( objectTYpe == null ) {
			file = new File( _destDir + FILE_ALL_FRAME );
			title = "すべてのオブジェクト";
			depth = 0;
		} else {
			file = new File( _destDir + getDirectoryName( objectType ) + _sepa + FILE_PACKAGE_FRAME );
			file.getParentFile().mkdirs();
			title = objectType;
			depth = 1;
		}
		PriontStream out new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( title, depth, out );
 
		out.println( BODYTAG );
 
		out.println( "<FONT size=\"+1\" CLASS=\"FrameHeadingFont\">" );
 
		if( objectType == null ) {
			out.println( "<B>" + title + "</B>" );
		} else {
			out.println( "<A HREF=\"" + FILE_PACKAGE_SUMMARY + "\" TARGET=\"classFrame\">" + title + "</A>" );
		}
 
		out.println( "</FONT>\n<BR>\n<BR>\n<TABLE BORDER=\"0\">\n<TR>" );
		out.println( "<TABLE BORDER=\"0\">\n<TR>\n<TD NOWRAP><FONT CLASS=\"FrameItemFont\">" );
 
		// objectItems ループ
		for( int i = 0; i < objectItems.length; i++ ) {
			String tmpName = objectItems[ i ].objectNmae;
			String tmpType = objectItems[ i ].objectType;
 
			out.println( "<A HREF=\"" + ( ( objectType == null ) ? ( getDirectoryName(tmpType) + "/" ) : "" ) + tmpName + ".html\" TARGET=\"classFrame\">" + tmpName + "</A>" );
			out.println( "<BR>" );
		}
 
		out.println( "</FONT></TD>\n</TR>\n</TABLE>\n\n</BODY" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * オブジェクト・リストページ( フレーム右側 )を生成します。
     * @param objectType オブジェクトタイプ
     * @param objectItems オブジェクトのリスト
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createPackageSummaryHTML( String objectType, ObjectItem[] objectItems ) throws UnsupportedEncodingException, FileNotFoundException {
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + FILE_PACKAGE_SUMMARY );
		String title = objectType;
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( title, 1, out );
 
		out.println( BODYTAG );
 
		out.println( "<HR>\n<H2>\n" + objectType + "\n</H2>" );
 
		out.println( "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( objectType + "の一覧", 2, out );
 
		for( int i = 0; i < objectItems.length; i++ ) {
			String objectName = objectItems[ i ].objectName;
			String rowTitle = "<A HREF=\"" + objectName + ".html\">" + objectName + "</A>";
			String rowData = objectName + "の詳細を表示します。";
			printTableRow( rowTitle, rowData, out );
		}
 
		out.println( "</TABLE>\n<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * TABLE ページ( フレーム右側 )を生成します。
     * @param item
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createTableFrameHTML( TableItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// 列の情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "列の情報", 3, out );
		String[] data = { "<B>COLUMN_NAME</B>", "<B>NULLABLE</B>", "<B>DATA_TYPE</B>" };
		printTableRow( data, out );
		for( int i = 0; i < item.columns.length; i++ ) {
			TableColumnItem citem = item.columns[ i ];
			String[] cdata = {"<A NAME=\"" + citem.columnName + "\">" + citem.columnName + "</A>", citem.nullable, citem.dataType };
			printTableRow( cdata, out );
		}
		out.println( "</TABLE>" );
 
		// 制約の情報
		if( item.constraints.size() > 0 ) {
			out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
			printTableHeader( "制約の情報", 4, out );
			out.println( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" );
			out.println( "<TD><B>CONSTRAINT_NAME</B></TD>");
v			out.println( "<TD><B>CONSTRAINT_TYPE</B></TD>");
			out.println( "<TD><B>SEARCH_CONDITION</B></TD>");
			out.println( "<TD><B>COLUMN_NAME</B></TD>\n</TR>");
			Set constSet = item.constraints.keySet();
			String[] constNames = (String[])constSet.toArray( new String[ constSet.size() ] );
			for( int i = 0; i < constNames.length; i++ ) {
				out.println( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" );
				TableConstItem citem = (TableConstItem)item.constraints.get( constName[ i ] );
				int columnConut = citem.columnNames.size();
				if( citem.constraintType.equals( "P" ) || citem.constraintType.equals( "U" ) ) {
					out.println( "<TD ROWSPAN =" + columnCount + "><A HREF=\"../index/" + citem.constraintName + ".html\">" + citem.constraintName + </A></TD>" );
				} else {
					out.println( "<TD ROWSPAN=" + columnCount + ">" + citem.constraintName + "</TD>" );
				}
				out.println( "<TD ROWSPAN=" + columnCount + ">" + getConstraintTypeString( citem.constraintType ) + "</TD>" );
				out.println( "<TD ROWSPAN=" + columnCount + ">" + citem.searchConidition + "</DT>" );
				for( int j = 0; j < columnCount; j++ ) {
					String columnName = (String)citem.columnNames.get( j );
					out.println( "<TD><A HREF=\"#" + columnName + "\">" + columnName + "</A></TD></TR>" );
				}
			}
 
			out.println( "</TABLE>" );
		}
 
		// 票領域の情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "票領域の情報", 2, out );
		printTableRow( "TABLESPACE_NAME", item.tablespaceName, out );
		printTableRow( "PCT_FREE", Integer.toString( item.pctFree), out );
		printTableRow( "PCT_USED", Integer.toString( item.pctUsed), out );
		printTableRow( "INITRANS", Integer.toString( item.iniTrans), out );
		printTableRow( "MAX_TRANS", Integer.toString( item.maxTrans), out );
		printTableRow( "INITIAL_EXTENT", Integer.toString( item.initialExtent), out );
		printTableRow( "NEXT_EXTENT", Integer.toString( item.nextExtent), out );
		printTableRow( "MIN_EXTENTS", Integer.toString( item.minExtents), out );
		printTableRow( "MAX_EXTENTS", Integer.toString( item.maxExtents), out );
		printTableRow( "PCT_INCREASE", Integer.toString( item.pctIncrease), out );
		printTableRow( "FREELISTS", Integer.toString( item.freelists), out );
		printTableRow( "FREELISTS_GROUPS", Integer.toString( item.freelistsGroups), out );
		out.println( "</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
 
	}
 
	/**
     * VIEW ページ( フレーム右側 )を生成します。
     * @param item
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createViewFrameHTML( ViewItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// ビューの情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "ビューの情報", 2, out );
		printTableRow( "TEXT", item.text, out );
		out.println( "</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * INDEX ページ( フレーム右側 )を生成します。
     * @param item
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createIndexFrameHTML( IndexItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// 索引の情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "索引の情報", 3, out );
		printTableRow( "INDEX_TYPE", item.indexType, out );
		printTableRow( "TABLE_OWNER", item.tableOwner, out );
		printTableRow( "TABLE_NAME", "<A HREF=\"../table/" + item.tableName + ".html\">" + item.tableName + "</A>", out );
 
		out.println( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" );
		out.println( "<TD ROWSPAN=" + item.column.length + "><B>COLUMN_NAME</B></TD>" );
		for( int i = 0; i < item.columns.length; i++ ) {
			out.println( "<TD><A HREF=\"../table/" + item.tableName + ".html#" + item.columns[ i ] + "\">" + item.column[ i ] + "</A></TD>\n</TD>" );
		}
 
		//printTableRow( "TABLE_TYPE", item.tableType, out );
		printTableRow( "UNIQUENESS", item.uniqueness, out );
		out.println( "</TABLE>" );
 
		// 票領域の情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "票領域の情報", 2, out );
		printTableRow( "TABLESPACE_NAME", item.tablespaceName, out );
		printTableRow( "PCT_FREE", Integer.toString( item.pctFree ), out );
		printTableRow( "INI_TRANS", Integer.toString( item.iniTrans ), out );
		printTableRow( "MAX_TRANS", Integer.toString( item.maxTrans ), out );
		printTableRow( "INITIAL_EXTENT", Integer.toString( item.initialExtent ), out );
		printTableRow( "NEXT_EXTENT", Integer.toString( item.nextExtent ), out );
		printTableRow( "MIN_EXTENTS", Integer.toString( item.minExtents ), out );
		printTableRow( "MAX_EXTENTS", Integer.toString( item.maxExtents ), out );
		printTableRow( "PCT_INCREASE", Integer.toString( item.pctIncrease ), out );
		printTableRow( "FREELISTS", Integer.toString( item.freelists ), out );
		printTableRow( "FREELIST_GROUPS", Integer.toString( item.freelistGroups ), out );
		out.println( "</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * SEQUENCE ページ( フレーム右側 )を生成します。
     * @param item
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createSequenceFrameHTML( IndexItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// 順序の情報
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "順序の情報", 2, out );
		printTableRow( "MIN_VALUE", item.minValue, out );
		printTableRow( "MAX_VALUE", item.maxValue, out );
		printTableRow( "INCREMENT_BY", item.incrementBy, out );
		printTableRow( "CYCLE_FLAG", item.cycleFlag, out );
		printTableRow( "ORDER_FLAG", item.orderFlag, out );
		printTableRow( "CACHE_SIZE", item.cacheSize, out );
		out.println( "</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * PROCEDURE ページ( フレーム右側 )を生成します。
     * @param item
     * @param source
     * @param args
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createProcedureFrameHTML( ObjectItem item, String[] source, ProcArgItem[] args ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// 引数
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "引数の情報", 3, out );
		String[] data = { "<B>ARGUMENT_NAME</B>", "<B>IN_OUT</B>", "<B>DATA_TYPE</B>" };
		printTableRow( data, out );
		for( int i = 0; i < args.length; i++ ) {
			String[] cdata = { args[ i ].argumentName, args[ i ].inOut, args[ i ].dataType };
			printTableRow( cdata, out );
		}
		out.println( "</TABLE>" );
 
		// ソース
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "ソース", 2, out );
		String[] header = { "<B>行</B>", "<B>ソース</B>" };
		printTableRow( header, out );
		out.println( "<TR><TD ALIGN=\"RIGHT\"><PRE STYLE=\"line-height:100%\">" );
		for( int i = 0; i < source.length; i++ ) {
			out.println( i + 1 );
		}
		out.println( "</PRE></TD><TD><PRE STYLE=\"line-height:110%\">" );
		String[] markedSource = getMarkedSource( source, 0, null );
		for( int i = 0; i < markedSource.length; i++ ) {
			out.println( markedSource[ i ] );
		}
		out.println( "</PRE></TD></TR>\n</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
 
	}
 
	/**
     * PACKAGE ページ( フレーム右側 )を生成します。
     * @param item
     * @param procedures
     * @param source
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createPackageFrameHTML( ObjectItem item, String[] procedure, String[] source ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// パッケージの情報
		if( procedures != null ) {
			out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
			printTableHeader( "内部プロシージャのリスト", 1, out );
			for( int i = 0; i < procedures.length; i++ ) {
				out.println( "<TR><TD><A HREF=\"../package_body/" + objectName + "/" + procedures[ i ] + ".html\">" + procedures[ i ] + "</A></TD></TR>" );
			}
			out.println( "</TABLE>" );
		}
 
		// ソース
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "ソース", 2, out );
		String[] header = { "<B>行</B>", "<B>ソース</B>" };
		printTableRow( header, out );
		out.println( "<TR><TD ALIGN=\"RIGHT\"><PRE STYLE=\"line-height:110%\">" );
		for( int i = 0; i < source.length; i++ ) {
			out.println( i + 1 );
		}
		out.println( "</PRE></TD><TD><PRE STYLE=\"line-height:110%\">" );
		String[] markedSource = getMarkedSource( source, 0, objectName );
		for( int i = 0; i < markedSource.length; i++ ) {
			out.println( markedSource[ i ];
		}
 
		out.println( "</PRE></TD></TR>\n</TABLE>" );
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
 
	}
 
	/**
     * PACKAGE BODY ページ( フレーム右側 )を生成します。
     * @param item
     * @param procedures
     * @param sourceMap
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createPkgBodyFrameHTML( ObjectItem item, String[] procedure, String[] source ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName, 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// ヘッダのリンク
		if( procedures != null ) {
			out.println( "<A HREF=\"../package/" + objectName + ".html\">パッケージヘッダ</A>" );
		}
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		// パッケージの情報
		if( procedures != null ) {
			out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
			printTableHeader( "内部プロシージャのリスト", 1, out );
			for( int i = 0; i < procedures.length; i++ ) {
				out.println( "<TR><TD><A HREF=\"" + objectName + "/" + procedures[ i ] + ".html\">" + procedures[ i ] + "</A></TD></TR>" );
			}
			out.println( "</TABLE>" );
		}
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
 
	}
 
	/**
     * パッケージ内部プロシージャページ( フレーム右側 )を生成します。
     * @param item
     * @param item2
     * @param args
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createPkgProcFrameHTML( ObjectItem item, PkgProcItem item2, ProcArgItem[] args ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + _sepa + item2.procName + ".html" );
		file.getParentFile().mkdirs();
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName + "." + item2.procName, 2, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">内部プロシージャ</FONT> " + objectName + "." + item2.procName + "</H2>" );
 
		// ヘッダ、本体へのリンク
		out.println( "<A HREF=\"../package/" + objectName + ".html\">パッケージヘッダ</A> | " );
		out.println( "<A HREF=\"../" + objectName + ".html\">パッケージ本体</A> | " );
 
		// 引数
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "引数の情報", 3, out );
		String[] data = { "<B>ARGUMENT_NAME</B>", "<B>IN_OUT</B>", "<B>DATA_TYPE</B>" };
		printTableRow( data, out );
		for( int i = 0; i < args.length; i++ ) {
			String[] cdata = { args[ i ].argumentName, args[ i ].inOut, args[ i ].dataType };
			printTableRow( cdata, out );
		}
		out.println( "</TABLE>" );
 
		// ソース
		out.println( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">" );
		printTableHeader( "ソース", 3, out );
		String[] header = { "<B>行</B>", "<B>通算</B>", "<B>ソース</B>" };
		printTableRow( header, out );
		out.println( "<TR><TD ALIGN=\"RIGHT\"><PRE STYLE=\"line-height:110%\">" );
		for( int i = 0; i <item2.source.length; i++ ) {
			out.println( i + 1 );
		}
		out.println( "</PRE></TD><TD ALIGN=\"RIGHT\"><PRE STYLE=\"line-height:110%\">" );
		for( int i = item2.startLine; i <= item2.endLine; i++ ) {
			out.println( i + 1 );
		}
		out.println( "</PRE></TD><TD><PRE STYLE=\"line-height:110%\">" );
		String[] markedSource = getMarkedSource( item2.source, 1, objectName );
		for( int i = 0; i < markedSource.length; i++ ) {
			out.println( markedSource[ i ];
		}
 
		out.println( "<HR>\n</BODY>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * その他のオブジェクトページ( フレーム右側 )を生成します。
     * @param item
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createObjectFrameHTML( ObjectItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		String objectName = item.objectName;
		String objectType = item.objectType;
 
		File file = new File( _destDir + getDirectoryName( objectType ) + _sepa + objectName + ".html" );
		file.getParentFile().mkdirs();
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		printHeader( objectName , 1, out );
 
		out.println( BODYTAG );
		out.println( "<H2><FONT SIZE=\"-1\">" + objectType + "</FONT>" + objectName + "</H2>" );
 
		// オブジェクトの情報
		printCommonTable( item, out );
 
		out.println( "<HR>\n</TABLE>" );
 
		printFooter( out );
		out.close();
	}
 
	/**
     * スタイルシートファイルを生成します。
     * @throws FileNotFoundException
     * @throws UnsupportedEncodingException
     */
	public static void createObjectFrameHTML( ObjectItem item ) throws UnsupportedEncodingException, FileNotFoundException {
		File file = new File( _destDir + FILE_STYLESHEET );
		PrintStream out = new PrintStream( new FileOutputStream( file ), true, _encoding );
 
		// ログ出力
		printLog( file.getAbsolutePath() );
 
		out.println( "/* javadoc スタイルシート */" );
		out.println( "" );
		out.println( "/* 色やフォントなどのスタイル属性のデフォルト値を上書きするには、ここで定義します。 */" );
		out.println( "" );
		out.println( "/* ページのバックグラウンドの色 */" );
		out.println( "body { background-color: #FFFFFF }" );
		out.println( "" );
		out.println( "/* テーブルの色 */" );
		out.println( ".TableHeadingColor    { background: #CCCCFF } /* 濃い藤色 */" );
		out.println( ".TableSubHeadingColor { background: #EEEEEE } /* 薄い藤色 */" );
		out.println( ".TableRowColor        { background: #FFFFFF } /* 白       */" );
		out.println( "" );
		out.println( "/* 左側のフレームのリストに使用するフォント */" );
		out.println( ".FrameTitileFont    { font-size: 10pts; font-family: Helvetica, Arial, san-serif }" );
		out.println( ".FrameHeadingFont   { font-size: 10pts; font-family: Helvetica, Arial, san-serif }" );
		out.println( ".FrameItemFont      { font-size: 10pts; font-family: Helvetica, Arial, san-serif }" );
		out.println( "" );
		out.println( "/* フレームにおける、より小さい、セリフなしフォントの例 */" );
		out.println( "/* .FrameItemFont      { font-size: 10pts; font-family: Helvetica, Arial, san-serif } */" );
		out.println( "" );
		out.println( "/* ナビゲーションバーのフォントと色 */" );
		out.println( ".NavBarCell1    { background-color:#EEEEFF; } /* 薄い藤色 */" );
		out.println( ".NavBarCell1Rev { background-color:#00008B; } /* 濃い青色 */" );
		out.println( ".NavBarFont1    { font-family: Arial, Helvetica, san-serif; color:#000000; }" );
		out.println( ".NavBarFont1Rev { font-family: Arial, Helvetica, san-serif; color:#FFFFFF; }" );
		out.println( "" );
		out.println( ".NavBarcell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFF; }" );
		out.println( ".NavBarcell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFF; }" );
 
		out.close();
	}
 
	/**
     * ヘッダを出力します。
     * @param windowTitle ウィンドウのタイトル
     * @param out 出力先
     */
	private static void printHeader( String title, int depth, PrintStream out ) {
		String windowTitle = _windowTitile;
		if( title != null ) {
			windowTitle = title + " (" + _windowTitle + ") ";
		}
 
		String path = "";
		for( int i = 0; i < depth; i++ ) {
			path = path + "../";
		}
 
		out.println( "<!DOCTYP HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\"http://www.w3.org/TR/TRC-html40/loose.dtd\">" );
		out.println( "<HTML>" );
		out.println( "<HEAD>" );
		out.println( "<!-- Generated by Oradoc.java on " + _generatedTime + " -->" );
		out.println( "<META http-equiv=\"Content-Type\" content=\"text/html; charset=" + _encoding + "\">" );
		out.println( "<TITLE>" + windowTitle + "</TITLE>" );
		out.println( "<LINK REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"" + path + FILE_STYLESHEET + "\" TTITLE=\"Style\">" );
		out.println( "</HEAD>" );
 
		if( title != nul ) {
			out.println( "<SCRIPT>" );
			out.println( "function asd() {" );
			out.println( "parent.document.title=\"" + windowTilte + "\";" );
			out.println( "}" );
			out.println( "</SCRIPT>" );
		}
 
	}
 
	/**
     * フッタを出力します。
     * @param out 出力先
     */
	private static void printFooter( PrintStream out ) {
		out.println( "</HTML>" );
	}
 
	/**
     * テーブルのヘッダを出力します。
     * param title
     * param data
     * param out 出力先
     */
	private static void printTableHeader( String data, itn colspan, PrintStream out ) {
		out.println( "<TR BGCOLOR=\"#CCCCFF\" CLAS=\"TableHeadingColor\">" );
		out.println( "<TD COLSPAN=" + colspan + "><FONT SIZE=\"+2\">" );
		out.println( "<B>" + data + "</B></FONT></TD>\n</TR>" );
	}
 
	/**
     * テーブルの一行を出力します
     * @param title
     * @param data
     * @param out 出力先
     */
	private static void printTableRow( String title, String data, PrintSteam out ) {
		out.println( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" );
		out.println( "<TD><B>" + title + "</B></TD>" );
		out.println( "<TD>" + data + "</TD>\n</TR>" );
	}
 
	/**
     * テーブルの一行を出力します
     * @param data
     * @param out
     */
	private static void printTableRow( String[] data, PrintSteam out ) {
		out.println( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" );
		for( int i = 0; i < data.length; i++ ) {
			out.println( "<TD>" + data[ i ] + "</TD>" );
		}
		out.println( "</TR>" );
	}
 
	/**
     * 共通部分を生成します
     * @param item
     * @param out
     */
	private static void printCommonTable( ObjectItem item, PrintStream out ) {
		out.prinln( "<HR>\n<TABLE BORDER=\"1\" CELLPADDING=\3\" CELLSPACING=\"0\">" );
		printTableHeader( "オブジェクトの情報", 2, out );
		printTableRow( "作成日時", item.createdDate + " " + item.createdTime, out );
		printTableRow( "更新日時", item.lastDDLDate + " " + item.lastDDLTime, out );
		printTableRow( "ステータス", item.status, out );
		printTableRow( "</TABLE>" );
	}
 
	/**
     * ログを出力します
     * @param fileName
     */
	private static void printLog( String fileName ) {
		if( _verbose ) {
			System.out.println( "[HTMLManager]" + fileName + "を出力しています。" );
		}
	}
 
	/**
     * ディレクトリ名を生成します。
     * @param dataType
     * @return
     */
	private static String getDirectoryName( String dataType ) {
		return dataType.toLowerCase().replace( ' ', '_' );
	}
 
	/**
     * 制約の種類を返します
     * @param constType
     * @return
     */
	private static String getConstraintTypeString( String constType ) {
		switch( constType.charAt( 0 ) ) {
		case 'C':
			return "Check";
		case 'P':
			return "Primary Key";
		case 'R':
			return "Foreign Key";
		case 'U':
			return "Unique Key";
		default:
			return null;
		}
	}
 
	/**
     * ソースを修飾します
     * @param lines
     * @param depth
     * @return
     */
	private static String[] getMarkedSource( String[] lines, int depth, String pkg ) {
		String path = "";
		for( int i = 0; i < depth; i++ ) {
			path = path + "../";
		}
 
		String[] newLines = new String[ lines.length ];
		boolean commentFlag = false;
		for( int i = 0; i < lines.length; i++ ) {
			String newLine = lines[ i ];
			// 改行を除去
			newLine = newLine.replaceAll( "\r|\n", "" );
			// タブ -> SPACE変換
			int tabIndex = -1;
			while( ( tabIndex = newLine.indexOf( '\t', tabIndex + 1 ) ) != -1 ) {
				String beforeTab = ( tabIndex > 0 ) ? newLine.substring( 0, tabIndex ) : "";
				String afterTab = newLine.substring( tabIndex + 1 );
				newLine = beforeTab;
				for( int j = 0; j < 4 - ( tabIndex % 4 ); j++ ) {
					newLine = newLine + " ";
				}
				newLine = newLine + afterTab;
			}
			// 括弧を変換
			newLine = newLine.replaceAll( "<", "&lt;" );
			newLine = newLine.replaceAll( ">", "&gt;" );
 
			// コメント
			String commentColor = "#008800";
			// head
			if( commentFlag ) {
				newLine = "<FONT COLOR=\"" + commentColor + "\">" + newLine;
			}
			// body
			if( !commentFlag && newLine.indexOf( "/*" ) != -1 ) {
				commentFlag = true;
				newLine = newLine.replaceFirst( "/\\*", "<FONT COLOR=\"" + commentColor + "\">/\\*" );
			}
			if( !commentFlag && newLine.indexOf( "*/" ) != -1 ) {
				commentFlag = false;
				newLine = newLine.replaceFirst( "\\*/", "\\*/</FONT>" );
			}
			if( !commentFlag && newLine.indexOf( "--" ) != -1 ) {
				newLine = newLine.replaceFirst( "--", "<FONT COLOR=\"" + commentColor + "\">--" );
				newLine = newLine + "</FONT>";
			}
			// foot
			if( commentFlag ) {
				newLine = newLine + "</FONT>";
			}
 
			// リンク
			if( !commentFlag ) {
				int commentIndex = newLine.indexOf( "--" );
				// ROWTYPE
				if( newLine.matches( ".+%ROWTYPE.*" ) && ( commentIndex == -1 || newLine.indexOf( "%ROWTYPE" ) < commentIndex ) ) {
					String[] strs = newLine.split( " " );
					String tmpLine = "";
					for( int j = 0; j < strs.length; j++ ) {
						if( strs[ j ].matches( ".+%ROWTYPE.*" ) ) {
							String tableName = strs[ j ].substring( 0, strs[ j ].indexOf( "%" ) );
							String linkStr = "<A HREF=\"" + path + "../table/" + tableName + ".html\">" + tableName + "</A>%ROWTYPE";
							tmpLine = tmpLine + strs[ j ].replaceAll( ".+%ROWTYPE", linkStr ) + " ";
						} else {
							tmpLine = tmpLine + strs[ j ] + " ";
						}
					}
					newLine = tmpLine;
				}
				// TYPE
				if( newLine.matches( ".+\\..+%TYPE.*" ) && ( commentIndex == -1 || newLine.indexOf( "%TYPE" ) < commentIndex ) ) {
					String[] strs = newLine.split( " " );
					String tmpLine = "";
					for( int j = 0; j < strs.length; j++ ) {
						if( strs[ j ].matches( ".+\\..+%TYPE.*" ) ) {
							int dot = strs[ j ].indexOf( "." );
							String tableName = strs[ j ].substring( 0, dot );
							String columnName = strs[ j ].substring( dot + 1, strs[ j ].indexOf( "%", dot ) );
							String linkStr = "<A HREF=\"" + path + "../table/" + tableName + ".html#" + columnName +"\">" + tableName + "." + columnName + "</A>%TYPE";
							tmpLine = tmpLine + strs[ j ].replaceAll( ".+\\..+%TYPE", linkStr ) + " ";
						} else {
							tmpLine = tmpLine + strs[ j ] + " ";
						}
					}
					newLine = tmpLine;
				}
				// PROCEDURES
				newLine = getLinkStr( newLine, path, pkg );
			}
			newLines[ i ] = newLine;
		}
		return newLines;
	}
 
	/**
     * リンク用プロシージャリスト設定
     * @param packages
     */
     public static void setProcedures( String[] procedures, String[] functions, HashMap package ) {
     	// Procedures
     	_procedures = procedures;
     	// Functions
     	_functions = functions;
     	// Package
     	_package = package;
     }
 
	/**
     * 他のプロシージャへのリンクを生成する
     * @param line
     * @param path
     * @return
     */
     public static String getLinkStr( String line, String path, String pkg ) {
     	String str = line.toUpperCase();
     	int commentIndex = line.indexOf( "--" );
 
     	// Packages
     	Set set = _packages.keySet();
     	for( Iterator iter = set.iterator(); iter.hasNext(); ) {
     		String key = ( String ) iter.next();
     		ArrayList list = ( ArrayList )_packages.get( key );
     		for( Iterator iterator = list.iterator(); iterator.hasNext(); ) {
     			String name = ( String ) iterator.next();
     			String compStr = key.toUpperCase() + "." + name.toUpperCase();
 
     			if( str.matches( ".*\\b" + compStr.toUpperCase() + "\\b.*" ) ) {
     				int index = str.indexOf( compStr );
     				if( index != -1 && ( commentIndex == -1 || index < commentIndex ) ) {
     					String orgStr = line.substring( index, index + compStr.length() );
     					String linkStr = "<A HREF=\"" + path + "../package_body/" + key + "/" + name + ".html\">" + orgStr + "</A>";
     					return line.replaceAll( orgStr, linkStr );
     				}
     			}
 
     			// inner
     			if( pkg != null && key.equals( pkg ) && str.matches( ".*\\b" + name.toUpperCase() + "\\b.*" ) ) {
     				int index = str.indexOf( name.toUpperCase() );
     				if( index != -1 && ( commentIndex == -1 || index < commentIndex ) ) {
     					String orgStr = line.substring( index, index + name.length() );
     					String linkStr = "<A HREF=\"" + path + "../package_body/" + key + "/" + name + ".html\">" + orgStr + "</A>";
     					return line.replaceAll( orgStr, linkStr );
     				}
     			}
     		}
     	}
 
     	// Procedures
     	if( _procedures != null ) {
     		for( int i = 0; i < _procedures.length; i++ ) {
     			if( str.matches( ".*\\b" + _procedures[ i ].toUppereCase() + "\\b.*" ) ) {
     				int index = str.indexOf( _procedures[ i ].toUpperCase() );
     				if( index != -1 && ( commentIndex == -1 || index < commentIndex ) ) {
     					String orgStr = line.substring( index, index + _procedures[ i ].length() );
     					String linkStr = "<A HREF=\"" + path + "../procedure/" + _procedures[ i ] + ".html\">" + orgStr + "</A>";
     					return line.replaceAll( orgStr, linkStr );
     				}
     			}
     		}
     	}
 
     	// Functions
     	if( _functions != null ) {
     		for( int i = 0; i < _functions.length; i++ ) {
     			int index = str.indexOf( _functions[ i ].toUpperCase() );
     			if( index != -1 && ( commentIndex == -1 || index < commentIndex ) ) {
     				String orgStr = line.substring( index, index + _functions[ i ].length() );
     				String linkStr = "<A HREF=\"" + path + "../function/" + _functions[ i ] + ".html\">" + orgStr + "</A>";
     				return line.replaceAll( orgStr, linkStr );
     			}
     		}
     	}
     	return line;
     }
}
 
----
作成日:2007/12/07
更新日:2007/12/07
----
最終更新:2007年12月07日 10:06