1
18 package net.bull.javamelody.internal.web.html;
19
20 import java.io.IOException;
21 import java.io.Writer;
22 import java.util.List;
23
24 import net.bull.javamelody.internal.model.JndiBinding;
25
26
30 class HtmlJndiTreeReport extends HtmlAbstractReport {
31 private final List<JndiBinding> jndiBindings;
32 private final String path;
33
34 HtmlJndiTreeReport(List<JndiBinding> jndiBindings, String path, Writer writer) {
35 super(writer);
36 assert jndiBindings != null;
37
38 this.jndiBindings = jndiBindings;
39 this.path = JndiBinding.normalizePath(path);
40 }
41
42 @Override
43 void toHtml() throws IOException {
44 writeLinks();
45 writeln("<br/>");
46
47 final String title;
48 if (path.isEmpty()) {
49 title = getString("Arbre_JNDI");
50 } else {
51 title = getFormattedString("Arbre_JNDI_pour_contexte", htmlEncode(path));
52 }
53 writeTitle("jndi.png", title);
54 writeTable();
55 }
56
57 private void writeTable() throws IOException {
58 final HtmlTable table = new HtmlTable();
59 table.beginTable(getString("Arbre_JNDI"));
60 write("<th>#Nom#</th><th>#Type#</th><th>#Value#</th>");
61 for (final JndiBinding binding : jndiBindings) {
62 table.nextRow();
63 writeBinding(binding);
64 }
65 table.endTable();
66 }
67
68 private void writeBinding(JndiBinding binding) throws IOException {
69 write("<td>");
70 final String name = binding.getName();
71 final String className = binding.getClassName();
72 final String contextPath = binding.getContextPath();
73 final String value = binding.getValue();
74 if (contextPath != null) {
75 writeDirectly("<a href=\"?part=jndi&path=" + urlEncode(contextPath) + "\">");
76 writeDirectly("<img width='16' height='16' src='?resource=folder.png' alt='"
77 + urlEncode(name) + "' /> ");
78 writeDirectly(htmlEncode(name));
79 writeDirectly("</a>");
80 } else {
81 writeDirectly(htmlEncode(name));
82 }
83 write("</td>");
84 write("<td>");
85 writeDirectly(className != null ? htmlEncode(className) : " ");
86 write("</td>");
87 write("<td>");
88 writeDirectly(value != null ? htmlEncodeButNotSpace(value) : " ");
89 write("</td>");
90 }
91
92 private void writeLinks() throws IOException {
93 writeln("<div class='noPrint'>");
94 writeln("<a class='back' href=''><img src='?resource=action_back.png' alt='#Retour#'/> #Retour#</a>");
95 writeln(" ");
96 writeDirectly("<a href='?#systeminfo'>");
97 writeln("<img src='?resource=action_home.png' alt='#Page_principale#'/> #Page_principale#</a>");
98 writeln(" ");
99 writeln("<a href='?part=jndi&path=" + htmlEncode(path)
100 + "'><img src='?resource=action_refresh.png' alt='#Actualiser#'/> #Actualiser#</a>");
101 if (isPdfEnabled()) {
102 writeln(" ");
103 write("<a href='?part=jndi&path=" + htmlEncode(path)
104 + "&format=pdf' title='#afficher_PDF#'>");
105 write("<img src='?resource=pdf.png' alt='#PDF#'/> #PDF#</a>");
106 }
107 writeln("</div>");
108 }
109 }
110