/*
- * jSite - Configuration.java - Copyright © 2006–2012 David Roden
+ * jSite - Configuration.java - Copyright © 2006–2019 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.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.io.StreamCopier;
+import net.pterodactylus.util.xml.SimpleXML;
+import net.pterodactylus.util.xml.XML;
import de.todesbaum.jsite.application.FileOption;
import de.todesbaum.jsite.application.Node;
import de.todesbaum.jsite.application.Project;
import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
-import de.todesbaum.util.freenet.fcp2.ClientPutDir.ManifestPutter;
import de.todesbaum.util.freenet.fcp2.PriorityClass;
-import de.todesbaum.util.io.Closer;
-import de.todesbaum.util.io.StreamCopier;
-import de.todesbaum.util.xml.SimpleXML;
-import de.todesbaum.util.xml.XML;
+import org.w3c.dom.Document;
/**
* The configuration.
StreamCopier.copy(fileInputStream, fileByteOutputStream, configurationFile.length());
fileByteOutputStream.close();
byte[] fileBytes = fileByteOutputStream.toByteArray();
- rootNode = SimpleXML.fromDocument(XML.transformToDocument(fileBytes));
+ Document document = XML.transformToDocument(fileBytes);
+ if (document != null) {
+ rootNode = SimpleXML.fromDocument(document);
+ }
return;
} catch (FileNotFoundException e) {
/* ignore. */
*
* @return A list of all projects
*/
- public Project[] getProjects() {
+ public List<Project> getProjects() {
List<Project> projects = new ArrayList<Project>();
SimpleXML projectsNode = rootNode.getNode("project-list");
if (projectsNode != null) {
try {
Project project = new Project();
projects.add(project);
- project.setDescription(projectNode.getNode("description").getValue(""));
- String indexFile = projectNode.getNode("index-file").getValue("");
+ project.setDescription(projectNode.getValue("description", ""));
+ String indexFile = projectNode.getValue("index-file", "");
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.setPath(projectNode.getNode("path").getValue(""));
+ project.setLastInsertionTime(Long.parseLong(projectNode.getValue("last-insertion-time", "0")));
+ project.setLocalPath(projectNode.getValue("local-path", ""));
+ project.setName(projectNode.getValue("name", ""));
+ project.setPath(projectNode.getValue("path", ""));
if ((project.getPath() != null) && (project.getPath().indexOf("/") != -1)) {
project.setPath(project.getPath().replaceAll("/", ""));
}
- project.setEdition(Integer.parseInt(projectNode.getNode("edition").getValue("0")));
- project.setInsertURI(projectNode.getNode("insert-uri").getValue(""));
- project.setRequestURI(projectNode.getNode("request-uri").getValue(""));
+ project.setEdition(Integer.parseInt(projectNode.getValue("edition", "0")));
+ project.setInsertURI(projectNode.getValue("insert-uri", ""));
+ project.setRequestURI(projectNode.getValue("request-uri", ""));
if (projectNode.getNode("ignore-hidden-files") != null) {
- project.setIgnoreHiddenFiles(Boolean.parseBoolean(projectNode.getNode("ignore-hidden-files").getValue("true")));
+ project.setIgnoreHiddenFiles(Boolean.parseBoolean(projectNode.getValue("ignore-hidden-files", "true")));
} else {
project.setIgnoreHiddenFiles(true);
}
+ project.setAlwaysForceInsert(Boolean.parseBoolean(projectNode.getValue("always-force-insert", "false")));
/* load last insert hashes. */
Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
if (fileOptionNode.getNode("insert-redirect") != null) {
fileOption.setInsertRedirect(Boolean.parseBoolean(fileOptionNode.getNode("insert-redirect").getValue()));
}
- fileOption.setCustomKey(fileOptionNode.getNode("custom-key").getValue(""));
+ fileOption.setCustomKey(fileOptionNode.getValue("custom-key", ""));
if (fileOptionNode.getNode("changed-name") != null) {
fileOption.setChangedName(fileOptionNode.getNode("changed-name").getValue());
}
- fileOption.setMimeType(fileOptionNode.getNode("mime-type").getValue(""));
+ fileOption.setMimeType(fileOptionNode.getValue("mime-type", ""));
fileOptions.put(filename, fileOption);
}
}
}
}
}
- return projects.toArray(new Project[projects.size()]);
+ return projects;
}
/**
* @param projects
* The list of all projects
*/
- public void setProjects(Project[] projects) {
+ public void setProjects(List<Project> projects) {
SimpleXML projectsNode = new SimpleXML("project-list");
for (Project project : projects) {
SimpleXML projectNode = projectsNode.append("project");
projectNode.append("insert-uri", project.getInsertURI());
projectNode.append("request-uri", project.getRequestURI());
projectNode.append("ignore-hidden-files", String.valueOf(project.isIgnoreHiddenFiles()));
+ projectNode.append("always-force-insert", String.valueOf(project.isAlwaysForceInsert()));
/* store last insert hashes. */
SimpleXML lastInsertHashesNode = projectNode.append("last-insert-hashes");
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("changed-name", fileOption.getChangedName().orElse(null));
fileOptionNode.append("mime-type", fileOption.getMimeType());
}
}
return this;
}
- /**
- * Returns the manifest putter.
- *
- * @return The manifest putter
- */
- public ManifestPutter getManifestPutter() {
- return ManifestPutter.valueOf(getNodeValue(new String[] { "manifest-putter" }, "simple").toUpperCase());
- }
-
- /**
- * Sets the manifest putter.
- *
- * @param manifestPutter
- * The manifest putter
- * @return This configuration
- */
- public Configuration setManifestPutter(ManifestPutter manifestPutter) {
- rootNode.replace("manifest-putter", manifestPutter.name().toLowerCase());
- return this;
- }
-
}