2 * fac - InsertManager.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.fac.core;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Properties;
33 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
35 public class InsertManager {
37 /** The list of inserts. */
38 private final List<Insert> inserts = Collections.synchronizedList(new ArrayList<Insert>());
45 * Starts the insert manager and loads its configuration file.
56 * Loads the configuration.
58 private void loadConfiguration() {
59 File configurationFile = new File("inserts.properties");
60 if (!configurationFile.exists()) {
63 FileInputStream fileInputStream = null;
65 fileInputStream = new FileInputStream(configurationFile);
66 Properties configurationProperties = new Properties();
67 configurationProperties.load(fileInputStream);
69 List<Insert> newInserts = new ArrayList<Insert>();
70 while (configurationProperties.containsKey("insert." + insertIndex + ".insertTime")) {
71 long insertTime = Long.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".insertTime"));
72 String uri = configurationProperties.getProperty("insert." + insertIndex + ".uri");
73 long checkTime = Long.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".checkTime"));
74 boolean checked = Boolean.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".checked"));
75 boolean successful = Boolean.valueOf(configurationProperties.getProperty("insert." + insertIndex + ".successful"));
76 Insert insert = new Insert();
77 insert.setInsertTime(insertTime);
79 insert.setCheckTime(checkTime);
80 insert.setChecked(checked);
81 insert.setSuccessful(successful);
82 newInserts.add(insert);
85 inserts.addAll(newInserts);
86 } catch (IOException ioe1) {
87 System.err.println("could not load configuration: " + ioe1.getClass().getSimpleName() + ((ioe1.getMessage() != null) ? (": " + ioe1.getMessage()) : ("")));
89 if (fileInputStream != null) {
91 fileInputStream.close();
92 } catch (IOException ioe1) {