Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.renderer.macro.code
Class JavaCodeViewer

java.lang.Object
  extended by com.jivesoftware.forum.renderer.macro.code.JavaCodeViewer

public class JavaCodeViewer
extends java.lang.Object

A class that syntax highlights Java code into html.

A CodeViewer object is used to syntax highlight Java code. To make use of this class, first set up how tokens should be highlighted by invoking the getXXX and setXXX methods, then pass in "chunks" of relevent input to be filtered. Typically this will mean the section(s) of a form input that has been tagged with [code][/code] tags.


Constructor Summary
JavaCodeViewer()
           
 
Method Summary
 java.lang.String getBracketEnd()
          Gets the html for the end of a bracket.
 java.lang.String getBracketStart()
          Gets the html for the start of a bracket.
 java.lang.String getCharacterEnd()
          Gets the html for the end of a character.
 java.lang.String getCharacterStart()
          Gets the html for the start of a character.
 java.lang.String getCommentEnd()
          Gets the html for the end of a comment block.
 java.lang.String getCommentStart()
          Gets the html for the start of a comment block.
 boolean getFilterMethod()
          See if method filtering is enabled.
 boolean getFilterNumber()
          See if number filtering is enabled.
 java.lang.String getMethodEnd()
          Gets the html for the end of a method.
 java.lang.String getMethodStart()
          Gets the html for the start of a method.
 java.lang.String getNumberEnd()
          Gets the html for the end of a number.
 java.lang.String getNumberStart()
          Gets the html for the start of a number
 java.lang.String getReservedWordEnd()
          Gets the html for the end of a reserved word.
 java.lang.String getReservedWordStart()
          Gets the html for the start of a reserved word.
 java.lang.String getStringEnd()
          Gets the html for the end of a String.
 java.lang.String getStringStart()
          Gets the html for the start of a String.
 java.lang.String javaCodeFilter(java.lang.String line)
          Syntax highlights any java code in the input.
 void setBracketEnd(java.lang.String bracketEnd)
          Sets the html for the end of a bracket.
 void setBracketStart(java.lang.String bracketStart)
          Sets the html for the start of a bracket.
 void setCharacterEnd(java.lang.String characterEnd)
          Sets the html for the end of a character.
 void setCharacterStart(java.lang.String characterStart)
          Sets the html for the start of a character.
 void setCommentEnd(java.lang.String commentEnd)
          Sets the html for the end of a comment block.
 void setCommentStart(java.lang.String commentStart)
          Sets the html for the start of a comment block.
 void setFilterMethod(boolean filterMethod)
          Enables or disables method filtering.
 void setFilterNumber(boolean filterNumber)
          Enables or disables number filtering.
 void setMethodEnd(java.lang.String methodEnd)
          Sets the html for the end of a method.
 void setMethodStart(java.lang.String methodStart)
          Sets the html for the start of a method.
 void setNumberEnd(java.lang.String numberEnd)
          Sets the html for the end of a number.
 void setNumberStart(java.lang.String numberStart)
          Sets the html for the start of a number.
 void setReservedWordEnd(java.lang.String reservedWordEnd)
          Sets the html for the end of a reserved word.
 void setReservedWordStart(java.lang.String reservedWordStart)
          Sets the html for the start of a reserved word.
 void setStringEnd(java.lang.String stringEnd)
          Sets the html for the end of a String.
 void setStringStart(java.lang.String stringStart)
          Sets the html for the start of a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaCodeViewer

public JavaCodeViewer()
Method Detail

getCommentStart

public java.lang.String getCommentStart()
Gets the html for the start of a comment block.


setCommentStart

public void setCommentStart(java.lang.String commentStart)
Sets the html for the start of a comment block.


getCommentEnd

public java.lang.String getCommentEnd()
Gets the html for the end of a comment block.


setCommentEnd

public void setCommentEnd(java.lang.String commentEnd)
Sets the html for the end of a comment block.


getStringStart

public java.lang.String getStringStart()
Gets the html for the start of a String.


setStringStart

public void setStringStart(java.lang.String stringStart)
Sets the html for the start of a String.


getStringEnd

public java.lang.String getStringEnd()
Gets the html for the end of a String.


setStringEnd

public void setStringEnd(java.lang.String stringEnd)
Sets the html for the end of a String.


getReservedWordStart

public java.lang.String getReservedWordStart()
Gets the html for the start of a reserved word.


setReservedWordStart

public void setReservedWordStart(java.lang.String reservedWordStart)
Sets the html for the start of a reserved word.


getReservedWordEnd

public java.lang.String getReservedWordEnd()
Gets the html for the end of a reserved word.


setReservedWordEnd

public void setReservedWordEnd(java.lang.String reservedWordEnd)
Sets the html for the end of a reserved word.


getMethodStart

public java.lang.String getMethodStart()
Gets the html for the start of a method.


setMethodStart

public void setMethodStart(java.lang.String methodStart)
Sets the html for the start of a method.


getMethodEnd

public java.lang.String getMethodEnd()
Gets the html for the end of a method.


setMethodEnd

public void setMethodEnd(java.lang.String methodEnd)
Sets the html for the end of a method.


getCharacterStart

public java.lang.String getCharacterStart()
Gets the html for the start of a character.


setCharacterStart

public void setCharacterStart(java.lang.String characterStart)
Sets the html for the start of a character.


getCharacterEnd

public java.lang.String getCharacterEnd()
Gets the html for the end of a character.


setCharacterEnd

public void setCharacterEnd(java.lang.String characterEnd)
Sets the html for the end of a character.


getBracketStart

public java.lang.String getBracketStart()
Gets the html for the start of a bracket.


setBracketStart

public void setBracketStart(java.lang.String bracketStart)
Sets the html for the start of a bracket.


getBracketEnd

public java.lang.String getBracketEnd()
Gets the html for the end of a bracket.


setBracketEnd

public void setBracketEnd(java.lang.String bracketEnd)
Sets the html for the end of a bracket.


getNumberStart

public java.lang.String getNumberStart()
Gets the html for the start of a number


setNumberStart

public void setNumberStart(java.lang.String numberStart)
Sets the html for the start of a number.


getNumberEnd

public java.lang.String getNumberEnd()
Gets the html for the end of a number.


setNumberEnd

public void setNumberEnd(java.lang.String numberEnd)
Sets the html for the end of a number.


getFilterMethod

public boolean getFilterMethod()
See if method filtering is enabled.


setFilterMethod

public void setFilterMethod(boolean filterMethod)
Enables or disables method filtering.


getFilterNumber

public boolean getFilterNumber()
See if number filtering is enabled.


setFilterNumber

public void setFilterNumber(boolean filterNumber)
Enables or disables number filtering.


javaCodeFilter

public final java.lang.String javaCodeFilter(java.lang.String line)
Syntax highlights any java code in the input. In working with this method it is helpful to know how lexers work in general.

The overall strategy is as follows:
The input is processed a character at a time, accompanied by a state update. When a valid Java token is detected, such as a keyword, a string, a comment block, etc, said token gets "wrapped" by htmlStart and htmlEnd tags. Not everything is implemented according to the Java Language Specifications. For example, the length of a valid number is left unchecked.

Parameters:
line - string possibly containing Java code
Returns:
the output string containing html formatted Java code

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.