Class SuppressionsLoader

java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.puppycrawl.tools.checkstyle.XmlLoader
com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public final class SuppressionsLoader extends XmlLoader
Loads a filter chain of suppressions.
  • Field Details

    • DTD_PUBLIC_ID_1_0

      private static final String DTD_PUBLIC_ID_1_0
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID_1_0

      private static final String DTD_PUBLIC_CS_ID_1_0
      The new public ID for version 1_0 configuration dtd.
      See Also:
    • DTD_SUPPRESSIONS_NAME_1_0

      private static final String DTD_SUPPRESSIONS_NAME_1_0
      The resource for the configuration dtd.
      See Also:
    • DTD_PUBLIC_ID_1_1

      private static final String DTD_PUBLIC_ID_1_1
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID_1_1

      private static final String DTD_PUBLIC_CS_ID_1_1
      The new public ID for version 1_1 configuration dtd.
      See Also:
    • DTD_SUPPRESSIONS_NAME_1_1

      private static final String DTD_SUPPRESSIONS_NAME_1_1
      The resource for the configuration dtd.
      See Also:
    • DTD_PUBLIC_ID_1_2

      private static final String DTD_PUBLIC_ID_1_2
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID_1_2

      private static final String DTD_PUBLIC_CS_ID_1_2
      The new public ID for version 1_2 configuration dtd.
      See Also:
    • DTD_SUPPRESSIONS_NAME_1_2

      private static final String DTD_SUPPRESSIONS_NAME_1_2
      The resource for the configuration dtd.
      See Also:
    • DTD_PUBLIC_ID_1_1_XPATH

      private static final String DTD_PUBLIC_ID_1_1_XPATH
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID_1_1_XPATH

      private static final String DTD_PUBLIC_CS_ID_1_1_XPATH
      The new public ID for version 1_1 configuration dtd.
      See Also:
    • DTD_SUPPRESSIONS_NAME_1_1_XPATH

      private static final String DTD_SUPPRESSIONS_NAME_1_1_XPATH
      The resource for the configuration dtd.
      See Also:
    • DTD_PUBLIC_ID_1_2_XPATH

      private static final String DTD_PUBLIC_ID_1_2_XPATH
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID_1_2_XPATH

      private static final String DTD_PUBLIC_CS_ID_1_2_XPATH
      The new public ID for version 1_2 configuration dtd.
      See Also:
    • DTD_SUPPRESSIONS_NAME_1_2_XPATH

      private static final String DTD_SUPPRESSIONS_NAME_1_2_XPATH
      The resource for the configuration dtd.
      See Also:
    • UNABLE_TO_FIND_ERROR_MESSAGE

      private static final String UNABLE_TO_FIND_ERROR_MESSAGE
      File search error message.
      See Also:
    • ATTRIBUTE_NAME_FILES

      private static final String ATTRIBUTE_NAME_FILES
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_CHECKS

      private static final String ATTRIBUTE_NAME_CHECKS
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_MESSAGE

      private static final String ATTRIBUTE_NAME_MESSAGE
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_ID

      private static final String ATTRIBUTE_NAME_ID
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_QUERY

      private static final String ATTRIBUTE_NAME_QUERY
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_LINES

      private static final String ATTRIBUTE_NAME_LINES
      String literal for attribute name.
      See Also:
    • ATTRIBUTE_NAME_COLUMNS

      private static final String ATTRIBUTE_NAME_COLUMNS
      String literal for attribute name.
      See Also:
    • filterChain

      private final FilterSet filterChain
      The filter chain to return in getAFilterChain(), configured during parsing.
    • treeWalkerFilters

      private final Set<TreeWalkerFilter> treeWalkerFilters
      The set of the TreeWalkerFilter filters. Being filled during parsing.
  • Constructor Details

  • Method Details

    • startElement

      public void startElement(String namespaceUri, String localName, String qName, Attributes attributes) throws SAXException
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Throws:
      SAXException
    • getSuppressElement

      private static SuppressFilterElement getSuppressElement(Attributes attributes) throws SAXException
      Returns the suppress element, initialized from given attributes.
      Parameters:
      attributes - the attributes of xml-tag "<suppress></suppress>", specified inside suppression file.
      Returns:
      the suppress element
      Throws:
      SAXException - if an error occurs.
    • getXpathFilter

      private static XpathFilterElement getXpathFilter(Attributes attributes) throws SAXException
      Returns the xpath filter, initialized from given attributes.
      Parameters:
      attributes - the attributes of xml-tag "<suppress-xpath></suppress-xpath>", specified inside suppression file.
      Returns:
      the xpath filter
      Throws:
      SAXException - if an error occurs.
    • loadSuppressions

      public static FilterSet loadSuppressions(String filename) throws CheckstyleException
      Returns the suppression filters in a specified file.
      Parameters:
      filename - name of the suppressions file.
      Returns:
      the filter chain of suppression elements specified in the file.
      Throws:
      CheckstyleException - if an error occurs.
    • loadSuppressions

      private static FilterSet loadSuppressions(InputSource source, String sourceName) throws CheckstyleException
      Returns the suppression filters in a specified source.
      Parameters:
      source - the source for the suppressions.
      sourceName - the name of the source.
      Returns:
      the filter chain of suppression elements in source.
      Throws:
      CheckstyleException - if an error occurs.
    • loadXpathSuppressions

      public static Set<TreeWalkerFilter> loadXpathSuppressions(String filename) throws CheckstyleException
      Returns the suppression TreeWalker filters in a specified file.
      Parameters:
      filename - name of the suppressions file.
      Returns:
      the set of xpath suppression elements specified in the file.
      Throws:
      CheckstyleException - if an error occurs.
    • loadXpathSuppressions

      private static Set<TreeWalkerFilter> loadXpathSuppressions(InputSource source, String sourceName) throws CheckstyleException
      Returns the suppression TreeWalker filters in a specified source.
      Parameters:
      source - the source for the suppressions.
      sourceName - the name of the source.
      Returns:
      the set of xpath suppression elements specified in source.
      Throws:
      CheckstyleException - if an error occurs.
    • getSuppressionLoader

      private static SuppressionsLoader getSuppressionLoader(InputSource source, String sourceName) throws CheckstyleException
      Parses specified source and returns the suppression loader.
      Parameters:
      source - the source for the suppressions.
      sourceName - the name of the source.
      Returns:
      the suppression loader
      Throws:
      CheckstyleException - if an error occurs.
    • createIdToResourceNameMap

      private static Map<String,String> createIdToResourceNameMap()
      Creates mapping between local resources and dtd ids.
      Returns:
      map between local resources and dtd ids.