@Override public List<PluginProperty> getDefaultConfiguration() { PluginProperty width = new PluginProperty(WIDTH_PROPERTY, INT, "100"); PluginProperty height = new PluginProperty(HEIGHT_PROPERTY, INT, "50"); PluginProperty length = new PluginProperty(LENGTH_PROPERTY, INT, "4"); PluginProperty possibleSymbols = new PluginProperty(POSSIBLE_SYMBOLS_PROPERTY, STRING, "0123456789"); return Arrays.asList(width, height, length, possibleSymbols); }
/** * {@inheritDoc} */ @Override public List<PluginProperty> getConfiguration() { PluginProperty orderProperty = new PluginProperty(ORDER_PROPERTY, PluginProperty.Type.INT, String.valueOf(order)); orderProperty.setHint(ORDER_HINT); return Arrays.asList(orderProperty); }
/** * {@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<>(); }
public static PluginProperty getDefaultPluginConfigurationProperty() { PluginProperty property = new PluginProperty("Property", PluginProperty.Type.BOOLEAN, "true"); PluginConfiguration configuration = new PluginConfiguration("Default name", true, Arrays.asList(property)); property.setPluginConfiguration(configuration); persist(configuration); return property; }
/** * {@inheritDoc} */ @Override public void updateProperties(List<PluginProperty> properties) { for (PluginProperty property: properties) { PluginProperty persistedProperty = (PluginProperty) session().load(property.getClass(), property.getId()); persistedProperty.setValue(property.getValue()); session().saveOrUpdate(persistedProperty); } session().flush(); } }
/** * 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; }
/** * {@inheritDoc} */ @Override public void saveOrUpdate(PluginConfiguration entity) { for (PluginProperty property: entity.getProperties()) { property.setPluginConfiguration(entity); } super.saveOrUpdate(entity); }
for (PluginProperty property : properties) { try { switch (property.getName()) { case WIDTH_PROPERTY: width = Integer.valueOf(property.getValue()); break; case HEIGHT_PROPERTY: height = Integer.valueOf(property.getValue()); break; case LENGTH_PROPERTY: length = Integer.valueOf(property.getValue()); break; case POSSIBLE_SYMBOLS_PROPERTY: possibleSymbols = property.getValue(); break; LOGGER.error(property.getValue() + " is not valid value for property " + property.getName(), ex);
/** * {@inheritDoc} */ @Override public List<PluginProperty> getDefaultConfiguration() { PluginProperty orderProperty = new PluginProperty(ORDER_PROPERTY, PluginProperty.Type.INT, String.valueOf(DEFAULT_ORDER_VALUE)); orderProperty.setHint(ORDER_HINT); return Arrays.asList(orderProperty); }
private void saveNewPluginConfiguration(PluginConfiguration newPluginConfiguration) { List<PluginProperty> properties = newPluginConfiguration.getProperties(); for (PluginProperty property : properties) { property.setPluginConfiguration(newPluginConfiguration); } this.getDao().updateProperties(newPluginConfiguration.getProperties()); }
@Override public List<PluginProperty> getDefaultConfiguration() { PluginProperty url = new PluginProperty(URL_PROPERTY, STRING, "http://localhost:8080"); PluginProperty login = new PluginProperty(LOGIN_PROPERTY, STRING, "user"); PluginProperty password = new PluginProperty(PASSWORD_PROPERTY, STRING, "1234"); return Arrays.asList(url, login, password); }
@Override public List<PluginProperty> getDefaultConfiguration() { PluginProperty url = new PluginProperty("URL", STRING, "http://localhost:1234"); return Arrays.asList(url); }