From 6c91b2d4a9b0ddca9c85068ac9ed85e38fc5491a Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Mon, 14 Nov 2005 02:09:23 +0000
Subject: [PATCH] migrate to the new system

---
 .../net/i2p/syndie/web/SyndicateServlet.java  | 151 ++++++++++++++++++
 apps/syndie/jsp/remote.jsp                    |  83 ----------
 apps/syndie/jsp/web.xml                       |   9 ++
 3 files changed, 160 insertions(+), 83 deletions(-)
 create mode 100644 apps/syndie/java/src/net/i2p/syndie/web/SyndicateServlet.java
 delete mode 100644 apps/syndie/jsp/remote.jsp

diff --git a/apps/syndie/java/src/net/i2p/syndie/web/SyndicateServlet.java b/apps/syndie/java/src/net/i2p/syndie/web/SyndicateServlet.java
new file mode 100644
index 0000000000..6018104f04
--- /dev/null
+++ b/apps/syndie/java/src/net/i2p/syndie/web/SyndicateServlet.java
@@ -0,0 +1,151 @@
+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.*;
+
+/**
+ * Syndicate with another remote Syndie node
+ *
+ */
+public class SyndicateServlet extends BaseServlet { 
+    protected String getTitle() { return "Syndie :: Syndicate"; }
+    
+    public static final String PARAM_SCHEMA = "schema";
+    
+    protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index, 
+                                        int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
+        if (!BlogManager.instance().authorizeRemote(user)) { 
+            out.write("<tr><td colspan=\"3\">Sorry, you are not authorized to access remote archives</td></tr>\n");
+        } else {
+            out.write("<form action=\"" + req.getRequestURI() + "\" method=\"POST\">");
+            displayForm(user, req, out);
+            handleRequest(user, req, index, out);
+            out.write("</form>\n");
+        }            
+    }
+    
+    private void handleRequest(User user, HttpServletRequest req, ThreadIndex index, PrintWriter out) throws IOException {
+        RemoteArchiveBean remote = getRemote(req);
+        String action = req.getParameter("action");
+        if ("Continue...".equals(action)) {
+            String location = req.getParameter("location");
+            String pn = req.getParameter("archivepetname");
+            if ( (pn != null) && (pn.trim().length() > 0) ) {
+                PetName pnval = user.getPetNameDB().getByName(pn);
+                if (pnval != null) location = pnval.getLocation();
+            }
+            
+            remote.fetchIndex(user, req.getParameter("schema"), location, 
+                              req.getParameter("proxyhost"), 
+                              req.getParameter("proxyport"));
+        } else if ("Fetch metadata".equals(action)) {
+            remote.fetchMetadata(user, req.getParameterMap());
+        } else if ("Fetch selected entries".equals(action)) {
+            //remote.fetchSelectedEntries(user, request.getParameterMap());
+            remote.fetchSelectedBulk(user, req.getParameterMap());
+        } else if ("Fetch all new entries".equals(action)) {
+            //remote.fetchAllEntries(user, request.getParameterMap());
+            remote.fetchSelectedBulk(user, req.getParameterMap());
+        } else if ("Post selected entries".equals(action)) {
+            remote.postSelectedEntries(user, req.getParameterMap());
+        }
+        String msgs = remote.getStatus();
+        if ( (msgs != null) && (msgs.length() > 0) ) { 
+            out.write("<pre class=\"b_remoteProgress\">");
+            out.write(msgs);
+            out.write("<a class=\"b_remoteProgress\" href=\"");
+            out.write(req.getRequestURI());
+            out.write("\">Refresh</a></pre><br />\n");
+        }
+        
+        if (remote.getFetchIndexInProgress()) { 
+            out.write("<span class=\"b_remoteProgress\">Please wait while the index is being fetched ");
+            out.write("from ");
+            out.write(remote.getRemoteLocation());
+            out.write(".</span>");
+        } else if (remote.getRemoteIndex() != null) {
+            // remote index is NOT null!
+            out.write("<span class=\"b_remoteLocation\">");
+            out.write(remote.getRemoteLocation());
+            out.write("</span>");
+            out.write("<a class=\"b_remoteRefetch\" href=\"");
+            out.write(req.getRequestURI());
+            out.write("?schema=" + remote.getRemoteSchema() + "&location=" + remote.getRemoteLocation());
+            if (remote.getProxyHost() != null && remote.getProxyPort() > 0) { 
+                out.write("&proxyhost=" + remote.getProxyHost() + "&proxyport=" + remote.getProxyPort());
+            } 
+            out.write("&action=Continue...\">(refetch)</a>:<br />\n");
+            
+            remote.renderDeltaForm(user, BlogManager.instance().getArchive().getIndex(), out);
+            out.write("<textarea class=\"b_remoteIndex\" rows=\"5\" cols=\"120\">" + 
+                      remote.getRemoteIndex().toString() + "</textarea>");
+        }
+        
+        out.write("</td></tr>\n");
+    }
+
+    private void displayForm(User user, HttpServletRequest req, PrintWriter out) throws IOException {
+        writeAuthActionFields(out);
+        out.write("<tr><td colspan=\"3\">");
+        out.write("<span class=\"b_remoteChooser\"><span class=\"b_remoteChooserField\">Import from:</span>\n");
+        out.write("<select class=\"b_remoteChooserNet\" name=\"schema\">\n");
+        String schema = req.getParameter(PARAM_SCHEMA);
+        out.write("<option value=\"web\" ");
+        if ("web".equals(schema))
+            out.write("selected=\"true\" ");
+        out.write(">I2P/Tor/Freenet</option>\n");
+
+        out.write("</select>\n");
+        out.write("<span class=\"b_remoteChooserField\">Proxy</span>\n");
+        out.write("<input class=\"b_remoteChooserHost\" type=\"text\" size=\"10\" name=\"proxyhost\" value=\"");
+        out.write(BlogManager.instance().getDefaultProxyHost());
+        out.write("\" />\n");
+        out.write("<input class=\"b_remoteChooserPort\" type=\"text\" size=\"4\" name=\"proxyport\" value=\"");
+        out.write(BlogManager.instance().getDefaultProxyPort());
+        out.write("\" /><br />\n");
+        out.write("<span class=\"b_remoteChooserField\">Bookmarked archives:</span>\n");
+        out.write("<select class=\"b_remoteChooserPN\" name=\"archivepetname\">");
+        out.write("<option value=\"\">Custom location</option>");
+
+        for (Iterator iter = user.getPetNameDB().iterator(); iter.hasNext(); ) {
+            PetName pn = (PetName)iter.next();
+            if (AddressesServlet.PROTO_ARCHIVE.equals(pn.getProtocol())) {
+                out.write("<option value=\"");
+                out.write(HTMLRenderer.sanitizeTagParam(pn.getName()));
+                out.write("\">");
+                out.write(HTMLRenderer.sanitizeString(pn.getName()));
+                out.write("</option>");
+            }
+        }
+        out.write("</select> or ");
+        out.write("<input type=\"text\" class=\"b_remoteChooserLocation\" name=\"location\" size=\"30\" value=\"");
+        String reqLoc = req.getParameter("location");
+        if (reqLoc != null)
+            out.write(reqLoc);
+        out.write("\" />\n");
+        out.write("<input class=\"b_remoteChooserContinue\" type=\"submit\" name=\"action\" value=\"Continue...\" /><br />\n");
+        out.write("</span>\n");
+    }
+
+    private static final String ATTR_REMOTE = "remote";
+    protected RemoteArchiveBean getRemote(HttpServletRequest req) {
+        RemoteArchiveBean remote = (RemoteArchiveBean)req.getSession().getAttribute(ATTR_REMOTE);
+        if (remote == null) {
+            remote = new RemoteArchiveBean();
+            req.getSession().setAttribute(ATTR_REMOTE, remote);
+        }
+        return remote;
+    }
+}
diff --git a/apps/syndie/jsp/remote.jsp b/apps/syndie/jsp/remote.jsp
deleted file mode 100644
index 0f79cbaa56..0000000000
--- a/apps/syndie/jsp/remote.jsp
+++ /dev/null
@@ -1,83 +0,0 @@
-<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.client.naming.PetName, net.i2p.syndie.web.*, net.i2p.syndie.*, net.i2p.syndie.sml.*, java.util.*" %><% 
-request.setCharacterEncoding("UTF-8"); 
-%><jsp:useBean scope="session" class="net.i2p.syndie.web.RemoteArchiveBean" id="remote" 
-/><jsp:useBean scope="session" class="net.i2p.syndie.User" id="user" 
-/><jsp:useBean scope="session" class="net.i2p.syndie.data.TransparentArchiveIndex" id="archive" 
-/><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
-<html>
-<head>
-<title>SyndieMedia remote</title>
-<link href="style.jsp" rel="stylesheet" type="text/css" >
-</head>
-<body>
-<table border="1" cellpadding="0" cellspacing="0" width="100%">
-<tr class="b_toplogo"><td colspan="5" valign="top" align="left" class="b_toplogo"><jsp:include page="_toplogo.jsp" /></td></tr>
-<tr><td valign="top" align="left" rowspan="2" class="b_leftnav"><jsp:include page="_leftnav.jsp" /></td>
-    <jsp:include page="_topnav.jsp" />
-    <td valign="top" align="left" rowspan="2" class="b_rightnav"><jsp:include page="_rightnav.jsp" /></td></tr>
-<tr class="b_content"><td valign="top" align="left" colspan="3" class="b_content"><%
-if (!BlogManager.instance().authorizeRemote(user)) { 
-%><span class="b_remoteMsgErr">Sorry, you are not allowed to access remote archives from here.  Perhaps you should install Syndie yourself?</span><%
-} else { %><form action="remote.jsp" method="POST"><span class="b_remoteChooser"><span class="b_remoteChooserField">Import from:</span>
-<select class="b_remoteChooserNet" name="schema">
- <option value="web" <%=("web".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>I2P/TOR/Freenet</option>
- <option value="mnet" <%=("mnet".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>MNet</option>
- <option value="feedspace" <%=("feedspace".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>Feedspace</option>
- <option value="usenet" <%=("usenet".equals(request.getParameter("schema")) ? "selected=\"true\"" : "")%>>Usenet</option>
-</select> 
-<span class="b_remoteChooserField">Proxy</span> 
-  <input class="b_remoteChooserHost" type="text" size="10" name="proxyhost" value="<%=BlogManager.instance().getDefaultProxyHost()%>" />
-  <input class="b_remoteChooserPort" type="text" size="4" name="proxyport" value="<%=BlogManager.instance().getDefaultProxyPort()%>" /><br />
-<span class="b_remoteChooserField">Bookmarked archives:</span> <select class="b_remoteChooserPN" name="archivepetname"><option value="">Custom location</option><%
-for (Iterator iter = user.getPetNameDB().iterator(); iter.hasNext(); ) {
-  PetName pn = (PetName)iter.next();
-  if ("syndiearchive".equals(pn.getProtocol())) {
-    %><option value="<%=HTMLRenderer.sanitizeTagParam(pn.getName())%>"><%=HTMLRenderer.sanitizeString(pn.getName())%></option><%
-  }
-}
-%></select> or 
-<input class="b_remoteChooserLocation" name="location" size="30" value="<%=(request.getParameter("location") != null ? request.getParameter("location") : "")%>" /> 
-<input class="b_remoteChooserContinue" type="submit" name="action" value="Continue..." /><br />
-</span>
-<%
-  String action = request.getParameter("action");
-  if ("Continue...".equals(action)) {
-    String location = request.getParameter("location");
-    String pn = request.getParameter("archivepetname");
-    if ( (pn != null) && (pn.trim().length() > 0) ) {
-      PetName pnval = user.getPetNameDB().getByName(pn);
-      if (pnval != null) location = pnval.getLocation();
-    }
-    remote.fetchIndex(user, request.getParameter("schema"), location, request.getParameter("proxyhost"), request.getParameter("proxyport"));
-  } else if ("Fetch metadata".equals(action)) {
-    remote.fetchMetadata(user, request.getParameterMap());
-  } else if ("Fetch selected entries".equals(action)) {
-    //remote.fetchSelectedEntries(user, request.getParameterMap());
-    remote.fetchSelectedBulk(user, request.getParameterMap());
-  } else if ("Fetch all new entries".equals(action)) {
-    //remote.fetchAllEntries(user, request.getParameterMap());
-    remote.fetchSelectedBulk(user, request.getParameterMap());
-  } else if ("Post selected entries".equals(action)) {
-    remote.postSelectedEntries(user, request.getParameterMap());
-  }
-  String msgs = remote.getStatus();
-  if ( (msgs != null) && (msgs.length() > 0) ) { %><pre class="b_remoteProgress"><%=msgs%>
-<a class="b_remoteProgress" href="remote.jsp">Refresh</a></pre><br /><% 
-  }
-  if (remote.getFetchIndexInProgress()) { %><span class="b_remoteProgress">Please wait while the index is being fetched 
-from <%=remote.getRemoteLocation()%>.</span><%
-  } else if (remote.getRemoteIndex() != null) {
-    // remote index is NOT null!
-   %><span class="b_remoteLocation"><%=remote.getRemoteLocation()%></span>
-<a class="b_remoteRefetch" href="remote.jsp?schema=<%=remote.getRemoteSchema()%>&location=<%=remote.getRemoteLocation()%><%
-if (remote.getProxyHost() != null && remote.getProxyPort() > 0) { 
-  %>&proxyhost=<%=remote.getProxyHost()%>&proxyport=<%=remote.getProxyPort()%><%
-} %>&action=Continue...">(refetch)</a>:<br />
-<%remote.renderDeltaForm(user, archive, out);%>
-<textarea class="b_remoteIndex" rows="5" cols="120"><%=remote.getRemoteIndex()%></textarea><%
-  }
-}
-%>
-</td></form></tr>
-</table>
-</body>
\ No newline at end of file
diff --git a/apps/syndie/jsp/web.xml b/apps/syndie/jsp/web.xml
index cf55c9df3b..22bb37ee1f 100644
--- a/apps/syndie/jsp/web.xml
+++ b/apps/syndie/jsp/web.xml
@@ -44,6 +44,11 @@
      <servlet-class>net.i2p.syndie.web.AdminServlet</servlet-class>
     </servlet>
      
+    <servlet>
+     <servlet-name>net.i2p.syndie.web.SyndicateServlet</servlet-name>
+     <servlet-class>net.i2p.syndie.web.SyndicateServlet</servlet-class>
+    </servlet>
+     
     <servlet>
 	 <servlet-name>net.i2p.syndie.UpdaterServlet</servlet-name>
 	 <servlet-class>net.i2p.syndie.UpdaterServlet</servlet-class>
@@ -90,6 +95,10 @@
       <servlet-name>net.i2p.syndie.web.AdminServlet</servlet-name>
       <url-pattern>/admin.jsp</url-pattern>
     </servlet-mapping>
+    <servlet-mapping> 
+      <servlet-name>net.i2p.syndie.web.SyndicateServlet</servlet-name>
+      <url-pattern>/syndicate.jsp</url-pattern>
+    </servlet-mapping>
     
     <session-config>
         <session-timeout>
-- 
GitLab