- java.lang.Object
-
- org.nibor.autolink.LinkExtractor
-
public class LinkExtractor extends java.lang.Object
Extracts links from input.Create and configure an extractor using
builder()
, then callextractLinks(java.lang.CharSequence)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LinkExtractor.Builder
Builder for configuring link extractor.private class
LinkExtractor.LinkIterator
private class
LinkExtractor.SpanIterator
-
Field Summary
Fields Modifier and Type Field Description private Scanner
emailScanner
private Scanner
urlScanner
private Scanner
wwwScanner
-
Constructor Summary
Constructors Modifier Constructor Description private
LinkExtractor(UrlScanner urlScanner, WwwScanner wwwScanner, EmailScanner emailScanner)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LinkExtractor.Builder
builder()
java.lang.Iterable<LinkSpan>
extractLinks(java.lang.CharSequence input)
Extract the links from the input text.java.lang.Iterable<Span>
extractSpans(java.lang.CharSequence input)
Extract spans from the input text.private Scanner
trigger(char c)
-
-
-
Constructor Detail
-
LinkExtractor
private LinkExtractor(UrlScanner urlScanner, WwwScanner wwwScanner, EmailScanner emailScanner)
-
-
Method Detail
-
builder
public static LinkExtractor.Builder builder()
-
extractLinks
public java.lang.Iterable<LinkSpan> extractLinks(java.lang.CharSequence input)
Extract the links from the input text. Can be called multiple times with different inputs (thread-safe).- Parameters:
input
- the input text, must not be null- Returns:
- a lazy iterable for the links in order that they appear in the input, never null
- See Also:
extractSpans to also get spans for the plain text pieces of the input
-
extractSpans
public java.lang.Iterable<Span> extractSpans(java.lang.CharSequence input)
Extract spans from the input text. A span is a substring of the input and represents either a link (seeLinkSpan
) or plain text outside a link.Using this is more convenient than
extractLinks(java.lang.CharSequence)
if you want to transform the whole input text to a different format.- Parameters:
input
- the input text, must not be null- Returns:
- a lazy iterable for the spans in order that they appear in the input, never null
-
trigger
private Scanner trigger(char c)
-
-