[Minor] Don't log writing to document in XmlHelper
This commit is contained in:
parent
30536cb11c
commit
d46bf18fa2
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -38,7 +38,7 @@ import org.xml.sax.helpers.DefaultHandler;
|
|||
|
||||
/**
|
||||
* Helper class for performing XML based tasks
|
||||
*
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class XmlHelper {
|
||||
|
@ -51,7 +51,7 @@ public class XmlHelper {
|
|||
/**
|
||||
* 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
|
||||
|
@ -62,9 +62,9 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||
*
|
||||
*
|
||||
* @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) {
|
||||
|
||||
|
@ -83,9 +83,9 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||
*
|
||||
*
|
||||
* @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) {
|
||||
|
||||
|
@ -104,12 +104,12 @@ public class XmlHelper {
|
|||
throw new XmlException("The XML stream not be read: " + e.getMessage(), e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses an XML file on the file system and returns the resulting {@link Document} object
|
||||
*
|
||||
*
|
||||
* @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) {
|
||||
|
||||
|
@ -131,14 +131,14 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Writes an {@link Element} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param rootElement
|
||||
* the {@link Element} to write to the file system
|
||||
* the {@link Element} to write to the file system
|
||||
* @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
|
||||
* 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 {
|
||||
Document document = createDocument();
|
||||
|
@ -148,14 +148,14 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Writes a {@link Document} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* the {@link Document} to write to the file system
|
||||
* the {@link Document} to write to the file system
|
||||
* @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
|
||||
* 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 {
|
||||
writeDocument(document, file, DEFAULT_ENCODING);
|
||||
|
@ -163,34 +163,31 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Writes a {@link Document} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* the {@link Document} to write to the file system
|
||||
* the {@link Document} to write to the file system
|
||||
* @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
|
||||
* encoding to use to write the file
|
||||
*
|
||||
* encoding to use to write the file
|
||||
*
|
||||
* @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 {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@link Document} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* the {@link Document} to write to the file system
|
||||
* the {@link Document} to write to the file system
|
||||
* @param outputStream
|
||||
* stream to write document to
|
||||
*
|
||||
* stream to write document to
|
||||
*
|
||||
* @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 {
|
||||
writeDocument(document, new StreamResult(outputStream), DEFAULT_ENCODING);
|
||||
|
@ -198,12 +195,12 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Writes a {@link Document} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* the {@link Document} to write to the file system
|
||||
*
|
||||
* the {@link Document} to write to the file system
|
||||
*
|
||||
* @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 {
|
||||
try {
|
||||
|
@ -217,16 +214,16 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Writes a {@link Document} to an XML file on the file system
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* the {@link Document} to write to the file system
|
||||
* the {@link Document} to write to the file system
|
||||
* @param streamResult
|
||||
* the destination
|
||||
* the destination
|
||||
* @param encoding
|
||||
* encoding to use to write the file
|
||||
*
|
||||
* encoding to use to write the file
|
||||
*
|
||||
* @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)
|
||||
throws RuntimeException {
|
||||
|
@ -250,7 +247,8 @@ public class XmlHelper {
|
|||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
|
||||
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");
|
||||
|
||||
// Transform to file
|
||||
|
@ -269,24 +267,21 @@ public class XmlHelper {
|
|||
|
||||
/**
|
||||
* Returns a new document instance
|
||||
*
|
||||
*
|
||||
* @return a new document instance
|
||||
*
|
||||
*
|
||||
* @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 {
|
||||
try {
|
||||
|
||||
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
|
||||
Document document = docBuilder.newDocument();
|
||||
|
||||
return document;
|
||||
return docBuilder.newDocument();
|
||||
|
||||
} catch (DOMException e) {
|
||||
throw new XmlException("Failed to create Document: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (DOMException | ParserConfigurationException e) {
|
||||
throw new XmlException("Failed to create Document: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue