Search in sources :

Example 1 with Registry

use of org.simpleframework.xml.convert.Registry in project syncany by syncany.

the class ConfigTO method save.

public void save(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass()));
        new Persister(strategy).write(this, file);
    } catch (Exception e) {
        throw new ConfigException("Cannot write config to file " + file, e);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 2 with Registry

use of org.simpleframework.xml.convert.Registry in project syncany by syncany.

the class ConfigTO method load.

public static ConfigTO load(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter());
        return new Persister(strategy).read(ConfigTO.class, file);
    } catch (ClassNotFoundException ex) {
        // Ugly hack to catch common case of non-existing plugin
        String message = ex.getMessage();
        if (!message.startsWith("org.syncany.plugins.")) {
            // Apparently there are other ClassNotFoundExceptions possible.
            throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
        }
        message = message.replaceFirst("org.syncany.plugins.", "");
        message = message.replaceAll("\\..*", "");
        throw new ConfigException("Is the " + message + " plugin installed?");
    } catch (Exception ex) {
        throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Aggregations

Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Persister (org.simpleframework.xml.core.Persister)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 ConfigException (org.syncany.config.ConfigException)2 SaltedSecretKeyConverter (org.syncany.crypto.SaltedSecretKeyConverter)2 EncryptedTransferSettingsConverter (org.syncany.plugins.transfer.EncryptedTransferSettingsConverter)2