[Minor] Don't log writing to document in XmlHelper
This commit is contained in:
parent
30536cb11c
commit
d46bf18fa2
|
@ -51,7 +51,7 @@ public class XmlHelper {
|
||||||
/**
|
/**
|
||||||
* UNIX_LINE_SEP = "\n" : mostly we want this line separator, instead of the windows version
|
* UNIX_LINE_SEP = "\n" : mostly we want this line separator, instead of the windows version
|
||||||
*/
|
*/
|
||||||
public static final String UNIX_LINE_SEP = "\n"; //$NON-NLS-1$
|
private static final String UNIX_LINE_SEP = "\n"; //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DEFAULT_ENCODING = "utf-8" : defines the default UTF-8 encoding expected of XML files
|
* DEFAULT_ENCODING = "utf-8" : defines the default UTF-8 encoding expected of XML files
|
||||||
|
@ -64,7 +64,7 @@ public class XmlHelper {
|
||||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||||
*
|
*
|
||||||
* @param xmlFile
|
* @param xmlFile
|
||||||
* the {@link File} which has the path to the XML file to read
|
* the {@link File} which has the path to the XML file to read
|
||||||
*/
|
*/
|
||||||
public static void parseDocument(File xmlFile, DefaultHandler xmlHandler) {
|
public static void parseDocument(File xmlFile, DefaultHandler xmlHandler) {
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class XmlHelper {
|
||||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||||
*
|
*
|
||||||
* @param xmlFileInputStream
|
* @param xmlFileInputStream
|
||||||
* the XML {@link InputStream} which is to be parsed
|
* the XML {@link InputStream} which is to be parsed
|
||||||
*/
|
*/
|
||||||
public static void parseDocument(InputStream xmlFileInputStream, DefaultHandler xmlHandler) {
|
public static void parseDocument(InputStream xmlFileInputStream, DefaultHandler xmlHandler) {
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ public class XmlHelper {
|
||||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||||
*
|
*
|
||||||
* @param xmlInputSource
|
* @param xmlInputSource
|
||||||
* the XML {@link InputSource} which is to be parsed
|
* the XML {@link InputSource} which is to be parsed
|
||||||
*/
|
*/
|
||||||
public static void parseDocument(InputSource xmlInputSource, DefaultHandler xmlHandler) {
|
public static void parseDocument(InputSource xmlInputSource, DefaultHandler xmlHandler) {
|
||||||
|
|
||||||
|
@ -133,12 +133,12 @@ public class XmlHelper {
|
||||||
* Writes an {@link Element} to an XML file on the file system
|
* Writes an {@link Element} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param rootElement
|
* @param rootElement
|
||||||
* the {@link Element} to write to the file system
|
* the {@link Element} to write to the file system
|
||||||
* @param file
|
* @param file
|
||||||
* the {@link File} describing the path on the file system where the XML file should be written to
|
* the {@link File} describing the path on the file system where the XML file should be written to
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static void writeElement(Element rootElement, File file) throws RuntimeException {
|
public static void writeElement(Element rootElement, File file) throws RuntimeException {
|
||||||
Document document = createDocument();
|
Document document = createDocument();
|
||||||
|
@ -150,12 +150,12 @@ public class XmlHelper {
|
||||||
* Writes a {@link Document} to an XML file on the file system
|
* Writes a {@link Document} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* the {@link Document} to write to the file system
|
* the {@link Document} to write to the file system
|
||||||
* @param file
|
* @param file
|
||||||
* the {@link File} describing the path on the file system where the XML file should be written to
|
* the {@link File} describing the path on the file system where the XML file should be written to
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static void writeDocument(Document document, File file) throws RuntimeException {
|
public static void writeDocument(Document document, File file) throws RuntimeException {
|
||||||
writeDocument(document, file, DEFAULT_ENCODING);
|
writeDocument(document, file, DEFAULT_ENCODING);
|
||||||
|
@ -165,19 +165,16 @@ public class XmlHelper {
|
||||||
* Writes a {@link Document} to an XML file on the file system
|
* Writes a {@link Document} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* the {@link Document} to write to the file system
|
* the {@link Document} to write to the file system
|
||||||
* @param file
|
* @param file
|
||||||
* the {@link File} describing the path on the file system where the XML file should be written to
|
* the {@link File} describing the path on the file system where the XML file should be written to
|
||||||
* @param encoding
|
* @param encoding
|
||||||
* encoding to use to write the file
|
* encoding to use to write the file
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static void writeDocument(Document document, File file, String encoding) throws RuntimeException {
|
public static void writeDocument(Document document, File file, String encoding) throws RuntimeException {
|
||||||
String msg = "Exporting document element {0} to {1}"; //$NON-NLS-1$
|
|
||||||
msg = MessageFormat.format(msg, document.getNodeName(), file.getAbsolutePath());
|
|
||||||
XmlHelper.logger.info(msg);
|
|
||||||
writeDocument(document, new StreamResult(file), encoding);
|
writeDocument(document, new StreamResult(file), encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,12 +182,12 @@ public class XmlHelper {
|
||||||
* Writes a {@link Document} to an XML file on the file system
|
* Writes a {@link Document} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* the {@link Document} to write to the file system
|
* the {@link Document} to write to the file system
|
||||||
* @param outputStream
|
* @param outputStream
|
||||||
* stream to write document to
|
* stream to write document to
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static void writeDocument(Document document, OutputStream outputStream) throws RuntimeException {
|
public static void writeDocument(Document document, OutputStream outputStream) throws RuntimeException {
|
||||||
writeDocument(document, new StreamResult(outputStream), DEFAULT_ENCODING);
|
writeDocument(document, new StreamResult(outputStream), DEFAULT_ENCODING);
|
||||||
|
@ -200,10 +197,10 @@ public class XmlHelper {
|
||||||
* Writes a {@link Document} to an XML file on the file system
|
* Writes a {@link Document} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* the {@link Document} to write to the file system
|
* the {@link Document} to write to the file system
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static String writeToString(Document document) throws RuntimeException {
|
public static String writeToString(Document document) throws RuntimeException {
|
||||||
try {
|
try {
|
||||||
|
@ -219,14 +216,14 @@ public class XmlHelper {
|
||||||
* Writes a {@link Document} to an XML file on the file system
|
* Writes a {@link Document} to an XML file on the file system
|
||||||
*
|
*
|
||||||
* @param document
|
* @param document
|
||||||
* the {@link Document} to write to the file system
|
* the {@link Document} to write to the file system
|
||||||
* @param streamResult
|
* @param streamResult
|
||||||
* the destination
|
* the destination
|
||||||
* @param encoding
|
* @param encoding
|
||||||
* encoding to use to write the file
|
* encoding to use to write the file
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration, or writing the element
|
* if something went wrong while creating the XML configuration, or writing the element
|
||||||
*/
|
*/
|
||||||
public static void writeDocument(Document document, StreamResult streamResult, String encoding)
|
public static void writeDocument(Document document, StreamResult streamResult, String encoding)
|
||||||
throws RuntimeException {
|
throws RuntimeException {
|
||||||
|
@ -250,7 +247,8 @@ public class XmlHelper {
|
||||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
|
||||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
|
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
|
||||||
transformer.setOutputProperty(OutputKeys.ENCODING, docEncoding);
|
transformer.setOutputProperty(OutputKeys.ENCODING, docEncoding);
|
||||||
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
transformer
|
||||||
|
.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
// transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", "\t");
|
// transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", "\t");
|
||||||
|
|
||||||
// Transform to file
|
// Transform to file
|
||||||
|
@ -273,20 +271,17 @@ public class XmlHelper {
|
||||||
* @return a new document instance
|
* @return a new document instance
|
||||||
*
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* if something went wrong while creating the XML configuration
|
* if something went wrong while creating the XML configuration
|
||||||
*/
|
*/
|
||||||
public static Document createDocument() throws RuntimeException {
|
public static Document createDocument() throws RuntimeException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
|
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
|
||||||
Document document = docBuilder.newDocument();
|
|
||||||
|
|
||||||
return document;
|
return docBuilder.newDocument();
|
||||||
|
|
||||||
} catch (DOMException e) {
|
} catch (DOMException | ParserConfigurationException e) {
|
||||||
throw new XmlException("Failed to create Document: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
throw new XmlException("Failed to create Document: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
|
throw new XmlException("Failed to create Document: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue