From 9bd47012c5201b216ab216d937118050c564b442 Mon Sep 17 00:00:00 2001 From: stefanp Date: Wed, 20 Nov 2002 16:00:41 +0000 Subject: [PATCH] restructured the whole helma.doc-package. - implemented latest helma features (function_action for actions etc) - removed double code, nicer hierarchy, all elements can be used alone - removed possibility to run from command line, rendering is now only done through manage application - streamlined supported tags --- src/helma/doc/DocApplication.java | 163 ++++++------ src/helma/doc/DocComparator.java | 46 ---- src/helma/doc/DocDirElement.java | 36 +++ src/helma/doc/DocElement.java | 409 +++++++++++++++++++----------- src/helma/doc/DocException.java | 2 +- src/helma/doc/DocFileElement.java | 84 ++++++ src/helma/doc/DocFunction.java | 206 +++++++++------ src/helma/doc/DocHtmlWriter.java | 328 ------------------------ src/helma/doc/DocProperties.java | 49 ++++ src/helma/doc/DocPrototype.java | 264 +++++-------------- src/helma/doc/DocRun.java | 227 ----------------- src/helma/doc/DocSkin.java | 78 ++++++ src/helma/doc/DocTag.java | 120 ++++++--- src/helma/doc/DocWriter.java | 128 ---------- src/helma/doc/Util.java | 38 +++ 15 files changed, 904 insertions(+), 1274 deletions(-) delete mode 100644 src/helma/doc/DocComparator.java create mode 100644 src/helma/doc/DocDirElement.java create mode 100644 src/helma/doc/DocFileElement.java delete mode 100644 src/helma/doc/DocHtmlWriter.java create mode 100644 src/helma/doc/DocProperties.java delete mode 100644 src/helma/doc/DocRun.java create mode 100644 src/helma/doc/DocSkin.java delete mode 100644 src/helma/doc/DocWriter.java create mode 100644 src/helma/doc/Util.java diff --git a/src/helma/doc/DocApplication.java b/src/helma/doc/DocApplication.java index 06d6b322..22d88d84 100644 --- a/src/helma/doc/DocApplication.java +++ b/src/helma/doc/DocApplication.java @@ -5,112 +5,103 @@ import helma.main.Server; import java.io.*; import java.util.*; -public class DocApplication extends DocElement implements IPathElement { - - private DocPrototype[] prototypes; +public class DocApplication extends DocDirElement { - /** 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 ); + public static void main (String args[]) { +// DocApplication app; +// app = new DocApplication (args[0], args[1]); +// app.readApplication (); + +// DocPrototype el = DocPrototype.newInstance (new File(args[0])); +// el.readFiles (); + +// DocFunction func = DocFunction.newTemplate (new File(args[0])); +// DocFunction func = DocFunction.newAction (new File(args[0])); + + DocFunction[] func = DocFunction.newFunctions (new File (args[0])); + +// DocSkin skin = DocSkin.newInstance (new File (args[0])); +// System.out.println (func.getContent ()); +// System.out.println ("\n\n\ncomment = " + func.getComment ()); + } + + + public DocApplication (String name, File location) throws DocException { + super (name, location, APPLICATION); } - /** return number of prototypes */ - public int countPrototypes() { - return prototypes.length; + public DocApplication (String name, String appDir) throws DocException { + super (name, new File (appDir), APPLICATION); } - /** return a single prototype */ - public DocPrototype getDocPrototype(String name) { - for ( int i=0; ie2.getType() ) - return 1; - else if ( mode==BY_TYPE && e1.getType()=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; ibeginLine && ctbeginLine && ct"))); + ASCII_CharStream ascii = new ASCII_CharStream (str,1,1); + EcmaScriptTokenManager mgr = new EcmaScriptTokenManager (ascii); + Token tok = mgr.getNextToken(); + parseCommentFromToken (tok); } - //////////////////////////////////// - // from helma.framework.IPathElement - //////////////////////////////////// - - public String getElementName() { - return getTypeName().toLowerCase()+"_"+name; - } - public IPathElement getChildElement(String name) { - return null; - } - - public IPathElement getParentElement() { - return prototype; - } - - public java.lang.String getPrototype() { + /** + * from helma.framework.IPathElement. All macros, templates, actions etc + * have the same prototype. + */ + public java.lang.String getPrototype () { return "docfunction"; } diff --git a/src/helma/doc/DocHtmlWriter.java b/src/helma/doc/DocHtmlWriter.java deleted file mode 100644 index 9d2ca931..00000000 --- a/src/helma/doc/DocHtmlWriter.java +++ /dev/null @@ -1,328 +0,0 @@ -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(""); - else - print(""); - print(""); - print(""); - println("" + title + ""); - if ( frameset==true ) - print(""); - println(""); - } - - - public void printFrameSet() { - println (""); - println (""); - println (""); - println ("sorry, your browser doesn't understand frames!"); - } - - /** print app title for left frame */ - public void printAppIndexTitle(String title) { - print("
"); - print(""); - print("Application " + title + "
" ); - } - - /** print prototype list for left frame */ - public void printAppIndexList(DocElement[] pt) { - print("
"); - print("

Prototypes

"); - for ( int i=0; i" + pt[i].getName() + "
"); - } - print ("

"); - } - - /** navigation on top of the page **/ - public void printNavBar(String name, DocPrototype pt, int page ) { - String urlPrefix = ( page==METHOD ) ? "../" : ""; - print(""); - print(""); - print(""); - print(""); - if ( pt!=null && page!=METHOD ) { - print(""); - } - - print("
Application " + name + "
"); - print("
"); - print(""); - } - - public void printElementTitle(DocElement docEl) { - print("

" + docEl.getName() + "
"); - print(docEl.getFullName() + "

"); - print("
"); - } - - public void printComment(DocElement docEl) { - if( docEl.getComment().length()>0 || docEl.countTags()>0 ) { - print("
" + docEl.getComment() + "
"); - print("
"); - for ( int i=0; i0 ) { - print("
" + DocTag.kindDesc[i] + "
"); - DocTag[] dt = docEl.listTags(i); - for ( int j=0; j" + renderTag(dt[j],j) + ""); - } - } - } - print("
"); - } - } - - private String renderFunctionName(DocFunction func) { - StringBuffer buf = new StringBuffer (); - buf.append(""); - if ( DocRun.getOption("-f").equals("true") ) - buf.append("" ); - if ( func.isMacro() ) { - buf.append( func.getDocPrototype().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"); - if ( func.isFunction() || func.isMacro() ) - buf.append(" in " + (new File(func.getLocation())).getName() + "" ); - 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( "Argument " + i + ": " + text ); - case DocTag.PARAM: - return( "Parameter " + name + " " + 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( "" + ((tok.countTokens()>0)?text.substring(url.length(),text.length()):text) + "" ); - } else { - StringBuffer buf = new StringBuffer(); - StringTokenizer tok = new StringTokenizer (text.trim(),"."); - if ( tok.countTokens()==0 ) return text; - DocPrototype dp = app.getDocPrototype( tok.nextToken() ); - if ( dp==null ) return text; - buf.append("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()+""); - } - } - return text; - } - - public void printListHeader(String title) { - print(""); - print(""); - print(""); - } - - public void printPrototypeList(DocPrototype[] dl, String title) { - if ( dl.length==0 ) return; - printListHeader(title); - for ( int i=0; i"); - print(""); - } - print("
" + title + "
"); - print(""); - print(" " + dl[i].getTypeName() + "" + dl[i].getName() + ""); - print("
          " + dl[i].getComment() + "
" ); - print("

"); - } - - public void printFunctionList(DocFunction[] dl, String title) { - if ( dl.length==0 ) return; - printListHeader(title); - for ( int i=0; i"); - print(""); - print(""); - print(" " + dl[i].getTypeName() + ""); - print("
" + renderFunctionName(dl[i]) ); - print("
"); - printComment(dl[i]); - print("
"); - } - print("
"); - } - - public void printFunctionIndex(DocFunction[] dl) { - if ( dl.length==0 ) return; - String curChar = " "; - print("
"); - for ( int i=0; i

" + name.substring(0,1).toUpperCase() + "

"); - curChar = name.substring(0,1).toLowerCase(); - } - print("
" + dl[i].getName() + " - " + dl[i].getTypeName() + " in " + dl[i].getDocPrototype().getName() + "" ); - } - print("
"); - } - - public void printInheritance(DocPrototype pt) { - if ( pt.getName().equalsIgnoreCase("hopobject") ) - return; - DocApplication app = pt.getApplication(); - DocPrototype hopobject = (DocPrototype)app.getDocPrototype("hopobject"); - if ( hopobject==null || hopobject.countFunctions()==0 ) - return; - print(""); - print(""); - print(""); - print(""); - print("
Methods inherited from Prototype hopobject
"); - DocFunction[] df = hopobject.listFunctions(); - - int lastType = -1; - StringBuffer buf1 = new StringBuffer(); - StringBuffer buf2 = new StringBuffer(); - - for ( int i=0; i0 && buf2.length()>0 ) { - buf1.append("" + DocElement.typeNames[lastType] + ": " ); - buf1.append( buf2.toString().substring(0, buf2.toString().length()-2) ); - buf1.append("
"); - buf2 = new StringBuffer(); - } - lastType = df[i].getType(); - buf2.append ( "" + df[i].getName() + ", " ); - } - if ( buf2.length()>0 ) { - buf1.append("" + DocElement.typeNames[lastType] + ": " ); - buf1.append( buf2.toString().substring(0, buf2.toString().length()-2) ); - buf1.append("
"); - } - print ( buf1.toString() ); - print("
"); - } - - public void printFunction(DocFunction func) { - print( "

in " + func.getDocPrototype().getName() + "/" + (new File(func.getLocation())).getName() + ":" ); - print( "
");
-		print( HtmlEncoder.encodeAll(func.getSource()) );
-		print( "
" ); - } - - 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.getDocPrototype().getName() + ".html#" + df.getName(); - } else { - return ""; - } - } - -} - diff --git a/src/helma/doc/DocProperties.java b/src/helma/doc/DocProperties.java new file mode 100644 index 00000000..d9f9ad82 --- /dev/null +++ b/src/helma/doc/DocProperties.java @@ -0,0 +1,49 @@ +package helma.doc; + +import helma.framework.IPathElement; +import helma.util.SystemProperties; +import java.io.*; +import java.util.*; + +public class DocProperties extends DocFileElement { + + Properties props = null; + + /** + * creates a new independent DocProperties object + */ + public static DocProperties newInstance (File location) { + return newInstance (location, null); + } + + /** + * creates a new DocProperties object connected to another DocElement + */ + public static DocProperties newInstance (File location, DocElement parent) { + try { + return new DocProperties (location, parent); + } catch (DocException doc) { + return null; + } + } + + protected DocProperties (File location, DocElement parent) throws DocException { + super (location.getName (), location, PROPERTIES); + this.parent = parent; + content = readFile (location); + props = new SystemProperties (); + try { + props.load (new FileInputStream (location)); + } catch (IOException e) { + debug ("couldn't read file: " + e.toString ()); + } catch (Exception e) { + throw new DocException (e.toString ()); + } + } + + protected Properties getProperties () { + return props; + } + +} + diff --git a/src/helma/doc/DocPrototype.java b/src/helma/doc/DocPrototype.java index 9f3d4751..4bd85b4e 100644 --- a/src/helma/doc/DocPrototype.java +++ b/src/helma/doc/DocPrototype.java @@ -6,215 +6,89 @@ import java.util.*; import FESI.Parser.*; -public class DocPrototype extends DocElement implements IPathElement { +public class DocPrototype extends DocDirElement { - DocFunction[] functions; - DocApplication app; + private DocProperties typeProperties = null; + private DocPrototype parentPrototype = null; - 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(); + /** + * creates a prototype that is independent of an + * application object + * @param homedirectory + */ + public static DocPrototype newInstance (File location) { + return newInstance (location, null); } - public String getFullName() { return ( "Prototype " + name ); } + /** + * creates a prototype that is connected to an + * application object and resides in app's home dir. + * @param application + * @param name + */ + public static DocPrototype newInstance (File location, DocElement parent) { + DocPrototype pt = new DocPrototype (location.getName (), location, parent); + return pt; + } - /** return number of functions */ - public int countFunctions() { return functions.length; } + private DocPrototype (String name, File location, DocElement parent) { + super (name, location, PROTOTYPE); + this.parent = parent; + typeProperties = DocProperties.newInstance (new File (location, "type.properties")); + } - /** return array of functions of a special type */ - public int countFunctions(int type) { - int ct = 0; - for ( int i=0; i")) ); - 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 + "]" ); - } - - - //////////////////////////////////// - // from helma.framework.IPathElement - //////////////////////////////////// - - public String getElementName() { - return name; - } - - public IPathElement getChildElement(String name) { - for ( int i=0; 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()); - } - } - - - /** - * Description of the Method - */ - 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"); - } - - - /** - * Description of the Method - * - *@param name Description of Parameter - *@return Description of the Returned Value - */ - 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 hopHomeDir Description of Parameter - */ - 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"); - } - - - /** - * Description of the Method - * - *@param msg Description of Parameter - */ - public static void debug(String msg) { - if (options.containsKey("-debug")) { - System.out.println(msg); - } - } - - - /** - * Description of the Method - * - *@param msg Description of Parameter - */ - public static void log(String msg) { - System.out.println(msg); - } - -} - - diff --git a/src/helma/doc/DocSkin.java b/src/helma/doc/DocSkin.java new file mode 100644 index 00000000..4d5a74f2 --- /dev/null +++ b/src/helma/doc/DocSkin.java @@ -0,0 +1,78 @@ +package helma.doc; + +import helma.framework.IPathElement; +import java.io.*; +import java.util.*; + +public class DocSkin extends DocFileElement { + + /** + * creates a new independent DocSkin object + */ + public static DocSkin newInstance (File location) { + return newInstance (location, null); + } + + /** + * creates a new DocSkin object connected to another DocElement + */ + public static DocSkin newInstance (File location, DocElement parent) { + String skinname = nameFromFile (location, ".skin"); + DocSkin skin = new DocSkin (skinname, location, parent); + return skin; + } + + protected DocSkin (String name, File location, DocElement parent) { + super (name, location, SKIN); + this.parent = parent; + content = readFile (location); + parseHandlers (); + } + + + /** + * parses the source code of the skin and + * extracts all included macros. code taken + * from helma.framework.core.Skin + * @see helma.framework.core.Skin + */ + private void parseHandlers () { + ArrayList partBuffer = new ArrayList (); + char[] source = content.toCharArray (); + int sourceLength = source.length; + int start = 0; + for (int i = 0; i < sourceLength-1; i++) { + if (source[i] == '<' && source[i+1] == '%') { + // found macro start tag + int j = i+2; + // search macro end tag + while (j < sourceLength-1 && (source[j] != '%' || source[j+1] != '>')) { + j++; + } + if (j > i+2) { + String str = (new String (source, i+2, j-i)).trim (); + str = str.substring (0, str.indexOf(" ")); + if (!partBuffer.contains(str)) + partBuffer.add (str); + start = j+2; + } + i = j+1; + } + } + String[] strArr = (String[]) partBuffer.toArray (new String [0]); + Arrays.sort (strArr); + for (int i=0; i