List Packages and Components(this howto is deprecated)Tag(s): DEPRECATED


Here a Servlet that will display Packages and their Components. This is done by looking at a Jaguar property to extract the package names. Then we are listing the props related to a particuliar package.
package com.rgagnon.servlet;

import javax.servlet.*;
import javax.servlet.http.*;

public class ListPackage extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void destroy() { }

    protected void processRequest
     (HttpServletRequest request, HttpServletResponse response)
     throws ServletException, java.io.IOException {
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();

        try {
            String hostname = request.getServerName();
            String servername =
               com.sybase.jaguar.server.Jaguar.getServerName();
            //
            // path is a INIT servlet parameter
            //  for example, path = c:/program files/sybase/jaguar cts 3.5
            //
            String jagPath = getInitParameter("path");
            String jagProps =
               jagPath + "/Repository/Server/" + servername + ".props";

            java.util.Properties p = new java.util.Properties();
            p.load(new java.io.FileInputStream(jagProps));

            out.println
              ("<html><head><title>Packages</title></head><body>");
            out.println
              ("<b>hostname</b> " + hostname + "   [" + servername + "]");

            out.println("<P>Packages:<br><br>") ;

            java.util.StringTokenizer st =
                new java.util.StringTokenizer
                 (p.getProperty("com.sybase.jaguar.server.packages"), ",");
            while(st.hasMoreTokens()){
                String aPackage=st.nextToken();
                out.println("<b>" + aPackage + "</b><br>" );
                //   scanning props for related components
                PropsFilter nf = new PropsFilter("props");
                java.io.File dir = new java.io.File
                    (jagPath + "/Repository/Component/"+ aPackage);
                String[] strs = dir.list(nf);
                for (int i = 0; i < strs.length; i++) {
                    String aComponent =
                        strs[i].substring(0, strs[i].indexOf(".props"));
                    // get the type (pb, ejb, ...)
                    java.util.Properties pc = new java.util.Properties();
                    pc.load
                      (new java.io.FileInputStream
                        (jagPath + "/Repository/Component/"
                         + aPackage + "/" + strs[i]));
                    out.println
                        ("&nbsp;&nbsp;" + aComponent
                         +"&nbsp;<FONT size='1'>("
                         + pc.getProperty
                             ("com.sybase.jaguar.component.type")
                         +")</FONT><br>");
                    }
                }
            }

            out.println("</body></html>");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            out.close();
        }

    }

    protected void doGet
      (HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {
        processRequest(request, response);
    }

    protected void doPost
      (HttpServletRequest request, HttpServletResponse response)
       throws ServletException, java.io.IOException {
        processRequest(request, response);
    }

    public String getServletInfo() {
        return "List Packages and Components";
    }

}
package com.rgagnon.servlet;

import java.io.File;
import java.io.FilenameFilter;

public class PropsFilter implements FilenameFilter {
  String pattern;
  public PropsFilter (String str) {
    pattern = str;
    }
  public boolean accept (File dir, String name) {
    return name.endsWith(pattern);
    }
 }

blog comments powered by Disqus