r27169 - in trunk/freenet/src/freenet: client/async clients/http

[email protected] Tue, 21 Apr 2009 21:43:48 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: toad
Date: 2009-04-21 21:43:47 +0000 (Tue, 21 Apr 2009)
New Revision: 27169

Modified:
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
   trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java
   trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
   trunk/freenet/src/freenet/client/async/USKRetriever.java
   trunk/freenet/src/freenet/clients/http/FProxyFetchInProgress.java
   trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
Log:
Show the size, fix the content type


Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -15,6 +15,8 @@
 import freenet.client.FetchContext;
 import freenet.client.FetchException;
 import freenet.client.FetchResult;
+import freenet.client.events.ExpectedFileSizeEvent;
+import freenet.client.events.ExpectedMIMEEvent;
 import freenet.client.events.SendingToNetworkEvent;
 import freenet.client.events.SplitfileProgressEvent;
 import freenet.keys.ClientKeyBlock;
@@ -438,18 +440,27 @@
 		return binaryBlobBucket != null;
 	}
 
-	public void onExpectedMIME(String mime, ObjectContainer container) {
+	public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 		if(finalizedMetadata) return;
 		expectedMIME = mime;
-		if(persistent())
+		if(persistent()) {
 			container.store(this);
+			container.activate(ctx, 1);
+			container.activate(ctx.eventProducer, 1);
+		}
+		ctx.eventProducer.produceEvent(new ExpectedMIMEEvent(mime), container, context);
+
 	}
 
-	public void onExpectedSize(long size, ObjectContainer container) {
+	public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 		if(finalizedMetadata) return;
 		expectedSize = size;
-		if(persistent())
+		if(persistent()) {
 			container.store(this);
+			container.activate(ctx, 1);
+			container.activate(ctx.eventProducer, 1);
+		}
+		ctx.eventProducer.produceEvent(new ExpectedFileSizeEvent(size), container, context);
 	}
 
 	public void onFinalizedMetadata(ObjectContainer container) {

Modified: trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/GetCompletionCallback.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/GetCompletionCallback.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -25,9 +25,9 @@
 
 	public void onTransition(ClientGetState oldState, ClientGetState newState, ObjectContainer container);
 
-	public void onExpectedSize(long size, ObjectContainer container);
+	public void onExpectedSize(long size, ObjectContainer container, ClientContext context);
 	
-	public void onExpectedMIME(String mime, ObjectContainer container);
+	public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context);
 	
 	public void onFinalizedMetadata(ObjectContainer container);
 	

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -553,7 +553,7 @@
 				clientMetadata.mergeNoOverwrite(metadata.getClientMetadata());
 				if(persistent) container.store(clientMetadata);
 				String mime = clientMetadata.getMIMEType();
-				if(mime != null) rcb.onExpectedMIME(mime, container);
+				if(mime != null) rcb.onExpectedMIME(mime, container, context);
 				if(metaStrings.isEmpty() && isFinal && clientMetadata.getMIMETypeNoParams() != null && ctx.allowedMIMETypes != null &&
 						!ctx.allowedMIMETypes.contains(clientMetadata.getMIMETypeNoParams())) {
 					throw new FetchException(FetchException.WRONG_MIME_TYPE, -1, false, clientMetadata.getMIMEType());
@@ -660,7 +660,7 @@
 				clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even splitfiles can have mime types!
 				if(persistent) container.store(clientMetadata);
 				String mime = clientMetadata.getMIMEType();
-				if(mime != null) rcb.onExpectedMIME(mime, container);
+				if(mime != null) rcb.onExpectedMIME(mime, container, context);
 
 				String mimeType = clientMetadata.getMIMETypeNoParams();
 				if(mimeType != null && ArchiveManager.ARCHIVE_TYPE.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
@@ -732,7 +732,7 @@
 				clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even splitfiles can have mime types!
 				if(persistent) container.store(clientMetadata);
 				String mime = clientMetadata.getMIMEType();
-				if(mime != null) rcb.onExpectedMIME(mime, container);
+				if(mime != null) rcb.onExpectedMIME(mime, container, context);
 				
 				String mimeType = clientMetadata.getMIMETypeNoParams();
 				if(mimeType != null && ArchiveManager.ARCHIVE_TYPE.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
@@ -1024,11 +1024,11 @@
 			// Ignore
 		}
 
-		public void onExpectedMIME(String mime, ObjectContainer container) {
+		public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 			// Ignore
 		}
 
-		public void onExpectedSize(long size, ObjectContainer container) {
+		public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 			boolean wasActive = true;
 			if(persistent) {
 				wasActive = container.ext().isActive(SingleFileFetcher.this);
@@ -1037,7 +1037,7 @@
 			}
 			if(persistent)
 				container.activate(rcb, 1);
-			rcb.onExpectedSize(size, container);
+			rcb.onExpectedSize(size, container, context);
 			if(!wasActive)
 				container.deactivate(SingleFileFetcher.this, 1);
 		}
@@ -1119,11 +1119,11 @@
 			// Ignore
 		}
 
-		public void onExpectedMIME(String mime, ObjectContainer container) {
+		public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 			// Ignore
 		}
 
-		public void onExpectedSize(long size, ObjectContainer container) {
+		public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 			boolean wasActive = true;
 			boolean cbWasActive = true;
 			if(persistent) {
@@ -1132,7 +1132,7 @@
 				cbWasActive = container.ext().isActive(rcb);
 				container.activate(rcb, 1);
 			}
-			rcb.onExpectedSize(size, container);
+			rcb.onExpectedSize(size, container, context);
 			if(!wasActive)
 				container.deactivate(SingleFileFetcher.this, 1);
 			if(!cbWasActive)

Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -181,10 +181,10 @@
 			if(!wasActive)
 				container.activate(cb, 1);
 		}
-		cb.onExpectedSize(eventualLength, container);
+		cb.onExpectedSize(eventualLength, container, context);
 		String mimeType = metadata.getMIMEType();
 		if(mimeType != null)
-			cb.onExpectedMIME(mimeType, container);
+			cb.onExpectedMIME(mimeType, container, context);
 		if(metadata.uncompressedDataLength() > 0)
 			cb.onFinalizedMetadata(container);
 		if(!wasActive)

Modified: trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -60,11 +60,11 @@
 		return super.toString()+ ':' +usk;
 	}
 
