migrated the syndie addressbook

This commit is contained in:
jrandom
2005-11-13 03:42:52 +00:00
committed by zzz
parent 7443457af4
commit 08be4c7b3d
6 changed files with 532 additions and 240 deletions

View File

@@ -44,6 +44,8 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
public static final String PARAM_PROFILE_DESC = "profileDesc";
public static final String PARAM_PROFILE_URL = "profileURL";
public static final String PARAM_PROFILE_OTHER = "profileOther";
public static final String PARAM_ARCHIVE = "archiveLocation";
public static String getFilterByTagLink(String uri, ThreadNode node, User user, String tag, String author) {
StringBuffer buf = new StringBuffer(64);

View File

@@ -0,0 +1,375 @@
package net.i2p.syndie.web;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import net.i2p.I2PAppContext;
import net.i2p.client.naming.*;
import net.i2p.data.*;
import net.i2p.syndie.*;
import net.i2p.syndie.data.*;
import net.i2p.syndie.sml.*;
/**
* Show the user's addressbook
*
*/
public class AddressesServlet extends BaseServlet {
public static final String PARAM_IS_PUBLIC = "addrPublic";
public static final String PARAM_NAME = "addrName";
public static final String PARAM_LOC = "addrLoc";
public static final String PARAM_FAVORITE = "addrFavorite";
public static final String PARAM_IGNORE = "addrIgnore";
public static final String PARAM_NET = "addrNet";
public static final String PARAM_PROTO = "addrProto";
public static final String PARAM_SYNDICATE = "addrSyndicate";
public static final String PARAM_ACTION = "action";
public static final String PROTO_BLOG = "syndieblog";
public static final String PROTO_ARCHIVE = "syndiearchive";
public static final String PROTO_I2PHEX = "i2phex";
public static final String PROTO_EEPSITE = "eep";
public static final String NET_SYNDIE = "syndie";
public static final String NET_I2P = "i2p";
public static final String NET_IP = "ip";
public static final String NET_FREENET = "freenet";
public static final String NET_TOR = "tor";
public static final String ACTION_DELETE_BLOG = "Delete author";
public static final String ACTION_UPDATE_BLOG = "Update author";
public static final String ACTION_ADD_BLOG = "Add author";
public static final String ACTION_DELETE_ARCHIVE = "Delete archive";
public static final String ACTION_UPDATE_ARCHIVE = "Update archive";
public static final String ACTION_ADD_ARCHIVE = "Add archive";
public static final String ACTION_DELETE_PEER = "Delete peer";
public static final String ACTION_UPDATE_PEER = "Update peer";
public static final String ACTION_ADD_PEER = "Add peer";
public static final String ACTION_DELETE_EEPSITE = "Delete eepsite";
public static final String ACTION_UPDATE_EEPSITE = "Update eepsite";
public static final String ACTION_ADD_EEPSITE = "Add eepsite";
public static final String ACTION_DELETE_OTHER = "Delete address";
public static final String ACTION_UPDATE_OTHER = "Update address";
public static final String ACTION_ADD_OTHER = "Add other address";
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
if (!user.getAuthenticated()) {
out.write("<tr><td colspan=\"3\">You must log in to view your addressbook</d></tr>\n");
} else {
PetNameDB db = user.getPetNameDB();
String uri = req.getRequestURI();
PetName pn = buildNewName(req, PROTO_BLOG);
renderBlogs(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_ARCHIVE);
renderArchives(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_I2PHEX);
renderI2Phex(user, db, uri, pn, out);
pn = buildNewName(req, PROTO_EEPSITE);
renderEepsites(user, db, uri, pn, out);
pn = buildNewName(req);
renderOther(user, db, uri, pn, out);
}
}
private void renderBlogs(User user, PetNameDB db, String baseURI, PetName newName, PrintWriter out) throws IOException {
TreeSet names = new TreeSet();
for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
PetName pn = db.getByName(name);
if (PROTO_BLOG.equals(pn.getProtocol()))
names.add(name);
}
out.write("<tr><td colspan=\"3\"><b>Syndie authors</b></td></tr>\n");
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
PetName pn = db.getByName((String)iter.next());
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_BLOG + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_SYNDIE + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" value=\"" + pn.getName() + "\" />" + pn.getName() + " ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + pn.getLocation() + "\" /> ");
if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE))
out.write("Favorite? <input type=\"checkbox\" name=\"" + PARAM_FAVORITE + "\" checked=\"true\" value=\"true\" /> ");
else
out.write("Favorite? <input type=\"checkbox\" name=\"" + PARAM_FAVORITE + "\" value=\"true\" /> ");
if (pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE + "\" checked=\"true\" value=\"true\" /> ");
} else {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE + "\" value=\"true\" /> ");
out.write("<a href=\"" + getControlTarget() + "?" + ThreadedHTMLRenderer.PARAM_AUTHOR + '='
+ pn.getLocation() + "\" title=\"View threads by the given author\">View posts</a> ");
}
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_BLOG + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_BLOG + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
}
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_BLOG + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_SYNDIE + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + newName.getLocation() + "\" /> ");
if (newName.isMember(FilteredThreadIndex.GROUP_FAVORITE))
out.write("Favorite? <input type=\"checkbox\" name=\"" + PARAM_FAVORITE + "\" checked=\"true\" value=\"true\" /> ");
else
out.write("Favorite? <input type=\"checkbox\" name=\"" + PARAM_FAVORITE + "\" value=\"true\" /> ");
if (newName.isMember(FilteredThreadIndex.GROUP_IGNORE)) {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE + "\" checked=\"true\" value=\"true\" /> ");
} else {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE + "\" value=\"true\" /> ");
}
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_BLOG + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
out.write("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
private void renderArchives(User user, PetNameDB db, String baseURI, PetName newName, PrintWriter out) throws IOException {
TreeSet names = new TreeSet();
for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
PetName pn = db.getByName(name);
if (PROTO_ARCHIVE.equals(pn.getProtocol()))
names.add(name);
}
out.write("<tr><td colspan=\"3\"><b>Syndie archives</b></td></tr>\n");
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
PetName pn = db.getByName((String)iter.next());
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_ARCHIVE + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_SYNDIE + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + pn.getName() + "\" />" + pn.getName() + " ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + pn.getLocation() + "\" /> ");
if (BlogManager.instance().syndicationScheduled(pn.getLocation()))
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />");
else
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />");
out.write("<a href=\"" + getSyndicateLink(user, pn.getName())
+ "\" title=\"Synchronize manually with the peer\">Sync manually</a> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_ARCHIVE + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_ARCHIVE + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
}
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_ARCHIVE + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_SYNDIE + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"20\" value=\"" + newName.getLocation() + "\" /> ");
if (BlogManager.instance().syndicationScheduled(newName.getLocation()))
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" checked=\"true\" value=\"true\" />");
else
out.write("Syndicate? <input type=\"checkbox\" name=\"" + PARAM_SYNDICATE + "\" value=\"true\" />");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_ARCHIVE + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
out.write("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
private void renderI2Phex(User user, PetNameDB db, String baseURI, PetName newName, PrintWriter out) throws IOException {
TreeSet names = new TreeSet();
for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
PetName pn = db.getByName(name);
if (PROTO_I2PHEX.equals(pn.getProtocol()))
names.add(name);
}
out.write("<tr><td colspan=\"3\"><b>I2Phex peers</b></td></tr>\n");
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
PetName pn = db.getByName((String)iter.next());
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_I2PHEX + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_I2P + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" value=\"" + pn.getName() + "\" />" + pn.getName() + " ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + pn.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_PEER + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_PEER + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
}
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_I2PHEX + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_I2P + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + newName.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_PEER + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
out.write("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
private void renderEepsites(User user, PetNameDB db, String baseURI, PetName newName, PrintWriter out) throws IOException {
TreeSet names = new TreeSet();
for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
PetName pn = db.getByName(name);
if (PROTO_EEPSITE.equals(pn.getProtocol()))
names.add(name);
}
out.write("<tr><td colspan=\"3\"><b>Eepsites</b></td></tr>\n");
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
PetName pn = db.getByName((String)iter.next());
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_EEPSITE + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_I2P + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" value=\"" + pn.getName() + "\" />" + pn.getName() + " ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + pn.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_EEPSITE + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_EEPSITE + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
}
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<input type=\"hidden\" name=\"" + PARAM_PROTO + "\" value=\"" + PROTO_EEPSITE + "\" />");
out.write("<input type=\"hidden\" name=\"" + PARAM_NET + "\" value=\"" + NET_I2P + "\" />");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + newName.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_EEPSITE + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
out.write("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
private void renderOther(User user, PetNameDB db, String baseURI, PetName newName, PrintWriter out) throws IOException {
TreeSet names = new TreeSet();
for (Iterator iter = db.getNames().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
PetName pn = db.getByName(name);
if (isRightProtocol(pn.getProtocol()))
names.add(name);
}
out.write("<tr><td colspan=\"3\"><b>Other addresses</b></td></tr>\n");
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
PetName pn = db.getByName((String)iter.next());
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (pn.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Network: <input type=\"text\" name=\"" + PARAM_NET + "\" value=\"" + pn.getNetwork() + "\" /> ");
out.write("Protocol: <input type=\"text\" name=\"" + PARAM_PROTO + "\" value=\"" + pn.getProtocol() + "\" /> ");
out.write("Name: <input type=\"hidden\" name=\"" + PARAM_NAME + "\" value=\"" + pn.getName() + "\" />" + pn.getName() +" ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + pn.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_DELETE_OTHER + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_UPDATE_OTHER + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
}
out.write("<form action=\"" + baseURI + "\" method=\"POST\">");
out.write("<tr><td colspan=\"3\">");
out.write("<input type=\"checkbox\" name=\"" + PARAM_IS_PUBLIC + "\" value=\"true\" " + (newName.getIsPublic() ? " checked=\"true\" " : "") + " />\n");
out.write("Network: <input type=\"text\" name=\"" + PARAM_NET + "\" value=\"" + newName.getNetwork() + "\" /> ");
out.write("Protocol: <input type=\"text\" name=\"" + PARAM_PROTO + "\" value=\"" + newName.getProtocol() + "\" /> ");
out.write("Name: <input type=\"text\" name=\"" + PARAM_NAME + "\" size=\"10\" value=\"" + newName.getName() + "\" /> ");
out.write("Location: <input type=\"text\" name=\"" + PARAM_LOC + "\" size=\"3\" value=\"" + newName.getLocation() + "\" /> ");
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_ADD_OTHER + "\" /> ");
out.write("</td></tr>\n");
out.write("</form>\n");
out.write("<tr><td colspan=\"3\"><hr /></td></tr>\n");
}
/** build the 'other' name passed in */
private PetName buildNewName(HttpServletRequest req) { return buildNewName(req, null); }
/** build a petname based by the request passed in, if the new entry is of the given protocol */
private PetName buildNewName(HttpServletRequest req, String protocol) {
PetName pn = new PetName();
if (!isRightProtocol(req, protocol)) {
pn.setIsPublic(true);
pn.setName("");
pn.setLocation("");
if (protocol == null)
pn.setProtocol("");
else
pn.setProtocol(protocol);
pn.setNetwork("");
return pn;
} else {
pn = buildNewAddress(req);
pn.setProtocol(protocol);
}
return pn;
}
private String getParam(HttpServletRequest req, String param) {
if (empty(req, param)) {
return "";
} else {
String val = req.getParameter(param);
return val;
}
}
private boolean isRightProtocol(HttpServletRequest req, String protocol) {
// if they hit submit, they are actually updating stuff, so don't include a 'new' one
if (!empty(req, PARAM_ACTION))
return false;
return isRightProtocol(protocol, req.getParameter(PARAM_PROTO));
}
private boolean isRightProtocol(String proto) { return isRightProtocol((String)null, proto); }
private boolean isRightProtocol(String proto, String reqProto) {
if (empty(reqProto))
return false;
if (proto == null) {
if (PROTO_ARCHIVE.equals(reqProto) ||
PROTO_BLOG.equals(reqProto) ||
PROTO_EEPSITE.equals(reqProto) ||
PROTO_I2PHEX.equals(reqProto))
return false;
else // its something other than the four default types
return true;
} else {
return proto.equals(reqProto);
}
}
}

