forked from I2P_Developers/i2p.i2p
use the logger, not stdout/stderr
This commit is contained in:
@@ -16,7 +16,7 @@ class ArchiveIndexer {
|
||||
private static final int RECENT_ENTRY_COUNT = 10;
|
||||
|
||||
public static ArchiveIndex index(I2PAppContext ctx, Archive source) {
|
||||
LocalArchiveIndex rv = new LocalArchiveIndex();
|
||||
LocalArchiveIndex rv = new LocalArchiveIndex(ctx);
|
||||
rv.setGeneratedOn(ctx.clock().now());
|
||||
|
||||
File rootDir = source.getArchiveDir();
|
||||
@@ -54,7 +54,7 @@ class ArchiveIndexer {
|
||||
long totalSize = 0;
|
||||
int newBlogs = 0;
|
||||
|
||||
SMLParser parser = new SMLParser();
|
||||
SMLParser parser = new SMLParser(ctx);
|
||||
|
||||
for (int i = 0; i < blogs.size(); i++) {
|
||||
BlogInfo cur = (BlogInfo)blogs.get(i);
|
||||
|
||||
@@ -111,7 +111,7 @@ public class CLI {
|
||||
entryKey = new SessionKey(Base64.decode(args[5]));
|
||||
EntryContainer entry = mgr.getArchive().getEntry(new BlogURI(new Hash(Base64.decode(args[2])), id), entryKey);
|
||||
if (entry != null) {
|
||||
HTMLRenderer renderer = new HTMLRenderer();
|
||||
HTMLRenderer renderer = new HTMLRenderer(I2PAppContext.getGlobalContext());
|
||||
boolean summaryOnly = "true".equalsIgnoreCase(args[5]);
|
||||
boolean showImages = "true".equalsIgnoreCase(args[6]);
|
||||
try {
|
||||
|
||||
@@ -7,11 +7,14 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.Archive;
|
||||
import net.i2p.syndie.BlogManager;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Simple read-only summary of an archive
|
||||
*/
|
||||
public class ArchiveIndex {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
protected String _version;
|
||||
protected long _generatedOn;
|
||||
protected int _allBlogs;
|
||||
@@ -31,9 +34,14 @@ public class ArchiveIndex {
|
||||
protected Properties _headers;
|
||||
|
||||
public ArchiveIndex() {
|
||||
this(false); //true);
|
||||
this(I2PAppContext.getGlobalContext(), false);
|
||||
}
|
||||
public ArchiveIndex(boolean shouldLoad) {
|
||||
public ArchiveIndex(I2PAppContext ctx) {
|
||||
this(ctx, false); //true);
|
||||
}
|
||||
public ArchiveIndex(I2PAppContext ctx, boolean shouldLoad) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(ArchiveIndex.class);
|
||||
_blogs = new ArrayList();
|
||||
_newestBlogs = new ArrayList();
|
||||
_newestEntries = new ArrayList();
|
||||
@@ -278,7 +286,8 @@ public class ArchiveIndex {
|
||||
}
|
||||
if (tag != null) {
|
||||
if (!tag.equals(summary.tag)) {
|
||||
System.out.println("Tag [" + summary.tag + "] does not match the requested [" + tag + "] in " + summary.blog.toBase64());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Tag [" + summary.tag + "] does not match the requested [" + tag + "] in " + summary.blog.toBase64());
|
||||
if (false) {
|
||||
StringBuffer b = new StringBuffer(tag.length()*2);
|
||||
for (int j = 0; j < tag.length(); j++) {
|
||||
@@ -290,7 +299,8 @@ public class ArchiveIndex {
|
||||
b.append('_');
|
||||
b.append(' ');
|
||||
}
|
||||
System.out.println("tag.summary: " + b.toString());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("tag.summary: " + b.toString());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Blog metadata. Formatted as: <pre>
|
||||
@@ -57,12 +58,14 @@ public class BlogInfo {
|
||||
public static final String EDITION = "Edition";
|
||||
|
||||
public void load(InputStream in) throws IOException {
|
||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(getClass());
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||
List names = new ArrayList();
|
||||
List vals = new ArrayList();
|
||||
String line = null;
|
||||
while ( (line = reader.readLine()) != null) {
|
||||
System.err.println("Read info line [" + line + "]");
|
||||
if (log.shouldLog(Log.DEBUG))
|
||||
log.debug("Read info line [" + line + "]");
|
||||
line = line.trim();
|
||||
int len = line.length();
|
||||
int split = line.indexOf(':');
|
||||
@@ -84,7 +87,7 @@ public class BlogInfo {
|
||||
for (int i = 0; i < _optionNames.length; i++) {
|
||||
_optionNames[i] = (String)names.get(i);
|
||||
_optionValues[i] = (String)vals.get(i);
|
||||
System.out.println("Loaded info: [" + _optionNames[i] + "] = [" + _optionValues[i] + "]");
|
||||
//System.out.println("Loaded info: [" + _optionNames[i] + "] = [" + _optionValues[i] + "]");
|
||||
}
|
||||
|
||||
String keyStr = getProperty(OWNER_KEY);
|
||||
@@ -119,12 +122,12 @@ public class BlogInfo {
|
||||
for (int i = 0; i < _optionNames.length; i++) {
|
||||
if (_optionNames[i].equals(name)) {
|
||||
String val = _optionValues[i];
|
||||
System.out.println("getProperty[" + name + "] = [" + val + "] [sz=" + val.length() +"]");
|
||||
for (int j = 0; j < val.length(); j++) {
|
||||
char c = (char)val.charAt(j);
|
||||
if (c != (c & 0x7F))
|
||||
System.out.println("char " + j + ": " + (int)c);
|
||||
}
|
||||
//System.out.println("getProperty[" + name + "] = [" + val + "] [sz=" + val.length() +"]");
|
||||
//for (int j = 0; j < val.length(); j++) {
|
||||
// char c = (char)val.charAt(j);
|
||||
// if (c != (c & 0x7F))
|
||||
// System.out.println("char " + j + ": " + (int)c);
|
||||
//}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.zip.*;
|
||||
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Securely wrap up an entry and any attachments. Container format:<pre>
|
||||
@@ -166,7 +167,9 @@ public class EntryContainer {
|
||||
}
|
||||
|
||||
public void seal(I2PAppContext ctx, SigningPrivateKey signingKey, SessionKey entryKey) throws IOException {
|
||||
System.out.println("Sealing " + _entryURI);
|
||||
Log l = ctx.logManager().getLog(getClass());
|
||||
if (l.shouldLog(Log.DEBUG))
|
||||
l.debug("Sealing " + _entryURI);
|
||||
if (entryKey == null)
|
||||
_format = FORMAT_ZIP_UNENCRYPTED;
|
||||
else
|
||||
@@ -272,10 +275,13 @@ public class EntryContainer {
|
||||
for (int i = 0; i < attachments.size(); i++) {
|
||||
byte data[] = (byte[])attachments.get(ZIP_ATTACHMENT_PREFIX + i + ZIP_ATTACHMENT_SUFFIX);
|
||||
byte metadata[] = (byte[])attachmentMeta.get(ZIP_ATTACHMENT_META_PREFIX + i + ZIP_ATTACHMENT_META_SUFFIX);
|
||||
if ( (data != null) && (metadata != null) )
|
||||
if ( (data != null) && (metadata != null) ) {
|
||||
_attachments[i] = new Attachment(data, metadata);
|
||||
else
|
||||
System.out.println("Unable to get " + i + ": " + data + "/" + metadata);
|
||||
} else {
|
||||
Log l = ctx.logManager().getLog(getClass());
|
||||
if (l.shouldLog(Log.WARN))
|
||||
l.warn("Unable to get " + i + ": " + data + "/" + metadata);
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.println("Attachments: " + _attachments.length + "/" + attachments.size() + ": " + attachments);
|
||||
@@ -348,8 +354,6 @@ public class EntryContainer {
|
||||
String idVal = getHeader(HEADER_ENTRYID);
|
||||
|
||||
if (keyHash == null) {
|
||||
System.err.println("Headers: " + _rawKeys);
|
||||
System.err.println("Values : " + _rawValues);
|
||||
throw new IOException("Missing " + HEADER_BLOGKEY + " header");
|
||||
}
|
||||
|
||||
@@ -358,8 +362,6 @@ public class EntryContainer {
|
||||
try {
|
||||
entryId = Long.parseLong(idVal.trim());
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.err.println("Headers: " + _rawKeys);
|
||||
System.err.println("Values : " + _rawValues);
|
||||
throw new IOException("Invalid format of entryId (" + idVal + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package net.i2p.syndie.data;
|
||||
|
||||
import java.util.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.Archive;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* writable archive index (most are readonly)
|
||||
*/
|
||||
public class LocalArchiveIndex extends ArchiveIndex {
|
||||
|
||||
public LocalArchiveIndex() {
|
||||
super(false);
|
||||
private Log _log;
|
||||
public LocalArchiveIndex(I2PAppContext ctx) {
|
||||
super(ctx, false);
|
||||
_log = ctx.logManager().getLog(getClass());
|
||||
}
|
||||
|
||||
public void setGeneratedOn(long when) { _generatedOn = when; }
|
||||
@@ -46,7 +49,8 @@ public class LocalArchiveIndex extends ArchiveIndex {
|
||||
if (summary.blog.equals(key) && (summary.tag.equals(tag)) ) {
|
||||
long entryId = Archive.getEntryIdFromIndexName(entry);
|
||||
int kb = Archive.getSizeFromIndexName(entry);
|
||||
System.out.println("Adding entry " + entryId + ", size=" + kb + "KB [" + entry + "]");
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Adding entry " + entryId + ", size=" + kb + "KB [" + entry + "]");
|
||||
EntrySummary entrySummary = new EntrySummary(new BlogURI(key, entryId), kb);
|
||||
for (int j = 0; j < summary.entries.size(); j++) {
|
||||
EntrySummary cur = (EntrySummary)summary.entries.get(j);
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.i2p.syndie.BlogManager;
|
||||
* Simple read-only summary of an archive, proxied to the BlogManager's instance
|
||||
*/
|
||||
public class TransparentArchiveIndex extends ArchiveIndex {
|
||||
public TransparentArchiveIndex() { super(false); }
|
||||
public TransparentArchiveIndex() { super(I2PAppContext.getGlobalContext(), false); }
|
||||
|
||||
private static ArchiveIndex index() { return BlogManager.instance().getArchive().getIndex(); }
|
||||
|
||||
|
||||
@@ -1,52 +1,108 @@
|
||||
package net.i2p.syndie.sml;
|
||||
|
||||
import java.util.List;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EventReceiverImpl implements SMLParser.EventReceiver {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
|
||||
public EventReceiverImpl(I2PAppContext ctx) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(EventReceiverImpl.class);
|
||||
}
|
||||
public void receiveHeader(String header, String value) {
|
||||
System.out.println("Receive header [" + header + "] = [" + value + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive header [" + header + "] = [" + value + "]");
|
||||
}
|
||||
public void receiveLink(String schema, String location, String text) {
|
||||
System.out.println("Receive link [" + schema + "]/[" + location+ "]/[" + text + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive link [" + schema + "]/[" + location+ "]/[" + text + "]");
|
||||
}
|
||||
public void receiveBlog(String name, String blogKeyHash, String blogPath, long blogEntryId,
|
||||
List blogArchiveLocations, String anchorText) {
|
||||
System.out.println("Receive blog [" + name + "]/[" + blogKeyHash + "]/[" + blogPath
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive blog [" + name + "]/[" + blogKeyHash + "]/[" + blogPath
|
||||
+ "]/[" + blogEntryId + "]/[" + blogArchiveLocations + "]/[" + anchorText + "]");
|
||||
}
|
||||
public void receiveArchive(String name, String description, String locationSchema, String location,
|
||||
String postingKey, String anchorText) {
|
||||
System.out.println("Receive archive [" + name + "]/[" + description + "]/[" + locationSchema
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive archive [" + name + "]/[" + description + "]/[" + locationSchema
|
||||
+ "]/[" + location + "]/[" + postingKey + "]/[" + anchorText + "]");
|
||||
}
|
||||
public void receiveImage(String alternateText, int attachmentId) {
|
||||
System.out.println("Receive image [" + alternateText + "]/[" + attachmentId + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive image [" + alternateText + "]/[" + attachmentId + "]");
|
||||
}
|
||||
public void receiveAddress(String name, String schema, String protocol, String location, String anchorText) {
|
||||
System.out.println("Receive address [" + name + "]/[" + schema + "]/[" + location + "]/[" + anchorText+ "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive address [" + name + "]/[" + schema + "]/[" + location + "]/[" + anchorText+ "]");
|
||||
}
|
||||
public void receiveBold(String text) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive bold [" + text+ "]");
|
||||
}
|
||||
public void receiveItalic(String text) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive italic [" + text+ "]");
|
||||
}
|
||||
public void receiveUnderline(String text) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive underline [" + text+ "]");
|
||||
}
|
||||
public void receiveBold(String text) { System.out.println("Receive bold [" + text+ "]"); }
|
||||
public void receiveItalic(String text) { System.out.println("Receive italic [" + text+ "]"); }
|
||||
public void receiveUnderline(String text) { System.out.println("Receive underline [" + text+ "]"); }
|
||||
public void receiveQuote(String text, String whoQuoted, String quoteLocationSchema, String quoteLocation) {
|
||||
System.out.println("Receive quote [" + text + "]/[" + whoQuoted + "]/[" + quoteLocationSchema + "]/[" + quoteLocation + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive quote [" + text + "]/[" + whoQuoted + "]/[" + quoteLocationSchema + "]/[" + quoteLocation + "]");
|
||||
}
|
||||
public void receiveCode(String text, String codeLocationSchema, String codeLocation) {
|
||||
System.out.println("Receive code [" + text+ "]/[" + codeLocationSchema + "]/[" + codeLocation + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive code [" + text+ "]/[" + codeLocationSchema + "]/[" + codeLocation + "]");
|
||||
}
|
||||
public void receiveCut(String summaryText) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive cut [" + summaryText + "]");
|
||||
}
|
||||
public void receivePlain(String text) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive plain [" + text + "]");
|
||||
}
|
||||
public void receiveNewline() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive NL");
|
||||
}
|
||||
public void receiveLT() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive LT");
|
||||
}
|
||||
public void receiveGT() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive GT");
|
||||
}
|
||||
public void receiveBegin() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive begin");
|
||||
}
|
||||
public void receiveEnd() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive end");
|
||||
}
|
||||
public void receiveHeaderEnd() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive header end");
|
||||
}
|
||||
public void receiveLeftBracket() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive [");
|
||||
}
|
||||
public void receiveRightBracket() {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receive ]");
|
||||
}
|
||||
public void receiveCut(String summaryText) { System.out.println("Receive cut [" + summaryText + "]"); }
|
||||
public void receivePlain(String text) { System.out.println("Receive plain [" + text + "]"); }
|
||||
public void receiveNewline() { System.out.println("Receive NL"); }
|
||||
public void receiveLT() { System.out.println("Receive LT"); }
|
||||
public void receiveGT() { System.out.println("Receive GT"); }
|
||||
public void receiveBegin() { System.out.println("Receive begin"); }
|
||||
public void receiveEnd() { System.out.println("Receive end"); }
|
||||
public void receiveHeaderEnd() { System.out.println("Receive header end"); }
|
||||
public void receiveLeftBracket() { System.out.println("Receive ["); }
|
||||
public void receiveRightBracket() { System.out.println("Receive ]"); }
|
||||
|
||||
public void receiveH1(String text) {}
|
||||
public void receiveH2(String text) {}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.i2p.syndie.sml;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
@@ -16,8 +17,8 @@ public class HTMLPreviewRenderer extends HTMLRenderer {
|
||||
private List _fileTypes;
|
||||
private List _files;
|
||||
|
||||
public HTMLPreviewRenderer(List filenames, List fileTypes, List files) {
|
||||
super();
|
||||
public HTMLPreviewRenderer(I2PAppContext ctx, List filenames, List fileTypes, List files) {
|
||||
super(ctx);
|
||||
_filenames = filenames;
|
||||
_fileTypes = fileTypes;
|
||||
_files = files;
|
||||
|
||||
@@ -3,15 +3,18 @@ package net.i2p.syndie.sml;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
import net.i2p.syndie.web.*;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class HTMLRenderer extends EventReceiverImpl {
|
||||
private Log _log;
|
||||
protected SMLParser _parser;
|
||||
protected Writer _out;
|
||||
protected User _user;
|
||||
@@ -31,8 +34,10 @@ public class HTMLRenderer extends EventReceiverImpl {
|
||||
protected StringBuffer _bodyBuffer;
|
||||
protected StringBuffer _postBodyBuffer;
|
||||
|
||||
public HTMLRenderer() {
|
||||
_parser = new SMLParser();
|
||||
public HTMLRenderer(I2PAppContext ctx) {
|
||||
super(ctx);
|
||||
_log = ctx.logManager().getLog(HTMLRenderer.class);
|
||||
_parser = new SMLParser(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +48,7 @@ public class HTMLRenderer extends EventReceiverImpl {
|
||||
System.err.println("Usage: HTMLRenderer smlFile outputFile");
|
||||
return;
|
||||
}
|
||||
HTMLRenderer renderer = new HTMLRenderer();
|
||||
HTMLRenderer renderer = new HTMLRenderer(I2PAppContext.getGlobalContext());
|
||||
Writer out = null;
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024*512);
|
||||
@@ -296,7 +301,8 @@ public class HTMLRenderer extends EventReceiverImpl {
|
||||
*
|
||||
*/
|
||||
public void receiveBlog(String name, String hash, String tag, long entryId, List locations, String description) {
|
||||
System.out.println("Receiving the blog: " + name + "/" + hash + "/" + tag + "/" + entryId +"/" + locations + ": "+ description);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receiving the blog: " + name + "/" + hash + "/" + tag + "/" + entryId +"/" + locations + ": "+ description);
|
||||
byte blogData[] = Base64.decode(hash);
|
||||
if ( (blogData == null) || (blogData.length != Hash.HASH_LENGTH) )
|
||||
return;
|
||||
@@ -446,7 +452,8 @@ public class HTMLRenderer extends EventReceiverImpl {
|
||||
_bodyBuffer.append(getSpan("addr")).append(sanitizeString(anchorText)).append("</span>");
|
||||
_bodyBuffer.append(getSpan("addrKnownName")).append("(").append(sanitizeString(knownName)).append(")</span>");
|
||||
} else {
|
||||
System.err.println("Receiving address [" + location + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Receiving address [" + location + "]");
|
||||
_bodyBuffer.append("<a ").append(getClass("addrAdd")).append(" href=\"addresses.jsp?");
|
||||
if (schema != null)
|
||||
_bodyBuffer.append("network=").append(sanitizeTagParam(schema)).append('&');
|
||||
@@ -829,7 +836,8 @@ public class HTMLRenderer extends EventReceiverImpl {
|
||||
long dayBegin = _dateFormat.parse(str).getTime();
|
||||
return str + " [" + (when - dayBegin) + "]";
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error formatting", pe);
|
||||
// wtf
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.i2p.syndie.sml;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
@@ -12,6 +13,10 @@ import net.i2p.syndie.data.*;
|
||||
*/
|
||||
public class RSSRenderer extends HTMLRenderer {
|
||||
|
||||
public RSSRenderer(I2PAppContext ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
public void render(User user, Archive archive, EntryContainer entry, String urlPrefix, Writer out) throws IOException {
|
||||
if (entry == null) return;
|
||||
prepare(user, archive, entry, entry.getEntry().getText(), out, true, false);
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.i2p.syndie.sml;
|
||||
import java.lang.String;
|
||||
import java.util.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Parse out the SML from the text, firing off info to the receiver whenever certain
|
||||
@@ -12,6 +14,7 @@ import net.i2p.syndie.data.*;
|
||||
*
|
||||
*/
|
||||
public class SMLParser {
|
||||
private Log _log;
|
||||
private static final char TAG_BEGIN = '[';
|
||||
private static final char TAG_END = ']';
|
||||
private static final char LT = '<';
|
||||
@@ -23,6 +26,10 @@ public class SMLParser {
|
||||
private static final char NL = '\n';
|
||||
private static final char CR = '\n';
|
||||
private static final char LF = '\f';
|
||||
|
||||
public SMLParser(I2PAppContext ctx) {
|
||||
_log = ctx.logManager().getLog(SMLParser.class);
|
||||
}
|
||||
|
||||
public void parse(String rawSML, EventReceiver receiver) {
|
||||
receiver.receiveBegin();
|
||||
@@ -273,7 +280,8 @@ public class SMLParser {
|
||||
} else if (T_ATTACHMENT.equals(tagName)) {
|
||||
receiver.receiveAttachment((int)getLong(P_ATTACHMENT_ID, attr), body);
|
||||
} else {
|
||||
System.out.println("need to learn how to parse the tag [" + tagName + "]");
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("need to learn how to parse the tag [" + tagName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +445,8 @@ public class SMLParser {
|
||||
test("A: B\n\n[b]This[/b] is [i]special[/i][cut]why?[/cut][u]because I say so[/u].\neven if you dont care");
|
||||
}
|
||||
private static void test(String rawSML) {
|
||||
SMLParser parser = new SMLParser();
|
||||
parser.parse(rawSML, new EventReceiverImpl());
|
||||
I2PAppContext ctx = I2PAppContext.getGlobalContext();
|
||||
SMLParser parser = new SMLParser(ctx);
|
||||
parser.parse(rawSML, new EventReceiverImpl(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,12 +297,12 @@ public class ArchiveViewerBean {
|
||||
if (selector != null) {
|
||||
if (selector.startsWith(SEL_BLOG)) {
|
||||
String blogStr = selector.substring(SEL_BLOG.length());
|
||||
System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "]");
|
||||
//System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "]");
|
||||
byte h[] = Base64.decode(blogStr);
|
||||
if (h != null)
|
||||
blog = new Hash(h);
|
||||
else
|
||||
System.out.println("blog string does not decode properly: [" + blogStr + "]");
|
||||
//else
|
||||
// System.out.println("blog string does not decode properly: [" + blogStr + "]");
|
||||
} else if (selector.startsWith(SEL_BLOGTAG)) {
|
||||
int tagStart = selector.lastIndexOf('/');
|
||||
String blogStr = selector.substring(SEL_BLOGTAG.length(), tagStart);
|
||||
@@ -319,7 +319,7 @@ public class ArchiveViewerBean {
|
||||
rawDecode = Base64.decode(tag);
|
||||
tag = DataHelper.getUTF8(rawDecode);
|
||||
}
|
||||
System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "] tag: [" + tag + "]");
|
||||
//System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "] tag: [" + tag + "]");
|
||||
if (false && tag != null) {
|
||||
StringBuffer b = new StringBuffer(tag.length()*2);
|
||||
for (int j = 0; j < tag.length(); j++) {
|
||||
@@ -332,7 +332,7 @@ public class ArchiveViewerBean {
|
||||
for (int j = 0; j < origTag.length(); j++) {
|
||||
b.append((int)origTag.charAt(j)).append(' ');
|
||||
}
|
||||
System.out.println("selected tag: " + b.toString());
|
||||
//System.out.println("selected tag: " + b.toString());
|
||||
}
|
||||
} else if (selector.startsWith(SEL_TAG)) {
|
||||
tag = selector.substring(SEL_TAG.length());
|
||||
@@ -341,7 +341,7 @@ public class ArchiveViewerBean {
|
||||
rawDecode = Base64.decode(tag);
|
||||
tag = DataHelper.getUTF8(rawDecode);
|
||||
}
|
||||
System.out.println("Selector [" + selector + "] tag: [" + tag + "]");
|
||||
//System.out.println("Selector [" + selector + "] tag: [" + tag + "]");
|
||||
if (false && tag != null) {
|
||||
StringBuffer b = new StringBuffer(tag.length()*2);
|
||||
for (int j = 0; j < tag.length(); j++) {
|
||||
@@ -350,7 +350,7 @@ public class ArchiveViewerBean {
|
||||
b.append('.').append((int)rawDecode[j]);
|
||||
b.append(' ');
|
||||
}
|
||||
System.out.println("selected tag: " + b.toString());
|
||||
//System.out.println("selected tag: " + b.toString());
|
||||
}
|
||||
} else if (selector.startsWith(SEL_ENTRY)) {
|
||||
int entryStart = selector.lastIndexOf('/');
|
||||
@@ -361,13 +361,13 @@ public class ArchiveViewerBean {
|
||||
Hash h = new Hash(Base64.decode(blogStr));
|
||||
if (h.getData() != null)
|
||||
blog = h;
|
||||
else
|
||||
System.out.println("Blog does not decode [" + blogStr + "]");
|
||||
System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "] entry: [" + entry + "]");
|
||||
//else
|
||||
// System.out.println("Blog does not decode [" + blogStr + "]");
|
||||
//System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "] entry: [" + entry + "]");
|
||||
} catch (NumberFormatException nfe) {}
|
||||
} else if (selector.startsWith(SEL_GROUP)) {
|
||||
group = DataHelper.getUTF8(Base64.decode(selector.substring(SEL_GROUP.length())));
|
||||
System.out.println("Selector [" + selector + "] group: [" + group + "]");
|
||||
//System.out.println("Selector [" + selector + "] group: [" + group + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,10 +380,10 @@ public class ArchiveViewerBean {
|
||||
archive.regenerateIndex();
|
||||
ArchiveIndex index = archive.getIndex();
|
||||
List entries = pickEntryURIs(user, index, blog, tag, entryId, group);
|
||||
System.out.println("Searching for " + blog + "/" + tag + "/" + entryId + "/" + pageNum + "/" + numPerPage + "/" + group);
|
||||
System.out.println("Entry URIs: " + entries);
|
||||
//System.out.println("Searching for " + blog + "/" + tag + "/" + entryId + "/" + pageNum + "/" + numPerPage + "/" + group);
|
||||
//System.out.println("Entry URIs: " + entries);
|
||||
|
||||
HTMLRenderer renderer = new HTMLRenderer();
|
||||
HTMLRenderer renderer = new HTMLRenderer(I2PAppContext.getGlobalContext());
|
||||
int start = pageNum * numPerPage;
|
||||
int end = start + numPerPage;
|
||||
int pages = 1;
|
||||
@@ -407,7 +407,7 @@ public class ArchiveViewerBean {
|
||||
prevURL = HTMLRenderer.getPageURL(blog, tag, entryId, group, numPerPage, pageNum-1, expandEntries, showImages);
|
||||
else
|
||||
prevURL = HTMLRenderer.getPageURL(user, selector, numPerPage, pageNum-1);
|
||||
System.out.println("prevURL: " + prevURL);
|
||||
//System.out.println("prevURL: " + prevURL);
|
||||
out.write(" <a class=\"b_selectorPrevMore\" href=\"" + prevURL + "\"><<</a>");
|
||||
} else {
|
||||
out.write(" <span class=\"b_selectorPrevNone\"><<</span> ");
|
||||
@@ -419,7 +419,7 @@ public class ArchiveViewerBean {
|
||||
nextURL = HTMLRenderer.getPageURL(blog, tag, entryId, group, numPerPage, pageNum+1, expandEntries, showImages);
|
||||
else
|
||||
nextURL = HTMLRenderer.getPageURL(user, selector, numPerPage, pageNum+1);
|
||||
System.out.println("nextURL: " + nextURL);
|
||||
//System.out.println("nextURL: " + nextURL);
|
||||
out.write(" <a class=\"b_selectorNextMore\" href=\"" + nextURL + "\">>></a>");
|
||||
} else {
|
||||
out.write(" <span class=\"b_selectorNextNone\">>></span>");
|
||||
@@ -451,7 +451,7 @@ public class ArchiveViewerBean {
|
||||
out.write(afterPagination);
|
||||
|
||||
if (entries.size() <= 0) end = -1;
|
||||
System.out.println("Entries.size: " + entries.size() + " start=" + start + " end=" + end);
|
||||
//System.out.println("Entries.size: " + entries.size() + " start=" + start + " end=" + end);
|
||||
for (int i = start; i < end; i++) {
|
||||
BlogURI uri = (BlogURI)entries.get(i);
|
||||
EntryContainer c = archive.getEntry(uri);
|
||||
@@ -479,7 +479,7 @@ public class ArchiveViewerBean {
|
||||
if ( (group != null) && (user != null) ) {
|
||||
List selectors = (List)user.getBlogGroups().get(group);
|
||||
if (selectors != null) {
|
||||
System.out.println("Selectors for group " + group + ": " + selectors);
|
||||
//System.out.println("Selectors for group " + group + ": " + selectors);
|
||||
for (int i = 0; i < selectors.size(); i++) {
|
||||
String sel = (String)selectors.get(i);
|
||||
Selector s = new Selector(sel);
|
||||
|
||||
@@ -2,14 +2,18 @@ package net.i2p.syndie.web;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.BlogURI;
|
||||
import net.i2p.syndie.sml.HTMLPreviewRenderer;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PostBean {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
private User _user;
|
||||
private String _subject;
|
||||
private String _tags;
|
||||
@@ -22,10 +26,15 @@ public class PostBean {
|
||||
private List _fileTypes;
|
||||
private boolean _previewed;
|
||||
|
||||
public PostBean() { reinitialize(); }
|
||||
public PostBean() {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_log = _context.logManager().getLog(PostBean.class);
|
||||
reinitialize();
|
||||
}
|
||||
|
||||
public void reinitialize() {
|
||||
System.out.println("Reinitializing " + (_text != null ? "(with " + _text.length() + " bytes of sml!)" : ""));
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Reinitializing " + (_text != null ? "(with " + _text.length() + " bytes of sml!)" : ""));
|
||||
_user = null;
|
||||
_subject = null;
|
||||
_tags = null;
|
||||
@@ -86,10 +95,12 @@ public class PostBean {
|
||||
}
|
||||
BlogURI uri = BlogManager.instance().createBlogEntry(_user, _subject, _tags, _headers, _text,
|
||||
_filenames, localStreams, _fileTypes);
|
||||
System.err.println("Posted the entry " + uri.toString() + " (archive = " + _archive + ")");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Posted the entry " + uri.toString() + " (archive = " + _archive + ")");
|
||||
if ( (uri != null) && (_user.getAllowAccessRemote()) ) {
|
||||
PetName pn = _user.getPetNameDB().get(_archive);
|
||||
System.err.println("Archive to petname? " + pn + " (protocol: " + (pn != null ? pn.getProtocol() : "") + ")");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Archive to petname? " + pn + " (protocol: " + (pn != null ? pn.getProtocol() : "") + ")");
|
||||
if ( (pn != null) && ("syndiearchive".equals(pn.getProtocol())) ) {
|
||||
RemoteArchiveBean r = new RemoteArchiveBean();
|
||||
Map params = new HashMap();
|
||||
@@ -98,24 +109,29 @@ public class PostBean {
|
||||
String port = BlogManager.instance().getDefaultProxyPort();
|
||||
int proxyPort = 4444;
|
||||
try { proxyPort = Integer.parseInt(port); } catch (NumberFormatException nfe) {}
|
||||
System.err.println("Posting the entry " + uri.toString() + " to " + pn.getLocation());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Posting the entry " + uri.toString() + " to " + pn.getLocation());
|
||||
r.postSelectedEntries(_user, params, proxyHost, proxyPort, pn.getLocation());
|
||||
System.err.println("Post status: " + r.getStatus());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Post status: " + r.getStatus());
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void renderPreview(Writer out) throws IOException {
|
||||
System.out.println("Subject: " + _subject);
|
||||
System.out.println("Text: " + _text);
|
||||
System.out.println("Headers: " + _headers);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Subject: " + _subject);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Text: " + _text);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Headers: " + _headers);
|
||||
// cache all the _fileStreams into temporary files, storing those files in _localFiles
|
||||
// then render the page accordingly with an HTMLRenderer, altered to use a different
|
||||
// 'view attachment'
|
||||
cacheAttachments();
|
||||
String smlContent = renderSMLContent();
|
||||
HTMLPreviewRenderer r = new HTMLPreviewRenderer(_filenames, _fileTypes, _localFiles);
|
||||
HTMLPreviewRenderer r = new HTMLPreviewRenderer(_context, _filenames, _fileTypes, _localFiles);
|
||||
r.render(_user, BlogManager.instance().getArchive(), null, smlContent, out, false, true);
|
||||
_previewed = true;
|
||||
}
|
||||
@@ -149,7 +165,8 @@ public class PostBean {
|
||||
o.close();
|
||||
in.close();
|
||||
_localFiles.add(f);
|
||||
System.out.println("Caching attachment " + i + " temporarily in "
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Caching attachment " + i + " temporarily in "
|
||||
+ f.getAbsolutePath() + " w/ " + f.length() + "bytes");
|
||||
}
|
||||
_fileStreams.clear();
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
@@ -73,7 +74,7 @@ public class RSSServlet extends HttpServlet {
|
||||
if (count < 0) count = 10;
|
||||
if (count > 100) count = 100;
|
||||
|
||||
RSSRenderer r = new RSSRenderer();
|
||||
RSSRenderer r = new RSSRenderer(I2PAppContext.getGlobalContext());
|
||||
for (int i = 0; i < count && i < entries.size(); i++) {
|
||||
BlogURI uri = (BlogURI)entries.get(i);
|
||||
EntryContainer entry = archive.getEntry(uri);
|
||||
|
||||
@@ -12,11 +12,14 @@ import net.i2p.util.EepPost;
|
||||
import net.i2p.syndie.data.*;
|
||||
import net.i2p.syndie.sml.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RemoteArchiveBean {
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
private String _remoteSchema;
|
||||
private String _remoteLocation;
|
||||
private String _proxyHost;
|
||||
@@ -27,6 +30,8 @@ public class RemoteArchiveBean {
|
||||
private boolean _exportCapable;
|
||||
|
||||
public RemoteArchiveBean() {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_log = _context.logManager().getLog(RemoteArchiveBean.class);
|
||||
reinitialize();
|
||||
}
|
||||
public void reinitialize() {
|
||||
@@ -311,7 +316,7 @@ public class RemoteArchiveBean {
|
||||
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile) {
|
||||
_statusMessages.add("Fetch of " + HTMLRenderer.sanitizeString(url) + " successful");
|
||||
_fetchIndexInProgress = false;
|
||||
ArchiveIndex i = new ArchiveIndex(false);
|
||||
ArchiveIndex i = new ArchiveIndex(I2PAppContext.getGlobalContext(), false);
|
||||
try {
|
||||
i.load(_archiveFile);
|
||||
_statusMessages.add("Archive fetched and loaded");
|
||||
@@ -329,7 +334,8 @@ public class RemoteArchiveBean {
|
||||
_statusMessages.add("Remote archive is bulk export capable");
|
||||
_exportCapable = true;
|
||||
} else {
|
||||
System.err.println("Header received: [" + key + "] = [" + val + "]");
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Header received: [" + key + "] = [" + val + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,7 +372,8 @@ public class RemoteArchiveBean {
|
||||
_statusMessages.add("Blog info at " + HTMLRenderer.sanitizeString(url) + " was corrupt / invalid / forged");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error handling metadata", ioe);
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
info.delete();
|
||||
@@ -412,7 +419,8 @@ public class RemoteArchiveBean {
|
||||
BlogManager.instance().getArchive().regenerateIndex();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error importing", ioe);
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
file.delete();
|
||||
@@ -491,7 +499,8 @@ public class RemoteArchiveBean {
|
||||
|
||||
BlogManager.instance().getArchive().regenerateIndex();
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.debug("Error importing", ioe);
|
||||
_statusMessages.add("Error importing from " + HTMLRenderer.sanitizeString(url) + ": " + ioe.getMessage());
|
||||
} finally {
|
||||
if (zi != null) try { zi.close(); } catch (IOException ioe) {}
|
||||
|
||||
Reference in New Issue
Block a user