use of org.eweb4j.mvc.config.bean.Uri in project eweb4j-framework by laiweiwei.
the class InterExecution method findAndExecuteInter.
/**
* 找
*
* @return
* @throws Exception
*/
public boolean findAndExecuteInter() throws Exception {
List<InterConfigBean> list = InterConfigBeanCache.getList();
// 按优先级从高到低排序
Collections.sort(list, new InterPriorityComparator());
final int listSize = list.size();
for (int index = 0; index < listSize; index++) {
InterConfigBean inter = list.get(index);
String _interType = inter.getType();
if (!interType.equals(_interType))
continue;
String uri = this.context.getUri();
if (uri.length() == 0)
uri = " ";
if (inter.getExcept().contains(uri))
continue;
String policy = inter.getPolicy();
boolean isOR = "or".equalsIgnoreCase(policy) ? true : false;
List<Uri> uris = inter.getUri();
final int size = uris.size();
// 默认不能处理
boolean canProcess = false;
for (int i = 0; i < size; i++) {
Uri u = uris.get(i);
String type = u.getType();
String value = u.getValue();
// 默认找到
boolean found = true;
if ("start".equalsIgnoreCase(type) && uri.startsWith(value))
// 以url开头
;
else if ("end".equalsIgnoreCase(type) && uri.endsWith(value))
// 以url结尾
;
else if ("contains".equalsIgnoreCase(type) && uri.contains(value))
// 包含url
;
else if ("all".equalsIgnoreCase(type) && uri.equals(value))
// 完全匹配url
;
else if ("regex".equalsIgnoreCase(type) && uri.matches(value))
// 正则匹配
;
else if ("actions".equalsIgnoreCase(type)) {
if (!findActionUriMapping())
found = false;
} else if ("!start".equalsIgnoreCase(type) && !uri.startsWith(value))
// 不以url开头
;
else if ("!end".equalsIgnoreCase(type) && !uri.endsWith(value))
// 不以url结尾
;
else if ("!contains".equalsIgnoreCase(type) && !uri.contains(value))
// 不包含url
;
else if ("!all".equalsIgnoreCase(type) && !uri.equals(value))
// 不完全匹配url
;
else if ("!regex".equalsIgnoreCase(type) && !uri.matches(value))
// 不正则匹配
;
else if ("!actions".equalsIgnoreCase(type)) {
if (ActionConfigBeanCache.containsKey(uri) || (ActionConfigBeanCache.getByMatches(uri, context.getHttpMethod())) != null)
found = false;
} else if ("*".equals(type)) {
// 所有都匹配
;
} else
found = false;
// 如果是 或者
if (isOR) {
// 如果找到一个规则符合,就可以执行了。
if (found) {
canProcess = true;
break;
}
} else {
// 如果是 并且
if (!found) {
//只要找到一个规则不符合,就退出,且不处理
canProcess = false;
break;
} else {
canProcess = true;
}
}
}
if (!canProcess)
continue;
this.doIntercept(inter);
if (this.error == null) {
// 如果拦截处理之后没有任何错误信息,进入下一个拦截器继续处理
continue;
} else {
// 否则显示错误信息, 并且退出方法
log.debug("do interceptor -> " + inter.getClazz() + " error -> " + error);
return true;
}
}
return false;
}
use of org.eweb4j.mvc.config.bean.Uri in project eweb4j-framework by laiweiwei.
the class MVCConfigBeanCreator method getInterBean.
public static InterConfigBean getInterBean() {
InterConfigBean icb = new InterConfigBean();
List<Uri> urls = new ArrayList<Uri>();
Uri url = new Uri();
urls.add(url);
icb.setUri(urls);
List<String> excepts = new ArrayList<String>();
excepts.add("");
icb.setExcept(excepts);
return icb;
}
use of org.eweb4j.mvc.config.bean.Uri in project eweb4j-framework by laiweiwei.
the class CheckConfigBean method checkMVCInterceptor.
public static String checkMVCInterceptor(InterConfigBean inter, String xmlFile) {
String error = null;
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
if ("true".equalsIgnoreCase(cb.getMvc().getOpen()) || "1".equals(cb.getMvc().getOpen())) {
StringBuilder sb = new StringBuilder();
if (!"".equals(inter.getClazz())) {
try {
if (Thread.currentThread().getContextClassLoader().loadClass(inter.getClazz()) == null) {
sb.append("当前您填写的( class=").append(inter.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
}
} catch (ClassNotFoundException e) {
sb.append("当前您填写的( class=").append(inter.getClazz()).append(" )是错误的!它必须是一个有效的类 ;\n");
}
}
if (inter.getType() == null)
inter.setType("");
if (!"".equals(inter.getType()) && !"before".equalsIgnoreCase(inter.getType()) && !"after".equalsIgnoreCase(inter.getType())) {
sb.append("当前您填写的:( type=").append(inter.getType()).append(" )是错误的!它只能填写为:before|after|留空 中的一种 ;").append("\n");
}
if (inter.getPolicy() != null && !"".equals(inter.getPolicy()) && !"and".equalsIgnoreCase(inter.getPolicy()) && !"or".equalsIgnoreCase(inter.getPolicy())) {
sb.append("当前您填写的:( policy=").append(inter.getPolicy()).append(" )是错误的!它只能填写为:and|or|留空 中的一种 ;").append("\n");
}
for (Uri url : inter.getUri()) {
if (url.getType() == null)
url.setType("");
if (!"start".equalsIgnoreCase(url.getType()) && !"end".equalsIgnoreCase(url.getType()) && !"contains".equalsIgnoreCase(url.getType()) && !"all".equalsIgnoreCase(url.getType()) && !"regex".equalsIgnoreCase(url.getType()) && !"!start".equalsIgnoreCase(url.getType()) && !"!end".equalsIgnoreCase(url.getType()) && !"!contains".equalsIgnoreCase(url.getType()) && !"!all".equalsIgnoreCase(url.getType()) && !"!regex".equalsIgnoreCase(url.getType()) && !"*".equals(url.getType()) && !"actions".equals(url.getType()) && !"!actions".equals(url.getType()) && !"".equals(url.getType())) {
sb.append("当前您填写的:( type=").append(url.getType()).append(" )是错误的!它只能填写为:start|end|contains|all|regex|!start|!end|!contains|!all|!regex|*|留空 中的一种 ;").append("\n");
}
}
if (!"".equals(sb.toString())) {
error = "\n<br /><b>" + xmlFile + ":[bean name=" + inter.getName() + "]</b>\n" + sb.toString();
}
}
return error;
}
Aggregations