1
18 package net.bull.javamelody.internal.web;
19
20 import java.io.IOException;
21 import java.io.Writer;
22 import java.util.LinkedHashMap;
23 import java.util.Map;
24
25 import net.bull.javamelody.Parameter;
26 import net.bull.javamelody.internal.common.I18N;
27 import net.bull.javamelody.internal.model.Collector;
28 import net.bull.javamelody.internal.model.CollectorServer;
29 import net.bull.javamelody.internal.model.Range;
30
31
35 public class JnlpPage {
36 public static final String JNLP_PREFIX = "jnlp.";
37 private final Collector collector;
38 private final CollectorServer collectorServer;
39 private final String codebase;
40 private final String cookies;
41 private final Range range;
42 private final Writer writer;
43
44 JnlpPage(Collector collector, CollectorServer collectorServer, String codebase, String cookies,
45 Range range, Writer writer) {
46 super();
47 this.collector = collector;
48 this.collectorServer = collectorServer;
49 this.codebase = codebase;
50 this.cookies = cookies;
51 this.range = range;
52 this.writer = writer;
53 }
54
55 void toJnlp() throws IOException {
56 println("<jnlp spec='1.0+' codebase='" + codebase + "'>");
57 println(" <information>");
58 println(" <title>JavaMelody</title>");
59 println(" <vendor>JavaMelody</vendor>");
60 println(" <description>Monitoring</description>");
61 println(" <icon href='" + codebase + "?resource=systemmonitor.png'/>");
62 println(" <offline-allowed />");
63 println(" </information>");
64 println(" <security> <all-permissions/> </security>");
65 println(" <update check='always' policy='always'/>");
66 println(" <resources>");
67 println(" <j2se version='1.7+' max-heap-size='300m'/>");
68 final String jarFileUrl = getJarFileUrl();
69 println(" <jar href='" + jarFileUrl + "' />");
70 final Map<String, Object> properties = new LinkedHashMap<>();
71 properties.put("javamelody.application", collector.getApplication());
72 properties.put("javamelody.collectorServer", collectorServer != null);
73 final String url;
74 if (collectorServer == null) {
75 url = codebase + "?format=serialized";
76 } else {
77 url = codebase + "?format=serialized&application=" + collector.getApplication();
78 }
79 properties.put("javamelody.url", url);
80 properties.put("javamelody.range", range.getValue());
81 properties.put("javamelody.locale", I18N.getCurrentLocale());
82
83
84 for (final Parameter parameter : Parameter.values()) {
85 if (parameter.getValue() != null && parameter != Parameter.ADMIN_EMAILS) {
86 properties.put("javamelody." + parameter.getCode(), parameter.getValue());
87 }
88 }
89 if (cookies != null) {
90 properties.put("cookies", cookies);
91 }
92
93
94
95 for (final Map.Entry<String, Object> entry : properties.entrySet()) {
96 println(" <property name='" + JNLP_PREFIX + entry.getKey() + "' value='"
97 + entry.getValue() + "'/>");
98 }
99 println(" </resources>");
100 println(" <application-desc main-class='net.bull.javamelody.Main' />");
101 println("</jnlp>");
102 }
103
104 private void println(String string) throws IOException {
105 writer.write(string);
106 writer.write('\n');
107 }
108
109 private static String getJarFileUrl() {
110 final String jarFileUrl;
111 if (Parameter.JAVAMELODY_SWING_URL.getValue() != null) {
112 jarFileUrl = Parameter.JAVAMELODY_SWING_URL.getValue();
113
114
115
116 } else {
117
118 jarFileUrl = "https:;
119 }
120 return jarFileUrl;
121 }
122 }
123