📄 modelscreencondition.java
字号:
// run hasPermission if (security.hasPermission(permission, userLogin)) { return true; } } } return false; } } public static class IfValidateMethod extends ScreenCondition { protected FlexibleMapAccessor fieldAcsr; protected FlexibleStringExpander methodExdr; protected FlexibleStringExpander classExdr; public IfValidateMethod(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.fieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("field-name")); this.methodExdr = new FlexibleStringExpander(condElement.getAttribute("method")); this.classExdr = new FlexibleStringExpander(condElement.getAttribute("class")); } public boolean eval(Map context) { String methodName = this.methodExdr.expandString(context); String className = this.classExdr.expandString(context); Object fieldVal = this.fieldAcsr.get(context); String fieldString = null; if (fieldVal != null) { try { fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, null); } catch (GeneralException e) { Debug.logError(e, "Could not convert object to String, using empty String", module); } } // always use an empty string by default if (fieldString == null) fieldString = ""; Class[] paramTypes = new Class[] {String.class}; Object[] params = new Object[] {fieldString}; Class valClass; try { valClass = ObjectType.loadClass(className); } catch (ClassNotFoundException cnfe) { Debug.logError("Could not find validation class: " + className, module); return false; } Method valMethod; try { valMethod = valClass.getMethod(methodName, paramTypes); } catch (NoSuchMethodException cnfe) { Debug.logError("Could not find validation method: " + methodName + " of class " + className, module); return false; } Boolean resultBool = Boolean.FALSE; try { resultBool = (Boolean) valMethod.invoke(null, params); } catch (Exception e) { Debug.logError(e, "Error in IfValidationMethod " + methodName + " of class " + className + ", defaulting to false ", module); } return resultBool.booleanValue(); } } public static class IfCompare extends ScreenCondition { protected FlexibleMapAccessor fieldAcsr; protected FlexibleStringExpander valueExdr; protected String operator; protected String type; protected FlexibleStringExpander formatExdr; public IfCompare(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.fieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("field-name")); this.valueExdr = new FlexibleStringExpander(condElement.getAttribute("value")); this.operator = condElement.getAttribute("operator"); this.type = condElement.getAttribute("type"); this.formatExdr = new FlexibleStringExpander(condElement.getAttribute("format")); } public boolean eval(Map context) { String value = this.valueExdr.expandString(context); String format = this.formatExdr.expandString(context); Object fieldVal = this.fieldAcsr.get(context); // always use an empty string by default if (fieldVal == null) { fieldVal = ""; } List messages = new LinkedList(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, null); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and value [" + value + "] with operator [" + operator + "] and type [" + type + "]: "); StringBuffer fullString = new StringBuffer(); Iterator miter = messages.iterator(); while (miter.hasNext()) { fullString.append((String) miter.next()); } Debug.logWarning(fullString.toString(), module); throw new IllegalArgumentException(fullString.toString()); } return resultBool.booleanValue(); } } public static class IfCompareField extends ScreenCondition { protected FlexibleMapAccessor fieldAcsr; protected FlexibleMapAccessor toFieldAcsr; protected String operator; protected String type; protected FlexibleStringExpander formatExdr; public IfCompareField(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.fieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("field-name")); this.toFieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("to-field-name")); this.operator = condElement.getAttribute("operator"); this.type = condElement.getAttribute("type"); this.formatExdr = new FlexibleStringExpander(condElement.getAttribute("format")); } public boolean eval(Map context) { String format = this.formatExdr.expandString(context); Object fieldVal = this.fieldAcsr.get(context); Object toFieldVal = this.toFieldAcsr.get(context); // always use an empty string by default if (fieldVal == null) { fieldVal = ""; } List messages = new LinkedList(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, toFieldVal, operator, type, format, messages, null, null); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare-field between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and to-field [" + toFieldAcsr.toString() + "] with value [" + toFieldVal + "] with operator [" + operator + "] and type [" + type + "]: "); StringBuffer fullString = new StringBuffer(); Iterator miter = messages.iterator(); while (miter.hasNext()) { fullString.append((String) miter.next()); } Debug.logWarning(fullString.toString(), module); throw new IllegalArgumentException(fullString.toString()); } return resultBool.booleanValue(); } } public static class IfRegexp extends ScreenCondition { static PatternMatcher matcher = new Perl5Matcher(); static PatternCompiler compiler = new Perl5Compiler(); protected FlexibleMapAccessor fieldAcsr; protected FlexibleStringExpander exprExdr; public IfRegexp(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.fieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("field-name")); this.exprExdr = new FlexibleStringExpander(condElement.getAttribute("expr")); } public boolean eval(Map context) { Object fieldVal = this.fieldAcsr.get(context); String expr = this.exprExdr.expandString(context); Pattern pattern = null; try { pattern = compiler.compile(expr); } catch (MalformedPatternException e) { String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } String fieldString = null; try { fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, null); } catch (GeneralException e) { Debug.logError(e, "Could not convert object to String, using empty String", module); } // always use an empty string by default if (fieldString == null) fieldString = ""; return matcher.matches(fieldString, pattern); } } public static class IfEmpty extends ScreenCondition { protected FlexibleMapAccessor fieldAcsr; public IfEmpty(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.fieldAcsr = new FlexibleMapAccessor(condElement.getAttribute("field-name")); } public boolean eval(Map context) { Object fieldVal = this.fieldAcsr.get(context); return ObjectType.isEmpty(fieldVal); } } public static class IfEntityPermission extends ScreenCondition { protected EntityPermissionChecker permissionChecker; public IfEntityPermission(ModelScreen modelScreen, Element condElement) { super (modelScreen, condElement); this.permissionChecker = new EntityPermissionChecker(condElement); } public boolean eval(Map context) { boolean passed = permissionChecker.runPermissionCheck(context); return passed; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -