org.apache.fop.messaging
Class MessageHandler

java.lang.Object
  extended byorg.apache.fop.messaging.MessageHandler

public class MessageHandler
extends java.lang.Object

The class MessageHandler contains the static methods log and error which should be used for any end user information instead of System.out.print() or System.err.print(). The class defines several output methods: writing to the screen (default), logging to a file, creating message events and repressing all output. If you don't want to change the default behaviour, you should be happy with MessageHandler.log(message) and MessageHandler.error(message)
The class MessageHandler also supports the setting of an id. If set every message has as a prefix an identifying string. That way Fop probably can also be used in environments, where more than one Fop instance are running in same JVM.
If Fop is embedded in a gui application or for any reasons the existing messaging system doesn't meet the programmer's requirements, one can add a MessageEvent listener to MessageHandler and handle the incoming messages in an appropriate way. See the class DefaultMessageListener, which is a trivial implementation of the MessageListener. Here is an example how to configure MessageHandler for the DefaultMessageListener (anybody can provide his own listener by extending MessageListener
MessageHandler.setOutputMethod(MessageHandler.EVENT); MessageHandler.addListener(new DefaultMessageListener());
This examples shows, how to redirect the messages to a log file called fop.log. All messages are appended to this file. MessageHandler.setOutputMethod(MessageHandler.FILE); MessageHandler.setLogfileName("\\fop.log",true);


Field Summary
static int EVENT
           
static int FILE
           
static int NONE
           
static int SCREEN
           
 
Constructor Summary
MessageHandler()
           
 
Method Summary
static void addListener(MessageListener listener)
          adds a MessageListener which listens for MessageEvents
static void error(java.lang.String errorMessage)
          error warning for the user
static void errorln(java.lang.String errorMessage)
          convenience method which adds a return to the error message
static java.lang.String getLogfileName()
          returns the logfile name
static int getOutputMethod()
          informs what output method is set
static void log(java.lang.String message)
          informs the user of the message
static void logln(java.lang.String message)
          convenience method which adds a return to the message
static void removeListener(MessageListener listener)
          removes a MessageListener
static void setID(boolean id)
          if set to true an id string is prefixed to every message uses the thread info as an id for the message producer.
static void setLogfileName(java.lang.String filename, boolean append)
          sets the logfile name
static void setOutputMethod(int method)
          sets the output method
static void setQuiet(boolean quietMode)
          if set to true all normal messages are suppressed.
static void setScreenLogger(org.apache.avalon.framework.logger.Logger newLogger)
          Sets the Logger used for the screen output method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCREEN

public static final int SCREEN
See Also:
Constant Field Values

FILE

public static final int FILE
See Also:
Constant Field Values

EVENT

public static final int EVENT
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values
Constructor Detail

MessageHandler

public MessageHandler()
Method Detail

log

public static void log(java.lang.String message)
informs the user of the message

Parameters:
message - the message for the user

logln

public static void logln(java.lang.String message)
convenience method which adds a return to the message

Parameters:
message - the message for the user

error

public static void error(java.lang.String errorMessage)
error warning for the user

Parameters:
errorMessage - contains the warning string

errorln

public static void errorln(java.lang.String errorMessage)
convenience method which adds a return to the error message

Parameters:
errorMessage - the message for the user

addListener

public static void addListener(MessageListener listener)
adds a MessageListener which listens for MessageEvents


removeListener

public static void removeListener(MessageListener listener)
removes a MessageListener


setScreenLogger

public static void setScreenLogger(org.apache.avalon.framework.logger.Logger newLogger)
Sets the Logger used for the screen output method.

Parameters:
newLogger - a logger for screen output. This may not be null.

setOutputMethod

public static void setOutputMethod(int method)
sets the output method

Parameters:
method - the output method to use, allowed values are
MessageHandler.SCREEN, MessageHandler.FILE, MessageHandler.EVENT MessageHandler.NONE

getOutputMethod

public static int getOutputMethod()
informs what output method is set

Returns:
the output method

setLogfileName

public static void setLogfileName(java.lang.String filename,
                                  boolean append)
sets the logfile name

Parameters:
filename - name of the logfile
append - if true, the logfile is appended

getLogfileName

public static java.lang.String getLogfileName()
returns the logfile name

Returns:
String containing the logfile name

setID

public static void setID(boolean id)
if set to true an id string is prefixed to every message uses the thread info as an id for the message producer. Should be used if more than one instance of Fop is running in the same JVM this id becomes a prefix to every message

Parameters:
id - boolean (default is false)

setQuiet

public static void setQuiet(boolean quietMode)
if set to true all normal messages are suppressed. error messages are displayed allthesame

Parameters:
quietMode - boolean (default is false)


Copyright © 1999-2003 Apache Software Foundation. All Rights Reserved.