/** * 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 rawOffsetIndex list exists or not. */ LinkedList roi = map.getRawOffsetsIndex(); if (roi == null) { Main.panic("Data not exist. (rawOffsetsIndex)"); return 1; } int roi_size = roi.size(); LinkedList roit = map.getRawOffsetsIndexTable(); if (roit == null || roit.size() != roi_size) { Main.panic("Data not exist. (rawOffsetsIndexTable) Otherwise, Invalid size"); return 1; } /* Whether alias list exists or not. */ TreeMap 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 + "<FRAMESET cols=\"20%,80%\">\n" + "<FRAMESET rows=\"30%,70%\">\n" + "<FRAME src=\"overview-frame.html\" name=\"TimeZoneListFrame\">\n" + "<FRAME src=\"allTimeZone-frame1.html\" name=\"allTimeZoneFrame\">\n" + "</FRAMESET>" + "<FRAME src=\"overview-summary.html\" name=\"rightFrame\">\n" + "</FRAMESET>\n" + "<NOFRAMES>\n" + "<H2>\nFrame Alert\n</H2>\n\n" + "<P>\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" + "<BR>\n" + "Link to<A HREF=\"overview-summary.html\">Non-frame version.</A>\n" + "</NOFRAMES>\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 + "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n<TR>\n" + "<TD NOWRAP><FONT size=\"+1\">\n" + "<B>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed.</B></FONT></TD>\n" + "</TR>\n</TABLE>\n\n" + "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n<TR>\n<TD NOWRAP>" + "<P>\n<FONT size=\"+1\">\nAll Time Zones Sorted By:</FONT>\n<BR>\n" + " <A HREF=\"allTimeZone-frame1.html\" TARGET=\"allTimeZoneFrame\">GMT offsets</A></FONT>\n<BR>\n" + " <A HREF=\"allTimeZone-frame2.html\" TARGET=\"allTimeZoneFrame\">Zone names</A></FONT>\n<BR>" + " <A HREF=\"allTimeZone-frame3.html\" TARGET=\"allTimeZoneFrame\">City names</A></FONT>\n" + "<P>\n<FONT size=\"+1\">\nContinents and Oceans</FONT>\n<BR>\n"); o = regionList.keySet().toArray(); len = regionList.size(); Object tzo[] = timezoneList.keySet().toArray(); int tzlen = timezoneList.size(); for (int i = 0; i < len; i++) { Object regionKey = o[i]; out1.write( " <A HREF=\"" + regionList.get(regionKey) + "\" TARGET=\"allTimeZoneFrame\">" + regionKey + "</A><BR>\n"); fw2 = new FileWriter(outputDir + regionList.get(regionKey), false); out2 = new BufferedWriter(fw2); out2.write( header1 + new Date() + header3 + regionKey + header4 + body1 + "<FONT size=\"+1\"><B>" + regionKey + "</B></FONT>\n<BR>\n<TABLE>\n<TR>\n<TD>"); boolean found = false; for (int j = 0; j < tzlen; j++) { String timezoneKey = (String) tzo[j]; 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 " + "<A HREF=\"" + timezoneList.get(realName) + "\" TARGET=\"rightFrame\">" + realName + "</A>)"); } else { out2.write( "<A HREF=\"" + timezoneList.get(timezoneKey) + "\" TARGET=\"rightFrame\">" + timezoneKey + "</A>"); } out2.write("<BR>\n"); } out2.write("</TD>\n</TR>\n</TABLE>\n" + body2 + footer); out2.close(); fw2.close(); } out1.write("</FONT></TD>\n</TR></TABLE>\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 + "<FONT size=\"+1\"><B>Sorted by GMT offsets</B></FONT>\n" + "<BR>\n\n" + "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n" + "<TR>\n<TD NOWRAP>\n"); for (int i = 0; i < roi_size; i++) { TreeSet perRO = (TreeSet) roit.get(i); Iterator keys = perRO.iterator(); while (keys.hasNext()) { Object timezoneKey = keys.next(); out1.write( "<TR>\n<TD><FONT SIZE=\"-1\">(" + Time.toGMTFormat(roi.get(i).toString()) + ")</FONT></TD>\n<TD>"); if (a.containsKey(timezoneKey)) { Object realName = a.get(timezoneKey); while (a.containsKey(realName)) { realName = a.get(realName); } out1.write( timezoneKey + " (alias for " + "<A HREF=\"" + timezoneList.get(realName) + "\" TARGET=\"rightFrame\">" + realName + "</A>)"); } else { out1.write( "<A HREF=\"" + timezoneList.get(timezoneKey) + "\" TARGET=\"rightFrame\">" + timezoneKey + "</A>"); } out1.write("</TD>\n</TR>\n"); } } out1.write("</FONT></TD>\n</TR>\n</TABLE>\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 + "<FONT size=\"+1\"><B>Sorted by zone names</B></FONT>\n" + "<BR>\n\n" + "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n" + "<TR>\n<TD NOWRAP>\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 " + "<A HREF=\"" + timezoneList.get(realName) + "\" TARGET=\"rightFrame\">" + realName + "</A>)"); } else { out1.write( "<A HREF=\"" + timezoneList.get(timezoneKey) + "\" TARGET=\"rightFrame\">" + timezoneKey + "</A>"); } out1.write("<BR> \n"); } out1.write("</FONT></TD>\n</TR>\n</TABLE>\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 + "<FONT size=\"+1\"><B>Sorted by city names</B></FONT>\n" + "<BR>\n\n" + "<TABLE BORDER=\"0\" WIDTH=\"100%\">\n" + "<TR>\n<TD NOWRAP>\n"); Set aliasSet = a.keySet(); len = aliasSet.size(); Object aliasNames[] = aliasSet.toArray(); for (int i = 0; i < len; i++) { displayNameList.put(transform((String) 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 " + "<A HREF=\"" + timezoneList.get(realName) + "\" TARGET=\"rightFrame\">" + realName + "</A>)"); } else { out1.write( "<A HREF=\"" + timezoneList.get(timezoneKey) + "\" TARGET=\"rightFrame\">" + displayName + "</A>"); } out1.write("<BR> \n"); } out1.write("</FONT></TD>\n</TR>\n</TABLE>\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 <B>" + Main.getVersionName() + "</B> for Java 2 Platform, " + "Standard Edition. The source code can be obtained " + "from ftp site <a href=\"ftp://elsie.nci.nih.gov/pub/\">" + "ftp://elsie.nci.nih.gov/pub/</a>. A total of <B>" + len + "</B> time zones and aliases are supported " + "in this edition.\n<BR>\n" + "(This site keeps only the latest release.)\nFor the " + "format of rules and zones, refer to the zic " + "(zoneinfo compiler) man page on " + "<a href=\"http://docs.sun.com/ab2/coll.40.6/REFMAN1M/@Ab2PageView/266070?DwebQuery=zic&oqt=zic&Ab2Lang=C&Ab2Enc=iso-8859-1\">Solaris</a> " + "or Linux.\n<p>\nNote that this time zone data is not " + "a public interface of the Java run-time. No " + "applications should rely on the time zone data on " + "this web page. Time zone names and time zone 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; }