This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new c2cde6f2 EMPIREDB-399 bugfix XMLWriter:saveAsFile
c2cde6f2 is described below
commit c2cde6f280ceeda79a7c68bd200d9ed1defb94d6
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Dec 27 12:52:39 2022 +0100
EMPIREDB-399 bugfix XMLWriter:saveAsFile
---
.../java/org/apache/empire/db/DBRecordBase.java | 5 +++-
.../empire/exceptions/FileReadException.java | 6 ++---
.../empire/exceptions/FileWriteException.java | 6 ++---
.../main/java/org/apache/empire/xml/XMLWriter.java | 30 ++++++++++------------
4 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
index 83d47a22..58631751 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordBase.java
@@ -109,7 +109,10 @@ public abstract class DBRecordBase extends DBRecordData
implements Record, Clone
@Override
public String getObjectInfo()
{
- return "Record
"+record.getRowSet().getName()+":"+StringUtils.arrayToString(record.getKey(),
"|");
+ String info = "Record "+record.getRowSet().getName();
+ if (record.getKeyColumns()==null)
+ return info;
+ return info+":"+StringUtils.arrayToString(record.getKey(), "|");
}
@Override
diff --git
a/empire-db/src/main/java/org/apache/empire/exceptions/FileReadException.java
b/empire-db/src/main/java/org/apache/empire/exceptions/FileReadException.java
index 08699725..afa0cd7c 100644
---
a/empire-db/src/main/java/org/apache/empire/exceptions/FileReadException.java
+++
b/empire-db/src/main/java/org/apache/empire/exceptions/FileReadException.java
@@ -18,17 +18,15 @@
*/
package org.apache.empire.exceptions;
-import java.io.IOException;
-
import org.apache.empire.commons.ErrorType;
public class FileReadException extends EmpireFileException
{
private static final long serialVersionUID = 1L;
- public static final ErrorType errorType = new
ErrorType("error.fileReadError", "Error reading the file {0}. Message is:
{1}.");
+ public static final ErrorType errorType = new
ErrorType("error.fileReadError", "Error reading file {0}. Message is: {1}.");
- public FileReadException(String fileName, IOException cause)
+ public FileReadException(String fileName, Exception cause)
{
super(errorType, new String[] { fileName, cause.toString() }, cause);
}
diff --git
a/empire-db/src/main/java/org/apache/empire/exceptions/FileWriteException.java
b/empire-db/src/main/java/org/apache/empire/exceptions/FileWriteException.java
index 98dac912..cd4b4047 100644
---
a/empire-db/src/main/java/org/apache/empire/exceptions/FileWriteException.java
+++
b/empire-db/src/main/java/org/apache/empire/exceptions/FileWriteException.java
@@ -18,17 +18,15 @@
*/
package org.apache.empire.exceptions;
-import java.io.IOException;
-
import org.apache.empire.commons.ErrorType;
public class FileWriteException extends EmpireFileException
{
private static final long serialVersionUID = 1L;
- public static final ErrorType errorType = new
ErrorType("error.fileWriteError", "Error writing the file {0}. Message is:
{1}.");
+ public static final ErrorType errorType = new
ErrorType("error.fileWriteError", "Error writing file {0}. Message is: {1}.");
- public FileWriteException(String fileName, IOException cause)
+ public FileWriteException(String fileName, Exception cause)
{
super(errorType, new String[] { fileName, cause.toString() }, cause);
}
diff --git a/empire-db/src/main/java/org/apache/empire/xml/XMLWriter.java
b/empire-db/src/main/java/org/apache/empire/xml/XMLWriter.java
index 21c8f31e..784ff3e8 100644
--- a/empire-db/src/main/java/org/apache/empire/xml/XMLWriter.java
+++ b/empire-db/src/main/java/org/apache/empire/xml/XMLWriter.java
@@ -33,6 +33,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.empire.exceptions.FileWriteException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
@@ -100,19 +101,13 @@ public class XMLWriter
// write xml
XMLWriter dbg = new XMLWriter(fileOutputStream);
dbg.print(doc, styleSheet);
- } catch (IOException ioe)
- {
+ } catch (IOException ioe) {
log.error("Error: Could not write XML to file: " + filename + " in
directory: " + xmlWriterRoot);
- } finally
- {
- try
- {
+ } finally {
+ try {
if (fileOutputStream != null)
- {
fileOutputStream.close();
- }
- } catch (IOException ioe)
- {
+ } catch (IOException ioe) {
log.error("Cannot write Document file", ioe);
/* Ignore IOExceptions */
}
@@ -120,19 +115,20 @@ public class XMLWriter
}
/**
- * Prints out the DOM-Tree. The file will be truncated if it
- * exists or created if if does not exist.
+ * Saves an XML-Document as file.
+ * The file will be truncated if it exists or created if if does not exist.
*
* @param doc The XML-Document to print
* @param filename The name of the file to write the XML-Document to
+ *
+ * @throws FileWriteException
*/
public static void saveAsFile(Document doc, String filename)
{
try
{
File file = new File(filename);
- if (file.exists() == true)
- {
+ if (file.exists() == true) {
file.delete();
}
@@ -143,9 +139,9 @@ public class XMLWriter
Transformer trf = transformerFactory.newTransformer();
trf.transform(domSource, streamResult);
- } catch (Exception ex)
- {
- log.error("Error: Could not write XML to file: " + filename);
+ } catch (Exception e) {
+ log.error("Could not write XML to file: " + filename);
+ throw new FileWriteException(filename, e);
}
}