X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProjectInserter.java;h=f3cf98a786480c2ad6c5e896e3190dc7f20d609e;hb=da487bd7b258bc47ad888c22f89343c6162569a6;hp=ed0653380aecbcc96c1c1cf4fb01e2df2ca111d6;hpb=9e6e70c28963fde2a6c8b120974f8a70d4da25bc;p=jSite.git
diff --git a/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java b/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java
index ed06533..f3cf98a 100644
--- a/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java
+++ b/src/main/java/de/todesbaum/jsite/application/ProjectInserter.java
@@ -20,6 +20,7 @@ package de.todesbaum.jsite.application;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -35,6 +36,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import net.pterodactylus.util.io.StreamCopier.ProgressListener;
+
+import com.google.common.base.Optional;
import de.todesbaum.jsite.gui.FileScanner;
import de.todesbaum.jsite.gui.FileScanner.ScannedFile;
import de.todesbaum.jsite.gui.FileScannerListener;
@@ -284,30 +287,6 @@ public class ProjectInserter implements FileScannerListener, Runnable {
}
/**
- * Creates an input stream that delivers the given file, replacing edition
- * tokens in the fileâs content, if necessary.
- *
- * @param filename
- * The name of the file
- * @param fileOption
- * The file options
- * @param edition
- * The current edition
- * @param length
- * An array containing a single long which is used to
- * return the final length of the file, after all
- * replacements
- * @return The input stream for the file
- * @throws IOException
- * if an I/O error occurs
- */
- private InputStream createFileInputStream(String filename, FileOption fileOption, int edition, long[] length) throws IOException {
- File file = new File(project.getLocalPath(), filename);
- length[0] = file.length();
- return new FileInputStream(file);
- }
-
- /**
* Creates a file entry suitable for handing in to
* {@link ClientPutComplexDir#addFileEntry(FileEntry)}.
*
@@ -318,30 +297,33 @@ public class ProjectInserter implements FileScannerListener, Runnable {
* @return A file entry for the given file
*/
private FileEntry createFileEntry(ScannedFile file, int edition) {
- FileEntry fileEntry = null;
String filename = file.getFilename();
FileOption fileOption = project.getFileOption(filename);
if (fileOption.isInsert()) {
fileOption.setCurrentHash(file.getHash());
/* check if file was modified. */
- if (!fileOption.isForceInsert() && file.getHash().equals(fileOption.getLastInsertHash())) {
+ if (!project.isAlwaysForceInsert() && !fileOption.isForceInsert() && file.getHash().equals(fileOption.getLastInsertHash())) {
/* only insert a redirect. */
logger.log(Level.FINE, String.format("Inserting redirect to edition %d for %s.", fileOption.getLastInsertEdition(), filename));
- return new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + fileOption.getLastInsertFilename());
+ return new RedirectFileEntry(fileOption.getChangedName().or(filename), fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + fileOption.getLastInsertFilename());
}
try {
- long[] fileLength = new long[1];
- InputStream fileEntryInputStream = createFileInputStream(filename, fileOption, edition, fileLength);
- fileEntry = new DirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileEntryInputStream, fileLength[0]);
+ return createFileEntry(filename, fileOption.getChangedName(), fileOption.getMimeType());
} catch (IOException ioe1) {
/* ignore, null is returned. */
}
} else {
if (fileOption.isInsertRedirect()) {
- fileEntry = new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileOption.getCustomKey());
+ return new RedirectFileEntry(fileOption.getChangedName().or(filename), fileOption.getMimeType(), fileOption.getCustomKey());
}
}
- return fileEntry;
+ return null;
+ }
+
+ private FileEntry createFileEntry(String filename, Optional changedName, String mimeType) throws FileNotFoundException {
+ File physicalFile = new File(project.getLocalPath(), filename);
+ InputStream fileEntryInputStream = new FileInputStream(physicalFile);
+ return new DirectFileEntry(changedName.or(filename), mimeType, fileEntryInputStream, physicalFile.length());
}
/**
@@ -399,10 +381,7 @@ public class ProjectInserter implements FileScannerListener, Runnable {
logger.log(Level.FINEST, "Ignoring {0}.", fileOptionEntry.getKey());
continue;
}
- String fileName = fileOptionEntry.getKey();
- if (fileOption.hasChangedName()) {
- fileName = fileOption.getChangedName();
- }
+ String fileName = fileOption.getChangedName().or(fileOptionEntry.getKey());
logger.log(Level.FINEST, "Adding â{0}â for {1}.", new Object[] { fileName, fileOptionEntry.getKey() });
if (!fileNames.add(fileName)) {
checkReport.addIssue("error.duplicate-file", true, fileName);