Added Stefan Pollach's magnificent helma.doc package
This commit is contained in:
parent
57eecf99be
commit
488cb46c09
10 changed files with 1261 additions and 0 deletions
89
src/helma/doc/DocApplication.java
Normal file
89
src/helma/doc/DocApplication.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class DocApplication extends DocElement {
|
||||
|
||||
private DocPrototype[] prototypes;
|
||||
|
||||
/** read all prototypes
|
||||
* @param name application to be documented
|
||||
* @param appDir directory of this application */
|
||||
public DocApplication(String name, String appDir) throws DocException {
|
||||
super( name, appDir, APPLICATION );
|
||||
checkCommentFile();
|
||||
readPrototypes();
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return ( "Application " + name );
|
||||
}
|
||||
|
||||
/** return number of prototypes */
|
||||
public int countPrototypes() {
|
||||
return prototypes.length;
|
||||
}
|
||||
|
||||
/** return a single prototype */
|
||||
public DocPrototype getPrototype(String name) {
|
||||
for ( int i=0; i<prototypes.length; i++ ) {
|
||||
if ( prototypes[i].getName().equalsIgnoreCase(name) )
|
||||
return prototypes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** return array of prototypes */
|
||||
public DocPrototype[] listPrototypes() {
|
||||
return prototypes;
|
||||
}
|
||||
|
||||
public DocFunction[] listFunctions() {
|
||||
return listFunctions(-1);
|
||||
}
|
||||
|
||||
public DocFunction[] listFunctions(int type) {
|
||||
Vector funcVec = new Vector();
|
||||
for ( int i=0; i<prototypes.length; i++ ) {
|
||||
DocFunction[] tmp = prototypes[i].listFunctions();
|
||||
for ( int j=0; j<tmp.length; j++ ) {
|
||||
if ( type==-1 || tmp[j].getType()==type )
|
||||
funcVec.addElement(tmp[j]);
|
||||
}
|
||||
}
|
||||
DocFunction[] funcArr = (DocFunction[])funcVec.toArray(new DocFunction[funcVec.size()]);
|
||||
Arrays.sort(funcArr,new DocComparator(this));
|
||||
return funcArr;
|
||||
}
|
||||
|
||||
/** read prototypes, create them and make them parse their functions */
|
||||
private void readPrototypes() {
|
||||
File d = new File ( location );
|
||||
String pt[] = d.list();
|
||||
Vector ptVec = new Vector();
|
||||
for ( int i=0; i<pt.length; i++ ) {
|
||||
File f = new File ( d.getAbsolutePath(), pt[i] );
|
||||
if ( f.isDirectory() && DocRun.prototypeAllowed(pt[i]) ) {
|
||||
try {
|
||||
DocPrototype p = new DocPrototype(pt[i],f.getAbsolutePath(),this);
|
||||
ptVec.addElement(p);
|
||||
//break;
|
||||
} catch ( DocException e ) {
|
||||
DocRun.log( "couldn't read prototype " + pt[i] + ": " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
prototypes = (DocPrototype[])ptVec.toArray(new DocPrototype[ptVec.size()]);
|
||||
Arrays.sort(prototypes,new DocComparator(this));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ( "[DocApplication " + name + "]" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
46
src/helma/doc/DocComparator.java
Normal file
46
src/helma/doc/DocComparator.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DocComparator implements Comparator {
|
||||
|
||||
public static final int BY_TYPE = 0;
|
||||
public static final int BY_NAME = 1;
|
||||
|
||||
int mode;
|
||||
DocElement docEl;
|
||||
|
||||
public DocComparator(int mode, DocElement docEl) {
|
||||
this.mode = mode;
|
||||
this.docEl = docEl;
|
||||
}
|
||||
|
||||
public DocComparator(DocElement docEl) {
|
||||
this.mode = 0;
|
||||
this.docEl = docEl;
|
||||
}
|
||||
|
||||
public int compare(Object obj1, Object obj2) {
|
||||
DocElement e1 = (DocElement)obj1;
|
||||
DocElement e2 = (DocElement)obj2;
|
||||
if ( mode==BY_TYPE && e1.getType()>e2.getType() )
|
||||
return 1;
|
||||
else if ( mode==BY_TYPE && e1.getType()<e2.getType() )
|
||||
return -1;
|
||||
else {
|
||||
return e1.name.compareTo(e2.name);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
DocElement el = (DocElement)obj;
|
||||
if ( el.name.equals(docEl.name) && el.getType()==docEl.getType() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
184
src/helma/doc/DocElement.java
Normal file
184
src/helma/doc/DocElement.java
Normal file
|
@ -0,0 +1,184 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class DocElement {
|
||||
|
||||
// identifiers of this element
|
||||
String name;
|
||||
int type;
|
||||
String location;
|
||||
|
||||
// comment-content
|
||||
DocTag tags[];
|
||||
String comment;
|
||||
|
||||
public static final int DOCROOT = 0;
|
||||
public static final int APPLICATION = 1;
|
||||
public static final int PROTOTYPE = 2;
|
||||
public static final int METHOD = 3;
|
||||
public static final int ACTION = 4;
|
||||
public static final int TEMPLATE = 5;
|
||||
public static final int FUNCTION = 6;
|
||||
public static final int MACRO = 7;
|
||||
public static final int SKIN = 8;
|
||||
public static final int PROPERTY = 9; // to be implemented
|
||||
|
||||
public static final String[] typeNames = {"DocRoot","Application","Prototype","Method","Action","Template","Function","Macro","Skin","Property"};
|
||||
|
||||
/** a default file that is read as comment for applications and prototypes if found in their directories */
|
||||
public static final String DOCFILENAME = "doc.html";
|
||||
|
||||
public DocElement(String name, String location, int type) throws DocException {
|
||||
if ( (new File(location)).exists()==false )
|
||||
throw new DocException( name + " not found in " + location );
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public DocElement(String name, File location, int type) throws DocException {
|
||||
if ( location.exists()==false )
|
||||
throw new DocException( name + " not found in " + location.toString() );
|
||||
this.name = name;
|
||||
this.location = location.getAbsolutePath();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/** @return the name of the element */
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
abstract public String getFullName();
|
||||
|
||||
/** @return absolute path to location of element (directory for apps and prototypes, file for methods) */
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public boolean isApplication() { return (type==APPLICATION)?true:false; }
|
||||
public boolean isPrototype() { return (type==PROTOTYPE)?true:false; }
|
||||
public boolean isMethod() { if ( type>=METHOD && type<=SKIN ) return true; else return false; }
|
||||
public boolean isAction() { return (type==ACTION)?true:false; }
|
||||
public boolean isTemplate() { return (type==TEMPLATE)?true:false; }
|
||||
public boolean isFunction() { return (type==FUNCTION)?true:false; }
|
||||
public boolean isMacro() { return (type==MACRO)?true:false; }
|
||||
public boolean isSkin() { return (type==SKIN)?true:false; }
|
||||
|
||||
public int getType() { return type; }
|
||||
public String getTypeName() { return typeNames[type]; }
|
||||
|
||||
public String getDocFileName() { return (typeNames[type] + "_" + name).toLowerCase() + ".html"; }
|
||||
|
||||
/** @return the text of the comment */
|
||||
public String getComment() { return (comment!=null)?comment:""; }
|
||||
|
||||
public int countTags() { return countTags(-1); }
|
||||
public int countTags(int kind) {
|
||||
int ct=0;
|
||||
for ( int i=0; i<tags.length; i++ ) {
|
||||
if ( kind==-1 || tags[i].getKind()==kind ) {
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
public DocTag[] listTags() { return listTags(-1); }
|
||||
/** @return an array of tags that should get a special format
|
||||
* expects a -1 if it should retrieve all tags! */
|
||||
public DocTag[] listTags(int kind) {
|
||||
Vector vec = new Vector();
|
||||
for ( int i=0; i<tags.length; i++ ) {
|
||||
if ( kind==-1 || tags[i].getKind()==kind ) {
|
||||
vec.addElement(tags[i]);
|
||||
}
|
||||
}
|
||||
DocTag[] dt = (DocTag[])vec.toArray(new DocTag[vec.size()]);
|
||||
return dt;
|
||||
}
|
||||
|
||||
/** parse rawComment, render DocTags */
|
||||
void parseComment(String rawComment) {
|
||||
try {
|
||||
// get rid of java comment tags (delimiter "/**")
|
||||
int beg = rawComment.indexOf("/*");
|
||||
beg = ( beg<0 ) ? beg=0 : beg+3;
|
||||
int end = rawComment.indexOf("*/");
|
||||
end = ( end<0 ) ? rawComment.length()-1 : end;
|
||||
end = ( end<0 ) ? 0 : end;
|
||||
rawComment = rawComment.substring(beg,end).trim();
|
||||
// separate comment from tags:
|
||||
StringBuffer commentBuf = new StringBuffer();
|
||||
StringBuffer tagBuf = new StringBuffer();
|
||||
boolean switched = false;
|
||||
StringTokenizer tok = new StringTokenizer(rawComment,"\n");
|
||||
while(tok.hasMoreTokens() ) {
|
||||
String line = tok.nextToken().trim();
|
||||
if ( line.startsWith("*") )
|
||||
line = line.substring(1).trim();
|
||||
if ( line.length()==0 ) continue;
|
||||
if ( line.startsWith("@") && switched==false )
|
||||
switched=true;
|
||||
if ( switched==true )
|
||||
tagBuf.append(line + "\n" );
|
||||
else
|
||||
commentBuf.append(line + "\n" );
|
||||
}
|
||||
comment = commentBuf.toString();
|
||||
// now create taglist:
|
||||
tok = new StringTokenizer(tagBuf.toString(),"@");
|
||||
tags = new DocTag[tok.countTokens()];
|
||||
int i = 0;
|
||||
while(tok.hasMoreTokens() ) {
|
||||
tags[i++] = new DocTag(tok.nextToken().trim());
|
||||
}
|
||||
} catch ( DocException e ) {
|
||||
DocRun.log("parse error in " + location + ": " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/** read properties file (app.props || type.props), format of comments has to be discussed! */
|
||||
static Properties readPropertiesFile(String filename) throws DocException {
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new FileInputStream(filename));
|
||||
} catch ( IOException e ) {
|
||||
DocRun.log("couldn't read file: " + e.getMessage() );
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
void checkCommentFile() throws DocException {
|
||||
File f = new File (location, DOCFILENAME );
|
||||
if ( f.exists() ) {
|
||||
String rawComment = readAFile(f.getAbsolutePath());
|
||||
parseComment(rawComment);
|
||||
} else {
|
||||
comment = "";
|
||||
tags = new DocTag[0];
|
||||
}
|
||||
}
|
||||
|
||||
/** read a complete file into a string */
|
||||
public static String readAFile(String str) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(new File(str)));
|
||||
String line = in.readLine();
|
||||
while(line!=null) {
|
||||
buf.append(line+"\n");
|
||||
line = in.readLine();
|
||||
}
|
||||
return ( buf.toString() );
|
||||
} catch ( IOException e ) {
|
||||
return ("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
16
src/helma/doc/DocException.java
Normal file
16
src/helma/doc/DocException.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package helma.doc;
|
||||
|
||||
public class DocException extends Exception {
|
||||
|
||||
String str;
|
||||
|
||||
public DocException (String str) {
|
||||
super (str);
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
82
src/helma/doc/DocFunction.java
Normal file
82
src/helma/doc/DocFunction.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class DocFunction extends DocElement {
|
||||
|
||||
public static final String[] typeSuffix = {"_action","_as_string","","_macro",""};
|
||||
|
||||
private DocPrototype prototype;
|
||||
private String source;
|
||||
|
||||
public DocFunction( String name, String location, int type, DocPrototype prototype, String rawComment ) throws DocException {
|
||||
super(name,location, type);
|
||||
this.prototype = prototype;
|
||||
parseComment(rawComment);
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
switch(type) {
|
||||
case ACTION: return ( "Action " + name );
|
||||
case TEMPLATE: return ( "Template " + name );
|
||||
case FUNCTION: return ( "Function " + name );
|
||||
case MACRO: return ( "Macro " + name );
|
||||
case SKIN: return ( "Skin" + name );
|
||||
}
|
||||
return ( "Method " + name );
|
||||
}
|
||||
|
||||
public DocPrototype getPrototype() { return prototype; }
|
||||
|
||||
public void readSource(String sourceFile, int beginLine, int beginColumn, int endLine, int endColumn ) {
|
||||
StringBuffer buf = new StringBuffer ();
|
||||
int ct=0;
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(sourceFile));
|
||||
String line="";
|
||||
while ( line!=null ) {
|
||||
line = in.readLine();
|
||||
if ( line==null ) break;
|
||||
ct++;
|
||||
if ( ct==beginLine )
|
||||
buf.append(line.substring(beginColumn-1, line.length())+"\n");
|
||||
else if ( ct>beginLine && ct<endLine )
|
||||
buf.append(line+"\n");
|
||||
else if ( ct==endLine )
|
||||
buf.append(line.substring(0,endColumn));
|
||||
}
|
||||
} catch ( FileNotFoundException e ) {
|
||||
} catch ( StringIndexOutOfBoundsException e ) {
|
||||
} catch ( IOException e ) {
|
||||
DocRun.log(e.getMessage());
|
||||
}
|
||||
source = buf.toString();
|
||||
}
|
||||
|
||||
public void readSource(String sourceFile) {
|
||||
StringBuffer buf = new StringBuffer ();
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(sourceFile));
|
||||
String line="";
|
||||
while ( line!=null ) {
|
||||
line = in.readLine();
|
||||
if ( line==null ) break;
|
||||
buf.append(line+"\n");
|
||||
}
|
||||
} catch ( FileNotFoundException e ) {
|
||||
} catch ( IOException e ) {
|
||||
DocRun.log(e.getMessage());
|
||||
}
|
||||
source = buf.toString();
|
||||
}
|
||||
|
||||
public void setSource(String source) { this.source = source; }
|
||||
public String getSource() { return (source!=null)?source:""; }
|
||||
|
||||
public String toString() {
|
||||
return ( "[DocFunction " + getTypeName() + " " + name + "]" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
328
src/helma/doc/DocHtmlWriter.java
Normal file
328
src/helma/doc/DocHtmlWriter.java
Normal file
|
@ -0,0 +1,328 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import helma.util.*;
|
||||
|
||||
public class DocHtmlWriter extends PrintWriter {
|
||||
|
||||
public static DocApplication app;
|
||||
|
||||
public static final int APPLICATION = 0;
|
||||
public static final int PROTOTYPE = 1;
|
||||
public static final int INDEX = 2;
|
||||
public static final int METHOD = 3;
|
||||
|
||||
public DocHtmlWriter(String filename) throws FileNotFoundException {
|
||||
super(new FileOutputStream(filename));
|
||||
}
|
||||
|
||||
public void printHeader( String title ) { printHeader(title,false); }
|
||||
|
||||
/** print header, slightly different for frameset file **/
|
||||
public void printHeader( String title, boolean frameset ) {
|
||||
if ( frameset==true )
|
||||
print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\"\"http://www.w3.org/TR/REC-html40/frameset.dtd\">");
|
||||
else
|
||||
print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">");
|
||||
print("<HTML><HEAD>");
|
||||
print("<!-- Generated by helmadoc on " + (new Date()).toString() + " -->");
|
||||
println("<TITLE>" + title + "</TITLE>");
|
||||
if ( frameset==true )
|
||||
print("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"stylesheet.css\" TITLE=Style>");
|
||||
println("</HEAD>");
|
||||
}
|
||||
|
||||
|
||||
public void printFrameSet() {
|
||||
println ("<FRAMESET cols=\"20%,80%\">");
|
||||
println ("<FRAME src=\"app-frame.html\" name=appFrame>");
|
||||
println ("<FRAME src=\"app.html\" name=prototypeFrame>");
|
||||
println ("</FRAMESET><NOFRAMES>sorry, your browser doesn't understand frames!</NOFRAMES></HTML>");
|
||||
}
|
||||
|
||||
/** print app title for left frame */
|
||||
public void printAppIndexTitle(String title) {
|
||||
print("<table border=0 width=\"100%\"><tr><td nowrap>");
|
||||
print("<FONT size=+1 ID=FrameTitleFont><b>");
|
||||
print("Application " + title + "</b></font></td></tr></table>" );
|
||||
}
|
||||
|
||||
/** print prototype list for left frame */
|
||||
public void printAppIndexList(DocElement[] pt) {
|
||||
print("<TABLE BORDER=0 WIDTH=\"100%\"><TR><TD NOWRAP>");
|
||||
print("<P><FONT size=+1 ID=FrameHeadingFont>Prototypes</FONT><BR><BR>");
|
||||
for ( int i=0; i<pt.length; i++ ) {
|
||||
print ("<FONT ID=FrameItemFont><A HREF=\"" + pt[i].getDocFileName() + "\" TARGET=prototypeFrame>" + pt[i].getName() + "</A></FONT><BR>");
|
||||
}
|
||||
print ("</TD></TR></TABLE>");
|
||||
}
|
||||
|
||||
/** navigation on top of the page **/
|
||||
public void printNavBar(String name, DocPrototype pt, int page ) {
|
||||
String urlPrefix = ( page==METHOD ) ? "../" : "";
|
||||
print("<!-- ========== START OF NAVBAR ========== -->");
|
||||
print("<A NAME=navbar_top><!-- --></A>");
|
||||
print("<TABLE BORDER=0 WIDTH=100% CELLPADDING=1 CELLSPACING=0>");
|
||||
print("<TR><TD COLSPAN=2 BGCOLOR=#EEEEFF ID=NavBarCell1>");
|
||||
print("<A NAME=navbar_top_firstrow><!-- --></A>");
|
||||
|
||||
print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=3>");
|
||||
print("<TR ALIGN=center VALIGN=top>");
|
||||
if ( page==APPLICATION )
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1Rev><FONT ID=NavBarFont1Rev><B>Application</B></FONT> </TD>");
|
||||
else
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1><A HREF=\"" + urlPrefix + "app.html\"><FONT ID=NavBarFont1><B>Application</B></FONT></A> </TD>");
|
||||
if ( page==PROTOTYPE )
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1Rev> <FONT ID=NavBarFont1Rev><B>Prototype</B></FONT> </TD>");
|
||||
else if ( page==METHOD )
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1> <a href=\"" + urlPrefix + "prototype_" + pt.getName() + ".html\"><FONT ID=NavBarFont1><B>Prototype</B></A></FONT> </TD>");
|
||||
else
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1> <FONT ID=NavBarFont1><B>Prototype</B></FONT> </TD>");
|
||||
if ( page==INDEX )
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1Rev><FONT ID=NavBarFont1><B>Index</B></FONT> </TD>");
|
||||
else
|
||||
print("<TD BGCOLOR=#EEEEFF ID=NavBarCell1><A HREF=\"" + urlPrefix + "index-1.html\"><FONT ID=NavBarFont1><B>Index</B></FONT></A> </TD>");
|
||||
print("</TR></TABLE>");
|
||||
|
||||
print("</TD><TD ALIGN=right VALIGN=top ROWSPAN=3><EM><b>Application " + name + "</b><br><font size=-1></font></EM>");
|
||||
print("</TD></TR>");
|
||||
if ( pt!=null && page!=METHOD ) {
|
||||
print("<TR><TD VALIGN=top ID=NavBarCell3><FONT SIZE=-2>");
|
||||
print("<a href=\"#Actions\">ACTIONS</a> | ");
|
||||
print("<a href=\"#Templates\">TEMPLATES</a> | ");
|
||||
print("<a href=\"#Functions\">FUNCTIONS</a> | ");
|
||||
print("<a href=\"#Macros\">MACROS</a> | ");
|
||||
print("<a href=\"#Skins\">SKINS</a> ");
|
||||
print("</TD></TR>");
|
||||
}
|
||||
|
||||
print("</TABLE>");
|
||||
print("<!-- =========== END OF NAVBAR =========== -->");
|
||||
}
|
||||
|
||||
public void printElementTitle(DocElement docEl) {
|
||||
print("<HR><H2>" + docEl.getName() + "<BR>");
|
||||
print(docEl.getFullName() + "</H2>");
|
||||
print("<HR>");
|
||||
}
|
||||
|
||||
public void printComment(DocElement docEl) {
|
||||
if( docEl.getComment().length()>0 || docEl.countTags()>0 ) {
|
||||
print("<DL><DT>" + docEl.getComment() + "</DT>");
|
||||
print("<DT>");
|
||||
for ( int i=0; i<DocTag.TYPE_COUNT; i++ ) {
|
||||
if ( docEl.countTags(i)>0 ) {
|
||||
print("<DT><b>" + DocTag.kindDesc[i] + "</b><DT>");
|
||||
DocTag[] dt = docEl.listTags(i);
|
||||
for ( int j=0; j<dt.length; j++ ) {
|
||||
print("<DD>" + renderTag(dt[j],j) + "</DD>");
|
||||
}
|
||||
}
|
||||
}
|
||||
print("</DL>");
|
||||
}
|
||||
}
|
||||
|
||||
private String renderFunctionName(DocFunction func) {
|
||||
StringBuffer buf = new StringBuffer ();
|
||||
buf.append("<CODE><B>");
|
||||
if ( DocRun.getOption("-f").equals("true") )
|
||||
buf.append("<a href=\"" + func.getPrototype().getName().toLowerCase()+"/"+func.getDocFileName() + "\">" );
|
||||
if ( func.isMacro() ) {
|
||||
buf.append( func.getPrototype().getName()+"."+func.getName().substring(0,func.getName().length()-6) );
|
||||
} else {
|
||||
buf.append(func.getName().trim());
|
||||
if( func.isTemplate() || func.isFunction() ) {
|
||||
buf.append("(");
|
||||
int ct = func.countTags(DocTag.ARG);
|
||||
for ( int i=0; i<ct; i++ ) {
|
||||
buf.append("arg"+i);
|
||||
if ( i<ct-1 )
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(")");
|
||||
}
|
||||
}
|
||||
buf.append("</a></B></CODE>");
|
||||
if ( func.isFunction() || func.isMacro() )
|
||||
buf.append(" <small><i>in " + (new File(func.getLocation())).getName() + "</i></small>" );
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private String renderTag(DocTag tag) {
|
||||
return renderTag(tag,0);
|
||||
}
|
||||
|
||||
private String renderTag(DocTag tag, int i) {
|
||||
int kind = tag.getKind();
|
||||
String text = tag.getText();
|
||||
String name = tag.getName();
|
||||
switch (kind) {
|
||||
case DocTag.ARG:
|
||||
return( "<b>arg" + i + ":</b> " + text );
|
||||
case DocTag.PARAM:
|
||||
return( "<b>" + name + "</b> " + text );
|
||||
case DocTag.RETURNS:
|
||||
case DocTag.AUTHOR:
|
||||
case DocTag.VERSION:
|
||||
case DocTag.RELEASE:
|
||||
return( text );
|
||||
case DocTag.SEE:
|
||||
if ( text.startsWith("http://") ) {
|
||||
StringTokenizer tok = new StringTokenizer (text.trim()," ");
|
||||
String url = (tok.countTokens()>1)?tok.nextToken():text;
|
||||
return( "<a href=\"" + url + "\">" + ((tok.countTokens()>0)?text.substring(url.length(),text.length()):text) + "</a>" );
|
||||
} else {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringTokenizer tok = new StringTokenizer (text.trim(),".");
|
||||
if ( tok.countTokens()==0 ) return text;
|
||||
DocPrototype dp = app.getPrototype( tok.nextToken() );
|
||||
if ( dp==null ) return text;
|
||||
buf.append("<a href=\"" );
|
||||
DocFunction df = null;
|
||||
if ( tok.countTokens()>0 )
|
||||
df = dp.getFunction( tok.nextToken() );
|
||||
if ( df==null )
|
||||
buf.append( link(dp) + "\">" + dp.getName() );
|
||||
else
|
||||
buf.append( link(df) + "\">" + dp.getName() + "." + df.getName() );
|
||||
return(buf.toString()+"</a>");
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public void printListHeader(String title) {
|
||||
print("<A NAME=\"" + title + "\"><!-- --></A>");
|
||||
print("<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>");
|
||||
print("<TR BGCOLOR=#CCCCFF ID=TableHeadingColor><TD COLSPAN=2><FONT SIZE=+2><B>" + title + "</B></FONT></TD></TR>");
|
||||
}
|
||||
|
||||
public void printPrototypeList(DocPrototype[] dl, String title) {
|
||||
if ( dl.length==0 ) return;
|
||||
printListHeader(title);
|
||||
for ( int i=0; i<dl.length; i++ ) {
|
||||
print("<TR BGCOLOR=white ID=TableRowColor><TD ALIGN=right VALIGN=top WIDTH=1%><FONT SIZE=-1>");
|
||||
print("<a name=\"" + dl[i].getName() + "\"><!-- --></a>");
|
||||
print("<CODE> " + dl[i].getTypeName() + "</CODE></FONT></TD>");
|
||||
print("<TD><CODE><B><A HREF=\"" + dl[i].getDocFileName() + "\">" + dl[i].getName() + "</A></B></CODE>");
|
||||
print("<BR> " + dl[i].getComment() + "<br>" );
|
||||
print("</TD></TR>");
|
||||
}
|
||||
print("</TABLE><BR>");
|
||||
}
|
||||
|
||||
public void printFunctionList(DocFunction[] dl, String title) {
|
||||
if ( dl.length==0 ) return;
|
||||
printListHeader(title);
|
||||
for ( int i=0; i<dl.length; i++ ) {
|
||||
print("<TR BGCOLOR=white ID=TableRowColor>");
|
||||
print("<TD ALIGN=right VALIGN=top WIDTH=50><FONT SIZE=-1>");
|
||||
print("<a name=\"" + dl[i].getName() + "\"><!-- --></a>");
|
||||
print("<CODE> " + dl[i].getTypeName() + "</CODE></FONT></TD>");
|
||||
print("<TD><DL><DT>" + renderFunctionName(dl[i]) );
|
||||
print("<DT>");
|
||||
printComment(dl[i]);
|
||||
print("</DL></TD></TR>");
|
||||
}
|
||||
print("</TABLE><BR>");
|
||||
}
|
||||
|
||||
public void printFunctionIndex(DocFunction[] dl) {
|
||||
if ( dl.length==0 ) return;
|
||||
String curChar = " ";
|
||||
print("<DL>");
|
||||
for ( int i=0; i<dl.length; i++ ) {
|
||||
String name = dl[i].getName();
|
||||
if ( !name.toLowerCase().startsWith(curChar) ) {
|
||||
print ( "</DL><h2>" + name.substring(0,1).toUpperCase() + "</h2><dl>");
|
||||
curChar = name.substring(0,1).toLowerCase();
|
||||
}
|
||||
print("<DT><a href=\"" + link(dl[i]) + "\">" + dl[i].getName() + "</a> - " + dl[i].getTypeName() + " in <a href=\"" + link(dl[i].getPrototype()) + "\">" + dl[i].getPrototype().getName() + "</a>" );
|
||||
}
|
||||
print("</DL>");
|
||||
}
|
||||
|
||||
public void printInheritance(DocPrototype pt) {
|
||||
if ( pt.getName().equalsIgnoreCase("hopobject") )
|
||||
return;
|
||||
DocApplication app = pt.getApplication();
|
||||
DocPrototype hopobject = (DocPrototype)app.getPrototype("hopobject");
|
||||
if ( hopobject==null || hopobject.countFunctions()==0 )
|
||||
return;
|
||||
print("<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>");
|
||||
print("<TR BGCOLOR=\"#EEEEFF\" CLASS=TableSubHeadingColor>");
|
||||
print("<TD><B>Methods inherited from Prototype <a href=\"" + link(hopobject) + "\">hopobject</A></B></TD>");
|
||||
print("</TR>");
|
||||
print("<TR BGCOLOR=\"white\" CLASS=TableRowColor><TD><code>");
|
||||
DocFunction[] df = hopobject.listFunctions();
|
||||
|
||||
int lastType = -1;
|
||||
StringBuffer buf1 = new StringBuffer();
|
||||
StringBuffer buf2 = new StringBuffer();
|
||||
|
||||
for ( int i=0; i<df.length; i++ ) {
|
||||
if ( df[i].getType()!=lastType && i>0 && buf2.length()>0 ) {
|
||||
buf1.append("<b>" + DocElement.typeNames[lastType] + ":</b> <code>" );
|
||||
buf1.append( buf2.toString().substring(0, buf2.toString().length()-2) );
|
||||
buf1.append("</code><br>");
|
||||
buf2 = new StringBuffer();
|
||||
}
|
||||
lastType = df[i].getType();
|
||||
buf2.append ( "<a href=\"" + link(df[i]) + "\">" + df[i].getName() + "</a>, " );
|
||||
}
|
||||
if ( buf2.length()>0 ) {
|
||||
buf1.append("<b>" + DocElement.typeNames[lastType] + ":</b> <code>" );
|
||||
buf1.append( buf2.toString().substring(0, buf2.toString().length()-2) );
|
||||
buf1.append("</code><br>");
|
||||
}
|
||||
print ( buf1.toString() );
|
||||
print("</TR></TABLE>");
|
||||
}
|
||||
|
||||
public void printFunction(DocFunction func) {
|
||||
print( "<br><br><small><i>in " + func.getPrototype().getName() + "/" + (new File(func.getLocation())).getName() + ":</i></small>" );
|
||||
print( "<br><pre>");
|
||||
print( HtmlEncoder.encodeAll(func.getSource()) );
|
||||
print( "</pre>" );
|
||||
}
|
||||
|
||||
public void printStyleSheet() {
|
||||
println( "/* Javadoc style sheet */");
|
||||
println( "/* Define colors, fonts and other style attributes here to override the defaults */");
|
||||
println( "* Page background color */");
|
||||
println( "body { background-color: #FFFFFF }");
|
||||
println( "/* Table colors */");
|
||||
println( "#TableHeadingColor { background: #CCCCFF } /* Dark mauve */");
|
||||
println( "#TableSubHeadingColor { background: #EEEEFF } /* Light mauve */");
|
||||
println( "#TableRowColor { background: #FFFFFF } /* White */");
|
||||
println( "/* Font used in left-hand frame lists */");
|
||||
println( "#FrameTitleFont { font-size: normal; font-family: normal }");
|
||||
println( "#FrameHeadingFont { font-size: normal; font-family: normal }");
|
||||
println( "#FrameItemFont { font-size: normal; font-family: normal }");
|
||||
println( "/* Example of smaller, sans-serif font in frames */");
|
||||
println( "/* #FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */");
|
||||
println( "/* Navigation bar fonts and colors */");
|
||||
println( "#NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */");
|
||||
println( "#NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */");
|
||||
println( "#NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;}");
|
||||
println( "#NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;}");
|
||||
println( "#NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}");
|
||||
println( "#NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}");
|
||||
}
|
||||
|
||||
public String link(DocElement docEl) {
|
||||
if ( docEl.isPrototype() ) {
|
||||
return "prototype_" + docEl.getName() + ".html";
|
||||
} else if ( docEl.isMethod() ) {
|
||||
DocFunction df = (DocFunction)docEl;
|
||||
return "prototype_" + df.getPrototype().getName() + ".html#" + df.getName();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
192
src/helma/doc/DocPrototype.java
Normal file
192
src/helma/doc/DocPrototype.java
Normal file
|
@ -0,0 +1,192 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import FESI.Parser.*;
|
||||
|
||||
|
||||
public class DocPrototype extends DocElement {
|
||||
|
||||
DocFunction[] functions;
|
||||
DocApplication app;
|
||||
|
||||
public DocPrototype( String name, String location, DocApplication app ) throws DocException {
|
||||
super( name, location, PROTOTYPE );
|
||||
this.app = app;
|
||||
if ( name.equals("hopobject")==false && name.equals("global")==false )
|
||||
readPropertiesFile( new File(location,"type.properties").getAbsolutePath());
|
||||
checkCommentFile();
|
||||
readFunctions();
|
||||
}
|
||||
|
||||
public String getFullName() { return ( "Prototype " + name ); }
|
||||
|
||||
/** return number of functions */
|
||||
public int countFunctions() { return functions.length; }
|
||||
|
||||
/** return array of functions of a special type */
|
||||
public int countFunctions(int type) {
|
||||
int ct = 0;
|
||||
for ( int i=0; i<functions.length; i++ ) {
|
||||
if ( functions[i].getType()==type ) {
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
return ct;
|
||||
}
|
||||
|
||||
/** return a single function */
|
||||
public DocFunction getFunction(String name) {
|
||||
for ( int i=0; i<functions.length; i++ ) {
|
||||
if ( functions[i].getName().equals(name) )
|
||||
return functions[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** return array of functions */
|
||||
public DocFunction[] listFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
/** return array of functions of a special type */
|
||||
public DocFunction[] listFunctions(int type) {
|
||||
Vector funcVec = new Vector();
|
||||
for ( int i=0; i<functions.length; i++ ) {
|
||||
if ( functions[i].getType()==type ) {
|
||||
funcVec.addElement(functions[i]);
|
||||
}
|
||||
}
|
||||
return (DocFunction[])funcVec.toArray(new DocFunction[funcVec.size()]);;
|
||||
}
|
||||
|
||||
|
||||
/** return the application */
|
||||
public DocApplication getApplication() { return app; }
|
||||
|
||||
|
||||
/** create the function list & read all valid files */
|
||||
private void readFunctions() {
|
||||
DocRun.debug("parsing Prototype " + name + " using " + location );
|
||||
String files[] = (new File(location)).list();
|
||||
Vector funcVec = new Vector();;
|
||||
for ( int i=0; i<files.length; i++ ) {
|
||||
DocRun.debug("reading " + files[i] );
|
||||
try {
|
||||
if ( files[i].endsWith(DocRun.actionExtension) ) {
|
||||
readAction(new File(location,files[i]).getAbsolutePath(),funcVec);
|
||||
} else if ( files[i].endsWith(DocRun.scriptExtension) ) {
|
||||
readFunctionFile(new File(location,files[i]).getAbsolutePath(),funcVec);
|
||||
} else if ( files[i].endsWith(DocRun.templateExtension) ) {
|
||||
readTemplate(new File(location,files[i]).getAbsolutePath(),funcVec);
|
||||
} else if ( files[i].endsWith(DocRun.skinExtension) ) {
|
||||
readSkin(new File(location,files[i]).getAbsolutePath(),funcVec);
|
||||
}
|
||||
} catch ( DocException e ) {
|
||||
DocRun.log ( "couldn't read function " + name + "." + files[i] + ": " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
functions = (DocFunction[])funcVec.toArray(new DocFunction[funcVec.size()]);
|
||||
DocRun.debug( name + " has " + functions.length + " functions" );
|
||||
Arrays.sort(functions,new DocComparator(this));
|
||||
}
|
||||
|
||||
private void readAction(String f, Vector funcVec) throws DocException {
|
||||
EcmaScriptTokenManager mgr = createTokenManager(new File(f));
|
||||
Token tok = mgr.getNextToken();
|
||||
DocFunction func = new DocFunction( fileToFuncName(f), f, DocElement.ACTION, this, getCommentFromToken(tok) );
|
||||
func.readSource(f);
|
||||
funcVec.addElement( func );
|
||||
}
|
||||
|
||||
private void readFunctionFile(String f, Vector funcVec) throws DocException {
|
||||
EcmaScriptTokenManager mgr = createTokenManager(new File(f));
|
||||
Token tok = mgr.getNextToken();
|
||||
while( tok.kind!=0 ) {
|
||||
if( tok.kind == EcmaScriptConstants.FUNCTION ) {
|
||||
int beginLine = tok.beginLine;
|
||||
int beginColumn = tok.beginColumn;
|
||||
String funcName = mgr.getNextToken().toString();
|
||||
DocFunction func;
|
||||
if ( funcName.endsWith("_macro") )
|
||||
func = new DocFunction( funcName, f, DocElement.MACRO, this, getCommentFromToken(tok) );
|
||||
else
|
||||
func = new DocFunction( funcName, f, DocElement.FUNCTION, this, getCommentFromToken(tok) );
|
||||
funcVec.addElement(func);
|
||||
|
||||
tok = mgr.getNextToken();
|
||||
int endLine=0, endColumn=0;
|
||||
while( tok.kind!=0 && tok.kind!=EcmaScriptConstants.FUNCTION ) {
|
||||
endLine = tok.endLine;
|
||||
endColumn = tok.endColumn;
|
||||
tok = mgr.getNextToken();
|
||||
}
|
||||
func.readSource(f,beginLine,beginColumn,endLine,endColumn);
|
||||
//DocRun.log("going from " + beginLine +"." + beginColumn + " to " + endLine + "." + endColumn );
|
||||
//DocRun.log("============================here starts a new one");
|
||||
}
|
||||
if ( tok.kind!=0 && tok.kind!=EcmaScriptConstants.FUNCTION )
|
||||
tok = mgr.getNextToken();
|
||||
}
|
||||
}
|
||||
|
||||
private void readTemplate(String f, Vector funcVec) throws DocException {
|
||||
String content = readAFile(f);
|
||||
// get the first scripting zone and tokenize it
|
||||
DocFunction func;
|
||||
try {
|
||||
StringReader str = new StringReader( content.substring(content.indexOf("<%")+2,content.indexOf("%>")) );
|
||||
EcmaScriptTokenManager mgr = new EcmaScriptTokenManager(new ASCII_CharStream(str,1,1),0);
|
||||
Token tok = mgr.getNextToken();
|
||||
func = new DocFunction( fileToFuncName(f), f, DocElement.TEMPLATE, this, getCommentFromToken(tok) );
|
||||
} catch ( IndexOutOfBoundsException e ) {
|
||||
func = new DocFunction( fileToFuncName(f), f, DocElement.TEMPLATE, this, "" );
|
||||
}
|
||||
func.setSource(content);
|
||||
funcVec.addElement(func);
|
||||
}
|
||||
|
||||
private void readSkin(String f, Vector funcVec) throws DocException {
|
||||
// can't be commented yet
|
||||
// simply add them
|
||||
DocFunction func = new DocFunction(fileToFuncName(f),f,DocElement.SKIN, this,"");
|
||||
func.readSource(f);
|
||||
funcVec.addElement(func);
|
||||
}
|
||||
|
||||
|
||||
/** create token manager for a file */
|
||||
private EcmaScriptTokenManager createTokenManager(File f) {
|
||||
try {
|
||||
ASCII_CharStream is = new ASCII_CharStream(new FileReader(f), 1, 1);
|
||||
EcmaScriptTokenManager mgr = new EcmaScriptTokenManager(is,0);
|
||||
return mgr;
|
||||
} catch ( FileNotFoundException shouldnotappear ) { }
|
||||
return null;
|
||||
}
|
||||
|
||||
/** connect all available specialTokens */
|
||||
private String getCommentFromToken(Token tok) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while( tok.specialToken!=null ) {
|
||||
buf.append(tok.specialToken.toString() );
|
||||
tok = tok.specialToken;
|
||||
}
|
||||
return ( buf.toString().trim() );
|
||||
}
|
||||
|
||||
private String fileToFuncName(String f) {
|
||||
return fileToFuncName(new File(f));
|
||||
}
|
||||
|
||||
private String fileToFuncName(File f) {
|
||||
String tmp = f.getName();
|
||||
return tmp.substring(0,tmp.indexOf("."));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ( "[DocPrototype " + name + "]" );
|
||||
}
|
||||
|
||||
}
|
||||
|
138
src/helma/doc/DocRun.java
Normal file
138
src/helma/doc/DocRun.java
Normal file
|
@ -0,0 +1,138 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import helma.objectmodel.*;
|
||||
|
||||
public class DocRun {
|
||||
|
||||
public static String propfile;
|
||||
public static SystemProperties sysProps, dbProps;
|
||||
public static String actionExtension;
|
||||
public static String scriptExtension;
|
||||
public static String templateExtension;
|
||||
public static String skinExtension = ".skin";
|
||||
|
||||
public static String hopHomeDir;
|
||||
|
||||
private static Hashtable options;
|
||||
|
||||
String appName;
|
||||
DocApplication app;
|
||||
|
||||
public static void main ( String args[] ) {
|
||||
boolean usageError = false;
|
||||
// parse options from command line
|
||||
options = new Hashtable();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
String name = "";
|
||||
for ( int i=0; i<args.length; i++ ) {
|
||||
if ( args[i].startsWith("-") ) {
|
||||
if ( i>0 ) {
|
||||
if ( buf.toString().length()==0 )
|
||||
usageError = true;
|
||||
else
|
||||
options.put(name,buf.toString() );
|
||||
}
|
||||
name = args[i];
|
||||
buf = new StringBuffer();
|
||||
} else {
|
||||
buf.append( ( (buf.toString().length()>0) ? " ":"" ) + args[i]);
|
||||
}
|
||||
}
|
||||
options.put(name,buf.toString()); // include last option
|
||||
// now check parameter
|
||||
if ( options.containsKey("-h") ) {
|
||||
hopHomeDir = (String)options.get("-h");
|
||||
} else {
|
||||
hopHomeDir = System.getProperty("user.dir");
|
||||
}
|
||||
readHopProperties(hopHomeDir);
|
||||
String parAppDir = "";
|
||||
if ( options.containsKey("-a") ) {
|
||||
parAppDir = (String)options.get("-a");
|
||||
} else {
|
||||
usageError = true;
|
||||
}
|
||||
if ( usageError==true ) {
|
||||
help();
|
||||
System.exit(0);
|
||||
}
|
||||
try {
|
||||
new DocRun(parAppDir);
|
||||
} catch ( DocException e ) {
|
||||
System.out.println("doc error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void help() {
|
||||
System.out.println ("usage: java helma.doc.DocApplication -a appdir [-f] [-h hopdir] [-d docdir] [-i ignore]");
|
||||
System.out.println (" -a appdir Specify source directory");
|
||||
System.out.println (" -h hopdir Specify hop home directory");
|
||||
System.out.println (" -d docdir Specify destination directory");
|
||||
System.out.println (" -f true Link functions to source code");
|
||||
System.out.println (" -i ignore Specify prototypes to ignore (like: \"-i CVS mistsack\")");
|
||||
System.out.println (" -debug");
|
||||
System.out.println ("\n");
|
||||
}
|
||||
|
||||
public static boolean prototypeAllowed(String name) {
|
||||
String ig = " " + getOption("-i").toLowerCase() + " ";
|
||||
if ( ig.equals("") ) return true;
|
||||
name = name.toLowerCase();
|
||||
if ( ig.indexOf(" "+name+" ")>-1 )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads server.properties, apps.properties and db.properties from hop-home-directory
|
||||
* TBD: should be cleaned up to work exactly like the helma server
|
||||
* @param homeDir hop-home-directory with server.properties-file
|
||||
*/
|
||||
public static void readHopProperties(String hopHomeDir) {
|
||||
propfile = new File (hopHomeDir, "server.properties").getAbsolutePath();
|
||||
sysProps = new SystemProperties (propfile);
|
||||
dbProps = new SystemProperties ( new File(hopHomeDir,"db.properties").getAbsolutePath() );
|
||||
actionExtension = sysProps.getProperty("actionExtension",".hac");
|
||||
scriptExtension = sysProps.getProperty("scriptExtension",".js");
|
||||
templateExtension = sysProps.getProperty("templateExtension",".hsp");
|
||||
}
|
||||
|
||||
public DocRun (String appDir) throws DocException {
|
||||
File d = new File(appDir);
|
||||
if ( !d.exists() )
|
||||
throw new DocException( d.toString() + " doesn't exist");
|
||||
if ( !d.isDirectory() )
|
||||
throw new DocException( d.toString() + " is not a directory");
|
||||
log ( "parsing application " + d.getName() + " located in " + d.getAbsolutePath() );
|
||||
log ( "writing output to " + getOption("-d", new File(hopHomeDir,"/appdocs/"+d.getName()).getAbsolutePath()) );
|
||||
app = new DocApplication(d.getName(),d.getAbsolutePath() );
|
||||
DocWriter.start( getOption("-d", new File(hopHomeDir,"/appdocs/"+d.getName()).getAbsolutePath()), app);
|
||||
}
|
||||
|
||||
public static String getOption(String name) {
|
||||
return getOption(name,"");
|
||||
}
|
||||
|
||||
public static String getOption(String name, String def) {
|
||||
if ( options.containsKey(name) )
|
||||
return(String)options.get(name);
|
||||
else
|
||||
return(def);
|
||||
}
|
||||
|
||||
public static void debug(String msg) {
|
||||
if ( options.containsKey("-debug") )
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
public static void log( String msg ) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
58
src/helma/doc/DocTag.java
Normal file
58
src/helma/doc/DocTag.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DocTag {
|
||||
|
||||
public static final int ARG = 0;
|
||||
public static final int PARAM = 1;
|
||||
public static final int RETURNS = 2;
|
||||
public static final int AUTHOR = 3;
|
||||
public static final int VERSION = 4;
|
||||
public static final int RELEASE = 5;
|
||||
public static final int SEE = 6;
|
||||
|
||||
/** number of different tag-types **/
|
||||
public static final int TYPE_COUNT = 7;
|
||||
|
||||
/** constants are used as array indices! **/
|
||||
public static final String[] kindNames = {"arg","param","return","author","version","release","see"};
|
||||
public static final String[] kindDesc = {"Arguments","Parameter","Returns","Author","Version","Release","See also"};
|
||||
|
||||
private String name;
|
||||
private int kind;
|
||||
private String text;
|
||||
|
||||
public DocTag( String rawTag ) throws DocException {
|
||||
//DocRun.log(rawTag);
|
||||
try {
|
||||
StringTokenizer tok = new StringTokenizer(rawTag);
|
||||
String kindstr = tok.nextToken().toLowerCase();
|
||||
for ( int i=0; i<kindNames.length; i++ ) {
|
||||
if ( kindstr.equals(kindNames[i]) ) {
|
||||
kind = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuffer buf = new StringBuffer();
|
||||
if ( kind==PARAM ) {
|
||||
name = tok.nextToken();
|
||||
}
|
||||
while ( tok.hasMoreTokens() ) {
|
||||
buf.append( tok.nextToken() + " " );
|
||||
}
|
||||
text = buf.toString();
|
||||
} catch ( Exception e ) { }
|
||||
}
|
||||
|
||||
public String getName() { return (name!=null && !name.equals("null"))?name:""; }
|
||||
public int getKind() { return kind; }
|
||||
public String getText() { return (text!=null && !text.equals("null"))?text:""; }
|
||||
|
||||
public String toString() {
|
||||
return ( (name!=null)?name+" ":"" ) + text;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
128
src/helma/doc/DocWriter.java
Normal file
128
src/helma/doc/DocWriter.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
package helma.doc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DocWriter extends DocHtmlWriter {
|
||||
|
||||
public static String docDir;
|
||||
|
||||
public DocWriter( String filename ) throws FileNotFoundException {
|
||||
super( new File(docDir,filename).getAbsolutePath() );
|
||||
DocRun.log("creating " + filename );
|
||||
}
|
||||
|
||||
public static void start( String parDocDir, DocApplication parApp ) {
|
||||
app = parApp;
|
||||
docDir = parDocDir;
|
||||
if ( !(new File(parDocDir).exists()) ) {
|
||||
DocRun.log("creating directory " + parDocDir );
|
||||
(new File(parDocDir)).mkdirs();
|
||||
}
|
||||
printStyleSheet(app);
|
||||
printFrameSet(app);
|
||||
printAppDoc(app);
|
||||
printAppIndex(app);
|
||||
printPrototypes(app);
|
||||
printFunctionIndex(app);
|
||||
if ( DocRun.getOption("-f").equals("true") )
|
||||
printFunctions(app);
|
||||
}
|
||||
|
||||
/** print index-1.html .. alphabetical list of all functions */
|
||||
public static void printFunctionIndex(DocApplication app) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter("index-1.html");
|
||||
dw.printHeader("Application " + app.getName() );
|
||||
dw.printNavBar(app.getName(), null, INDEX );
|
||||
DocFunction[] df = app.listFunctions();
|
||||
Arrays.sort(df,new DocComparator(1,df[0]));
|
||||
dw.printFunctionIndex(df);
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
|
||||
/** print stylesheet.css */
|
||||
public static void printStyleSheet(DocApplication app) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter("stylesheet.css");
|
||||
dw.printStyleSheet();
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
|
||||
/** print index.html */
|
||||
public static void printFrameSet(DocApplication app) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter("index.html");
|
||||
dw.printHeader("Application " + app.getName() );
|
||||
dw.printFrameSet();
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
|
||||
/** print app.html, list of prototypes */
|
||||
public static void printAppDoc(DocApplication app) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter("app.html");
|
||||
dw.printHeader("Application " + app.getName() );
|
||||
dw.printNavBar(app.getName(), null, APPLICATION );
|
||||
dw.printElementTitle(app);
|
||||
dw.printComment(app);
|
||||
dw.printPrototypeList(app.listPrototypes(),"Prototypes");
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
|
||||
/** print app-frame.html, content of left frame */
|
||||
public static void printAppIndex(DocApplication app) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter("app-frame.html");
|
||||
dw.printHeader("Application " + app.getName() );
|
||||
dw.printAppIndexTitle(app.getName());
|
||||
dw.printAppIndexList((DocPrototype[])app.listPrototypes());
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
|
||||
/** print all prototype-files, lists of functions */
|
||||
public static void printPrototypes(DocApplication app) {
|
||||
DocPrototype[] pt = app.listPrototypes();
|
||||
for ( int i=0; i<pt.length; i++ ) {
|
||||
try {
|
||||
DocWriter dw = new DocWriter( pt[i].getDocFileName());
|
||||
dw.printHeader("Application " + app.getName() + " / Prototype " + pt[i].getName());
|
||||
dw.printNavBar(app.getName(), pt[i], PROTOTYPE );
|
||||
dw.printElementTitle(pt[i]);
|
||||
dw.printComment(pt[i]);
|
||||
dw.printFunctionList(pt[i].listFunctions(DocElement.ACTION), "Actions");
|
||||
dw.printFunctionList(pt[i].listFunctions(DocElement.TEMPLATE), "Templates");
|
||||
dw.printFunctionList(pt[i].listFunctions(DocElement.FUNCTION), "Functions");
|
||||
dw.printFunctionList(pt[i].listFunctions(DocElement.MACRO), "Macros");
|
||||
dw.printFunctionList(pt[i].listFunctions(DocElement.SKIN), "Skins");
|
||||
dw.printInheritance(pt[i]);
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
}
|
||||
|
||||
/** print all function sources */
|
||||
public static void printFunctions(DocApplication app) {
|
||||
DocFunction[] df = app.listFunctions();
|
||||
for ( int i=0;i<df.length; i++ ) {
|
||||
try {
|
||||
File d = new File ( docDir, df[i].getPrototype().getName().toLowerCase() );
|
||||
if ( !d.exists() )
|
||||
d.mkdir();
|
||||
DocWriter dw = new DocWriter( df[i].getPrototype().getName().toLowerCase() + "/" + df[i].getDocFileName() );
|
||||
dw.printHeader( app.getName() + "." + df[i].getPrototype().getName() + "." + df[i].getName() );
|
||||
dw.printNavBar( app.getName(), df[i].getPrototype(), DocHtmlWriter.METHOD);
|
||||
dw.printFunction( df[i] );
|
||||
dw.close();
|
||||
} catch ( FileNotFoundException e ) { DocRun.log( e.getMessage() ); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue