2005-01-11 jrandom

* Include the attachments/blogs/etc for comments on the blog view
    * Syndie HTML fixes (thanks cervantes!)
    * Make sure we fully reset the objects going into our cache before we
      reuse them (thanks zzz!)
This commit is contained in:
jrandom
2006-01-11 20:32:34 +00:00
committed by zzz
parent 97a206fcda
commit 79476d3609
12 changed files with 279 additions and 224 deletions

View File

@ -0,0 +1,17 @@
package net.i2p.syndie.sml;
import java.util.*;
import net.i2p.data.DataHelper;
/** contains intermediary rendering state */
class Address {
public String name;
public String schema;
public String location;
public String protocol;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Address a = (Address)o;
return DataHelper.eq(schema, a.schema) && DataHelper.eq(location, a.location) && DataHelper.eq(protocol, a.protocol) && DataHelper.eq(name, a.name);
}
}

View File

@ -0,0 +1,19 @@
package net.i2p.syndie.sml;
import java.util.*;
import net.i2p.data.DataHelper;
/** contains intermediary rendering state */
class ArchiveRef {
public String name;
public String description;
public String locationSchema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
ArchiveRef a = (ArchiveRef)o;
return DataHelper.eq(name, a.name) && DataHelper.eq(description, a.description)
&& DataHelper.eq(locationSchema, a.locationSchema)
&& DataHelper.eq(location, a.location);
}
}

View File

@ -0,0 +1,19 @@
package net.i2p.syndie.sml;
import java.util.*;
import net.i2p.data.DataHelper;
/** contains intermediary rendering state */
class Blog {
public String name;
public String hash;
public String tag;
public long entryId;
public List locations;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Blog b = (Blog)o;
return DataHelper.eq(hash, b.hash) && DataHelper.eq(tag, b.tag) && DataHelper.eq(name, b.name)
&& DataHelper.eq(entryId, b.entryId) && DataHelper.eq(locations, b.locations);
}
}

View File

