Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
C4J committed Jan 18, 2025
1 parent 4a95c96 commit c78b1b7
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 107 deletions.
Binary file modified b6/commander4j.jar
Binary file not shown.
Binary file modified b6/lib/devonly/i4jruntime.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion b6/src/com/commander4j/app/JVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class JVersion
{

public static String getProgramVersion() {
return "11.60";
return "11.61";
}

public static Double getProgramVersionValue() {
Expand Down
129 changes: 48 additions & 81 deletions b6/src/com/commander4j/util/JFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@
*/

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class JFileIO
{
Expand Down Expand Up @@ -89,7 +91,8 @@ public boolean move_File(String srcFile, String destFile)
{
deleteFile(destFile);
org.apache.commons.io.FileUtils.moveFile(from, to);
} catch (IOException e)
}
catch (IOException e)
{
logger.debug("move_File error :" + e.getMessage());
setErrorMessage(e.getMessage());
Expand All @@ -107,7 +110,8 @@ public boolean move_FileToDirectory(String srcFile, String destDir, boolean crea
try
{
org.apache.commons.io.FileUtils.moveFileToDirectory(from, dir, createDestDir);
} catch (IOException e)
}
catch (IOException e)
{
logger.debug("move_FileToDirectory error :" + e.getMessage());
setErrorMessage(e.getMessage());
Expand All @@ -124,9 +128,10 @@ public String readFiletoString(String filename)

try
{
result = FileUtils.readFileToString(file,"UTF-8");
result = FileUtils.readFileToString(file, "UTF-8");

} catch (IOException e)
}
catch (IOException e)
{
logger.debug("readFiletoString error :" + e.getMessage());
setErrorMessage(e.getMessage());
Expand All @@ -148,8 +153,7 @@ public boolean deleteFile(String filename)
public Boolean writeToDisk(String path, Document document, long dbTransactionRef, String filesuffix)
{
Boolean result = true;
try
{

NumberFormat formatter = new DecimalFormat("0000000000");
path = path.replace("\\", java.io.File.separator);
path = path.replace("/", java.io.File.separator);
Expand All @@ -162,50 +166,18 @@ public Boolean writeToDisk(String path, Document document, long dbTransactionRef
}
}
String filename = path;

if (dbTransactionRef >= 0)
{
filename = filename + formatter.format(dbTransactionRef);
filename = filename + formatter.format(dbTransactionRef);
}

filename = filename + filesuffix;

setFilename(filename);
setShortFilename(formatter.format(dbTransactionRef) + filesuffix);

// ===============================

DOMImplementationLS DOMiLS = null;
FileOutputStream FOS = null;

// testing the support for DOM Load and Save
if ((document.getFeature("Core", "3.0") != null) && (document.getFeature("LS", "3.0") != null))
{
DOMiLS = (DOMImplementationLS) (document.getImplementation()).getFeature("LS", "3.0");

// get a LSOutput object
LSOutput LSO = DOMiLS.createLSOutput();

FOS = new FileOutputStream(filename);
LSO.setByteStream((OutputStream) FOS);

// get a LSSerializer object
LSSerializer LSS = DOMiLS.createLSSerializer();

// do the serialization
LSS.write(document, LSO);
filename = filename + filesuffix;

FOS.close();
}

result = writeToDisk(filename,document);

// ===============================

} catch (Exception ex)
{
logger.debug("writeToDisk error :" + ex.getMessage());
setErrorMessage("Error writing message to disk. " + ex.getMessage());
result = false;
}
return result;
}

Expand All @@ -232,55 +204,48 @@ public Boolean writeToDisk(String path, String document, long dbTransactionRef,
fw.write(document);
fw.close();

} catch (Exception ex)
}
catch (Exception ex)
{
logger.debug("writeToDisk error :" + ex.getMessage());
setErrorMessage("Error writing message to disk. " + ex.getMessage());
result = false;
}
return result;
}

public Boolean writeToDisk(String filename, Document document)
{
Boolean result = true;
try
{
setFilename(filename);
setShortFilename(filename);
// ===============================

DOMImplementationLS DOMiLS = null;
FileOutputStream FOS = null;
Boolean result = false;

// testing the support for DOM Load and Save
if ((document.getFeature("Core", "3.0") != null) && (document.getFeature("LS", "3.0") != null))
{
DOMiLS = (DOMImplementationLS) (document.getImplementation()).getFeature("LS", "3.0");
setFilename(filename);
setShortFilename(filename);

// get a LSOutput object
LSOutput LSO = DOMiLS.createLSOutput();

FOS = new FileOutputStream(filename);
LSO.setByteStream((OutputStream) FOS);

// get a LSSerializer object
LSSerializer LSS = DOMiLS.createLSSerializer();

// do the serialization
LSS.write(document, LSO);
try
{
StreamResult sr = new StreamResult(new File(filename));
sr.setSystemId(URLDecoder.decode(sr.getSystemId(), "UTF-8"));

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

FOS.close();
}
transformer.transform(new DOMSource(document), sr);

// ===============================
result = true;

} catch (Exception ex)
}
catch (Exception ex)
{
logger.debug("writeToDisk error :" + ex.getMessage());
setErrorMessage("Error writing message to disk. " + ex.getMessage());
result = false;
}

return result;
}

Expand All @@ -290,8 +255,9 @@ public List<String> readFileLines(String filename)
File from = new File(filename);
try
{
result = FileUtils.readLines(from,"UTF-8");
} catch (IOException e)
result = FileUtils.readLines(from, "UTF-8");
}
catch (IOException e)
{
logger.debug("readFileLines error :" + e.getMessage());
e.printStackTrace();
Expand All @@ -306,7 +272,8 @@ public Boolean writeFileLines(String filename, List<String> data)
try
{
FileUtils.writeLines(from, data);
} catch (IOException e)
}
catch (IOException e)
{
result = false;
logger.debug("writeFileLines error :" + e.getMessage());
Expand Down
Loading

0 comments on commit c78b1b7

Please sign in to comment.