2 * FreenetSone - Core.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.core;
20 import java.net.MalformedURLException;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
30 import java.util.UUID;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
34 import net.pterodactylus.sone.core.Options.DefaultOption;
35 import net.pterodactylus.sone.core.Options.Option;
36 import net.pterodactylus.sone.core.Options.OptionWatcher;
37 import net.pterodactylus.sone.core.SoneException.Type;
38 import net.pterodactylus.sone.data.Post;
39 import net.pterodactylus.sone.data.Profile;
40 import net.pterodactylus.sone.data.Reply;
41 import net.pterodactylus.sone.data.Sone;
42 import net.pterodactylus.util.config.Configuration;
43 import net.pterodactylus.util.config.ConfigurationException;
44 import net.pterodactylus.util.filter.Filter;
45 import net.pterodactylus.util.filter.Filters;
46 import net.pterodactylus.util.logging.Logging;
47 import net.pterodactylus.util.service.AbstractService;
48 import freenet.client.FetchResult;
49 import freenet.keys.FreenetURI;
54 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
56 public class Core extends AbstractService {
59 * Enumeration for the possible states of a {@link Sone}.
61 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
63 public enum SoneStatus {
65 /** The Sone is unknown, i.e. not yet downloaded. */
68 /** The Sone is idle, i.e. not being downloaded or inserted. */
71 /** The Sone is currently being inserted. */
74 /** The Sone is currently being downloaded. */
79 private static final Logger logger = Logging.getLogger(Core.class);
82 private final Options options = new Options();
84 /** The configuration. */
85 private Configuration configuration;
87 /** Interface to freenet. */
88 private FreenetInterface freenetInterface;
90 /** The Sone downloader. */
91 private SoneDownloader soneDownloader;
93 /** The local Sones. */
94 private final Set<Sone> localSones = new HashSet<Sone>();
96 /** Sone inserters. */
97 private final Map<Sone, SoneInserter> soneInserters = new HashMap<Sone, SoneInserter>();
99 /** The Sones’ statuses. */
100 private final Map<Sone, SoneStatus> soneStatuses = Collections.synchronizedMap(new HashMap<Sone, SoneStatus>());
102 /* various caches follow here. */
104 /** Cache for all known Sones. */
105 private final Map<String, Sone> soneCache = new HashMap<String, Sone>();
107 /** Cache for all known posts. */
108 private final Map<String, Post> postCache = new HashMap<String, Post>();
110 /** Cache for all known replies. */
111 private final Map<String, Reply> replyCache = new HashMap<String, Reply>();
114 * Creates a new core.
117 super("Sone Core", false);
125 * Returns the options of the Sone plugin.
127 * @return The options of the Sone plugin
129 public Options getOptions() {
134 * Sets the configuration of the core.
136 * @param configuration
137 * The configuration of the core
138 * @return This core (for method chaining)
140 public Core configuration(Configuration configuration) {
141 this.configuration = configuration;
146 * Sets the Freenet interface to use.
148 * @param freenetInterface
149 * The Freenet interface to use
150 * @return This core (for method chaining)
152 public Core freenetInterface(FreenetInterface freenetInterface) {
153 this.freenetInterface = freenetInterface;
154 soneDownloader = new SoneDownloader(this, freenetInterface);
155 soneDownloader.start();
160 * Returns the local Sones.
162 * @return The local Sones
164 public Set<Sone> getSones() {
165 return Collections.unmodifiableSet(localSones);
169 * Returns the Sone with the given ID, or an empty Sone that has been
170 * initialized with the given ID.
176 public Sone getSone(String soneId) {
177 if (!soneCache.containsKey(soneId)) {
178 Sone sone = new Sone(soneId);
179 soneCache.put(soneId, sone);
180 setSoneStatus(sone, SoneStatus.unknown);
182 return soneCache.get(soneId);
186 * Returns all known sones.
188 * @return All known sones
190 public Collection<Sone> getKnownSones() {
191 return soneCache.values();
195 * Gets all known Sones that are not local Sones.
197 * @return All remote Sones
199 public Collection<Sone> getRemoteSones() {
200 return Filters.filteredCollection(getKnownSones(), new Filter<Sone>() {
203 @SuppressWarnings("synthetic-access")
204 public boolean filterObject(Sone object) {
205 return !localSones.contains(object);
211 * Returns the status of the given Sone.
214 * The Sone to get the status for
215 * @return The status of the Sone
217 public SoneStatus getSoneStatus(Sone sone) {
218 return soneStatuses.get(sone);
222 * Sets the status of the Sone.
225 * The Sone to set the status for
227 * The status of the Sone
229 public void setSoneStatus(Sone sone, SoneStatus soneStatus) {
230 soneStatuses.put(sone, soneStatus);
234 * Creates a new post and adds it to the given Sone.
237 * The sone that creates the post
239 * The text of the post
240 * @return The created post
242 public Post createPost(Sone sone, String text) {
243 return createPost(sone, System.currentTimeMillis(), text);
247 * Creates a new post and adds it to the given Sone.
250 * The Sone that creates the post
252 * The time of the post
254 * The text of the post
255 * @return The created post
257 public Post createPost(Sone sone, long time, String text) {
258 Post post = getPost(UUID.randomUUID().toString()).setSone(sone).setTime(time).setText(text);
267 * The Sone that posts the reply
269 * The post the reply refers to
271 * The text of the reply
272 * @return The created reply
274 public Reply createReply(Sone sone, Post post, String text) {
275 return createReply(sone, post, System.currentTimeMillis(), text);
282 * The Sone that posts the reply
284 * The post the reply refers to
286 * The time of the post
288 * The text of the reply
289 * @return The created reply
291 public Reply createReply(Sone sone, Post post, long time, String text) {
292 Reply reply = getReply(UUID.randomUUID().toString()).setSone(sone).setPost(post).setTime(time).setText(text);
293 sone.addReply(reply);
302 * Adds a Sone to watch for updates. The Sone needs to be completely
306 * The Sone to watch for updates
308 public void addSone(Sone sone) {
309 soneCache.put(sone.getId(), sone);
310 if (!localSones.contains(sone)) {
311 soneDownloader.addSone(sone);
316 * Adds the given Sone.
321 public void addLocalSone(Sone sone) {
322 if (localSones.add(sone)) {
323 setSoneStatus(sone, SoneStatus.idle);
324 SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone);
325 soneInserter.start();
326 soneInserters.put(sone, soneInserter);
331 * Creates a new Sone at a random location.
334 * The name of the Sone
335 * @return The created Sone
336 * @throws SoneException
337 * if a Sone error occurs
339 public Sone createSone(String name) throws SoneException {
340 return createSone(name, "Sone", null, null);
344 * Creates a new Sone at the given location. If one of {@code requestUri} or
345 * {@code insertUrI} is {@code null}, the Sone is created at a random
349 * The name of the Sone
350 * @param documentName
351 * The document name in the SSK
353 * The request URI of the Sone, or {@link NullPointerException}
354 * to create a Sone at a random location
356 * The insert URI of the Sone, or {@code null} to create a Sone
357 * at a random location
358 * @return The created Sone
359 * @throws SoneException
360 * if a Sone error occurs
362 public Sone createSone(String name, String documentName, String requestUri, String insertUri) throws SoneException {
363 if ((name == null) || (name.trim().length() == 0)) {
364 throw new SoneException(Type.INVALID_SONE_NAME);
366 String finalRequestUri;
367 String finalInsertUri;
368 if ((requestUri == null) || (insertUri == null)) {
369 String[] keyPair = freenetInterface.generateKeyPair();
370 finalRequestUri = keyPair[0];
371 finalInsertUri = keyPair[1];
373 finalRequestUri = requestUri;
374 finalInsertUri = insertUri;
378 logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, finalRequestUri, finalInsertUri });
379 sone = getSone(UUID.randomUUID().toString()).setName(name).setRequestUri(new FreenetURI(finalRequestUri).setKeyType("USK").setDocName(documentName)).setInsertUri(new FreenetURI(finalInsertUri).setKeyType("USK").setDocName(documentName));
380 sone.setProfile(new Profile());
381 /* set modification counter to 1 so it is inserted immediately. */
382 sone.setModificationCounter(1);
384 } catch (MalformedURLException mue1) {
385 throw new SoneException(Type.INVALID_URI);
391 * Loads the Sone from the given request URI. The fetching of the data is
392 * performed in a new thread so this method returns immediately.
395 * The request URI to load the Sone from
397 public void loadSone(final String requestUri) {
398 loadSone(requestUri, null);
402 * Loads the Sone from the given request URI. The fetching of the data is
403 * performed in a new thread so this method returns immediately. If
404 * {@code insertUri} is not {@code null} the loaded Sone is converted into a
405 * local Sone and available using as any other local Sone.
408 * The request URI to load the Sone from
410 * The insert URI of the Sone
412 public void loadSone(final String requestUri, final String insertUri) {
413 new Thread(new Runnable() {
416 @SuppressWarnings("synthetic-access")
419 FreenetURI realRequestUri = new FreenetURI(requestUri).setMetaString(new String[] { "sone.xml" });
420 FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri);
421 if (fetchResult == null) {
424 Sone parsedSone = soneDownloader.parseSone(null, fetchResult, realRequestUri);
425 if (parsedSone != null) {
426 if (insertUri != null) {
427 parsedSone.setInsertUri(new FreenetURI(insertUri));
428 addLocalSone(parsedSone);
433 } catch (MalformedURLException mue1) {
434 logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1);
437 }, "Sone Downloader").start();
441 * Loads and updates the given Sone.
446 public void loadSone(final Sone sone) {
447 new Thread(new Runnable() {
450 @SuppressWarnings("synthetic-access")
452 FreenetURI realRequestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" });
453 setSoneStatus(sone, SoneStatus.downloading);
455 FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri);
456 if (fetchResult == null) {
457 /* TODO - mark Sone as bad. */
460 Sone parsedSone = soneDownloader.parseSone(sone, fetchResult, realRequestUri);
461 if (parsedSone != null) {
465 setSoneStatus(sone, (sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
468 }, "Sone Downloader").start();
472 * Deletes the given Sone from this plugin instance.
477 public void deleteSone(Sone sone) {
478 SoneInserter soneInserter = soneInserters.remove(sone);
480 localSones.remove(sone);
484 * Returns the post with the given ID. If no post exists yet with the given
485 * ID, a new post is returned.
491 public Post getPost(String postId) {
492 if (!postCache.containsKey(postId)) {
493 postCache.put(postId, new Post(postId));
495 return postCache.get(postId);
499 * Returns the reply with the given ID. If no reply exists yet with the
500 * given ID, a new reply is returned.
503 * The ID of the reply
506 public Reply getReply(String replyId) {
507 if (!replyCache.containsKey(replyId)) {
508 replyCache.put(replyId, new Reply(replyId));
510 return replyCache.get(replyId);
514 * Gets all replies to the given post, sorted by date, oldest first.
517 * The post the replies refer to
518 * @return The sorted list of replies for the post
520 public List<Reply> getReplies(Post post) {
521 List<Reply> replies = new ArrayList<Reply>();
522 for (Reply reply : replyCache.values()) {
523 if (reply.getPost().equals(post)) {
527 Collections.sort(replies, new Comparator<Reply>() {
533 public int compare(Reply leftReply, Reply rightReply) {
534 return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, leftReply.getTime() - rightReply.getTime()));
541 * Gets all Sones that like the given post.
544 * The post to check for
545 * @return All Sones that like the post
547 public Set<Sone> getLikes(final Post post) {
548 return Filters.filteredSet(getSones(), new Filter<Sone>() {
551 public boolean filterObject(Sone sone) {
552 return sone.isLikedPostId(post.getId());
558 * Gets all Sones that like the given reply.
561 * The reply to check for
562 * @return All Sones that like the reply
564 public Set<Sone> getLikes(final Reply reply) {
565 return Filters.filteredSet(getSones(), new Filter<Sone>() {
568 public boolean filterObject(Sone sone) {
569 return sone.isLikedReplyId(reply.getId());
575 * Deletes the given reply. It is removed from its Sone and from the reply
579 * The reply to remove
581 public void deleteReply(Reply reply) {
582 reply.getSone().removeReply(reply);
583 replyCache.remove(reply.getId());
594 protected void serviceStart() {
602 protected void serviceStop() {
603 soneDownloader.stop();
604 /* stop all Sone inserters. */
605 for (SoneInserter soneInserter : soneInserters.values()) {
616 * Loads the configuration.
618 private void loadConfiguration() {
619 logger.entering(Core.class.getName(), "loadConfiguration()");
621 options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new OptionWatcher<Integer>() {
624 public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
625 SoneInserter.setInsertionDelay(newValue);
628 })).set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
630 /* parse local Sones. */
631 logger.log(Level.INFO, "Loading Sones…");
634 String sonePrefix = "Sone/Sone." + soneId++;
635 String id = configuration.getStringValue(sonePrefix + "/ID").getValue(null);
639 String name = configuration.getStringValue(sonePrefix + "/Name").getValue(null);
640 long time = configuration.getLongValue(sonePrefix + "/Time").getValue((long) 0);
641 String insertUri = configuration.getStringValue(sonePrefix + "/InsertURI").getValue(null);
642 String requestUri = configuration.getStringValue(sonePrefix + "/RequestURI").getValue(null);
643 long modificationCounter = configuration.getLongValue(sonePrefix + "/ModificationCounter").getValue((long) 0);
644 String firstName = configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null);
645 String middleName = configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null);
646 String lastName = configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null);
647 Integer birthDay = configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null);
648 Integer birthMonth = configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null);
649 Integer birthYear = configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null);
651 Profile profile = new Profile();
652 profile.setFirstName(firstName);
653 profile.setMiddleName(middleName);
654 profile.setLastName(lastName);
655 profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
656 Sone sone = getSone(id).setName(name).setTime(time).setRequestUri(new FreenetURI(requestUri)).setInsertUri(new FreenetURI(insertUri));
657 sone.setProfile(profile);
660 String postPrefix = sonePrefix + "/Post." + postId++;
661 id = configuration.getStringValue(postPrefix + "/ID").getValue(null);
665 time = configuration.getLongValue(postPrefix + "/Time").getValue((long) 0);
666 String text = configuration.getStringValue(postPrefix + "/Text").getValue(null);
667 Post post = getPost(id).setSone(sone).setTime(time).setText(text);
670 int replyCounter = 0;
672 String replyPrefix = sonePrefix + "/Reply." + replyCounter++;
673 String replyId = configuration.getStringValue(replyPrefix + "/ID").getValue(null);
674 if (replyId == null) {
677 Post replyPost = getPost(configuration.getStringValue(replyPrefix + "/Post").getValue(null));
678 long replyTime = configuration.getLongValue(replyPrefix + "/Time").getValue(null);
679 String replyText = configuration.getStringValue(replyPrefix + "/Text").getValue(null);
680 Reply reply = getReply(replyId).setSone(sone).setPost(replyPost).setTime(replyTime).setText(replyText);
681 sone.addReply(reply);
685 int friendCounter = 0;
687 String friendPrefix = sonePrefix + "/Friend." + friendCounter++;
688 String friendId = configuration.getStringValue(friendPrefix + "/ID").getValue(null);
689 if (friendId == null) {
692 Sone friendSone = getSone(friendId);
693 String friendKey = configuration.getStringValue(friendPrefix + "/Key").getValue(null);
694 String friendName = configuration.getStringValue(friendPrefix + "/Name").getValue(null);
695 friendSone.setRequestUri(new FreenetURI(friendKey)).setName(friendName);
696 sone.addFriend(friendSone);
699 /* load blocked Sone IDs. */
700 int blockedSoneCounter = 0;
702 String blockedSonePrefix = sonePrefix + "/BlockedSone." + blockedSoneCounter++;
703 String blockedSoneId = configuration.getStringValue(blockedSonePrefix + "/ID").getValue(null);
704 if (blockedSoneId == null) {
707 sone.addBlockedSoneId(blockedSoneId);
710 /* load liked post IDs. */
711 int likedPostIdCounter = 0;
713 String likedPostIdPrefix = sonePrefix + "/LikedPostId." + likedPostIdCounter++;
714 String likedPostId = configuration.getStringValue(likedPostIdPrefix + "/ID").getValue(null);
715 if (likedPostId == null) {
718 sone.addLikedPostId(likedPostId);
721 /* load liked reply IDs. */
722 int likedReplyIdCounter = 0;
724 String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
725 String likedReplyId = configuration.getStringValue(likedReplyIdPrefix + "/ID").getValue(null);
726 if (likedReplyId == null) {
729 sone.addLikedReplyId(likedReplyId);
732 sone.setModificationCounter(modificationCounter);
734 } catch (MalformedURLException mue1) {
735 logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1);
738 logger.log(Level.INFO, "Loaded %d Sones.", getSones().size());
740 /* load all known Sones. */
741 int knownSonesCounter = 0;
743 String knownSonePrefix = "KnownSone." + knownSonesCounter++;
744 String knownSoneId = configuration.getStringValue(knownSonePrefix + "/ID").getValue(null);
745 if (knownSoneId == null) {
748 String knownSoneName = configuration.getStringValue(knownSonePrefix + "/Name").getValue(null);
749 String knownSoneKey = configuration.getStringValue(knownSonePrefix + "/Key").getValue(null);
751 getSone(knownSoneId).setName(knownSoneName).setRequestUri(new FreenetURI(knownSoneKey));
752 } catch (MalformedURLException mue1) {
753 logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + knownSoneKey + "”)!", mue1);
757 /* load all remote Sones. */
758 for (Sone remoteSone : getRemoteSones()) {
759 loadSone(remoteSone);
762 logger.exiting(Core.class.getName(), "loadConfiguration()");
766 * Saves the configuraiton.
768 private void saveConfiguration() {
769 Set<Sone> sones = getSones();
770 logger.log(Level.INFO, "Storing %d Sones…", sones.size());
773 /* store the options first. */
774 configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal());
776 /* store all Sones. */
778 for (Sone sone : localSones) {
779 String sonePrefix = "Sone/Sone." + soneId++;
780 configuration.getStringValue(sonePrefix + "/ID").setValue(sone.getId());
781 configuration.getStringValue(sonePrefix + "/Name").setValue(sone.getName());
782 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
783 configuration.getStringValue(sonePrefix + "/RequestURI").setValue(sone.getRequestUri().toString());
784 configuration.getStringValue(sonePrefix + "/InsertURI").setValue(sone.getInsertUri().toString());
785 configuration.getLongValue(sonePrefix + "/ModificationCounter").setValue(sone.getModificationCounter());
786 Profile profile = sone.getProfile();
787 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
788 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
789 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
790 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
791 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
792 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
794 for (Post post : sone.getPosts()) {
795 String postPrefix = sonePrefix + "/Post." + postId++;
796 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
797 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
798 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
800 /* write null ID as terminator. */
801 configuration.getStringValue(sonePrefix + "/Post." + postId + "/ID").setValue(null);
804 for (Reply reply : sone.getReplies()) {
805 String replyPrefix = sonePrefix + "/Reply." + replyId++;
806 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
807 configuration.getStringValue(replyPrefix + "/Post").setValue(reply.getPost().getId());
808 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
809 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
811 /* write null ID as terminator. */
812 configuration.getStringValue(sonePrefix + "/Reply." + replyId + "/ID").setValue(null);
815 for (Sone friend : sone.getFriends()) {
816 String friendPrefix = sonePrefix + "/Friend." + friendId++;
817 configuration.getStringValue(friendPrefix + "/ID").setValue(friend.getId());
818 configuration.getStringValue(friendPrefix + "/Key").setValue(friend.getRequestUri().toString());
819 configuration.getStringValue(friendPrefix + "/Name").setValue(friend.getName());
821 /* write null ID as terminator. */
822 configuration.getStringValue(sonePrefix + "/Friend." + friendId + "/ID").setValue(null);
824 /* write all blocked Sones. */
825 int blockedSoneCounter = 0;
826 for (String blockedSoneId : sone.getBlockedSoneIds()) {
827 String blockedSonePrefix = sonePrefix + "/BlockedSone." + blockedSoneCounter++;
828 configuration.getStringValue(blockedSonePrefix + "/ID").setValue(blockedSoneId);
830 configuration.getStringValue(sonePrefix + "/BlockedSone." + blockedSoneCounter + "/ID").setValue(null);
832 /* write all liked posts. */
833 int likedPostIdCounter = 0;
834 for (String soneLikedPostId : sone.getLikedPostIds()) {
835 String likedPostIdPrefix = sonePrefix + "/LikedPostId." + likedPostIdCounter++;
836 configuration.getStringValue(likedPostIdPrefix + "/ID").setValue(soneLikedPostId);
838 configuration.getStringValue(sonePrefix + "/LikedPostId." + likedPostIdCounter + "/ID").setValue(null);
840 /* write all liked replies. */
841 int likedReplyIdCounter = 0;
842 for (String soneLikedReplyId : sone.getLikedReplyIds()) {
843 String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
844 configuration.getStringValue(likedReplyIdPrefix + "/ID").setValue(soneLikedReplyId);
846 configuration.getStringValue(sonePrefix + "/LikedReplyId." + likedReplyIdCounter + "/ID").setValue(null);
849 /* write null ID as terminator. */
850 configuration.getStringValue("Sone/Sone." + soneId + "/ID").setValue(null);
852 /* write all known Sones. */
853 int knownSonesCounter = 0;
854 for (Sone knownSone : getRemoteSones()) {
855 String knownSonePrefix = "KnownSone." + knownSonesCounter++;
856 configuration.getStringValue(knownSonePrefix + "/ID").setValue(knownSone.getId());
857 configuration.getStringValue(knownSonePrefix + "/Name").setValue(knownSone.getName());
858 configuration.getStringValue(knownSonePrefix + "/Key").setValue(knownSone.getRequestUri().toString());
859 /* TODO - store all known stuff? */
861 configuration.getStringValue("KnownSone." + knownSonesCounter + "/ID").setValue(null);
863 } catch (ConfigurationException ce1) {
864 logger.log(Level.WARNING, "Could not store configuration!", ce1);