View File

@@ -60,6 +60,7 @@ public abstract class BaseServlet extends HttpServlet {
req.getSession().setAttribute("user", user);
forceNewIndex = handleAddressbook(user, req) || forceNewIndex;
forceNewIndex = handleBookmarking(user, req) || forceNewIndex;
handleUpdateProfile(user, req);
@@ -148,6 +149,123 @@ public abstract class BaseServlet extends HttpServlet {
return rv;
}
private boolean handleAddressbook(User user, HttpServletRequest req) {
if ( (!user.getAuthenticated()) || (empty(AddressesServlet.PARAM_ACTION)) ) {
return false;
}
String action = req.getParameter(AddressesServlet.PARAM_ACTION);
if ( (AddressesServlet.ACTION_ADD_ARCHIVE.equals(action)) ||
(AddressesServlet.ACTION_ADD_BLOG.equals(action)) ||
(AddressesServlet.ACTION_ADD_EEPSITE.equals(action)) ||
(AddressesServlet.ACTION_ADD_OTHER.equals(action)) ||
(AddressesServlet.ACTION_ADD_PEER.equals(action)) ) {
PetName pn = buildNewAddress(req);
if ( (pn != null) && (pn.getName() != null) && (pn.getLocation() != null) &&
(!user.getPetNameDB().containsName(pn.getName())) ) {
user.getPetNameDB().add(pn);
BlogManager.instance().saveUser(user);
updateSyndication(user, pn.getLocation(), !empty(req, AddressesServlet.PARAM_SYNDICATE));
if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE) ||
pn.isMember(FilteredThreadIndex.GROUP_IGNORE))
return true;
else
return false;
} else {
// not valid, ignore
return false;
}
} else if ( (AddressesServlet.ACTION_UPDATE_ARCHIVE.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_BLOG.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_EEPSITE.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_OTHER.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_PEER.equals(action)) ) {
return updateAddress(user, req);
} else if ( (AddressesServlet.ACTION_DELETE_ARCHIVE.equals(action)) ||
(AddressesServlet.ACTION_DELETE_BLOG.equals(action)) ||
(AddressesServlet.ACTION_DELETE_EEPSITE.equals(action)) ||
(AddressesServlet.ACTION_DELETE_OTHER.equals(action)) ||
(AddressesServlet.ACTION_DELETE_PEER.equals(action)) ) {
PetName pn = user.getPetNameDB().getByName(req.getParameter(AddressesServlet.PARAM_NAME));
if (pn != null) {
user.getPetNameDB().remove(pn);
BlogManager.instance().saveUser(user);
updateSyndication(user, pn.getLocation(), false);
if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE) ||
pn.isMember(FilteredThreadIndex.GROUP_IGNORE))
return true;
else
return false;
} else {
return false;
}
} else {
// not an addressbook op
return false;
}
}
private boolean updateAddress(User user, HttpServletRequest req) {
PetName pn = user.getPetNameDB().getByName(req.getParameter(AddressesServlet.PARAM_NAME));
if (pn != null) {
boolean wasIgnored = pn.isMember(FilteredThreadIndex.GROUP_IGNORE);
boolean wasFavorite = pn.isMember(FilteredThreadIndex.GROUP_FAVORITE);
pn.setIsPublic(!empty(req, AddressesServlet.PARAM_IS_PUBLIC));
pn.setLocation(req.getParameter(AddressesServlet.PARAM_LOC));
pn.setNetwork(req.getParameter(AddressesServlet.PARAM_NET));
pn.setProtocol(req.getParameter(AddressesServlet.PARAM_PROTO));
if (empty(req, AddressesServlet.PARAM_FAVORITE))
pn.removeGroup(FilteredThreadIndex.GROUP_FAVORITE);
else
pn.addGroup(FilteredThreadIndex.GROUP_FAVORITE);
if (empty(req, AddressesServlet.PARAM_IGNORE))
pn.removeGroup(FilteredThreadIndex.GROUP_IGNORE);
else
pn.addGroup(FilteredThreadIndex.GROUP_IGNORE);
BlogManager.instance().saveUser(user);
if (AddressesServlet.PROTO_ARCHIVE.equals(pn.getProtocol()))
updateSyndication(user, pn.getLocation(), !empty(req, AddressesServlet.PARAM_SYNDICATE));
return (wasIgnored != pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) ||
(wasFavorite != pn.isMember(FilteredThreadIndex.GROUP_IGNORE));
} else {
return false;
}
}
protected void updateSyndication(User user, String loc, boolean shouldAutomate) {
if (BlogManager.instance().authorizeRemote(user)) {
if (shouldAutomate)
BlogManager.instance().scheduleSyndication(loc);
else
BlogManager.instance().unscheduleSyndication(loc);
}
}
protected PetName buildNewAddress(HttpServletRequest req) {
PetName pn = new PetName();
pn.setName(req.getParameter(AddressesServlet.PARAM_NAME));
pn.setIsPublic(!empty(req, AddressesServlet.PARAM_IS_PUBLIC));
pn.setLocation(req.getParameter(AddressesServlet.PARAM_LOC));
pn.setNetwork(req.getParameter(AddressesServlet.PARAM_NET));
pn.setProtocol(req.getParameter(AddressesServlet.PARAM_PROTO));
if (empty(req, AddressesServlet.PARAM_FAVORITE))
pn.removeGroup(FilteredThreadIndex.GROUP_FAVORITE);
else
pn.addGroup(FilteredThreadIndex.GROUP_FAVORITE);
if (empty(req, AddressesServlet.PARAM_IGNORE))
pn.removeGroup(FilteredThreadIndex.GROUP_IGNORE);
else
pn.addGroup(FilteredThreadIndex.GROUP_IGNORE);
return pn;
}
protected void handleUpdateProfile(User user, HttpServletRequest req) {
if ( (user == null) || (!user.getAuthenticated()) || (user.getBlog() == null) )
return;
@@ -261,6 +379,7 @@ public abstract class BaseServlet extends HttpServlet {
out.write("</a>\n");
out.write("(<a href=\"switchuser.jsp\" title=\"Log in as another user\">switch</a>)\n");
out.write("<a href=\"post.jsp\" title=\"Post a new thread\">Post a new thread</a>\n");
out.write("<a href=\"addresses.jsp\" title=\"View your addressbook\">Addressbook</a>\n");
} else {
out.write("<form action=\"" + req.getRequestURI() + "\" method=\"GET\">\n");
out.write("Login: <input type=\"text\" name=\"login\" />\n");
@@ -270,13 +389,22 @@ public abstract class BaseServlet extends HttpServlet {
//out.write("</td><td class=\"topNav_admin\">\n");
out.write("</span><span class=\"topNav_admin\">\n");
if (BlogManager.instance().authorizeRemote(user)) {
out.write("<a href=\"syndicate.jsp\" title=\"Syndicate data between other Syndie nodes\">Syndicate</a>\n");
out.write("<a href=\"" + getSyndicateLink(user, null) + "\" title=\"Syndicate data between other Syndie nodes\">Syndicate</a>\n");
out.write("<a href=\"importfeed.jsp\" title=\"Import RSS/Atom data\">Import RSS/Atom</a>\n");
out.write("<a href=\"admin.jsp\" title=\"Configure this Syndie node\">Admin</a>\n");
}
out.write("</span><!-- nav bar end -->\n</td></tr>\n");
}
protected String getSyndicateLink(User user, String archiveName) {
if ( (user != null) && (archiveName != null) ) {
PetName pn = user.getPetNameDB().getByName(archiveName);
if (pn != null)
return "syndicate.jsp?" + ThreadedHTMLRenderer.PARAM_ARCHIVE + "=" + pn.getLocation();
}
return "syndicate.jsp";
}
protected static final ArrayList SKIP_TAGS = new ArrayList();
static {
SKIP_TAGS.add("action");
@@ -317,7 +445,7 @@ public abstract class BaseServlet extends HttpServlet {
out.write("<input type=\"hidden\" name=\"" + param + "\" value=\"" + val + "\" />\n");
}
}
out.write("<tr class=\"controlBar\"><td colspan=\"2\">\n");
out.write("<tr class=\"controlBar\"><td colspan=\"2\" width=\"99%\">\n");
out.write("<!-- control bar begin -->\n");
out.write("Filter: <select name=\"" + ThreadedHTMLRenderer.PARAM_AUTHOR + "\">\n");
@@ -346,7 +474,7 @@ public abstract class BaseServlet extends HttpServlet {
out.write("Tags: <input type=\"text\" name=\"" + ThreadedHTMLRenderer.PARAM_TAGS + "\" size=\"10\" value=\"" + tags + "\" />\n");
out.write("<input type=\"submit\" name=\"action\" value=\"Go\" />\n");
out.write("</td><td class=\"controlBarRight\"><a href=\"#threads\" title=\"Jump to the thread navigation\">Threads</a></td>\n");
out.write("</td><td class=\"controlBarRight\" width=\"1%\"><a href=\"#threads\" title=\"Jump to the thread navigation\">Threads</a></td>\n");
out.write("<!-- control bar end -->\n");
out.write("</tr>\n");
out.write("</form>\n");

View File

@@ -135,22 +135,22 @@ public class ProfileServlet extends BaseServlet {
out.write("<tr><td colspan=\"3\">Currently ignored - threads they create are hidden.</td></tr>\n");
String remIgnore = getRemoveFromGroupLink(user, pn.getName(), FilteredThreadIndex.GROUP_IGNORE,
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + remIgnore + "\">Unignore " + pn.getName() + "</a></td></tr>\n");
out.write("<tr><td colspan=\"3\"><a href=\"" + remIgnore + "\">Unignore " + pn.getName() + "</a></td></tr>\n");
String remCompletely = getRemoveFromGroupLink(user, pn.getName(), "",
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
out.write("<tr><td colspan=\"3\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
} else if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE)) {
out.write("<tr><td colspan=\"3\">Currently marked as a favorite author - threads they participate in " +
"are highlighted.</td></tr>\n");
String remIgnore = getRemoveFromGroupLink(user, pn.getName(), FilteredThreadIndex.GROUP_FAVORITE,
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + remIgnore + "\">Remove " + pn.getName() + " from the list of favorite authors</a></td></tr>\n");
out.write("<tr><td colspan=\"3\"><a href=\"" + remIgnore + "\">Remove " + pn.getName() + " from the list of favorite authors</a></td></tr>\n");
String addIgnore = getAddToGroupLink(user, author, FilteredThreadIndex.GROUP_IGNORE,
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + addIgnore + "\" title=\"Threads by ignored authors are hidden from view\">Ignore the author</a></td></tr>");
out.write("<tr><td colspan=\"3\"><a href=\"" + addIgnore + "\" title=\"Threads by ignored authors are hidden from view\">Ignore the author</a></td></tr>");
String remCompletely = getRemoveFromGroupLink(user, pn.getName(), "",
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
out.write("<tr><td colspan=\"3\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
} else {
out.write("<tr><td colspan=\"3\">Currently bookmarked. Add them to your ");
String addFav = getAddToGroupLink(user, author, FilteredThreadIndex.GROUP_FAVORITE,
@@ -161,7 +161,7 @@ public class ProfileServlet extends BaseServlet {
out.write("<a href=\"" + addIgnore + "\" title=\"Threads by ignored authors are hidden from view\">ignored</a> list</td></tr>");
String remCompletely = getRemoveFromGroupLink(user, pn.getName(), "",
baseURI, "", "", "", "", "", author.toBase64());
out.write("<tr><td></td><td colspan=\"2\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
out.write("<tr><td colspan=\"3\"><a href=\"" + remCompletely + "\">Forget about " + pn.getName() + " entirely</a></td></tr>\n");
}
if (info != null) {