/*
- * Sone - SoneInserter.java - Copyright © 2010 David Roden
+ * Sone - SoneInserter.java - Copyright © 2010–2012 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertingEvent;
import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.freenet.StringBucket;
import net.pterodactylus.sone.main.SonePlugin;
-import net.pterodactylus.util.collection.ListBuilder;
-import net.pterodactylus.util.collection.ReverseComparator;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.template.TemplateException;
import net.pterodactylus.util.template.TemplateParser;
import net.pterodactylus.util.template.XmlFilter;
+
+import com.google.common.collect.Ordering;
+import com.google.common.eventbus.EventBus;
+
import freenet.client.async.ManifestElement;
import freenet.keys.FreenetURI;
/** The core. */
private final Core core;
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The Freenet interface. */
private final FreenetInterface freenetInterface;
/** The Sone to insert. */
private final Sone sone;
- /** The insert listener manager. */
- private SoneInsertListenerManager soneInsertListenerManager;
-
/** Whether a modification has been detected. */
private volatile boolean modified = false;
*
* @param core
* The core
+ * @param eventBus
+ * The event bus
* @param freenetInterface
* The freenet interface
* @param sone
* The Sone to insert
*/
- public SoneInserter(Core core, FreenetInterface freenetInterface, Sone sone) {
+ public SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone) {
super("Sone Inserter for “" + sone.getName() + "”", false);
this.core = core;
+ this.eventBus = eventBus;
this.freenetInterface = freenetInterface;
this.sone = sone;
- this.soneInsertListenerManager = new SoneInsertListenerManager(sone);
- }
-
- //
- // LISTENER MANAGEMENT
- //
-
- /**
- * Adds a listener for Sone insert events.
- *
- * @param soneInsertListener
- * The Sone insert listener
- */
- public void addSoneInsertListener(SoneInsertListener soneInsertListener) {
- soneInsertListenerManager.addListener(soneInsertListener);
- }
-
- /**
- * Removes a listener for Sone insert events.
- *
- * @param soneInsertListener
- * The Sone insert listener
- */
- public void removeSoneInsertListener(SoneInsertListener soneInsertListener) {
- soneInsertListenerManager.removeListener(soneInsertListener);
}
//
soneProperties.put("requestUri", sone.getRequestUri());
soneProperties.put("insertUri", sone.getInsertUri());
soneProperties.put("profile", sone.getProfile());
- soneProperties.put("posts", new ListBuilder<Post>(new ArrayList<Post>(sone.getPosts())).sort(Post.TIME_COMPARATOR).get());
- soneProperties.put("replies", new ListBuilder<PostReply>(new ArrayList<PostReply>(sone.getReplies())).sort(new ReverseComparator<Reply<?>>(Reply.TIME_COMPARATOR)).get());
+ soneProperties.put("posts", Ordering.from(Post.TIME_COMPARATOR).sortedCopy(sone.getPosts()));
+ soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
soneProperties.put("likedPostIds", new HashSet<String>(sone.getLikedPostIds()));
soneProperties.put("likedReplyIds", new HashSet<String>(sone.getLikedReplyIds()));
soneProperties.put("albums", sone.getAllAlbums());