| 1 |
– |
//---PACKAGE DECLARATION--- |
| 1 |
|
|
| 3 |
– |
|
| 2 |
|
|
| 5 |
– |
//---IMPORTS--- |
| 3 |
|
|
| 7 |
– |
|
| 4 |
|
|
| 9 |
– |
import java.io.*; |
| 5 |
|
|
| 11 |
– |
import java.util.*; |
| 6 |
|
|
| 13 |
– |
|
| 7 |
|
|
| 15 |
– |
/** |
| 8 |
|
|
| 17 |
– |
* Produces non-root index pages for reports. |
| 18 |
– |
* (levels 2, 3 and 4) |
| 9 |
|
|
| 20 |
– |
* |
| 10 |
|
|
| 22 |
– |
* @author $Author$ |
| 11 |
|
|
| 24 |
– |
* @version $Id$ |
| 12 |
|
|
| 26 |
– |
*/ |
| 13 |
|
|
| 28 |
– |
public class NodePage { |
| 14 |
|
|
| 30 |
– |
|
| 15 |
|
|
| 32 |
– |
//---FINAL ATTRIBUTES--- |
| 16 |
|
|
| 34 |
– |
|
| 17 |
|
|
| 36 |
– |
/** |
| 18 |
|
|
| 38 |
– |
* The current CVS revision of this class |
| 19 |
|
|
| 40 |
– |
*/ |
| 20 |
|
|
| 42 |
– |
public final String REVISION = "$Revision$"; |
| 21 |
|
|
| 44 |
– |
|
| 22 |
|
|
| 46 |
– |
//---STATIC METHODS--- |
| 23 |
|
|
| 48 |
– |
|
| 24 |
|
|
| 50 |
– |
//---CONSTRUCTORS--- |
| 25 |
|
|
| 52 |
– |
|
| 26 |
|
|
| 54 |
– |
public NodePage(String reportDirectory, LinkedList pages){ |
| 27 |
|
|
| 56 |
– |
_reportDirectory = reportDirectory; |
| 57 |
– |
_pages = pages; |
| 28 |
|
|
| 59 |
– |
} |
| 29 |
|
|
| 61 |
– |
|
| 30 |
|
|
| 63 |
– |
//---PUBLIC METHODS--- |
| 31 |
|
|
| 65 |
– |
|
| 32 |
|
|
| 67 |
– |
|
| 68 |
– |
public void generateAllLevels() { |
| 69 |
– |
this.generateLevel(4, 0, 1, 2); |
| 70 |
– |
this.generateLevel(4, 0, 2, 1); |
| 71 |
– |
this.generateLevel(4, 1, 0, 2); |
| 72 |
– |
this.generateLevel(4, 1, 2, 0); |
| 73 |
– |
this.generateLevel(4, 2, 0, 1); |
| 74 |
– |
this.generateLevel(4, 2, 1, 0); |
| 75 |
– |
} |
| 76 |
– |
|
| 77 |
– |
private LinkedList generateLevel(int level, int indexA, int indexB, int indexC) { |
| 78 |
– |
LinkedList pagesMade = new LinkedList(); |
| 79 |
– |
switch (level) { |
| 80 |
– |
case 4: |
| 81 |
– |
|
| 82 |
– |
// Select unique pairs of elements |
| 83 |
– |
HashSet set = new HashSet(); |
| 84 |
– |
|
| 85 |
– |
// Populate the HashSets. |
| 86 |
– |
Iterator it = _pages.iterator(); |
| 87 |
– |
while (it.hasNext()) { |
| 88 |
– |
String[] pair = new String[2]; |
| 89 |
– |
pair[0] = ((String[])it.next())[indexA]; |
| 90 |
– |
pair[1] = ((String[])it.next())[indexB]; |
| 91 |
– |
set.add(pair); |
| 92 |
– |
} |
| 93 |
– |
|
| 94 |
– |
Iterator setit = set.iterator(); |
| 95 |
– |
while (setit.hasNext()){ |
| 96 |
– |
String[] pair = (String[])setit.next(); |
| 97 |
– |
it = _pages.iterator(); |
| 98 |
– |
while (it.hasNext()){ |
| 99 |
– |
String[] entry = (String[])it.next(); |
| 100 |
– |
if (pair[indexA] == entry[indexA] && pair[indexB] == entry[indexB]) { |
| 101 |
– |
pagesMade.add(entry); |
| 102 |
– |
} |
| 103 |
– |
} |
| 104 |
– |
} |
| 105 |
– |
|
| 106 |
– |
String[] descriptions = new String[3]; |
| 107 |
– |
descriptions[0] = "machine name"; |
| 108 |
– |
descriptions[1] = "time period"; |
| 109 |
– |
descriptions[2] = "report type"; |
| 110 |
– |
it = pagesMade.iterator(); |
| 111 |
– |
while (it.hasNext()){ |
| 112 |
– |
String[] entry = (String[])it.next(); |
| 113 |
– |
System.out.println("4th level index: "+descriptions[indexC]+"s available for "+descriptions[indexA]+entry[indexA]+" and "+descriptions[indexB]+entry[indexB]); |
| 114 |
– |
} |
| 115 |
– |
|
| 116 |
– |
break; |
| 117 |
– |
case 3: |
| 118 |
– |
// bla |
| 119 |
– |
break; |
| 120 |
– |
case 2: |
| 121 |
– |
//bla |
| 122 |
– |
break; |
| 123 |
– |
} |
| 124 |
– |
return pagesMade; |
| 125 |
– |
} |
| 126 |
– |
|
| 33 |
|
|
| 128 |
– |
/** |
| 34 |
|
|
| 130 |
– |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 35 |
|
|
| 132 |
– |
* method to provide clean logging (every class should have this). |
| 36 |
|
|
| 134 |
– |
* |
| 37 |
|
|
| 136 |
– |
* @return the name of this class and its CVS revision |
| 38 |
|
|
| 138 |
– |
*/ |
| 39 |
|
|
| 140 |
– |
public String toString() { |
| 40 |
|
|
| 142 |
– |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 41 |
|
|
| 144 |
– |
} |
| 42 |
|
|
| 146 |
– |
|
| 43 |
|
|
| 148 |
– |
//---PRIVATE METHODS--- |
| 44 |
|
|
| 150 |
– |
|
| 45 |
|
|
| 152 |
– |
//---ACCESSOR/MUTATOR METHODS--- |
| 46 |
|
|
| 154 |
– |
|
| 47 |
|
|
| 156 |
– |
//---ATTRIBUTES--- |
| 48 |
|
|
| 158 |
– |
|
| 159 |
– |
String _reportDirectory; |
| 160 |
– |
LinkedList _pages; |
| 161 |
– |
|
| 49 |
|
|
| 163 |
– |
//---STATIC ATTRIBUTES--- |
| 50 |
|
|
| 165 |
– |
|
| 51 |
|
|
| 167 |
– |
} |
| 52 |
|
|
| 53 |
+ |
//---PACKAGE DECLARATION--- |
| 54 |
+ |
|
| 55 |
+ |
//---IMPORTS--- |
| 56 |
+ |
|
| 57 |
+ |
import java.io.*; |
| 58 |
+ |
import java.util.*; |
| 59 |
+ |
|
| 60 |
+ |
/** |
| 61 |
+ |
* Produces 2nd-, 3rd- and 4th-level index pages for reports. |
| 62 |
+ |
* |
| 63 |
+ |
* @author $Author$ |
| 64 |
+ |
* @version $Id$ |
| 65 |
+ |
*/ |
| 66 |
+ |
public class NodePage { |
| 67 |
+ |
|
| 68 |
+ |
//---FINAL ATTRIBUTES--- |
| 69 |
+ |
|
| 70 |
+ |
/** |
| 71 |
+ |
* The current CVS revision of this class |
| 72 |
+ |
*/ |
| 73 |
+ |
public final String REVISION = "$Revision$"; |
| 74 |
+ |
|
| 75 |
+ |
private final String[] FIELDS = {"machine name", "time period", "report type"}; |
| 76 |
+ |
|
| 77 |
+ |
//---STATIC METHODS--- |
| 78 |
+ |
|
| 79 |
+ |
//---CONSTRUCTORS--- |
| 80 |
+ |
|
| 81 |
+ |
public NodePage(String reportDirectory, LinkedList pages){ |
| 82 |
+ |
_reportDirectory = reportDirectory; |
| 83 |
+ |
_pages = pages; |
| 84 |
+ |
} |
| 85 |
+ |
|
| 86 |
+ |
//---PUBLIC METHODS--- |
| 87 |
+ |
|
| 88 |
+ |
|
| 89 |
+ |
public void generateAllLevels(String levelsDir) { |
| 90 |
+ |
|
| 91 |
+ |
// Create the directory to dump the levels into. |
| 92 |
+ |
try { |
| 93 |
+ |
File newSubDir = new File(_reportDirectory + levelsDir); |
| 94 |
+ |
if (!newSubDir.isDirectory()){ |
| 95 |
+ |
newSubDir.mkdir(); |
| 96 |
+ |
} |
| 97 |
+ |
} |
| 98 |
+ |
catch (Exception e){ |
| 99 |
+ |
System.out.println("Could not create a subdirectory in the reports directory: "+e); |
| 100 |
+ |
return; |
| 101 |
+ |
} |
| 102 |
+ |
|
| 103 |
+ |
LinkedList level4_0_1 = this.generateLevel(0, 1, 2); |
| 104 |
+ |
LinkedList level4_0_2 = this.generateLevel(0, 2, 1); |
| 105 |
+ |
LinkedList level4_1_2 = this.generateLevel(1, 2, 0); |
| 106 |
+ |
|
| 107 |
+ |
LinkedList level3_0 = this.generateLevel(0); |
| 108 |
+ |
LinkedList level3_1 = this.generateLevel(1); |
| 109 |
+ |
LinkedList level3_2 = this.generateLevel(2); |
| 110 |
+ |
|
| 111 |
+ |
LinkedList level2_0 = this.generateBasicLevel(0); |
| 112 |
+ |
LinkedList level2_1 = this.generateBasicLevel(1); |
| 113 |
+ |
LinkedList level2_2 = this.generateBasicLevel(2); |
| 114 |
+ |
|
| 115 |
+ |
stringArrayBottomFileOut(levelsDir, "level4_0_1", level4_0_1, 0, 1, "The following types of report are available. "); |
| 116 |
+ |
stringArrayBottomFileOut(levelsDir, "level4_0_2", level4_0_2, 0, 2, "Reports are available for following time periods. "); |
| 117 |
+ |
stringArrayBottomFileOut(levelsDir, "level4_1_2", level4_1_2, 1, 2, "Reports are available for the following machines. "); |
| 118 |
+ |
|
| 119 |
+ |
stringArrayFileOut(levelsDir, "level3_0", level3_0, 0, 0, 1, "The following reports are available for machine "); |
| 120 |
+ |
stringArrayFileOut(levelsDir, "level3_1", level3_1, 1, 0, 1, "The following reports are available for time period "); |
| 121 |
+ |
stringArrayFileOut(levelsDir, "level3_2", level3_2, 2, 1, 2, "The following reports are available for report type "); |
| 122 |
+ |
|
| 123 |
+ |
stringFileOut(levelsDir, "level2_0", level2_0, 0, "Reports are available for the following machines"); |
| 124 |
+ |
stringFileOut(levelsDir, "level2_1", level2_1, 1, "Reports are available for the following time periods"); |
| 125 |
+ |
stringFileOut(levelsDir, "level2_2", level2_2, 2, "The following types of report are available"); |
| 126 |
+ |
|
| 127 |
+ |
} |
| 128 |
+ |
|
| 129 |
+ |
|
| 130 |
+ |
private void stringFileOut(String levelsDir, String filename, LinkedList reports, int indexA, String title) { |
| 131 |
+ |
try { |
| 132 |
+ |
FileWriter writer = new FileWriter(_reportDirectory+levelsDir+filename+".shtml"); |
| 133 |
+ |
BufferedWriter bw = new BufferedWriter(writer); |
| 134 |
+ |
Iterator it = reports.iterator(); |
| 135 |
+ |
bw.write("<html><body><p><b>"+title+"</b></p>"); |
| 136 |
+ |
bw.newLine(); |
| 137 |
+ |
while (it.hasNext()) { |
| 138 |
+ |
String str = (String)it.next(); |
| 139 |
+ |
bw.write("<a href=\"../"+levelsDir+"level3_"+indexA+"."+str.replace('/', '_')+".shtml"+"\">"+str+"</a><br>"); |
| 140 |
+ |
bw.newLine(); |
| 141 |
+ |
} |
| 142 |
+ |
bw.write("</body></html>"); |
| 143 |
+ |
bw.flush(); |
| 144 |
+ |
bw.close(); |
| 145 |
+ |
} |
| 146 |
+ |
catch (IOException e) { |
| 147 |
+ |
System.out.println("Failed to output "+filename); |
| 148 |
+ |
} |
| 149 |
+ |
} |
| 150 |
+ |
|
| 151 |
+ |
private void stringArrayFileOut(String levelsDir, String filename, LinkedList reports, int indexA, int indexB, int indexC, String baseTitle) { |
| 152 |
+ |
Iterator it = reports.iterator(); |
| 153 |
+ |
HashSet set = new HashSet(); |
| 154 |
+ |
while (it.hasNext()){ |
| 155 |
+ |
String item = ((String[])it.next())[indexA]; |
| 156 |
+ |
set.add(item); |
| 157 |
+ |
} |
| 158 |
+ |
Iterator setit = set.iterator(); |
| 159 |
+ |
while (setit.hasNext()) { |
| 160 |
+ |
String extension = (String)setit.next(); |
| 161 |
+ |
String title = baseTitle + extension; |
| 162 |
+ |
try { |
| 163 |
+ |
FileWriter writer = new FileWriter(_reportDirectory+levelsDir+filename+"."+extension.replace('/', '_')+".shtml"); |
| 164 |
+ |
BufferedWriter bw = new BufferedWriter(writer); |
| 165 |
+ |
bw.write("<html><body><p><b>"+title+"</b></p>"); |
| 166 |
+ |
bw.newLine(); |
| 167 |
+ |
it = reports.iterator(); |
| 168 |
+ |
while (it.hasNext()) { |
| 169 |
+ |
String[] stra = (String[])it.next(); |
| 170 |
+ |
if (extension.equals(stra[indexA])) { |
| 171 |
+ |
bw.write("<a href=\"../"+levelsDir+"level4_"+indexB+"_"+indexC+"."+stra[indexB].replace('/', '_')+"."+stra[indexC].replace('/', '_')+".shtml\">"); |
| 172 |
+ |
for (int i = 0; i < stra.length; i++) { |
| 173 |
+ |
bw.write(stra[i]+" "); |
| 174 |
+ |
} |
| 175 |
+ |
bw.write("</a><br>"); |
| 176 |
+ |
bw.newLine(); |
| 177 |
+ |
} |
| 178 |
+ |
} |
| 179 |
+ |
bw.write("</body></html>"); |
| 180 |
+ |
bw.flush(); |
| 181 |
+ |
bw.close(); |
| 182 |
+ |
} |
| 183 |
+ |
catch (IOException e) { |
| 184 |
+ |
System.out.println("Failed to output "+filename+"."+extension); |
| 185 |
+ |
} |
| 186 |
+ |
} |
| 187 |
+ |
} |
| 188 |
+ |
|
| 189 |
+ |
private void stringArrayBottomFileOut(String levelsDir, String filename, LinkedList reports, int indexA, int indexB, String baseTitle) { |
| 190 |
+ |
Iterator it = reports.iterator(); |
| 191 |
+ |
HashSet set = new HashSet(); |
| 192 |
+ |
while (it.hasNext()){ |
| 193 |
+ |
String[] entry = (String[])it.next(); |
| 194 |
+ |
set.add(entry); |
| 195 |
+ |
} |
| 196 |
+ |
Iterator setit = set.iterator(); |
| 197 |
+ |
while (setit.hasNext()) { |
| 198 |
+ |
String[] entry = (String[])setit.next(); |
| 199 |
+ |
String title = baseTitle + "Your choice has been limited to the "+FIELDS[indexA]+" "+entry[indexA]+" and the "+FIELDS[indexB]+" "+entry[indexB]; |
| 200 |
+ |
HashSet links = new HashSet(); |
| 201 |
+ |
try { |
| 202 |
+ |
String extension = ("."+entry[indexA]+"."+entry[indexB]).replace('/', '_'); |
| 203 |
+ |
FileWriter writer = new FileWriter(_reportDirectory+levelsDir+filename+extension+".shtml"); |
| 204 |
+ |
BufferedWriter bw = new BufferedWriter(writer); |
| 205 |
+ |
it = reports.iterator(); |
| 206 |
+ |
bw.write("<html><body><p><b>"+title+"</b></p>"); |
| 207 |
+ |
bw.newLine(); |
| 208 |
+ |
while (it.hasNext()) { |
| 209 |
+ |
String[] stra = (String[])it.next(); |
| 210 |
+ |
if (entry[indexA].equals(stra[indexA]) && entry[indexB].equals(stra[indexB])) { |
| 211 |
+ |
String link = "<a href=\"../"+stra[1]+stra[0]+"."+stra[2]+".shtml\">"; |
| 212 |
+ |
for (int i = 0; i < stra.length; i++) { |
| 213 |
+ |
link += (stra[i]+" "); |
| 214 |
+ |
} |
| 215 |
+ |
link += "</a><br>"; |
| 216 |
+ |
links.add(link); |
| 217 |
+ |
} |
| 218 |
+ |
} |
| 219 |
+ |
// Write the unique links we found. |
| 220 |
+ |
Iterator linkit = links.iterator(); |
| 221 |
+ |
while (linkit.hasNext()) { |
| 222 |
+ |
bw.write((String)linkit.next()); |
| 223 |
+ |
bw.newLine(); |
| 224 |
+ |
} |
| 225 |
+ |
bw.write("</body></html>"); |
| 226 |
+ |
bw.flush(); |
| 227 |
+ |
bw.close(); |
| 228 |
+ |
} |
| 229 |
+ |
catch (IOException e) { |
| 230 |
+ |
System.out.println("Failed to output "+filename+"."+entry[indexA]+"."+entry[indexB]+": "+e); |
| 231 |
+ |
} |
| 232 |
+ |
} |
| 233 |
+ |
} |
| 234 |
+ |
|
| 235 |
+ |
|
| 236 |
+ |
private LinkedList generateBasicLevel(int indexA) { |
| 237 |
+ |
LinkedList pagesMade = new LinkedList(); |
| 238 |
+ |
HashSet set = new HashSet(); |
| 239 |
+ |
Iterator it = _pages.iterator(); |
| 240 |
+ |
while (it.hasNext()) { |
| 241 |
+ |
String item = ((String[])it.next())[indexA]; |
| 242 |
+ |
set.add(item); |
| 243 |
+ |
} |
| 244 |
+ |
|
| 245 |
+ |
Iterator setit = set.iterator(); |
| 246 |
+ |
while (setit.hasNext()){ |
| 247 |
+ |
String setitem = (String)setit.next(); |
| 248 |
+ |
// Make the page. |
| 249 |
+ |
pagesMade.add(setitem); |
| 250 |
+ |
} |
| 251 |
+ |
|
| 252 |
+ |
return pagesMade; |
| 253 |
+ |
} |
| 254 |
+ |
|
| 255 |
+ |
|
| 256 |
+ |
private LinkedList generateLevel(int indexA) { |
| 257 |
+ |
LinkedList pagesMade = new LinkedList(); |
| 258 |
+ |
//Populate the HashSet. |
| 259 |
+ |
HashSet set = new HashSet(); |
| 260 |
+ |
Iterator it = _pages.iterator(); |
| 261 |
+ |
while (it.hasNext()) { |
| 262 |
+ |
String item = ((String[])it.next())[indexA]; |
| 263 |
+ |
set.add(item); |
| 264 |
+ |
} |
| 265 |
+ |
|
| 266 |
+ |
Iterator setit = set.iterator(); |
| 267 |
+ |
while (setit.hasNext()){ |
| 268 |
+ |
String setitem = (String)setit.next(); |
| 269 |
+ |
it = _pages.iterator(); |
| 270 |
+ |
while (it.hasNext()){ |
| 271 |
+ |
String[] entry = (String[])it.next(); |
| 272 |
+ |
if (setitem.equals(entry[indexA])) { |
| 273 |
+ |
// Make this page. |
| 274 |
+ |
pagesMade.add(entry); |
| 275 |
+ |
} |
| 276 |
+ |
} |
| 277 |
+ |
} |
| 278 |
+ |
|
| 279 |
+ |
return pagesMade; |
| 280 |
+ |
} |
| 281 |
+ |
|
| 282 |
+ |
private LinkedList generateLevel(int indexA, int indexB, int indexC) { |
| 283 |
+ |
LinkedList pagesMade = new LinkedList(); |
| 284 |
+ |
// Select unique pairs of elements |
| 285 |
+ |
HashSet set = new HashSet(); |
| 286 |
+ |
|
| 287 |
+ |
// Populate the HashSet. |
| 288 |
+ |
Iterator it = _pages.iterator(); |
| 289 |
+ |
while (it.hasNext()) { |
| 290 |
+ |
String[] pair = new String[2]; |
| 291 |
+ |
String[] entry = (String[])it.next(); |
| 292 |
+ |
pair[0] = entry[indexA]; |
| 293 |
+ |
pair[1] = entry[indexB]; |
| 294 |
+ |
set.add(pair); |
| 295 |
+ |
} |
| 296 |
+ |
|
| 297 |
+ |
Iterator setit = set.iterator(); |
| 298 |
+ |
while (setit.hasNext()){ |
| 299 |
+ |
String[] pair = (String[])setit.next(); |
| 300 |
+ |
it = _pages.iterator(); |
| 301 |
+ |
while (it.hasNext()){ |
| 302 |
+ |
String[] entry = (String[])it.next(); |
| 303 |
+ |
if (pair[0].equals(entry[indexA]) && pair[1].equals(entry[indexB])) { |
| 304 |
+ |
// Make this page. |
| 305 |
+ |
pagesMade.add(entry); |
| 306 |
+ |
} |
| 307 |
+ |
} |
| 308 |
+ |
} |
| 309 |
+ |
|
| 310 |
+ |
return pagesMade; |
| 311 |
+ |
} |
| 312 |
+ |
|
| 313 |
+ |
/** |
| 314 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 315 |
+ |
* method to provide clean logging (every class should have this). |
| 316 |
+ |
* |
| 317 |
+ |
* @return the name of this class and its CVS revision |
| 318 |
+ |
*/ |
| 319 |
+ |
public String toString() { |
| 320 |
+ |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 321 |
+ |
} |
| 322 |
+ |
|
| 323 |
+ |
//---PRIVATE METHODS--- |
| 324 |
+ |
|
| 325 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
| 326 |
+ |
|
| 327 |
+ |
//---ATTRIBUTES--- |
| 328 |
+ |
|
| 329 |
+ |
String _reportDirectory; |
| 330 |
+ |
LinkedList _pages; |
| 331 |
+ |
|
| 332 |
+ |
//---STATIC ATTRIBUTES--- |
| 333 |
+ |
|
| 334 |
+ |
} |