Commit fc739bba authored by Stephan Kreutzer's avatar Stephan Kreutzer

change_instructions_executor_1: Added the option to copy the last version to...

change_instructions_executor_1: Added the option to copy the last version to an output file with a fixed name.
parent f10558ef
/* Copyright (C) 2016-2018 Stephan Kreutzer
/* Copyright (C) 2016-2019 Stephan Kreutzer
*
* This file is part of change_instructions_executor_1, a submodule of the
* digital_publishing_workflow_tools package.
......@@ -54,7 +54,7 @@ public class change_instructions_executor_1
{
public static void main(String args[])
{
System.out.print("change_instructions_executor_1 Copyright (C) 2016-2018 Stephan Kreutzer\n" +
System.out.print("change_instructions_executor_1 Copyright (C) 2016-2019 Stephan Kreutzer\n" +
"This program comes with ABSOLUTELY NO WARRANTY.\n" +
"This is free software, and you are welcome to redistribute it\n" +
"under certain conditions. See the GNU Affero General Public License 3\n" +
......@@ -326,6 +326,7 @@ public class change_instructions_executor_1
File inputFile = null;
File outputDirectory = null;
boolean fileLast = false;
try
{
......@@ -451,6 +452,16 @@ public class change_instructions_executor_1
throw constructTermination("messageOutputDirectoryCantCreate", null, null, outputDirectory.getAbsolutePath(), jobFile.getAbsolutePath());
}
}
Attribute fileLastAttribute = outputDirectoryElement.getAttributeByName(new QName("file-last"));
if (fileLastAttribute == null)
{
if (fileLastAttribute.getValue().equals("true") == true)
{
fileLast = true;
}
}
}
}
}
......@@ -677,6 +688,120 @@ public class change_instructions_executor_1
throw constructTermination("messageInputFileErrorWhileReading", ex, null, inputFile.getAbsolutePath());
}
if (this.outputFiles.size() > 0 &&
fileLast == true)
{
CopyFileBinary(this.outputFiles.get(this.outputFiles.size() - 1).getFile(),
new File(outputDirectory.getAbsolutePath() + File.separator + "last.txt"));
}
return 0;
}
public int CopyFileBinary(File from, File to) throws ProgramTerminationException
{
if (from.exists() != true)
{
throw constructTermination("messageCantCopyBecauseFromDoesntExist", null, null, from.getAbsolutePath(), to.getAbsolutePath());
}
if (from.isFile() != true)
{
throw constructTermination("messageCantCopyBecauseFromIsntAFile", null, null, from.getAbsolutePath(), to.getAbsolutePath());
}
if (from.canRead() != true)
{
throw constructTermination("messageCantCopyBecauseFromIsntReadable", null, null, from.getAbsolutePath(), to.getAbsolutePath());
}
if (to.exists() == true)
{
if (to.isFile() == true)
{
if (to.canWrite() != true)
{
throw constructTermination("messageCantCopyBecauseToIsntWritable", null, null, from.getAbsolutePath(), to.getAbsolutePath());
}
}
else
{
throw constructTermination("messageCantCopyBecauseToIsntAFile", null, null, from.getAbsolutePath(), to.getAbsolutePath());
}
}
ProgramTerminationException exception = null;
byte[] buffer = new byte[1024];
FileInputStream reader = null;
FileOutputStream writer = null;
try
{
to.createNewFile();
reader = new FileInputStream(from);
writer = new FileOutputStream(to);
int bytesRead = reader.read(buffer, 0, buffer.length);
while (bytesRead > 0)
{
writer.write(buffer, 0, bytesRead);
bytesRead = reader.read(buffer, 0, buffer.length);
}
writer.close();
reader.close();
}
catch (FileNotFoundException ex)
{
exception = constructTermination("messageCopyFileError", ex, null, from.getAbsolutePath(), to.getAbsolutePath());
}
catch (IOException ex)
{
exception = constructTermination("messageCopyFileError", ex, null, from.getAbsolutePath(), to.getAbsolutePath());
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch (IOException ex)
{
if (exception == null)
{
exception = constructTermination("messageCopyFileError", ex, null, from.getAbsolutePath(), to.getAbsolutePath());
}
}
}
if (reader != null)
{
try
{
reader.close();
}
catch (IOException ex)
{
if (exception == null)
{
exception = constructTermination("messageCopyFileError", ex, null, from.getAbsolutePath(), to.getAbsolutePath());
}
}
}
}
if (exception != null)
{
throw exception;
}
return 0;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2017-2018 Stephan Kreutzer
Copyright (C) 2017-2019 Stephan Kreutzer
This file is part of change_instructions_executor_1, a submodule of the
digital_publishing_workflow_tools package.
......@@ -19,5 +19,5 @@ along with change_instructions_executor_1. If not, see <http://www.gnu.org/licen
-->
<change-instructions-executor-1-job>
<input-file path="./input.xml"/>
<output-directory path="./output/"/>
<output-directory path="./output/" file-last="true" />
</change-instructions-executor-1-job>
# Copyright (C) 2015-2018 Stephan Kreutzer
# Copyright (C) 2015-2019 Stephan Kreutzer
#
# This file is part of change_instructions_executor_1, a submodule of the
# digital_publishing_workflow_tools package.
......@@ -44,3 +44,9 @@ messageInputFilePositionExceedsLastPosition = The position {2,number} of instruc
messageInputFileCountUndercutsTextBegin = The count {3,number} of instruction #{4,number} ({1}) from position {2,number} as specified in input file "{0}" undercuts the begin of the text by {5,number} characters.
messageInputFileErrorWhileReading = An error occurred while reading input file "{0}".
messageOutputFileErrorWhileWriting = An error occurred while writing output file "{0}".
messageCantCopyBecauseFromDoesntExist = Can''t copy "{0}" to "{1}" because "{0}" doesn''t exist.
messageCantCopyBecauseFromIsntAFile = Can''t copy "{0}" to "{1}" because "{0}" isn''t a file.
messageCantCopyBecauseFromIsntReadable = Can''t copy "{0}" to "{1}" because "{0}" isn''t readable.
messageCantCopyBecauseToIsntAFile = Can''t copy "{0}" to "{1}" because "{1}" exists already and isn''t a file.
messageCantCopyBecauseToIsntWritable = Can''t copy "{0}" to "{1}" because "{1}" isn''t writable.
messageCopyFileError = An error occurred while copying "{0}" to "{1}".
# Copyright (C) 2015-2018 Stephan Kreutzer
# Copyright (C) 2015-2019 Stephan Kreutzer
#
# This file is part of change_instructions_executor_1, a submodule of the
# digital_publishing_workflow_tools package.
......@@ -44,3 +44,9 @@ messageInputFilePositionExceedsLastPosition = Die Positionsangabe {2,number} der
messageInputFileCountUndercutsTextBegin = Die Längenangabe {3,number}" der Anweisung #{4,number} ({1}) von Position {2,number} wie in Eingabedatei "{0}" angegeben unterschreitet den Beginn des Textes um {5,numbers} Zeichen.
messageInputFileErrorWhileReading = Beim Lesen der Eingabedatei "{0}" ist ein Fehler aufgetreten.
messageOutputFileErrorWhileWriting = Beim Schreiben der Ergebnisdatei "{0}" ist ein Fehler aufgetreten.
messageCantCopyBecauseFromDoesntExist = Kann "{0}" nicht nach "{1}" kopieren, weil "{0}" nicht existiert.
messageCantCopyBecauseFromIsntAFile = Kann "{0}" nicht nach "{1}" kopieren, weil "{0}" keine Datei ist.
messageCantCopyBecauseFromIsntReadable = Kann "{0}" nicht nach "{1}" kopieren, weil "{0}" nicht lesbar ist.
messageCantCopyBecauseToIsntAFile = Kann "{0}" nicht nach "{1}" kopieren, weil "{1}" bereits existiert und es sich nicht um eine Datei handelt.
messageCantCopyBecauseToIsntWritable = Kann "{0}" nicht nach "{1}" kopieren, weil "{1}" nicht schreibbar ist.
messageCopyFileError = Beim Kopieren von "{0}" nach "{1}" ist ein Fehler aufgetreten.
/* Copyright (C) 2016-2018 Stephan Kreutzer
/* Copyright (C) 2016-2019 Stephan Kreutzer
*
* This file is part of edl_to_xml_1, a submodule of the
* digital_publishing_workflow_tools package.
......@@ -56,7 +56,7 @@ public class edl_to_xml_1
{
public static void main(String args[])
{
System.out.print("edl_to_xml_1 Copyright (C) 2016-2018 Stephan Kreutzer\n" +
System.out.print("edl_to_xml_1 Copyright (C) 2016-2019 Stephan Kreutzer\n" +
"This program comes with ABSOLUTELY NO WARRANTY.\n" +
"This is free software, and you are welcome to redistribute it\n" +
"under certain conditions. See the GNU Affero General Public License 3\n" +
......@@ -426,12 +426,12 @@ public class edl_to_xml_1
{
if (outputFile.canWrite() != true)
{
throw constructTermination("messageOutputFileIsntWritable", null, null, outputFile.getAbsolutePath());
throw constructTermination("messageOutputFileIsntWritable", null, null, outputFile.getAbsolutePath(), jobFile.getAbsolutePath());
}
}
else
{
throw constructTermination("messageOutputPathIsntAFile", null, null, outputFile.getAbsolutePath());
throw constructTermination("messageOutputPathIsntAFile", null, null, outputFile.getAbsolutePath(), jobFile.getAbsolutePath());
}
}
......
# Copyright (C) 2015-2017 Stephan Kreutzer
# Copyright (C) 2015-2019 Stephan Kreutzer
#
# This file is part of edl_to_xml_1, a submodule of the
# digital_publishing_workflow_tools package.
......
# Copyright (C) 2015-2018 Stephan Kreutzer
# Copyright (C) 2015-2019 Stephan Kreutzer
#
# This file is part of edl_to_xml_1, a submodule of the
# digital_publishing_workflow_tools package.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment