/** * Returns the localized message for the given key. * * @param key the key for the message * @param languageID the languageID of the localized message * @return the localized message for the given key. */ protected String getMessage(String key, String languageID) { I18nValidationResult validationResult = key2ValidationResults.get(key); if (validationResult != null) { return validationResult.getI18nValidationResultMessage().getText(languageID); } return null; }
@Override public ValidationResult validate(DataFieldType dataElement, StructFieldType structElement) { ScriptEngine jsEngine = getJavaScriptEngine(); Bindings bindings = jsEngine.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put(VAR_DATA_FIELD, dataElement); bindings.put(VAR_STRUCT_FIELD, structElement); try { // run script Object scriptResult = jsEngine.eval(script); // check result type // -> String: lookup in key2ValidationResults (its the key) // -> everything else: return null if (scriptResult instanceof String) { I18nValidationResult validationResult = key2ValidationResults.get((String) scriptResult); if (validationResult != null) { String message = validationResult.getI18nValidationResultMessage().getText(); return new ValidationResult(validationResult.getResultType(), message); } } return null; } catch (ScriptException e) { throw new RuntimeException(e); } }