package net.pterodactylus.fac.core;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
/**
* TODO
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class InsertManager {
- /* TODO */
+ /** The list of inserts. */
+ private final List<Insert> inserts = Collections.synchronizedList(new ArrayList<Insert>());
+
+ //
+ // ACTIONS
+ //
+
+ /**
+ * Starts the insert manager and loads its configuration file.
+ */
+ public void start() {
+ loadConfiguration();
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Loads the configuration.
+ */
+ private void loadConfiguration() {
+ File configurationFile = new File("inserts.properties");
+ if (!configurationFile.exists()) {
+ return;
+ }
+ FileInputStream fileInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(configurationFile);
+ Properties configurationProperties = new Properties();
+ configurationProperties.load(fileInputStream);
+ int insertIndex = 0;
+ List<Insert> newInserts = new ArrayList<Insert>();
+ while (configurationProperties.containsKey("insert." + insertIndex + ".insertTime")) {
+ long insertTime = Long.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".insertTime"));
+ String uri = configurationProperties.getProperty("insert." + insertIndex + ".uri");
+ long checkTime = Long.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".checkTime"));
+ boolean checked = Boolean.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".checked"));
+ boolean successful = Boolean.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".successful"));
+ Insert insert = new Insert();
+ insert.setInsertTime(insertTime);
+ insert.setURI(uri);
+ insert.setCheckTime(checkTime);
+ insert.setChecked(checked);
+ insert.setSuccessful(successful);
+ newInserts.add(insert);
+ }
+ inserts.clear();
+ inserts.addAll(newInserts);
+ } catch (IOException ioe1) {
+ System.err.println("could not load configuration: " + ioe1.getClass().getSimpleName() + ((ioe1.getMessage() != null) ? (": " + ioe1.getMessage()) : ("")));
+ } finally {
+ if (fileInputStream != null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+ }
+ }
}