/* VCServlet.java * * Copyright (c) 2001, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka */ package org.gzigzag.module; import org.gzigzag.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; /** A Virtual Community demo servlet. */ public class VCServlet extends ZZServlet { public static final String rcsid = "$Id: VCServlet.java,v 1.1 2002/10/07 12:37:35 tuukkah Exp $"; String getURL(ZZCell c) { return "org.gzigzag.module.VCServlet?"+c.getID(); } void printAuthor(ZZCell txt, PrintWriter wr) { ZZCell h = txt.h("d.author", true); if(h != null) { wr.print(""+h.getText()+""); } } void printmsg(ZZCell h, PrintWriter wr) { printAuthor(h, wr); wr.print(": "); wr.print(""+ h.getText() + ""); } void printRefs(ZZCell thing, PrintWriter wr) { wr.print("

Referenced in:

\n"); } void printAuthored(ZZCell thing, PrintWriter wr) { wr.print("

Messages written:

\n"); } void printReplies(ZZCell thing, PrintWriter wr) { thing = thing.s("d.replies"); if(thing == null) return; wr.print("

Replies:

\n"); } void printText(ZZCell start, PrintWriter wr) { wr.print("

"+start.getText()+"

"); ZZCell im = start.h("d.images", true); if(im != null) { wr.print(""); } printAuthor(start, wr); wr.print("

"); ZZCell orig = start; while((start = start.s("d.text")) != null) { ZZCell h = start.h("d.kahva", true); String txt = start.getText(); if(h != null) { txt = ""+ txt + ""; } wr.print(txt); } if(orig.s("d.author", -1) == null) printAuthored(orig, wr); ZZCell inreply = orig.h("d.replies-list").s("d.replies",-1); if(inreply != null) { wr.print("

In reply to "); printmsg(inreply, wr); } printReplies(orig, wr); printRefs(orig, wr); } protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { try { synchronized(space) { // resp.getWriter().print("HELLO\n\n!!\n\n"); String s = req.getQueryString(); PrintWriter wr = resp.getWriter(); wr.print("HELLO\n\n!!\n\n Query: '"+s+"'\n"); ZZCell c; if(s == null || s.equals("")) c = space.getHomeCell().s("d.1"); else c = space.getCellByID(s); wr.print("
Cell content: '"+c.getText()+"'\n"); printText(c, wr); wr.close(); } } catch(Exception e) { throw new ServletException("doGet: ", e); } } }