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;
}
}
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);
}
}
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();
}
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;
}
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();
}
Aggregations