org.clapper.curn.output
Class FileOutputHandler

java.lang.Object
  extended by org.clapper.curn.output.FileOutputHandler
All Implemented Interfaces:
OutputHandler
Direct Known Subclasses:
FreeMarkerOutputHandler, ScriptOutputHandler

public abstract class FileOutputHandler
extends java.lang.Object
implements OutputHandler

FileOutputHandler is an abstract base class for OutputHandler subclasses that write RSS feed summaries to a file. It consolidates common logic and configuration handling for such classes, providing both consistent implementation and configuration.

Version:
$Revision: 6459 $
See Also:
OutputHandler, Curn, RSSChannel

Field Summary
static java.lang.String CFG_ENCODING
          Configuration variable: encoding
static java.lang.String CFG_SAVE_AS
          Where to save the output, if any
static java.lang.String CFG_SAVE_ONLY
          Whether we're ONLY saving output
static java.lang.String CFG_SAVED_BACKUPS
          Number of backups of saved files to keep.
static java.lang.String CFG_SHOW_CURN_INFO
          Whether or not to show curn information
 
Constructor Summary
FileOutputHandler()
          Construct a new FileOutputHandler
 
Method Summary
abstract  void displayChannel(RSSChannel channel, FeedInfo feedInfo)
          Display the list of RSSItem news items to whatever output is defined for the underlying class.
protected  boolean displayToolInfo()
          Determine whether or not to display curn tool-related information in the generated output.
abstract  void flush()
          Flush any buffered-up output.
abstract  java.lang.String getContentType()
          Get the content (i.e., MIME) type for output produced by this output handler.
 java.io.File getGeneratedOutput()
          Get the File that represents the output produced by the handler, if applicable.
 java.lang.String getName()
          Get the name of this output handler.
 java.lang.String getOutputEncoding()
          Get the output encoding.
protected  java.io.File getOutputFile()
          Get the output file.
 boolean hasGeneratedOutput()
          Determine whether this handler has produced any actual output (i.e., whether getGeneratedOutput() will return a non-null File if called).
 void init(CurnConfig config, ConfiguredOutputHandler cfgHandler)
          Initializes the output handler for another set of RSS channels.
abstract  void initOutputHandler(CurnConfig config, ConfiguredOutputHandler cfgHandler)
          Perform any subclass-specific initialization.
protected  java.io.PrintWriter openOutputFile()
          Open the output file, returning a PrintWriter.
protected  boolean savingOutputOnly()
          Determine whether the handler is saving output only, or also reporting output to curn.
 void setName(java.lang.String name)
          Set the name of this output handler.
protected  void setOutputEncoding(java.lang.String newEncoding)
          Override the encoding specified by the CFG_ENCODING configuration parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CFG_ENCODING

public static final java.lang.String CFG_ENCODING
Configuration variable: encoding

See Also:
Constant Field Values

CFG_SHOW_CURN_INFO

public static final java.lang.String CFG_SHOW_CURN_INFO
Whether or not to show curn information

See Also:
Constant Field Values

CFG_SAVE_AS

public static final java.lang.String CFG_SAVE_AS
Where to save the output, if any

See Also:
Constant Field Values

CFG_SAVE_ONLY

public static final java.lang.String CFG_SAVE_ONLY
Whether we're ONLY saving output

See Also:
Constant Field Values

CFG_SAVED_BACKUPS

public static final java.lang.String CFG_SAVED_BACKUPS
Number of backups of saved files to keep.

See Also:
Constant Field Values
Constructor Detail

FileOutputHandler

public FileOutputHandler()
Construct a new FileOutputHandler

Method Detail

getName

public java.lang.String getName()
Get the name of this output handler. The name must be unique.

Specified by:
getName in interface OutputHandler
Returns:
the name

setName

public void setName(java.lang.String name)
             throws CurnException
Set the name of this output handler. Called by curn.

Specified by:
setName in interface OutputHandler
Parameters:
name - the name
Throws:
CurnException - on error

init

public final void init(CurnConfig config,
                       ConfiguredOutputHandler cfgHandler)
                throws org.clapper.util.config.ConfigurationException,
                       CurnException
