1 4 5 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 mIsInitializedLock = new Object (); 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 username) 31 throws IOException 32 { 33 String 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 buf = new StringBuffer ("<list>"); 41 Set set = group.list(users); 42 Iterator iter = set.iterator(); 43 while (iter.hasNext()) { 44 buf.append("<user name=\"") 45 .append((String )iter.next()) 46 .append("\" />"); 47 } 48 buf.append("</list>"); 49 50 mLogger.debug(buf.toString()); 51 52 String 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 |