Package org.apache.maven.jxr
Class JavaCodeTransform
- java.lang.Object
-
- org.apache.maven.jxr.JavaCodeTransform
-
- All Implemented Interfaces:
java.io.Serializable
public class JavaCodeTransform extends java.lang.Object implements java.io.SerializableSyntax 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCOMMENT_ENDend comment delimiterprivate static java.lang.StringCOMMENT_STARTstart comment delimiterprivate java.nio.file.PathcurrentFilenameFile name that is currently being processed.private FileManagerfileManagercurrent file managerprivate booleaninJavadocCommentFlag set to true when a javadoc comment is started.private booleaninMultiLineCommentFlag set to true when a multi-line comment is started.private static java.lang.StringJAVADOC_COMMENT_ENDend javadoc comment delimiterprivate static java.lang.StringJAVADOC_COMMENT_STARTstart javadoc comment delimiterprivate java.nio.file.PathjavadocLinkDirRelative path to javadocs, suitable for hyperlinking.private static booleanLINE_NUMBERSshow line numbersprivate java.util.LocalelocaleThe wanted localeprivate java.lang.StringoutputEncodingThe output encodingprivate PackageManagerpackageManagerPackage Manager for this project.private static java.lang.StringRESERVED_WORD_ENDend reserved word delimiterprivate static java.lang.StringRESERVED_WORD_STARTstart reserved word delimiterprivate java.util.Map<java.lang.String,java.lang.String>reservedWordsHashTable containing java reserved wordsprivate java.lang.StringrevisionRevision of the currently transformed document.private static java.lang.StringSTRING_ENDend String delimiterprivate static java.lang.StringSTRING_STARTstart String delimiterprivate static java.lang.StringSTYLESHEET_FILENAMEstylesheet file nameprivate static char[]VALID_URI_CHARSSpecify the only characters that are allowed in a URI besides alpha and numeric characters.private static java.lang.String[]VALID_URI_SCHEMES
-
Constructor Summary
Constructors Constructor Description JavaCodeTransform(PackageManager packageManager, FileManager fileManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidappendFooter(java.io.PrintWriter out, java.lang.String bottom)Gets the footer attribute of the JavaCodeTransform objectprivate voidappendHeader(java.io.PrintWriter out)Gets the header attribute of the JavaCodeTransform objectprivate java.lang.StringbeginMultiLineCommentFilter(java.lang.String line)Detect and handle the start of multiLine comments.private java.nio.file.PathgetCurrentFilename()Gets the current file name.private java.lang.StringgetFileOverview()Gets an overview header for this file.private java.lang.StringgetHREF(java.lang.String dest)Based on the destination package, get the HREF.private java.lang.StringgetHREF(java.lang.String dest, ClassType jc)Given the current package, get an HREF to the package and class givenprivate java.lang.StringgetLineWidth(int linenumber)Handles line width which may need to change depending on which line number you are on.private intgetPackageCount(java.lang.String packageName)Given the name of a package...private java.lang.StringgetPackageRoot()From the current file, determine the package root based on the current path.private java.io.ReadergetReader(java.nio.file.Path sourcefile, java.lang.String inputEncoding)java.lang.StringgetRevision()The current revision of the module.private java.io.WritergetWriter(java.nio.file.Path destfile, java.lang.String outputEncoding)private java.lang.StringhtmlFilter(java.lang.String line)Filter html tags into more benign text.private java.lang.StringimportFilter(java.lang.String line)Parse out the current link and look for package/import statements and then create HREFs for themprivate java.lang.StringinlineCommentFilter(java.lang.String line)Filter inline comments from a line and formats them properly.private booleanisInsideString(java.lang.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 java.lang.StringjxrFilter(java.lang.String line)Handles finding classes based on the current filename and then makes HREFs for you to link to them with.private java.lang.StringkeywordFilter(java.lang.String line)Filters keywords from a line of text and formats them properly.private java.lang.StringongoingMultiLineCommentFilter(java.lang.String line)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.(package private) voidreadObject(java.io.ObjectInputStream ois)private voidsetCurrentFilename(java.nio.file.Path filename)Sets the current file name.private java.lang.StringstringFilter(java.lang.String line)Filters strings from a line of text and formats them properly.private java.lang.StringsyntaxHighlight(java.lang.String line)Now different method of seeing if at end of input stream, closes inputs stream at end.private voidtransform(java.io.Reader sourceReader, java.io.Writer destWriter, java.util.Locale locale, java.lang.String outputEncoding, java.nio.file.Path javadocLinkDir, java.lang.String revision, java.lang.String bottom)This is the public method for doing all transforms of code.voidtransform(java.nio.file.Path sourcefile, java.nio.file.Path destfile, java.util.Locale locale, java.lang.String inputEncoding, java.lang.String outputEncoding, java.nio.file.Path javadocLinkDir, java.lang.String revision, java.lang.String bottom)This is the public method for doing all transforms of code.private java.lang.StringuriFilter(java.lang.String line)Given a line of text, search for URIs and make href's out of them.(package private) voidwriteObject(java.io.ObjectOutputStream oos)private java.lang.StringxrLine(java.lang.String line, java.lang.String packageName, ClassType classType)Cross Reference the given line with JXR returning the new content.
-
-
-
Field Detail
-
LINE_NUMBERS
private static final boolean LINE_NUMBERS
show line numbers- See Also:
- Constant Field Values
-
COMMENT_START
private static final java.lang.String COMMENT_START
start comment delimiter- See Also:
- Constant Field Values
-
COMMENT_END
private static final java.lang.String COMMENT_END
end comment delimiter- See Also:
- Constant Field Values
-
JAVADOC_COMMENT_START
private static final java.lang.String JAVADOC_COMMENT_START
start javadoc comment delimiter- See Also:
- Constant Field Values
-
JAVADOC_COMMENT_END
private static final java.lang.String JAVADOC_COMMENT_END
end javadoc comment delimiter- See Also:
- Constant Field Values
-
STRING_START
private static final java.lang.String STRING_START
start String delimiter- See Also:
- Constant Field Values
-
STRING_END
private static final java.lang.String STRING_END
end String delimiter- See Also:
- Constant Field Values
-
RESERVED_WORD_START
private static final java.lang.String RESERVED_WORD_START
start reserved word delimiter- See Also:
- Constant Field Values
-
RESERVED_WORD_END
private static final java.lang.String RESERVED_WORD_END
end reserved word delimiter- See Also:
- Constant Field Values
-
STYLESHEET_FILENAME
private static final java.lang.String STYLESHEET_FILENAME
stylesheet file name- See Also:
- Constant Field Values
-
VALID_URI_SCHEMES
private static final java.lang.String[] VALID_URI_SCHEMES
-
VALID_URI_CHARS
private static final char[] VALID_URI_CHARS
Specify the only characters that are allowed in a URI besides alpha and numeric characters. Refer RFC2396 - http://www.ietf.org/rfc/rfc2396.txt
-
reservedWords
private java.util.Map<java.lang.String,java.lang.String> reservedWords
HashTable containing java reserved words
-
inMultiLineComment
private boolean inMultiLineComment
Flag set to true when a multi-line comment is started.
-
inJavadocComment
private boolean inJavadocComment
Flag set to true when a javadoc comment is started.
-
currentFilename
private java.nio.file.Path currentFilename
File name that is currently being processed.
-
revision
private java.lang.String revision
Revision of the currently transformed document.
-
outputEncoding
private java.lang.String outputEncoding
The output encoding
-
locale
private java.util.Locale locale
The wanted locale
-
javadocLinkDir
private java.nio.file.Path javadocLinkDir
Relative path to javadocs, suitable for hyperlinking.
-
packageManager
private final PackageManager packageManager
Package Manager for this project.
-
fileManager
private final FileManager fileManager
current file manager
-
-
Constructor Detail
-
JavaCodeTransform
public JavaCodeTransform(PackageManager packageManager, FileManager fileManager)
-
-
Method Detail
-
syntaxHighlight
private java.lang.String syntaxHighlight(java.lang.String line)
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
private void appendHeader(java.io.PrintWriter out)
Gets the header attribute of the JavaCodeTransform object- Parameters:
out- the writer where the header is appended to
-
appendFooter
private void appendFooter(java.io.PrintWriter out, java.lang.String bottom)Gets the footer attribute of the JavaCodeTransform object- Parameters:
out- the writer where the header is appended tobottom- the bottom text
-
transform
private void transform(java.io.Reader sourceReader, java.io.Writer destWriter, java.util.Locale locale, java.lang.String outputEncoding, java.nio.file.Path javadocLinkDir, java.lang.String revision, java.lang.String bottom) throws java.io.IOExceptionThis is the public method for doing all transforms of code.- Parameters:
sourceReader- ReaderdestWriter- Writerlocale- StringoutputEncoding- StringjavadocLinkDir- Stringrevision- Stringbottom- string- Throws:
java.io.IOException
-
transform
public final void transform(java.nio.file.Path sourcefile, java.nio.file.Path destfile, java.util.Locale locale, java.lang.String inputEncoding, java.lang.String outputEncoding, java.nio.file.Path javadocLinkDir, java.lang.String revision, java.lang.String bottom) throws java.io.IOExceptionThis 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:
java.io.IOException- in I/O failures in reading/writing files
-
getWriter
private java.io.Writer getWriter(java.nio.file.Path destfile, java.lang.String outputEncoding) throws java.io.IOException- Throws:
java.io.IOException
-
getReader
private java.io.Reader getReader(java.nio.file.Path sourcefile, java.lang.String inputEncoding) throws java.io.IOException- Throws:
java.io.IOException
-
getCurrentFilename
private java.nio.file.Path getCurrentFilename()
Gets the current file name.- Returns:
- path of file
-
setCurrentFilename
private void setCurrentFilename(java.nio.file.Path filename)
Sets the current file name.- Parameters:
filename- file name
-
getPackageRoot
private java.lang.String getPackageRoot()
From the current file, determine the package root based on the current path.- Returns:
- package root
-
uriFilter
private java.lang.String uriFilter(java.lang.String line)
Given a line of text, search for URIs and make href's out of them.- Parameters:
line- String- Returns:
- href
-
getRevision
public final java.lang.String getRevision()
The current revision of the module.- Returns:
- revision
-
xrLine
private java.lang.String xrLine(java.lang.String line, java.lang.String packageName, ClassType classType)Cross Reference the given line with JXR returning the new content.- Parameters:
line- linepackageName- StringclassType- ClassType- Returns:
- cross-referenced line
-
htmlFilter
private java.lang.String htmlFilter(java.lang.String line)
Filter html tags into more benign text.- Parameters:
line- String- Returns:
- html encoded line
-
ongoingMultiLineCommentFilter
private java.lang.String ongoingMultiLineCommentFilter(java.lang.String line)
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
private java.lang.String inlineCommentFilter(java.lang.String line)
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
private java.lang.String beginMultiLineCommentFilter(java.lang.String line)
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
private java.lang.String stringFilter(java.lang.String line)
Filters strings from a line of text and formats them properly.- Parameters:
line- line- Returns:
- processed line
-
keywordFilter
private java.lang.String keywordFilter(java.lang.String line)
Filters keywords from a line of text and formats them properly.- Parameters:
line- line- Returns:
- processed line
-
isInsideString
private boolean isInsideString(java.lang.String line, int position)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
final void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException- Parameters:
oos- ObjectOutputStream- Throws:
java.io.IOException- on I/O error during write
-
readObject
final void readObject(java.io.ObjectInputStream ois) throws java.lang.ClassNotFoundException, java.io.IOException- Parameters:
ois- object input stream- Throws:
java.lang.ClassNotFoundException- if the class of a serialized object could not be found.java.io.IOException- on I/O error during read
-
getFileOverview
private java.lang.String getFileOverview()
Gets an overview header for this file.- Returns:
- overview header
-
getLineWidth
private java.lang.String getLineWidth(int linenumber)
Handles line width which may need to change depending on which line number you are on.- Parameters:
linenumber- int- Returns:
- blanks
-
jxrFilter
private java.lang.String jxrFilter(java.lang.String line)
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
private java.lang.String getHREF(java.lang.String dest, ClassType jc)Given the current package, get an HREF to the package and class given- Parameters:
dest- destinationjc- class type- Returns:
- href
-
getHREF
private java.lang.String getHREF(java.lang.String dest)
Based on the destination package, get the HREF.- Parameters:
dest- destination- Returns:
- href
-
getPackageCount
private int getPackageCount(java.lang.String packageName)
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
private java.lang.String importFilter(java.lang.String line)
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
-
-