-	public void onExpectedMIME(String mime, ObjectContainer container) {
+	public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 		// Ignore
 	}
 
-	public void onExpectedSize(long size, ObjectContainer container) {
+	public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 		// Ignore
 	}
 

Modified: trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -67,16 +67,16 @@
 		// Ignore
 	}
 
-	public void onExpectedMIME(String mime, ObjectContainer container) {
+	public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 		if(container != null && persistent)
 			container.activate(cb, 1);
-		cb.onExpectedMIME(mime, container);
+		cb.onExpectedMIME(mime, container, context);
 	}
 
-	public void onExpectedSize(long size, ObjectContainer container) {
+	public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 		if(container != null && persistent)
 			container.activate(cb, 1);
-		cb.onExpectedSize(size, container);
+		cb.onExpectedSize(size, container, context);
 	}
 
 	public void onFinalizedMetadata(ObjectContainer container) {

Modified: trunk/freenet/src/freenet/client/async/USKRetriever.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetriever.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/client/async/USKRetriever.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -98,11 +98,11 @@
 		// Ignore
 	}
 
-	public void onExpectedMIME(String mime, ObjectContainer container) {
+	public void onExpectedMIME(String mime, ObjectContainer container, ClientContext context) {
 		// Ignore
 	}
 
-	public void onExpectedSize(long size, ObjectContainer container) {
+	public void onExpectedSize(long size, ObjectContainer container, ClientContext context) {
 		// Ignore
 	}
 

Modified: trunk/freenet/src/freenet/clients/http/FProxyFetchInProgress.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyFetchInProgress.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/clients/http/FProxyFetchInProgress.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -15,6 +15,8 @@
 import freenet.client.async.ClientGetter;
 import freenet.client.events.ClientEvent;
 import freenet.client.events.ClientEventListener;
+import freenet.client.events.ExpectedFileSizeEvent;
+import freenet.client.events.ExpectedMIMEEvent;
 import freenet.client.events.SendingToNetworkEvent;
 import freenet.client.events.SplitfileProgressEvent;
 import freenet.keys.FreenetURI;
@@ -154,6 +156,14 @@
 				goneToNetwork = true;
 				fetchedBlocksPreNetwork = fetchedBlocks;
 			}
+		} else if(ce instanceof ExpectedMIMEEvent) {
+			synchronized(this) {
+				this.mimeType = ((ExpectedMIMEEvent)ce).expectedMIMEType;
+			}
+		} else if(ce instanceof ExpectedFileSizeEvent) {
+			synchronized(this) {
+				this.size = ((ExpectedFileSizeEvent)ce).expectedSize;
+			}
 		} else return;
 		wakeWaiters(false);
 	}

Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java	2009-04-21 19:34:12 UTC (rev 27168)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java	2009-04-21 21:43:47 UTC (rev 27169)
@@ -518,9 +518,10 @@
 				HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-information");
 				infobox.addChild("div", "class", "infobox-header", l10n("fetchingPageBox"));
 				HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
-				infoboxContent.addChild("#", "Filename: "+key.getPreferredFilename());
-				infoboxContent.addChild("br", "Key: "+key);
-				if(fr.mimeType != null) infoboxContent.addChild("p", "Content type: "+mimeType);
+				infoboxContent.addChild("#", "Filename: ");
+				infoboxContent.addChild("a", "href", "/"+key.toString(false, false), key.getPreferredFilename());
+				if(fr.mimeType != null) infoboxContent.addChild("br", "Content type: "+fr.mimeType);
+				if(fr.size > 0) infoboxContent.addChild("br", "Size: "+SizeUtil.formatSize(fr.size));
 				if(core.isAdvancedModeEnabled()) {
 					infoboxContent.addChild("br", "Blocks: need "+fr.requiredBlocks+" total "+fr.totalBlocks+" fetched "+fr.fetchedBlocks+" failed "+fr.failedBlocks+" fatally failed "+fr.fatallyFailedBlocks);
 				}
@@ -596,7 +597,7 @@
 		try {
 			if(Logger.shouldLog(Logger.MINOR, this))
 				Logger.minor(this, "FProxy fetching "+key+" ("+maxSize+ ')');
-			if(data == null) {
+			if(data == null && fe == null) {
 			FetchResult result = fetch(key, maxSize, new RequestClient() {
 				public boolean persistent() {
 					return false;