A Multiple Source Input Framework
This article describes a Java framework for collecting and processing input from five types of input source: files on the local machine, files on the web, copy and paste and drag and drop operations, and programmatic input. The framework distills the five input sources into a generic Reader
object from which the input is read and processed by a data source processor, an abstraction of data processing functionality such as parsing and data analysis.
1. Introduction
This article describes a Java framework for collecting and processing input from five types of input source:
- files on the local machine;
- files on the web;
- copy and paste;
- drag and drop; and
- programmatic input.
The framework captures data from the five input sources by distilling the input sources into a generic Reader object from which the input is read and processed by a data source processor. A data source processor is an abstraction of data processing functionality such as parsing and data analysis. The framework has four layers: input, capture, readers, and processing.
2. Input and Capture
The five input sources are generalized into three groups: URLs, objects transferred with drag and drop and copy and paste operations, and programmatic input. URLs can be selected directly with a WebChooser dialog. When files are selected with a file selection dialog, the URL of the file is obtained by calling the URL toURL()
method of the File
object returned by the file selection dialog.
When the input comes from a drag and drop or copy and paste operation, a Transferable
object that contains the data is captured. Programmatic input does not need to be captured because clients supply the object that contains the data.
3. Readers
The output of the reader stage is a Reader
object that is used by the data source processor to read input data from. When a URL is captured, the getStream()
method of the URL
object is called to return an InputStream
object which is used to create an InputStreamReader
object, a sub-class of the Reader
class.
When a Transferable
object is captured from a drag and drop or a copy and paste operation, the String
object contained in the Transferable
object is used to create a StringReader
object, a sub-class of the Reader
class.
Clients supply a sub-class of the Reader
class for programmatic input.
4. Processing
The data source processor is an abstraction of a processor that accepts data collected by the framework. The data is processed by reading from the Reader
object and processing it in an application specific manner, such as parsing and data analysis. Clients provide an application specific data source processor by implementing the DataSourceProcessor
interface.