KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderLIST


1 /******************************************************************************
2  * ResponderLIST.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.*;
14 import javax.servlet.*;
15 import javax.servlet.http.*;
16 import org.openlaszlo.connection.*;
17 import org.openlaszlo.media.*;
18 import org.openlaszlo.utils.*;
19 import org.openlaszlo.xml.internal.*;
20 import org.apache.log4j.*;
21
22 public final class ResponderLIST extends ResponderConnection
23 {
24     private static boolean mIsInitialized = false;
25     private static Object JavaDoc mIsInitializedLock = new Object JavaDoc();
26
27     private static Logger mLogger = Logger.getLogger(ResponderLIST.class);
28
29     protected void respondImpl(HttpServletRequest req, HttpServletResponse res,
30                                Application app, int serial, String JavaDoc username)
31         throws IOException
32     {
33         String JavaDoc users = req.getParameter("users");
34         if (users==null||users.equals("")) {
35             respondWithErrorSWF(res, "missing 'users' parameter");
36             return;
37         }
38
39         ConnectionGroup group = app.getConnectionGroup();
40         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("<list>");
41         Set set = group.list(users);
42         Iterator iter = set.iterator();
43         while (iter.hasNext()) {
44             buf.append("<user name=\"")
45                 .append((String JavaDoc)iter.next())
46                 .append("\" />");
47         }
48         buf.append("</list>");
49
50         mLogger.debug(buf.toString());
51
52         String JavaDoc xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
53             "<!DOCTYPE laszlo-data>" +
54             "<resultset s=\"" + serial + "\">"
55             + buf.toString()
56             + "</resultset>";
57
58         res.setContentType(MimeType.SWF);
59
60         ServletOutputStream sos = res.getOutputStream();
61         try {
62             InputStream swfbytes = DataCompiler.compile(xml, mSWFVersionNum);
63             FileUtils.sendToStream(swfbytes, sos);
64             sos.flush();
65
66         } catch (FileUtils.StreamWritingException e) {
67             mLogger.warn("StreamWritingException while sending list response: " + e.getMessage());
68         } catch (DataCompilerException e) {
69             respondWithExceptionSWF(res, e);
70             return;
71         } finally {
72             FileUtils.close(sos);
73         }
74     }
75 }
76
Popular Tags