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
public class Verbatim extends AbstractElementContent
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Verbatim.WhitespaceExpansion
An instance of this enum defines how whitespaces are expanded in a Verbatim.
-
Field Summary
Fields Modifier and Type Field Description static char
CARRIAGE_RETURN
Character used to indicate a line feed (LF) in verbatim content.static char
LINE_FEED
Character used to indicate a line feed (LF) in verbatim content.static char
TABULATOR_EXPANSION
Character used to indicate the positions skipped by a tabulator in verbatim content.static char
TABULATOR_START
Character used to indicate a tab start position in verbatim content.static char
TABULATOR_STOP
Character used to indicate a tab stop position in verbatim content.static int
TABWIDTH
default tab width-
Fields inherited from class de.hsh.graja.util.comment.Content
EXCLUSIVE, renderUuid
-
-
Constructor Summary
Constructors Constructor Description Verbatim(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
createSymbolLegendForText(String input)
Creates a legend that describes the meaning of various expansion symbols.boolean
equals(Object obj)
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.String
getData()
String
getDataWithExpandedWhitespaces()
Creates a string that results from expanding tabs and line breaks according to the settings of this instance.int
getTabWidth()
Verbatim.WhitespaceExpansion
getWhitespaceExpansion()
int
hashCode()
implements the contract ofObject.hashCode()
.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
setData(String data)
Set the raw textvoid
setTabWidth(int tabWidth)
Set the tab width defining tab stops at regular intervalsString
toString(String prefix)
This 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, disableCallerStacktraceRecording, enableCallerStacktraceRecording, excludeGlobally, getIncludeSpec, getRenderUuid, getStackdump, hide, 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 Detail
-
LINE_FEED
public static final char LINE_FEED
Character used to indicate a line feed (LF) in verbatim content. Currently this is the character ¶ (U+00B6)- See Also:
- Constant Field Values
-
CARRIAGE_RETURN
public static final char CARRIAGE_RETURN
Character used to indicate a line feed (LF) in verbatim content. Currently this is the character « (U+00AB)- See Also:
- Constant Field Values
-
TABWIDTH
public static final int TABWIDTH
default tab width- See Also:
- Constant Field Values
-
TABULATOR_START
public static final char TABULATOR_START
Character 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:
- Constant Field Values
-
TABULATOR_EXPANSION
public static final char TABULATOR_EXPANSION
Character used to indicate the positions skipped by a tabulator in verbatim content. Currently this is the space character (U+0020).- See Also:
- Constant Field Values
-
TABULATOR_STOP
public static final char TABULATOR_STOP
Character used to indicate a tab stop position in verbatim content. Currently this is the zero-width space (U+200B)- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Verbatim
public Verbatim(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.- Parameters:
includeSpec
- the includeSpec of the contentdata
- raw text
-
Verbatim
public Verbatim(IncludeSpec includeSpec, Verbatim.WhitespaceExpansion wsExpansion, String data)
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 Detail
-
format
public static Verbatim format(IncludeSpec includeSpec, String format, Object... args)
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
public Verbatim.WhitespaceExpansion getWhitespaceExpansion()
- Returns:
- the white space expansion strategy for this content
-
getData
public String getData()
- Returns:
- the raw text of this content
-
setData
public void setData(String data)
Set the raw text- Parameters:
data
- raw text.
-
expandTabsWithSymbols
public 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. The default tab width is used.- Parameters:
line
- the original string- Returns:
- a string, where tabs have been expanded.
-
expandTabsWithSymbols
public 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. 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
public String 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
public static String createSymbolLegendForText(String input)
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
-
toString
public String toString(String prefix)
Description copied from class:Content
This method is for debugging purposes.
-
hashCode
public int hashCode()
implements the contract ofObject.hashCode()
.- Overrides:
hashCode
in classContent
- See Also:
Object.hashCode()
-
equals
public boolean equals(Object obj)
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
public void renderPlainImpl(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx)
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:
Content.renderPlainImpl(StringBuilder, IncludeInfo, RenderContext)
-
-