Class 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
    • 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
      • 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 content
        data - 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 content
        wsExpansion - the expansion strategy for white spaces in the raw text
        data - 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 content
        format - format string as defined by Formatter to create a raw text
        args - 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 string
        tabWidth - 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 with setTabWidth(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 parameter input.
        Parameters:
        input - text
        Returns:
        a legend string
      • toString

        public String toString​(String prefix)
        Description copied from class: Content
        This method is for debugging purposes.
        Overrides:
        toString in class Content
        Parameters:
        prefix - If the output has multiple lines, prefix specifies the indentation of the subsequent lines.
        Returns:
        a string representation of the content and it's internal structure.
        See Also:
        de.hsh.graja.util.Content#toString(java.lang.String)
      • 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 class Content
        Parameters:
        sb - HTML code result
        includeInfo - controls, which content to be rendered.
        ctx - render context
        useJavascript - if true, the generated HTML code will contain Javascript
        See Also:
        Content#renderHtmlImpl(StringBuilder, IncludeInfo, RenderContext)