Package com.puppycrawl.tools.checkstyle
Class XMLLogger
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.XMLLogger
-
- All Implemented Interfaces:
AuditListener,Configurable,Contextualizable,java.util.EventListener
public class XMLLogger extends AutomaticBean implements AuditListener
Simple XML logger. It outputs everything in UTF-8 (default XML encoding is UTF-8) in case we want to localize error messages or simply that file names are localized and takes care about escaping as well.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classXMLLogger.FileMessagesThe registered file messages.-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private static intBASE_10Decimal radix.private static intBASE_16Hex radix.private booleancloseStreamClose output stream in auditFinished.private static java.lang.String[]ENTITIESSome known entities to detect.private java.util.Map<java.lang.String,XMLLogger.FileMessages>fileMessagesHolds all messages for the given file.private java.io.PrintWriterwriterHelper writer that allows easy encoding and printing.private java.lang.ObjectwriterLockThe writer lock object.
-
Constructor Summary
Constructors Constructor Description XMLLogger(java.io.OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions)Creates a newXMLLoggerinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddError(AuditEvent event)Notify that an audit error was discovered on a specific file.voidaddException(AuditEvent event, java.lang.Throwable throwable)Notify that an exception happened while performing audit.voidauditFinished(AuditEvent event)Notify that the audit is finished.voidauditStarted(AuditEvent event)Notify that the audit is about to start.static java.lang.Stringencode(java.lang.String value)Escape <, > & ' and " as their entities.voidfileFinished(AuditEvent event)Notify that audit is finished on a specific file.voidfileStarted(AuditEvent event)Notify that audit is about to start on a specific file.protected voidfinishLocalSetup()Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.static booleanisReference(java.lang.String ent)Finds whether the given argument is character or entity reference.private voidwriteException(java.lang.Throwable throwable)Writes the exception event to the print writer.private voidwriteFileClosingTag()Prints the "file" closing tag.private voidwriteFileError(AuditEvent event)Outputs the given event to the writer.private voidwriteFileMessages(java.lang.String fileName, XMLLogger.FileMessages messages)Prints the file section with all file errors and exceptions.private voidwriteFileOpeningTag(java.lang.String fileName)Prints the "file" opening tag with the given filename.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
BASE_10
private static final int BASE_10
Decimal radix.- See Also:
- Constant Field Values
-
BASE_16
private static final int BASE_16
Hex radix.- See Also:
- Constant Field Values
-
ENTITIES
private static final java.lang.String[] ENTITIES
Some known entities to detect.
-
closeStream
private final boolean closeStream
Close output stream in auditFinished.
-
writerLock
private final java.lang.Object writerLock
The writer lock object.
-
fileMessages
private final java.util.Map<java.lang.String,XMLLogger.FileMessages> fileMessages
Holds all messages for the given file.
-
writer
private final java.io.PrintWriter writer
Helper writer that allows easy encoding and printing.
-
-
Constructor Detail
-
XMLLogger
public XMLLogger(java.io.OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions)
Creates a newXMLLoggerinstance. Sets the output to a defined stream.- Parameters:
outputStream- the stream to write logs to.outputStreamOptions- ifCLOSEstream should be closed in auditFinished()- Throws:
java.lang.IllegalArgumentException- if outputStreamOptions is null.
-
-
Method Detail
-
finishLocalSetup
protected void finishLocalSetup()
Description copied from class:AutomaticBeanProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetupin classAutomaticBean
-
auditStarted
public void auditStarted(AuditEvent event)
Description copied from interface:AuditListenerNotify that the audit is about to start.- Specified by:
auditStartedin interfaceAuditListener- Parameters:
event- the event details
-
auditFinished
public void auditFinished(AuditEvent event)
Description copied from interface:AuditListenerNotify that the audit is finished.- Specified by:
auditFinishedin interfaceAuditListener- Parameters:
event- the event details
-
fileStarted
public void fileStarted(AuditEvent event)
Description copied from interface:AuditListenerNotify that audit is about to start on a specific file.- Specified by:
fileStartedin interfaceAuditListener- Parameters:
event- the event details
-
fileFinished
public void fileFinished(AuditEvent event)
Description copied from interface:AuditListenerNotify that audit is finished on a specific file.- Specified by:
fileFinishedin interfaceAuditListener- Parameters:
event- the event details
-
writeFileMessages
private void writeFileMessages(java.lang.String fileName, XMLLogger.FileMessages messages)
Prints the file section with all file errors and exceptions.- Parameters:
fileName- The file name, as should be printed in the opening file tag.messages- The file messages.
-
writeFileOpeningTag
private void writeFileOpeningTag(java.lang.String fileName)
Prints the "file" opening tag with the given filename.- Parameters:
fileName- The filename to output.
-
writeFileClosingTag
private void writeFileClosingTag()
Prints the "file" closing tag.
-
addError
public void addError(AuditEvent event)
Description copied from interface:AuditListenerNotify that an audit error was discovered on a specific file.- Specified by:
addErrorin interfaceAuditListener- Parameters:
event- the event details
-
writeFileError
private void writeFileError(AuditEvent event)
Outputs the given event to the writer.- Parameters:
event- An event to print.
-
addException
public void addException(AuditEvent event, java.lang.Throwable throwable)
Description copied from interface:AuditListenerNotify that an exception happened while performing audit.- Specified by:
addExceptionin interfaceAuditListener- Parameters:
event- the event detailsthrowable- details of the exception
-
writeException
private void writeException(java.lang.Throwable throwable)
Writes the exception event to the print writer.- Parameters:
throwable- The
-
encode
public static java.lang.String encode(java.lang.String value)
Escape <, > & ' and " as their entities.- Parameters:
value- the value to escape.- Returns:
- the escaped value if necessary.
-
isReference
public static boolean isReference(java.lang.String ent)
Finds whether the given argument is character or entity reference.- Parameters:
ent- the possible entity to look for.- Returns:
- whether the given argument a character or entity reference
-
-