1    //
2    // SwitchRMI  Framework
3    // Copyright (c) 2000-2002 by Michael J. Henderson & Associates.
4    //
5    // Michael Henderson
6    // http://switchrmi.sf.net
7    // mailto:mikehenderson@dunelm.org.uk
8    //
9    // This library is free software.
10   //
11   // You may redistribute it and/or modify it under the terms of the GNU
12   // Lesser General Public License as published by the Free Software Foundation.
13   //
14   // Version 2.1 of the license should be included with this distribution in
15   // the file LICENSE, as well as License.html. If the license is not
16   // included with this distribution, you may find a copy at the FSF web
17   // site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
18   // Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
19   //
20   // This library is distributed in the hope that it will be useful,
21   // but WITHOUT ANY WARRANTY; without even the implied waranty of
22   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23   // Lesser General Public License for more details.
24   //
25   // $Id: HtmlIndexResponse.java,v 1.1 2002/11/11 22:19:48 mikehenderson Exp $
26   package com.mjh.switchrmi.protocol.html;
27   
28   import com.mjh.switchrmi.*;
29   import com.mjh.switchrmi.jndi.*;
30   
31   import java.io.*;
32   
33   import java.util.*;
34   
35   import javax.naming.*;
36   
37   public class HtmlIndexResponse
38       extends HtmlResponse
39   {
40       public HtmlIndexResponse()
41       {
42       }
43   
44       public HtmlIndexResponse(InputStream in)
45       {
46           super(in);
47       }
48   
49       protected String toHtmlString()
50                              throws Exception
51       {
52           Context jndiCtx = context.getJndiContext();
53           Context ctx = (Context) jndiCtx.lookup("/switchrmi/service/object");
54           Hashtable env = ctx.getEnvironment();
55   
56           Collection names = new TreeSet(env.keySet());
57   
58           StringBuffer sb = new StringBuffer();
59   
60           sb.append("<html>\n");
61           sb.append("<head>\n");
62           sb.append("  <title>SwitchRMI Inspector</title>\n");
63           appendStyles(sb);
64           sb.append("</head>\n");
65           sb.append("<body bgcolor=\"lightsteelblue\">\n");
66           sb.append("<p class=\"heading\">\n");
67           sb.append("SwitchRMI Deployed Objects\n");
68           sb.append("<p>\n");
69           sb.append("The following objects are deployed in this instance. Click on the object name\n");
70           sb.append("for further detail.\n");
71           sb.append("<p>\n");
72           sb.append("<table border=\1\" cellpadding=\"2\" cellspacing=\"0\">\n");
73           sb.append("  <tr>\n");
74           sb.append("    <th valign=\"top\" align=\"center\" >Name</th>\n");
75           sb.append("    <th valign=\"top\" align=\"center\" >Description</th>\n");
76           sb.append("  </tr>\n");
77   
78           Iterator iterator = names.iterator();
79   
80           while (iterator.hasNext())
81           {
82               String name = (String) iterator.next();
83               ObjectReferenceable ref = (ObjectReferenceable) env.get(name);
84   
85               sb.append("  <tr>\n");
86               sb.append("    <td valign=\"top\" ><a href=\"" + name + ".html\">"
87                         + name + "</a></td>\n");
88               sb.append("    <td valign=\"top\" >" + ref.getDescription()
89                         + "</td>\n");
90               sb.append("  </tr>\n");
91           }
92   
93           sb.append("</table>\n");
94   
95           sb.append("</body>\n");
96           sb.append("</html>\n");
97   
98           htmlString = sb.toString();
99   
100          return htmlString;
101      }
102  
103      public Object getObject()
104      {
105          return htmlString;
106      }
107  }