- * The Sone to delete
- */
- public void deleteSone(Sone sone) {
- if (!(sone.getIdentity() instanceof OwnIdentity)) {
- logger.log(Level.WARNING, "Tried to delete Sone of non-own identity: %s", sone);
- return;
- }
- synchronized (localSones) {
- if (!localSones.containsKey(sone.getId())) {
- logger.log(Level.WARNING, "Tried to delete non-local Sone: %s", sone);
- return;
- }
- localSones.remove(sone.getId());
- soneInserters.remove(sone).stop();
- }
- try {
- ((OwnIdentity) sone.getIdentity()).removeContext("Sone");
- ((OwnIdentity) sone.getIdentity()).removeProperty("Sone.LatestEdition");
- } catch (WebOfTrustException wote1) {
- logger.log(Level.WARNING, "Could not remove context and properties from Sone: " + sone, wote1);
- }
- try {
- configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
- } catch (ConfigurationException ce1) {
- logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
- }
- }
-
- /**
- * Loads and updates the given Sone from the configuration. If any error is
- * encountered, loading is aborted and the given Sone is not changed.
- *
- * @param sone
- * The Sone to load and update
- */
- public void loadSone(Sone sone) {
- if (!isLocalSone(sone)) {
- logger.log(Level.FINE, "Tried to load non-local Sone: %s", sone);
- return;
- }
-
- /* load Sone. */
- String sonePrefix = "Sone/" + sone.getId();
- Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
- if (soneTime == null) {
- logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
- return;
- }
- String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");
-
- /* load profile. */
- Profile profile = new Profile();
- profile.setFirstName(configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null));
- profile.setMiddleName(configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null));
- profile.setLastName(configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null));
- profile.setBirthDay(configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null));
- profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null));
- profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null));
-
- /* load profile fields. */
- while (true) {
- String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFields().size();
- String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null);
- if (fieldName == null) {
- break;
- }
- String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue("");
- profile.addField(fieldName).setValue(fieldValue);
- }
-
- /* load posts. */
- Set<Post> posts = new HashSet<Post>();
- while (true) {
- String postPrefix = sonePrefix + "/Posts/" + posts.size();
- String postId = configuration.getStringValue(postPrefix + "/ID").getValue(null);
- if (postId == null) {
- break;
- }
- String postRecipientId = configuration.getStringValue(postPrefix + "/Recipient").getValue(null);
- long postTime = configuration.getLongValue(postPrefix + "/Time").getValue((long) 0);
- String postText = configuration.getStringValue(postPrefix + "/Text").getValue(null);
- if ((postTime == 0) || (postText == null)) {
- logger.log(Level.WARNING, "Invalid post found, aborting load!");
- return;
- }
- Post post = getPost(postId).setSone(sone).setTime(postTime).setText(postText);
- if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- post.setRecipient(getSone(postRecipientId));
- }
- posts.add(post);
- }
-
- /* load replies. */
- Set<Reply> replies = new HashSet<Reply>();
- while (true) {
- String replyPrefix = sonePrefix + "/Replies/" + replies.size();
- String replyId = configuration.getStringValue(replyPrefix + "/ID").getValue(null);
- if (replyId == null) {
- break;
- }
- String postId = configuration.getStringValue(replyPrefix + "/Post/ID").getValue(null);
- long replyTime = configuration.getLongValue(replyPrefix + "/Time").getValue((long) 0);
- String replyText = configuration.getStringValue(replyPrefix + "/Text").getValue(null);
- if ((postId == null) || (replyTime == 0) || (replyText == null)) {
- logger.log(Level.WARNING, "Invalid reply found, aborting load!");