ca.cbc.sportwire.feed
Class TSNFeed

java.lang.Object
  |
  +--ca.cbc.sportwire.feed.TSNFeed
All Implemented Interfaces:
java.lang.Runnable, SportwireFeed, TSNFeedProperties, WireFeederProperties

public class TSNFeed
extends java.lang.Object
implements java.lang.Runnable, SportwireFeed, TSNFeedProperties, WireFeederProperties

TSNFeed.java Read the TSN XML stream socket into a buffer and provide a string reader over the spooled story breaking the input at

Created: Mon Mar 25 20:43:39 EST 2002

Version:
$Id: TSNFeed.java,v 1.10 2002/04/19 20:38:04 garym Exp $
Author:
Gary Lawrence Murphy

Field Summary
private  java.net.InetAddress authHost
           
(package private) static org.apache.log4j.Category cat
           
private  org.apache.commons.collections.ExtendedProperties config
           
private  java.lang.String connectState
           
private static org.apache.oro.text.regex.Pattern elementpattern
           
private static TSNFeed feeder
          singleton constructor
private static java.util.List fixkeys
           
private static RegexMap fixmap
           
private  java.io.BufferedReader in
           
private  boolean isrunning
           
private  java.lang.String lastTag
           
private  java.io.PrintWriter log
           
private static org.apache.oro.text.regex.Perl5Compiler perl
           
private  java.lang.StringBuffer storybuffer
           
private static org.apache.oro.text.regex.Pattern tagpattern
           
 
Fields inherited from interface ca.cbc.sportwire.feed.TSNFeedProperties
ELEMENT_PATTERN_DEFAULT, ELEMENT_PATTERN_PROPERTY, PAGEBREAK, TSN_HOST_PROPERTY, TSN_IDLE_DEFAULT, TSN_IDLE_PROPERTY, TSN_PASSWORD_PROPERTY, TSN_PORT_PROPERTY, TSN_SOURCE_DEFAULT, TSN_SOURCE_PROPERTY, TSN_SPOOL_PROPERTY, TSN_TAG_DEFAULT, TSN_TAG_PROPERTY, TSN_USER_PROPERTY
 
Fields inherited from interface ca.cbc.sportwire.WireFeederProperties
CONFIGFILE_DEFAULT, CONFIGFILE_PROPERTY, DEFAULT_FILENAME_XPATH, DEFAULT_SAX_DRIVER_CLASS, DEFAULT_XML_PATH, DEFAULT_XMLRPC_PORT, DOCHANDLER_DEFAULT, DOCHANDLER_PROPERTY, DOCWORKERS_DEFAULT, DOCWORKERS_PROPERTY, DTD_PATH_PROPERTY, FEED_REGEX_PROPERTY, FEEDCLASS_DEFAULT, FEEDCLASS_PROPERTY, FEEDFILTER_DEFAULT, FEEDFILTER_PROPERTY, FILENAME_XPATH_PROPERTY, IGNOREFILE_PROPERTY, LOGFILE_DEFAULT, LOGFILE_PROPERTY, MAP_PATH_PROPERTY, SAX_CLASS_PROPERTY, WATCHDOG_IDLE_DEFAULT, WATCHDOG_IDLE_PROPERTY, XML_PATH_PROPERTY, XMLRPC_PORT_PROPERTY, XSL_PATH_PROPERTY
 
Constructor Summary
protected TSNFeed(org.apache.commons.collections.ExtendedProperties sc)
          TSNFeed constructor
 
Method Summary
protected  int bufferStory()
          bufferStory spools one document at a time for the SportWire system to load into the doc queue for later parsing/archiving or whatever else gets done to it.
protected  com.oroinc.net.telnet.TelnetClient connect()
          connect: open the socket to TSN and do the login sequence to get connected
static int countLines(java.lang.String text)
          countLines: returns the number of newline chars in the string; used to decide if a CDATA block is worth piping out to the txt2html process.
