com.twitter
Class Autolink

java.lang.Object
  extended by com.twitter.Autolink

public class Autolink
extends Object

A class for adding HTML links to hashtag, username and list references in Tweet text.


Nested Class Summary
static interface Autolink.LinkAttributeModifier
           
static interface Autolink.LinkTextModifier
           
 
Field Summary
protected  String cashtagClass
           
protected  String cashtagUrlBase
           
static String DEFAULT_CASHTAG_CLASS
          Default CSS class for auto-linked cashtag URLs
static String DEFAULT_CASHTAG_URL_BASE
          Default href for cashtag links (the cashtag without the $ will be appended)
static String DEFAULT_HASHTAG_CLASS
          Default CSS class for auto-linked hashtag URLs
static String DEFAULT_HASHTAG_URL_BASE
          Default href for hashtag links (the hashtag without the # will be appended)
static String DEFAULT_INVISIBLE_TAG_ATTRS
          Default attribute for invisible span tag
static String DEFAULT_LIST_CLASS
          Default CSS class for auto-linked list URLs
static String DEFAULT_LIST_URL_BASE
          Default href for list links (the username/list without the @ will be appended)
static String DEFAULT_USERNAME_CLASS
          Default CSS class for auto-linked username URLs
static String DEFAULT_USERNAME_URL_BASE
          Default href for username links (the username without the @ will be appended)
protected  String hashtagClass
           
protected  String hashtagUrlBase
           
protected  String invisibleTagAttrs
           
protected  Autolink.LinkAttributeModifier linkAttributeModifier
           
protected  Autolink.LinkTextModifier linkTextModifier
           
protected  String listClass
           
protected  String listUrlBase
           
protected  boolean noFollow
           
protected  String symbolTag
           
protected  String textWithSymbolTag
           
protected  String urlClass
           
protected  String urlTarget
           
protected  String usernameClass
           
protected  boolean usernameIncludeSymbol
           
protected  String usernameUrlBase
           
 
Constructor Summary
Autolink()
           
 
Method Summary
 String autoLink(String text)
          Auto-link hashtags, URLs, usernames and lists.
 String autoLinkCashtags(String text)
          Auto-link $cashtag references in the provided Tweet text.
 String autoLinkEntities(String text, List<Extractor.Entity> entities)
           
 String autoLinkHashtags(String text)
          Auto-link #hashtag references in the provided Tweet text.
 String autoLinkURLs(String text)
          Auto-link URLs in the Tweet text provided.
 String autoLinkUsernamesAndLists(String text)
          Auto-link the @username and @username/list references in the provided text.
 String escapeBrackets(String text)
           
 String getCashtagClass()
           
 String getCashtagUrlBase()
           
 String getHashtagClass()
           
 String getHashtagUrlBase()
           
 String getListClass()
           
 String getListUrlBase()
           
 String getUrlClass()
           
 String getUsernameClass()
           
 String getUsernameUrlBase()
           
 boolean isNoFollow()
           
 void linkToCashtag(Extractor.Entity entity, String text, StringBuilder builder)
           
 void linkToHashtag(Extractor.Entity entity, String text, StringBuilder builder)
           
 void linkToMentionAndList(Extractor.Entity entity, String text, StringBuilder builder)
           
 void linkToText(Extractor.Entity entity, CharSequence text, Map<String,String> attributes, StringBuilder builder)
           
 void linkToTextWithSymbol(Extractor.Entity entity, CharSequence symbol, CharSequence text, Map<String,String> attributes, StringBuilder builder)
           
 void linkToURL(Extractor.Entity entity, String text, StringBuilder builder)
           
 void setCashtagClass(String cashtagClass)
          Set the CSS class for auto-linked cashtag URLs
 void setCashtagUrlBase(String cashtagUrlBase)
          Set the href base for cashtag links.
 void setHashtagClass(String hashtagClass)
          Set the CSS class for auto-linked hashtag URLs
 void setHashtagUrlBase(String hashtagUrlBase)
          Set the href base for hashtag links.
 void setLinkAttributeModifier(Autolink.LinkAttributeModifier modifier)
          Set a modifier to modify attributes of a link based on an entity
 void setLinkTextModifier(Autolink.LinkTextModifier modifier)
          Set a modifier to modify text of a link based on an entity
 void setListClass(String listClass)
          Set the CSS class for auto-linked list URLs
 void setListUrlBase(String listUrlBase)
          Set the href base for list links.
 void setNoFollow(boolean noFollow)
          Set if the current URL links will include rel="nofollow" (true by default)
 void setSymbolTag(String tag)
          Set HTML tag to be applied around #/@/# symbols in hashtags/usernames/lists/cashtag
 void setTextWithSymbolTag(String tag)
          Set HTML tag to be applied around text part of hashtags/usernames/lists/cashtag
 void setUrlClass(String urlClass)
          Set the CSS class for auto-linked URLs
 void setUrlTarget(String target)
          Set the value of the target attribute in auto-linked URLs
 void setUsernameClass(String usernameClass)
          Set the CSS class for auto-linked username URLs
 void setUsernameIncludeSymbol(boolean usernameIncludeSymbol)
          Set if the at mark '@' should be included in the link (false by default)
 void setUsernameUrlBase(String usernameUrlBase)
          Set the href base for username links.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LIST_CLASS

public static final String DEFAULT_LIST_CLASS
Default CSS class for auto-linked list URLs

See Also:
Constant Field Values

DEFAULT_USERNAME_CLASS

public static final String DEFAULT_USERNAME_CLASS
Default CSS class for auto-linked username URLs

See Also:
Constant Field Values

DEFAULT_HASHTAG_CLASS

public static final String DEFAULT_HASHTAG_CLASS
Default CSS class for auto-linked hashtag URLs

See Also:
Constant Field Values

DEFAULT_CASHTAG_CLASS

public static final String DEFAULT_CASHTAG_CLASS
Default CSS class for auto-linked cashtag URLs

See Also:
Constant Field Values

DEFAULT_USERNAME_URL_BASE

public static final String DEFAULT_USERNAME_URL_BASE
Default href for username links (the username without the @ will be appended)

See Also:
Constant Field Values

DEFAULT_LIST_URL_BASE

public static final String DEFAULT_LIST_URL_BASE
Default href for list links (the username/list without the @ will be appended)

See Also:
Constant Field Values

DEFAULT_HASHTAG_URL_BASE

public static final String DEFAULT_HASHTAG_URL_BASE
Default href for hashtag links (the hashtag without the # will be appended)

See Also:
Constant Field Values

DEFAULT_CASHTAG_URL_BASE

public static final String DEFAULT_CASHTAG_URL_BASE
Default href for cashtag links (the cashtag without the $ will be appended)

See Also:
Constant Field Values

DEFAULT_INVISIBLE_TAG_ATTRS

public static final String DEFAULT_INVISIBLE_TAG_ATTRS
Default attribute for invisible span tag

See Also:
Constant Field Values

urlClass

protected String urlClass

listClass

protected String listClass

usernameClass

protected String usernameClass

hashtagClass

protected String hashtagClass

cashtagClass

protected String cashtagClass

usernameUrlBase

protected String usernameUrlBase

listUrlBase

protected String listUrlBase

hashtagUrlBase

protected String hashtagUrlBase

cashtagUrlBase

protected String cashtagUrlBase

invisibleTagAttrs

protected String invisibleTagAttrs

noFollow

protected boolean noFollow

usernameIncludeSymbol

protected boolean usernameIncludeSymbol

symbolTag

protected String symbolTag

textWithSymbolTag

protected String textWithSymbolTag

urlTarget

protected String urlTarget

linkAttributeModifier

protected Autolink.LinkAttributeModifier linkAttributeModifier

linkTextModifier

protected Autolink.LinkTextModifier linkTextModifier
Constructor Detail

Autolink

public Autolink()
Method Detail

escapeBrackets

public String escapeBrackets(String text)

linkToText

public void linkToText(Extractor.Entity entity,
                       CharSequence text,
                       Map<String,String> attributes,
                       StringBuilder builder)

linkToTextWithSymbol

public void linkToTextWithSymbol(Extractor.Entity entity,
                                 CharSequence symbol,
                                 CharSequence text,
                                 Map<String,String> attributes,
                                 StringBuilder builder)

linkToHashtag

public void linkToHashtag(Extractor.Entity entity,
                          String text,
                          StringBuilder builder)

linkToCashtag

public void linkToCashtag(Extractor.Entity entity,
                          String text,
                          StringBuilder builder)

linkToMentionAndList

public void linkToMentionAndList(Extractor.Entity entity,
                                 String text,
                                 StringBuilder builder)

linkToURL

public void linkToURL(Extractor.Entity entity,
                      String text,
                      StringBuilder builder)

autoLinkEntities

public String autoLinkEntities(String text,
                               List<Extractor.Entity> entities)

autoLink

public String autoLink(String text)
Auto-link hashtags, URLs, usernames and lists.

Parameters:
text - of the Tweet to auto-link
Returns:
text with auto-link HTML added

autoLinkUsernamesAndLists

public String autoLinkUsernamesAndLists(String text)
Auto-link the @username and @username/list references in the provided text. Links to @username references will have the usernameClass CSS classes added. Links to @username/list references will have the listClass CSS class added.

Parameters:
text - of the Tweet to auto-link
Returns:
text with auto-link HTML added

autoLinkHashtags

public String autoLinkHashtags(String text)
Auto-link #hashtag references in the provided Tweet text. The #hashtag links will have the hashtagClass CSS class added.

Parameters:
text - of the Tweet to auto-link
Returns:
text with auto-link HTML added

autoLinkURLs

public String autoLinkURLs(String text)
Auto-link URLs in the Tweet text provided.

This only auto-links URLs with protocol.

Parameters:
text - of the Tweet to auto-link
Returns:
text with auto-link HTML added

autoLinkCashtags

public String autoLinkCashtags(String text)
Auto-link $cashtag references in the provided Tweet text. The $cashtag links will have the cashtagClass CSS class added.

Parameters:
text - of the Tweet to auto-link
Returns:
text with auto-link HTML added

getUrlClass

public String getUrlClass()
Returns:
CSS class for auto-linked URLs

setUrlClass

public void setUrlClass(String urlClass)
Set the CSS class for auto-linked URLs

Parameters:
urlClass - new CSS value.

getListClass

public String getListClass()
Returns:
CSS class for auto-linked list URLs

setListClass

public void setListClass(String listClass)
Set the CSS class for auto-linked list URLs

Parameters:
listClass - new CSS value.

getUsernameClass

public String getUsernameClass()
Returns:
CSS class for auto-linked username URLs

setUsernameClass

public void setUsernameClass(String usernameClass)
Set the CSS class for auto-linked username URLs

Parameters:
usernameClass - new CSS value.

getHashtagClass

public String getHashtagClass()
Returns:
CSS class for auto-linked hashtag URLs

setHashtagClass

public void setHashtagClass(String hashtagClass)
Set the CSS class for auto-linked hashtag URLs

Parameters:
hashtagClass - new CSS value.

getCashtagClass

public String getCashtagClass()
Returns:
CSS class for auto-linked cashtag URLs

setCashtagClass

public void setCashtagClass(String cashtagClass)
Set the CSS class for auto-linked cashtag URLs

Parameters:
cashtagClass - new CSS value.

getUsernameUrlBase

public String getUsernameUrlBase()
Returns:
the href value for username links (to which the username will be appended)

setUsernameUrlBase

public void setUsernameUrlBase(String usernameUrlBase)
Set the href base for username links.

Parameters:
usernameUrlBase - new href base value

getListUrlBase

public String getListUrlBase()
Returns:
the href value for list links (to which the username/list will be appended)

setListUrlBase

public void setListUrlBase(String listUrlBase)
Set the href base for list links.

Parameters:
listUrlBase - new href base value

getHashtagUrlBase

public String getHashtagUrlBase()
Returns:
the href value for hashtag links (to which the hashtag will be appended)

setHashtagUrlBase

public void setHashtagUrlBase(String hashtagUrlBase)
Set the href base for hashtag links.

Parameters:
hashtagUrlBase - new href base value

getCashtagUrlBase

public String getCashtagUrlBase()
Returns:
the href value for cashtag links (to which the cashtag will be appended)

setCashtagUrlBase

public void setCashtagUrlBase(String cashtagUrlBase)
Set the href base for cashtag links.

Parameters:
cashtagUrlBase - new href base value

isNoFollow

public boolean isNoFollow()
Returns:
if the current URL links will include rel="nofollow" (true by default)

setNoFollow

public void setNoFollow(boolean noFollow)
Set if the current URL links will include rel="nofollow" (true by default)

Parameters:
noFollow - new noFollow value

setUsernameIncludeSymbol

public void setUsernameIncludeSymbol(boolean usernameIncludeSymbol)
Set if the at mark '@' should be included in the link (false by default)

Parameters:
noFollow - new noFollow value

setSymbolTag

public void setSymbolTag(String tag)
Set HTML tag to be applied around #/@/# symbols in hashtags/usernames/lists/cashtag

Parameters:
tag - HTML tag without bracket. e.g., "b" or "s"

setTextWithSymbolTag

public void setTextWithSymbolTag(String tag)
Set HTML tag to be applied around text part of hashtags/usernames/lists/cashtag

Parameters:
tag - HTML tag without bracket. e.g., "b" or "s"

setUrlTarget

public void setUrlTarget(String target)
Set the value of the target attribute in auto-linked URLs

Parameters:
target - target value e.g., "_blank"

setLinkAttributeModifier

public void setLinkAttributeModifier(Autolink.LinkAttributeModifier modifier)
Set a modifier to modify attributes of a link based on an entity

Parameters:
modifier - LinkAttributeModifier instance

setLinkTextModifier

public void setLinkTextModifier(Autolink.LinkTextModifier modifier)
Set a modifier to modify text of a link based on an entity

Parameters:
modifier - LinkTextModifier instance


Copyright © 2014. All Rights Reserved.