1 34 35 package com.micronova.jsp.tag; 36 37 import com.micronova.util.*; 38 import java.util.*; 39 import javax.servlet.jsp.*; 40 import java.lang.reflect.*; 41 import java.util.regex.*; 42 43 public class ELComparator extends NestedMap implements Comparator 44 { 45 public static final String EQUAL = "equal"; 46 public static final String LESS = "less"; 47 public static final String MORE = "more"; 48 public static final String X = "x"; 49 public static final String Y = "y"; 50 public static final String CODEC = "codec"; 51 52 protected PageContext _pageContext; 53 54 public ELComparator(PageContext pageContext, Object source) throws Exception 55 { 56 super(source); 57 58 _pageContext = pageContext; 59 } 60 61 public int compare(Object o1, Object o2) 62 { 63 try 64 { 65 PageContext pageContext = _pageContext; 66 67 String codec = getString(CODEC); 68 69 if (!TypeUtil.isEmptyString(codec)) 70 { 71 o1 = EL.applyCodec(pageContext, codec, o1); 72 o2 = EL.applyCodec(pageContext, codec, o2); 73 } 74 75 put(X, o1); 76 put(Y, o2); 77 78 String equalCodec = getString(EQUAL); 79 80 if (!TypeUtil.isEmptyString(equalCodec)) 81 { 82 Object equalValue = EL.applyCodec(pageContext, equalCodec, this); 83 84 if (TypeUtil.isTrue(equalValue)) 85 { 86 return 0; 87 } 88 } 89 90 int comparison = -2; 91 92 if (o1 == null) 93 { 94 if (o2 == null) 95 { 96 return 0; 97 } 98 else 99 { 100 return -1; 101 } 102 } 103 else 104 { 105 comparison = ((Comparable )o1).compareTo(o2); 106 107 if (comparison == 0) 108 { 109 return 0; 110 } 111 } 112 113 String lessCodec = getString(LESS); 114 115 if (!TypeUtil.isEmptyString(lessCodec)) 116 { 117 Object lessValue = EL.applyCodec(pageContext, lessCodec, this); 118 119 if (TypeUtil.isTrue(lessValue)) 120 { 121 return -1; 122 } 123 else 124 { 125 return 1; 126 } 127 } 128 129 String moreCodec = getString(MORE); 130 131 if (!TypeUtil.isEmptyString(moreCodec)) 132 { 133 Object moreValue = EL.applyCodec(pageContext, moreCodec, this); 134 135 if (TypeUtil.isTrue(moreValue)) 136 { 137 return 1; 138 } 139 else 140 { 141 return -1; 142 } 143 } 144 145 return comparison; 146 } 147 catch (Exception e) 148 { 149 throw new RuntimeException (e); 150 } 151 } 152 } 153 | Popular Tags |