You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2007/10/20 18:58:24 UTC
svn commit: r586760 - in
/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc:
GenerateHTMLDoc.java GenerateHTMLIndex.java
Author: hboutemy
Date: Sat Oct 20 09:58:23 2007
New Revision: 586760
URL: http://svn.apache.org/viewvc?rev=586760&view=rev
Log:
o changed OutputStream to PrintWriter
o changed some private static fields to local variables
Modified:
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLDoc.java
maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLIndex.java
Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLDoc.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLDoc.java?rev=586760&r1=586759&r2=586760&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLDoc.java (original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLDoc.java Sat Oct 20 09:58:23 2007
@@ -24,9 +24,10 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.PrintWriter;
/**
* Class that mounts a Document in HTML as document
@@ -39,14 +40,10 @@
/** Logger for this class */
private static final Logger log = Logger.getLogger( GenerateHTMLDoc.class );
- private static FileOutputStream fos;
+ private static PrintWriter out;
private static BufferedReader br;
- private static String LINE_SEPARATOR = String.valueOf( (char) 13 ) + String.valueOf( (char) 10 );
-
- private static String stringReader;
-
private static int functionCount = 0;
private static String functionName = "";
@@ -61,99 +58,87 @@
public GenerateHTMLDoc( File fis, String destDir )
{
- String nomeArquivo = fis.getName();
try
{
- fos = new FileOutputStream( destDir + nomeArquivo.substring( 0, nomeArquivo.indexOf( "." ) ) + ".htm" );
- br = new BufferedReader( new FileReader( fis ) );
-
- }
- catch ( FileNotFoundException fnfe )
- {
- log.error( "FileNotFoundException: " + fnfe.getMessage(), fnfe );
- }
+ String nomeArquivo = fis.getName();
+ try
+ {
+ out = new PrintWriter( new FileWriter( destDir + nomeArquivo.substring( 0, nomeArquivo.indexOf( "." ) ) + ".htm" ) );
+ br = new BufferedReader( new FileReader( fis ) );
+ }
+ catch ( FileNotFoundException fnfe )
+ {
+ log.error( "FileNotFoundException: " + fnfe.getMessage(), fnfe );
+ }
- try
- {
- fos.write( ( "<html>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<head>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<style type=\"text/css\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( ".TableHeadingColor { background: #CCCCFF } /* Dark mauve */" + LINE_SEPARATOR )
- .getBytes() );
- fos.write( ( ".NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</style>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<title>Javascript code documentation</title>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</head>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<body>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<H2>Filename: " + nomeArquivo + "</H2>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<br>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<br>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">" + LINE_SEPARATOR )
- .getBytes() );
- fos.write( ( "<TR CLASS=\"TableHeadingColor\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD ALIGN=\"left\" colspan=\"2\"><FONT SIZE=\"+2\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<B>Function Summary</B></FONT></TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</TR>" + LINE_SEPARATOR ).getBytes() );
+ out.println( "<html>" );
+ out.println( "<head>" );
+ out.println( "<style type=\"text/css\">" );
+ out.println( ".TableHeadingColor { background: #CCCCFF } /* Dark mauve */" );
+ out.println( ".NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */" );
+ out.println( "</style>" );
+ out.println( "<title>Javascript code documentation</title>" );
+ out.println( "</head>" );
+ out.println( "<body>" );
+ out.println( "<H2>Filename: " + nomeArquivo + "</H2>" );
+ out.println( "<br>" );
+ out.println( "<br>" );
+ out.println( "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">" );
+ out.println( "<TR CLASS=\"TableHeadingColor\">" );
+ out.println( "<TD ALIGN=\"left\" colspan=\"2\"><FONT SIZE=\"+2\">" );
+ out.println( "<B>Function Summary</B></FONT></TD>" );
+ out.println( "</TR>" );
+
while ( br.ready() )
{
- stringReader = br.readLine();
+ String content = br.readLine();
- while ( summary && null != stringReader && stringReader.indexOf( "summary" ) == -1 )
+ while ( summary && null != content && content.indexOf( "summary" ) == -1 )
{
- stringReader = br.readLine();
-
+ content = br.readLine();
}
summary = false;
- if ( null != stringReader && stringReader.indexOf( "/**" ) != -1 )
+ if ( null != content && content.indexOf( "/**" ) != -1 )
{
- fos.write( ( "<TR>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD WIDTH=\"30%\" BGCOLOR=\"#f3f3f3\"><font face=\"Verdana\"><b><span id=\"Function"
- + functionCount + "\"></span></b></font></TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD WIDTH=\"70%\">" + LINE_SEPARATOR ).getBytes() );
- stringReader = br.readLine();
+ out.println( "<TR>" );
+ out.println( "<TD WIDTH=\"30%\" BGCOLOR=\"#f3f3f3\"><font face=\"Verdana\"><b><span id=\"Function"
+ + functionCount + "\"></span></b></font></TD>" );
+ out.println( "<TD WIDTH=\"70%\">" );
+ content = br.readLine();
- while ( null != stringReader && stringReader.indexOf( "*/" ) == -1 )
+ while ( null != content && content.indexOf( "*/" ) == -1 )
{
-
- if ( stringReader.indexOf( "* @" ) != -1 )
+ if ( content.indexOf( "* @" ) != -1 )
{
- if ( ( stringReader.indexOf( "author" ) == -1 ) )
+ if ( ( content.indexOf( "author" ) == -1 ) )
{
- if ( stringReader.indexOf( "param" ) != -1 )
+ if ( content.indexOf( "param" ) != -1 )
{
if ( parameterList == false )
{
parameterList = true;
- fos.write( "<font size=\"-1\" face=\"Verdana\"><b>Parameters: </b></font>"
- .getBytes() );
- fos.write( "<BR>".getBytes() );
+ out.println( "<font size=\"-1\" face=\"Verdana\"><b>Parameters: </b></font>" );
+ out.println( "<BR>" );
}
- fos.write( " ".getBytes() );
- fos
- .write( ( stringReader.substring( stringReader.indexOf( "* @param" ) + 9 ) + LINE_SEPARATOR )
- .getBytes() );
+ out.println( " " );
+ out.println( content.substring( content.indexOf( "* @param" ) + 9 ) );
}
- else if ( stringReader.indexOf( "use" ) != -1 )
+ else if ( content.indexOf( "use" ) != -1 )
{
if ( useList == false )
{
useList = true;
- fos.write( "<font size=\"-1\" face=\"Verdana\"><b>Uso: </b></font>".getBytes() );
- fos.write( "<BR>".getBytes() );
+ out.println( "<font size=\"-1\" face=\"Verdana\"><b>Uso: </b></font><BR>" );
}
- fos.write( " ".getBytes() );
- fos
- .write( ( stringReader.substring( stringReader.indexOf( "* @use" ) + 7 ) + LINE_SEPARATOR )
- .getBytes() );
+ out.print( " " );
+ out.println( content.substring( content.indexOf( "* @use" ) + 7 ) );
}
- else if ( stringReader.indexOf( "return" ) != -1 )
+ else if ( content.indexOf( "return" ) != -1 )
{
- fos.write( "<font size=\"-1\" face=\"Verdana\"><b>Return type: </b></font>".getBytes() );
- fos
- .write( ( stringReader.substring( stringReader.indexOf( "* @return" ) + 10 ) + LINE_SEPARATOR )
- .getBytes() );
+ out.print( "<font size=\"-1\" face=\"Verdana\"><b>Return type: </b></font>" );
+ out.print( content.substring( content.indexOf( "* @return" ) + 10 ) );
}
- fos.write( "<BR>".getBytes() );
+ out.println( "<BR>" );
}
}
else
@@ -161,48 +146,45 @@
if ( description )
{
description = false;
- fos.write( "<font size=\"-1\" face=\"Verdana\"><b>Description: </b></font>".getBytes() );
+ out.println( "<font size=\"-1\" face=\"Verdana\"><b>Description: </b></font>" );
}
else
- fos.write( " ".getBytes() );
- fos.write( ( stringReader.substring( stringReader.indexOf( "*" ) + 1 ) + LINE_SEPARATOR )
- .getBytes() );
- fos.write( "<BR>".getBytes() );
+ out.println( " " );
+ out.println( content.substring( content.indexOf( "*" ) + 1 ) + "<BR>" );
}
- stringReader = br.readLine();
+ content = br.readLine();
}
description = true;
parameterList = false;
useList = false;
- while ( null != stringReader && stringReader.indexOf( "function" ) == -1 )
+ while ( null != content && content.indexOf( "function" ) == -1 )
{
- stringReader = br.readLine();
+ content = br.readLine();
}
- if ( stringReader.indexOf( "function" ) != -1 )
+ if ( content.indexOf( "function" ) != -1 )
{
- if ( stringReader.indexOf( "{" ) != -1 )
+ if ( content.indexOf( "{" ) != -1 )
{
- functionName = stringReader.substring( stringReader.indexOf( "function" ) + 9, stringReader
- .indexOf( "{" ) );
+ functionName = content.substring( content.indexOf( "function" ) + 9, content.indexOf( "{" ) );
}
else
{
- functionName = stringReader.substring( stringReader.indexOf( "function" ) + 9 );
+ functionName = content.substring( content.indexOf( "function" ) + 9 );
}
}
- fos.write( ( "</TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<script>document.all.Function" + functionCount + ".innerHTML = \"" + functionName
- + "\"; </script>" + LINE_SEPARATOR ).getBytes() );
+ out.println( "</TD>" );
+ out.println( "<script>document.all.Function" + functionCount + ".innerHTML = \"" + functionName
+ + "\"; </script>" );
functionCount++;
- fos.write( ( "</TR>" + LINE_SEPARATOR ).getBytes() );
+ out.println( "</TR>" );
}
}
- fos.write( ( "</TABLE>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<a href=\"javascript:history.back()\"><font size=\"+1\">Back</font></a>" + LINE_SEPARATOR )
- .getBytes() );
- fos.write( "</body>".getBytes() );
- fos.write( "</html>".getBytes() );
+ out.println( "</TABLE>" );
+ out.println( "<a href=\"javascript:history.back()\"><font size=\"+1\">Back</font></a>" );
+ out.println( "</body>" );
+ out.println( "</html>" );
+ out.close();
}
catch ( IOException ioe )
{
Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLIndex.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLIndex.java?rev=586760&r1=586759&r2=586760&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLIndex.java (original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-js/src/main/java/org/apache/maven/jxr/js/doc/GenerateHTMLIndex.java Sat Oct 20 09:58:23 2007
@@ -25,9 +25,11 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Writer;
import java.util.Vector;
/**
@@ -41,22 +43,8 @@
/** Logger for this class */
private static final Logger log = Logger.getLogger( GenerateHTMLIndex.class );
- private static File file = null;
-
- private static FileInputStream fis;
-
- private static FileOutputStream fos;
-
- private static BufferedReader br;
-
- private static String stringReader;
-
- private static String LINE_SEPARATOR = String.valueOf( (char) 13 ) + String.valueOf( (char) 10 );
-
private static Vector v = new Vector();
- private static GenerateHTMLDoc docGenerator;
-
public GenerateHTMLIndex( String jSDir, String destDir )
throws IllegalArgumentException
{
@@ -96,7 +84,7 @@
destDir = destDir + "/";
}
- file = new File( jSDir );
+ File file = new File( jSDir );
if ( !file.isDirectory() )
{
@@ -107,53 +95,53 @@
try
{
- fos = new FileOutputStream( destDir + "index.htm" );
-
- }
- catch ( FileNotFoundException fnfe )
- {
+ Writer writer = null;
try
{
- file = new File( destDir );
- file.mkdir();
- fos = new FileOutputStream( destDir + "index.htm" );
+ writer = new FileWriter( destDir + "index.htm" ); // platform encoding
+
}
- catch ( FileNotFoundException e )
+ catch ( FileNotFoundException fnfe )
{
- log.error( "FileNotFoundException: " + e.getMessage(), e );
+ try
+ {
+ file = new File( destDir );
+ file.mkdir();
+ writer = new FileWriter( destDir + "index.htm" );
+ }
+ catch ( FileNotFoundException e )
+ {
+ log.error( "FileNotFoundException: " + e.getMessage(), e );
+ }
}
- }
- try
- {
- fos.write( ( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " +
- "\"http://www.w3.org/TR/html4/loose.dtd\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<html>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<head>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<style type=\"text/css\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( ".TableHeadingColor { background: #CCCCFF } /* Dark mauve */" + LINE_SEPARATOR )
- .getBytes() );
- fos.write( ( ".NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</style>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<title>JavaScript Code Documentation</title>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</head>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<body>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<H2>Index</H2>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<br>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<br>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">" + LINE_SEPARATOR )
- .getBytes() );
- fos.write( ( "<TR CLASS=\"TableHeadingColor\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD ALIGN=\"left\"><FONT SIZE=\"+2\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<B>Filename</B></FONT></TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD ALIGN=\"left\"><FONT SIZE=\"+2\">" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<B>Summary</B></FONT></TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</TR>" + LINE_SEPARATOR ).getBytes() );
+
+ PrintWriter out = new PrintWriter( writer );
+
+ out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " +
+ "\"http://www.w3.org/TR/html4/loose.dtd\">" );
+ out.println( "<html>" );
+ out.println( "<head>" );
+ out.println( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" );
+ out.println( "<style type=\"text/css\">" );
+ out.println( ".TableHeadingColor { background: #CCCCFF } /* Dark mauve */" );
+ out.println( ".NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */" );
+ out.println( "</style>" );
+ out.println( "<title>JavaScript Code Documentation</title>" );
+ out.println( "</head>" );
+ out.println( "<body>" );
+ out.println( "<H2>Index</H2>" );
+ out.println( "<br>" );
+ out.println( "<br>" );
+ out.println( "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">" );
+ out.println( "<TR CLASS=\"TableHeadingColor\">" );
+ out.println( "<TD ALIGN=\"left\"><FONT SIZE=\"+2\"><B>Filename</B></FONT></TD>" );
+ out.println( "<TD ALIGN=\"left\"><FONT SIZE=\"+2\"><B>Summary</B></FONT></TD>" );
+ out.println( "</TR>" );
for ( int i = 0; i < v.size(); i++ )
{
file = (File) v.get( i );
- docGenerator = new GenerateHTMLDoc( file, destDir );
+ GenerateHTMLDoc docGenerator = new GenerateHTMLDoc( file, destDir );
}
if ( log.isInfoEnabled() )
@@ -169,38 +157,35 @@
}
file = (File) v.get( i );
- fos.write( ( "<TR>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD WIDTH=\"30%\" BGCOLOR=\"#f3f3f3\"><font face=\"Verdana\"><b><a href=\""
+ out.println( "<TR>" );
+ out.println( "<TD WIDTH=\"30%\" BGCOLOR=\"#f3f3f3\"><font face=\"Verdana\"><b><a href=\""
+ file.getName().substring( 0, file.getName().indexOf( "." ) ) + ".htm" + "\">" + file.getName()
- + "</a></b></font></TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "<TD WIDTH=\"70%\">" + LINE_SEPARATOR ).getBytes() );
+ + "</a></b></font></TD>" );
+ out.println( "<TD WIDTH=\"70%\">" );
try
{
- fis = new FileInputStream( file );
- br = new BufferedReader( new InputStreamReader( fis ) );
+ FileInputStream fis = new FileInputStream( file );
+ BufferedReader br = new BufferedReader( new InputStreamReader( fis ) ); // platform encoding
+ String content;
while ( br.ready() )
{
- stringReader = br.readLine();
- if ( null != stringReader && stringReader.indexOf( "/**" ) != -1 )
+ content = br.readLine();
+ if ( null != content && content.indexOf( "/**" ) != -1 )
{
- stringReader = br.readLine();
- while ( null != stringReader && stringReader.indexOf( "*/" ) == -1 )
+ content = br.readLine();
+ while ( null != content && content.indexOf( "*/" ) == -1 )
{
- if ( stringReader.indexOf( "* @" ) != -1 )
+ if ( content.indexOf( "* @" ) != -1 )
{
- if ( stringReader.indexOf( "summary" ) != -1 )
+ if ( content.indexOf( "summary" ) != -1 )
{
-
- fos
- .write( ( stringReader
- .substring( stringReader.indexOf( "* @summary" ) + 11 ) + LINE_SEPARATOR )
- .getBytes() );
- fos.write( "<BR>".getBytes() );
+ out.println( content.substring( content.indexOf( "* @summary" ) + 11 ) );
+ out.println( "<BR>" );
}
}
- stringReader = br.readLine();
+ content = br.readLine();
}
}
}
@@ -211,14 +196,15 @@
log.error( "FileNotFoundException: " + fnfe.getMessage(), fnfe );
}
- fos.write( ( "</TD>" + LINE_SEPARATOR ).getBytes() );
- fos.write( ( "</TR>" + LINE_SEPARATOR ).getBytes() );
+ out.println( "</TD>" );
+ out.println( "</TR>" );
}
- fos.write( ( "</TABLE>" + LINE_SEPARATOR ).getBytes() );
- fos.write( "</body>".getBytes() );
- fos.write( "</html>".getBytes() );
+ out.println( "</TABLE>" );
+ out.println( "</body>" );
+ out.println( "</html>" );
+ out.close();
}
catch ( IOException ioe )
{