@ -76,97 +76,103 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
}
private void renderAttachments(BlogURI postURI, Attachment attachments[]) {
renderAttachments(postURI, "syndieBlogPostInfo", attachments, _bodyBuffer);
}
public static void renderAttachments(BlogURI postURI, String baseStyleName, Attachment attachments[], StringBuffer out) {
if ( (attachments != null) && (attachments.length > 0) ) {
_bodyBuffer.append("<div class=\"syndieBlogPostInfoGroup\">\n");
_bodyBuffer.append("<span class=\"syndieBlogPostInfoGroupName\">Attachments</span>\n<ol>");
out.append("<div class=\"").append(baseStyleName).append("Group\">\n");
out.append("<span class=\"").append(baseStyleName).append("GroupName\">Attachments</span>\n<ol>");
// for each attachment:
// <li><a>$name</a>\n($size of type $type)</li>
for (int i = 0; i < attachments.length; i++) {
_bodyBuffer.append("<li>");
out.append("<li>");
String name = attachments[i].getName();
if ( (name == null) && (name.trim().length() <= 0) )
name = "Attachment " + i;
if (postURI != null) {
_bodyBuffer.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_ATTACHMENT).append("=");
_bodyBuffer.append(postURI.getKeyHash().toBase64()).append("/").append(postURI.getEntryId());
_bodyBuffer.append("/").append(i).append("\" title=\"View the attachment\">");
out.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_ATTACHMENT).append("=");
out.append(postURI.getKeyHash().toBase64()).append("/").append(postURI.getEntryId());
out.append("/").append(i).append("\" title=\"View the attachment\">");
}
_bodyBuffer.append(HTMLRenderer.sanitizeString(name, 40));
out.append(HTMLRenderer.sanitizeString(name, 40));
if (postURI != null)
_bodyBuffer.append("</a>");
out.append("</a>");
_bodyBuffer.append("\n(");
out.append("\n(");
int bytes = attachments[i].getDataLength();
if (bytes > 10*1024*1024)
_bodyBuffer.append(bytes/(1024*1024)).append("MBytes");
out.append(bytes/(1024*1024)).append("MBytes");
else if (bytes > 10*1024)
_bodyBuffer.append(bytes/(10*1024)).append("KBytes");
out.append(bytes/(10*1024)).append("KBytes");
else
_bodyBuffer.append(bytes).append("Bytes");
out.append(bytes).append("Bytes");
String type = attachments[i].getMimeType();
if (type != null) {
if ("application/octet-stream".equals(type)) {
_bodyBuffer.append(", binary");
out.append(", binary");
} else {
int split = type.lastIndexOf('/');
if (split > 0)
_bodyBuffer.append(", ").append(HTMLRenderer.sanitizeString(type.substring(split+1), 30));
out.append(", ").append(HTMLRenderer.sanitizeString(type.substring(split+1), 30));
else
_bodyBuffer.append(", ").append(HTMLRenderer.sanitizeString(type, 30));
out.append(", ").append(HTMLRenderer.sanitizeString(type, 30));
}
}
_bodyBuffer.append(")");
out.append(")");
String desc = attachments[i].getDescription();
if ( (desc != null) && (desc.trim().length() > 0) )
_bodyBuffer.append("<br />\n").append(HTMLRenderer.sanitizeString(desc, 120));
out.append("<br />\n").append(HTMLRenderer.sanitizeString(desc, 120));
_bodyBuffer.append("</li>\n");
out.append("</li>\n");
}
_bodyBuffer.append("</ol>\n");
_bodyBuffer.append("</div><!-- syndieBlogPostInfoGroup -->\n");
out.append("</ol>\n");
out.append("</div><!-- syndieBlogPostInfoGroup -->\n");
}
}
private void renderBlogs(BlogURI postURI) {
if ( (_blogs != null) && (_blogs.size() > 0) ) {
_bodyBuffer.append("<div class=\"syndieBlogPostInfoGroup\">\n");
_bodyBuffer.append("<span class=\"syndieBlogPostInfoGroupName\">Blogs</span>\n<ol>");
renderBlogs(postURI, _user, "syndieBlogPostInfo", _blogs, _bodyBuffer);
}
public static void renderBlogs(BlogURI postURI, User user, String baseStyleName, List blogs, StringBuffer out) {
if ( (blogs != null) && (blogs.size() > 0) ) {
out.append("<div class=\"").append(baseStyleName).append("Group\">\n");
out.append("<span class=\"").append(baseStyleName).append("GroupName\">Blogs</span>\n<ol>");
// for each blog ref:
// <li><a>$name</a>\n ? :) :(</li>
for (int i = 0; i < _blogs.size(); i++) {
_bodyBuffer.append("<li>");
Blog blog = (Blog)_blogs.get(i);
PetNameDB db = _user.getPetNameDB();
for (int i = 0; i < blogs.size(); i++) {
out.append("<li>");
Blog blog = (Blog)blogs.get(i);
PetNameDB db = user.getPetNameDB();
PetName pn = db.getByLocation(blog.hash);
if ( (blog.entryId > 0) && (blog.hash != null) ) {
// view a specific post in their blog (jumping to their blog, rather than keeping the
// current blog's formatting... is that the right thing to do?)
_bodyBuffer.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_BLOG).append("=");
_bodyBuffer.append(HTMLRenderer.sanitizeTagParam(blog.hash)).append("&amp;");
_bodyBuffer.append(ViewBlogServlet.PARAM_ENTRY).append("=").append(HTMLRenderer.sanitizeTagParam(blog.hash));
_bodyBuffer.append("/").append(blog.entryId);
_bodyBuffer.append("&amp;\" title=\"View the blog post\">");
out.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_BLOG).append("=");
out.append(HTMLRenderer.sanitizeTagParam(blog.hash)).append("&amp;");
out.append(ViewBlogServlet.PARAM_ENTRY).append("=").append(HTMLRenderer.sanitizeTagParam(blog.hash));
out.append("/").append(blog.entryId);
out.append("&amp;\" title=\"View the blog post\">");
if (pn != null)
_bodyBuffer.append(HTMLRenderer.sanitizeString(pn.getName()));
out.append(HTMLRenderer.sanitizeString(pn.getName()));
else
_bodyBuffer.append(HTMLRenderer.sanitizeString(blog.name));
_bodyBuffer.append(" on ").append(getEntryDate(blog.entryId));
_bodyBuffer.append("</a>");
out.append(HTMLRenderer.sanitizeString(blog.name));
out.append(" on ").append(getEntryDate(blog.entryId));
out.append("</a>");
} else if (blog.hash != null) {
// view their full blog
_bodyBuffer.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_BLOG);
_bodyBuffer.append("=").append(HTMLRenderer.sanitizeString(blog.hash)).append("\" title=\"View their blog\">");
out.append("<a href=\"blog.jsp?").append(ViewBlogServlet.PARAM_BLOG);
out.append("=").append(HTMLRenderer.sanitizeString(blog.hash)).append("\" title=\"View their blog\">");
if (pn != null) {
// we already have a petname for this user
_bodyBuffer.append(pn.getName()).append("</a>");
out.append(pn.getName()).append("</a>");
/* <a href=\"profile.jsp?");
_bodyBuffer.append(ThreadedHTMLRenderer.PARAM_AUTHOR).append("=");
_bodyBuffer.append(HTMLRenderer.sanitizeTagParam(pn.getLocation())).append("\" title=\"View their profile\">");
@ -177,7 +183,7 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
// generate a new nym
while ( (pn = db.getByName(blog.name)) != null)
blog.name = blog.name + ".";
_bodyBuffer.append(HTMLRenderer.sanitizeString(blog.name)).append("</a>");
out.append(HTMLRenderer.sanitizeString(blog.name)).append("</a>");
/* <a href=\"profile.jsp?");
_bodyBuffer.append(ThreadedHTMLRenderer.PARAM_AUTHOR).append("=");
_bodyBuffer.append(HTMLRenderer.sanitizeTagParam(blog.hash)).append("\" title=\"View their profile\">");
@ -186,14 +192,14 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
// should probably add on some inline-bookmarking support, but we'd need requestURL for that
}
}
_bodyBuffer.append("</li>\n");
out.append("</li>\n");
}
_bodyBuffer.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
out.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
}
}
private final SimpleDateFormat _dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.UK);
private final String getEntryDate(long when) {
private static final SimpleDateFormat _dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.UK);
private static final String getEntryDate(long when) {
synchronized (_dateFormat) {
try {
String str = _dateFormat.format(new Date(when));
@ -207,73 +213,79 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
}
private void renderLinks(BlogURI postURI) {
if ( (_links != null) && (_links.size() > 0) ) {
_bodyBuffer.append("<div class=\"syndieBlogPostInfoGroup\">\n");
_bodyBuffer.append("<span class=\"syndieBlogPostInfoGroupName\">Links</span>\n<ol>");
renderLinks(postURI, _user, "syndieBlogPostInfo", _links, _bodyBuffer);
}
public static void renderLinks(BlogURI postURI, User user, String baseStyleName, List links, StringBuffer out) {
if ( (links != null) && (links.size() > 0) ) {
out.append("<div class=\"").append(baseStyleName).append("Group\">\n");
out.append("<span class=\"").append(baseStyleName).append("GroupName\">Links</span>\n<ol>");
// for each link:
// <li><a>$location</a></li>
for (int i = 0; i < _links.size(); i++) {
_bodyBuffer.append("<li>");
for (int i = 0; i < links.size(); i++) {
out.append("<li>");
Link l = (Link)_links.get(i);
Link l = (Link)links.get(i);
String schema = l.schema;
_bodyBuffer.append("<a href=\"externallink.jsp?");
out.append("<a href=\"externallink.jsp?");
if (l.schema != null)
_bodyBuffer.append("schema=").append(HTMLRenderer.sanitizeURL(l.schema)).append("&amp;");
out.append("schema=").append(HTMLRenderer.sanitizeURL(l.schema)).append("&amp;");
if (l.location != null)
_bodyBuffer.append("location=").append(HTMLRenderer.sanitizeURL(l.location)).append("&amp;");
_bodyBuffer.append("\">").append(HTMLRenderer.sanitizeString(l.location, 40)).append(" (");
_bodyBuffer.append(HTMLRenderer.sanitizeString(l.schema, 10)).append(")</a>");
out.append("location=").append(HTMLRenderer.sanitizeURL(l.location)).append("&amp;");
out.append("\">").append(HTMLRenderer.sanitizeString(l.location, 30)).append(" (");
out.append(HTMLRenderer.sanitizeString(l.schema, 6)).append(")</a>");
_bodyBuffer.append("</li>\n");
out.append("</li>\n");
}
_bodyBuffer.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
out.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
}
}
private void renderAddresses(BlogURI postURI) {
if ( (_addresses != null) && (_addresses.size() > 0) ) {
_bodyBuffer.append("<div class=\"syndieBlogPostInfoGroup\">\n");
_bodyBuffer.append("<span class=\"syndieBlogPostInfoGroupName\">Addresses</span>\n<ol>");
renderAddresses(postURI, _user, "syndieBlogPostInfo", _addresses, _bodyBuffer);
}
public static void renderAddresses(BlogURI postURI, User user, String baseStyleName, List addresses, StringBuffer out) {
if ( (addresses != null) && (addresses.size() > 0) ) {
out.append("<div class=\"").append(baseStyleName).append("Group\">\n");
out.append("<span class=\"").append(baseStyleName).append("GroupName\">Addresses</span>\n<ol>");
// for each address:
// <li><a>$name</a></li>
for (int i = 0; i < _addresses.size(); i++) {
_bodyBuffer.append("<li>");
Address a = (Address)_addresses.get(i);
importAddress(a);
for (int i = 0; i < addresses.size(); i++) {
out.append("<li>");
Address a = (Address)addresses.get(i);
importAddress(a, user);
PetName pn = null;
if (_user != null)
pn = _user.getPetNameDB().getByLocation(a.location);
if (user != null)
pn = user.getPetNameDB().getByLocation(a.location);
if (pn != null) {
_bodyBuffer.append(HTMLRenderer.sanitizeString(pn.getName()));
out.append(HTMLRenderer.sanitizeString(pn.getName()));
} else {
_bodyBuffer.append("<a href=\"addresses.jsp?");
out.append("<a href=\"addresses.jsp?");
if (a.schema != null)
_bodyBuffer.append(AddressesServlet.PARAM_NET).append("=").append(HTMLRenderer.sanitizeTagParam(a.schema)).append("&amp;");
out.append(AddressesServlet.PARAM_NET).append("=").append(HTMLRenderer.sanitizeTagParam(a.schema)).append("&amp;");
if (a.location != null)
_bodyBuffer.append(AddressesServlet.PARAM_LOC).append("=").append(HTMLRenderer.sanitizeTagParam(a.location)).append("&amp;");
out.append(AddressesServlet.PARAM_LOC).append("=").append(HTMLRenderer.sanitizeTagParam(a.location)).append("&amp;");
if (a.name != null)
_bodyBuffer.append(AddressesServlet.PARAM_NAME).append("=").append(HTMLRenderer.sanitizeTagParam(a.name)).append("&amp;");
out.append(AddressesServlet.PARAM_NAME).append("=").append(HTMLRenderer.sanitizeTagParam(a.name)).append("&amp;");
if (a.protocol != null)
_bodyBuffer.append(AddressesServlet.PARAM_PROTO).append("=").append(HTMLRenderer.sanitizeTagParam(a.protocol)).append("&amp;");
_bodyBuffer.append("\" title=\"Add this address to your addressbook\">").append(HTMLRenderer.sanitizeString(a.name)).append("</a>");
out.append(AddressesServlet.PARAM_PROTO).append("=").append(HTMLRenderer.sanitizeTagParam(a.protocol)).append("&amp;");
out.append("\" title=\"Add this address to your addressbook\">").append(HTMLRenderer.sanitizeString(a.name)).append("</a>");
}
_bodyBuffer.append("</li>\n");
out.append("</li>\n");
}
_bodyBuffer.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
out.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
}
}
public void importAddress(Address a) {
if (_user != null && _user.getImportAddresses() && !_user.getPetNameDB().containsName(a.name)) {
public static void importAddress(Address a, User user) {
if (user != null && user.getImportAddresses() && !user.getPetNameDB().containsName(a.name)) {
PetName pn = new PetName(a.name, a.schema, a.protocol, a.location);
_user.getPetNameDB().add(pn);
user.getPetNameDB().add(pn);
try {
_user.getPetNameDB().store(_user.getAddressbookLocation());
user.getPetNameDB().store(user.getAddressbookLocation());
} catch (IOException ioe) {
//ignore
}
@ -292,38 +304,41 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
}
private void renderArchives(BlogURI postURI) {
if ( (_archives != null) && (_archives.size() > 0) ) {
_bodyBuffer.append("<div class=\"syndieBlogPostInfoGroup\">\n");
_bodyBuffer.append("<span class=\"syndieBlogPostInfoGroupName\">Archives</span>\n<ol>");
renderArchives(postURI, _user, "syndieBlogPostInfo", _archives, _bodyBuffer);
}
public static void renderArchives(BlogURI postURI, User user, String baseStyleName, List archives, StringBuffer out) {
if ( (archives != null) && (archives.size() > 0) ) {
out.append("<div class=\"").append(baseStyleName).append("Group\">\n");
out.append("<span class=\"").append(baseStyleName).append("GroupName\">Archives</span>\n<ol>");
// for each archive:
// <li><a>$name</a> :)<br/>$description</li>
for (int i = 0; i < _archives.size(); i++) {
_bodyBuffer.append("<li>");
ArchiveRef a = (ArchiveRef)_archives.get(i);
boolean authRemote = BlogManager.instance().authorizeRemote(_user);
for (int i = 0; i < archives.size(); i++) {
out.append("<li>");
ArchiveRef a = (ArchiveRef)archives.get(i);
boolean authRemote = BlogManager.instance().authorizeRemote(user);
if (authRemote) {
_bodyBuffer.append("<a href=\"");
_bodyBuffer.append(HTMLRenderer.getArchiveURL(null, new SafeURL(a.locationSchema + "://" + a.location)));
_bodyBuffer.append("\" title=\"Browse the remote archive\">");
out.append("<a href=\"");
out.append(HTMLRenderer.getArchiveURL(null, new SafeURL(a.locationSchema + "://" + a.location)));
out.append("\" title=\"Browse the remote archive\">");
}
_bodyBuffer.append(HTMLRenderer.sanitizeString(a.name));
out.append(HTMLRenderer.sanitizeString(a.name));
if (authRemote) {
_bodyBuffer.append("</a>");
out.append("</a>");
}
if ( (a.description != null) && (a.description.trim().length() > 0) )
_bodyBuffer.append(" ").append(HTMLRenderer.sanitizeString(a.description, 64));
out.append(" ").append(HTMLRenderer.sanitizeString(a.description, 64));
/*
_bodyBuffer.append(" <a href=\"").append(HTMLRenderer.getBookmarkURL(a.name, a.location, a.locationSchema, AddressesServlet.PROTO_ARCHIVE));
_bodyBuffer.append("\" title=\"Bookmark the remote archive\">bookmark it</a>");
_bodyBuffer.append("</li>\n");
*/
out.append("</li>\n");
}
_bodyBuffer.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
out.append("</div><!-- end syndieBlogPostInfoGroup -->\n");
}
}
@ -371,19 +386,6 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
public void receiveLeftBracket() { }
public void receiveRightBracket() { }
protected static class Blog {
public String name;
public String hash;
public String tag;
public long entryId;
public List locations;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Blog b = (Blog)o;
return DataHelper.eq(hash, b.hash) && DataHelper.eq(tag, b.tag) && DataHelper.eq(name, b.name)
&& DataHelper.eq(entryId, b.entryId) && DataHelper.eq(locations, b.locations);
}
}
/**
* when we see a link to a blog, we may want to:
* = view the blog entry
@ -414,19 +416,6 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
_blogs.add(b);
}
protected static class ArchiveRef {
public String name;
public String description;
public String locationSchema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
ArchiveRef a = (ArchiveRef)o;
return DataHelper.eq(name, a.name) && DataHelper.eq(description, a.description)
&& DataHelper.eq(locationSchema, a.locationSchema)
&& DataHelper.eq(location, a.location);
}
}
public void receiveArchive(String name, String description, String locationSchema, String location,
String postingKey, String anchorText) {
ArchiveRef a = new ArchiveRef();
@ -438,15 +427,6 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
_archives.add(a);
}
protected static class Link {
public String schema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Link l = (Link)o;
return DataHelper.eq(schema, l.schema) && DataHelper.eq(location, l.location);
}
}
public void receiveLink(String schema, String location, String text) {
Link l = new Link();
l.schema = schema;
@ -455,17 +435,6 @@ public class BlogPostInfoRenderer extends EventReceiverImpl {
_links.add(l);
}
protected static class Address {
public String name;
public String schema;
public String location;
public String protocol;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Address a = (Address)o;
return DataHelper.eq(schema, a.schema) && DataHelper.eq(location, a.location) && DataHelper.eq(protocol, a.protocol) && DataHelper.eq(name, a.name);
}
}
public void receiveAddress(String name, String schema, String protocol, String location, String anchorText) {
Address a = new Address();
a.name = name;

View File

@ -7,6 +7,7 @@ import net.i2p.client.naming.PetName;
import net.i2p.data.*;
import net.i2p.syndie.data.*;
import net.i2p.syndie.web.*;
import net.i2p.syndie.*;
/**
* Renders posts for display within the blog view
@ -15,10 +16,21 @@ import net.i2p.syndie.web.*;
public class BlogRenderer extends HTMLRenderer {
private BlogInfo _blog;
private BlogInfoData _data;
private boolean _isComment;
public BlogRenderer(I2PAppContext ctx, BlogInfo info, BlogInfoData data) {
super(ctx);
_blog = info;
_data = data;
_isComment = false;
}
public void renderPost(User user, Archive archive, EntryContainer entry, Writer out, boolean cutBody, boolean showImages) throws IOException {
_isComment = false;
render(user, archive, entry, out, cutBody, showImages);
}
public void renderComment(User user, Archive archive, EntryContainer entry, Writer out) throws IOException {
_isComment = true;
render(user, archive, entry, out, false, true);
}
public void receiveHeaderEnd() {
@ -64,9 +76,26 @@ public class BlogRenderer extends HTMLRenderer {
}
_postBodyBuffer.append("<a href=\"");
_postBodyBuffer.append(getReplyURL()).append("\" title=\"Reply to this post\">Leave a comment</a>\n");
if (_isComment)
renderCommentMeta();
_postBodyBuffer.append("</div><!-- end syndieBlogPostDetails -->\n");
_postBodyBuffer.append("</div><!-- end syndieBlogPost -->\n\n");
}
private void renderCommentMeta() {
BlogURI postURI = null;
Attachment attachments[] = null;
if (_entry != null) {
postURI = _entry.getURI();
attachments = _entry.getAttachments();
}
BlogPostInfoRenderer.renderAttachments(postURI, "syndieBlogCommentInfo", attachments, _postBodyBuffer);
BlogPostInfoRenderer.renderBlogs(postURI, _user, "syndieBlogCommentInfo", _blogs, _postBodyBuffer);
BlogPostInfoRenderer.renderLinks(postURI, _user, "syndieBlogCommentInfo", _links, _postBodyBuffer);
BlogPostInfoRenderer.renderAddresses(postURI, _user, "syndieBlogCommentInfo", _addresses, _postBodyBuffer);
BlogPostInfoRenderer.renderArchives(postURI, _user, "syndieBlogCommentInfo", _archives, _postBodyBuffer);
}
private int getChildCount(ThreadNode node) {
int nodes = 0;
for (int i = 0; i < node.getChildCount(); i++) {

View File

@ -274,19 +274,6 @@ public class HTMLRenderer extends EventReceiverImpl {
_bodyBuffer.append(getSpan("rb")).append("]</span>");
}
protected static class Blog {
public String name;
public String hash;
public String tag;
public long entryId;
public List locations;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Blog b = (Blog)o;
return DataHelper.eq(hash, b.hash) && DataHelper.eq(tag, b.tag) && DataHelper.eq(name, b.name)
&& DataHelper.eq(entryId, b.entryId) && DataHelper.eq(locations, b.locations);
}
}
/**
* when we see a link to a blog, we may want to:
* = view the blog entry
@ -370,19 +357,6 @@ public class HTMLRenderer extends EventReceiverImpl {
_bodyBuffer.append("]</span> ");
}
protected static class ArchiveRef {
public String name;
public String description;
public String locationSchema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
ArchiveRef a = (ArchiveRef)o;
return DataHelper.eq(name, a.name) && DataHelper.eq(description, a.description)
&& DataHelper.eq(locationSchema, a.locationSchema)
&& DataHelper.eq(location, a.location);
}
}
public void receiveArchive(String name, String description, String locationSchema, String location,
String postingKey, String anchorText) {
ArchiveRef a = new ArchiveRef();
@ -419,15 +393,6 @@ public class HTMLRenderer extends EventReceiverImpl {
_bodyBuffer.append("]</span>");
}
protected static class Link {
public String schema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Link l = (Link)o;
return DataHelper.eq(schema, l.schema) && DataHelper.eq(location, l.location);
}
}
public void receiveLink(String schema, String location, String text) {
Link l = new Link();
l.schema = schema;
@ -446,39 +411,8 @@ public class HTMLRenderer extends EventReceiverImpl {
append("</a>");
}
protected static class Address {
public String name;
public String schema;
public String location;
public String protocol;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Address a = (Address)o;
return DataHelper.eq(schema, a.schema) && DataHelper.eq(location, a.location) && DataHelper.eq(protocol, a.protocol) && DataHelper.eq(name, a.name);
}
}
public void importAddress(Address a) {
if (_user != null && _user.getImportAddresses() && !_user.getPetNameDB().containsName(a.name)) {
PetName pn = new PetName(a.name, a.schema, a.protocol, a.location);
_user.getPetNameDB().add(pn);
try {
_user.getPetNameDB().store(_user.getAddressbookLocation());
} catch (IOException ioe) {
//ignore
}
}
if (BlogManager.instance().getImportAddresses()
&& I2PAppContext.getGlobalContext().namingService().lookup(a.name) == null
&& a.schema.equalsIgnoreCase("i2p")) {
PetName pn = new PetName(a.name, a.schema, a.protocol, a.location);
I2PAppContext.getGlobalContext().petnameDb().add(pn);
try {
I2PAppContext.getGlobalContext().petnameDb().store();
} catch (IOException ioe) {
//ignore
}
}
BlogPostInfoRenderer.importAddress(a, _user);
}
public void receiveAddress(String name, String schema, String protocol, String location, String anchorText) {

View File

@ -0,0 +1,15 @@
package net.i2p.syndie.sml;
import java.util.*;
import net.i2p.data.DataHelper;
/** contains intermediary rendering state */
class Link {
public String schema;
public String location;
public int hashCode() { return -1; }
public boolean equals(Object o) {
Link l = (Link)o;
return DataHelper.eq(schema, l.schema) && DataHelper.eq(location, l.location);
}
}

