winterwell.jtwitter
Class InternalUtils

java.lang.Object
  extended by winterwell.jtwitter.InternalUtils

public class InternalUtils
extends java.lang.Object

Utility methods used in Twitter. This class is public in case anyone else wants to use these methods. WARNING: they don't really form part of the JTwitter API, and may be changed or reorganised in future versions.

NB: Some of these are copies (sometimes simplified) of methods in winterwell.utils.Utils


Field Summary
static java.util.regex.Pattern latLongLocn
          Matches latitude, longitude, including with the UberTwitter UT: prefix Group 2 = latitude, Group 3 = longitude.
static java.util.regex.Pattern pComment
          Matches an xml comment - including some bad versions
static java.util.regex.Pattern pDocType
          Matches a doctype element.
static java.util.regex.Pattern pScriptOrStyle
          Used in strip tags to get rid of scripts and css style blocks altogether.
static java.util.regex.Pattern REGEX_JUST_DIGITS
           
static java.util.regex.Pattern TAG_REGEX
           
 
Constructor Summary
InternalUtils()
           
 
Method Summary
static java.util.Map asMap(java.lang.Object... keyValuePairs)
          Create a map from a list of key, value pairs.
static void close(java.io.Closeable strm)
           
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Long> getAPIUsageStats()
           
static java.util.Date getDate(int year, java.lang.String month, int day)
          Convenience method for making Dates.
static java.lang.String join(java.lang.String[] screenNames)
          Join the list
protected static java.lang.String jsonGet(java.lang.String key, winterwell.json.JSONObject jsonObj)
          Helper method to deal with JSON-in-Java weirdness
static void setTrackAPIUsage(boolean on)
           
static java.lang.String stripTags(java.lang.String xml)
          Remove xml and html tags, e.g.
static java.lang.String stripUrls(java.lang.String text)
           
protected static java.lang.String toString(java.io.InputStream inputStream)
          Use a bufferred reader (preferably UTF-8) to extract the contents of the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_REGEX

public static final java.util.regex.Pattern TAG_REGEX

latLongLocn

public static final java.util.regex.Pattern latLongLocn
Matches latitude, longitude, including with the UberTwitter UT: prefix Group 2 = latitude, Group 3 = longitude.

Weird: I saw this as an address - "ÜT: 25.324488,55.376224t" Is it just a one-off typo? Should we match N/S/E/W markers?


REGEX_JUST_DIGITS

public static final java.util.regex.Pattern REGEX_JUST_DIGITS

pComment

public static final java.util.regex.Pattern pComment
Matches an xml comment - including some bad versions


pScriptOrStyle

public static final java.util.regex.Pattern pScriptOrStyle
Used in strip tags to get rid of scripts and css style blocks altogether.


pDocType

public static final java.util.regex.Pattern pDocType
Matches a doctype element.

Constructor Detail

InternalUtils

public InternalUtils()
Method Detail

stripUrls

public static java.lang.String stripUrls(java.lang.String text)

asMap

public static java.util.Map asMap(java.lang.Object... keyValuePairs)
Create a map from a list of key, value pairs. An easy way to make small maps, basically the equivalent of Arrays.asList(Object...). If the value is null, the key will not be included.


close

public static void close(java.io.Closeable strm)

getAPIUsageStats

public static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Long> getAPIUsageStats()
Returns:
a map of API endpoint to count-of-calls. null if switched off (which is the default).
See Also:
setTrackAPIUsage(boolean)

getDate

public static java.util.Date getDate(int year,
                                     java.lang.String month,
                                     int day)
Convenience method for making Dates. Because Date is a tricksy bugger of a class.

Parameters:
year -
month -
day -
Returns:
date object

join

public static java.lang.String join(java.lang.String[] screenNames)
Join the list

Parameters:
screenNames -
Returns:

jsonGet

protected static java.lang.String jsonGet(java.lang.String key,
                                          winterwell.json.JSONObject jsonObj)
Helper method to deal with JSON-in-Java weirdness

Returns:
Can be null

setTrackAPIUsage

public static void setTrackAPIUsage(boolean on)
Parameters:
on - true to activate getAPIUsageStats(). false to switch stats off. false by default

toString

protected static java.lang.String toString(java.io.InputStream inputStream)
Use a bufferred reader (preferably UTF-8) to extract the contents of the given stream. A convenience method for toString(Reader).


stripTags

public static java.lang.String stripTags(java.lang.String xml)
Remove xml and html tags, e.g. to safeguard against javascript injection attacks, or to get plain text for NLP.

Parameters:
xml - can be null, in which case null will be returned
Returns:
the text contents - ie input with all tags removed