Package org.apache.maven.jxr
Class JavaCodeTransform
java.lang.Object
org.apache.maven.jxr.JavaCodeTransform
- All Implemented Interfaces:
Serializable
Syntax highlights java by turning it into html. A codeviewer object is created and then keeps state as lines are
passed in. Each line passed in as java test, is returned as syntax highlighted html text. Users of the class can set
how the java code will be highlighted with setter methods. Only valid java lines should be passed in since the object
maintains state and may not handle illegal code gracefully. The actual system is implemented as a series of filters
that deal with specific portions of the java code. The filters are as follows:
htmlFilter
|__
ongoingMultiLineCommentFilter -> uriFilter
|__
inlineCommentFilter
|__
beginMultiLineCommentFilter -> ongoingMultiLineCommentFilter
|__
stringFilter
|__
keywordFilter
|__
uriFilter
|__
jxrFilter
|__
importFilter
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringend comment delimiterprivate static final Stringstart comment delimiterprivate PathFile name that is currently being processed.private final FileManagercurrent file managerprivate booleanFlag set to true when a javadoc comment is started.private booleanFlag set to true when a multi-line comment is started.private static final Stringend javadoc comment delimiterprivate static final Stringstart javadoc comment delimiterprivate PathRelative path to javadocs, suitable for hyperlinking.private static final booleanshow line numbersprivate LocaleThe wanted localeprivate StringThe output encodingprivate final PackageManagerPackage Manager for this project.private static final Stringend reserved word delimiterprivate static final Stringstart reserved word delimiterHashTable containing java reserved wordsprivate StringRevision of the currently transformed document.private static final Stringend String delimiterprivate static final Stringstart String delimiterprivate static final Stringstylesheet file nameprivate static final char[]Specify the only characters that are allowed in a URI besides alpha and numeric characters.private static final String[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendFooter(PrintWriter out, String bottom) Gets the footer attribute of the JavaCodeTransform objectprivate voidappendHeader(PrintWriter out) Gets the header attribute of the JavaCodeTransform objectprivate StringDetect and handle the start of multiLine comments.private PathGets the current file name.private StringGets an overview header for this file.private StringBased on the destination package, get the HREF.private StringGiven the current package, get an HREF to the package and class givenprivate StringgetLineWidth(int linenumber) Handles line width which may need to change depending on which line number you are on.private intgetPackageCount(String packageName) Given the name of a package...private StringFrom the current file, determine the package root based on the current path.private Readerfinal StringThe current revision of the module.private Writerprivate StringhtmlFilter(String line) Filter html tags into more benign text.private StringimportFilter(String line) Parse out the current link and look for package/import statements and then create HREFs for themprivate StringinlineCommentFilter(String line) Filter inline comments from a line and formats them properly.private booleanisInsideString(String line, int position) Checks to see if some position in a line is between String start and ending characters.private booleanisInvalidURICharacter(char c) if the given char is not one of the following in VALID_URI_CHARS then return trueprivate StringHandles finding classes based on the current filename and then makes HREFs for you to link to them with.private StringkeywordFilter(String line) Filters keywords from a line of text and formats them properly.private StringHandle ongoing multi-line comments, detecting ends if present.
State is maintained in private boolean members, one each for javadoc and (normal) multi-line comments.(package private) final voidprivate voidsetCurrentFilename(Path filename) Sets the current file name.private StringstringFilter(String line) Filters strings from a line of text and formats them properly.private StringsyntaxHighlight(String line) Now different method of seeing if at end of input stream, closes inputs stream at end.private voidtransform(Reader sourceReader, Writer destWriter, Locale locale, String outputEncoding, Path javadocLinkDir, String revision, String bottom) This is the public method for doing all transforms of code.final voidtransform(Path sourcefile, Path destfile, Locale locale, String inputEncoding, String outputEncoding, Path javadocLinkDir, String revision, String bottom) This is the public method for doing all transforms of code.private StringGiven a line of text, search for URIs and make href's out of them.(package private) final voidprivate StringCross Reference the given line with JXR returning the new content.
-
Field Details
-
LINE_NUMBERS
private static final boolean LINE_NUMBERSshow line numbers- See Also:
-
COMMENT_START
start comment delimiter- See Also:
-
COMMENT_END
end comment delimiter- See Also:
-
JAVADOC_COMMENT_START
start javadoc comment delimiter- See Also:
-
JAVADOC_COMMENT_END
end javadoc comment delimiter- See Also:
-
STRING_START
start String delimiter- See Also:
-
STRING_END
end String delimiter- See Also:
-
RESERVED_WORD_START
start reserved word delimiter- See Also:
-
RESERVED_WORD_END
end reserved word delimiter- See Also:
-
STYLESHEET_FILENAME
stylesheet file name- See Also:
-
VALID_URI_SCHEMES
-
VALID_URI_CHARS
private static final char[] VALID_URI_CHARSSpecify the only characters that are allowed in a URI besides alpha and numeric characters. Refer RFC2396 - http://www.ietf.org/rfc/rfc2396.txt -
reservedWords
HashTable containing java reserved words -
inMultiLineComment
private boolean inMultiLineCommentFlag set to true when a multi-line comment is started. -
inJavadocComment
private boolean inJavadocCommentFlag set to true when a javadoc comment is started. -
currentFilename
File name that is currently being processed. -
revision
Revision of the currently transformed document. -
outputEncoding
The output encoding -
locale
The wanted locale -
javadocLinkDir
Relative path to javadocs, suitable for hyperlinking. -
packageManager
Package Manager for this project. -
fileManager
current file manager
-
-
Constructor Details
-
JavaCodeTransform
-
-
Method Details
-
syntaxHighlight
Now different method of seeing if at end of input stream, closes inputs stream at end.- Parameters:
line- String- Returns:
- filtered line of code
-
appendHeader
Gets the header attribute of the JavaCodeTransform object- Parameters:
out- the writer where the header is appended to
-
transform
private void transform(Reader sourceReader, Writer destWriter, Locale locale, String outputEncoding, Path javadocLinkDir, String revision, String bottom) throws IOException This is the public method for doing all transforms of code.- Parameters:
sourceReader- ReaderdestWriter- Writerlocale- StringoutputEncoding- StringjavadocLinkDir- Stringrevision- Stringbottom- string- Throws:
IOException
-
transform
public final void transform(Path sourcefile, Path destfile, Locale locale, String inputEncoding, String outputEncoding, Path javadocLinkDir, String revision, String bottom) throws IOException This is the public method for doing all transforms of code.- Parameters:
sourcefile- source filedestfile- destination filelocale- localeinputEncoding- input encodingoutputEncoding- output encodingjavadocLinkDir- relative path to javadocsrevision- revision of the modulebottom- bottom text- Throws:
IOException- in I/O failures in reading/writing files
-
getWriter
- Throws:
IOException
-
getReader
- Throws:
IOException
-
getCurrentFilename
Gets the current file name.- Returns:
- path of file
-
setCurrentFilename
Sets the current file name.- Parameters:
filename- file name
-
getPackageRoot
From the current file, determine the package root based on the current path.- Returns:
- package root
-
uriFilter
Given a line of text, search for URIs and make href's out of them.- Parameters:
line- String- Returns:
- href
-
getRevision
The current revision of the module.- Returns:
- revision
-
xrLine
Cross Reference the given line with JXR returning the new content.- Parameters:
line- linepackageName- StringclassType- ClassType- Returns:
- cross-referenced line
-
htmlFilter
Filter html tags into more benign text.- Parameters:
line- String- Returns:
- html encoded line
-
ongoingMultiLineCommentFilter
Handle ongoing multi-line comments, detecting ends if present.
State is maintained in private boolean members, one each for javadoc and (normal) multi-line comments.- Parameters:
line- line- Returns:
- processed line
-
inlineCommentFilter
Filter inline comments from a line and formats them properly. One problem we'll have to solve here: comments contained in a string should be ignored... this is also true of the multi-line comments. So, we could either ignore the problem, or implement a function called something like isInsideString(line, index) where index points to some point in the line that we need to check... started doing this function below.- Parameters:
line- line- Returns:
- processed line
-
beginMultiLineCommentFilter
Detect and handle the start of multiLine comments. State is maintained in private boolean members one each for javadoc and (normal) multiline comments.- Parameters:
line- line- Returns:
- processed line
-
stringFilter
Filters strings from a line of text and formats them properly.- Parameters:
line- line- Returns:
- processed line
-
keywordFilter
Filters keywords from a line of text and formats them properly.- Parameters:
line- line- Returns:
- processed line
-
isInsideString
Checks to see if some position in a line is between String start and ending characters. Not yet used in code or fully working :)- Parameters:
line- Stringposition- int- Returns:
- boolean
-
writeObject
- Parameters:
oos- ObjectOutputStream- Throws:
IOException- on I/O error during write
-
readObject
- Parameters:
ois- object input stream- Throws:
ClassNotFoundException- if the class of a serialized object could not be found.IOException- on I/O error during read
-
getFileOverview
Gets an overview header for this file.- Returns:
- overview header
-
getLineWidth
Handles line width which may need to change depending on which line number you are on.- Parameters:
linenumber- int- Returns:
- blanks
-
jxrFilter
Handles finding classes based on the current filename and then makes HREFs for you to link to them with.- Parameters:
line- line- Returns:
- processed line
-
getHREF
Given the current package, get an HREF to the package and class given- Parameters:
dest- destinationjc- class type- Returns:
- href
-
getHREF
Based on the destination package, get the HREF.- Parameters:
dest- destination- Returns:
- href
-
getPackageCount
Given the name of a package... get the number of subdirectories/subpackages there would be.
EX:
org.apache.maven == 3- Parameters:
packageName- String- Returns:
- int
-
importFilter
Parse out the current link and look for package/import statements and then create HREFs for them- Parameters:
line- line- Returns:
- processed line
-
isInvalidURICharacter
private boolean isInvalidURICharacter(char c) if the given char is not one of the following in VALID_URI_CHARS then return true- Parameters:
c- char to check against VALID_URI_CHARS list- Returns:
trueif c is a valid URI char
-