View File

@ -558,7 +558,9 @@ public abstract class BaseServlet extends HttpServlet {
}
protected void renderBegin(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws IOException {
out.write("<html>\n<head><title>" + getTitle() + "</title>\n");
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>" + getTitle() + "</title>\n");
out.write("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
out.write("<meta http-equiv=\"pragma\" content=\"no-cache\" />");
out.write("<style>");
@ -1111,6 +1113,10 @@ public abstract class BaseServlet extends HttpServlet {
" margin: 0px;\n" +
" padding: 0px;\n" +
"}\n" +
"* {\n" +
" margin: 0px;\n" +
" padding: 0px;\n" +
"}\n" +
".topNav {\n" +
" background-color: #BBBBBB;\n" +
"}\n" +

View File

@ -159,7 +159,9 @@ public class ViewBlogServlet extends BaseServlet {
String pageTitle = "Syndie :: Blogs" + (desc != null ? " :: " + desc : "");
if (title != null) pageTitle = pageTitle + " (" + title + ")";
pageTitle = HTMLRenderer.sanitizeString(pageTitle);
out.write("<html>\n<head>\n<title>" + pageTitle + "</title>\n");
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>" + pageTitle + "</title>\n");
out.write("<style>");
renderStyle(out, info, data, req);
out.write("</style></head>");
@ -381,13 +383,13 @@ public class ViewBlogServlet extends BaseServlet {
if ( (posts.size() == 1) && (req.getParameter(PARAM_ENTRY) != null) ) {
BlogURI uri = (BlogURI)posts.get(0);
EntryContainer entry = archive.getEntry(uri);
renderer.render(user, archive, entry, out, false, true);
renderer.renderPost(user, archive, entry, out, false, true);
renderComments(user, out, info, data, entry, archive, renderer);
} else {
for (int i = offset; i < posts.size() && i < offset + POSTS_PER_PAGE; i++) {
BlogURI uri = (BlogURI)posts.get(i);
EntryContainer entry = archive.getEntry(uri);
renderer.render(user, archive, entry, out, true, true);
renderer.renderPost(user, archive, entry, out, true, true);
}
renderNav(out, info, data, posts, offset, archive, req);
@ -412,7 +414,7 @@ public class ViewBlogServlet extends BaseServlet {
out.write("<li>");
if (!shouldIgnore(user, uri)) {
EntryContainer cur = archive.getEntry(uri);
renderer.render(user, archive, cur, out, false, true);
renderer.renderComment(user, archive, cur, out);
// recurse
renderComments(user, out, uri, archive, index, renderer);
}
@ -618,12 +620,18 @@ public class ViewBlogServlet extends BaseServlet {
}
private static final String CSS =
"<style>\n" +
"body {\n" +
" margin: 0px;\n" +
" padding: 0px;\n" +
" font-family: Arial, Helvetica, sans-serif;\n" +
"}\n" +
"* {\n" +
" margin: 0px;\n" +
" padding: 0px;\n" +
"}\n" +
"select {\n" +
" min-width: 1.5em;\n" +
"}\n" +
".syndieBlog {\n" +
" font-size: 100%;\n" +
" margin: 0px;\n" +
@ -683,10 +691,10 @@ public class ViewBlogServlet extends BaseServlet {
".syndieBlogLinkGroup li {\n" +
" margin: 0;\n" +
"}\n" +
".syndieBlogLinkGroup li a {\n" +
" display: block;\n" +
//".syndieBlogLinkGroup li a {\n" +
//" display: block;\n" +
//" width: 100%;\n" +
"}\n" +
//"}\n" +
".syndieBlogLinkGroupName {\n" +
" font-size: 80%;\n" +
" font-weight: bold;\n" +
@ -740,7 +748,7 @@ public class ViewBlogServlet extends BaseServlet {
" border-width: 1px 1px 1px 1px;\n" +
" border-color: #000;\n" +
" margin-top: 5px;\n" +
" width: 100%;\n" +
" width: 99%;\n" +
"}\n" +
".syndieBlogPostHeader {\n" +
" background-color: #BBB;\n" +
@ -768,8 +776,35 @@ public class ViewBlogServlet extends BaseServlet {
"}\n" +
".syndieBlogComments ul {\n" +
" list-style: none;\n" +
" margin-left: 10;\n" +
" margin-left: 10px;\n" +
" padding-left: 0;\n" +
"}\n" +
".syndieBlogCommentInfoGroup {\n" +
" text-align: left;\n" +
" font-size: 80%;\n" +
//" background-color: #FFEA9F;\n" +
//" border: solid;\n" +
//" border-width: 1px 1px 1px 1px;\n" +
//" border-color: #000;\n" +
//" margin-top: 5px;\n" +
" margin-right: 5px;\n" +
"}\n" +
".syndieBlogCommentInfoGroup ol {\n" +
" list-style: none;\n" +
" margin-left: 0;\n" +
" margin-top: 0;\n" +
" margin-bottom: 0;\n" +
" padding-left: 0;\n" +
"}\n" +
".syndieBlogCommentInfoGroup li {\n" +
" margin: 0;\n" +
"}\n" +
".syndieBlogCommentInfoGroup li a {\n" +
" display: block;\n" +
"}\n" +
".syndieBlogCommentInfoGroupName {\n" +
" font-size: 80%;\n" +
" font-weight: bold;\n" +
"}\n";
protected String getTitle() { return "unused"; }

View File

@ -77,7 +77,10 @@ public final class ByteCache {
}
_lastOverflow = System.currentTimeMillis();
byte data[] = new byte[_entrySize];
return new ByteArray(data);
ByteArray rv = new ByteArray(data);
rv.setValid(0);
rv.setOffset(0);
return rv;
}
/**
@ -92,6 +95,9 @@ public final class ByteCache {
if ( (entry == null) || (entry.getData() == null) )
return;
entry.setValid(0);
entry.setOffset(0);
if (shouldZero)
Arrays.fill(entry.getData(), (byte)0x0);
synchronized (_available) {

View File

@ -1,4 +1,10 @@
$Id: history.txt,v 1.381 2006/01/09 17:22:43 jrandom Exp $
$Id: history.txt,v 1.382 2006/01/10 01:59:08 jrandom Exp $
2005-01-11 jrandom
* Include the attachments/blogs/etc for comments on the blog view
* Syndie HTML fixes (thanks cervantes!)
* Make sure we fully reset the objects going into our cache before we
reuse them (thanks zzz!)
2005-01-10 jrandom
* Added the per-post list of attachments/blogs/etc to the blog view in

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.327 $ $Date: 2006/01/09 17:22:42 $";
public final static String ID = "$Revision: 1.328 $ $Date: 2006/01/10 01:59:08 $";
public final static String VERSION = "0.6.1.8";
public final static long BUILD = 11;
public final static long BUILD = 12;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);