Class XmlParsingUtils
java.lang.Object
dev.jcputney.elearning.parser.util.XmlParsingUtils
Utility class for XML parsing operations used throughout the app.
This class provides methods for parsing XML files into Java objects using Jackson's XmlMapper, with appropriate security settings and error handling.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidloadExternalMetadataIntoMetadata(LoadableMetadata subMetadata, FileAccess fileAccess) Loads an external LOM metadata file into the specified LoadableMetadata object.static voidloadExternalMetadataIntoMetadata(LoadableMetadata subMetadata, ModuleFileProvider moduleFileProvider) Loads an external LOM metadata file into the specified LoadableMetadata object.static <C> CparseXmlToObject(InputStream stream, Class<C> clazz) Parses an XML file into an object of the specified class using Jackson's XmlMapper.static <C> CparseXmlToObject(InputStream stream, Class<C> clazz, String filePath) Parses an XML file into an object of the specified class using Jackson's XmlMapper.
-
Method Details
-
parseXmlToObject
public static <C> C parseXmlToObject(InputStream stream, Class<C> clazz) throws IOException, XMLStreamException Parses an XML file into an object of the specified class using Jackson's XmlMapper.- Type Parameters:
C- The type of the class to parse the XML into.- Parameters:
stream- The InputStream for the XML file.clazz- The class to parse the XML into.- Returns:
- A new instance of the specified class with the parsed XML data.
- Throws:
IOException- If an error occurs while reading the file.XMLStreamException- If an error occurs while parsing the XML.IllegalArgumentException- if stream or clazz is null
-
parseXmlToObject
public static <C> C parseXmlToObject(InputStream stream, Class<C> clazz, String filePath) throws IOException, XMLStreamException Parses an XML file into an object of the specified class using Jackson's XmlMapper.- Type Parameters:
C- The type of the class to parse the XML into.- Parameters:
stream- The InputStream for the XML file.clazz- The class to parse the XML into.filePath- The path of the file being parsed for error context.- Returns:
- A new instance of the specified class with the parsed XML data.
- Throws:
IOException- If an error occurs while reading the file.XMLStreamException- If an error occurs while parsing the XML.IllegalArgumentException- if stream or clazz is null
-
loadExternalMetadataIntoMetadata
public static void loadExternalMetadataIntoMetadata(LoadableMetadata subMetadata, FileAccess fileAccess) throws XMLStreamException, IOException Loads an external LOM metadata file into the specified LoadableMetadata object.This method reads the external metadata file and sets the LOM object in the LoadableMetadata instance if the file exists and can be parsed.
If the external metadata file doesn't exist or can't be parsed, the LoadableMetadata object will not be modified.
- Parameters:
subMetadata- The LoadableMetadata object to load the external metadata into.fileAccess- The FileAccess instance to use for reading the file.- Throws:
XMLStreamException- If an error occurs while parsing the XML.IOException- If an error occurs while reading the file.IllegalArgumentException- if subMetadata or fileAccess is null
-
loadExternalMetadataIntoMetadata
public static void loadExternalMetadataIntoMetadata(LoadableMetadata subMetadata, ModuleFileProvider moduleFileProvider) throws XMLStreamException, IOException Loads an external LOM metadata file into the specified LoadableMetadata object.This method reads the external metadata file and sets the LOM object in the LoadableMetadata instance if the file exists and can be parsed.
If the external metadata file does not exist or cannot be parsed, the LoadableMetadata object will not be modified.
- Parameters:
subMetadata- The LoadableMetadata object to load the external metadata into.moduleFileProvider- The ModuleFileProvider instance to use for reading the file.- Throws:
XMLStreamException- If an error occurs while parsing the XML.IOException- If an error occurs while reading the file.IllegalArgumentException- if subMetadata or moduleFileProvider is null
-