Class ImportControlLoader
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.puppycrawl.tools.checkstyle.XmlLoader
-
- com.puppycrawl.tools.checkstyle.checks.imports.ImportControlLoader
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
public final class ImportControlLoader extends XmlLoader
Responsible for loading the contents of an import control configuration 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 java.lang.StringALLOW_ELEMENT_NAMEQualified name for element 'allow'.private static java.lang.StringDTD_PUBLIC_CS_ID_1_0The new public ID for version 1_0 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_1The new public ID for version 1_1 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_2The new public ID for version 1_2 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_3The new public ID for version 1_3 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_CS_ID_1_4The new public ID for version 1_4 of the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_0The public ID for the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_1The public ID for the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_2The public ID for the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_3The public ID for the configuration dtd.private static java.lang.StringDTD_PUBLIC_ID_1_4The public ID for the configuration dtd.private static java.util.Map<java.lang.String,java.lang.String>DTD_RESOURCE_BY_IDThe map to lookup the resource name by the id.private static java.lang.StringDTD_RESOURCE_NAME_1_0The resource for the configuration dtd.private static java.lang.StringDTD_RESOURCE_NAME_1_1The resource for the configuration dtd.private static java.lang.StringDTD_RESOURCE_NAME_1_2The resource for the configuration dtd.private static java.lang.StringDTD_RESOURCE_NAME_1_3The resource for the configuration dtd.private static java.lang.StringDTD_RESOURCE_NAME_1_4The resource for the configuration dtd.private static java.lang.StringFILE_ELEMENT_NAMEQualified name for element 'file'.private static java.lang.StringNAME_ATTRIBUTE_NAMEName for attribute 'name'.private static java.lang.StringPKG_ATTRIBUTE_NAMEName for attribute 'pkg'.private java.util.Deque<AbstractImportControl>stackUsed to hold theAbstractImportControlobjects.private static java.lang.StringSTRATEGY_ON_MISMATCH_ALLOWED_VALUEValue "allowed" for attribute 'strategyOnMismatch'.private static java.lang.StringSTRATEGY_ON_MISMATCH_ATTRIBUTE_NAMEName for attribute 'strategyOnMismatch'.private static java.lang.StringSTRATEGY_ON_MISMATCH_DISALLOWED_VALUEValue "disallowed" for attribute 'strategyOnMismatch'.private static java.lang.StringSUBPACKAGE_ELEMENT_NAMEQualified name for element 'subpackage'.
-
Constructor Summary
Constructors Modifier Constructor Description privateImportControlLoader()Constructs an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleancontainsRegexAttribute(org.xml.sax.Attributes attributes)Check if the given attributes contain the regex attribute.private static AbstractImportRulecreateImportRule(java.lang.String qName, org.xml.sax.Attributes attributes)Constructs an instance of an import rule based on the givennameandattributes.voidendElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName)private PkgImportControlgetRoot()Returns root PkgImportControl.private static MismatchStrategygetStrategyForImportControl(org.xml.sax.Attributes attributes)Utility to get a strategyOnMismatch property for "import-control" tag.private static MismatchStrategygetStrategyForSubpackage(org.xml.sax.Attributes attributes)Utility to get a strategyOnMismatch property for "subpackage" tag.static PkgImportControlload(java.net.URI uri)Loads the import control file from a file.private static PkgImportControlload(org.xml.sax.InputSource source, java.net.URI uri)Loads the import control file from aInputSource.private static PkgImportControlloadUri(java.net.URI uri)Loads the import control file from a URI.private static java.lang.StringsafeGet(org.xml.sax.Attributes attributes, java.lang.String name)Utility to safely get an attribute.voidstartElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)-
Methods inherited from class com.puppycrawl.tools.checkstyle.XmlLoader
error, parseInputSource, resolveEntity
-
-
-
-
Field Detail
-
DTD_PUBLIC_ID_1_0
private static final java.lang.String DTD_PUBLIC_ID_1_0
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_0
private static final java.lang.String DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_1
private static final java.lang.String DTD_PUBLIC_ID_1_1
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_1
private static final java.lang.String DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_2
private static final java.lang.String DTD_PUBLIC_ID_1_2
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_2
private static final java.lang.String DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_3
private static final java.lang.String DTD_PUBLIC_ID_1_3
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_3
private static final java.lang.String DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_4
private static final java.lang.String DTD_PUBLIC_ID_1_4
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_4
private static final java.lang.String DTD_PUBLIC_CS_ID_1_4
The new public ID for version 1_4 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_0
private static final java.lang.String DTD_RESOURCE_NAME_1_0
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_1
private static final java.lang.String DTD_RESOURCE_NAME_1_1
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_2
private static final java.lang.String DTD_RESOURCE_NAME_1_2
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_3
private static final java.lang.String DTD_RESOURCE_NAME_1_3
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_4
private static final java.lang.String DTD_RESOURCE_NAME_1_4
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_BY_ID
private static final java.util.Map<java.lang.String,java.lang.String> DTD_RESOURCE_BY_ID
The map to lookup the resource name by the id.
-
PKG_ATTRIBUTE_NAME
private static final java.lang.String PKG_ATTRIBUTE_NAME
Name for attribute 'pkg'.- See Also:
- Constant Field Values
-
NAME_ATTRIBUTE_NAME
private static final java.lang.String NAME_ATTRIBUTE_NAME
Name for attribute 'name'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
private static final java.lang.String STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
Name for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_ALLOWED_VALUE
private static final java.lang.String STRATEGY_ON_MISMATCH_ALLOWED_VALUE
Value "allowed" for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
private static final java.lang.String STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
Value "disallowed" for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
SUBPACKAGE_ELEMENT_NAME
private static final java.lang.String SUBPACKAGE_ELEMENT_NAME
Qualified name for element 'subpackage'.- See Also:
- Constant Field Values
-
FILE_ELEMENT_NAME
private static final java.lang.String FILE_ELEMENT_NAME
Qualified name for element 'file'.- See Also:
- Constant Field Values
-
ALLOW_ELEMENT_NAME
private static final java.lang.String ALLOW_ELEMENT_NAME
Qualified name for element 'allow'.- See Also:
- Constant Field Values
-
stack
private final java.util.Deque<AbstractImportControl> stack
Used to hold theAbstractImportControlobjects.
-
-
Constructor Detail
-
ImportControlLoader
private ImportControlLoader() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Constructs an instance.- Throws:
javax.xml.parsers.ParserConfigurationException- if an error occurs.org.xml.sax.SAXException- if an error occurs.
-
-
Method Detail
-
startElement
public void startElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
createImportRule
private static AbstractImportRule createImportRule(java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
Constructs an instance of an import rule based on the givennameandattributes.- Parameters:
qName- The qualified name.attributes- The attributes attached to the element.- Returns:
- The created import rule.
- Throws:
org.xml.sax.SAXException- if an error occurs.
-
containsRegexAttribute
private static boolean containsRegexAttribute(org.xml.sax.Attributes attributes)
Check if the given attributes contain the regex attribute.- Parameters:
attributes- the attributes.- Returns:
- if the regex attribute is contained.
-
endElement
public void endElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qName)
- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler
-
load
public static PkgImportControl load(java.net.URI uri) throws CheckstyleException
Loads the import control file from a file.- Parameters:
uri- the uri of the file to load.- Returns:
- the root
PkgImportControlobject. - Throws:
CheckstyleException- if an error occurs.
-
load
private static PkgImportControl load(org.xml.sax.InputSource source, java.net.URI uri) throws CheckstyleException
Loads the import control file from aInputSource.- Parameters:
source- the source to load from.uri- uri of the source being loaded.- Returns:
- the root
PkgImportControlobject. - Throws:
CheckstyleException- if an error occurs.
-
loadUri
private static PkgImportControl loadUri(java.net.URI uri) throws CheckstyleException
Loads the import control file from a URI.- Parameters:
uri- the uri of the file to load.- Returns:
- the root
PkgImportControlobject. - Throws:
CheckstyleException- if an error occurs.
-
getRoot
private PkgImportControl getRoot()
Returns root PkgImportControl.- Returns:
- the root
PkgImportControlobject loaded.
-
getStrategyForImportControl
private static MismatchStrategy getStrategyForImportControl(org.xml.sax.Attributes attributes)
Utility to get a strategyOnMismatch property for "import-control" tag.- Parameters:
attributes- collect to get attribute from.- Returns:
- the value of the attribute.
-
getStrategyForSubpackage
private static MismatchStrategy getStrategyForSubpackage(org.xml.sax.Attributes attributes)
Utility to get a strategyOnMismatch property for "subpackage" tag.- Parameters:
attributes- collect to get attribute from.- Returns:
- the value of the attribute.
-
safeGet
private static java.lang.String safeGet(org.xml.sax.Attributes attributes, java.lang.String name) throws org.xml.sax.SAXException
Utility to safely get an attribute. If it does not exist an exception is thrown.- Parameters:
attributes- collect to get attribute from.name- name of the attribute to get.- Returns:
- the value of the attribute.
- Throws:
org.xml.sax.SAXException- if the attribute does not exist.
-
-