Class XMLLogger

java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.XMLLogger
All Implemented Interfaces:
AuditListener, Configurable, Contextualizable, 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 Details

    • BASE_10

      private static final int BASE_10
      Decimal radix.
      See Also:
    • BASE_16

      private static final int BASE_16
      Hex radix.
      See Also:
    • ENTITIES

      private static final String[] ENTITIES
      Some known entities to detect.
    • closeStream

      private final boolean closeStream
      Close output stream in auditFinished.
    • writerLock

      private final Object writerLock
      The writer lock object.
    • fileMessages

      private final Map<String,XMLLogger.FileMessages> fileMessages
      Holds all messages for the given file.
    • writer

      private final PrintWriter writer
      Helper writer that allows easy encoding and printing.
  • Constructor Details

    • XMLLogger

      public XMLLogger(OutputStream outputStream, AutomaticBean.OutputStreamOptions outputStreamOptions)
      Creates a new XMLLogger instance. Sets the output to a defined stream.
      Parameters:
      outputStream - the stream to write logs to.
      outputStreamOptions - if CLOSE stream should be closed in auditFinished()
      Throws:
      IllegalArgumentException - if outputStreamOptions is null.
  • Method Details

    • finishLocalSetup

      protected void finishLocalSetup()
      Description copied from class: AutomaticBean
      Provides 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:
      finishLocalSetup in class AutomaticBean
    • auditStarted

      public void auditStarted(AuditEvent event)
      Description copied from interface: AuditListener
      Notify that the audit is about to start.
      Specified by:
      auditStarted in interface AuditListener
      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 interface AuditListener
      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 interface AuditListener
      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 interface AuditListener
      Parameters:
      event - the event details
    • writeFileMessages

      private void writeFileMessages(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(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: AuditListener
      Notify that an audit error was discovered on a specific file.
      Specified by:
      addError in interface AuditListener
      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, Throwable throwable)
      Description copied from interface: AuditListener
      Notify that an exception happened while performing audit.
      Specified by:
      addException in interface AuditListener
      Parameters:
      event - the event details
      throwable - details of the exception
    • writeException

      private void writeException(Throwable throwable)
      Writes the exception event to the print writer.
      Parameters:
      throwable - The
    • encode

      public static String encode(String value)
      Escape <, > & ' and " as their entities.
      Parameters:
      value - the value to escape.
      Returns:
      the escaped value if necessary.
    • isReference

      public static boolean isReference(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