415 avProps = setDefaultAVProps(); 416 } 417 } else { 418 // create the $USER/.appletviewer file 419 420 // see if $USER/.hotjava/properties exists 421 File userHome = new File(System.getProperty("user.home")); 422 File dotHJ = new File(userHome, ".hotjava"); 423 dotHJ = new File(dotHJ, "properties"); 424 if (dotHJ.exists()) { 425 // just read the file 426 avProps = getAVProps(dotHJ); 427 } else { 428 // send out warning and use defaults 429 System.err.println(lookup("main.warn.cantreadprops", 430 dotHJ.toString())); 431 avProps = setDefaultAVProps(); 432 } 433 434 // SAVE THE FILE 435 try { 436 FileOutputStream out = new FileOutputStream(dotAV); 437 avProps.store(out, lookup("main.prop.store")); 438 out.close(); 439 } catch (IOException e) { 440 System.err.println(lookup("main.err.prop.cantsave", 441 dotAV.toString())); 442 } 443 } 444 return avProps; 445 } 446 447 /** 448 * Set the AppletViewer user-specific properties to be the default values. 449 * 450 * @return A Properties object containing all of the AppletViewer 451 * user-specific properties, set to the default values. 452 */ 453 private Properties setDefaultAVProps() { 454 Properties avProps = new Properties(); 455 for (int i = 0; i < avDefaultUserProps.length; i++) { 456 avProps.setProperty(avDefaultUserProps[i][0], 457 avDefaultUserProps[i][1]); 458 } 459 return avProps; 460 } 461 462 /** 463 * Given a file, find only the properties that are setable by AppletViewer. 464 * 465 * @param inFile A Properties file from which we select the properties of 466 * interest. 467 * @return A Properties object containing all of the AppletViewer 468 * user-specific properties. 469 */ 470 private Properties getAVProps(File inFile) { 471 Properties avProps = new Properties(); 472 473 // read the file 474 Properties tmpProps = new Properties(); 475 try { 476 FileInputStream in = new FileInputStream(inFile); 477 tmpProps.load(new BufferedInputStream(in)); 478 in.close(); 479 } catch (IOException e) { 480 System.err.println(lookup("main.err.prop.cantread", 481 inFile.toString())); 482 } 483 484 // pick off the properties we care about 485 for (int i = 0; i < avDefaultUserProps.length; i++) { 486 String value = tmpProps.getProperty(avDefaultUserProps[i][0]); 487 if (value != null) { 488 // the property exists in the file, so replace the default 489 avProps.setProperty(avDefaultUserProps[i][0], value); 490 } else { 491 // just use the default 492 avProps.setProperty(avDefaultUserProps[i][0], 493 avDefaultUserProps[i][1]); 494 } 495 } 496 return avProps; 497 } 498 499 /** 500 * Methods for easier i18n handling. 501 */ | 415 avProps = setDefaultAVProps(); 416 } 417 } else { 418 // create the $USER/.appletviewer file 419 420 // see if $USER/.hotjava/properties exists 421 File userHome = new File(System.getProperty("user.home")); 422 File dotHJ = new File(userHome, ".hotjava"); 423 dotHJ = new File(dotHJ, "properties"); 424 if (dotHJ.exists()) { 425 // just read the file 426 avProps = getAVProps(dotHJ); 427 } else { 428 // send out warning and use defaults 429 System.err.println(lookup("main.warn.cantreadprops", 430 dotHJ.toString())); 431 avProps = setDefaultAVProps(); 432 } 433 434 // SAVE THE FILE 435 try (FileOutputStream out = new FileOutputStream(dotAV)) { 436 avProps.store(out, lookup("main.prop.store")); 437 } catch (IOException e) { 438 System.err.println(lookup("main.err.prop.cantsave", 439 dotAV.toString())); 440 } 441 } 442 return avProps; 443 } 444 445 /** 446 * Set the AppletViewer user-specific properties to be the default values. 447 * 448 * @return A Properties object containing all of the AppletViewer 449 * user-specific properties, set to the default values. 450 */ 451 private Properties setDefaultAVProps() { 452 Properties avProps = new Properties(); 453 for (int i = 0; i < avDefaultUserProps.length; i++) { 454 avProps.setProperty(avDefaultUserProps[i][0], 455 avDefaultUserProps[i][1]); 456 } 457 return avProps; 458 } 459 460 /** 461 * Given a file, find only the properties that are setable by AppletViewer. 462 * 463 * @param inFile A Properties file from which we select the properties of 464 * interest. 465 * @return A Properties object containing all of the AppletViewer 466 * user-specific properties. 467 */ 468 private Properties getAVProps(File inFile) { 469 Properties avProps = new Properties(); 470 471 // read the file 472 Properties tmpProps = new Properties(); 473 try (FileInputStream in = new FileInputStream(inFile)) { 474 tmpProps.load(new BufferedInputStream(in)); 475 } catch (IOException e) { 476 System.err.println(lookup("main.err.prop.cantread", inFile.toString())); 477 } 478 479 // pick off the properties we care about 480 for (int i = 0; i < avDefaultUserProps.length; i++) { 481 String value = tmpProps.getProperty(avDefaultUserProps[i][0]); 482 if (value != null) { 483 // the property exists in the file, so replace the default 484 avProps.setProperty(avDefaultUserProps[i][0], value); 485 } else { 486 // just use the default 487 avProps.setProperty(avDefaultUserProps[i][0], 488 avDefaultUserProps[i][1]); 489 } 490 } 491 return avProps; 492 } 493 494 /** 495 * Methods for easier i18n handling. 496 */ |