Initializes the output handler for another set of RSS channels.

Specified by:
init in interface OutputHandler
Parameters:
config - the parsed curn configuration data
cfgHandler - the ConfiguredOutputHandler wrapper containing this object; the wrapper has some useful metadata, such as the object's configuration section name and extra variables.
Throws:
org.clapper.util.config.ConfigurationException - configuration error
CurnException - some other initialization error
See Also:
CurnConfig, ConfiguredOutputHandler

initOutputHandler

public abstract void initOutputHandler(CurnConfig config,
                                       ConfiguredOutputHandler cfgHandler)
                                throws org.clapper.util.config.ConfigurationException,
                                       CurnException
Perform any subclass-specific initialization. Subclasses must override this method.

Parameters:
config - the parsed curn configuration data
cfgHandler - the ConfiguredOutputHandler wrapper containing this object; the wrapper has some useful metadata, such as the object's configuration section name and extra variables.
Throws:
org.clapper.util.config.ConfigurationException - configuration error
CurnException - some other initialization error

displayChannel

public abstract void displayChannel(RSSChannel channel,
                                    FeedInfo feedInfo)
                             throws CurnException
Display the list of RSSItem news items to whatever output is defined for the underlying class. Output should be written to the PrintWriter that was passed to the init() method.

Specified by:
displayChannel in interface OutputHandler
Parameters:
channel - The parsed channel data
feedInfo - The feed.
Throws:
CurnException - unable to write output

flush

public abstract void flush()
                    throws CurnException
Flush any buffered-up output.

Specified by:
flush in interface OutputHandler
Throws:
CurnException - unable to write output

getContentType

public abstract java.lang.String getContentType()
Get the content (i.e., MIME) type for output produced by this output handler.

Specified by:
getContentType in interface OutputHandler
Returns:
the content type
See Also:
OutputHandler.hasGeneratedOutput(), OutputHandler.getGeneratedOutput()

getGeneratedOutput

public final java.io.File getGeneratedOutput()
                                      throws CurnException
Get the File that represents the output produced by the handler, if applicable. (Use of a File, rather than an InputStream, is more efficient when mailing the output, since the email API ultimately wants files and will create temporary files for InputStreams.)

Specified by:
getGeneratedOutput in interface OutputHandler
Returns:
the output file, or null if no suitable output was produced
Throws:
CurnException - an error occurred

getOutputEncoding

public java.lang.String getOutputEncoding()
Get the output encoding.

Specified by:
getOutputEncoding in interface OutputHandler
Returns:
the encoding

hasGeneratedOutput

public final boolean hasGeneratedOutput()
Determine whether this handler has produced any actual output (i.e., whether getGeneratedOutput() will return a non-null File if called).

Specified by:
hasGeneratedOutput in interface OutputHandler
Returns:
true if the handler has produced output, false if not
See Also:
getGeneratedOutput(), getContentType()

getOutputFile

protected final java.io.File getOutputFile()
Get the output file.

Returns:
the output file, or none if not created yet

openOutputFile

protected java.io.PrintWriter openOutputFile()
                                      throws CurnException
Open the output file, returning a PrintWriter. Handles whether or not to roll the saved file, etc.

Returns:
the PrintWriter
Throws:
CurnException - unable to open file

savingOutputOnly

protected final boolean savingOutputOnly()
Determine whether the handler is saving output only, or also reporting output to curn.

Returns:
true if saving output only, false if also reporting output to curn

setOutputEncoding

protected final void setOutputEncoding(java.lang.String newEncoding)
Override the encoding specified by the CFG_ENCODING configuration parameter. To have any effect, this method must be called before openOutputFile()

Parameters:
newEncoding - the new encoding, or null to use the default
See Also:
getOutputEncoding()

displayToolInfo

protected final boolean displayToolInfo()
Determine whether or not to display curn tool-related information in the generated output. Subclasses are not required to display tool-related information in the generated output, but if they do, they are strongly encouraged to do so conditionally, based on the value of this configuration item.

Returns:
true if tool-related information is to be displayed (assuming the output handler supports it), or false if tool-related information should be suppressed.


Copyright © 2004-2006 Brian M. Clapper. All Rights Reserved.