"""
Null Transformation XComponent - Lexical Approach - Jython implementation
Replicate contents of input file to output file
Content of input just has to be text - does not have to be XML
Output is created by simply byte-for-byte re-creating the inputfile.
"""
import sys
def NullTransformationLexical (InputFilename,OutputFilename,LogFilename):
try:
LogFO = open (LogFilename,"w")
except IOError,e:
# Cannot open logging file - no option for error message other than standard out
sys.stderr.write ("Cannot open log file '%s'" % LogFilename)
return 0
try:
InputFO = open (InputFilename,"r")
except IOError,e:
# Cannot open input file - log the error
LogFO.write ("Cannot open input file '%s'" % InputFilename)
LogFO.close()
return 0
try:
OutputFO = open (OutputFilename,"w")
except IOError,e:
# Cannot open output file - log the error
LogFO.write ("Cannot open outout file '%s'" % OutputFilename)
LogFO.close()
InputFO.close()
return 0
try:
# All three files sucessfully opened - down to business
OutputFO.write (InputFO.read())
# Close all files
InputFO.close()
OutputFO.close()
LogFO.close()
# and return success
return 1
except Exception,e:
LogFO.write ("Exception Occurred:'%s'" % str(e))
InputFO.close()
OutputFO.close()
LogFO.close()
return 0
def main (argv):
if len(argv) != 3:
sys.stderr.write ("Usage: Parameters: InputFile OutputFile LogFile")
return 0
InputFilename = argv[0]
OutputFilename = argv[1]
LogFilename = argv[2]
return NullTransformationLexical (InputFilename,OutputFilename,LogFilename)
if __name__ == "__main__":
# Allow XComponent to be called from the command line like any standalone Jython program
main (sys.argv[1:])
|