|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
DEPRECATED — DO NOT USE.
This interface is included for backwards compatibility only and will be removed in CSV Manager 2.x
Implement this interface by extending FieldListenerSupport to receive each data field as it is loaded.
It is possible to handle each data field separately with this callback interface.
Pass an instance of FieldListener to CsvManager.setFieldListener(com.ricebridge.csvman.FieldListener) and the CsvManager
will call the addField(java.lang.String) method each time a data field is loaded. The String value of each data field is passed to
the FieldListener using addField(java.lang.String).
At the end of each data line, the endLine(java.lang.String, long) method is called. When a badly formatted line is
encountered, the badLine(com.ricebridge.csvman.BadLine) method is called. Note that a LineListener object is always used as
part of the CSV loading process, so LineListener.handleBadLine(com.ricebridge.csvman.BadLine) will also be called.
During loading, FieldListener methods are always called before LineListener methods.
If you set CsvManager.setIgnoreBadLines(boolean) to true then loading of CSV data will continue
past any badly formatted data lines. If this setting is false (the default), then loading is halted
and a CsvManagerException (CODE_bad_line) is thrown after badLine is called.
To use a FieldListener, just use the CsvManager.load* methods in the usual manner.
The FieldListener functionality is independent of the main loading functionality which uses LineListener.
An example of a FieldListener is provided by DebugFieldListener. This is a simple FieldListener
implementation that prints out debugging information as each data field is parsed. You can use it to see exactly how
far into your CSV file the parser gets before failing.
Important: You should implement this interface by extending the helper class FieldListenerSupport.
This helper class adds fault tolerance and helps make your FieldListener
implementation compatible with any future changes to the CSV Manager API.
Note: you may assume in your implementation that no parameters are null.
The Source Code of this Java class is available under a BSD-style license.
FieldListenerSupport,
CsvManager,
CsvManagerException| Method Summary | |
void |
addField(String pValue)
Deprecated. Called each time a data field is loaded. |
void |
badLine(BadLine pBadLine)
Deprecated. Called when a badly formatted data line is encountered. |
BadLine |
endLine(String pOriginalLine,
long pLineNumber)
Deprecated. Called each time the end of a data line is reached. |
void |
endLoad()
Deprecated. Called just after loading of the CSV data ends. |
void |
startLoad()
Deprecated. Called just before loading of the CSV data starts. |
| Method Detail |
public void startLoad()
You should use this method to initialise any data containers in your FieldListener.
This method is called before LineListener.startProcess().
endLoad()public void endLoad()
You should use this method to release any resources used by your FieldListener.
This method is called before LineListener.endProcess().
startLoad()public void addField(String pValue)
This method is called before LineListener.handleLine(java.lang.String[], int, long, java.lang.String).
Note: implement this method by implementing FieldListenerSupport.addFieldImpl(java.lang.String).
pValue - String value of data field
public BadLine endLine(String pOriginalLine,
long pLineNumber)
If you encounter any errors in the data fields for the current line, use this method to
report them by returning a BadLine object describing the error (If you also return a BadLine from
a FieldListener from the same line, the error message from the BadLine returned here will be appended
to the FieldListener BadLine error message. This is to ensure that only one
BadLine object is created per bad line).
If the data is valid, then return null to indicate that everything is OK.
Note: this method is called before LineListener.handleLine(java.lang.String[], int, long, java.lang.String).
Note: implement this method by implementing FieldListenerSupport.endLineImpl(java.lang.String, long).
pLineNumber - line number index, counting from 1pOriginalLine - original line of data
null if line is OK, BadLine object if line was bad in some waypublic void badLine(BadLine pBadLine)
This method is only called once if CsvManager.setIgnoreBadLines(boolean) is true.
See LineListener.handleBadLine(com.ricebridge.csvman.BadLine) for more details about the pBadLine parameter.
If you return a BadLine from endLine(java.lang.String, long), then it is not subsequently passed into this
method. Only BadLines generated externally are passed into the FieldListener.
This method is called before LineListener.handleBadLine(com.ricebridge.csvman.BadLine).
Note: implement this method by implementing FieldListenerSupport.badLineImpl(com.ricebridge.csvman.BadLine).
pBadLine - BadLine object describing problemLineListener.handleBadLine(com.ricebridge.csvman.BadLine)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||