01: package com.bostechcorp.cbesb.map;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import javax.activation.DataHandler;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10:
11: import com.bostechcorp.cbesb.runtime.ccsl.lib.ITransformationOperation;
12:
13: /**
14: * User Map Operation used to copy an attachment from the source message
15: * to the target message.
16: * Arguments:
17: * Source Arg 1: source attachment content ID. This is usually supplied in a field
18: * from the source message.
19: * Source Arg 2: (optional) target content ID value. The value to use as the
20: * content ID in the target message. If not supplied, the value supplied in the first
21: * argument is used.
22: * Target Arg 1: The field in the target message to store the target content ID.
23: *
24: */
25: public class CopyAttachment implements ITransformationOperation {
26:
27: protected final transient Log logger = LogFactory
28: .getLog(getClass());
29:
30: private HashMap<String, DataHandler> sourceAttachmentMap;
31: private HashMap<String, DataHandler> targetAttachmentMap;
32:
33: public void initialize(Map<String, Object> transformContext)
34: throws Exception {
35: sourceAttachmentMap = (HashMap<String, DataHandler>) transformContext
36: .get("Source.AttachmentMap");
37: targetAttachmentMap = (HashMap<String, DataHandler>) transformContext
38: .get("Target.AttachmentMap");
39: }
40:
41: public void addProperty(String name, String value) {
42:
43: }
44:
45: public void cleanup(Map<String, Object> transformContext)
46: throws Exception {
47:
48: }
49:
50: public boolean process(String[] source, String[] target)
51: throws Exception {
52: if (source.length > 0 && source[0] != null) {
53: //Get Content ID of attachment from first arg
54: String srcCID = source[0];
55: DataHandler dh = sourceAttachmentMap.get(srcCID);
56: if (dh == null) {
57: logger.error("No attachment was found for Content ID: "
58: + source[0]);
59: return false;
60: }
61: String destCID;
62: if (source.length == 2) {
63: destCID = source[1];
64: } else {
65: destCID = srcCID;
66: }
67: targetAttachmentMap.put(destCID, dh);
68: target[0] = destCID;
69: } else {
70: logger.error("No source argument provided.");
71: return false;
72: }
73: return true;
74: }
75:
76: }
|