Search in sources :

Example 86 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ApplicationLink method shortenLink.

private String shortenLink(String applicationLink) {
    if (!LINK_PATTERN.matcher(applicationLink).matches()) {
        throw new IllegalArgumentException("Invalid link provided, must start with syncany:// and match link pattern.");
    }
    try {
        logger.log(Level.INFO, "Shortining link " + applicationLink + " via " + LINK_SHORT_API_URL_ADD + " ...");
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("l", applicationLink));
        HttpPost postMethod = new HttpPost(LINK_SHORT_API_URL_ADD);
        postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = createHttpClient().execute(postMethod);
        ApplicationLinkShortenerResponse shortenerResponse = new Persister().read(ApplicationLinkShortenerResponse.class, httpResponse.getEntity().getContent());
        return String.format(LINK_SHORT_URL_FORMAT, shortenerResponse.getShortLinkId());
    } catch (Exception e) {
        logger.log(Level.WARNING, "Cannot shorten URL. Using long URL.", e);
        return applicationLink;
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Example 87 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ConnectOperation method verifyRepoFile.

private void verifyRepoFile(String repoFileStr) throws StorageException {
    try {
        Serializer serializer = new Persister();
        serializer.read(RepoTO.class, repoFileStr);
    } catch (Exception e) {
        throw new StorageException("Repo file corrupt.", e);
    }
}
Also used : Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) CipherException(org.syncany.crypto.CipherException) Serializer(org.simpleframework.xml.Serializer)

Example 88 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class PluginOperation method getRemotePluginInfoList.

private List<PluginInfo> getRemotePluginInfoList() throws Exception {
    String remoteListStr = getRemoteListStr(null);
    PluginListResponse pluginListResponse = new Persister().read(PluginListResponse.class, remoteListStr);
    return pluginListResponse.getPlugins();
}
Also used : Persister(org.simpleframework.xml.core.Persister)

Example 89 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class TestConfigUtil method createTestLocalConfig.

public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception {
    File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection));
    tempLocalDir.mkdirs();
    RepoTO repoTO = createRepoTO();
    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20));
    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);
    LocalTransferSettings localConnection = (LocalTransferSettings) connection;
    // Create connection TO
    Map<String, String> localConnectionSettings = new HashMap<String, String>();
    localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath());
    configTO.setTransferSettings(connection);
    // Create
    Config config = new Config(tempLocalDir, configTO, repoTO);
    config.setConnection(connection);
    config.getAppDir().mkdirs();
    config.getCacheDir().mkdirs();
    config.getDatabaseDir().mkdirs();
    config.getLogDir().mkdirs();
    config.getStateDir().mkdirs();
    // Write to config folder (required for some tests)
    new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG));
    new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO));
    return config;
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) HashMap(java.util.HashMap) UserConfig(org.syncany.config.UserConfig) Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) Persister(org.simpleframework.xml.core.Persister) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 90 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class WatchRunner method start.

public void start() {
    watchThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                logger.log(Level.INFO, "STARTING watch at" + config.getLocalDir());
                watchOperationResult = null;
                // Write port to portFile
                File portFile = config.getPortFile();
                portFile.createNewFile();
                portFile.deleteOnExit();
                new Persister().write(portTO, portFile);
                // Start operation (blocks!)
                watchOperationResult = watchOperation.execute();
                logger.log(Level.INFO, "STOPPED watch at " + config.getLocalDir());
            } catch (Exception e) {
                logger.log(Level.SEVERE, "ERROR while running watch at " + config.getLocalDir(), e);
            }
        }
    }, "WR/" + config.getLocalDir().getName());
    watchThread.start();
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File) ConfigException(org.syncany.config.ConfigException)

Aggregations

Persister (org.simpleframework.xml.core.Persister)177 Serializer (org.simpleframework.xml.Serializer)141 StringWriter (java.io.StringWriter)74 Writer (java.io.Writer)62 Registry (org.simpleframework.xml.convert.Registry)23 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)23 Strategy (org.simpleframework.xml.strategy.Strategy)23 AnnotationStrategy (org.simpleframework.xml.convert.AnnotationStrategy)20 File (java.io.File)18 Test (org.junit.Test)14 IOException (java.io.IOException)12 StorageException (org.syncany.plugins.transfer.StorageException)8 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)6 ConfigTO (org.syncany.config.to.ConfigTO)5 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4