protected  java.lang.String filter(java.lang.String line)
          filter: apply various fixups to the line-by-line feed; also watches for the DOCTYPE to trap the doctag value.
protected  org.apache.commons.collections.ExtendedProperties getConfig()
          Get the value of config.
protected  java.io.BufferedReader getIn()
          getIn: returns the current input stream reader
static SportwireFeed getInstance(org.apache.commons.collections.ExtendedProperties sc)
          getInstance returns the Singleton, synchronized to protect against concurrent invocations.
 java.lang.String getLastTag()
          getLastTag: holds the tag id value from the last item read; used by the WireParser to filter unwanted messages
 java.lang.String getStatus()
          Get the value of connectState.
private  java.lang.StringBuffer getStorybuffer()
           
protected  boolean login(com.oroinc.net.telnet.TelnetClient socket)
          login: dead stupid login chat
 java.lang.String logLine()
          logLine: add a blank line to the log
 java.lang.String logLine(java.lang.String line)
          logLine: add the message to the spool log; this lets us record the pre-processed (ie fixed) XML received over the socket.
protected  java.lang.String readPrompt()
          readPrompt: reads in characters looking for the end of the prompt (new line or colon)
 void run()
          run: when running in socket mode, this will ensure the connection stays alive and has workers reading it.
 boolean running()
          running: returns true while the socket reader thread is active
protected  void runstate(boolean r)
          runstate: set the run state indicator
protected  void setIn(java.io.InputStream in)
          setIn: sets the current input stream and wraps it in a buffered reader with a buffer of 256k
protected  void setStatus(java.lang.String v)
          Set the value of connectState.
 void skipToNext()
          Deprecated.  
protected  void startLog()
          startLog: if tsn.log appears in the config file, it defines a filename that will receive everything the wire receives (after the cleanup of bad XML).
protected  boolean startSession()
          startSession: tests the config parameters and starts up the wire service reader thread
 void stop()
          stop: override TSN method to avoid system exit
 java.io.Reader storyReader()
          Method: 'storyReader' provides a StringReader over the internal story buffer.
protected  java.lang.String toHtml(java.lang.String cdata)
          toHtml: if the string is longer than 3 lines of text, it gets piped out to an external process to be translated to HTML.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

static org.apache.log4j.Category cat

config

private org.apache.commons.collections.ExtendedProperties config

connectState

private java.lang.String connectState

log

private java.io.PrintWriter log

in

private java.io.BufferedReader in

authHost

private java.net.InetAddress authHost

lastTag

private java.lang.String lastTag

storybuffer

private java.lang.StringBuffer storybuffer

isrunning

private boolean isrunning

perl

private static org.apache.oro.text.regex.Perl5Compiler perl

fixmap

private static RegexMap fixmap

fixkeys

private static java.util.List fixkeys

tagpattern

private static org.apache.oro.text.regex.Pattern tagpattern

elementpattern

private static org.apache.oro.text.regex.Pattern elementpattern

feeder

private static TSNFeed feeder
singleton constructor
Constructor Detail

TSNFeed

protected TSNFeed(org.apache.commons.collections.ExtendedProperties sc)
TSNFeed constructor
Parameters:
sc - an ExtendedProperties value
Method Detail

getConfig

protected org.apache.commons.collections.ExtendedProperties getConfig()
Get the value of config.
Returns:
ExtendedProperties value of config.

getStatus

public java.lang.String getStatus()
Get the value of connectState.
Specified by:
getStatus in interface SportwireFeed
Returns:
String value of connectState.

setStatus

protected void setStatus(java.lang.String v)
Set the value of connectState.
Parameters:
v - Value to assign to connectState.

getIn

protected java.io.BufferedReader getIn()
getIn: returns the current input stream reader
Returns:
a BufferedReader value

setIn

protected void setIn(java.io.InputStream in)
setIn: sets the current input stream and wraps it in a buffered reader with a buffer of 256k
Parameters:
in - an InputStream value

getLastTag

