Top Description Inners Fields Constructors Methods
org.nibor.autolink

public Class LinkExtractor

extends Object
Class Inheritance
Imports
org.nibor.autolink.internal.*, .Scanner, java.util.*

Extracts links from input.

Create and configure an extractor using builder(), then call extractLinks.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
LinkExtractor.Builder

Builder for configuring link extractor.

private class
private class

Field Summary

Modifier and TypeField and Description
private final Scanner
private final Scanner
private final Scanner

Constructor Summary

AccessConstructor and Description
private
LinkExtractor(UrlScanner urlScanner, WwwScanner wwwScanner, EmailScanner emailScanner)

Method Summary

Modifier and TypeMethod and Description
public static LinkExtractor.Builder
public Iterable<Span>

Returns:

a lazy iterable for the spans in order that they appear in the input, never null
extractSpans
(final CharSequence
the input text, must not be null
input
)

Extract spans from the input text.

private Scanner
trigger(char c)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

emailScannerback to summary
private final Scanner emailScanner
urlScannerback to summary
private final Scanner urlScanner
wwwScannerback to summary
private final Scanner wwwScanner

Constructor Detail

LinkExtractorback to summary
private LinkExtractor(UrlScanner urlScanner, WwwScanner wwwScanner, EmailScanner emailScanner)

Method Detail

builderback to summary
public static LinkExtractor.Builder builder()
extractSpansback to summary
public Iterable<Span> extractSpans(final CharSequence input)

Extract spans from the input text. A span is a substring of the input and represents either a link (see LinkSpan) or plain text outside a link.

Using this is more convenient than extractLinks if you want to transform the whole input text to a different format.

Parameters
input:CharSequence

the input text, must not be null

Returns:Iterable<Span>

a lazy iterable for the spans in order that they appear in the input, never null

triggerback to summary
private Scanner trigger(char c)
org.nibor.autolink back to summary

public Class LinkExtractor.Builder

extends Object
Class Inheritance

Builder for configuring link extractor.

Field Summary

Modifier and TypeField and Description
private boolean
private Set<LinkType>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public LinkExtractor

Returns:

the configured link extractor
build
()

public LinkExtractor.Builder

Returns:

this builder
emailDomainMustHaveDot
(boolean
true if the domain in an email address is required to have more than one part, false if it can also just have single part (e.g. foo@com); true by default
emailDomainMustHaveDot
)

public LinkExtractor.Builder

Returns:

this builder
linkTypes
(Set<LinkType>
the link types that should be extracted (by default, all types are extracted)
linkTypes
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

emailDomainMustHaveDotback to summary
private boolean emailDomainMustHaveDot
linkTypesback to summary
private Set<LinkType> linkTypes

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public LinkExtractor build()
Returns:LinkExtractor

the configured link extractor

emailDomainMustHaveDotback to summary
public LinkExtractor.Builder emailDomainMustHaveDot(boolean emailDomainMustHaveDot)
Parameters
emailDomainMustHaveDot:boolean

true if the domain in an email address is required to have more than one part, false if it can also just have single part (e.g. foo@com); true by default

Returns:LinkExtractor.Builder

this builder

linkTypesback to summary
public LinkExtractor.Builder linkTypes(Set<LinkType> linkTypes)
Parameters
linkTypes:Set<LinkType>

the link types that should be extracted (by default, all types are extracted)

Returns:LinkExtractor.Builder

this builder

org.nibor.autolink back to summary

private Class LinkExtractor.LinkIterator

extends Object
implements Iterator<LinkSpan>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private final CharSequence
private LinkSpan
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public LinkSpan
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private int index
inputback to summary
private final CharSequence input
nextback to summary
private LinkSpan next
rewindIndexback to summary
private int rewindIndex

Constructor Detail

LinkIteratorback to summary
public LinkIterator(CharSequence input)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public LinkSpan next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:LinkSpan

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
setNextback to summary
private void setNext()
org.nibor.autolink back to summary

private Class LinkExtractor.SpanIterator

extends Object
implements Iterator<Span>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private final CharSequence
private final LinkExtractor.LinkIterator
private LinkSpan

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Span
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

private Span
nextTextSpan(int endIndex)

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private int index
inputback to summary
private final CharSequence input
linkIteratorback to summary
private final LinkExtractor.LinkIterator linkIterator

Constructor Detail

SpanIteratorback to summary
public SpanIterator(CharSequence input, LinkExtractor.LinkIterator linkIterator)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Span next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Span

the next element in the iteration

Annotations
@Override
nextTextSpanback to summary
private Span nextTextSpan(int endIndex)
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override