*/
public class Configuration {
+ /**
+ * The location of the configuration directory.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+ public enum ConfigurationDirectory {
+
+ /** The configuration is in the same directory as the JAR file. */
+ NEXT_TO_JAR_FILE,
+
+ /**
+ * The configuration is in the user’s home directory. This is the
+ * pre-0.9.3 default.
+ */
+ HOME_DIRECTORY;
+
+ }
+
+ /** The configuration directory. */
+ private ConfigurationDirectory configurationDirectory = ConfigurationDirectory.HOME_DIRECTORY;
+
/** The name of the file the configuration is stored to. */
private String filename;
}
/**
+ * Returns the configuration directory.
+ *
+ * @return The configuration directory
+ */
+ public ConfigurationDirectory getConfigurationDirectory() {
+ return configurationDirectory;
+ }
+
+ /**
+ * Sets the configuration directory.
+ *
+ * @param configurationDirectory
+ * The configuration directory
+ */
+ public void setConfigurationDirectory(ConfigurationDirectory configurationDirectory) {
+ this.configurationDirectory = configurationDirectory;
+ }
+
+ /**
* Creates the directory of the configuration file.
*
* @return <code>true</code> if the directory exists, or if it could be
Project project = new Project();
projects.add(project);
project.setDescription(projectNode.getNode("description").getValue(""));
- project.setIndexFile(projectNode.getNode("index-file").getValue(""));
+ String indexFile = projectNode.getNode("index-file").getValue("");
+ if (indexFile.indexOf('/') > -1) {
+ indexFile = "";
+ }
+ project.setIndexFile(indexFile);
project.setLastInsertionTime(Long.parseLong(projectNode.getNode("last-insertion-time").getValue("0")));
project.setLocalPath(projectNode.getNode("local-path").getValue(""));
project.setName(projectNode.getNode("name").getValue(""));
project.setEdition(Integer.parseInt(projectNode.getNode("edition").getValue("0")));
project.setInsertURI(projectNode.getNode("insert-uri").getValue(""));
project.setRequestURI(projectNode.getNode("request-uri").getValue(""));
+ if (projectNode.getNode("ignore-hidden-files") != null) {
+ project.setIgnoreHiddenFiles(Boolean.parseBoolean(projectNode.getNode("ignore-hidden-files").getValue("true")));
+ } else {
+ project.setIgnoreHiddenFiles(true);
+ }
SimpleXML fileOptionsNode = projectNode.getNode("file-options");
Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
if (fileOptionsNode != null) {
String filename = fileOptionNode.getNode("filename").getValue();
FileOption fileOption = project.getFileOption(filename);
fileOption.setInsert(Boolean.parseBoolean(fileOptionNode.getNode("insert").getValue()));
+ if (fileOptionNode.getNode("insert-redirect") != null) {
+ fileOption.setInsertRedirect(Boolean.parseBoolean(fileOptionNode.getNode("insert-redirect").getValue()));
+ }
fileOption.setCustomKey(fileOptionNode.getNode("custom-key").getValue(""));
+ if (fileOptionNode.getNode("changed-name") != null) {
+ fileOption.setChangedName(fileOptionNode.getNode("changed-name").getValue());
+ }
fileOption.setMimeType(fileOptionNode.getNode("mime-type").getValue(""));
fileOption.setContainer(fileOptionNode.getNode("container").getValue());
if (fileOptionNode.getNode("replace-edition") != null) {
projectNode.append("path", project.getPath());
projectNode.append("insert-uri", project.getInsertURI());
projectNode.append("request-uri", project.getRequestURI());
+ projectNode.append("ignore-hidden-files", String.valueOf(project.isIgnoreHiddenFiles()));
SimpleXML fileOptionsNode = projectNode.append("file-options");
Iterator<Entry<String, FileOption>> entries = project.getFileOptions().entrySet().iterator();
while (entries.hasNext()) {
SimpleXML fileOptionNode = fileOptionsNode.append("file-option");
fileOptionNode.append("filename", entry.getKey());
fileOptionNode.append("insert", String.valueOf(fileOption.isInsert()));
+ fileOptionNode.append("insert-redirect", String.valueOf(fileOption.isInsertRedirect()));
fileOptionNode.append("custom-key", fileOption.getCustomKey());
+ fileOptionNode.append("changed-name", fileOption.getChangedName());
fileOptionNode.append("mime-type", fileOption.getMimeType());
fileOptionNode.append("container", fileOption.getContainer());
fileOptionNode.append("replace-edition", String.valueOf(fileOption.getReplaceEdition()));