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.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BASE_10
Decimal radix.private static int
BASE_16
Hex radix.private boolean
closeStream
Close output stream in auditFinished.private static java.lang.String[]
ENTITIES
Some known entities to detect.private java.io.PrintWriter
writer
Helper writer that allows easy encoding and printing.
-
Constructor Summary
Constructors Constructor Description XMLLogger(java.io.OutputStream outputStream, boolean closeStream)
Creates a newXMLLogger
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addError(AuditEvent event)
Notify that an audit error was discovered on a specific file.void
addException(AuditEvent event, java.lang.Throwable throwable)
Notify that an exception happened while performing audit.void
auditFinished(AuditEvent event)
Notify that the audit is finished.void
auditStarted(AuditEvent event)
Notify that the audit is about to start.static java.lang.String
encode(java.lang.String value)
Escape <, > & ' and " as their entities.private static java.lang.String
encodeAmpersand(java.lang.String value, int ampPosition)
Encodes ampersand in value at required position.void
fileFinished(AuditEvent event)
Notify that audit is finished on a specific file.void
fileStarted(AuditEvent event)
Notify that audit is about to start on a specific file.static boolean
isReference(java.lang.String ent)
Finds whether the given argument is character or entity reference.private void
setOutputStream(java.io.OutputStream outputStream)
Sets the OutputStream.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, 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.
-
writer
private java.io.PrintWriter writer
Helper writer that allows easy encoding and printing.
-
-
Method Detail
-
setOutputStream
private void setOutputStream(java.io.OutputStream outputStream)
Sets the OutputStream.- Parameters:
outputStream
- the OutputStream to use
-
auditStarted
public void auditStarted(AuditEvent event)
Description copied from interface:AuditListener
Notify that the audit is about to start.- Specified by:
auditStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
auditFinished
public void auditFinished(AuditEvent event)
Description copied from interface:AuditListener
Notify that the audit is finished.- Specified by:
auditFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileStarted
public void fileStarted(AuditEvent event)
Description copied from interface:AuditListener
Notify that audit is about to start on a specific file.- Specified by:
fileStarted
in interfaceAuditListener
- Parameters:
event
- the event details
-
fileFinished
public void fileFinished(AuditEvent event)
Description copied from interface:AuditListener
Notify that audit is finished on a specific file.- Specified by:
fileFinished
in interfaceAuditListener
- Parameters:
event
- the event details
-
addError
public void addError(AuditEvent event)
Description copied from interface:AuditListener
Notify that an audit error was discovered on a specific file.- Specified by:
addError
in interfaceAuditListener
- Parameters:
event
- the event details
-
addException
public void addException(AuditEvent event, java.lang.Throwable throwable)
Description copied from interface:AuditListener
Notify that an exception happened while performing audit.- Specified by:
addException
in interfaceAuditListener
- Parameters:
event
- the event detailsthrowable
- details of the exception
-
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
-
encodeAmpersand
private static java.lang.String encodeAmpersand(java.lang.String value, int ampPosition)
Encodes ampersand in value at required position.- Parameters:
value
- string value, which contains ampersandampPosition
- position of ampersand in value- Returns:
- encoded ampersand which should be used in xml
-
-