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 @SuppressWarnings("unchecked")
619 private void loadConfiguration() {
620 logger.entering(Core.class.getName(), "loadConfiguration()");
622 options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new OptionWatcher<Integer>() {
625 public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
626 SoneInserter.setInsertionDelay(newValue);
629 })).set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
631 options.addBooleanOption("ClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ClearOnNextRestart").getValue(null));
632 options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ReallyClearOnNextRestart").getValue(null));
634 boolean clearConfiguration = options.getBooleanOption("ClearOnNextRestart").get() && options.getBooleanOption("ReallyClearOnNextRestart").get();
635 options.getBooleanOption("ClearOnNextRestart").set(null);
636 options.getBooleanOption("ReallyClearOnNextRestart").set(null);
637 if (clearConfiguration) {
638 /* stop loading the configuration. */
642 /* parse local Sones. */
643 logger.log(Level.INFO, "Loading Sones…");
646 String sonePrefix = "Sone/Sone." + soneId++;
647 String id = configuration.getStringValue(sonePrefix + "/ID").getValue(null);
651 String name = configuration.getStringValue(sonePrefix + "/Name").getValue(null);
652 long time = configuration.getLongValue(sonePrefix + "/Time").getValue((long) 0);
653 String insertUri = configuration.getStringValue(sonePrefix + "/InsertURI").getValue(null);
654 String requestUri = configuration.getStringValue(sonePrefix + "/RequestURI").getValue(null);
655 long modificationCounter = configuration.getLongValue(sonePrefix + "/ModificationCounter").getValue((long) 0);
656 String firstName = configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null);
657 String middleName = configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null);
658 String lastName = configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null);
659 Integer birthDay = configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null);
660 Integer birthMonth = configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null);
661 Integer birthYear = configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null);
663 Profile profile = new Profile();
664 profile.setFirstName(firstName);
665 profile.setMiddleName(middleName);
666 profile.setLastName(lastName);
667 profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
668 Sone sone = getSone(id).setName(name).setTime(time).setRequestUri(new FreenetURI(requestUri)).setInsertUri(new FreenetURI(insertUri));
669 sone.setProfile(profile);
672 String postPrefix = sonePrefix + "/Post." + postId++;
673 id = configuration.getStringValue(postPrefix + "/ID").getValue(null);
677 time = configuration.getLongValue(postPrefix + "/Time").getValue((long) 0);
678 String text = configuration.getStringValue(postPrefix + "/Text").getValue(null);
679 Post post = getPost(id).setSone(sone).setTime(time).setText(text);
682 int replyCounter = 0;
684 String replyPrefix = sonePrefix + "/Reply." + replyCounter++;
685 String replyId = configuration.getStringValue(replyPrefix + "/ID").getValue(null);
686 if (replyId == null) {
689 Post replyPost = getPost(configuration.getStringValue(replyPrefix + "/Post").getValue(null));
690 long replyTime = configuration.getLongValue(replyPrefix + "/Time").getValue(null);
691 String replyText = configuration.getStringValue(replyPrefix + "/Text").getValue(null);
692 Reply reply = getReply(replyId).setSone(sone).setPost(replyPost).setTime(replyTime).setText(replyText);
693 sone.addReply(reply);
697 int friendCounter = 0;
699 String friendPrefix = sonePrefix + "/Friend." + friendCounter++;
700 String friendId = configuration.getStringValue(friendPrefix + "/ID").getValue(null);
701 if (friendId == null) {
704 Sone friendSone = getSone(friendId);
705 String friendKey = configuration.getStringValue(friendPrefix + "/Key").getValue(null);
706 String friendName = configuration.getStringValue(friendPrefix + "/Name").getValue(null);
707 friendSone.setRequestUri(new FreenetURI(friendKey)).setName(friendName);
708 sone.addFriend(friendSone);
711 /* load blocked Sone IDs. */
712 int blockedSoneCounter = 0;
714 String blockedSonePrefix = sonePrefix + "/BlockedSone." + blockedSoneCounter++;
715 String blockedSoneId = configuration.getStringValue(blockedSonePrefix + "/ID").getValue(null);
716 if (blockedSoneId == null) {
719 sone.addBlockedSoneId(blockedSoneId);
722 /* load liked post IDs. */
723 int likedPostIdCounter = 0;
725 String likedPostIdPrefix = sonePrefix + "/LikedPostId." + likedPostIdCounter++;
726 String likedPostId = configuration.getStringValue(likedPostIdPrefix + "/ID").getValue(null);
727 if (likedPostId == null) {
730 sone.addLikedPostId(likedPostId);
733 /* load liked reply IDs. */
734 int likedReplyIdCounter = 0;
736 String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
737 String likedReplyId = configuration.getStringValue(likedReplyIdPrefix + "/ID").getValue(null);
738 if (likedReplyId == null) {
741 sone.addLikedReplyId(likedReplyId);
744 sone.setModificationCounter(modificationCounter);
746 } catch (MalformedURLException mue1) {
747 logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1);
750 logger.log(Level.INFO, "Loaded %d Sones.", getSones().size());
752 /* load all known Sones. */
753 int knownSonesCounter = 0;
755 String knownSonePrefix = "KnownSone." + knownSonesCounter++;
756 String knownSoneId = configuration.getStringValue(knownSonePrefix + "/ID").getValue(null);
757 if (knownSoneId == null) {
760 String knownSoneName = configuration.getStringValue(knownSonePrefix + "/Name").getValue(null);
761 String knownSoneKey = configuration.getStringValue(knownSonePrefix + "/Key").getValue(null);
763 getSone(knownSoneId).setName(knownSoneName).setRequestUri(new FreenetURI(knownSoneKey));
764 } catch (MalformedURLException mue1) {
765 logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + knownSoneKey + "”)!", mue1);
769 /* load all remote Sones. */
770 for (Sone remoteSone : getRemoteSones()) {
771 loadSone(remoteSone);
774 logger.exiting(Core.class.getName(), "loadConfiguration()");
778 * Saves the configuraiton.
780 private void saveConfiguration() {
781 Set<Sone> sones = getSones();
782 logger.log(Level.INFO, "Storing %d Sones…", sones.size());
785 /* store the options first. */
786 configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal());
787 configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal());
788 configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal());
790 /* store all Sones. */
792 for (Sone sone : localSones) {
793 String sonePrefix = "Sone/Sone." + soneId++;
794 configuration.getStringValue(sonePrefix + "/ID").setValue(sone.getId());
795 configuration.getStringValue(sonePrefix + "/Name").setValue(sone.getName());
796 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
797 configuration.getStringValue(sonePrefix + "/RequestURI").setValue(sone.getRequestUri().toString());
798 configuration.getStringValue(sonePrefix + "/InsertURI").setValue(sone.getInsertUri().toString());
799 configuration.getLongValue(sonePrefix + "/ModificationCounter").setValue(sone.getModificationCounter());
800 Profile profile = sone.getProfile();
801 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
802 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
803 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
804 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
805 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
806 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
808 for (Post post : sone.getPosts()) {
809 String postPrefix = sonePrefix + "/Post." + postId++;
810 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
811 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
812 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
814 /* write null ID as terminator. */
815 configuration.getStringValue(sonePrefix + "/Post." + postId + "/ID").setValue(null);
818 for (Reply reply : sone.getReplies()) {
819 String replyPrefix = sonePrefix + "/Reply." + replyId++;
820 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
821 configuration.getStringValue(replyPrefix + "/Post").setValue(reply.getPost().getId());
822 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
823 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
825 /* write null ID as terminator. */
826 configuration.getStringValue(sonePrefix + "/Reply." + replyId + "/ID").setValue(null);
829 for (Sone friend : sone.getFriends()) {
830 String friendPrefix = sonePrefix + "/Friend." + friendId++;
831 configuration.getStringValue(friendPrefix + "/ID").setValue(friend.getId());
832 configuration.getStringValue(friendPrefix + "/Key").setValue(friend.getRequestUri().toString());
833 configuration.getStringValue(friendPrefix + "/Name").setValue(friend.getName());
835 /* write null ID as terminator. */
836 configuration.getStringValue(sonePrefix + "/Friend." + friendId + "/ID").setValue(null);
838 /* write all blocked Sones. */
839 int blockedSoneCounter = 0;
840 for (String blockedSoneId : sone.getBlockedSoneIds()) {
841 String blockedSonePrefix = sonePrefix + "/BlockedSone." + blockedSoneCounter++;
842 configuration.getStringValue(blockedSonePrefix + "/ID").setValue(blockedSoneId);
844 configuration.getStringValue(sonePrefix + "/BlockedSone." + blockedSoneCounter + "/ID").setValue(null);
846 /* write all liked posts. */
847 int likedPostIdCounter = 0;
848 for (String soneLikedPostId : sone.getLikedPostIds()) {
849 String likedPostIdPrefix = sonePrefix + "/LikedPostId." + likedPostIdCounter++;
850 configuration.getStringValue(likedPostIdPrefix + "/ID").setValue(soneLikedPostId);
852 configuration.getStringValue(sonePrefix + "/LikedPostId." + likedPostIdCounter + "/ID").setValue(null);
854 /* write all liked replies. */
855 int likedReplyIdCounter = 0;
856 for (String soneLikedReplyId : sone.getLikedReplyIds()) {
857 String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
858 configuration.getStringValue(likedReplyIdPrefix + "/ID").setValue(soneLikedReplyId);
860 configuration.getStringValue(sonePrefix + "/LikedReplyId." + likedReplyIdCounter + "/ID").setValue(null);
863 /* write null ID as terminator. */
864 configuration.getStringValue("Sone/Sone." + soneId + "/ID").setValue(null);
866 /* write all known Sones. */
867 int knownSonesCounter = 0;
868 for (Sone knownSone : getRemoteSones()) {
869 String knownSonePrefix = "KnownSone." + knownSonesCounter++;
870 configuration.getStringValue(knownSonePrefix + "/ID").setValue(knownSone.getId());
871 configuration.getStringValue(knownSonePrefix + "/Name").setValue(knownSone.getName());
872 configuration.getStringValue(knownSonePrefix + "/Key").setValue(knownSone.getRequestUri().toString());
873 /* TODO - store all known stuff? */
875 configuration.getStringValue("KnownSone." + knownSonesCounter + "/ID").setValue(null);
877 } catch (ConfigurationException ce1) {
878 logger.log(Level.WARNING, "Could not store configuration!", ce1);