Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/j9nls/com/ibm/oti/NLSTool/NLSHtmlGenerator.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2004, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.oti.NLSTool;
23
24
import java.io.File;
25
import java.io.FileNotFoundException;
26
import java.io.FileWriter;
27
import java.io.IOException;
28
import java.util.Collections;
29
import java.util.Enumeration;
30
import java.util.Vector;
31
32
public class NLSHtmlGenerator {
33
private File htmlFile;
34
private FileWriter htmlWriter;
35
36
public void generateHTML(Vector nlsInfos, String outFileName, String htmlFileName) throws IOException, FileNotFoundException {
37
Collections.sort(nlsInfos);
38
htmlFile = new File(htmlFileName);
39
StringBuffer buffer = new StringBuffer("");
40
41
writeHTMLHeader(buffer, outFileName);
42
writeIndexTable(nlsInfos, buffer);
43
buffer.append("<br>");
44
writeMsgTable(nlsInfos, buffer);
45
writeHTMLFooter(buffer);
46
47
if (J9NLS.differentFromCopyOnDisk(htmlFileName, buffer)) {
48
htmlWriter = new FileWriter(htmlFile);
49
htmlWriter.write(buffer.toString());
50
htmlWriter.close();
51
52
J9NLS.dp("** Generated " + htmlFile.getAbsolutePath());
53
}
54
}
55
56
private void writeIndexTable(Vector nlsInfos, StringBuffer buffer) {
57
buffer.append("<table border=\"1\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\">\n");
58
buffer.append("<colgroup span=\"4\"</colgroup>\n");
59
buffer.append("<tr>");
60
buffer.append("<td>Module Name</td>\n");
61
buffer.append("<td>Path</td>\n");
62
buffer.append("<td>Header Name</td>\n");
63
buffer.append("<td>Locales</td>\n");
64
buffer.append("</tr>\n");
65
for(Enumeration enumer = nlsInfos.elements(); enumer.hasMoreElements(); ) {
66
NLSInfo nlsInfo = (NLSInfo)enumer.nextElement();
67
Vector locales = sortLocales(nlsInfo.getLocales());
68
buffer.append("<tr>\n");
69
buffer.append("<td>");
70
buffer.append("<a href=\"#" + nlsInfo.getModule() + "\">\n");
71
buffer.append(nlsInfo.getModule() + "</a></td>\n");
72
buffer.append("<td>" + nlsInfo.getPath() + "</td>\n");
73
buffer.append("<td>" + nlsInfo.getHeaderName() + "</td>\n");
74
buffer.append("<td>\n");
75
for(Enumeration e = locales.elements(); e.hasMoreElements(); ) {
76
String temp = (String)e.nextElement();
77
String locale = getLocale(temp);
78
buffer.append(locale);
79
if(e.hasMoreElements())
80
buffer.append(", ");
81
}
82
buffer.append("</td>\n");
83
buffer.append("</tr>\n\n");
84
}
85
buffer.append("</table>");
86
}
87
88
private void writeMsgTable(Vector nlsInfos, StringBuffer buffer) {
89
buffer.append("<table border=\"1\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\">\n");
90
buffer.append("<colgroup span=\"4\"</colgroup>\n");
91
buffer.append("<tr>");
92
buffer.append("<td>Macro</td>\n");
93
buffer.append("<td>ID</td>\n");
94
buffer.append("<td>Key</td>\n");
95
buffer.append("<td>Message</td>\n");
96
buffer.append("</tr>\n\n");
97
for(Enumeration enumer = nlsInfos.elements(); enumer.hasMoreElements(); ) {
98
NLSInfo nlsInfo = (NLSInfo)enumer.nextElement();
99
Vector msgInfos = nlsInfo.getMsgInfo();
100
boolean firstMessage = true;
101
for(Enumeration e = msgInfos.elements(); e.hasMoreElements(); ) {
102
MsgInfo msgInfo = (MsgInfo)e.nextElement();
103
writeMsgTable(msgInfo, buffer, firstMessage);
104
firstMessage = false;
105
}
106
}
107
buffer.append("</table>\n");
108
}
109
110
private void writeMsgTable(MsgInfo msgInfo, StringBuffer buffer, boolean firstMessage) {
111
buffer.append("<tr>\n");
112
buffer.append("<td>" + msgInfo.getMacro() + "</td>\n");
113
buffer.append("<td>" + msgInfo.getId() + "</td>\n");
114
buffer.append("<td>" + msgInfo.getKey() + "</td>\n");
115
116
buffer.append("<td>");
117
if(firstMessage)
118
buffer.append("<a name=" + msgInfo.getMacro().substring(0,4) + ">");
119
if(msgInfo.getMsg().equals(""))
120
buffer.append("<i>No Value</i>");
121
else
122
buffer.append("<xmp>" + msgInfo.getMsg() + "</xmp>");
123
124
if (msgInfo.containsDiagnostics()) {
125
buffer.append("<p><b>Explanation: </b>" + msgInfo.getExplanation());
126
buffer.append("<p><b>System Action: </b>" + msgInfo.getSystemAction());
127
buffer.append("<p><b>User Response: </b>" + msgInfo.getUserResponse());
128
}
129
130
if(firstMessage)
131
buffer.append("</a>");
132
buffer.append("</td>\n");
133
buffer.append("</tr>\n\n");
134
}
135
136
private void writeHTMLHeader(StringBuffer buffer, String outFileName) {
137
buffer.append("<html>\n");
138
buffer.append("<head>\n");
139
buffer.append("<title>");
140
buffer.append(outFileName);
141
buffer.append("</title>\n");
142
buffer.append("</head>\n");
143
buffer.append("<body bgcolor=\"#C0C0C0\" link=black vlink=blue>");
144
}
145
146
private void writeHTMLFooter(StringBuffer buffer) {
147
buffer.append("</body>\n");
148
buffer.append("</html>");
149
}
150
151
private Vector sortLocales(Vector locales) {
152
Vector sortedLocales = new Vector();
153
if(locales.contains("")) {
154
sortedLocales.addElement("");
155
locales.remove("");
156
}
157
Collections.sort(locales);
158
sortedLocales.addAll(locales);
159
return sortedLocales;
160
}
161
162
private String getLocale(String nlsFileName) {
163
if(nlsFileName.lastIndexOf('_') != -1)
164
return nlsFileName.substring(nlsFileName.indexOf('_')+1);
165
else
166
return "(default)";
167
}
168
}
169
170