Class XmlParser
java.lang.Object
org.cyclonedx.CycloneDxSchema
org.cyclonedx.parsers.XmlParser
- All Implemented Interfaces:
Parser
XmlParser is responsible for validating and parsing CycloneDX bill-of-material
XML documents and returning a
Bom object.- Since:
- 3.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.fasterxml.jackson.databind.ObjectMapperFields inherited from class CycloneDxSchema
ALL_VERSIONS, NS_BOM_10, NS_BOM_11, NS_BOM_12, NS_BOM_13, NS_BOM_14, NS_BOM_15, NS_BOM_16, NS_BOM_LATEST, NS_DEPENDENCY_GRAPH_10, VERSION_LATEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Documentprivate voidextractNamespaces(Node node, List<String> namespaces) private Stringprivate BominjectSchemaVersion(Bom bom, String schemaVersion) Uses reflection to set the schemaVersion field inside a Bom instance.booleanisValid(byte[] bomBytes) Verifies a CycloneDX BOM conforms to the latest version of the specification.booleanVerifies a CycloneDX BOM conforms to the specified specification version.booleanVerifies a CycloneDX BOM conforms to the latest version of the specification.booleanVerifies a CycloneDX BOM conforms to the specified specification version.booleanisValid(InputStream inputStream) Verifies a CycloneDX BOM conforms to the latest version of the specification.booleanisValid(InputStream inputStream, Version schemaVersion) Verifies a CycloneDX BOM conforms to the specified specification version.booleanVerifies a CycloneDX BOM conforms to the latest version of the specification.booleanVerifies a CycloneDX BOM conforms to the specified specification version.parse(byte[] bomBytes) Parses a CycloneDX BOM.Parses a CycloneDX BOM.parse(InputStream inputStream) Parses a CycloneDX BOM.Parses a CycloneDX BOM.validate(byte[] bomBytes) Validates a CycloneDX BOM.Validates a CycloneDX BOM conforms to a specific specification version.Validates a CycloneDX BOM.Validates a CycloneDX BOM conforms to a specific specification version.validate(InputStream inputStream) Validates a CycloneDX BOM.validate(InputStream inputStream, Version schemaVersion) Validates a CycloneDX BOM conforms to a specific specification version.Validates a CycloneDX BOM.Validates a CycloneDX BOM conforms to a specific specification version.Methods inherited from class CycloneDxSchema
getJsonSchema, getXmlSchema, getXmlSchema
-
Field Details
-
mapper
private final com.fasterxml.jackson.databind.ObjectMapper mapper -
NAMESPACE_TO_VERSION_MAP
-
-
Constructor Details
-
XmlParser
public XmlParser()
-
-
Method Details
-
parse
Parses a CycloneDX BOM.- Specified by:
parsein interfaceParser- Parameters:
file- a File to parse- Returns:
- a Bom object
- Throws:
ParseException- when errors are encountered
-
parse
Parses a CycloneDX BOM.- Specified by:
parsein interfaceParser- Parameters:
bomBytes- the byte array to parse- Returns:
- a Bom object
- Throws:
ParseException- when errors are encountered
-
parse
Parses a CycloneDX BOM.- Specified by:
parsein interfaceParser- Parameters:
inputStream- the InputStream from which to parse- Returns:
- a Bom object
- Throws:
ParseException- when errors are encountered
-
parse
Parses a CycloneDX BOM.- Specified by:
parsein interfaceParser- Parameters:
reader- the Reader from which to parse- Returns:
- a Bom object
- Throws:
ParseException- when errors are encountered
-
injectSchemaVersion
Uses reflection to set the schemaVersion field inside a Bom instance. The schemaVersion is 'not user serviceable' so no methods for setting it are provided, other than the constructor, which xstream does not use.- Parameters:
bom- the Bom to set the schemaVersion forschemaVersion- the value of the schema version- Returns:
- the updated Bom
- Since:
- 3.0.0
-
validate
Validates a CycloneDX BOM.- Specified by:
validatein interfaceParser- Parameters:
file- the CycloneDX BOM file to validate- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM conforms to a specific specification version.- Specified by:
validatein interfaceParser- Parameters:
file- the CycloneDX BOM file to validateschemaVersion- the schema version to validate against- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM.- Specified by:
validatein interfaceParser- Parameters:
bomBytes- the byte array to validate- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM conforms to a specific specification version.- Specified by:
validatein interfaceParser- Parameters:
bomBytes- the byte array to validateschemaVersion- the schema version to validate against- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM.- Specified by:
validatein interfaceParser- Parameters:
reader- the Reader from which to parse- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM conforms to a specific specification version.- Specified by:
validatein interfaceParser- Parameters:
reader- the Reader from which to parseschemaVersion- the schema version to validate against- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
Validates a CycloneDX BOM.- Specified by:
validatein interfaceParser- Parameters:
inputStream- the InputStream from which to validate- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
public List<ParseException> validate(InputStream inputStream, Version schemaVersion) throws IOException Validates a CycloneDX BOM conforms to a specific specification version.- Specified by:
validatein interfaceParser- Parameters:
inputStream- the InputStream from which to validateschemaVersion- the schema version to validate against- Returns:
- a List of ParseException. If the size of the list is 0, validation was successful
- Throws:
IOException- when errors are encountered
-
validate
- Throws:
IOException
-
isValid
Verifies a CycloneDX BOM conforms to the latest version of the specification.- Specified by:
isValidin interfaceParser- Parameters:
file- the CycloneDX BOM file to validate- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the specified specification version.- Specified by:
isValidin interfaceParser- Parameters:
file- the CycloneDX BOM file to validateschemaVersion- the schema version to validate against- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the latest version of the specification.- Specified by:
isValidin interfaceParser- Parameters:
bomBytes- the byte array to validate- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the specified specification version.- Specified by:
isValidin interfaceParser- Parameters:
bomBytes- the byte array to validateschemaVersion- the schema version to validate against- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the latest version of the specification.- Specified by:
isValidin interfaceParser- Parameters:
reader- the Reader from which to validate- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the specified specification version.- Specified by:
isValidin interfaceParser- Parameters:
reader- the Reader from which to validateschemaVersion- the schema version to validate against- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the latest version of the specification.- Specified by:
isValidin interfaceParser- Parameters:
inputStream- the InputStream from which to validate- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
isValid
Verifies a CycloneDX BOM conforms to the specified specification version.- Specified by:
isValidin interfaceParser- Parameters:
inputStream- the InputStream from which to validateschemaVersion- the schema version to validate against- Returns:
- true if the file is a valid BOM, false if not
- Throws:
IOException- when errors are encountered
-
identifySchemaVersion
private String identifySchemaVersion(InputSource in) throws ParserConfigurationException, IOException, SAXException -
extractAllNamespaceDeclarations
private List<String> extractAllNamespaceDeclarations(InputSource in) throws ParserConfigurationException, IOException, SAXException -
extractNamespaces
-
createSecureDocument
private Document createSecureDocument(InputSource in) throws ParserConfigurationException, IOException, SAXException
-