//将java代码生成html并且高亮显示
import java.util.*;
import java.io.*;
public class java2html
{
private static boolean comment=false;
private static boolean lineComment=false;
private static boolean START = true;
private static boolean END = false;
private static boolean backslash=false;
private static boolean stringlit = false;
private static boolean stringlit2 = false;
private static int tabWidth = 0;
private static String tab=" ";
private static Collection varList = new ArrayList();
private static StringBuffer out = new StringBuffer();
private static Collection primitives = new ArrayList();
static
{
String[] primString =
{"int","Integer", "byte","Byte", "boolean","Boolean", "short", "Short", "long", "Long", "char", "Character", "float", "Float", "double", "Double", "String", "void","StringBuffer","Collection"};
for(int i=0; i<primString.length; i++)
primitives.add(primString[i]);
}
private static Collection operators = new ArrayList();
static
{
String[] operString =
{"=", ">", "<", "!", "~", "?", ":", "==", "<=", ">=", "!=", "&&", "||", "++", "--", "+", "-", "*", "/", "&", "|", "^", "%", ">>", "<<", ">>>", "+=", "-=", "*=", "/=", "&=", "|=", "^=", "%=", "<<=", ">>=", "<<<"};
for(int i=0; i<operString.length; i++)
operators.add(operString[i]);
}
private static Collection string = new ArrayList();
static
{
String[] stringString =
{"\""};
for(int i=0; i<stringString.length; i++)
string.add(stringString[i]);
}
private static Collection flow = new ArrayList();
static
{
String[] flowString =
{"true" , "false" , "null" , "import"};
for(int i=0; i<flowString.length; i++)
flow.add(flowString[i]);
}
private static Collection resWords = new ArrayList();
static
{
String[] reswString =
{"private", "static", "new", "public", "final", "class", "this", "synchronized", "native", "package", "if", "then", "else", "finally", "switch", "do", "while", "case", "default", "return", "break", "continue", "throw", "throws", "catch", "try", "for","protected"};
for(int i=0; i<reswString.length; i++)
resWords.add(reswString[i]);
}
private static void java2html(String fileName)
{ }
public static void tabIncrease(boolean up)
{
//prComment(START);out.append("tabs");prComment(END);
if(up)
{
tabWidth++;
} else
{
tabWidth--;
}
tab=" ";
for(int i=tabWidth; i>0; i--)
{
tab = tab+" ";
}
}
public static void prTitle(String str)
{
out.append("<TITLE>" + str + "</TITLE>");
out.append("\n");
}
public static void prPrimitive(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<b><FONT color=red>" + str + "</FONT></b>");
out.append("\n");
}
}
public static void prVar(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<FONT color=red>" + str + "</FONT>");
out.append("\n");
}
}
public static void prFlow(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<b><FONT color=black>" + str + "</FONT></b>");
out.append("\n");
}
}
public static void prResWord(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<b><FONT color=black>" + str + "</FONT></b>");
out.append("\n");
}
}
public static void prNormal(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append(str);
out.append("\n");
}
}
public static void prJComment(String str)
{
out.append("<FONT color=#888888>" + str + "</FONT>");
out.append("\n");
}
public static void prOperator(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<FONT color=black>" + str + "</FONT>\n");
}
}
public static void prNumber(String str)
{
if (comment || lineComment)
{
prJComment(str);
} else if (stringlit)
{
prStringLit(str);
} else
{
out.append("<FONT color=blue>" + str + "</FONT>\n");
}
}
public static void prStringLit(String str)
{
out.append(str +"\n");
}
public static void prHead(boolean start)
{
if(start)
{
out.append("<HEAD>");
out.append("\n");
} else
{
out.append("</HEAD>");
out.append("\n");
}
}
public static void prBody(boolean start)
{
if (start)
{
out.append("<BODY bgcolor=white color=red>");
out.append("\n");
out.append("<tt><FONT color=red>");
out.append("\n");
} else
{
out.append("</FONT></tt>");
out.append("\n");
out.append("</BODY>");
out.append("\n");
}
}
public static void prComment(boolean start)
{
if(start)
{
out.append("<!--");
out.append("\n");
} else
{
out.append("-->");
out.append("\n");
}
}
public static void prHtml(boolean start)
{
if(start)
{
out.append("<HTML>");
out.append("\n");
} else
{
out.append("</HTML>");
out.append("\n");
}
}
public static void prBr(boolean start)
{
if(start)
{
out.append("<BR>");
out.append("\n");
} else
{
out.append("<BR>");
out.append("\n");
}
out.append(tab);
}
public static void prP(boolean start)
{
if(start)
{
out.append("<P>");
out.append("\n");
} else
{
out.append("</P>");
out.append("\n");
}
}
public static void prTable(boolean start)
{
if(start)
{
out.append("<TABLE>");
out.append("\n");
} else
{
out.append("</TABLE>");
out.append("\n");
}
}
public static void prTr(boolean start)
{
if(start)
{
out.append("<TR>");
out.append("\n");
} else
{
out.append("</TR>");
out.append("\n");
}
}
public static void prTd(boolean start)
{
if(start)
评论0