Author: saces
Date: 2008-11-11 19:45:03 +0000 (Tue, 11 Nov 2008)
New Revision: 23490
Modified:
trunk/plugins/KeyExplorer/KeyExplorer.java
trunk/plugins/KeyExplorer/VerySimpleGet.java
trunk/plugins/KeyExplorer/VerySimpleGetter.java
Log:
Version 0.3: support for new container types
fixes, anotations.
Modified: trunk/plugins/KeyExplorer/KeyExplorer.java
===================================================================
--- trunk/plugins/KeyExplorer/KeyExplorer.java 2008-11-11 19:19:37 UTC (rev
23489)
+++ trunk/plugins/KeyExplorer/KeyExplorer.java 2008-11-11 19:45:03 UTC (rev
23490)
@@ -12,6 +12,9 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.apache.tools.tar.TarEntry;
+import org.apache.tools.tar.TarInputStream;
+
import freenet.client.FetchContext;
import freenet.client.FetchException;
import freenet.client.FetchResult;
@@ -54,11 +57,14 @@
public String handleHTTPGet(HTTPRequest request) throws
PluginHTTPException {
String uri = request.getParam("key");
String type = request.getParam("type");
- if ("zipmanifest".equals(type)) {
- return makeManifestPage(uri, false);
+ if ("ZIPmanifest".equals(type)) {
+ return makeManifestPage(uri, true, false);
}
+ if ("TARmanifest".equals(type)) {
+ return makeManifestPage(uri, false, true);
+ }
if ("simplemanifest".equals(type)) {
- return makeManifestPage(uri, true);
+ return makeManifestPage(uri, false, false);
}
return makeMainPage(uri);
}
@@ -154,10 +160,6 @@
replysender.send(sfs);
}
- private String makeMainPage() {
- return makeMainPage(null);
- }
-
private String makeMainPage(String key) {
HTMLNode pageNode = m_pm.getPageNode("KeyExplorer", null);
HTMLNode contentNode = m_pm.getContentNode(pageNode);
@@ -303,7 +305,7 @@
if (md.isArchiveManifest()) {
metaBox.addChild("#", "Document
type: ArchiveManifest");
metaBox.addChild("#", "\u00a0");
- metaBox.addChild(new
HTMLNode("a", "href",
"/plugins/plugins.KeyExplorer.KeyExplorer/?type=zipmanifest&key=" + furi,
+ metaBox.addChild(new
HTMLNode("a", "href",
"/plugins/plugins.KeyExplorer.KeyExplorer/?type="+md.getArchiveType().name()+"manifest&key="
+ furi,
"reopen as manifest"));
metaBox.addChild("%", "<BR />");
}
@@ -311,7 +313,7 @@
if (!md.isCompressed()) {
metaBox.addChild("#",
"Uncompressed");
} else {
- metaBox.addChild("#",
"Compressed (codec " + md.getCompressionCodec() + ")");
+ metaBox.addChild("#",
"Compressed (codec " + md.getCompressionCodec().name + ")");
metaBox.addChild("%", "<BR />");
metaBox.addChild("#",
"Decompressed size: " + md.uncompressedDataLength() + " bytes");
}
@@ -334,7 +336,7 @@
return pageNode.generate();
}
- private String makeManifestPage(String key, boolean simple) {
+ private String makeManifestPage(String key, boolean zip, boolean tar) {
HTMLNode pageNode = m_pm.getPageNode("KeyExplorer", null);
HTMLNode contentNode = m_pm.getContentNode(pageNode);
@@ -350,10 +352,13 @@
ClientKey tempKey = tempUSK.getSSK();
furi = tempKey.getURI();
}
- if (simple)
+
+ if (zip)
+ metadata = zipManifestGet(furi);
+ else if (tar)
+ metadata = tarManifestGet(furi);
+ else
metadata = simpleManifestGet(furi);
- else
- metadata = zipManifestGet(furi);
} catch (MalformedURLException e) {
error = "MalformedURL";
} catch (FetchException e) {
@@ -386,10 +391,10 @@
}
private void parseMetadata(HTMLNode htmlnode, HashMap<String, Metadata>
docs, String prefix, String furi) {
- Set s = docs.keySet();
- Iterator i = s.iterator();
+ Set<String> s = docs.keySet();
+ Iterator<String> i = s.iterator();
while (i.hasNext()) {
- String name = (String) i.next();
+ String name = i.next();
Metadata md = docs.get(name);
String fname = prefix + name;
if (md.isArchiveInternalRedirect()) {
@@ -436,7 +441,7 @@
}
public String getVersion() {
- return "0.2 r"+ Version.svnRevision;
+ return "0.3 r"+ Version.svnRevision;
}
private Metadata simpleManifestGet(FreenetURI uri) throws
MetadataParseException, LowLevelGetException, IOException {
@@ -451,6 +456,7 @@
HighLevelSimpleClient hlsc = m_pr.getHLSimpleClient();
FetchContext fctx = hlsc.getFetchContext();
fctx.returnZIPManifests = true;
+ //fctx.r
FetchWaiter fw = new FetchWaiter();
hlsc.fetch(uri, -1, this, fw, fctx);
FetchResult fr = fw.waitForCompletion();
@@ -476,7 +482,39 @@
}
throw new FetchException(200, "impossible? no metadata in
archive " + uri);
}
+
+ private Metadata tarManifestGet(FreenetURI uri) throws FetchException,
MetadataParseException, IOException{
+ HighLevelSimpleClient hlsc = m_pr.getHLSimpleClient();
+ FetchContext fctx = hlsc.getFetchContext();
+ fctx.returnZIPManifests = true;
+ //fctx.r
+ FetchWaiter fw = new FetchWaiter();
+ hlsc.fetch(uri, -1, this, fw, fctx);
+ FetchResult fr = fw.waitForCompletion();
+ TarInputStream zis = new
TarInputStream(fr.asBucket().getInputStream());
+ TarEntry entry;
+ ByteArrayOutputStream bos;
+ while(true) {
+ entry = zis.getNextEntry();
+ if(entry == null) break;
+ if(entry.isDirectory()) continue;
+ String name = entry.getName();
+ if(".metadata".equals(name)) {
+ byte[] buf = new byte[32768];
+ bos = new ByteArrayOutputStream();
+ // Read the element
+ int readBytes;
+ while((readBytes = zis.read(buf)) > 0) {
+ bos.write(buf, 0, readBytes);
+ }
+ bos.close();
+ return Metadata.construct(bos.toByteArray());
+ }
+ }
+ throw new FetchException(200, "impossible? no metadata in
archive " + uri);
+ }
+
public String getString(String key) {
// TODO Auto-generated method stub
return key;
Modified: trunk/plugins/KeyExplorer/VerySimpleGet.java
===================================================================
--- trunk/plugins/KeyExplorer/VerySimpleGet.java 2008-11-11 19:19:37 UTC
(rev 23489)
+++ trunk/plugins/KeyExplorer/VerySimpleGet.java 2008-11-11 19:45:03 UTC
(rev 23490)
@@ -34,13 +34,14 @@
super(key2, maxRetries2, ctx2, parent2);
}
+ @Override
public void onFailure(LowLevelGetException e, Object token,
RequestScheduler sched) {
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
if (logMINOR)
Logger.minor(this, "onFailure( " + e + " , ...)", e);
- if (!(isFatalError(e.code))) {
+ if ((!isFatalError(e.code)) && (sched != null)) {
if (retry(sched, getContext().executor)) {
if (logMINOR)
Logger.minor(this, "Retrying");
@@ -54,6 +55,7 @@
}
}
+ @Override
public void onSuccess(ClientKeyBlock block, boolean fromStore,
Object token, RequestScheduler scheduler) {
data = extract(block);
Modified: trunk/plugins/KeyExplorer/VerySimpleGetter.java
===================================================================
--- trunk/plugins/KeyExplorer/VerySimpleGetter.java 2008-11-11 19:19:37 UTC
(rev 23489)
+++ trunk/plugins/KeyExplorer/VerySimpleGetter.java 2008-11-11 19:45:03 UTC
(rev 23490)
@@ -29,19 +29,23 @@
uri = uri2;
}
+ @Override
public FreenetURI getURI() {
return uri;
}
+ @Override
public boolean isFinished() {
Logger.error(this, "TODO?", new Error("TODO?"));
return false;
}
+ @Override
public void notifyClients() {
Logger.error(this, "TODO?", new Error("TODO?"));
}
+ @Override
public void onTransition(ClientGetState oldState, ClientGetState
newState) {
Logger.error(this, "TODO?", new Error("TODO?"));
}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs