|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.clapper.curn.output.FileOutputHandler
org.clapper.curn.output.script.ScriptOutputHandler
public class ScriptOutputHandler
Provides an output handler calls a script via the Apache Jakarta
Bean Scripting Framework
(BSF). This handler supports any scripting language supported by BSF. In
addition to the configuration parameters supported by the
FileOutputHandler base class, this handler supports the
following additional configuration variables, which must be specified in
the handler's configuration section.
| Parameter | Explanation |
|---|---|
| Script | Path to the script to be invoked. The script will be called as if from the command line, except that additional objects will be available via BSF. |
| Language | The scripting language, as recognized by BSF. This handler supports all the scripting language engines that are registered with the BSF software. (Those predefined engines are configured in a properties file within the BSF software.) Some of the scripting language engines are actually bundled with BSF. Some are not. Regardless, of course, the actual the jar files for the scripting languages themselves must be in the CLASSPATH at runtime, for those languages to be available. If you want to use a BSF scripting language engine that isn't
automatically registered with BSF, simply extend this class and
override the
Then, simply use your class instead of ScriptOutputHandler
in your configuration file.
|
This handler's displayChannel() method does
not invoke the script; instead, it buffers up all the channels so that
the flush() method can invoke the script. That way, the overhead
of invoking the script only occurs once. Via the BSF engine, this
handler makes available an iterator of special objects that wrap both
the RSSChannel and FeedInfo objects for a given channel.
See below for a more complete description.
The complete list of objects bound into the BSF beanspace follows.
| Bound name | Java type | Explanation |
|---|---|---|
| channels | java.util.Collection | An Collection of special internal objects that wrap
both RSSChannel and FeedInfo objects. The
wrapper objects provide two methods: |
| outputPath | java.lang.String | The path to an output file. The script should write its output to that file. Overwriting the file is fine. If the script generates no output, then it can ignore the file. |
| config | CurnConfig |
The org.clapper.curn.CurnConfig object that represents the parsed configuration data. Useful in conjunction with the "configSection" object, to parse additional parameters from the configuration. |
| configSection | java.lang.String | The name of the configuration file section in which the output handler was defined. Useful if the script wants to access additional script-specific configuration data. |
| mimeType | java.io.PrintWriter | A PrintWriter object to which the script should print the MIME type that corresponds to the generated output. If the script generates no output, then it can ignore this object. |
| logger | org.clapper.util.logging.Logger |
A Logger object, useful for logging messages to the curn log file. |
| version | java.lang.String | Full curn version string, in case the script wants to include it in the generated output |
For example, the following Jython script can be used as a template for a Jython output handler.
import sys
def __init__ (self):
"""
Initialize a new TextOutputHandler object.
"""
self.__channels = bsf.lookupBean ("channels")
self.__outputPath = bsf.lookupBean ("outputPath")
self.__mimeTypeOut = bsf.lookupBean ("mimeType")
self.__config = bsf.lookupBean ("config")
self.__sectionName = bsf.lookupBean ("configSection")
self.__logger = bsf.lookupBean ("logger");
self.__version = bsf.lookupBean ("version")
self.__message = None
def processChannels (self):
"""
Process the channels passed in through the Bean Scripting Framework.
"""
out = open (self.__outputPath, "w")
msg = self.__config.getOptionalStringValue (self.__sectionName,
"Message",
None)
totalNew = 0
# First, count the total number of new items
iterator = self.__channels.iterator()
while iterator.hasNext():
channel_wrapper = iterator.next()
channel = channel_wrapper.getChannel()
totalNew = totalNew + channel.getItems().size()
if totalNew > 0:
# If the config file specifies a message for this handler,
# display it.
if msg != None:
out.println (msg)
out.println ()
# Now, process the items
iterator = self.__channels.iterator()
while iterator.hasNext():
channel_wrapper = iterator.next()
channel = channel_wrapper.getChannel()
feed_info = channel_wrapper.getFeedInfo()
self.__process_channel (out, channel, feed_info, indentation)
self.__mimeTypeBuf.print ("text/plain")
# Output a footer
self.__indent (out, indentation)
out.write ("\n")
out.write (self.__version + "\n")
out.close ()
def process_channel (channel, feed_info):
item_iterator = channel.getItems().iterator()
while item_iterator.hasNext():
# Do output for item
...
main()
OutputHandler,
FileOutputHandler,
Curn,
RSSChannel| Nested Class Summary | |
|---|---|
class |
ScriptOutputHandler.ChannelWrapper
Wraps an RSSChannel object and its FeedInfo object. |
class |
ScriptOutputHandler.CurnScriptObjects
Container for the objects exported to the script. |
| Field Summary |
|---|
| Fields inherited from class org.clapper.curn.output.FileOutputHandler |
|---|
CFG_ENCODING, CFG_SAVE_AS, CFG_SAVE_ONLY, CFG_SAVED_BACKUPS, CFG_SHOW_CURN_INFO |
| Constructor Summary | |
|---|---|
ScriptOutputHandler()
Construct a new ScriptOutputHandler. |
|
| Method Summary | |
|---|---|
void |
displayChannel(RSSChannel channel,
FeedInfo feedInfo)
Display the list of RSSItem news items to whatever output is defined for the underlying class. |
void |
flush()
Flush any buffered-up output. |
java.lang.String |
getContentType()
Get the content (i.e., MIME) type for output produced by this output handler. |
void |
initOutputHandler(CurnConfig config,
ConfiguredOutputHandler cfgHandler)
Initializes the output handler for another set of RSS channels. |
void |
registerAdditionalScriptingEngines()
Deprecated. as of curn 3.1. |
| Methods inherited from class org.clapper.curn.output.FileOutputHandler |
|---|
displayToolInfo, getGeneratedOutput, getName, getOutputEncoding, getOutputFile, hasGeneratedOutput, init, openOutputFile, savingOutputOnly, setName, setOutputEncoding |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ScriptOutputHandler()
| Method Detail |
|---|
public final void initOutputHandler(CurnConfig config,
ConfiguredOutputHandler cfgHandler)
throws org.clapper.util.config.ConfigurationException,
CurnException
initOutputHandler in class FileOutputHandlerconfig - the parsed curn configuration datacfgHandler - the ConfiguredOutputHandler wrapper
containing this object; the wrapper has some useful
metadata, such as the object's configuration section
name and extra variables.
org.clapper.util.config.ConfigurationException - configuration error
CurnException - some other initialization error
public final void displayChannel(RSSChannel channel,
FeedInfo feedInfo)
throws CurnException
flush() can pass all the channels to the
script.
displayChannel in interface OutputHandlerdisplayChannel in class FileOutputHandlerchannel - The channel containing the items to emit. The method
should emit all the items in the channel; the caller
is responsible for clearing out any items that should
not be seen.feedInfo - Information about the feed, from the configuration
CurnException - unable to write output
public final void flush()
throws CurnException
flush in interface OutputHandlerflush in class FileOutputHandlerCurnException - unable to write outputpublic final java.lang.String getContentType()
getContentType in interface OutputHandlergetContentType in class FileOutputHandlerOutputHandler.hasGeneratedOutput(),
OutputHandler.getGeneratedOutput()
public void registerAdditionalScriptingEngines()
throws CurnException
CurnException - on error
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||