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
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
FieldsModifier and TypeFieldDescriptionprivate static final String
Name of default checkstyle package names resource file.private static final String
The new public ID for the configuration dtd.private static final String
The public ID for the configuration dtd.private static final String
The resource for the configuration dtd.private static final String
Qualified name for element 'package'.The fully qualified package names.The temporary stack of package name parts. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Creates a newPackageNamesLoader
instance. -
Method Summary
Modifier and TypeMethodDescriptionCreates mapping between local resources and dtd ids.void
endElement
(String uri, String localName, String qName) private String
Creates a full package name from the package names on the stack.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 Details
-
DTD_PUBLIC_ID
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID
The new public ID for the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME
The resource for the configuration dtd.- See Also:
-
CHECKSTYLE_PACKAGES
Name of default checkstyle package names resource file. The file must be in the classpath.- See Also:
-
PACKAGE_ELEMENT_NAME
Qualified name for element 'package'.- See Also:
-
packageStack
The temporary stack of package name parts. -
packageNames
The fully qualified package names.
-
-
Constructor Details
-
PackageNamesLoader
Creates a newPackageNamesLoader
instance.- Throws:
ParserConfigurationException
- if an error occursSAXException
- if an error occurs
-
-
Method Details
-
startElement
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
-
getPackageName
Creates a full package name from the package names on the stack.- Returns:
- the full name of the current package.
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
-
getPackageNames
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
Creates mapping between local resources and dtd ids.- Returns:
- map between local resources and dtd ids.
-