1 /*
   2  * $Id$
   3  *
   4  * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.  Oracle designates this
  10  * particular file as subject to the "Classpath" exception as provided
  11  * by Oracle in the LICENSE file that accompanied this code.
  12  *
  13  * This code is distributed in the hope that it will be useful, but WITHOUT
  14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16  * version 2 for more details (a copy is included in the LICENSE file that
  17  * accompanied this code).
  18  *
  19  * You should have received a copy of the GNU General Public License version
  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.servlets;
  28 
  29 import java.io.*;
  30 import java.nio.charset.StandardCharsets;
  31 import java.util.Iterator;
  32 import javax.servlet.ServletException;
  33 import javax.servlet.http.HttpServlet;
  34 import javax.servlet.http.HttpServletRequest;
  35 import javax.servlet.http.HttpServletResponse;
  36 import com.sun.javatest.ExcludeList;
  37 import com.sun.javatest.util.StringArray;
  38 
  39 public class ExcludeBrowser extends HttpServlet {
  40     public void doGet(HttpServletRequest req, HttpServletResponse res)
  41                 throws ServletException, IOException {
  42         String uri = req.getRequestURI();
  43         File file = new File(req.getRealPath(uri));
  44 
  45         if (!file.exists()) {
  46             res.sendError(HttpServletResponse.SC_NOT_FOUND);
  47             return;
  48         }
  49 
  50         ExcludeList excludeList;
  51         try {
  52             excludeList = new ExcludeList(file);
  53         }
  54         catch (ExcludeList.Fault e) {
  55             String msg =
  56                 "The file does not appear to be a valid exclude-list file. " +
  57                 "The following exception was received while trying to open it: " +
  58                 e.toString();
  59             res.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
  60             return;
  61         }
  62         catch (IOException e) {
  63             String msg =
  64                 "The file does not appear to be a valid exclude-list file. " +
  65                 "The following exception was received while trying to open it: " +
  66                 e.toString();
  67             res.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
  68             return;
  69         }
  70 
  71         String bugLink = getInitParameter("bugLink");
  72 
  73         res.setContentType("text/html");
  74         PrintWriter out = new PrintWriter(new OutputStreamWriter(res.getOutputStream(), StandardCharsets.UTF_8), true);
  75         out.println("<html>");
  76         out.println("<head>");
  77         out.println("<title>" + file + "</title>");
  78         out.println("</head>");
  79         out.println("<body>");
  80 
  81         if (excludeList.size() == 0)
  82             out.println("Exclude list is empty.");
  83         else {
  84             out.println("<table border=1>");
  85             for (Iterator<?> iter = excludeList.getIterator(false); iter.hasNext(); ) {
  86                 ExcludeList.Entry entry = (ExcludeList.Entry) (iter.next());
  87                 String[] bugIds = entry.getBugIdStrings();
  88                 StringBuffer bugIdText = new StringBuffer();
  89                 for (int i = 0; i < bugIds.length; i++) {
  90                     if (i > 0)
  91                         bugIdText.append(" ");
  92                     String b = bugIds[i];
  93                     if (bugLink == null)
  94                         bugIdText.append(b);
  95                     else
  96                         bugIdText.append("<a href=\"" + bugLink + b + "\">" + b + "</a>");
  97                 }
  98                 out.print("<tr>");
  99                 out.print("<td>" + entry.getRelativeURL());
 100                 if (entry.getTestCases() != null) {
 101                     out.print("[" + entry.getTestCases() + "]");
 102                 }
 103                 out.print("<td>" + bugIdText);
 104                 out.print("<td>" + StringArray.join(entry.getPlatforms()));
 105                 out.print("<td>" + entry.getSynopsis());
 106                 out.println();
 107             }
 108             out.println("</table>");
 109         }
 110 
 111         out.println("<p><hr>");
 112 
 113         // trailer
 114         out.println("File: <em>" + file + "</em>");
 115         out.println("</body>");
 116         out.println("</html>");
 117         out.close();
 118     }
 119 }