Class XMLDocumentBuilder
java.lang.Object
se.swedenconnect.sigval.xml.utils.XMLDocumentBuilder
Safe document builder class for parsing XML data but also providing some function for converting XML documents back to text
- Author:
- Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Provides a canonical print of the XML document.static DocumentBuilderFactory
Getter for a safe document builder factorystatic String
getDocText
(Document doc) Generates a pretty XML print of an XML document based on java.xml functions.static Document
getDocument
(byte[] xmlData) Returns an XML document from a safe document builder processstatic String
getParsedXMLText
(File xmlFile) Parse an XML file and returns an XML stringstatic Document
loadXMLContent
(File xmlFile) Parse an XML file and returns an XML document
-
Constructor Details
-
XMLDocumentBuilder
public XMLDocumentBuilder()
-
-
Method Details
-
getDocText
Generates a pretty XML print of an XML document based on java.xml functions.- Parameters:
doc
- The doc being processed- Returns:
- Test representation of the XML document
- Throws:
IOException
- errors parsing document
-
getCanonicalDocBytes
Provides a canonical print of the XML document. The purpose of this print is to try to preserve integrity of an existing signature.- Parameters:
doc
- The XML document being processed.- Returns:
- The bytes of the xml document
- Throws:
TransformerException
- transformer error
-
getDocument
public static Document getDocument(byte[] xmlData) throws IOException, SAXException, ParserConfigurationException Returns an XML document from a safe document builder process- Parameters:
xmlData
- XML document bytes- Returns:
- XML document
- Throws:
IOException
- On IO errorsSAXException
- Error parsing XML contentParserConfigurationException
- Error in configuration of the parser
-
loadXMLContent
public static Document loadXMLContent(File xmlFile) throws IOException, ParserConfigurationException, SAXException Parse an XML file and returns an XML document- Parameters:
xmlFile
- The XML file being parsed- Returns:
- XML Document
- Throws:
IOException
- On IO errorsSAXException
- Error parsing XML contentParserConfigurationException
- Error in configuration of the parser
-
getParsedXMLText
public static String getParsedXMLText(File xmlFile) throws ParserConfigurationException, SAXException, IOException Parse an XML file and returns an XML string- Parameters:
xmlFile
- The XML file being parsed- Returns:
- XML String
- Throws:
ParserConfigurationException
- parser configuration errorsSAXException
- XML parsing errorsIOException
- other data parsing errors
-
getDbFactory
Getter for a safe document builder factory- Returns:
- safe document builder factory
-