Package com.puppycrawl.tools.checkstyle
Class PackageNamesLoader
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.puppycrawl.tools.checkstyle.XmlLoader
-
- com.puppycrawl.tools.checkstyle.PackageNamesLoader
-
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
public final class PackageNamesLoader extends XmlLoader
Loads a list of package names from a package name XML file.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.XmlLoader
XmlLoader.LoadExternalDtdFeatureProvider
-
-
Field Summary
Fields Modifier and Type Field Description private static String
CHECKSTYLE_PACKAGES
Name of default checkstyle package names resource file.private static String
DTD_PUBLIC_CS_ID
The new public ID for the configuration dtd.private static String
DTD_PUBLIC_ID
The public ID for the configuration dtd.private static String
DTD_RESOURCE_NAME
The resource for the configuration dtd.private static String
PACKAGE_ELEMENT_NAME
Qualified name for element 'package'.private Set<String>
packageNames
The fully qualified package names.private Deque<String>
packageStack
The temporary stack of package name parts.
-
Constructor Summary
Constructors Modifier Constructor Description private
PackageNamesLoader()
Creates a newPackageNamesLoader
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Map<String,String>
createIdToResourceNameMap()
Creates mapping between local resources and dtd ids.void
endElement(String uri, String localName, String qName)
private String
getPackageName()
Creates a full package name from the package names on the stack.static Set<String>
getPackageNames(ClassLoader classLoader)
Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.private static void
processFile(URL packageFile, PackageNamesLoader namesLoader)
Reads the file provided and parses it with package names loader.void
startElement(String uri, String localName, String qName, Attributes attributes)
-
Methods inherited from class com.puppycrawl.tools.checkstyle.XmlLoader
error, parseInputSource, resolveEntity
-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Field Detail
-
DTD_PUBLIC_ID
private static final String DTD_PUBLIC_ID
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID
private static final String DTD_PUBLIC_CS_ID
The new public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME
private static final String DTD_RESOURCE_NAME
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
CHECKSTYLE_PACKAGES
private static final String CHECKSTYLE_PACKAGES
Name of default checkstyle package names resource file. The file must be in the classpath.- See Also:
- Constant Field Values
-
PACKAGE_ELEMENT_NAME
private static final String PACKAGE_ELEMENT_NAME
Qualified name for element 'package'.- See Also:
- Constant Field Values
-
packageStack
private final Deque<String> packageStack
The temporary stack of package name parts.
-
packageNames
private final Set<String> packageNames
The fully qualified package names.
-
-
Constructor Detail
-
PackageNamesLoader
private PackageNamesLoader() throws ParserConfigurationException, SAXException
Creates a newPackageNamesLoader
instance.- Throws:
ParserConfigurationException
- if an error occursSAXException
- if an error occurs
-
-
Method Detail
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes)
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
-
getPackageName
private String getPackageName()
Creates a full package name from the package names on the stack.- Returns:
- the full name of the current package.
-
endElement
public void endElement(String uri, String localName, String qName)
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
-
getPackageNames
public static Set<String> getPackageNames(ClassLoader classLoader) throws CheckstyleException
Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.- Parameters:
classLoader
- the class loader for loading the checkstyle_packages.xml files.- Returns:
- the set of package names.
- Throws:
CheckstyleException
- if an error occurs.
-
processFile
private static void processFile(URL packageFile, PackageNamesLoader namesLoader) throws SAXException, CheckstyleException
Reads the file provided and parses it with package names loader.- Parameters:
packageFile
- file from packagenamesLoader
- package names loader- Throws:
SAXException
- if an error while parsing occursCheckstyleException
- if unable to open file
-
createIdToResourceNameMap
private static Map<String,String> createIdToResourceNameMap()
Creates mapping between local resources and dtd ids.- Returns:
- map between local resources and dtd ids.
-
-