Java tutorial
package com.edm.utils; import java.util.List; import org.apache.commons.lang.StringUtils; import com.edm.app.auth.Auth; import com.edm.entity.Menu; import com.edm.utils.consts.BrowserMap; import com.edm.utils.consts.LangMap; import com.edm.utils.consts.OsMap; import com.edm.utils.consts.WeekMap; public class View { /** * LICENSE??. */ public boolean auth(String link) { if (!Auth.isAuth()) return true; // String robot = Auth.ROBOT; // String code = Auth.MAP.get(UrlMap.CODE.getAction()); // return Auth.link(link, robot, code); return true; } /** * ?. */ public String value(String value, String defaultValue) { if (StringUtils.isNotBlank(value)) return value; return defaultValue; } /** * ?. */ public String browser(int id) { return BrowserMap.getName(id); } /** * . */ public String lang(int id) { return LangMap.getName(id); } /** * . */ public String os(int id) { return OsMap.getName(id); } /** * cron. */ public String cron(String cron) { String cronStr = null; if (StringUtils.isNotBlank(cron)) { String[] crons = StringUtils.splitPreserveAllTokens(cron, " "); if (Asserts.empty(crons) || crons.length < 5) { return null; } String minute = crons[0]; String hour = crons[1]; String day = crons[2]; String week = crons[3]; String month = crons[4]; // month if (!day.equals("*")) { cronStr = "?"; if (day.equals("-1")) cronStr += "?"; else cronStr += day + ""; } // week if (!week.equals("*")) { cronStr = "?"; if (week.equals("1,2,3,4,5")) cronStr += ""; else if (week.equals("6,7")) cronStr += "?"; else if (StringUtils.splitPreserveAllTokens(week, ",").length == 1) cronStr += "" + WeekMap.week(week); } // day if (month.equals("*") && week.equals("*") && day.equals("*")) { cronStr = "?"; } if (StringUtils.isNotBlank(cronStr)) { if (hour.length() == 1) hour = "0" + hour; if (minute.length() == 1) minute = "0" + minute; cronStr += hour + ":" + minute; } } return cronStr; } /** * . */ public String active_cnd(String cnd) { if (cnd.equals("-1")) { return "?"; } else if (cnd.equals("1")) { return ""; } else if (cnd.equals("1week")) { return "?"; } else if (cnd.equals("1month")) { return "?"; } else if (cnd.equals("2month")) { return "?"; } else if (cnd.equals("3month")) { return "?"; } else { return ""; } } /** * ??????? </br> * ????0=1,2,3,4,5,6=????? * @param url * ??URL * @param funcAuthNum * ????,=1?=2?=3?=4?=5??6? * @return */ public boolean funcAuth(String url, Integer funcAuthNum) { if (StringUtils.isBlank(url) || funcAuthNum == null) return false; List<Menu> menuList = UserSession.getUser().getMenus(); if (menuList == null || menuList.size() == 0) return false; for (Menu m : menuList) { String menuUrl = m.getUrl(); if (url.equals(menuUrl)) { Integer[] funcAuths = m.getFuncAuths(); // 0 ? 0 ???funcAuthNumtrue if (funcAuths != null && funcAuths.length == 1 && funcAuths[0] == 0) { return true; } if (Asserts.hasAny(funcAuthNum, funcAuths)) { return true; } else { return false; } } } return false; } }