Sample source code for a custom transform class
The provided sample source code demonstrates how to pass the data and metadata associated with the ODHit to your custom class file that implements the transformData method.
About this task
This sample does not demonstrate how to transform the data but rather how to access the needed elements and set the appropriate return to ODWEK. With this sample, the data as it is stored in Content Manager OnDemand and the data returned are identical. Your implementation will need complete the transformation itself.
//*******************************************************************
// Testcase: CustomTransform
//
// This class tests the ODWEK Generic Transform's Custom
// Java Interface by implementing the required transformData method.
//
// transformData is called by ODWEK when its corresponding custom
// viewer is called via ODHit.retrieve.
//*******************************************************************
import java.util.*;
import com.ibm.edms.od.*;
public class CustomTransform {
public static HashMap<String,byte[]> transformData(HashMap<String,?> odMap) throws Exception {
// List this transform name from the XML file
System.out.println(" Transform name: " + (String)odMap.get(ODTransform.TXFRM_REQ_NAME));
// List the property keys and values ODWEK read from the transform XML
// file and provided to this Custom Class
System.out.println(" Transform properties:");
Properties gtProps = (Properties)odMap.get(ODTransform.TXFRM_REQ_PROPS);
Enumeration<?> enumeration = gtProps.keys();
List<String> list = new ArrayList<String>();
while (enumeration.hasMoreElements()) {
list.add((String)enumeration.nextElement());
}
Collections.sort(list);
for (String key : list)
System.out.println(String.format("%25s = %-25s", key, gtProps.getProperty(key)));
// Retrieve the native document from ODWEK
byte[] inDoc = (byte [])odMap.get(ODTransform.TXFRM_REQ_DATA);
System.out.println(" Retrieved document size: "
+ (inDoc == null ? "0" : inDoc.length) + " bytes");
// Retrieve the document resources from ODWEK
byte[] inRes = (byte [])odMap.get(ODTransform.TXFRM_REQ_RES);
System.out.println(" Retrieved resource size: "
+ (inRes == null ? "No resources available": inRes.length));
// Normally this is where you do the transform or do something with the byte data.
// Let's just concat the resources if there are any to the doc
byte[] transformedDoc;
if (inRes != null) {
transformedDoc = new byte[inRes.length + inDoc.length];
System.arraycopy(inRes, 0, transformedDoc, 0, inRes.length);
System.arraycopy(inDoc, 0, transformedDoc, inRes.length, inDoc.length);
}
else
transformedDoc = inDoc;
System.out.println(" Transformed document total size: " + transformedDoc.length);
// Send the transformed data back to ODWEK
HashMap<String,byte[]> rtnMap = new HashMap<String, byte[]>();
rtnMap.put(ODTransform.TXFRM_RESP_DATA, (byte[])transformedDoc);
return rtnMap;
}
}
Output from the print statements in the example CustomTransform program might look like the following. Note that output values are definition dependent.
Transform name: MYTXFRM
Transform properties:
ApplGrpName = FinancialReports
ApplName = Ledgers
CC = A
CodePage = 850
recfmt = S
Retrieved document size: 7018 bytes
Retrieved resource size: No resources available
Transformed document total size: 7018