/** * {@inheritDoc} */ @Override protected Map<PluginProperty, String> applyConfiguration(List<PluginProperty> properties) throws PluginConfigurationException { if (properties.size() == 1 && ORDER_PROPERTY.equalsIgnoreCase(properties.get(0).getName())) { order = properties.get(0).getValue() == null ? DEFAULT_ORDER_VALUE : Integer.parseInt(properties.get(0).getValue()); properties.get(0).setHint(ORDER_HINT); return new HashMap<>(); } else { throw new PluginConfigurationException( "Can't apply configuration: incorrect parameters count or order not found"); } }
@Override protected Map<PluginProperty, String> applyConfiguration(List<PluginProperty> properties) throws PluginConfigurationException { String url = null; String login = null; String password = null; for (PluginProperty property : properties) { if (URL_PROPERTY.equalsIgnoreCase(property.getName())) { url = property.getValue() == null ? null : property.getValue().trim(); } else if (LOGIN_PROPERTY.equalsIgnoreCase(property.getName())) { login = property.getValue() == null ? null : property.getValue().trim(); } else if (PASSWORD_PROPERTY.equalsIgnoreCase(property.getName())) { password = property.getValue(); } } if (url == null || url.isEmpty()) { // this should be returned as a map, but this mechanism should be implemented in the plugin API first throw new PluginConfigurationException("Can't apply configuration: Url should not be null."); } else if (!validateUrl(url)) { throw new PluginConfigurationException("Can't apply configuration: Incorrect format for Url value."); } service = new PoulpeAuthService(url, login, password); pluginProperties = properties; return new HashMap<>(); }
/** * Translate labels for specified plugin into language which selected by current user as forum language. * * @param properties list of properties to translate * @param plugin plugin with have specified properties * * @return map of properties translation depending from name */ private Map<String, String> translatePropertiesLabels(List<PluginProperty> properties, Plugin plugin) { Map<String, String> labels = new HashMap<>(); Locale locale = userService.getCurrentUser().getLanguage().getLocale(); for (PluginProperty property : properties) { String translation = plugin.translateLabel(property.getName(), locale); labels.put(property.getName(), translation); if (property.getHint() != null) { String hintTranslation = plugin.translateLabel(property.getHint(), locale); labels.put(property.getHint(), hintTranslation); } } return labels; }