Package de.hsh.graja.util.comment
Class Verbatim
java.lang.Object
de.hsh.graja.util.comment.Content
de.hsh.graja.util.comment.AbstractElementContent
de.hsh.graja.util.comment.Verbatim
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
InspectorLine
This content is rendered exactly like the passed String with all whitespaces assumed preformatted. If the String includes Tabs (U+0009), the tab is converted to a number of spaces and or a special symbol. In HTML we use the <pre> tag to format a verbatim comment.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An instance of this enum defines how whitespaces are expanded in a Verbatim. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
Character used to indicate a line feed (LF) in verbatim content.static final char
Character used to indicate a line feed (LF) in verbatim content.static final char
Character used to indicate the positions skipped by a tabulator in verbatim content.static final char
Character used to indicate a tab start position in verbatim content.static final char
Character used to indicate a tab stop position in verbatim content.static final int
default tab widthFields inherited from class de.hsh.graja.util.comment.Content
EXCLUSIVE, renderUuid
-
Constructor Summary
ConstructorsConstructorDescriptionVerbatim
(IncludeSpec includeSpec, Verbatim.WhitespaceExpansion wsExpansion, String data) Create a comment assuming a tabwidth of 4Verbatim
(IncludeSpec includeSpec, String data) Create a content assuming a tabwidth of 4 and a tab expansion using spaces and a LF / CR expansion using LF. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
createSymbolLegendForText
(String input) Creates a legend that describes the meaning of various expansion symbols.boolean
implements the contract ofObject.equals(Object)
.static String
expandTabsWithSymbols
(String line) Produces a line where tabs (U+0009) have been replaced by indicators of tab start and end, filled between these indicators with spaces.static String
expandTabsWithSymbols
(String line, int tabWidth) Produces a line where tabs (U+0009) have been replaced by indicators of tab start and end, filled between these indicators with spaces.static Verbatim
format
(IncludeSpec includeSpec, String format, Object... args) Factory method using a formatter.getData()
Creates a string that results from expanding tabs and line breaks according to the settings of this instance.int
int
hashCode()
implements the contract ofObject.hashCode()
.boolean
void
renderHtmlImpl
(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript) render content to HTML.void
renderPlainImpl
(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx) render content to plain text.void
Set the raw textvoid
setTabWidth
(int tabWidth) Set the tab width defining tab stops at regular intervalsThis method is for debugging purposes.Methods inherited from class de.hsh.graja.util.comment.AbstractElementContent
getNestedContents
Methods inherited from class de.hsh.graja.util.comment.Content
click, dehighlight, disableCallerStacktraceRecording, enableCallerStacktraceRecording, excludeGlobally, getIncludeSpec, getRenderUuid, getStackdump, hide, highlight, include, isCallerStacktraceRecordingEnabled, isHidden, isShowing, onClick, onClick, onHide, onHide, onLoad, onLoad, onShow, onShow, registerCallable, renderHtml, renderHtml, renderIdAttribute, renderJavascriptOncePerClass, renderOnClickAttribute, renderPlain, renderPlain, setGlobalIncludeInfo, setHref, setIncludeSpec, show, toString
-
Field Details
-
LINE_FEED
public static final char LINE_FEEDCharacter used to indicate a line feed (LF) in verbatim content. Currently this is the character ¶ (U+00B6)- See Also:
-
CARRIAGE_RETURN
public static final char CARRIAGE_RETURNCharacter used to indicate a line feed (LF) in verbatim content. Currently this is the character « (U+00AB)- See Also:
-
TABWIDTH
public static final int TABWIDTHdefault tab width- See Also:
-
TABULATOR_START
public static final char TABULATOR_STARTCharacter used to indicate a tab start position in verbatim content. Currently this is the character → (U+2192), since this right arrow seems to be monospaced in typical fonts like courier new.- See Also:
-
TABULATOR_EXPANSION
public static final char TABULATOR_EXPANSIONCharacter used to indicate the positions skipped by a tabulator in verbatim content. Currently this is the space character (U+0020).- See Also:
-
TABULATOR_STOP
public static final char TABULATOR_STOPCharacter used to indicate a tab stop position in verbatim content. Currently this is the zero-width space (U+200B)- See Also:
-
-
Constructor Details
-
Verbatim
Create a content assuming a tabwidth of 4 and a tab expansion using spaces and a LF / CR expansion using LF.- Parameters:
includeSpec
- the includeSpec of the contentdata
- raw text
-
Verbatim
Create a comment assuming a tabwidth of 4- Parameters:
includeSpec
- the includeSpec of the contentwsExpansion
- the expansion strategy for white spaces in the raw textdata
- raw text
-
-
Method Details
-
format
Factory method using a formatter.- Parameters:
includeSpec
- the includeSpec of the contentformat
- format string as defined byFormatter
to create a raw textargs
- arguments to the format string- Returns:
- A new content assuming a tabwidth of 4 and a tab expansion using spaces and a LF / CR expansion using LF.
-
getTabWidth
public int getTabWidth()- Returns:
- the actual tabulator width defining tab stops at regular intervals
-
setTabWidth
public void setTabWidth(int tabWidth) Set the tab width defining tab stops at regular intervals- Parameters:
tabWidth
- the actual setting
-
getWhitespaceExpansion
- Returns:
- the white space expansion strategy for this content
-
getData
- Returns:
- the raw text of this content
-
setData
Set the raw text- Parameters:
data
- raw text.
-
expandTabsWithSymbols
Produces a line where tabs (U+0009) have been replaced by indicators of tab start and end, filled between these indicators with spaces. The default tab width is used.- Parameters:
line
- the original string- Returns:
- a string, where tabs have been expanded.
-
expandTabsWithSymbols
Produces a line where tabs (U+0009) have been replaced by indicators of tab start and end, filled between these indicators with spaces. The given tab width is used.- Parameters:
line
- the original stringtabWidth
- the desired tab width- Returns:
- a string, where tabs have been expanded.
- Throws:
IllegalArgumentException
- thrown, when tabWidth < 1.
-
getDataWithExpandedWhitespaces
Creates a string that results from expanding tabs and line breaks according to the settings of this instance. Expansion type and tab width can be specified with the constructor and withsetTabWidth(int)
.- Returns:
- the resulting string after expansion.
-
createSymbolLegendForText
Creates a legend that describes the meaning of various expansion symbols. The legend does only contain those expansion symbols that are present in the parameterinput
.- Parameters:
input
- text- Returns:
- a legend string
-
isInlineContent
public boolean isInlineContent()- Specified by:
isInlineContent
in classContent
- Returns:
- false
- See Also:
-
toString
Description copied from class:Content
This method is for debugging purposes. -
hashCode
public int hashCode()implements the contract ofObject.hashCode()
. -
equals
implements the contract ofObject.equals(Object)
. -
renderHtmlImpl
public void renderHtmlImpl(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript) Description copied from class:Content
render content to HTML. This method is meant to be overriden by subclasses.- Specified by:
renderHtmlImpl
in classContent
- Parameters:
sb
- HTML code resultincludeInfo
- controls, which content to be rendered.ctx
- render contextuseJavascript
- if true, the generated HTML code will contain Javascript- See Also:
-
Content#renderHtmlImpl(StringBuilder, IncludeInfo, RenderContext)
-
renderPlainImpl
Description copied from class:Content
render content to plain text. This method is meant to be overriden by subclasses.- Specified by:
renderPlainImpl
in classContent
- Parameters:
sb
- plain text resultincludeInfo
- controls, which content to be rendered.ctx
- render context (unused).- See Also:
-