* 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.core.Application;
|
||||
import helma.framework.repository.FileRepository;
|
||||
import helma.framework.core.Prototype;
|
||||
import helma.main.Server;
|
||||
import helma.util.ResourceProperties;
|
||||
import java.io.*;
|
||||
|
@ -40,60 +40,11 @@ public class DocApplication extends DocElement {
|
|||
* @throws DocException ...
|
||||
*/
|
||||
public DocApplication(Application app) throws DocException {
|
||||
super(app.getName(), app.getAppDir(), APPLICATION);
|
||||
super(app.getName(), APPLICATION);
|
||||
this.app = app;
|
||||
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
|
||||
*/
|
||||
|
@ -129,57 +80,31 @@ public class DocApplication extends DocElement {
|
|||
/**
|
||||
*
|
||||
*
|
||||
* @param str ...
|
||||
* @param name ...
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public boolean isExcluded(String str) {
|
||||
return (excluded.contains(str.toLowerCase()));
|
||||
public boolean isExcluded(String name) {
|
||||
return (excluded.contains(name.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* reads all prototypes and files of the application
|
||||
*/
|
||||
public void readApplication() {
|
||||
public void readApplication() throws IOException {
|
||||
readProps();
|
||||
children.clear();
|
||||
|
||||
Iterator it = app.getRepositories().iterator();
|
||||
Iterator it = app.getPrototypes().iterator();
|
||||
// Iterator it = app.getRepositories().iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Object next = it.next();
|
||||
|
||||
if (!(next instanceof FileRepository)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
File dir = ((FileRepository) next).getDirectory();
|
||||
|
||||
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);
|
||||
}
|
||||
Prototype proto = (Prototype) it.next();
|
||||
proto.checkForUpdates();
|
||||
DocPrototype pt = new DocPrototype(proto, this);
|
||||
addChild(pt);
|
||||
pt.readFiles();
|
||||
|
||||
for (Iterator i = children.values().iterator(); i.hasNext();) {
|
||||
((DocPrototype) i.next()).checkInheritance();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package helma.doc;
|
||||
|
||||
import helma.framework.IPathElement;
|
||||
import java.io.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,6 @@ public abstract class DocElement implements IPathElement {
|
|||
// identifiers of this element
|
||||
String name;
|
||||
int type;
|
||||
File location;
|
||||
DocElement parent = null;
|
||||
Map children = new HashMap();
|
||||
|
||||
|
@ -53,19 +52,8 @@ public abstract class DocElement implements IPathElement {
|
|||
List tags = new Vector();
|
||||
List parameters = new Vector();
|
||||
|
||||
protected DocElement(String name, String location, int type)
|
||||
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());
|
||||
}
|
||||
|
||||
protected DocElement(String name, int type) throws DocException {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
@ -76,15 +64,6 @@ public abstract class DocElement implements IPathElement {
|
|||
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());
|
||||
}
|
||||
} 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.util.Vector;
|
||||
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) {
|
||||
super(name, location, type);
|
||||
protected DocFunction(String name, Resource res, DocElement parent, int type) {
|
||||
super(name, res, type);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new independent DocFunction object of type ACTION
|
||||
*/
|
||||
public static DocFunction newAction(File location) {
|
||||
return newAction(location, null);
|
||||
public static DocFunction newAction(Resource res) throws IOException {
|
||||
return newAction(res, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new DocFunction object of type ACTION connected to another DocElement
|
||||
*/
|
||||
public static DocFunction newAction(File location, DocElement parent) {
|
||||
String name = Util.nameFromFile(location, ".hac");
|
||||
DocFunction func = new DocFunction(name, location, parent, ACTION);
|
||||
public static DocFunction newAction(Resource res, DocElement parent) throws IOException{
|
||||
String name = res.getBaseName();
|
||||
DocFunction func = new DocFunction(name, res, parent, ACTION);
|
||||
String rawComment = "";
|
||||
try {
|
||||
TokenStream ts = getTokenStream (location);
|
||||
TokenStream ts = getTokenStream (res);
|
||||
Point p = getPoint (ts);
|
||||
ts.getToken();
|
||||
rawComment = Util.getStringFromFile(location, p, getPoint(ts));
|
||||
rawComment = Util.getStringFromFile(res, p, getPoint(ts));
|
||||
rawComment = Util.chopComment (rawComment);
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
throw new DocException (io.toString());
|
||||
}
|
||||
func.parseComment(rawComment);
|
||||
func.content = Util.readFile(location);
|
||||
func.content = res.getContent();
|
||||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a function file and creates independent DocFunction objects of type FUNCTION
|
||||
*/
|
||||
public static DocFunction[] newFunctions(File location) {
|
||||
return newFunctions(location, null);
|
||||
public static DocFunction[] newFunctions(Resource res) {
|
||||
return newFunctions(res, null);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class DocFunction extends DocFileElement {
|
|||
* reads a function file and creates DocFunction objects of type FUNCTION
|
||||
* connected to another DocElement.
|
||||
*/
|
||||
public static DocFunction[] newFunctions(File location, DocElement parent) {
|
||||
public static DocFunction[] newFunctions(Resource res, DocElement parent) {
|
||||
|
||||
Vector vec = new Vector();
|
||||
|
||||
|
@ -89,16 +90,16 @@ public class DocFunction extends DocFileElement {
|
|||
String functionName = null;
|
||||
String context = null;
|
||||
|
||||
TokenStream ts = getTokenStream (location);
|
||||
TokenStream ts = getTokenStream (res);
|
||||
|
||||
while (!ts.eof()) {
|
||||
|
||||
// store the position of the last token
|
||||
endOfLastToken = getPoint (ts);
|
||||
|
||||
|
||||
// store last token
|
||||
lastToken = token;
|
||||
|
||||
|
||||
// now get a new token
|
||||
// regular expression syntax is troublesome for the TokenStream
|
||||
// we can safely ignore syntax errors in regular expressions here
|
||||
|
@ -117,7 +118,7 @@ public class DocFunction extends DocFileElement {
|
|||
context = ts.getString();
|
||||
|
||||
} else if (token == Token.RC && context != null) {
|
||||
|
||||
|
||||
// when we come across a right brace outside of a function,
|
||||
// we reset the current context cache
|
||||
context = null;
|
||||
|
@ -148,7 +149,7 @@ public class DocFunction extends DocFileElement {
|
|||
}
|
||||
|
||||
} else if (token == Token.FUNCTION) {
|
||||
|
||||
|
||||
// store the end of the function word
|
||||
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
|
||||
// declaration like this: function abc() {}
|
||||
|
||||
|
||||
// set the pointer for the start of the actual function body
|
||||
// to the letter f of the function word
|
||||
startOfFunctionBody = p;
|
||||
|
@ -176,7 +177,7 @@ public class DocFunction extends DocFileElement {
|
|||
functionName = ts.getString();
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// it's a different kind of function declaration.
|
||||
// the function name is the last found NAME-token
|
||||
// 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) ...
|
||||
String rawComment = Util.getStringFromFile(location, endOfLastUsedToken, startOfFunctionBody).trim ();
|
||||
String rawComment = Util.getStringFromFile(res, endOfLastUsedToken, startOfFunctionBody).trim ();
|
||||
// .. and clean it
|
||||
rawComment = Util.chopComment (rawComment);
|
||||
|
||||
// create the function object
|
||||
DocFunction theFunction = newFunction (functionName, location, parent);
|
||||
DocFunction theFunction = newFunction (functionName, res, parent);
|
||||
theFunction.parseComment (rawComment);
|
||||
vec.add (theFunction);
|
||||
|
||||
|
@ -221,8 +222,8 @@ public class DocFunction extends DocFileElement {
|
|||
}
|
||||
}
|
||||
endOfFunctionBody = getPoint(ts);
|
||||
|
||||
theFunction.content = Util.getStringFromFile(location, startOfFunctionBody, endOfFunctionBody);
|
||||
|
||||
theFunction.content = Util.getStringFromFile(res, startOfFunctionBody, endOfFunctionBody);
|
||||
|
||||
} // end if
|
||||
} // 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")) {
|
||||
return new DocFunction(funcName, location, parent, ACTION);
|
||||
return new DocFunction(funcName, res, parent, ACTION);
|
||||
} else if (funcName.endsWith("_macro")) {
|
||||
return new DocFunction(funcName, location, parent, MACRO);
|
||||
return new DocFunction(funcName, res, parent, MACRO);
|
||||
} 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
|
||||
*/
|
||||
protected static TokenStream getTokenStream (File f) {
|
||||
FileReader reader = null;
|
||||
protected static TokenStream getTokenStream (Resource res) throws IOException {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new FileReader(f);
|
||||
reader = new InputStreamReader(res.getInputStream());
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
fnfe.printStackTrace();
|
||||
throw new DocException (fnfe.toString());
|
||||
}
|
||||
String name = f.getName();
|
||||
String name = res.getName();
|
||||
int line = 0;
|
||||
CompilerEnvirons compilerEnv = new CompilerEnvirons();
|
||||
compilerEnv.initFromContext(Context.getCurrentContext());
|
||||
|
|
|
@ -16,59 +16,52 @@
|
|||
|
||||
package helma.doc;
|
||||
|
||||
import helma.util.SystemProperties;
|
||||
import java.io.*;
|
||||
import helma.util.ResourceProperties;
|
||||
import helma.framework.repository.Resource;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Documentation around a properties file
|
||||
*/
|
||||
public class DocProperties extends DocFileElement {
|
||||
Properties props = null;
|
||||
public class DocProperties extends DocResourceElement {
|
||||
|
||||
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;
|
||||
content = Util.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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
this.props = props;
|
||||
this.comment = resource.getName();
|
||||
this.content = resource.getContent();
|
||||
this.elementName = name + "_" + index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying properties
|
||||
*
|
||||
*
|
||||
* @return ...
|
||||
* @return the properties
|
||||
*/
|
||||
public Properties getProperties() {
|
||||
public ResourceProperties getProperties() {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import helma.framework.repository.Resource;
|
||||
import helma.framework.core.Prototype;
|
||||
import helma.util.ResourceProperties;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DocPrototype extends DocDirElement {
|
||||
private DocProperties typeProperties = null;
|
||||
private DocPrototype parentPrototype = null;
|
||||
public class DocPrototype extends DocElement {
|
||||
|
||||
private DocPrototype(String name, File location, DocElement parent) {
|
||||
super(name, location, PROTOTYPE);
|
||||
this.parent = parent;
|
||||
typeProperties = DocProperties.newInstance(new File(location, "type.properties"));
|
||||
}
|
||||
DocPrototype parentPrototype = null;
|
||||
Prototype proto;
|
||||
|
||||
/**
|
||||
* creates a prototype that is independent of an
|
||||
* application object
|
||||
* @param location
|
||||
*/
|
||||
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
|
||||
* creates a prototype based on a prototype of the application
|
||||
*
|
||||
* @param proto
|
||||
* @param parent
|
||||
*/
|
||||
public static DocPrototype newInstance(File location, DocElement parent) {
|
||||
DocPrototype pt = new DocPrototype(location.getName(), location, parent);
|
||||
|
||||
return pt;
|
||||
*/ protected DocPrototype(Prototype proto, DocElement parent) {
|
||||
super(proto.getName(), PROTOTYPE);
|
||||
this.parent = parent;
|
||||
this.proto = proto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,15 +54,12 @@ public class DocPrototype extends DocDirElement {
|
|||
return;
|
||||
}
|
||||
|
||||
if (typeProperties != null) {
|
||||
// check for "_extends" in the the type.properties
|
||||
String ext = typeProperties.getProperties().getProperty("_extends");
|
||||
// check for "_extends" in the the type.properties
|
||||
String ext = proto.getTypeProperties().getProperty("_extends");
|
||||
|
||||
if ((ext != null) && (parent != null)) {
|
||||
// try to get the prototype if available
|
||||
parentPrototype = (DocPrototype) parent.getChildElement("prototype_" +
|
||||
ext);
|
||||
}
|
||||
if ((ext != null) && (parent != null)) {
|
||||
// try to get the prototype if available
|
||||
parentPrototype = (DocPrototype) parent.getChildElement("prototype_" + ext);
|
||||
}
|
||||
|
||||
if ((parentPrototype == null) && (parent != null) && !name.equals("global")) {
|
||||
|
@ -82,63 +69,66 @@ public class DocPrototype extends DocDirElement {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return this prototype's parent prototype
|
||||
*
|
||||
*
|
||||
* @return ...
|
||||
* @return this prototype's parent prototype
|
||||
*/
|
||||
public DocPrototype getParentPrototype() {
|
||||
return parentPrototype;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public DocProperties getTypeProperties() {
|
||||
return typeProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* runs through the prototype directory and parses all helma files
|
||||
*/
|
||||
public void readFiles() {
|
||||
public void readFiles() throws IOException {
|
||||
children.clear();
|
||||
|
||||
String[] arr = location.list();
|
||||
Iterator it = proto.getCodeResources();
|
||||
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (getDocApplication().isExcluded(arr[i])) {
|
||||
continue;
|
||||
}
|
||||
while (it.hasNext()) {
|
||||
Resource res = (Resource) it.next();
|
||||
|
||||
File f = new File(location.getAbsolutePath(), arr[i]);
|
||||
|
||||
if (f.isDirectory()) {
|
||||
String name = res.getShortName();
|
||||
if (getDocApplication().isExcluded(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if (arr[i].endsWith(".skin")) {
|
||||
addChild(DocSkin.newInstance(f, this));
|
||||
} else if (arr[i].endsWith(".properties")) {
|
||||
continue;
|
||||
} else if (arr[i].endsWith(".hac")) {
|
||||
addChild(DocFunction.newAction(f, this));
|
||||
} else if (arr[i].endsWith(".js")) {
|
||||
DocElement[] elements = DocFunction.newFunctions(f, this);
|
||||
if (name.endsWith(".hac")) {
|
||||
addChild(DocFunction.newAction(res, this));
|
||||
} else if (name.endsWith(".js")) {
|
||||
DocElement[] elements = DocFunction.newFunctions(res, this);
|
||||
|
||||
for (int j = 0; j < elements.length; j++) {
|
||||
addChild(elements[j]);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("couldn't parse file " + f.getAbsolutePath() + ": " +
|
||||
ex.toString());
|
||||
ex.printStackTrace();
|
||||
} catch (Throwable err) {
|
||||
System.out.println("couldn't parse file " + f.getAbsolutePath() + ": " +
|
||||
err.toString());
|
||||
proto.getApplication().logError("Couldn't parse file " + res, err);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import helma.framework.repository.Repository;
|
||||
import helma.framework.repository.Resource;
|
||||
|
||||
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
|
||||
// and prototypes if found in their directories
|
||||
public static final String[] DOCFILES = {
|
||||
|
@ -30,17 +36,40 @@ public abstract class DocDirElement extends DocElement {
|
|||
"prototype.htm", "index.html", "index.htm"
|
||||
};
|
||||
|
||||
protected DocDirElement(String name, File location, int type) {
|
||||
super(name, location, type);
|
||||
protected DocRepositoryElement(String name, Repository repos, int type) throws IOException {
|
||||
super(name, type);
|
||||
this.repos = repos;
|
||||
checkCommentFiles();
|
||||
}
|
||||
|
||||
private void checkCommentFiles() throws DocException {
|
||||
for (int i = 0; i < DOCFILES.length; i++) {
|
||||
File f = new File(location, DOCFILES[i]);
|
||||
/**
|
||||
* Get a string describing this element's location
|
||||
*
|
||||
* @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);
|
||||
|
|
@ -16,19 +16,27 @@
|
|||
|
||||
package helma.doc;
|
||||
|
||||
import java.io.File;
|
||||
import helma.framework.repository.Resource;
|
||||
|
||||
/**
|
||||
* abstract class for extracting doc information from files.
|
||||
* not used at the moment but left in for further extensions-
|
||||
*/
|
||||
public abstract class DocFileElement extends DocElement {
|
||||
protected DocFileElement(String name, File location, int type) {
|
||||
super(name, location, type);
|
||||
public abstract class DocResourceElement extends DocElement {
|
||||
|
||||
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;
|
||||
|
||||
import java.io.*;
|
||||
import helma.framework.repository.Resource;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DocSkin extends DocFileElement {
|
||||
protected DocSkin(String name, File location, DocElement parent) {
|
||||
super(name, location, SKIN);
|
||||
public class DocSkin extends DocResourceElement {
|
||||
|
||||
protected DocSkin(String name, Resource res, DocElement parent) throws IOException {
|
||||
super(name, res, SKIN);
|
||||
this.parent = parent;
|
||||
content = Util.readFile(location);
|
||||
content = res.getContent();
|
||||
parseHandlers();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new independent DocSkin object
|
||||
*/
|
||||
public static DocSkin newInstance(File location) {
|
||||
return newInstance(location, null);
|
||||
public static DocSkin newInstance(Resource res) throws IOException {
|
||||
return newInstance(res, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new DocSkin object connected to another DocElement
|
||||
*/
|
||||
public static DocSkin newInstance(File location, DocElement parent) {
|
||||
String skinname = Util.nameFromFile(location, ".skin");
|
||||
DocSkin skin = new DocSkin(skinname, location, parent);
|
||||
|
||||
return skin;
|
||||
public static DocSkin newInstance(Resource res, DocElement parent) throws IOException {
|
||||
String skinname = res.getBaseName();
|
||||
return new DocSkin(skinname, res, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,7 @@ public final class DocTag {
|
|||
name = tok.nextToken();
|
||||
}
|
||||
while (tok.hasMoreTokens()) {
|
||||
comment.append (" " + tok.nextToken());
|
||||
comment.append (" ").append(tok.nextToken());
|
||||
}
|
||||
} catch (NoSuchElementException nsee) { // ignore
|
||||
}
|
||||
|
@ -143,9 +143,9 @@ public final class DocTag {
|
|||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer ("[@" + type);
|
||||
if (name!=null && !"".equals(name))
|
||||
buf.append (" " + name);
|
||||
buf.append (" ").append(name);
|
||||
if (text!=null && !"".equals(text))
|
||||
buf.append (" " + text);
|
||||
buf.append (" ").append(text);
|
||||
return buf.toString() + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package helma.doc;
|
||||
|
||||
import helma.framework.repository.Resource;
|
||||
|
||||
import java.awt.Point;
|
||||
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
|
||||
|
||||
|
@ -104,11 +78,11 @@ public final class Util {
|
|||
|
||||
* @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();
|
||||
int ct = 0;
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(sourceFile));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(res.getInputStream()));
|
||||
String line = "";
|
||||
while (line != null) {
|
||||
line = in.readLine();
|
||||
|
@ -116,13 +90,13 @@ public final class Util {
|
|||
break;
|
||||
}
|
||||
if ((ct > start.y) && (ct < end.y)) {
|
||||
buf.append(line + "\n");
|
||||
buf.append(line).append("\n");
|
||||
} else if (ct == start.y) {
|
||||
if (start.y==end.y) {
|
||||
buf.append (line.substring (start.x, end.x));
|
||||
break;
|
||||
} 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) {
|
||||
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() {
|
||||
if (doc == null) {
|
||||
doc = new DocApplication(app);
|
||||
doc.readApplication();
|
||||
try {
|
||||
doc = new DocApplication(app);
|
||||
doc.readApplication();
|
||||
} catch (IOException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue