Class XmlMetaReader
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.meta.XmlMetaReader
-
public final class XmlMetaReader extends Object
Class having utilities required to read module details from an XML metadata file of a module. This class is used by plugins that need load of metadata from XML files.
-
-
Field Summary
Fields Modifier and Type Field Description private static String
XML_TAG_DESCRIPTION
Description tag of metadata XML files.private static String
XML_TAG_NAME
Name tag of metadata XML files.
-
Constructor Summary
Constructors Modifier Constructor Description private
XmlMetaReader()
Do no allowXmlMetaReader
instances to be created.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static List<ModulePropertyDetails>
createProperties(Element properties)
Create module property details from the XML metadata.private static String
getAttributeValue(Element element, String attribute)
Utility to get attribute value of an element.private static List<Element>
getDirectChildsByTag(Element element, String sTagName)
Utility to get the children of an element by tag name.private static List<String>
getListContentByAttribute(Element element, String listParent, String listOption, String attribute)
Utility to get the list contents by the attribute specified.private static void
populateModule(Element mod, ModuleDetails moduleDetails)
Populate the module detail object from XML metadata.static ModuleDetails
read(InputStream moduleMetadataStream, ModuleType moduleType)
Read the module details from the supplied input stream of the module's XML metadata file.static List<ModuleDetails>
readAllModulesIncludingThirdPartyIfAny(String... thirdPartyPackages)
Utility to load all the metadata files present in the checkstyle JAR including third parties' module metadata files.
-
-
-
Field Detail
-
XML_TAG_NAME
private static final String XML_TAG_NAME
Name tag of metadata XML files.- See Also:
- Constant Field Values
-
XML_TAG_DESCRIPTION
private static final String XML_TAG_DESCRIPTION
Description tag of metadata XML files.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlMetaReader
private XmlMetaReader()
Do no allowXmlMetaReader
instances to be created.
-
-
Method Detail
-
readAllModulesIncludingThirdPartyIfAny
public static List<ModuleDetails> readAllModulesIncludingThirdPartyIfAny(String... thirdPartyPackages)
Utility to load all the metadata files present in the checkstyle JAR including third parties' module metadata files. checkstyle metadata files are grouped in a folder hierarchy similar to that of their corresponding source files. Third party(e.g. SevNTU Checks) metadata files are prefixed withcheckstylemeta-
to their file names.- Parameters:
thirdPartyPackages
- fully qualified third party package names(can be only a hint, e.g. for SevNTU it can be com.github.sevntu / com.github)- Returns:
- list of module details found in the classpath satisfying the above conditions
- Throws:
IllegalStateException
- if there was a problem reading the module metadata files
-
read
public static ModuleDetails read(InputStream moduleMetadataStream, ModuleType moduleType) throws ParserConfigurationException, IOException, SAXException
Read the module details from the supplied input stream of the module's XML metadata file.- Parameters:
moduleMetadataStream
- input stream object of a module's metadata filemoduleType
- type of module- Returns:
- module detail object extracted from the XML metadata file
- Throws:
ParserConfigurationException
- if a parser configuration exception occursIOException
- if a IO exception occursSAXException
- if a SAX exception occurs during parsing the XML file
-
populateModule
private static void populateModule(Element mod, ModuleDetails moduleDetails)
Populate the module detail object from XML metadata.- Parameters:
mod
- root XML document elementmoduleDetails
- module detail object, which is to be updated
-
createProperties
private static List<ModulePropertyDetails> createProperties(Element properties)
Create module property details from the XML metadata.- Parameters:
properties
- parent document element which contains property's metadata- Returns:
- list of property details object created
-
getListContentByAttribute
private static List<String> getListContentByAttribute(Element element, String listParent, String listOption, String attribute)
Utility to get the list contents by the attribute specified.- Parameters:
element
- doc elementlistParent
- parent element of listlistOption
- child list elementattribute
- attribute key- Returns:
- list of strings containing the XML list data
-
getDirectChildsByTag
private static List<Element> getDirectChildsByTag(Element element, String sTagName)
Utility to get the children of an element by tag name.- Parameters:
element
- parent elementsTagName
- tag name of children required- Returns:
- list of elements retrieved
-
getAttributeValue
private static String getAttributeValue(Element element, String attribute)
Utility to get attribute value of an element.- Parameters:
element
- target elementattribute
- attribute key- Returns:
- attribute value
-
-