/**
* @author David Roden <droden@gmail.com>
- * @version $Id: ProjectInserter.java 486 2006-04-27 10:58:34Z bombe $
+ * @version $Id$
*/
public class ProjectInserter implements FileScannerListener, Runnable {
protected Project project;
private FileScanner fileScanner;
protected final Object lockObject = new Object();
- private int maxRetries = 99999;
public void addInsertListener(InsertListener insertListener) {
insertListeners.add(insertListener);
insertListener.projectInsertStarted(project);
}
}
+
+ protected void fireProjectURIGenerated(String uri) {
+ for (InsertListener insertListener: insertListeners) {
+ insertListener.projectURIGenerated(project, uri);
+ }
+ }
protected void fireProjectInsertProgress(int succeeded, int failed, int fatal, int total, boolean finalized) {
for (InsertListener insertListener: insertListeners) {
this.freenetInterface = freenetInterface;
}
- /**
- * @param maxRetries
- * The maxRetries to set.
- */
- public void setMaxRetries(int maxRetries) {
- this.maxRetries = maxRetries;
- }
-
public void start() {
fileScanner = new FileScanner(project);
fileScanner.addFileScannerListener(this);
ByteArrayOutputStream filteredByteOutputStream = new ByteArrayOutputStream(Math.min(Integer.MAX_VALUE, (int) length[0]));
ReplacingOutputStream outputStream = new ReplacingOutputStream(filteredByteOutputStream);
FileInputStream fileInput = new FileInputStream(file);
- outputStream.addReplacement("$[CONTAINER]", "/");
outputStream.addReplacement("$[EDITION]", String.valueOf(edition));
- outputStream.addReplacement("$[URI]", project.getFinalURI(0));
+ outputStream.addReplacement("$[URI]", project.getFinalRequestURI(0));
for (int index = 1; index <= fileOption.getEditionRange(); index++) {
- outputStream.addReplacement("$[URI+" + index + "]", project.getFinalURI(index));
+ outputStream.addReplacement("$[URI+" + index + "]", project.getFinalRequestURI(index));
outputStream.addReplacement("$[EDITION+" + index + "]", String.valueOf(edition + index));
}
StreamCopier.copy(fileInput, outputStream, length[0]);
createContainers(files, containers, containerFiles);
/* collect files */
- int edition = ((EditionProject) project).getEdition();
- String dirURI = project.getInsertURI() + project.getPath() + "-" + edition;
+ int edition = project.getEdition();
+ String dirURI = "freenet:USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/";
ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI);
putDir.setDefaultName(project.getIndexFile());
putDir.setVerbosity(Verbosity.ALL);
- putDir.setMaxRetries(maxRetries);
+ putDir.setMaxRetries(-1);
for (String filename: files) {
FileEntry fileEntry = createFileEntry(filename, edition, containerFiles);
if (fileEntry != null) {
}
/* parse progress and success messages */
- boolean success = true;
+ String finalURI = null;
+ boolean success = false;
boolean finished = false;
boolean disconnected = false;
while (!finished) {
Message message = client.readMessage();
- finished = (message == null) && (disconnected = client.isDisconnected());
+ finished = (message == null) || (disconnected = client.isDisconnected());
if (debug) {
System.out.println(message);
}
if (!finished) {
String messageName = message.getName();
+ if ("URIGenerated".equals(messageName)) {
+ finalURI = message.get("URI");
+ fireProjectURIGenerated(finalURI);
+ }
if ("SimpleProgress".equals(messageName)) {
int total = Integer.parseInt(message.get("Total"));
int succeeded = Integer.parseInt(message.get("Succeeded"));
/* post-insert work */
fireProjectInsertFinished(success, disconnected ? new IOException("Connection terminated") : null);
if (success) {
- if (project instanceof EditionProject) {
- ((EditionProject) project).setEdition(edition + 1);
- }
+ String editionPart = finalURI.substring(finalURI.lastIndexOf('/') + 1);
+ int newEdition = Integer.parseInt(editionPart);
+ project.setEdition(newEdition);
}
}