public java.lang.String getLastTag()
getLastTag: holds the tag id value from the last item read; used by the WireParser to filter unwanted messages
Specified by:
getLastTag in interface SportwireFeed
Returns:
a String value

getStorybuffer

private java.lang.StringBuffer getStorybuffer()

running

public boolean running()
running: returns true while the socket reader thread is active
Returns:
a boolean value

runstate

protected void runstate(boolean r)
runstate: set the run state indicator
Parameters:
r - a boolean value

startLog

protected void startLog()
startLog: if tsn.log appears in the config file, it defines a filename that will receive everything the wire receives (after the cleanup of bad XML). This is useful for creating test data that you can then pipe into the program after disabling the socket reader.

getInstance

public static SportwireFeed getInstance(org.apache.commons.collections.ExtendedProperties sc)
getInstance returns the Singleton, synchronized to protect against concurrent invocations.
Parameters:
sc - an ExtendedProperties value
Returns:
a SportwireFeed value

startSession

protected boolean startSession()
startSession: tests the config parameters and starts up the wire service reader thread
Returns:
a boolean true if all goes well

connect

protected com.oroinc.net.telnet.TelnetClient connect()
                                              throws java.io.IOException
connect: open the socket to TSN and do the login sequence to get connected
Returns:
a Socket value
Throws:
java.io.IOException - if an error occurs

readPrompt

protected java.lang.String readPrompt()
                               throws java.io.IOException
readPrompt: reads in characters looking for the end of the prompt (new line or colon)
Returns:
a String value
Throws:
java.io.IOException - if an error occurs

login

protected boolean login(com.oroinc.net.telnet.TelnetClient socket)
login: dead stupid login chat
Parameters:
socket - a TelnetClient value
Returns:
a boolean value

run

public void run()
run: when running in socket mode, this will ensure the connection stays alive and has workers reading it.
Specified by:
run in interface java.lang.Runnable

stop

public void stop()
stop: override TSN method to avoid system exit

skipToNext

public void skipToNext()
                throws java.io.IOException
Deprecated.  

Method: 'skipToNext' syncs the ticker to the next complete story; if it was already at the top of a story, this scraps that one and moves on to the next.
Specified by:
skipToNext in interface SportwireFeed
Throws:
java.io.IOException - if a read error occurs

countLines

public static int countLines(java.lang.String text)
countLines: returns the number of newline chars in the string; used to decide if a CDATA block is worth piping out to the txt2html process.
Parameters:
text - a String value
Returns:
an int value

toHtml

protected java.lang.String toHtml(java.lang.String cdata)
toHtml: if the string is longer than 3 lines of text, it gets piped out to an external process to be translated to HTML.
Parameters:
cdata - a String value
Returns:
a String value

filter

protected java.lang.String filter(java.lang.String line)
filter: apply various fixups to the line-by-line feed; also watches for the DOCTYPE to trap the doctag value.
Parameters:
line - a String value
Returns:
a String value

logLine

public java.lang.String logLine()
logLine: add a blank line to the log
Returns:
a String value

logLine

public java.lang.String logLine(java.lang.String line)
logLine: add the message to the spool log; this lets us record the pre-processed (ie fixed) XML received over the socket.
Parameters:
line - a String value
Returns:
a String value

bufferStory

protected int bufferStory()
                   throws java.io.IOException
bufferStory spools one document at a time for the SportWire system to load into the doc queue for later parsing/archiving or whatever else gets done to it. Keep in mind that TSN XML is not legal XML, so this method will correct certain patterns on the fly.
Returns:
int count of lines in this story
Throws:
java.io.IOException - if an error occurs

storyReader

public java.io.Reader storyReader()
                           throws java.io.IOException
Method: 'storyReader' provides a StringReader over the internal story buffer. The storybuffer is replaced with each call to skipToNext.
Specified by:
storyReader in interface SportwireFeed
Returns:
'Reader' value
Throws:
java.io.IOException - if an error occurs