com.twitter
Class HitHighlighter

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

public class HitHighlighter
extends java.lang.Object

A class for adding HTML highlighting in Tweet text (such as would be returned from a Search)


Field Summary
static java.lang.String DEFAULT_HIGHLIGHT_TAG
          Default HTML tag for highlight hits
protected  java.lang.String highlightTag
          the current HTML tag used for hit highlighting
 
Constructor Summary
HitHighlighter()
          Create a new HitHighlighter object.
 
Method Summary
 java.lang.String getHighlightTag()
          Get the current HTML tag used for phrase highlighting.
 java.lang.String highlight(java.lang.String text, java.util.List<java.util.List<java.lang.Integer>> hits)
          Surround the hits in the provided text with an HTML tag.
 void setHighlightTag(java.lang.String highlightTag)
          Set the current HTML tag used for phrase highlighting.
protected  java.lang.String tag(boolean closeTag)
          Format the current highlightTag by adding < and >.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HIGHLIGHT_TAG

public static final java.lang.String DEFAULT_HIGHLIGHT_TAG
Default HTML tag for highlight hits

See Also:
Constant Field Values

highlightTag

protected java.lang.String highlightTag
the current HTML tag used for hit highlighting

Constructor Detail

HitHighlighter

public HitHighlighter()
Create a new HitHighlighter object.

Method Detail

highlight

public java.lang.String highlight(java.lang.String text,
                                  java.util.List<java.util.List<java.lang.Integer>> hits)
Surround the hits in the provided text with an HTML tag. This is used with offsets from the search API to support the highlighting of query terms.

Parameters:
text - of the Tweet to highlight
hits - A List of highlighting offsets (themselves lists of two elements)
Returns:
text with highlight HTML added

tag

protected java.lang.String tag(boolean closeTag)
Format the current highlightTag by adding < and >. If closeTag is true then the tag returned will include a / to signify a closing tag.

Parameters:
true - if this is a closing tag, false otherwise

getHighlightTag

public java.lang.String getHighlightTag()
Get the current HTML tag used for phrase highlighting.

Returns:
current HTML tag (without < or >)

setHighlightTag

public void setHighlightTag(java.lang.String highlightTag)
Set the current HTML tag used for phrase highlighting.

Parameters:
new - HTML tag (without < or >)


Copyright © 2010 Twitter, Inc. All Rights Reserved.