X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FConfiguration.java;h=ca5a1af298689e823d9597738779dfc6a8be271f;hb=d11bfba4213cc49fed096b6c58cfc22db1cd9e1e;hp=b38e986042c02540c81307942a7fbfcb87926ecd;hpb=437a0b9a2bc4c71877533b6e7137a1e964cb1748;p=jSite.git
diff --git a/src/de/todesbaum/jsite/main/Configuration.java b/src/de/todesbaum/jsite/main/Configuration.java
index b38e986..ca5a1af 100644
--- a/src/de/todesbaum/jsite/main/Configuration.java
+++ b/src/de/todesbaum/jsite/main/Configuration.java
@@ -49,6 +49,27 @@ import de.todesbaum.util.xml.XML;
*/
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;
@@ -92,6 +113,25 @@ public class Configuration {
}
/**
+ * 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 true
if the directory exists, or if it could be
@@ -331,18 +371,27 @@ public class Configuration {
try {
Project project = new Project();
projects.add(project);
- project.setDescription(projectNode.getNode("description").getValue());
- project.setIndexFile(projectNode.getNode("index-file").getValue());
- project.setLastInsertionTime(Long.parseLong(projectNode.getNode("last-insertion-time").getValue()));
- project.setLocalPath(projectNode.getNode("local-path").getValue());
- project.setName(projectNode.getNode("name").getValue());
- project.setPath(projectNode.getNode("path").getValue());
+ project.setDescription(projectNode.getNode("description").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.setPath(projectNode.getNode("path").getValue(""));
if ((project.getPath() != null) && (project.getPath().indexOf("/") != -1)) {
project.setPath(project.getPath().replaceAll("/", ""));
}
- project.setEdition(Integer.parseInt(projectNode.getNode("edition").getValue()));
- project.setInsertURI(projectNode.getNode("insert-uri").getValue());
- project.setRequestURI(projectNode.getNode("request-uri").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 fileOptions = new HashMap();
if (fileOptionsNode != null) {
@@ -351,8 +400,14 @@ public class Configuration {
String filename = fileOptionNode.getNode("filename").getValue();
FileOption fileOption = project.getFileOption(filename);
fileOption.setInsert(Boolean.parseBoolean(fileOptionNode.getNode("insert").getValue()));
- fileOption.setCustomKey(fileOptionNode.getNode("custom-key").getValue());
- fileOption.setMimeType(fileOptionNode.getNode("mime-type").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) {
fileOption.setReplaceEdition(Boolean.parseBoolean(fileOptionNode.getNode("replace-edition").getValue()));
@@ -389,6 +444,7 @@ public class Configuration {
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> entries = project.getFileOptions().entrySet().iterator();
while (entries.hasNext()) {
@@ -398,7 +454,9 @@ public class Configuration {
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()));
@@ -523,4 +581,31 @@ public class Configuration {
return new Node(hostname, port, name);
}
+ /**
+ * Returns the temp directory to use.
+ *
+ * @return The temp directoy, or {@code null} to use the default temp
+ * directory
+ */
+ public String getTempDirectory() {
+ return getNodeValue(new String[] { "temp-directory" }, null);
+ }
+
+ /**
+ * Sets the temp directory to use.
+ *
+ * @param tempDirectory
+ * The temp directory to use, or {@code null} to use the default
+ * temp directory
+ */
+ public void setTempDirectory(String tempDirectory) {
+ if (tempDirectory != null) {
+ SimpleXML tempDirectoryNode = new SimpleXML("temp-directory");
+ tempDirectoryNode.setValue(tempDirectory);
+ rootNode.replace(tempDirectoryNode);
+ } else {
+ rootNode.remove("temp-directory");
+ }
+ }
+
}