]> WPIA git - gigi.git/blob - util-testing/org/cacert/gigi/GenerateProfileOverview.java
upd: move CertificateProfile overview generation to own tool
[gigi.git] / util-testing / org / cacert / gigi / GenerateProfileOverview.java
1 package org.cacert.gigi;
2
3 import java.awt.Desktop;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.io.InputStreamReader;
8 import java.io.PrintWriter;
9 import java.io.Reader;
10 import java.util.LinkedList;
11 import java.util.Properties;
12 import java.util.TreeSet;
13
14 import org.cacert.gigi.database.DatabaseConnection;
15 import org.cacert.gigi.dbObjects.CertificateProfile;
16 import org.cacert.gigi.dbObjects.CertificateProfile.PropertyTemplate;
17
18 public class GenerateProfileOverview {
19
20     public static void main(String[] args) throws IOException {
21         Properties pr = new Properties();
22         try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) {
23             pr.load(reader);
24         }
25         DatabaseConnection.init(pr);
26
27         TreeSet<String> pt = new TreeSet<>();
28         TreeSet<String> req = new TreeSet<>();
29         LinkedList<CertificateProfile> cps = new LinkedList<>();
30         for (CertificateProfile cp : CertificateProfile.getAll()) {
31             cps.add(cp);
32             for (PropertyTemplate p : cp.getTemplates().values()) {
33                 pt.add(p.getBase());
34             }
35             req.addAll(cp.getReqireds());
36         }
37         PrintWriter pw = new PrintWriter("profiles.html");
38         pw.println("<!DOCTYPE html><html><head><title>Profiles</title>");
39         pw.println("<style>.split{background-color:#000;margin:0;cell-spacing:0}td{text-align:center}</style>");
40         pw.println("</head>");
41         pw.println("<body><table border='1'>");
42         pw.println("<tr><td>id</td><td> </td>");
43         for (String p : pt) {
44             pw.println("<th>" + p + "</th>");
45         }
46         pw.println("<th class='split'></th>");
47         for (String p : req) {
48             pw.println("<th class='req'>" + p + "</th>");
49         }
50         pw.println("</tr>");
51         for (CertificateProfile certificateProfile : cps) {
52             pw.println("<tr>");
53             pw.println("<td>" + certificateProfile.getId() + "</td>");
54             pw.println("<td>" + certificateProfile.getKeyName() + "</td>");
55             outer:
56             for (String p : pt) {
57                 for (PropertyTemplate t : certificateProfile.getTemplates().values()) {
58                     if (t.getBase().equals(p)) {
59                         pw.println("<td>" + (t.isRequired() ? (t.isMultiple() ? "+" : "y") : (t.isMultiple() ? "*" : "?")) + "</td>");
60                         continue outer;
61                     }
62                 }
63                 pw.println("<td></td>");
64             }
65             pw.println("<td class='split'></td>");
66             outer:
67             for (String p : req) {
68                 for (String t : certificateProfile.getReqireds()) {
69                     if (t.equals(p)) {
70                         pw.println("<td class='req'>y</td>");
71                         continue outer;
72                     }
73                 }
74                 pw.println("<td></td>");
75             }
76             pw.println("</tr>");
77         }
78         pw.println("</table></body></html>");
79         Desktop.getDesktop().browse(new File("profiles.html").toURI());
80         pw.close();
81     }
82
83 }