return false;
}
File lockFile = new File(lockFilename);
- lockFile.deleteOnExit();
try {
- return lockFile.createNewFile();
+ boolean fileLocked = lockFile.createNewFile();
+ if (fileLocked) {
+ lockFile.deleteOnExit();
+ }
+ return fileLocked;
} catch (IOException e) {
/* ignore. */
}
}
/**
+ * Tells the VM to remove the lock file on program exit.
+ */
+ public void removeLockfileOnExit() {
+ new File(lockFilename).deleteOnExit();
+ }
+
+ /**
* Reads the configuration from the file.
*/
private void readConfiguration() {
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(""));
+ project.setIndexFile(projectNode.getNode("index-file").getValue(""));
+ 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<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()));
- fileOption.setCustomKey(fileOptionNode.getNode("custom-key").getValue());
- fileOption.setMimeType(fileOptionNode.getNode("mime-type").getValue());
+ fileOption.setCustomKey(fileOptionNode.getNode("custom-key").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()));
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()) {
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");
+ }
+ }
+
}