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