1 7 package com.inversoft.verge.util; 8 9 10 import javax.servlet.jsp.PageContext ; 11 12 13 22 public class ScopeTools { 23 24 27 private ScopeTools() { 28 } 29 30 31 38 public static boolean isValidScope(String scope) { 39 40 return (scope.equalsIgnoreCase(ScopeConstants.PAGE) || 41 scope.equalsIgnoreCase(ScopeConstants.REQUEST) || 42 scope.equalsIgnoreCase(ScopeConstants.SESSION) || 43 scope.equalsIgnoreCase(ScopeConstants.APPLICATION)); 44 } 45 46 53 public static boolean isValidScope(int scope) { 54 55 return (scope >= ScopeConstants.PAGE_INT && 56 scope <= ScopeConstants.APPLICATION_INT); 57 } 58 59 66 public static int convertScope(String scope) { 67 68 if (scope.equalsIgnoreCase(ScopeConstants.PAGE)) { 69 return ScopeConstants.PAGE_INT; 70 } else if (scope.equalsIgnoreCase(ScopeConstants.REQUEST)) { 71 return ScopeConstants.REQUEST_INT; 72 } else if (scope.equalsIgnoreCase(ScopeConstants.SESSION)) { 73 return ScopeConstants.SESSION_INT; 74 } else if (scope.equalsIgnoreCase(ScopeConstants.APPLICATION)) { 75 return ScopeConstants.APPLICATION_INT; 76 } 77 78 throw new IllegalArgumentException ("Invalid Portal framework scope String"); 79 } 80 81 88 public static String convertScope(int scope) { 89 90 switch (scope) { 91 case ScopeConstants.PAGE_INT: 92 return ScopeConstants.PAGE; 93 case ScopeConstants.REQUEST_INT: 94 return ScopeConstants.REQUEST; 95 case ScopeConstants.SESSION_INT: 96 return ScopeConstants.SESSION; 97 case ScopeConstants.APPLICATION_INT: 98 return ScopeConstants.APPLICATION; 99 } 100 101 throw new IllegalArgumentException ("Invalid Portal framework scope int"); 102 } 103 104 111 public static boolean isPage(String scope) { 112 return scope.equalsIgnoreCase(ScopeConstants.PAGE); 113 } 114 115 122 public static boolean isRequest(String scope) { 123 return scope.equalsIgnoreCase(ScopeConstants.REQUEST); 124 } 125 126 133 public static boolean isSession(String scope) { 134 return scope.equalsIgnoreCase(ScopeConstants.SESSION); 135 } 136 137 144 public static boolean isApplication(String scope) { 145 return scope.equalsIgnoreCase(ScopeConstants.APPLICATION); 146 } 147 148 156 public static int convertToJ2EE(int scope) { 157 158 switch (scope) { 159 case ScopeConstants.PAGE_INT: 160 return PageContext.PAGE_SCOPE; 161 case ScopeConstants.REQUEST_INT: 162 return PageContext.REQUEST_SCOPE; 163 case ScopeConstants.SESSION_INT: 164 return PageContext.SESSION_SCOPE; 165 case ScopeConstants.APPLICATION_INT: 166 return PageContext.APPLICATION_SCOPE; 167 } 168 169 throw new IllegalArgumentException ("Invalid Portal framework scope int"); 170 } 171 172 181 public static String convertToJ2EE(String scope) { 182 183 if (scope.equalsIgnoreCase(ScopeConstants.PAGE)) { 184 return PageContext.PAGE; 185 } else if (scope.equalsIgnoreCase(ScopeConstants.REQUEST)) { 186 return PageContext.REQUEST; 187 } else if (scope.equalsIgnoreCase(ScopeConstants.SESSION)) { 188 return PageContext.SESSION; 189 } else if (scope.equalsIgnoreCase(ScopeConstants.APPLICATION)) { 190 return PageContext.APPLICATION; 191 } 192 193 throw new IllegalArgumentException ("Invalid Portal framework scope String"); 194 } 195 196 204 public static int convertFromJ2EE(int scope) { 205 206 switch (scope) { 207 case PageContext.PAGE_SCOPE: 208 return ScopeConstants.PAGE_INT; 209 case PageContext.REQUEST_SCOPE: 210 return ScopeConstants.REQUEST_INT; 211 case PageContext.SESSION_SCOPE: 212 return ScopeConstants.SESSION_INT; 213 case PageContext.APPLICATION_SCOPE: 214 return ScopeConstants.APPLICATION_INT; 215 } 216 217 throw new IllegalArgumentException ("Invalid Portal framework scope int"); 218 } 219 220 229 public static String convertFromJ2EE(String scope) { 230 231 if (scope.equalsIgnoreCase(PageContext.PAGE)) { 232 return ScopeConstants.PAGE; 233 } else if (scope.equalsIgnoreCase(PageContext.REQUEST)) { 234 return ScopeConstants.REQUEST; 235 } else if (scope.equalsIgnoreCase(PageContext.SESSION)) { 236 return ScopeConstants.SESSION; 237 } else if (scope.equalsIgnoreCase(PageContext.APPLICATION)) { 238 return ScopeConstants.APPLICATION; 239 } 240 241 throw new IllegalArgumentException ("Invalid Portal framework scope String"); 242 } 243 244 267 public static int compareScopes(String scope1, String scope2) { 268 int scope1Int = convertScope(scope1); 269 int scope2Int = convertScope(scope2); 270 271 return scope1Int - scope2Int; 272 } 273 } 274 | Popular Tags |