Class BBCodeParser

java.lang.Object
atlantafx.base.util.BBCodeParser

public class BBCodeParser extends Object
A simple push parser for the BBCode markup. As the content is parsed, methods of BBCodeHandler are called.

The parser doesn't impose restrictions on tag names or tag params. It's a handler implementation responsibility to differentiate supported tags from unsupported and so to for the tag params. This allows user to utilize arbitrary tags or params without changing the parser behaviour. The parser, however, verifies that each opening tag has the matching closing tag.

If parsing is failed due to invalid input an IllegalStateException will be thrown.

  • Field Details

    • RESERVED_TAGS

      public static final Set<String> RESERVED_TAGS
      Reserved tag names. Note, this isn't the list of supported codes as the BBCodeHandler is responsible for implementation.
  • Constructor Details

    • BBCodeParser

      public BBCodeParser(String input, BBCodeHandler handler)
      Creates a new parser.
    • BBCodeParser

      public BBCodeParser(String input, BBCodeHandler handler, @Nullable @Nullable Set<String> tags)
      Creates a new parser.
      Parameters:
      input - An input non-null string.
      handler - A BBCodeHandler implementation.
      tags - The list of processed tags, i.e. the tags that parser won't ignore.
  • Method Details

    • parse

      public void parse()
      Starts input parsing. There's no way to stop the process until parsing is finished.
    • createFormattedText

      public static javafx.scene.text.TextFlow createFormattedText(String input)
    • createLayout

      public static javafx.scene.layout.VBox createLayout(String input)
    • createLayout

      public static <T extends javafx.scene.layout.Pane> T createLayout(String input, T container)
      Parses the given string using BBCode markup and returns corresponding layout. This is a shorthand method for using the feature.
      Parameters:
      input - The BBCode markup string.
      container - The root container.
      See Also:
    • handleStartTag

      protected boolean handleStartTag(int start, int length, boolean selfClose)
    • handleEndTag

      protected boolean handleEndTag(int start, int length)
    • handleCharacters

      protected void handleCharacters(int start, int length)
    • splitBySpace

      protected List<String> splitBySpace(String str, int start, int length)
      Splits input string by whitespace ignoring quoted text. E.g.
       "foo bar" = ["foo", "bar"]
       "foo 'bar baz'" = ["foo", "bar baz"]