X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProjectInserter.java;h=0fcddcc40a1afc5bef2acc6ccc799267ac16099f;hb=e44d6888ffaa3151a99b9bb7cb3c887d11feb596;hp=d525ddbd69ae182797b0c51f5e84758d21937613;hpb=f00de4e0d5ba4c14dc09ff84263563a7abc45cd9;p=jSite.git diff --git a/src/de/todesbaum/jsite/application/ProjectInserter.java b/src/de/todesbaum/jsite/application/ProjectInserter.java index d525ddb..0fcddcc 100644 --- a/src/de/todesbaum/jsite/application/ProjectInserter.java +++ b/src/de/todesbaum/jsite/application/ProjectInserter.java @@ -48,7 +48,7 @@ import de.todesbaum.util.io.StreamCopier; /** * @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 { @@ -74,6 +74,12 @@ public class ProjectInserter implements FileScannerListener, Runnable { 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) { @@ -134,11 +140,10 @@ public class ProjectInserter implements FileScannerListener, Runnable { 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]); @@ -261,8 +266,8 @@ public class ProjectInserter implements FileScannerListener, Runnable { 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); @@ -283,17 +288,22 @@ public class ProjectInserter implements FileScannerListener, Runnable { } /* 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")); @@ -310,9 +320,9 @@ public class ProjectInserter implements FileScannerListener, Runnable { /* 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); } }