* Refactored helma.doc package to make it work with repositories.
This commit is contained in:
parent
b5b60e3d92
commit
24e878c176
11 changed files with 227 additions and 335 deletions
|
@ -18,7 +18,7 @@ package helma.doc;
|
||||||
|
|
||||||
import helma.framework.IPathElement;
|
import helma.framework.IPathElement;
|
||||||
import helma.framework.core.Application;
|
import helma.framework.core.Application;
|
||||||
import helma.framework.repository.FileRepository;
|
import helma.framework.core.Prototype;
|
||||||
import helma.main.Server;
|
import helma.main.Server;
|
||||||
import helma.util.ResourceProperties;
|
import helma.util.ResourceProperties;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -40,60 +40,11 @@ public class DocApplication extends DocElement {
|
||||||
* @throws DocException ...
|
* @throws DocException ...
|
||||||
*/
|
*/
|
||||||
public DocApplication(Application app) throws DocException {
|
public DocApplication(Application app) throws DocException {
|
||||||
super(app.getName(), app.getAppDir(), APPLICATION);
|
super(app.getName(), APPLICATION);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
readProps();
|
readProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new DocApplication object.
|
|
||||||
*
|
|
||||||
* @param name ...
|
|
||||||
* @param appDir ...
|
|
||||||
*
|
|
||||||
* @throws DocException ...
|
|
||||||
*/
|
|
||||||
public DocApplication(String name, String appDir) throws DocException {
|
|
||||||
super(name, new File(appDir), APPLICATION);
|
|
||||||
readProps();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param args ...
|
|
||||||
*/
|
|
||||||
/* public static void main(String[] args) {
|
|
||||||
System.out.println("this is helma.doc");
|
|
||||||
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]));
|
|
||||||
// for (int i=0; i<func.length; i++) {
|
|
||||||
// System.out.println("=============================================");
|
|
||||||
// System.out.println("function " + func[i].name);
|
|
||||||
// System.out.println("comment = " + func[i].comment + "<<<");
|
|
||||||
// String[] arr = func[i].listParameters();
|
|
||||||
// for (int j=0; j<arr.length; j++) {
|
|
||||||
// System.out.println (arr[j]);
|
|
||||||
// }
|
|
||||||
// System.out.println ("\ncontent:\n" + func[i].content + "<<<");
|
|
||||||
// System.out.println ("\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// DocSkin skin = DocSkin.newInstance (new File (args[0]));
|
|
||||||
|
|
||||||
// System.out.println (func.getContent ());
|
|
||||||
// System.out.println ("\n\n\ncomment = " + func.getComment ());
|
|
||||||
} */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads the app.properties file and parses for helma.excludeDocs
|
* reads the app.properties file and parses for helma.excludeDocs
|
||||||
*/
|
*/
|
||||||
|
@ -129,57 +80,31 @@ public class DocApplication extends DocElement {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param str ...
|
* @param name ...
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public boolean isExcluded(String str) {
|
public boolean isExcluded(String name) {
|
||||||
return (excluded.contains(str.toLowerCase()));
|
return (excluded.contains(name.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads all prototypes and files of the application
|
* reads all prototypes and files of the application
|
||||||
*/
|
*/
|
||||||
public void readApplication() {
|
public void readApplication() throws IOException {
|
||||||
readProps();
|
readProps();
|
||||||
children.clear();
|
children.clear();
|
||||||
|
|
||||||
Iterator it = app.getRepositories().iterator();
|
Iterator it = app.getPrototypes().iterator();
|
||||||
|
// Iterator it = app.getRepositories().iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Object next = it.next();
|
|
||||||
|
|
||||||
if (!(next instanceof FileRepository)) {
|
Prototype proto = (Prototype) it.next();
|
||||||
continue;
|
proto.checkForUpdates();
|
||||||
}
|
DocPrototype pt = new DocPrototype(proto, this);
|
||||||
|
addChild(pt);
|
||||||
File dir = ((FileRepository) next).getDirectory();
|
pt.readFiles();
|
||||||
|
|
||||||
String[] arr = dir.list();
|
|
||||||
|
|
||||||
for (int i = 0; i < arr.length; i++) {
|
|
||||||
if (isExcluded(arr[i])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
File f = new File(dir.getAbsolutePath(), arr[i]);
|
|
||||||
|
|
||||||
if (!f.isDirectory()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.err.println("*** NEW PROTOTYPE DOC: " + f);
|
|
||||||
DocPrototype pt = DocPrototype.newInstance(f, this);
|
|
||||||
|
|
||||||
addChild(pt);
|
|
||||||
pt.readFiles();
|
|
||||||
} catch (DocException e) {
|
|
||||||
debug("Couldn't read prototype " + arr[i] + ": " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Iterator i = children.values().iterator(); i.hasNext();) {
|
for (Iterator i = children.values().iterator(); i.hasNext();) {
|
||||||
((DocPrototype) i.next()).checkInheritance();
|
((DocPrototype) i.next()).checkInheritance();
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
import helma.framework.IPathElement;
|
import helma.framework.IPathElement;
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,6 @@ public abstract class DocElement implements IPathElement {
|
||||||
// identifiers of this element
|
// identifiers of this element
|
||||||
String name;
|
String name;
|
||||||
int type;
|
int type;
|
||||||
File location;
|
|
||||||
DocElement parent = null;
|
DocElement parent = null;
|
||||||
Map children = new HashMap();
|
Map children = new HashMap();
|
||||||
|
|
||||||
|
@ -53,19 +52,8 @@ public abstract class DocElement implements IPathElement {
|
||||||
List tags = new Vector();
|
List tags = new Vector();
|
||||||
List parameters = new Vector();
|
List parameters = new Vector();
|
||||||
|
|
||||||
protected DocElement(String name, String location, int type)
|
protected DocElement(String name, int type) throws DocException {
|
||||||
throws DocException {
|
|
||||||
this(name, new File(location), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DocElement(String name, File location, int type)
|
|
||||||
throws DocException {
|
|
||||||
if (!location.exists()) {
|
|
||||||
throw new DocException(name + " not found in " + location.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.location = location;
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +64,6 @@ public abstract class DocElement implements IPathElement {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return absolute path to location of element
|
|
||||||
* (directory for apps and prototypes, file for
|
|
||||||
* methods and properties files)
|
|
||||||
*/
|
|
||||||
public File getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -246,7 +225,7 @@ public abstract class DocElement implements IPathElement {
|
||||||
addTag(buf.toString());
|
addTag(buf.toString());
|
||||||
}
|
}
|
||||||
} catch (RuntimeException rt) {
|
} catch (RuntimeException rt) {
|
||||||
debug("parse error in " + location + ": " + rt.getMessage());
|
debug("parse error in " + name + ": " + rt.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,51 +20,52 @@ import java.awt.Point;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import org.mozilla.javascript.*;
|
import org.mozilla.javascript.*;
|
||||||
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DocFunction extends DocFileElement {
|
public class DocFunction extends DocResourceElement {
|
||||||
|
|
||||||
protected DocFunction(String name, File location, DocElement parent, int type) {
|
protected DocFunction(String name, Resource res, DocElement parent, int type) {
|
||||||
super(name, location, type);
|
super(name, res, type);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new independent DocFunction object of type ACTION
|
* creates a new independent DocFunction object of type ACTION
|
||||||
*/
|
*/
|
||||||
public static DocFunction newAction(File location) {
|
public static DocFunction newAction(Resource res) throws IOException {
|
||||||
return newAction(location, null);
|
return newAction(res, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new DocFunction object of type ACTION connected to another DocElement
|
* creates a new DocFunction object of type ACTION connected to another DocElement
|
||||||
*/
|
*/
|
||||||
public static DocFunction newAction(File location, DocElement parent) {
|
public static DocFunction newAction(Resource res, DocElement parent) throws IOException{
|
||||||
String name = Util.nameFromFile(location, ".hac");
|
String name = res.getBaseName();
|
||||||
DocFunction func = new DocFunction(name, location, parent, ACTION);
|
DocFunction func = new DocFunction(name, res, parent, ACTION);
|
||||||
String rawComment = "";
|
String rawComment = "";
|
||||||
try {
|
try {
|
||||||
TokenStream ts = getTokenStream (location);
|
TokenStream ts = getTokenStream (res);
|
||||||
Point p = getPoint (ts);
|
Point p = getPoint (ts);
|
||||||
ts.getToken();
|
ts.getToken();
|
||||||
rawComment = Util.getStringFromFile(location, p, getPoint(ts));
|
rawComment = Util.getStringFromFile(res, p, getPoint(ts));
|
||||||
rawComment = Util.chopComment (rawComment);
|
rawComment = Util.chopComment (rawComment);
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
io.printStackTrace();
|
io.printStackTrace();
|
||||||
throw new DocException (io.toString());
|
throw new DocException (io.toString());
|
||||||
}
|
}
|
||||||
func.parseComment(rawComment);
|
func.parseComment(rawComment);
|
||||||
func.content = Util.readFile(location);
|
func.content = res.getContent();
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads a function file and creates independent DocFunction objects of type FUNCTION
|
* reads a function file and creates independent DocFunction objects of type FUNCTION
|
||||||
*/
|
*/
|
||||||
public static DocFunction[] newFunctions(File location) {
|
public static DocFunction[] newFunctions(Resource res) {
|
||||||
return newFunctions(location, null);
|
return newFunctions(res, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public class DocFunction extends DocFileElement {
|
||||||
* reads a function file and creates DocFunction objects of type FUNCTION
|
* reads a function file and creates DocFunction objects of type FUNCTION
|
||||||
* connected to another DocElement.
|
* connected to another DocElement.
|
||||||
*/
|
*/
|
||||||
public static DocFunction[] newFunctions(File location, DocElement parent) {
|
public static DocFunction[] newFunctions(Resource res, DocElement parent) {
|
||||||
|
|
||||||
Vector vec = new Vector();
|
Vector vec = new Vector();
|
||||||
|
|
||||||
|
@ -89,16 +90,16 @@ public class DocFunction extends DocFileElement {
|
||||||
String functionName = null;
|
String functionName = null;
|
||||||
String context = null;
|
String context = null;
|
||||||
|
|
||||||
TokenStream ts = getTokenStream (location);
|
TokenStream ts = getTokenStream (res);
|
||||||
|
|
||||||
while (!ts.eof()) {
|
while (!ts.eof()) {
|
||||||
|
|
||||||
// store the position of the last token
|
// store the position of the last token
|
||||||
endOfLastToken = getPoint (ts);
|
endOfLastToken = getPoint (ts);
|
||||||
|
|
||||||
// store last token
|
// store last token
|
||||||
lastToken = token;
|
lastToken = token;
|
||||||
|
|
||||||
// now get a new token
|
// now get a new token
|
||||||
// regular expression syntax is troublesome for the TokenStream
|
// regular expression syntax is troublesome for the TokenStream
|
||||||
// we can safely ignore syntax errors in regular expressions here
|
// we can safely ignore syntax errors in regular expressions here
|
||||||
|
@ -117,7 +118,7 @@ public class DocFunction extends DocFileElement {
|
||||||
context = ts.getString();
|
context = ts.getString();
|
||||||
|
|
||||||
} else if (token == Token.RC && context != null) {
|
} else if (token == Token.RC && context != null) {
|
||||||
|
|
||||||
// when we come across a right brace outside of a function,
|
// when we come across a right brace outside of a function,
|
||||||
// we reset the current context cache
|
// we reset the current context cache
|
||||||
context = null;
|
context = null;
|
||||||
|
@ -148,7 +149,7 @@ public class DocFunction extends DocFileElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (token == Token.FUNCTION) {
|
} else if (token == Token.FUNCTION) {
|
||||||
|
|
||||||
// store the end of the function word
|
// store the end of the function word
|
||||||
Point p = getPoint(ts);
|
Point p = getPoint(ts);
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ public class DocFunction extends DocFileElement {
|
||||||
|
|
||||||
// if the token after FUNCTION is NAME, it's the usual function
|
// if the token after FUNCTION is NAME, it's the usual function
|
||||||
// declaration like this: function abc() {}
|
// declaration like this: function abc() {}
|
||||||
|
|
||||||
// set the pointer for the start of the actual function body
|
// set the pointer for the start of the actual function body
|
||||||
// to the letter f of the function word
|
// to the letter f of the function word
|
||||||
startOfFunctionBody = p;
|
startOfFunctionBody = p;
|
||||||
|
@ -176,7 +177,7 @@ public class DocFunction extends DocFileElement {
|
||||||
functionName = ts.getString();
|
functionName = ts.getString();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// it's a different kind of function declaration.
|
// it's a different kind of function declaration.
|
||||||
// the function name is the last found NAME-token
|
// the function name is the last found NAME-token
|
||||||
// if context is set, prepend it to the function name
|
// if context is set, prepend it to the function name
|
||||||
|
@ -185,12 +186,12 @@ public class DocFunction extends DocFileElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the comment from the file (unfortunately, the stream simply skips comments) ...
|
// get the comment from the file (unfortunately, the stream simply skips comments) ...
|
||||||
String rawComment = Util.getStringFromFile(location, endOfLastUsedToken, startOfFunctionBody).trim ();
|
String rawComment = Util.getStringFromFile(res, endOfLastUsedToken, startOfFunctionBody).trim ();
|
||||||
// .. and clean it
|
// .. and clean it
|
||||||
rawComment = Util.chopComment (rawComment);
|
rawComment = Util.chopComment (rawComment);
|
||||||
|
|
||||||
// create the function object
|
// create the function object
|
||||||
DocFunction theFunction = newFunction (functionName, location, parent);
|
DocFunction theFunction = newFunction (functionName, res, parent);
|
||||||
theFunction.parseComment (rawComment);
|
theFunction.parseComment (rawComment);
|
||||||
vec.add (theFunction);
|
vec.add (theFunction);
|
||||||
|
|
||||||
|
@ -221,8 +222,8 @@ public class DocFunction extends DocFileElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endOfFunctionBody = getPoint(ts);
|
endOfFunctionBody = getPoint(ts);
|
||||||
|
|
||||||
theFunction.content = Util.getStringFromFile(location, startOfFunctionBody, endOfFunctionBody);
|
theFunction.content = Util.getStringFromFile(res, startOfFunctionBody, endOfFunctionBody);
|
||||||
|
|
||||||
} // end if
|
} // end if
|
||||||
} // end while
|
} // end while
|
||||||
|
@ -235,13 +236,13 @@ public class DocFunction extends DocFileElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static DocFunction newFunction (String funcName, File location, DocElement parent) {
|
private static DocFunction newFunction (String funcName, Resource res, DocElement parent) {
|
||||||
if (funcName.endsWith("_action")) {
|
if (funcName.endsWith("_action")) {
|
||||||
return new DocFunction(funcName, location, parent, ACTION);
|
return new DocFunction(funcName, res, parent, ACTION);
|
||||||
} else if (funcName.endsWith("_macro")) {
|
} else if (funcName.endsWith("_macro")) {
|
||||||
return new DocFunction(funcName, location, parent, MACRO);
|
return new DocFunction(funcName, res, parent, MACRO);
|
||||||
} else {
|
} else {
|
||||||
return new DocFunction(funcName, location, parent, FUNCTION);
|
return new DocFunction(funcName, res, parent, FUNCTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,15 +250,15 @@ public class DocFunction extends DocFileElement {
|
||||||
/**
|
/**
|
||||||
* creates a rhino token stream for a given file
|
* creates a rhino token stream for a given file
|
||||||
*/
|
*/
|
||||||
protected static TokenStream getTokenStream (File f) {
|
protected static TokenStream getTokenStream (Resource res) throws IOException {
|
||||||
FileReader reader = null;
|
Reader reader = null;
|
||||||
try {
|
try {
|
||||||
reader = new FileReader(f);
|
reader = new InputStreamReader(res.getInputStream());
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
fnfe.printStackTrace();
|
fnfe.printStackTrace();
|
||||||
throw new DocException (fnfe.toString());
|
throw new DocException (fnfe.toString());
|
||||||
}
|
}
|
||||||
String name = f.getName();
|
String name = res.getName();
|
||||||
int line = 0;
|
int line = 0;
|
||||||
CompilerEnvirons compilerEnv = new CompilerEnvirons();
|
CompilerEnvirons compilerEnv = new CompilerEnvirons();
|
||||||
compilerEnv.initFromContext(Context.getCurrentContext());
|
compilerEnv.initFromContext(Context.getCurrentContext());
|
||||||
|
|
|
@ -16,59 +16,52 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
import helma.util.SystemProperties;
|
import helma.util.ResourceProperties;
|
||||||
import java.io.*;
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Documentation around a properties file
|
||||||
*/
|
*/
|
||||||
public class DocProperties extends DocFileElement {
|
public class DocProperties extends DocResourceElement {
|
||||||
Properties props = null;
|
|
||||||
|
ResourceProperties props;
|
||||||
|
String elementName;
|
||||||
|
|
||||||
|
protected DocProperties(Resource res, ResourceProperties props,
|
||||||
|
int index, DocElement parent)
|
||||||
|
throws DocException, IOException {
|
||||||
|
super(res.getShortName(), res, PROPERTIES);
|
||||||
|
|
||||||
protected DocProperties(File location, DocElement parent)
|
|
||||||
throws DocException {
|
|
||||||
super(location.getName(), location, PROPERTIES);
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
content = Util.readFile(location);
|
this.props = props;
|
||||||
props = new SystemProperties();
|
this.comment = resource.getName();
|
||||||
|
this.content = resource.getContent();
|
||||||
try {
|
this.elementName = name + "_" + index;
|
||||||
props.load(new FileInputStream(location));
|
|
||||||
} catch (IOException e) {
|
|
||||||
debug("couldn't read file: " + e.toString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new DocException(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the underlying properties
|
||||||
*
|
*
|
||||||
*
|
* @return the properties
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public Properties getProperties() {
|
public ResourceProperties getProperties() {
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getElementName() {
|
||||||
|
return elementName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the comment string, empty string if no comment is set.
|
||||||
|
*/
|
||||||
|
public String getComment() {
|
||||||
|
return resource.getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -92,4 +85,11 @@ public class DocProperties extends DocFileElement {
|
||||||
|
|
||||||
return childProps;
|
return childProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* from helma.framework.IPathElement. Use the same prototype as functions etc.
|
||||||
|
*/
|
||||||
|
public java.lang.String getPrototype() {
|
||||||
|
return "docfunction";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,40 +16,30 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
|
import helma.framework.repository.Resource;
|
||||||
|
import helma.framework.core.Prototype;
|
||||||
|
import helma.util.ResourceProperties;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DocPrototype extends DocDirElement {
|
public class DocPrototype extends DocElement {
|
||||||
private DocProperties typeProperties = null;
|
|
||||||
private DocPrototype parentPrototype = null;
|
|
||||||
|
|
||||||
private DocPrototype(String name, File location, DocElement parent) {
|
DocPrototype parentPrototype = null;
|
||||||
super(name, location, PROTOTYPE);
|
Prototype proto;
|
||||||
this.parent = parent;
|
|
||||||
typeProperties = DocProperties.newInstance(new File(location, "type.properties"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a prototype that is independent of an
|
* creates a prototype based on a prototype of the application
|
||||||
* application object
|
*
|
||||||
* @param location
|
* @param proto
|
||||||
*/
|
|
||||||
public static DocPrototype newInstance(File location) {
|
|
||||||
return newInstance(location, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a prototype that is connected to an
|
|
||||||
* application object and resides in app's home dir.
|
|
||||||
* @param location
|
|
||||||
* @param parent
|
* @param parent
|
||||||
*/
|
*/ protected DocPrototype(Prototype proto, DocElement parent) {
|
||||||
public static DocPrototype newInstance(File location, DocElement parent) {
|
super(proto.getName(), PROTOTYPE);
|
||||||
DocPrototype pt = new DocPrototype(location.getName(), location, parent);
|
this.parent = parent;
|
||||||
|
this.proto = proto;
|
||||||
return pt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,15 +54,12 @@ public class DocPrototype extends DocDirElement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeProperties != null) {
|
// check for "_extends" in the the type.properties
|
||||||
// check for "_extends" in the the type.properties
|
String ext = proto.getTypeProperties().getProperty("_extends");
|
||||||
String ext = typeProperties.getProperties().getProperty("_extends");
|
|
||||||
|
|
||||||
if ((ext != null) && (parent != null)) {
|
if ((ext != null) && (parent != null)) {
|
||||||
// try to get the prototype if available
|
// try to get the prototype if available
|
||||||
parentPrototype = (DocPrototype) parent.getChildElement("prototype_" +
|
parentPrototype = (DocPrototype) parent.getChildElement("prototype_" + ext);
|
||||||
ext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((parentPrototype == null) && (parent != null) && !name.equals("global")) {
|
if ((parentPrototype == null) && (parent != null) && !name.equals("global")) {
|
||||||
|
@ -82,63 +69,66 @@ public class DocPrototype extends DocDirElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return this prototype's parent prototype
|
||||||
*
|
*
|
||||||
*
|
* @return this prototype's parent prototype
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public DocPrototype getParentPrototype() {
|
public DocPrototype getParentPrototype() {
|
||||||
return parentPrototype;
|
return parentPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
|
||||||
public DocProperties getTypeProperties() {
|
|
||||||
return typeProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runs through the prototype directory and parses all helma files
|
* runs through the prototype directory and parses all helma files
|
||||||
*/
|
*/
|
||||||
public void readFiles() {
|
public void readFiles() throws IOException {
|
||||||
children.clear();
|
children.clear();
|
||||||
|
|
||||||
String[] arr = location.list();
|
Iterator it = proto.getCodeResources();
|
||||||
|
|
||||||
for (int i = 0; i < arr.length; i++) {
|
while (it.hasNext()) {
|
||||||
if (getDocApplication().isExcluded(arr[i])) {
|
Resource res = (Resource) it.next();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
File f = new File(location.getAbsolutePath(), arr[i]);
|
String name = res.getShortName();
|
||||||
|
if (getDocApplication().isExcluded(name)) {
|
||||||
if (f.isDirectory()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (arr[i].endsWith(".skin")) {
|
if (name.endsWith(".hac")) {
|
||||||
addChild(DocSkin.newInstance(f, this));
|
addChild(DocFunction.newAction(res, this));
|
||||||
} else if (arr[i].endsWith(".properties")) {
|
} else if (name.endsWith(".js")) {
|
||||||
continue;
|
DocElement[] elements = DocFunction.newFunctions(res, this);
|
||||||
} else if (arr[i].endsWith(".hac")) {
|
|
||||||
addChild(DocFunction.newAction(f, this));
|
|
||||||
} else if (arr[i].endsWith(".js")) {
|
|
||||||
DocElement[] elements = DocFunction.newFunctions(f, this);
|
|
||||||
|
|
||||||
for (int j = 0; j < elements.length; j++) {
|
for (int j = 0; j < elements.length; j++) {
|
||||||
addChild(elements[j]);
|
addChild(elements[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("couldn't parse file " + f.getAbsolutePath() + ": " +
|
|
||||||
ex.toString());
|
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (Throwable err) {
|
} catch (Throwable err) {
|
||||||
System.out.println("couldn't parse file " + f.getAbsolutePath() + ": " +
|
proto.getApplication().logError("Couldn't parse file " + res, err);
|
||||||
err.toString());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it = proto.getSkinResources();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Resource res = (Resource) it.next();
|
||||||
|
|
||||||
|
String name = res.getShortName();
|
||||||
|
if (getDocApplication().isExcluded(name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
addChild(DocSkin.newInstance(res, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceProperties props = proto.getTypeProperties();
|
||||||
|
it = props.getResources();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Resource res = (Resource) it.next();
|
||||||
|
if (res.exists()) {
|
||||||
|
addChild(new DocProperties(res, props, index++, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,18 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
|
import helma.framework.repository.Repository;
|
||||||
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class DocDirElement extends DocElement {
|
public abstract class DocRepositoryElement extends DocElement {
|
||||||
|
|
||||||
|
protected Repository repos;
|
||||||
|
|
||||||
// a default file that is read as comment for applications
|
// a default file that is read as comment for applications
|
||||||
// and prototypes if found in their directories
|
// and prototypes if found in their directories
|
||||||
public static final String[] DOCFILES = {
|
public static final String[] DOCFILES = {
|
||||||
|
@ -30,17 +36,40 @@ public abstract class DocDirElement extends DocElement {
|
||||||
"prototype.htm", "index.html", "index.htm"
|
"prototype.htm", "index.html", "index.htm"
|
||||||
};
|
};
|
||||||
|
|
||||||
protected DocDirElement(String name, File location, int type) {
|
protected DocRepositoryElement(String name, Repository repos, int type) throws IOException {
|
||||||
super(name, location, type);
|
super(name, type);
|
||||||
|
this.repos = repos;
|
||||||
checkCommentFiles();
|
checkCommentFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCommentFiles() throws DocException {
|
/**
|
||||||
for (int i = 0; i < DOCFILES.length; i++) {
|
* Get a string describing this element's location
|
||||||
File f = new File(location, DOCFILES[i]);
|
*
|
||||||
|
* @return lstring representation of the element's repository
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return repos.getName();
|
||||||
|
}
|
||||||
|
|
||||||
if (f.exists()) {
|
/**
|
||||||
String rawComment = Util.readFile(f);
|
* @return absolute path to location of element
|
||||||
|
* (directory for apps and prototypes, file for
|
||||||
|
* methods and properties files)
|
||||||
|
*/
|
||||||
|
public Repository getRepository() {
|
||||||
|
return repos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkCommentFiles() throws DocException, IOException {
|
||||||
|
if (repos == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < DOCFILES.length; i++) {
|
||||||
|
Resource res = repos.getResource(DOCFILES[i]);
|
||||||
|
|
||||||
|
if (res.exists()) {
|
||||||
|
String rawComment = res.getContent();
|
||||||
|
|
||||||
parseComment(rawComment);
|
parseComment(rawComment);
|
||||||
|
|
|
@ -16,19 +16,27 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
import java.io.File;
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* abstract class for extracting doc information from files.
|
* abstract class for extracting doc information from files.
|
||||||
* not used at the moment but left in for further extensions-
|
* not used at the moment but left in for further extensions-
|
||||||
*/
|
*/
|
||||||
public abstract class DocFileElement extends DocElement {
|
public abstract class DocResourceElement extends DocElement {
|
||||||
protected DocFileElement(String name, File location, int type) {
|
|
||||||
super(name, location, type);
|
protected Resource resource;
|
||||||
|
|
||||||
|
protected DocResourceElement(String name, Resource res, int type) {
|
||||||
|
super(name, type);
|
||||||
|
this.resource = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string describing this element's location
|
||||||
|
*
|
||||||
|
* @return string representation of the element's resource
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return resource.getName();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,35 +16,36 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
import java.io.*;
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DocSkin extends DocFileElement {
|
public class DocSkin extends DocResourceElement {
|
||||||
protected DocSkin(String name, File location, DocElement parent) {
|
|
||||||
super(name, location, SKIN);
|
protected DocSkin(String name, Resource res, DocElement parent) throws IOException {
|
||||||
|
super(name, res, SKIN);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
content = Util.readFile(location);
|
content = res.getContent();
|
||||||
parseHandlers();
|
parseHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new independent DocSkin object
|
* creates a new independent DocSkin object
|
||||||
*/
|
*/
|
||||||
public static DocSkin newInstance(File location) {
|
public static DocSkin newInstance(Resource res) throws IOException {
|
||||||
return newInstance(location, null);
|
return newInstance(res, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new DocSkin object connected to another DocElement
|
* creates a new DocSkin object connected to another DocElement
|
||||||
*/
|
*/
|
||||||
public static DocSkin newInstance(File location, DocElement parent) {
|
public static DocSkin newInstance(Resource res, DocElement parent) throws IOException {
|
||||||
String skinname = Util.nameFromFile(location, ".skin");
|
String skinname = res.getBaseName();
|
||||||
DocSkin skin = new DocSkin(skinname, location, parent);
|
return new DocSkin(skinname, res, parent);
|
||||||
|
|
||||||
return skin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,7 +63,7 @@ public final class DocTag {
|
||||||
name = tok.nextToken();
|
name = tok.nextToken();
|
||||||
}
|
}
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
comment.append (" " + tok.nextToken());
|
comment.append (" ").append(tok.nextToken());
|
||||||
}
|
}
|
||||||
} catch (NoSuchElementException nsee) { // ignore
|
} catch (NoSuchElementException nsee) { // ignore
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ public final class DocTag {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer ("[@" + type);
|
StringBuffer buf = new StringBuffer ("[@" + type);
|
||||||
if (name!=null && !"".equals(name))
|
if (name!=null && !"".equals(name))
|
||||||
buf.append (" " + name);
|
buf.append (" ").append(name);
|
||||||
if (text!=null && !"".equals(text))
|
if (text!=null && !"".equals(text))
|
||||||
buf.append (" " + text);
|
buf.append (" ").append(text);
|
||||||
return buf.toString() + "]";
|
return buf.toString() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package helma.doc;
|
package helma.doc;
|
||||||
|
|
||||||
|
import helma.framework.repository.Resource;
|
||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
@ -67,34 +69,6 @@ public final class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reads a complete file
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
*
|
|
||||||
* @return string with content of file
|
|
||||||
*/
|
|
||||||
public static String readFile(File file) {
|
|
||||||
try {
|
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
BufferedReader in = new BufferedReader(new FileReader(file));
|
|
||||||
String line = in.readLine();
|
|
||||||
|
|
||||||
while (line != null) {
|
|
||||||
buf.append(line + "\n");
|
|
||||||
line = in.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return ("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads a part of a file defined by two points
|
* reads a part of a file defined by two points
|
||||||
|
|
||||||
|
@ -104,11 +78,11 @@ public final class Util {
|
||||||
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static String getStringFromFile (File sourceFile, Point start, Point end) {
|
public static String getStringFromFile (Resource res, Point start, Point end) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
int ct = 0;
|
int ct = 0;
|
||||||
try {
|
try {
|
||||||
BufferedReader in = new BufferedReader(new FileReader(sourceFile));
|
BufferedReader in = new BufferedReader(new InputStreamReader(res.getInputStream()));
|
||||||
String line = "";
|
String line = "";
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
line = in.readLine();
|
line = in.readLine();
|
||||||
|
@ -116,13 +90,13 @@ public final class Util {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((ct > start.y) && (ct < end.y)) {
|
if ((ct > start.y) && (ct < end.y)) {
|
||||||
buf.append(line + "\n");
|
buf.append(line).append("\n");
|
||||||
} else if (ct == start.y) {
|
} else if (ct == start.y) {
|
||||||
if (start.y==end.y) {
|
if (start.y==end.y) {
|
||||||
buf.append (line.substring (start.x, end.x));
|
buf.append (line.substring (start.x, end.x));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
buf.append(line.substring(start.x, line.length()) + "\n");
|
buf.append(line.substring(start.x, line.length())).append("\n");
|
||||||
}
|
}
|
||||||
} else if (ct == end.y) {
|
} else if (ct == end.y) {
|
||||||
buf.append(line.substring(0, end.x));
|
buf.append(line.substring(0, end.x));
|
||||||
|
@ -173,23 +147,4 @@ public final class Util {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* extracts the function name from a file. basically chops the given suffix
|
|
||||||
* and throws an error if the file name doesn't fit.
|
|
||||||
*/
|
|
||||||
public static String nameFromFile(File f, String suffix)
|
|
||||||
throws DocException {
|
|
||||||
String filename = f.getName();
|
|
||||||
|
|
||||||
if (!filename.endsWith(suffix)) {
|
|
||||||
throw new DocException("file doesn't have suffix " + suffix + ": " +
|
|
||||||
f.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return filename.substring(0, filename.lastIndexOf(suffix));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,8 +449,12 @@ public class RhinoEngine implements ScriptingEngine {
|
||||||
*/
|
*/
|
||||||
public IPathElement getIntrospector() {
|
public IPathElement getIntrospector() {
|
||||||
if (doc == null) {
|
if (doc == null) {
|
||||||
doc = new DocApplication(app);
|
try {
|
||||||
doc.readApplication();
|
doc = new DocApplication(app);
|
||||||
|
doc.readApplication();
|
||||||
|
} catch (IOException x) {
|
||||||
|
throw new RuntimeException(x.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue