();
String line;
while ((line = in.readLine()) != null) {
// skip blank and comment lines
if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}
StringTokenizer tokens = new StringTokenizer(line);
String token = tokens.nextToken(); /* We don't use the first token. */
token = tokens.nextToken();
LatitudeAndLongitude location = new LatitudeAndLongitude(token);
token = tokens.nextToken();
mapList.put(token, location);
}
in.close();
}
/* Open zoneinfo file to write. */
FileWriter fw = new FileWriter(outputDir + zonefile.substring(index+1));
BufferedWriter out = new BufferedWriter(fw);
out.write(header1 + new Date() + header3 + zonename + header4);
out.write(body1 + "" + zonename + "");
LatitudeAndLongitude location = mapList.get(zonename);
if (location != null) {
int deg, min, sec;
deg = location.getLatDeg();
min = location.getLatMin();
sec = location.getLatSec();
if (deg < 0) {
min = -min;
sec = -sec;
} else if (min < 0) {
sec = -sec;
}
out.write(" " +
"[map]");
}
out.write("\n\n");
List zone = tz.getZones();
List rule = tz.getRules();
if (rule != null && zone != null) {
out.write("\n" +
"\n" +
" " +
"Rules
| \n" +
"" +
" Zone
| \n" +
"
\n
\n");
}
/* Output Rule records. */
if (rule != null) {
size = rule.size();
out.write("\n" +
"Rules\n" +
"
\n" +
"\n" +
"NAME | FROM | TO | TYPE | " +
"IN | ON | AT | SAVE | " +
"LETTER/S | NOTES | \n
\n");
for (int i = 0; i < size; i++) {
out.write("\n");
StringTokenizer st = new StringTokenizer(rule.get(i).getLine());
String s;
if (st.hasMoreTokens()) { /* RULE - truncated */
st.nextToken();
}
if (st.hasMoreTokens()) { /* NAME */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* FROM */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* TO */
s = st.nextToken();
if (s.equals("min") || s.equals("max")) {
out.write("" + s + " | ");
} else {
out.write("" + s + " | ");
}
}
if (st.hasMoreTokens()) { /* TYPE */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* IN */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* ON */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* AT */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* SAVE */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* LETTER/S */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* NOTES */
s = st.nextToken();
while (st.hasMoreTokens()) {
s += " " + st.nextToken();
}
index = s.indexOf('#');
out.write("" + s.substring(index+1) + " | \n");
} else {
out.write(" | \n");
}
out.write("
\n");
}
out.write("
\n
\n");
}
/* Output Zone records. */
if (zone != null) {
size = zone.size();
out.write("
\n" +
"Zone\n" +
"
\n" +
"\nGMTOFF | " +
"RULES | FORMAT | UNTIL | " +
"NOTES | \n
\n");
for (int i = 0; i < size; i++) {
out.write("\n");
StringTokenizer st = new StringTokenizer(zone.get(i).getLine());
String s = st.nextToken();
if (s.equals("Zone")) { /* NAME */
s = st.nextToken();
s = st.nextToken();
}
out.write("" + s + " | "); /* GMTOFFSET */
if (st.hasMoreTokens()) { /* RULES */
out.write("" + st.nextToken() + " | ");
}
if (st.hasMoreTokens()) { /* FORMAT */
s = st.nextToken();
index = s.indexOf('#');
if (index != -1) {
if (index != 0) {
out.write("" + s.substring(0, index-1) +
" | "); /* FORMAT */
s = s.substring(index+1);
} else {
out.write(" | "); /* FORMAT */
}
while (st.hasMoreTokens()) {
s += " " + st.nextToken();
}
out.write(" | "); /* UNTIL */
out.write("" + s + " | \n
\n"); /* NOTES */
continue;
} else {
out.write("" + s + " | "); /* FORMAT */
}
}
if (st.hasMoreTokens()) { /* UNTIL */
s = st.nextToken();
while (st.hasMoreTokens()) {
s += " " + st.nextToken();
}
index = s.indexOf('#');
if (index != -1) {
if (index != 0) {
out.write("" + s.substring(0, index-1) +
" | "); /* UNTIL */
} else {
out.write(" | "); /* UNTIL */
}
out.write("" + s.substring(index+1) +
" | \n"); /* NOTES */
} else {
out.write("" + s + " | "); /* UNTIL */
out.write(" | \n"); /* NOTES */
}
} else {
out.write(" | "); /* UNTIL */
out.write(" | \n"); /* NOTES */
}
out.write("\n");
}
out.write("
\n");
}
out.write(body2 + footer);
out.close();
fw.close();
} catch(IOException e) {
Main.panic("IO error: "+e.getMessage());
return 1;
}
return 0;
}
/**
* Generates index.html and other top-level frame files.
* @param Mappings
* @return 0 if no errors, or 1 if error occurred.
*/
int generateSrc(Mappings map) {
try {
int len;
Object o[];
String outputDir = Main.getOutputDir();
FileWriter fw1, fw2;
BufferedWriter out1, out2;
/* Whether alias list exists or not. */
Map a = map.getAliases();
if (a == null) {
Main.panic("Data not exist. (aliases)");
return 1;
}
timezoneList.putAll(a);
/* If outputDir doesn't end with file-separator, adds it. */
if (!outputDir.endsWith(File.separator)) {
outputDir += File.separatorChar;
}
outputDir += docDir + File.separatorChar;
File outD = new File(outputDir);
outD.mkdirs();
/* Creates index.html */
fw1 = new FileWriter(outputDir + "index.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 +
"\n" +
"\n" +
"\nFrame Alert\n
\n\n" +
"\n\n" +
"This document is designed to be viewed using the frames feature. If you see this\n" +
"message, you are using a non-frame-capable web client.\n" +
"
\n" +
"Link toNon-frame version.\n" +
"
\n" + footer);
out1.close();
fw1.close();
/* Creates overview-frame.html */
fw1 = new FileWriter(outputDir + "overview-frame.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 + body1 +
"\n\n" +
"\n" +
"JavaTM Platform Standard Ed. | \n" +
"
\n
\n\n" +
"\n\n" +
" \n\nAll Time Zones Sorted By:\n \n" +
" GMT offsets\n \n" +
" Zone names\n " +
" City names\n" +
" \n\nContinents and Oceans\n \n");
for (String regionKey : regionList.keySet()) {
out1.write(" " + regionKey +
" \n");
fw2 = new FileWriter(outputDir + regionList.get(regionKey),
false);
out2 = new BufferedWriter(fw2);
out2.write(header1 + new Date() + header3 + regionKey +
header4 + body1 + "" +
regionKey + "\n \n \n\n");
boolean found = false;
for (String timezoneKey : timezoneList.keySet()) {
int regionIndex = timezoneKey.indexOf('/');
if (regionIndex == -1 ||
!regionKey.equals(timezoneKey.substring(0, regionIndex))) {
if (found) {
break;
} else {
continue;
}
}
found = true;
if (a.containsKey(timezoneKey)) {
Object realName = a.get(timezoneKey);
while (a.containsKey(realName)) {
realName = a.get(realName);
}
out2.write(timezoneKey +
" (alias for " + "" +
realName + ")");
} else {
out2.write("" + timezoneKey +
"");
}
out2.write(" \n");
}
out2.write(" | \n \n \n" + body2 + footer);
out2.close();
fw2.close();
}
out1.write(" | \n
\n" + body2 + footer);
out1.close();
fw1.close();
/* Creates allTimeZone-frame1.html (Sorted by GMT offsets) */
fw1 = new FileWriter(outputDir + "allTimeZone-frame1.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 + body1 +
"Sorted by GMT offsets\n" +
"
\n\n" + "\n" +
"\n\n");
List roi = map.getRawOffsetsIndex();
List> roit = map.getRawOffsetsIndexTable();
int index = 0;
for (Integer offset : zonesByOffset.keySet()) {
int off = roi.get(index);
Set perRO = zonesByOffset.get(offset);
if (offset == off) {
// Merge aliases into zonesByOffset
perRO.addAll(roit.get(index));
}
index++;
for (String timezoneKey : perRO) {
out1.write("\n(" +
Time.toGMTFormat(offset.toString()) +
") | \n");
if (a.containsKey(timezoneKey)) {
Object realName = a.get(timezoneKey);
while (a.containsKey(realName)) {
realName = a.get(realName);
}
out1.write(timezoneKey +
" (alias for " + "" + realName +
")");
} else {
out1.write("" + timezoneKey +
"");
}
out1.write(" | \n \n");
}
}
out1.write(" | \n
\n
\n" + body2 + footer);
out1.close();
fw1.close();
/* Creates allTimeZone-frame2.html (Sorted by zone names) */
fw1 = new FileWriter(outputDir + "allTimeZone-frame2.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 + body1 +
"Sorted by zone names\n" +
"
\n\n" + "\n" +
"\n\n");
o = timezoneList.keySet().toArray();
len = timezoneList.size();
for (int i = 0; i < len; i++) {
Object timezoneKey = o[i];
if (a.containsKey(timezoneKey)) {
Object realName = a.get(timezoneKey);
while (a.containsKey(realName)) {
realName = a.get(realName);
}
out1.write(timezoneKey +
" (alias for " +
"" + realName +
")");
} else {
out1.write("" + timezoneKey +
"");
}
out1.write(" \n");
}
out1.write(" | \n
\n
\n" + body2 + footer);
out1.close();
fw1.close();
/* Creates allTimeZone-frame3.html (Sorted by city names) */
fw1 = new FileWriter(outputDir + "allTimeZone-frame3.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 + body1 +
"Sorted by city names\n" +
"
\n\n" + "\n" +
"\n\n");
Set aliasSet = a.keySet();
len = aliasSet.size();
String aliasNames[] = aliasSet.toArray(new String[0]);
for (int i = 0; i < len; i++) {
displayNameList.put(transform(aliasNames[i]),
aliasNames[i]);
}
o = displayNameList.keySet().toArray();
len = displayNameList.size();
for (int i = 0; i < len; i++) {
Object displayName = o[i];
Object timezoneKey = displayNameList.get(o[i]);
if (a.containsKey(timezoneKey)) {
Object realName = a.get(timezoneKey);
while (a.containsKey(realName)) {
realName = a.get(realName);
}
out1.write(displayName +
" (alias for " +
"" + realName +
")");
} else {
out1.write("" + displayName +
"");
}
out1.write(" \n");
}
out1.write(" | \n
\n
\n" + body2 + footer);
out1.close();
fw1.close();
/* Creates overview-summary.html */
fw1 = new FileWriter(outputDir + "overview-summary.html", false);
out1 = new BufferedWriter(fw1);
out1.write(header1 + new Date() + header2 + Main.getVersionName() +
header4 + body1 +
"This is the list of time zones generated from " +
Main.getVersionName() + " for Java Platform, " +
"Standard Edition. The source code can be obtained " +
"from ftp site " +
"ftp://elsie.nci.nih.gov/pub/. A total of " +
len +
" time zones and aliases are supported " +
"in this edition. For the " +
"format of rules and zones, refer to the zic " +
"(zoneinfo compiler) man page on " +
"Solaris or Linux.
\n" +
"Note that the time zone data is not " +
"a public interface of the Java Platform. No " +
"applications should rely on the time zone data of " +
"this document. Time zone names and data " +
"may change without any prior notice.
\n" +
body2 + footer);
out1.close();
fw1.close();
} catch(IOException e) {
Main.panic("IO error: "+e.getMessage());
return 1;
}
return 0;
}
String transform(String s) {
int index = s.lastIndexOf("/");
/* If the string doesn't include any delimiter, return */
if (index == -1) {
return s;
}
int lastIndex = index;
String str = s.substring(index+1);
do {
index = s.substring(0, lastIndex).lastIndexOf('/');
str += ", " + s.substring(index+1, lastIndex);
lastIndex = index;
} while (index > -1);
return str;
}
static class LatitudeAndLongitude {
private int latDeg, latMin, latSec, longDeg, longMin, longSec;
LatitudeAndLongitude(String s) {
try {
// First of all, check the string has the correct format:
// either +-DDMM+-DDDMM or +-DDMMSS+-DDDMMSS
if (!s.startsWith("+") && !s.startsWith("-")) {
Main.warning("Wrong latitude&longitude data: " + s);
return;
}
int index;
if (((index = s.lastIndexOf("+")) <= 0) &&
((index = s.lastIndexOf("-")) <= 0)) {
Main.warning("Wrong latitude&longitude data: " + s);
return;
}
if (index == 5) {
latDeg = Integer.parseInt(s.substring(1, 3));
latMin = Integer.parseInt(s.substring(3, 5));
latSec = 0;
} else if (index == 7) {
latDeg = Integer.parseInt(s.substring(1, 3));
latMin = Integer.parseInt(s.substring(3, 5));
latSec = Integer.parseInt(s.substring(5, 7));
} else {
Main.warning("Wrong latitude&longitude data: " + s);
return;
}
if (s.startsWith("-")){
latDeg = -latDeg;
latMin = -latMin;
latSec = -latSec;
}
int len = s.length();
if (index == 5 && len == 11) {
longDeg = Integer.parseInt(s.substring(index+1, index+4));
longMin = Integer.parseInt(s.substring(index+4, index+6));
longSec = 0;
} else if (index == 7 && len == 15) {
longDeg = Integer.parseInt(s.substring(index+1, index+4));
longMin = Integer.parseInt(s.substring(index+4, index+6));
longSec = Integer.parseInt(s.substring(index+6, index+8));
} else {
Main.warning("Wrong latitude&longitude data: " + s);
return;
}
if (s.charAt(index) == '-'){
longDeg = -longDeg;
longMin = -longMin;
longSec = -longSec;
}
} catch(Exception e) {
Main.warning("LatitudeAndLongitude() Parse error: " + s);
}
}
int getLatDeg() {
return latDeg;
}
int getLatMin() {
return latMin;
}
int getLatSec() {
return latSec;
}
int getLongDeg() {
return longDeg;
}
int getLongMin() {
return longMin;
}
int getLongSec() {
return longSec;
}
}
}