XComponent Datasheet (xc3.xco)

Compliant with the XPipe XML Component Architecture (http://xpipe.sourceforge.net)

Null Transformation - Lexical - Jython implementation

Documentation

Synopsis

Do nothing i.e. replicate input file on output file.

Parameters

None

Description

Do nothing i.e. replicate input file on output file. Very useful for testing and as a "placeholder" component during application development.

Details Summary
Version0.1
Author Sean McGrath
KeyWordsJython
Null Transformation
Parameters

Pre
HREFNone
TypeNone
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
BodyNone

Code
TypeJython
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
"""
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:])

Post
HREFNone
TypeNone
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
BodyNone

Test : First Test
Parameters
Input
HREF#UnitTestFile1
EncodingPLAIN
BodyNone
Output
HREF#UnitTestFile2
EncodingPLAIN
BodyNone

Resource : UnitTestFile1
EncodingPLAIN
ExtractFilenameNone
Body
This is a two
line test document

Resource : UnitTestFile2
EncodingPLAIN
ExtractFilenameNone
Body
This is a two
line test document