jvanzyl 02/02/26 06:45:55
Modified: src/java/org/apache/maven/jxr CodeTransform.java
DirectoryIndexer.java JXR.java JxrTask.java
Removed: src/java/org/apache/maven/jxr/util MetaData.java
StringUtil.java Util.java
Log:
The xref tool no long depends on the maven project om so it can be
used outside the context of maven.
Revision Changes Path
1.6 +395 -200
jakarta-turbine-maven/src/java/org/apache/maven/jxr/CodeTransform.java
Index: CodeTransform.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jxr/CodeTransform.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CodeTransform.java 24 Feb 2002 18:37:07 -0000 1.5
+++ CodeTransform.java 26 Feb 2002 14:45:54 -0000 1.6
@@ -30,15 +30,16 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.*;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.apache.commons.util.StringUtils;
+
import org.apache.maven.jxr.pacman.*;
-import org.apache.maven.jxr.util.MetaData;
import org.apache.maven.jxr.util.SimpleWordTokenizer;
import org.apache.maven.jxr.util.StringEntry;
-import org.apache.maven.jxr.util.Util;
-import java.io.*;
-import java.util.Hashtable;
-import java.util.Vector;
/**
* Syntax highlights java by turning it into html. A codeviewer object is
@@ -66,39 +67,61 @@
* importFilter
* </pre>
*/
-public class CodeTransform implements Serializable {
-
- /** Description of the Field */
+public class CodeTransform implements Serializable
+{
+ /**
+ * Description of the Field
+ */
public final static boolean LINE_NUMBERS = true;
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String BACKGROUND_COLOR = "#ffffff";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String COMMENT_START = "<font color=\"#329900\"><i>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String COMMENT_END = "</font></i>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String JAVADOC_COMMENT_START = "<font
color=\"#AA0000\"><i>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String JAVADOC_COMMENT_END = "</font></i>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String STRING_START = "<font color=\"#000099\">";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String STRING_END = "</font>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String RESERVED_WORD_START = "<b>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String RESERVED_WORD_END = "</b>";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String[] VALID_URI_SCHEMES = {"http://", "mailto:"};
/**
@@ -116,27 +139,37 @@
private boolean inJavadocComment = false;
- /** Keep a handle on the current metadata */
- private MetaData metadata;
-
- /** Set the filename that is currently being processed. */
+ /**
+ * Set the filename that is currently being processed.
+ */
private String currentFilename = null;
- /** The current CVS revision of the currently transformed documnt */
+ /**
+ * The current CVS revision of the currently transformed documnt
+ */
private String revision = null;
- /** The currently being transformed source file */
+ /**
+ * The currently being transformed source file
+ */
private String sourcefile = null;
- /** The currently being written destfile */
+ /**
+ * The currently being written destfile
+ */
private String destfile = null;
- /** The virtual source directory that is being read from: src/java */
+ /**
+ * The virtual source directory that is being read from: src/java
+ */
private String sourcedir = null;
- /** Constructor for the CodeTransform object */
- public CodeTransform() {
+ /**
+ * Constructor for the CodeTransform object
+ */
+ public CodeTransform()
+ {
loadHash();
}
@@ -145,14 +178,19 @@
* Now different method of seeing if at end of input stream, closes inputs
* stream at end.
*/
- public final String syntaxHighlight(String line) {
+ public final String syntaxHighlight(String line)
+ {
return htmlFilter(line);
}
- /** Filter html tags into more benign text. */
- private final String htmlFilter(String line) {
+ /**
+ * Filter html tags into more benign text.
+ */
+ private final String htmlFilter(String line)
+ {
StringBuffer buf = new StringBuffer();
- if (line == null || line.equals("")) {
+ if (line == null || line.equals(""))
+ {
return "";
}
line = replace(line, "<", "<");
@@ -168,8 +206,10 @@
* Filter out multiLine comments. State is kept with a private boolean
* variable.
*/
- private final String multiLineCommentFilter(String line) {
- if (line == null || line.equals("")) {
+ private final String multiLineCommentFilter(String line)
+ {
+ if (line == null || line.equals(""))
+ {
return "";
}
StringBuffer buf = new StringBuffer();
@@ -177,12 +217,14 @@
//First, check for the end of a java comment.
if (inJavadocComment &&
- (index = line.indexOf("*/")) > -1 && !isInsideString(line, index)) {
+ (index = line.indexOf("*/")) > -1 && !isInsideString(line, index))
+ {
inJavadocComment = false;
buf.append(JAVADOC_COMMENT_START);
buf.append(line.substring(0, index));
buf.append("*/").append(JAVADOC_COMMENT_END);
- if (line.length() > index + 2) {
+ if (line.length() > index + 2)
+ {
buf.append(inlineCommentFilter(line.substring(index + 2)));
}
@@ -190,12 +232,14 @@
}
//Second, check for the end of a multi-line comment.
- if (inMultiLineComment && (index = line.indexOf("*/")) > -1 &&
!isInsideString(line, index)) {
+ if (inMultiLineComment && (index = line.indexOf("*/")) > -1 &&
!isInsideString(line, index))
+ {
inMultiLineComment = false;
buf.append(COMMENT_START);
buf.append(line.substring(0, index));
buf.append("*/").append(COMMENT_END);
- if (line.length() > index + 2) {
+ if (line.length() > index + 2)
+ {
buf.append(inlineCommentFilter(line.substring(index + 2)));
}
return uriFilter(buf.toString());
@@ -203,13 +247,16 @@
//If there was no end detected and we're currently in a multi-line
//comment, we don't want to do anymore work, so return line.
- else if (inMultiLineComment) {
+ else if (inMultiLineComment)
+ {
StringBuffer buffer = new StringBuffer(line);
buffer.insert(0, COMMENT_START);
buffer.append(COMMENT_END);
return uriFilter(buffer.toString());
- } else if (inJavadocComment) {
+ }
+ else if (inJavadocComment)
+ {
StringBuffer buffer = new StringBuffer(line);
buffer.insert(0, JAVADOC_COMMENT_START);
@@ -219,7 +266,8 @@
//We're not currently in a Javadoc comment, so check to see if the start
//of a multi-line Javadoc comment is in this line.
- else if ((index = line.indexOf("/**")) > -1 && !isInsideString(line,
index)) {
+ else if ((index = line.indexOf("/**")) > -1 && !isInsideString(line, index))
+ {
inJavadocComment = true;
//Return result of other filters + everything after the start
//of the multiline comment. We need to pass the through the
@@ -234,7 +282,8 @@
//We're not currently in a comment, so check to see if the start
//of a multi-line comment is in this line.
- else if ((index = line.indexOf("/*")) > -1 && !isInsideString(line, index))
{
+ else if ((index = line.indexOf("/*")) > -1 && !isInsideString(line, index))
+ {
inMultiLineComment = true;
//Return result of other filters + everything after the start
//of the multiline comment. We need to pass the through the
@@ -249,7 +298,8 @@
//Otherwise, no useful multi-line comment information was found so
//pass the line down to the next filter for processesing.
- else {
+ else
+ {
return inlineCommentFilter(line);
}
}
@@ -262,31 +312,41 @@
* isInsideString(line, index) where index points to some point in the line
* that we need to check... started doing this function below.
*/
- private final String inlineCommentFilter(String line) {
- if (line == null || line.equals("")) {
+ private final String inlineCommentFilter(String line)
+ {
+ if (line == null || line.equals(""))
+ {
return "";
}
StringBuffer buf = new StringBuffer();
int index;
- if ((index = line.indexOf("//")) > -1 && !isInsideString(line, index)) {
+ if ((index = line.indexOf("//")) > -1 && !isInsideString(line, index))
+ {
buf.append(stringFilter(line.substring(0, index)));
buf.append(COMMENT_START);
buf.append(line.substring(index));
buf.append(COMMENT_END);
- } else {
+ }
+ else
+ {
buf.append(stringFilter(line));
}
return buf.toString();
}
- /** Filters strings from a line of text and formats them properly. */
- private final String stringFilter(String line) {
+ /**
+ * Filters strings from a line of text and formats them properly.
+ */
+ private final String stringFilter(String line)
+ {
- if (line == null || line.equals("")) {
+ if (line == null || line.equals(""))
+ {
return "";
}
StringBuffer buf = new StringBuffer();
- if (line.indexOf("\"") <= -1) {
+ if (line.indexOf("\"") <= -1)
+ {
return keywordFilter(line);
}
int start = 0;
@@ -294,16 +354,19 @@
int endStringIndex = -1;
int tempIndex;
//Keep moving through String characters until we want to stop...
- while ((tempIndex = line.indexOf("\"")) > -1) {
+ while ((tempIndex = line.indexOf("\"")) > -1)
+ {
//We found the beginning of a string
- if (startStringIndex == -1) {
+ if (startStringIndex == -1)
+ {
startStringIndex = 0;
buf.append(stringFilter(line.substring(start, tempIndex)));
buf.append(STRING_START).append("\"");
line = line.substring(tempIndex + 1);
}
//Must be at the end
- else {
+ else
+ {
startStringIndex = -1;
endStringIndex = tempIndex;
buf.append(line.substring(0, endStringIndex + 1));
@@ -320,8 +383,10 @@
/**
* Filters keywords from a line of text and formats them properly.
*/
- private final String keywordFilter(String line) {
- if (line == null || line.equals("")) {
+ private final String keywordFilter(String line)
+ {
+ if (line == null || line.equals(""))
+ {
return "";
}
StringBuffer buf = new StringBuffer();
@@ -331,24 +396,30 @@
int startAt = 0;
char ch;
StringBuffer temp = new StringBuffer();
- while (i < line.length()) {
+ while (i < line.length())
+ {
temp.setLength(0);
ch = line.charAt(i);
startAt = i;
while (i < line.length() && ((ch >= 65 && ch <= 90)
- || (ch >= 97 && ch <= 122))) {
+ || (ch >= 97 && ch <= 122)))
+ {
temp.append(ch);
i++;
- if (i < line.length()) {
+ if (i < line.length())
+ {
ch = line.charAt(i);
}
}
String tempString = temp.toString();
- if (reservedWords.containsKey(tempString) &&
!usedReservedWords.containsKey(tempString)) {
+ if (reservedWords.containsKey(tempString) &&
!usedReservedWords.containsKey(tempString))
+ {
usedReservedWords.put(tempString, tempString);
line = replace(line, tempString, (RESERVED_WORD_START + tempString
+ RESERVED_WORD_END));
i += (RESERVED_WORD_START.length() + RESERVED_WORD_END.length());
- } else {
+ }
+ else
+ {
i++;
}
}
@@ -359,9 +430,11 @@
/**
* Replace... I made it use a stringBuffer... hope it still works :)
*/
- private final String replace(String line, String oldString, String newString) {
+ private final String replace(String line, String oldString, String newString)
+ {
int i = 0;
- while ((i = line.indexOf(oldString, i)) >= 0) {
+ while ((i = line.indexOf(oldString, i)) >= 0)
+ {
line = (new StringBuffer().append(line.substring(0,
i)).append(newString).append(line.substring(i + oldString.length()))).toString();
i += newString.length();
}
@@ -372,8 +445,10 @@
* Checks to see if some position in a line is between String start and
* ending characters. Not yet used in code or fully working :)
*/
- private final boolean isInsideString(String line, int position) {
- if (line.indexOf("\"") < 0) {
+ private final boolean isInsideString(String line, int position)
+ {
+ if (line.indexOf("\"") < 0)
+ {
return false;
}
int index;
@@ -381,23 +456,31 @@
String right = line.substring(position);
int leftCount = 0;
int rightCount = 0;
- while ((index = left.indexOf("\"")) > -1) {
+ while ((index = left.indexOf("\"")) > -1)
+ {
leftCount++;
left = left.substring(index + 1);
}
- while ((index = right.indexOf("\"")) > -1) {
+ while ((index = right.indexOf("\"")) > -1)
+ {
rightCount++;
right = right.substring(index + 1);
}
- if (rightCount % 2 != 0 && leftCount % 2 != 0) {
+ if (rightCount % 2 != 0 && leftCount % 2 != 0)
+ {
return true;
- } else {
+ }
+ else
+ {
return false;
}
}
- /** Description of the Method */
- private final void loadHash() {
+ /**
+ * Description of the Method
+ */
+ private final void loadHash()
+ {
reservedWords.put("abstract", "abstract");
reservedWords.put("do", "do");
reservedWords.put("inner", "inner");
@@ -453,52 +536,65 @@
reservedWords.put("try", "try");
}
- /** Description of the Method */
+ /**
+ * Description of the Method
+ */
final void writeObject(ObjectOutputStream oos)
- throws IOException {
+ throws IOException
+ {
oos.defaultWriteObject();
}
- /** Description of the Method */
+ /**
+ * Description of the Method
+ */
final void readObject(ObjectInputStream ois)
- throws ClassNotFoundException, IOException {
+ throws ClassNotFoundException, IOException
+ {
ois.defaultReadObject();
}
- /** Gets the header attribute of the CodeTransform object */
- public final String getHeader() {
+ /**
+ * Gets the header attribute of the CodeTransform object
+ */
+ public final String getHeader()
+ {
//FIX ME: migrate this to use ECS
return "<html>\n" +
- "<body bgcolor=\"white\">\n" +
- "<pre>\n" + this.getFileOverview();
+ "<body bgcolor=\"white\">\n" +
+ "<pre>\n" + this.getFileOverview();
}
- /** Gets the footer attribute of the CodeTransform object */
- public final String getFooter() {
+ /**
+ * Gets the footer attribute of the CodeTransform object
+ */
+ public final String getFooter()
+ {
//FIX ME: migrate this to use ECS
return "</pre>\n" +
- "<hr>" +
- "<center>" + JXR.NOTICE + "</center>" +
- "</body>\n" +
- "</html>\n";
+ "<hr>" +
+ "<center>" + JXR.NOTICE + "</center>" +
+ "</body>\n" +
+ "</html>\n";
}
- /** This is the public method for doing all transforms of code. */
+ /**
+ * This is the public method for doing all transforms of code.
+ */
public final void transform(String sourcefile,
String destfile,
- String revision,
- MetaData metadata)
- throws IOException {
+ String revision)
+ throws IOException
+ {
this.setCurrentFilename(sourcefile);
this.sourcefile = sourcefile;
this.destfile = destfile;
this.revision = revision;
- this.metadata = metadata;
//make sure that the parent directories exist...
new File(new File(destfile).getParent()).mkdirs();
@@ -512,12 +608,14 @@
out.println(getHeader());
int linenumber = 1;
- while ((line = in.readLine()) != null) {
- if (LINE_NUMBERS) {
+ while ((line = in.readLine()) != null)
+ {
+ if (LINE_NUMBERS)
+ {
out.print("<a name=\"" + linenumber + "\" " +
- "href=\"#" + linenumber + "\">" +
- linenumber +
- "</a>" + getLineWidth(linenumber));
+ "href=\"#" + linenumber + "\">" +
+ linenumber +
+ "</a>" + getLineWidth(linenumber));
}
out.println(this.syntaxHighlight(line));
@@ -530,31 +628,40 @@
}
- /** Get an overview header for this file. */
- private final String getFileOverview() {
+ /**
+ * Get an overview header for this file.
+ */
+ private final String getFileOverview()
+ {
StringBuffer overview = new StringBuffer();
overview.append("<table bgcolor=\"#FFFFCC\" cellpadding=\"0\"
cellspacing=\"0\" border=\"0\" width=\"100%\">");
//get the URI to get Javadoc info.
StringBuffer javadocURI = new StringBuffer()
- .append(getPackageRoot())
- .append("../apidocs");
+ .append(getPackageRoot())
+ .append("../apidocs");
- try {
+ try
+ {
JavaFile jf =
FileManager.getInstance().getFile(this.getCurrentFilename());
javadocURI.append("/");
- javadocURI.append(Util.replace(jf.getPackageType().getName(), ".",
"/"));
+ javadocURI.append(StringUtils.replace(jf.getPackageType().getName(),
".", "/"));
javadocURI.append("/");
- if (jf.getClassType() != null) {
+ if (jf.getClassType() != null)
+ {
javadocURI.append(jf.getClassType().getName());
- } else {
+ }
+ else
+ {
System.out.println(this.getCurrentFilename());
}
javadocURI.append(".html");
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
e.printStackTrace();
}
@@ -566,8 +673,11 @@
return overview.toString();
}
- /** Gets the overviewEntry attribute of the CodeTransform object */
- private final String getOverviewEntry(String name, String value) {
+ /**
+ * Gets the overviewEntry attribute of the CodeTransform object
+ */
+ private final String getOverviewEntry(String name, String value)
+ {
StringBuffer buff = new StringBuffer();
@@ -592,8 +702,11 @@
return buff.toString();
}
- /** Gets the overviewEntry attribute of the CodeTransform object */
- private final String getOverviewEntry(String name, String value, String right) {
+ /**
+ * Gets the overviewEntry attribute of the CodeTransform object
+ */
+ private final String getOverviewEntry(String name, String value, String right)
+ {
StringBuffer buff = new StringBuffer();
@@ -632,12 +745,18 @@
* Handles line width which may need to change depending on which line
* number you are on.
*/
- private final String getLineWidth(int linenumber) {
- if (linenumber < 10) {
+ private final String getLineWidth(int linenumber)
+ {
+ if (linenumber < 10)
+ {
return " ";
- } else if (linenumber < 100) {
+ }
+ else if (linenumber < 100)
+ {
return " ";
- } else {
+ }
+ else
+ {
return " ";
}
}
@@ -646,19 +765,24 @@
* Handles finding classes based on the current filename and then makes
* HREFs for you to link to them with.
*/
- private final String jxrFilter(String line) {
+ private final String jxrFilter(String line)
+ {
JavaFile jf = null;
- try {
+ try
+ {
//if the current file isn't set then just return
- if (this.getCurrentFilename() == null) {
+ if (this.getCurrentFilename() == null)
+ {
return line;
}
jf = FileManager.getInstance().getFile(this.getCurrentFilename());
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
e.printStackTrace();
return line;
}
@@ -667,7 +791,8 @@
//get the imported packages
ImportType[] imports = jf.getImportTypes();
- for (int j = 0; j < imports.length; ++j) {
+ for (int j = 0; j < imports.length; ++j)
+ {
v.addElement(imports[j].getPackage());
}
@@ -680,24 +805,27 @@
StringEntry[] words = SimpleWordTokenizer.tokenize(line);
//go through each word and then match them to the correct class if
necessary.
- for (int i = 0; i < words.length; ++i) {
+ for (int i = 0; i < words.length; ++i)
+ {
//each word
StringEntry word = words[i];
- for (int j = 0; j < packages.length; ++j) {
+ for (int j = 0; j < packages.length; ++j)
+ {
//get the package from teh PackageManager because this will hold
//the version with the classes also.
PackageType currentImport = PackageManager.getInstance()
- .getPackageType(packages[j]);
+ .getPackageType(packages[j]);
//the package here might in fact be null because it wasn't parsed
out
//this might be something that is either not included or os part
//of another package and wasn't parsed out.
- if (currentImport == null) {
+ if (currentImport == null)
+ {
continue;
}
@@ -708,7 +836,8 @@
String wordName = word.toString();
- if (wordName.indexOf(".") != -1) {
+ if (wordName.indexOf(".") != -1)
+ {
//if there is a "." in the string then we have to assume
//it is a package.
@@ -731,11 +860,13 @@
PackageType pt =
PackageManager.getInstance().getPackageType(fqpn_package);
- if (pt != null) {
+ if (pt != null)
+ {
ClassType ct = pt.getClassType(fqpn_class);
- if (ct != null) {
+ if (ct != null)
+ {
//OK. the user specified a full package to be imported
//that is in the package manager so it is time to
//link to it.
@@ -748,7 +879,8 @@
}
if (fqpn_package.equals(currentImport.getName()) &&
- currentImport.getClassType(fqpn_class) != null) {
+ currentImport.getClassType(fqpn_class) != null)
+ {
//then the package we are currently in is the one specified
in the string
//and the import class is correct.
@@ -758,7 +890,9 @@
}
- } else if (currentImport.getClassType(wordName) != null) {
+ }
+ else if (currentImport.getClassType(wordName) != null)
+ {
//System.out.println( "FIX ME: found imported class: "+
wordName );
line = xrLine(line, packages[j],
currentImport.getClassType(wordName));
@@ -772,13 +906,19 @@
return importFilter(line);
}
- /** Get the current filename */
- public final String getCurrentFilename() {
+ /**
+ * Get the current filename
+ */
+ public final String getCurrentFilename()
+ {
return this.currentFilename;
}
- /** Set the current filename */
- public final void setCurrentFilename(String filename) {
+ /**
+ * Set the current filename
+ */
+ public final void setCurrentFilename(String filename)
+ {
this.currentFilename = filename;
}
@@ -786,7 +926,8 @@
* Given the current package, get an HREF to the package and class given
*/
private final String getHREF(String dest,
- ClassType jc) {
+ ClassType jc)
+ {
StringBuffer href = new StringBuffer();
@@ -795,13 +936,14 @@
href.append(this.getPackageRoot());
//now find out how to get to the dest package
- dest = Util.replace(dest, ".*", "");
- dest = Util.replace(dest, ".", "/");
+ dest = StringUtils.replace(dest, ".*", "");
+ dest = StringUtils.replace(dest, ".", "/");
href.append(dest);
//now append the classname.html file
- if (jc != null) {
+ if (jc != null)
+ {
href.append("/");
href.append(jc.getName());
href.append(".html");
@@ -810,8 +952,11 @@
return href.toString();
}
- /** Based on the destination package, get the HREF. */
- private final String getHREF(String dest) {
+ /**
+ * Based on the destination package, get the HREF.
+ */
+ private final String getHREF(String dest)
+ {
return getHREF(dest, null);
}
@@ -823,9 +968,11 @@
*
* EX: org.apache.maven == 3 </p>
*/
- private final int getPackageCount(String packageName) {
+ private final int getPackageCount(String packageName)
+ {
- if (packageName == null) {
+ if (packageName == null)
+ {
return 0;
}
@@ -833,11 +980,13 @@
int index = 0;
- while (true) {
+ while (true)
+ {
index = packageName.indexOf(".", index);
- if (index == -1) {
+ if (index == -1)
+ {
break;
}
++index;
@@ -854,7 +1003,8 @@
* Parse out the current link and look for package/import statements and
* then create HREFs for them
*/
- private final String importFilter(String line) {
+ private final String importFilter(String line)
+ {
int start = -1;
@@ -869,12 +1019,14 @@
//
if (line.indexOf("import") != -1 ||
- isPackage) {
+ isPackage)
+ {
start = line.trim().indexOf(" ");
}
- if (start != -1) {
+ if (start != -1)
+ {
//filter out this packagename...
@@ -883,11 +1035,14 @@
//specify the classname of this import if any.
String classname = null;
- if (pkg.indexOf(".*") != -1) {
+ if (pkg.indexOf(".*") != -1)
+ {
- pkg = Util.replace(pkg, ".*", "");
+ pkg = StringUtils.replace(pkg, ".*", "");
- } else if (isPackage == false) {
+ }
+ else if (isPackage == false)
+ {
//this is an explicit Class import
@@ -897,7 +1052,8 @@
int end = pkg.lastIndexOf(".");
- if (end == -1) {
+ if (end == -1)
+ {
end = pkg.length() - 1;
}
@@ -905,35 +1061,37 @@
}
- pkg = Util.replace(pkg, ";", "");
+ pkg = StringUtils.replace(pkg, ";", "");
//if this package is within the PackageManager then you can create an
HREF for it.
if (PackageManager.getInstance().getPackageType(pkg.toString()) != null
||
- isPackage) {
+ isPackage)
+ {
//Create an HREF for explicit classname imports
- if (classname != null) {
-
- line = Util.replace(line, classname, "<a href=\"" +
- this.getHREF(pkg.toString()) +
- "/" +
- classname +
- ".html" +
- "\">" +
- classname +
- "</a>");
-
- }
+ if (classname != null)
+ {
- //now replace the given package with a href
- line = Util.replace(line, pkg.toString(), "<a href=\"" +
+ line = StringUtils.replace(line, classname, "<a href=\"" +
this.getHREF(pkg.toString()) +
"/" +
- DirectoryIndexer.INDEX +
+ classname +
+ ".html" +
"\">" +
- pkg.toString() +
+ classname +
"</a>");
+
+ }
+
+ //now replace the given package with a href
+ line = StringUtils.replace(line, pkg.toString(), "<a href=\"" +
+ this.getHREF(pkg.toString()) +
+ "/" +
+ DirectoryIndexer.INDEX +
+ "\">" +
+ pkg.toString() +
+ "</a>");
}
}
@@ -946,15 +1104,19 @@
* From the current file, determine the package root based on the current
* path.
*/
- public final String getPackageRoot() {
+ public final String getPackageRoot()
+ {
StringBuffer buff = new StringBuffer();
JavaFile jf = null;
- try {
+ try
+ {
jf = FileManager.getInstance().getFile(this.getCurrentFilename());
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
e.printStackTrace();
return null;
}
@@ -963,7 +1125,8 @@
int count = this.getPackageCount(current);
- for (int i = 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i)
+ {
buff.append("../");
}
@@ -973,26 +1136,31 @@
/**
* Given a line of text, search for URIs and make href's out of them
*/
- public final String uriFilter(String line) {
+ public final String uriFilter(String line)
+ {
- for (int i = 0; i < VALID_URI_SCHEMES.length; ++i) {
+ for (int i = 0; i < VALID_URI_SCHEMES.length; ++i)
+ {
String scheme = VALID_URI_SCHEMES[i];
int index = line.indexOf(scheme);
- if (index != -1) {
+ if (index != -1)
+ {
int start = index;
int end = -1;
- for (int j = start; j < line.length(); ++j) {
+ for (int j = start; j < line.length(); ++j)
+ {
char current = line.charAt(j);
if (Character.isLetterOrDigit(current) == false &&
- isInvalidURICharacter(current)) {
+ isInvalidURICharacter(current))
+ {
end = j;
break;
}
@@ -1004,15 +1172,16 @@
//now you should have the full URI so you can replace this
//in the current buffer
- if (end != -1) {
+ if (end != -1)
+ {
String uri = line.substring(start, end);
- line = Util.replace(line, uri, "<a href=\"" +
- uri +
- "\" target=\"alexandria_uri\">" +
- uri +
- "</a>");
+ line = StringUtils.replace(line, uri, "<a href=\"" +
+ uri +
+ "\" target=\"alexandria_uri\">" +
+ uri +
+ "</a>");
}
@@ -1022,9 +1191,12 @@
//if we are in a multiline comment we should not call JXR here.
if (inMultiLineComment == false &&
- inJavadocComment == false) {
+ inJavadocComment == false)
+ {
return jxrFilter(line);
- } else {
+ }
+ else
+ {
return line;
}
@@ -1035,11 +1207,14 @@
* if the given char is not one of the following in VALID_URI_CHARS then
* return true
*/
- private final boolean isInvalidURICharacter(char c) {
+ private final boolean isInvalidURICharacter(char c)
+ {
- for (int i = 0; i < VALID_URI_CHARS.length; ++i) {
+ for (int i = 0; i < VALID_URI_CHARS.length; ++i)
+ {
- if (VALID_URI_CHARS[i] == c) {
+ if (VALID_URI_CHARS[i] == c)
+ {
return false;
}
@@ -1048,23 +1223,35 @@
return true;
}
- /** The current revision of the CVS module */
- public final String getRevision() {
+ /**
+ * The current revision of the CVS module
+ */
+ public final String getRevision()
+ {
return this.revision;
}
- /** The current source file being read */
- public final String getSourcefile() {
+ /**
+ * The current source file being read
+ */
+ public final String getSourcefile()
+ {
return this.sourcefile;
}
- /** The current dest file being written */
- public final String getDestfile() {
+ /**
+ * The current dest file being written
+ */
+ public final String getDestfile()
+ {
return this.destfile;
}
- /** The current source directory being read from. */
- public final String getSourceDirectory() {
+ /**
+ * The current source directory being read from.
+ */
+ public final String getSourceDirectory()
+ {
return this.sourcedir;
}
@@ -1074,14 +1261,16 @@
*/
public final String xrLine(String line,
String packageName,
- ClassType classType) {
+ ClassType classType)
+ {
StringBuffer buff = new StringBuffer(line);
String link = null;
String find = null;
- if (classType != null) {
+ if (classType != null)
+ {
String href = this.getHREF(packageName, classType);
@@ -1091,7 +1280,9 @@
//build out what the link would be.
link = "<a href=\"" + href + "\">" + find + "</a>";
- } else {
+ }
+ else
+ {
String href = this.getHREF(packageName);
@@ -1114,7 +1305,8 @@
StringEntry[] tokens = SimpleWordTokenizer.tokenize(buff.toString(), find);
- for (int l = 0; l < tokens.length; ++l) {
+ for (int l = 0; l < tokens.length; ++l)
+ {
int start = tokens[l].getIndex();
int end = tokens[l].getIndex() + find.length();
@@ -1126,9 +1318,12 @@
return buff.toString();
}
- /** Highlight the package in this line. */
+ /**
+ * Highlight the package in this line.
+ */
public final String xrLine(String line,
- String packageName) {
+ String packageName)
+ {
String href = this.getHREF(packageName);
@@ -1139,7 +1334,7 @@
//System.out.println( "find" );
- return Util.replace(line, find, link);
+ return StringUtils.replace(line, find, link);
}
}
1.5 +119 -67
jakarta-turbine-maven/src/java/org/apache/maven/jxr/DirectoryIndexer.java
Index: DirectoryIndexer.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jxr/DirectoryIndexer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DirectoryIndexer.java 24 Feb 2002 18:37:07 -0000 1.4
+++ DirectoryIndexer.java 26 Feb 2002 14:45:54 -0000 1.5
@@ -54,8 +54,6 @@
* <http://www.apache.org/>.
*/
-import org.apache.maven.jxr.util.Util;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -69,29 +67,46 @@
import java.util.StringTokenizer;
import java.util.Vector;
+import org.apache.commons.util.StringUtils;
+
/**
* Handles building a directory index of files and directories.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
- * @version $Id: DirectoryIndexer.java,v 1.4 2002/02/24 18:37:07 kschrader Exp $
+ * @version $Id: DirectoryIndexer.java,v 1.5 2002/02/26 14:45:54 jvanzyl Exp $
*/
-public class DirectoryIndexer {
+public class DirectoryIndexer
+{
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static int MODE_FULL = 1;
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static int MODE_JAVA = 2;
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static int MODE_DEFAULT = MODE_JAVA;
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String INDEX = "index.html";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String IMAGE_DIRECTORY = "./folder.gif";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static String IMAGE_FILE = "./file.gif";
- /** Description of the Field */
+ /**
+ * Description of the Field
+ */
public final static int IMAGE_WIDTH = 15;
private File directory = null;
@@ -100,7 +115,9 @@
private String image_file = "";
- /** Optionally specify the global root for a DirectoryIndexer. */
+ /**
+ * Optionally specify the global root for a DirectoryIndexer.
+ */
private String root = null;
private int mode = MODE_DEFAULT;
@@ -116,7 +133,8 @@
public DirectoryIndexer(String directory,
String image_folder,
String image_file)
- throws IOException {
+ throws IOException
+ {
this(directory, image_folder, image_file, MODE_JAVA);
@@ -135,7 +153,8 @@
String image_folder,
String image_file,
int mode)
- throws IOException {
+ throws IOException
+ {
this(null, directory, image_folder, image_file, mode);
@@ -156,7 +175,8 @@
String image_folder,
String image_file,
int mode)
- throws IOException {
+ throws IOException
+ {
this.root = root;
@@ -174,15 +194,17 @@
* Process the directory
*/
private final void process()
- throws IOException {
+ throws IOException
+ {
- if (!directory.isDirectory()) {
+ if (!directory.isDirectory())
+ {
throw new IOException("Not a directory");
}
String index = directory.getAbsolutePath() +
- System.getProperty("file.separator") +
- INDEX;
+ System.getProperty("file.separator") +
+ INDEX;
//System.out.println("\tWriting index file -> " + index);
@@ -195,7 +217,8 @@
//if the mode is MODE_JAVA then provide a package header for this dir.
if (this.getMode() == MODE_JAVA &&
- this.getRoot() != null) {
+ this.getRoot() != null)
+ {
String dir = this.getDirectory();
@@ -205,27 +228,34 @@
int end = dir.length();
if (start != -1 &&
- end != -1 &&
- start < end) {
+ end != -1 &&
+ start < end)
+ {
String pkg = dir.substring(start, end);
out.print("<br><p><b>Package: ");
StringTokenizer toke = new StringTokenizer(pkg,
System.getProperty("file.separator"));
- while (toke.hasMoreElements()) {
+ while (toke.hasMoreElements())
+ {
String subpkg = (String) toke.nextElement();
- if (toke.hasMoreTokens()) {
+ if (toke.hasMoreTokens())
+ {
out.print("<a href=\"");
- for (int i = 0; i < toke.countTokens(); i++) {
+ for (int i = 0; i < toke.countTokens(); i++)
+ {
out.print("../");
}
out.print(INDEX + "\">" + subpkg + "</a>.");
- } else {
+ }
+ else
+ {
out.print(subpkg);
}
}
- pkg = Util.replace(pkg, System.getProperty("file.separator"), ".");
+
+ pkg = StringUtils.replace(pkg,
System.getProperty("file.separator"), ".");
out.println("</b></p>");
@@ -246,26 +276,27 @@
items = this.getDirs();
- for (int i = 0; i < items.length; ++i) {
+ for (int i = 0; i < items.length; ++i)
+ {
String directory = items[i];
out.println(getItem(new File(directory)));
new DirectoryIndexer(this.getRoot(),
- directory,
- image_folder,
- image_file,
- this.getMode());
+ directory,
+ image_folder,
+ image_file,
+ this.getMode());
}
items = this.getFiles();
- for (int i = 0; i < items.length; ++i) {
+ for (int i = 0; i < items.length; ++i)
+ {
out.println(getItem(new File(items[i])));
}
-
out.println("</table>");
out.println("<hr>");
out.println("<center>" + JXR.NOTICE + "</center>");
@@ -279,15 +310,16 @@
/**
* Make an href for a file
- *
*/
- private final String getItem(File item) {
+ private final String getItem(File item)
+ {
String image = IMAGE_FILE;
String href = item.getName();
String name = item.getName();
- if (item.isDirectory()) {
+ if (item.isDirectory())
+ {
href = item.getName() + "/" + INDEX;
@@ -295,12 +327,14 @@
}
//potentially rip off.html links on names
- if (item.isFile()) {
+ if (item.isFile())
+ {
int start = 0;
int end = item.getName().indexOf(".html");
- if (end != -1) {
+ if (end != -1)
+ {
name = item.getName().substring(start, end);
}
@@ -309,29 +343,32 @@
//"<td width=\"" + IMAGE_WIDTH + "\"><img src=\"" + image + "\"
border=\"0\"></td>" +
return "<tr valign=\"middle\">" +
- "<td valign=\"middle\" NOWRAP><img src=\"" + image + "\"
valign=\"middle\" border=\"0\"> <a href=\"" + href + "\">" + name + "</a></td>" +
- "<td valign=\"middle\" NOWRAP>" + item.length() + " (in bytes)
</td>" +
- "<td valign=\"middle\" NOWRAP>" +
DateFormat.getDateInstance().format(new Date(item.lastModified())) + "</td>" +
- "</tr>";
+ "<td valign=\"middle\" NOWRAP><img src=\"" + image + "\"
valign=\"middle\" border=\"0\"> <a href=\"" + href + "\">" + name + "</a></td>" +
+ "<td valign=\"middle\" NOWRAP>" + item.length() + " (in bytes) </td>" +
+ "<td valign=\"middle\" NOWRAP>" +
DateFormat.getDateInstance().format(new Date(item.lastModified())) + "</td>" +
+ "</tr>";
}
/**
* Get the directories
*/
private final String[] getDirs()
- throws IOException {
+ throws IOException
+ {
Vector v = new Vector();
String[] list = directory.list();
- for (int i = 0; i < list.length; ++i) {
+ for (int i = 0; i < list.length; ++i)
+ {
String item = directory.getAbsolutePath() +
- System.getProperty("file.separator") +
- list[i];
+ System.getProperty("file.separator") +
+ list[i];
- if (new File(item).isDirectory()) {
+ if (new File(item).isDirectory())
+ {
v.addElement(item);
}
@@ -347,19 +384,22 @@
* Get the files
*/
private final String[] getFiles()
- throws IOException {
+ throws IOException
+ {
Vector v = new Vector();
String[] list = directory.list();
- for (int i = 0; i < list.length; ++i) {
+ for (int i = 0; i < list.length; ++i)
+ {
String item = directory.getAbsolutePath() +
- System.getProperty("file.separator") +
- list[i];
+ System.getProperty("file.separator") +
+ list[i];
//don't process the index file
- if (list[i].equals(INDEX)) {
+ if (list[i].equals(INDEX))
+ {
continue;
}
@@ -367,16 +407,19 @@
//if the mode is JAVA only return .html files else return all
if (this.getMode() == MODE_JAVA &&
- JXR.isHtmlFile(item) &&
- new File(item).isFile()) {
+ JXR.isHtmlFile(item) &&
+ new File(item).isFile())
+ {
v.addElement(item);
- } else if (this.getMode() == MODE_DEFAULT &&
- filename.equals(INDEX) == false &&
- filename.equals(new File(IMAGE_DIRECTORY).getName()) == false &&
- filename.equals(new File(IMAGE_FILE).getName()) == false &&
- new File(item).isFile()) {
+ }
+ else if (this.getMode() == MODE_DEFAULT &&
+ filename.equals(INDEX) == false &&
+ filename.equals(new File(IMAGE_DIRECTORY).getName()) == false &&
+ filename.equals(new File(IMAGE_FILE).getName()) == false &&
+ new File(item).isFile())
+ {
v.addElement(item);
@@ -395,7 +438,8 @@
* Copy one file to another file
*/
public void copy(String source, String dest)
- throws IOException {
+ throws IOException
+ {
InputStream is = new FileInputStream(source);
OutputStream os = new FileOutputStream(dest);
@@ -404,7 +448,8 @@
byte bytes[] = new byte[200];
int readCount = 0;
- while ((readCount = is.read(bytes)) > 0) {
+ while ((readCount = is.read(bytes)) > 0)
+ {
os.write(bytes, 0, readCount);
}
@@ -419,17 +464,24 @@
* @see MODE_DEFAULT
* @see MODE_JAVA
*/
- public int getMode() {
+ public int getMode()
+ {
return mode;
}
- /** Get the root dir for directory indexing. */
- public String getRoot() {
+ /**
+ * Get the root dir for directory indexing.
+ */
+ public String getRoot()
+ {
return this.root;
}
- /** Get the directory */
- public String getDirectory() {
+ /**
+ * Get the directory
+ */
+ public String getDirectory()
+ {
return this.directory.getAbsolutePath();
}
}
1.7 +4 -10 jakarta-turbine-maven/src/java/org/apache/maven/jxr/JXR.java
Index: JXR.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jxr/JXR.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JXR.java 24 Feb 2002 18:37:07 -0000 1.6
+++ JXR.java 26 Feb 2002 14:45:54 -0000 1.7
@@ -54,18 +54,17 @@
* <http://www.apache.org/>.
*/
-import org.apache.maven.jxr.util.MetaData;
-import org.apache.tools.ant.DirectoryScanner;
-
import java.io.File;
import java.io.IOException;
+import org.apache.tools.ant.DirectoryScanner;
+
/**
* Main entry point into Maven used to kick off the XReference code
* building.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
- * @version $Id: JXR.java,v 1.6 2002/02/24 18:37:07 kschrader Exp $
+ * @version $Id: JXR.java,v 1.7 2002/02/26 14:45:54 jvanzyl Exp $
*/
public class JXR {
/** Description of the Field */
@@ -84,8 +83,6 @@
*/
private CodeTransform transformer = new CodeTransform();
- private MetaData metadata;
-
/** The revision of the module currently being processed. */
private String revision;
@@ -96,15 +93,12 @@
* @param source The directory that files are being read from (src/java)
* @param source
* @param dest
- * @param metadata
*/
public JXR(String source,
String dest,
- MetaData metadata,
String revision) {
this.source = source;
this.dest = dest;
- this.metadata = metadata;
this.revision = revision;
this.process();
@@ -226,7 +220,7 @@
log(source + " -> " + dest);
- transformer.transform(source, dest, this.revision, this.metadata);
+ transformer.transform(source, dest, this.revision);
}
1.5 +50 -32 jakarta-turbine-maven/src/java/org/apache/maven/jxr/JxrTask.java
Index: JxrTask.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jxr/JxrTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JxrTask.java 24 Feb 2002 18:37:07 -0000 1.4
+++ JxrTask.java 26 Feb 2002 14:45:54 -0000 1.5
@@ -53,11 +53,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
import org.apache.maven.jxr.pacman.PackageManager;
-import org.apache.maven.jxr.util.MetaData;
-import org.apache.maven.project.Project;
-import org.apache.maven.project.Repository;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
@@ -66,60 +62,82 @@
* will create an html-based version of Java source code
*/
-public class JxrTask extends Task {
-
- /** the starting directory housing the .java files */
+public class JxrTask extends Task
+{
+ /**
+ * the starting directory housing the .java files
+ */
private String startDir;
- /** the destination directory */
+ /**
+ * the destination directory
+ */
private String destDir;
- /** the location of the folder.gif */
+ /**
+ * the location of the folder.gif
+ */
private String imageFolder;
- /** the location of the file.gif */
+ /**
+ * the location of the file.gif
+ */
private String imageFile;
- /** Description of the Method */
+ /**
+ * Description of the Method
+ */
public void execute()
- throws BuildException {
- try {
+ throws BuildException
+ {
+ try
+ {
PackageManager pkgmgr = PackageManager.getInstance();
pkgmgr.setTask(this);
pkgmgr.process(startDir);
- MetaData meta = new MetaData(new Repository(), new Project());
- // source file
- // destination directory
- // metadata
- // revision -> cvs tag ???
- // sourcedir -> null ???
-
- new JXR(startDir, destDir, meta, "HEAD");
- new DirectoryIndexer(destDir, destDir, imageFolder,
- imageFile, DirectoryIndexer.MODE_JAVA);
- } catch (Exception ex) {
+ // It is certainly not clear what's going on here. I believe we
+ // have some in-memory work going on and then the results of the
+ // work are placed in 'destDir' by the DirectoryIndexer.
+
+ new JXR(startDir, destDir, "HEAD");
+ new DirectoryIndexer(destDir, imageFolder, imageFile,
DirectoryIndexer.MODE_JAVA);
+ }
+ catch (Exception ex)
+ {
throw new BuildException(ex);
}
}
- /** Sets the imageFile attribute of the JxrTask object */
- public void setImageFile(String imageFile) {
+ /**
+ * Sets the imageFile attribute of the JxrTask object
+ */
+ public void setImageFile(String imageFile)
+ {
this.imageFile = imageFile;
}
- /** Sets the imageFolder attribute of the JxrTask object */
- public void setImageFolder(String imageFolder) {
+ /**
+ * Sets the imageFolder attribute of the JxrTask object
+ */
+ public void setImageFolder(String imageFolder)
+ {
this.imageFolder = imageFolder;
}
- /** Sets the startDir attribute of the JxrTask object */
- public void setStartDir(String startDir) {
+ /**
+ * Sets the startDir attribute of the JxrTask object
+ */
+ public void setStartDir(String startDir)
+ {
this.startDir = startDir;
}
- /** Sets the destDir attribute of the JxrTask object */
- public void setDestDir(String destDir) {
+ /**
+ * Sets the destDir attribute of the JxrTask object
+ */
+ public void setDestDir(String destDir)
+ {
this.destDir = destDir;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>