org.apache.fop.messaging
Class MessageHandler


public class MessageHandler

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
 final static intEVENT
           
 final static intFILE
           
 final static intNONE
           
 final static intSCREEN
           

Method Summary
 static voidaddListener(MessageListener listener)
          adds a MessageListener which listens for MessageEvents
 static voiderror(String errorMessage)
          error warning for the user
 static voiderrorln(String errorMessage)
          convenience method which adds a return to the error message
 static StringgetLogfileName()
          returns the logfile name
 static intgetOutputMethod()
          informs what output method is set
 static voidlog(String message)
          informs the user of the message
 static voidlogln(String message)
          convenience method which adds a return to the message
 static voidremoveListener(MessageListener listener)
          removes a MessageListener
 static voidsetID(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 voidsetLogfileName(String filename, boolean append)
          sets the logfile name
 static voidsetOutputMethod(int method)
          sets the output method

Field Detail

EVENT

public final static int EVENT

FILE

public final static int FILE

NONE

public final static int NONE

SCREEN

public final static int SCREEN
Method Detail

addListener

public static void addListener(MessageListener listener)
adds a MessageListener which listens for MessageEvents
Parameters:
MessageListener - the listener to add

error

public static void error(String errorMessage)
error warning for the user
Parameters:
errorMessage - contains the warning string

errorln

public static void errorln(String errorMessage)
convenience method which adds a return to the error message
Parameters:
errorMessage - the message for the user

getLogfileName

public static String getLogfileName()
returns the logfile name
Returns: String containing the logfile name

getOutputMethod

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

log

public static void log(String message)
informs the user of the message
Parameters:
message - the message for the user

logln

public static void logln(String message)
convenience method which adds a return to the message
Parameters:
message - the message for the user

removeListener

public static void removeListener(MessageListener listener)
removes a MessageListener
Parameters:
MessageListener - the listener to remove

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)

setLogfileName

public static void setLogfileName(String filename, boolean append)
sets the logfile name
Parameters:
filename - name of the logfile
append - if true, the logfile is appended

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

Association Links

to Class java.lang.String

to Class java.io.PrintWriter

to Class java.lang.String

to Class java.lang.String

to Class java.util.Vector