/** * Get localized message by reference provided in the full format. * @param ref reference to message in the following format: {@code msg://message_pack/message_id} * @return localized message or input string itself if it doesn't begin with {@code msg://} */ public String loadString(String ref) { return loadString(null, ref); }
/** * Get localized message by reference provided in the full format. * @param ref reference to message in the following format: {@code msg://message_pack/message_id} * @return localized message or input string itself if it doesn't begin with {@code msg://} */ public String loadString(String ref, Locale locale) { return loadString(null, ref, locale); }
/** * Get localized message by reference provided in full or brief format. * @param messagesPack messages pack to use if the second parameter is in brief format * @param ref reference to message in the following format: * <ul> * <li>Full: {@code msg://message_pack/message_id} * <li>Brief: {@code msg://message_id}, in this case the first parameter is taken into account * <li>Message from a main messages pack: {@code mainMsg://message_id} * </ul> * @return localized message or input string itself if it doesn't begin with {@code msg://} or {@code mainMsg://} */ @Nullable public String loadString(@Nullable String messagesPack, @Nullable String ref) { return loadString(messagesPack, ref, null); }
protected String loadResourceString(String caption) { if (StringUtils.isEmpty(caption)) { return caption; } return getMessageTools().loadString(messagesPack, caption); }
public CustomConditionDescriptor(Element element, String messagesPack, String filterComponentName, MetaClass metaClass, String entityAlias) { super(element.attributeValue("name"), filterComponentName, metaClass, entityAlias); this.element = element; this.messagesPack = messagesPack; this.caption = element.attributeValue("caption"); if (this.caption != null) { MessageTools messageTools = AppBeans.get(MessageTools.NAME); this.locCaption = messageTools.loadString(messagesPack, this.caption); } inExpr = Boolean.valueOf(element.attributeValue("inExpr")); }
@Override public void validate(Object value) throws ValidationException { if (value == null || !pattern.matcher(((String) value)).matches()) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value != null ? value : "")); } } }
public CustomCondition(Element element, String messagesPack, String filterComponentName, com.haulmont.chile.core.model.MetaClass metaClass) { super(element, messagesPack, filterComponentName, metaClass); if (isBlank(caption)) { locCaption = element.attributeValue("locCaption"); } else { MessageTools messageTools = AppBeans.get(MessageTools.NAME); locCaption = messageTools.loadString(messagesPack, caption); } entityAlias = element.attributeValue("entityAlias"); Element joinElement = element.element("join"); if (joinElement != null) { this.join = joinElement.getText(); } else { //for backward compatibility this.join = element.attributeValue("join"); } }
protected AbstractCondition(Element element, String messagesPack, String filterComponentName, com.haulmont.chile.core.model.MetaClass metaClass) { this.messagesPack = messagesPack; this.filterComponentName = filterComponentName; name = element.attributeValue("name"); text = StringEscapeUtils.unescapeXml(element.getText()); this.metaClass = metaClass; if (text == null) text = ""; caption = element.attributeValue("caption"); MessageTools messageTools = AppBeans.get(MessageTools.class); locCaption = messageTools.loadString(messagesPack, caption); unary = Boolean.valueOf(element.attributeValue("unary")); inExpr = Boolean.valueOf(element.attributeValue("inExpr")); hidden = Boolean.valueOf(element.attributeValue("hidden")); required = Boolean.valueOf(element.attributeValue("required")); useUserTimeZone = Boolean.valueOf(element.attributeValue("useUserTimeZone")); entityParamWhere = element.attributeValue("paramWhere"); entityParamView = element.attributeValue("paramView"); width = Strings.isNullOrEmpty(element.attributeValue("width")) ? 1 : Integer.parseInt(element.attributeValue("width")); resolveParam(element); }
protected void assignDescription(SideMenu.MenuItem menuItem, MenuItem conf) { String description = conf.getDescription(); if (StringUtils.isNotEmpty(description)) { menuItem.setDescription(messageTools.loadString(description)); } }
@Override public void validate(Object value) throws ValidationException { if (!(value instanceof String)) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }
@Override public String getLocCaption() { if (Strings.isNullOrEmpty(caption)) { return getPropertyLocCaption(); } else { MessageTools messageTools = AppBeans.get(MessageTools.class); return messageTools.loadString(messagesPack, caption); } }
protected void assignDescription(AppMenu.MenuItem menuItem, MenuItem conf) { String description = conf.getDescription(); if (StringUtils.isNotEmpty(description)) { menuItem.setDescription(messageTools.loadString(description)); } }
@Override public String getLocCaption() { if (Strings.isNullOrEmpty(caption)) { Messages messages = AppBeans.get(Messages.class); return messages.getMainMessage("filter.ftsCondition.caption"); } else { MessageTools messageTools = AppBeans.get(MessageTools.class); return messageTools.loadString(messagesPack, caption); } }
protected String loadResourceString(String caption) { return messages.getTools().loadString(messages.getMainMessagePack(), caption); }
public PropertyConditionDescriptor(String name, @Nullable String caption, String messagesPack, String filterComponentName, MetaClass metaClass, String entityAlias) { super(name, filterComponentName, metaClass, entityAlias); this.caption = caption; this.messagesPack = messagesPack; Messages messages = AppBeans.get(Messages.NAME); if (!isBlank(caption)) { this.locCaption = messages.getTools().loadString(messagesPack, caption); } else { this.locCaption = FilterConditionUtils.getPropertyLocCaption(datasourceMetaClass, name); } }
protected String resolveParameter(String parameterName, Locale locale) { String parameterValue; String messageCode = removeCurlyBraces(parameterName); try { if (messageCode.startsWith("javax.validation.constraints") || messageCode.startsWith("org.hibernate.validator.constraints")) { parameterValue = messages.getMessage(DEFAULT_CONSTRAINTS_MESSAGE_PACK, messageCode, locale); // try to find tokens recursive parameterValue = interpolateMessage(parameterValue, locale); } else if (messageCode.startsWith(MessageTools.MARK) || messageCode.startsWith(MessageTools.MAIN_MARK)) { parameterValue = messages.getTools().loadString(messageCode, locale); // try to find tokens recursive parameterValue = interpolateMessage(parameterValue, locale); } else { parameterValue = parameterName; } } catch (UnsupportedOperationException e) { // return parameter itself parameterValue = parameterName; } return parameterValue; }
@Override public void validate(Object value) throws ValidationException { Boolean isValid = false; if (params == null) { params = new HashMap<>(); params.put("value", value); } else { params.put("value", value); } Scripting scripting = AppBeans.get(Scripting.NAME); if (innerScript) { isValid = scripting.evaluateGroovy(script, params); } else if (scriptPath != null) { isValid = scripting.runGroovyScript(scriptPath, params); } if (!isValid) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }
@Override public String getLocCaption() { if (isBlank(caption) && !isBlank(propertyPath)) { MessageTools messageTools = AppBeans.get(MessageTools.class); String propertyCaption = messageTools.getPropertyCaption(metaClass, propertyPath); if (!isBlank(propertyCaption)) { return propertyCaption + "." + locCaption; } } else if (isNotBlank(caption)) { MessageTools messageTools = AppBeans.get(MessageTools.class); return messageTools.loadString(messagesPack, caption); } MetaPropertyPath mpp = DynamicAttributesUtils.getMetaPropertyPath(metaClass, getCategoryAttributeId()); if (mpp != null) { return DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty()).getLocaleName(); } return super.getLocCaption(); } }
@Override public void validate(Object value) throws ValidationException { if (value == null) return; boolean result; if (value instanceof String) { try { Datatype datatype = Datatypes.getNN(java.sql.Date.class); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); datatype.parse((String) value, sessionSource.getLocale()); result = true; } catch (ParseException e) { result = false; } } else { result = value instanceof Date; } if (!result) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }
@Override public void validate(Object value) throws ValidationException { if (value == null) { return; } boolean result; if (value instanceof String) { try { Datatype<Double> datatype = Datatypes.getNN(Double.class); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); Double num = datatype.parse((String) value, sessionSource.getLocale()); result = checkDoubleOnPositive(num); } catch (ParseException e) { result = false; } } else { result = (value instanceof Double && checkDoubleOnPositive((Double) value)) || (value instanceof BigDecimal && checkBigDecimalOnPositive((BigDecimal) value)); } if (!result) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }