1 10 11 package org.mule.interceptors; 12 13 import org.apache.commons.jxpath.JXPathContext; 14 import org.mule.impl.MuleMessage; 15 import org.mule.umo.Invocation; 16 import org.mule.umo.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.util.StringUtils; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 32 public class JXPathNormalizerInterceptor extends MessageNormalizerInterceptor 33 { 34 private List beforeExpressionsList; 35 private String beforeExpressions; 36 private String afterExpression; 37 38 43 public UMOMessage before(Invocation invocation) throws UMOException 44 { 45 if (beforeExpressions != null && beforeExpressionsList.size() > 0) 46 { 47 JXPathContext ctx = JXPathContext.newContext(getOriginalPayload()); 48 Object [] result = new Object [beforeExpressionsList.size()]; 49 for (int i = 0; i < result.length; i++) 50 { 51 result[i] = ctx.getValue((String )beforeExpressionsList.get(i)); 52 } 53 if (result.length == 1) 54 { 55 return new MuleMessage(result[0], invocation.getMessage()); 56 } 57 else 58 { 59 return new MuleMessage(result, invocation.getMessage()); 60 } 61 } 62 return null; 63 } 64 65 70 public UMOMessage after(Invocation invocation) throws UMOException 71 { 72 if (afterExpression != null) 73 { 74 JXPathContext ctx = JXPathContext.newContext(getOriginalPayload()); 75 ctx.setValue(afterExpression, invocation.getMessage().getPayload()); 76 return new MuleMessage(getOriginalPayload(), invocation.getMessage()); 77 } 78 return null; 79 } 80 81 public String getBeforeExpressions() 82 { 83 return beforeExpressions; 84 } 85 86 public void setBeforeExpressions(String beforeExpressions) 87 { 88 this.beforeExpressions = beforeExpressions; 89 String [] exp = StringUtils.splitAndTrim(beforeExpressions, ","); 90 this.beforeExpressionsList = new ArrayList (exp.length); 91 for (int i = 0; i < exp.length; i++) 92 { 93 this.beforeExpressionsList.add(exp[i]); 94 95 } 96 } 97 98 public String getAfterExpression() 99 { 100 return afterExpression; 101 } 102 103 public void setAfterExpression(String afterExpression) 104 { 105 this.afterExpression = afterExpression; 106 } 107 } 108 | Popular Tags |