|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.alicebot.server.core.parser.GenericReader
public abstract class GenericReader
Provides generic reading functionality for such classes
as AIMLReader
and org.alicebot.server.core.util.TargetsReader
.
Nested Class Summary | |
---|---|
class |
GenericReader.TransitionMade
Thrown by the various transition
methods when a transition is successfully made. |
Field Summary | |
---|---|
protected static java.lang.String |
ASTERISK
An asterisk. |
protected java.lang.StringBuffer |
buffer
The parse buffer. |
protected static int |
bufferStartCapacity
An estimate of the maximum buffer length needed (helps tune performance). |
protected java.lang.String |
bufferString
The parse buffer as a String. |
protected java.io.BufferedReader |
buffReader
Access to the file. |
protected long |
byteCount
Used to count bytes read. |
protected static java.lang.String |
COLON
A colon. |
protected static java.lang.String |
COMMENT_MARK
' !-- ' |
protected boolean |
done
The flag that indicates whether parsing is done. |
protected static java.lang.String |
EMPTY_STRING
An empty string. |
protected java.lang.String |
encoding
Used to calculate bytes read. |
protected java.lang.String |
fileName
The name of the file. |
protected static java.lang.String |
LINE_SEPARATOR
The system line separator. |
protected int |
lineNumber
The current line number. |
protected GenericReaderListener |
listener
The Listener that will handle new items. |
protected static java.lang.String |
MARKER_END
The end of a tag marker. |
protected static java.lang.String |
MARKER_START
The start of a tag marker. |
protected static java.lang.String |
QUOTE_MARK
A quote mark. |
protected GenericReader |
readerInstance
An instance of GenericReader should set this field to itself. |
protected boolean |
searching
The flag that indicates whether the read method is searching for a tag marker start. |
protected int |
searchStart
The location in bufferString to...... |
protected static java.lang.String |
SLASH
A slash. |
protected static java.lang.String |
SPACE
A space. |
protected int |
state
Parser state. |
protected int |
tagLength
The most recent length of a tag being checked. |
protected int |
tagStart
The most recent start of a tag. |
protected GenericReader.TransitionMade |
TRANSITION_MADE
A custom Throwable thrown by the various transition methods if they succeed. |
Constructor Summary | |
---|---|
GenericReader(java.lang.String fileName,
java.io.BufferedReader buffReader,
GenericReaderListener listener)
Constructs a new GenericReader , given a
BufferedReader handle to some input stream
(buffReader ), a filename to use in printing error messages
(fileName ), and a TargetsReaderListener that will
handle creation of new categories as they are discovered. |
|
GenericReader(java.lang.String fileName,
java.io.BufferedReader buffReader,
java.lang.String encoding,
boolean countBytes,
GenericReaderListener listener)
Constructs a new GenericReader , given a
BufferedReader handle to some input stream
(buffReader ), a filename to use in printing error messages
(fileName ), and a TargetsReaderListener that will
handle creation of new categories as they are discovered. |
Method Summary | |
---|---|
protected abstract void |
initialize()
|
void |
read()
Reads a targets data file and looks for categories. |
protected boolean |
succeed(java.lang.String tag,
int toState)
Checks whether bufferString contains
tag at tagStart , |
protected void |
transition(java.lang.String tag,
int toState)
If bufferString contains
tag at tagStart and
sets state to toState . |
protected void |
transition(java.lang.String tag,
int toState,
java.lang.reflect.Field component)
If bufferString contains
tag at tagStart ,
sets state to toState ,
captures the substring of bufferString from
0 to tagStart ,
filtering whitespace and setting component
to the result. |
protected void |
transition(java.lang.String tag,
int toState,
java.lang.reflect.Field component,
java.lang.String attributeName)
If bufferString contains
tag at tagStart ,
sets state to toState ,
captures the substring of bufferString from
0 to tagStart ,
filtering whitespace and setting component
to the result, then deleting the tag from the buffer. |
protected abstract void |
tryStates()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String MARKER_START
protected static final java.lang.String MARKER_END
protected static final java.lang.String COMMENT_MARK
!--
'
protected static final java.lang.String EMPTY_STRING
protected static final java.lang.String SLASH
protected static final java.lang.String QUOTE_MARK
protected static final java.lang.String ASTERISK
protected static final java.lang.String COLON
protected static final java.lang.String SPACE
protected static final java.lang.String LINE_SEPARATOR
protected static int bufferStartCapacity
protected GenericReader readerInstance
protected GenericReaderListener listener
Listener
that will handle new items.
protected java.io.BufferedReader buffReader
protected java.lang.String fileName
protected boolean done
protected boolean searching
protected int state
protected int tagStart
protected int tagLength
protected int searchStart
protected int lineNumber
protected java.lang.StringBuffer buffer
protected java.lang.String bufferString
protected GenericReader.TransitionMade TRANSITION_MADE
transition
methods if they succeed.
protected long byteCount
protected java.lang.String encoding
Constructor Detail |
---|
public GenericReader(java.lang.String fileName, java.io.BufferedReader buffReader, java.lang.String encoding, boolean countBytes, GenericReaderListener listener)
GenericReader
, given a
BufferedReader
handle to some input stream
(buffReader
), a filename to use in printing error messages
(fileName
), and a TargetsReaderListener
that will
handle creation of new categories as they are discovered.
fileName
- name of the targets data file to be readbuffReader
- a BufferedReader already open to the file (could be remote)encoding
- the encoding with which the file is being readcountBytes
- whether or not to count bytes read (slows down the process)listener
- will handle new itemsTargets
public GenericReader(java.lang.String fileName, java.io.BufferedReader buffReader, GenericReaderListener listener)
GenericReader
, given a
BufferedReader
handle to some input stream
(buffReader
), a filename to use in printing error messages
(fileName
), and a TargetsReaderListener
that will
handle creation of new categories as they are discovered.
In this version, byte counting is disabled.
fileName
- name of the targets data file to be readbuffReader
- a BufferedReader already open to the file (could be remote)listener
- will handle new itemsTargets
Method Detail |
---|
protected abstract void initialize()
public void read()
protected abstract void tryStates() throws GenericReader.TransitionMade
GenericReader.TransitionMade
protected boolean succeed(java.lang.String tag, int toState)
Checks whether bufferString
contains
tag
at tagStart
,
If so, sets tagLength
to the length of
tag
, sets state
to toState
and returns true
.
If not, returns false
.
tag
- the tag to look for in buffer
toState
- the parser state
to assign if successful
protected void transition(java.lang.String tag, int toState) throws GenericReader.TransitionMade
bufferString
contains
tag
at tagStart
and
sets state
to toState
.
tag
- the tag to look for in buffer
toState
- the parser state
to assign if successful
GenericReader.TransitionMade
- if the transition is successfully madeprotected void transition(java.lang.String tag, int toState, java.lang.reflect.Field component) throws GenericReader.TransitionMade
bufferString
contains
tag
at tagStart
,
sets state
to toState
,
captures the substring of bufferString
from
0
to tagStart
,
filtering whitespace and setting component
to the result.
tag
- the tag to look for in buffer
toState
- the parser state
to assign if successfulcomponent
- the component to set to the whitespace-filtered substring of buffer
from 0
to tagStart
GenericReader.TransitionMade
- if the transition is successfully madeprotected void transition(java.lang.String tag, int toState, java.lang.reflect.Field component, java.lang.String attributeName) throws GenericReader.TransitionMade
If bufferString
contains
tag
at tagStart
,
sets state
to toState
,
captures the substring of bufferString
from
0
to tagStart
,
filtering whitespace and setting component
to the result, then deleting the tag from the buffer.
tag
- the tag to look for in buffer
toState
- the parser state
to assign if successfulcomponent
- the component to set to the whitespace-filtered substring of buffer
from 0
to tagStart
attributeName
- the name of the attribute holding the desired content
GenericReader.TransitionMade
- if the transition is successfully made
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |