better filtering/ignoring
ui improvements (per isamoor's suggestions) more petname integration
This commit is contained in:
@ -117,6 +117,20 @@ public class ArchiveIndex {
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
public int getBlogEntryCount(Hash blog) {
|
||||
Set uris = new HashSet(64);
|
||||
for (int i = 0; i < _blogs.size(); i++) {
|
||||
BlogSummary summary = (BlogSummary)_blogs.get(i);
|
||||
if (summary.blog.equals(blog)) {
|
||||
uris.addAll(summary.entries);
|
||||
//for (int j = 0; j < summary.entries.size(); j++) {
|
||||
// EntrySummary entry = (EntrySummary)summary.entries.get(j);
|
||||
// uris.add(entry.entry);
|
||||
//}
|
||||
}
|
||||
}
|
||||
return uris.size();
|
||||
}
|
||||
|
||||
/** how many 'new' blogs are listed */
|
||||
public int getNewestBlogCount() { return _newestBlogs.size(); }
|
||||
@ -379,6 +393,14 @@ public class ArchiveIndex {
|
||||
size = kb;
|
||||
entry = uri;
|
||||
}
|
||||
public int hashCode() {
|
||||
return entry.hashCode();
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if ( (obj instanceof EntrySummary) && (((EntrySummary)obj).entry.equals(entry)) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** export the index into an archive.txt */
|
||||
|
@ -118,11 +118,21 @@ public class ArchiveViewerBean {
|
||||
|
||||
for (int i = 0; i < index.getNewestBlogCount(); i++) {
|
||||
Hash cur = index.getNewestBlog(i);
|
||||
String knownName = user.getPetNameDB().getNameByLocation(cur.toBase64());
|
||||
PetName pn = null;
|
||||
if (knownName != null) {
|
||||
pn = user.getPetNameDB().get(knownName);
|
||||
knownName = pn.getName();
|
||||
}
|
||||
if ( (pn != null) && (pn.isMember("Ignore")) )
|
||||
continue;
|
||||
String blog = Base64.encode(cur.getData());
|
||||
out.write("<option value=\"blog://" + blog + "\">");
|
||||
out.write("New blog: ");
|
||||
BlogInfo info = archive.getBlogInfo(cur);
|
||||
String name = info.getProperty(BlogInfo.NAME);
|
||||
String name = knownName;
|
||||
if ( (name == null) && (info != null) )
|
||||
name = info.getProperty(BlogInfo.NAME);
|
||||
if (name != null)
|
||||
name = HTMLRenderer.sanitizeString(name);
|
||||
else
|
||||
@ -131,24 +141,43 @@ public class ArchiveViewerBean {
|
||||
out.write("</option>\n");
|
||||
}
|
||||
|
||||
List allTags = new ArrayList();
|
||||
////List allTags = new ArrayList();
|
||||
// perhaps sort this by name (even though it isnt unique...)
|
||||
Set blogs = index.getUniqueBlogs();
|
||||
for (Iterator iter = blogs.iterator(); iter.hasNext(); ) {
|
||||
Hash cur = (Hash)iter.next();
|
||||
String knownName = user.getPetNameDB().getNameByLocation(cur.toBase64());
|
||||
PetName pn = null;
|
||||
if (knownName != null) {
|
||||
pn = user.getPetNameDB().get(knownName);
|
||||
knownName = pn.getName();
|
||||
}
|
||||
if ( (pn != null) && (pn.isMember("Ignore")) )
|
||||
continue;
|
||||
|
||||
String blog = Base64.encode(cur.getData());
|
||||
out.write("<option value=\"blog://");
|
||||
out.write(blog);
|
||||
out.write("\">");
|
||||
BlogInfo info = archive.getBlogInfo(cur);
|
||||
String name = info.getProperty(BlogInfo.NAME);
|
||||
String name = knownName;
|
||||
if ( (name == null) && (info != null) )
|
||||
name = info.getProperty(BlogInfo.NAME);
|
||||
if (name != null)
|
||||
name = HTMLRenderer.sanitizeString(name);
|
||||
else
|
||||
name = Base64.encode(cur.getData());
|
||||
out.write(name);
|
||||
out.write("- all posts</option>\n");
|
||||
if (info != null) {
|
||||
int howMany = index.getBlogEntryCount(info.getKey().calculateHash());
|
||||
if (howMany == 1)
|
||||
out.write(" [1 post]");
|
||||
else
|
||||
out.write(" [" + howMany + " posts]");
|
||||
}
|
||||
out.write("</option>\n");
|
||||
|
||||
/*
|
||||
List tags = index.getBlogTags(cur);
|
||||
for (int j = 0; j < tags.size(); j++) {
|
||||
String tag = (String)tags.get(j);
|
||||
@ -190,7 +219,9 @@ public class ArchiveViewerBean {
|
||||
out.write(tag);
|
||||
out.write(""</option>\n");
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
for (int i = 0; i < allTags.size(); i++) {
|
||||
String tag = (String)allTags.get(i);
|
||||
out.write("<option value=\"tag://");
|
||||
@ -199,6 +230,7 @@ public class ArchiveViewerBean {
|
||||
out.write(tag);
|
||||
out.write(""</option>\n");
|
||||
}
|
||||
*/
|
||||
out.write("</select>");
|
||||
|
||||
int numPerPage = getInt(parameters, PARAM_NUM_PER_PAGE, 5);
|
||||
@ -224,11 +256,12 @@ public class ArchiveViewerBean {
|
||||
String blogStr = getString(parameters, PARAM_BLOG);
|
||||
Hash blog = null;
|
||||
if (blogStr != null) blog = new Hash(Base64.decode(blogStr));
|
||||
if ( (blog != null) && (blog.getData() == null) ) blog = null;
|
||||
String tag = getString(parameters, PARAM_TAG);
|
||||
if (tag != null) tag = DataHelper.getUTF8(Base64.decode(tag));
|
||||
|
||||
long entryId = -1;
|
||||
if (blogStr != null) {
|
||||
if (blog != null) {
|
||||
String entryIdStr = getString(parameters, PARAM_ENTRY);
|
||||
try {
|
||||
entryId = Long.parseLong(entryIdStr);
|
||||
@ -285,11 +318,20 @@ public class ArchiveViewerBean {
|
||||
if (selector.startsWith(SEL_BLOG)) {
|
||||
String blogStr = selector.substring(SEL_BLOG.length());
|
||||
System.out.println("Selector [" + selector + "] blogString: [" + blogStr + "]");
|
||||
blog = new Hash(Base64.decode(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 if (selector.startsWith(SEL_BLOGTAG)) {
|
||||
int tagStart = selector.lastIndexOf('/');
|
||||
String blogStr = selector.substring(SEL_BLOGTAG.length(), tagStart);
|
||||
blog = new Hash(Base64.decode(blogStr));
|
||||
if (blog.getData() == null) {
|
||||
System.out.println("Blog string [" + blogStr + "] does not decode");
|
||||
blog = null;
|
||||
return;
|
||||
}
|
||||
tag = selector.substring(tagStart+1);
|
||||
String origTag = tag;
|
||||
byte rawDecode[] = null;
|
||||
@ -336,7 +378,11 @@ public class ArchiveViewerBean {
|
||||
String entryStr = selector.substring(entryStart+1);
|
||||
try {
|
||||
entry = Long.parseLong(entryStr);
|
||||
blog = new Hash(Base64.decode(blogStr));
|
||||
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 + "]");
|
||||
} catch (NumberFormatException nfe) {}
|
||||
} else if (selector.startsWith(SEL_GROUP)) {
|
||||
@ -444,6 +490,8 @@ public class ArchiveViewerBean {
|
||||
}
|
||||
|
||||
private static List pickEntryURIs(User user, ArchiveIndex index, Hash blog, String tag, long entryId, String group) {
|
||||
if ( (blog != null) && ( (blog.getData() == null) || (blog.getData().length != Hash.HASH_LENGTH) ) )
|
||||
blog = null;
|
||||
List rv = new ArrayList(16);
|
||||
if ( (blog != null) && (entryId >= 0) ) {
|
||||
rv.add(new BlogURI(blog, entryId));
|
||||
|
@ -51,6 +51,12 @@ public class RemoteArchiveBean {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private boolean ignoreBlog(User user, Hash blog) {
|
||||
PetNameDB db = user.getPetNameDB();
|
||||
String name = db.getNameByLocation(blog.toBase64());
|
||||
return ( (name != null) && (db.get(name).isMember("Ignore")) );
|
||||
}
|
||||
|
||||
public void fetchMetadata(User user, Map parameters) {
|
||||
String meta = ArchiveViewerBean.getString(parameters, "blog");
|
||||
if (meta == null) return;
|
||||
@ -61,11 +67,17 @@ public class RemoteArchiveBean {
|
||||
for (Iterator iter = remoteBlogs.iterator(); iter.hasNext(); ) {
|
||||
Hash blog = (Hash)iter.next();
|
||||
if (!localBlogs.contains(blog)) {
|
||||
blogs.add(blog);
|
||||
if (!ignoreBlog(user, blog))
|
||||
blogs.add(blog);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
blogs.add(new Hash(Base64.decode(meta.trim())));
|
||||
byte h[] = Base64.decode(meta.trim());
|
||||
if (h != null) {
|
||||
Hash blog = new Hash(h);
|
||||
if (!ignoreBlog(user, blog))
|
||||
blogs.add(blog);
|
||||
}
|
||||
}
|
||||
List urls = new ArrayList(blogs.size());
|
||||
List tmpFiles = new ArrayList(blogs.size());
|
||||
@ -96,7 +108,10 @@ public class RemoteArchiveBean {
|
||||
List urls = new ArrayList(entries.length);
|
||||
List tmpFiles = new ArrayList(entries.length);
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
urls.add(buildEntryURL(new BlogURI(entries[i])));
|
||||
BlogURI uri = new BlogURI(entries[i]);
|
||||
if (ignoreBlog(user, uri.getKeyHash()))
|
||||
continue;
|
||||
urls.add(buildEntryURL(uri));
|
||||
try {
|
||||
tmpFiles.add(File.createTempFile("fetchBlog", ".txt", BlogManager.instance().getTempDir()));
|
||||
} catch (IOException ioe) {
|
||||
@ -118,6 +133,9 @@ public class RemoteArchiveBean {
|
||||
List matches = new ArrayList();
|
||||
for (Iterator iter = _remoteIndex.getUniqueBlogs().iterator(); iter.hasNext(); ) {
|
||||
Hash blog = (Hash)iter.next();
|
||||
if (ignoreBlog(user, blog))
|
||||
continue;
|
||||
|
||||
_remoteIndex.selectMatchesOrderByEntryId(matches, blog, null);
|
||||
for (int i = 0; i < matches.size(); i++) {
|
||||
BlogURI uri = (BlogURI)matches.get(i);
|
||||
@ -177,6 +195,8 @@ public class RemoteArchiveBean {
|
||||
List entries = new ArrayList();
|
||||
for (Iterator iter = _remoteIndex.getUniqueBlogs().iterator(); iter.hasNext(); ) {
|
||||
Hash blog = (Hash)iter.next();
|
||||
if (ignoreBlog(user, blog))
|
||||
continue;
|
||||
_remoteIndex.selectMatchesOrderByEntryId(entries, blog, null);
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
BlogURI uri = (BlogURI)entries.get(i);
|
||||
@ -486,6 +506,8 @@ public class RemoteArchiveBean {
|
||||
int newBlogs = 0;
|
||||
for (Iterator iter = remoteBlogs.iterator(); iter.hasNext(); ) {
|
||||
Hash blog = (Hash)iter.next();
|
||||
if (ignoreBlog(user, blog))
|
||||
continue;
|
||||
if (!localBlogs.contains(blog)) {
|
||||
buf.append("<option value=\"" + blog.toBase64() + "\">" + blog.toBase64() + "</option>\n");
|
||||
newBlogs++;
|
||||
@ -502,6 +524,8 @@ public class RemoteArchiveBean {
|
||||
List entries = new ArrayList();
|
||||
for (Iterator iter = remoteBlogs.iterator(); iter.hasNext(); ) {
|
||||
Hash blog = (Hash)iter.next();
|
||||
if (ignoreBlog(user, blog))
|
||||
continue;
|
||||
buf.setLength(0);
|
||||
int shownEntries = 0;
|
||||
buf.append("<tr><td colspan=\"5\" align=\"left\" valign=\"top\">\n");
|
||||
|
@ -28,6 +28,8 @@ if (!user.getAuthenticated()) {
|
||||
cur.setIsPublic(null != request.getParameter("isPublic"));
|
||||
cur.setLocation(request.getParameter("location"));
|
||||
cur.setGroups(request.getParameter("groups"));
|
||||
names.remove(oldPetname);
|
||||
names.set(cur.getName(), cur);
|
||||
names.store(user.getAddressbookLocation());
|
||||
%><b>Address updated</b><%
|
||||
}
|
||||
|
Reference in New Issue
Block a user