Index: org/snipsnap/net/RenderServlet.java
===================================================================
RCS file: /var/cvs/snip/src/org/snipsnap/net/RenderServlet.java,v
retrieving revision 1.6.2.1
diff -u -r1.6.2.1 RenderServlet.java
--- org/snipsnap/net/RenderServlet.java 18 Aug 2004 12:20:37 -0000 1.6.2.1
+++ org/snipsnap/net/RenderServlet.java 24 Nov 2004 00:37:58 -0000
@@ -36,7 +36,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.Collections; /**
* Get some data from a snip and render the content
@@ -45,12 +45,39 @@
* @version $Id: RenderServlet.java,v 1.6.2.1 2004/08/18 12:20:37 leo Exp $
*/
public class RenderServlet extends HttpServlet {
- private static Map contentMap = new WeakHashMap();
+ private static Map contentMap = Collections.synchronizedMap(new HashMap());
private Map handlers = new HashMap();
private final static ContentRenderer DEFAULT_HANDLER = new HorizontalContentRenderer();- public static void addContent(String id, String content) {
- contentMap.put(id, content);
+ /**
+ * Temporarily stores some content that will later be retrieved using the id that
+ * is returned.
+ * This can be used if some content must be retrieved after the normal HTML has been rendered.
+ * This is used by the {@link org.snipsnap.render.macro.GraphMacro} which stores its
+ * content here and generates something like:
+ * <pre>
+ * <img src="....?id=XXX"/>
+ * </pre>
+ *
+ * The id in the URL is the id that is used as a key to retrieve the content when
+ * the browser retrieves the image. Which is then rendered on the fly using the
+ * content.
+ *
+ * @param content
+ * @return the id that is later used to retrieve the content
+ */
+ public static String addContent(String content) {
+ String key = null;
+ synchronized (contentMap) {
+ int add = 0;
+ int hashCode = content.hashCode();
+ do {
+ key = String.valueOf(hashCode + add);
+ add++;
+ } while ( contentMap.containsKey(key) );
+ contentMap.put(key, content);
+ }
+ return key;
} public void init() throws ServletException {
@@ -69,6 +96,7 @@
String handler = request.getParameter("handler");
String id = request.getParameter("id");
String content = (String) contentMap.get(id);
+ contentMap.remove(id); ContentRenderer renderer = (ContentRenderer) handlers.get(handler);
if (null == renderer) {
Index: org/snipsnap/render/macro/GraphMacro.java
===================================================================
RCS file: /var/cvs/snip/src/org/snipsnap/render/macro/GraphMacro.java,v
retrieving revision 1.14.2.1
diff -u -r1.14.2.1 GraphMacro.java
--- org/snipsnap/render/macro/GraphMacro.java 18 Aug 2004 12:20:37 -0000 1.14.2.1
+++ org/snipsnap/render/macro/GraphMacro.java 24 Nov 2004 00:37:58 -0000
@@ -70,8 +70,7 @@
writer.write(handler); String content = Encoder.unescape(params.getContent());
- String id = "" + content.hashCode();
- RenderServlet.addContent(id, content);
+ String id = RenderServlet.addContent(content);
writer.write("&id=" + id);
writer.write(""/>");
}