The easy Weblog and Wiki Software
[ start | index | login ]
start > comment-phobia > graph macro test-13

graph macro test-13 commented phobia/graph macro test

Created by Victor Volle. Last edited by Victor Volle, 3 years and 239 days ago. Viewed 188 times. #7
[diff] [history] [edit] [rdf]
labels
attachments
Possible patch

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(""/>"); }

16 comments (by phobia, val42, goresc, hotmaz, josh, JotFried, girvine, leo, rol, rbtst, Victor Volle, aos, eoinwoods, test) | post comment

What is SnipSnap?
SnipSnap is a free and easy to install weblog and wiki tool written in Java.

SnipSnap download
Current version: 1.0b3-uttoxeter
Try our >>Web Start Demo!

Resources

5567 Users and 13712 Snips. Installed 6 years and 9 days ago

Logged in Users: (1)
… and 15 Guests.

snipsnap-changed for older changes.

< July 2008 >
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031

snipsnap
Listed on BlogShares
XHTML 1.0 validated
CSS validated
RSS 2.0 validated
RSS Feed

pico-powered

Powered by SnipSnap 1.0b3-uttoxeter
YourKit >>Java Profiler

Fraunhofer FIRST

snipsnap.org | Copyright 2000-2006 Fraunhofer FIRST