Ejemplo n.º 1
0
 static {
   try {
     properties = new Properties();
     properties.load(Notepad.class.getResourceAsStream("resources/NotepadSystem.properties"));
     resources = ResourceBundle.getBundle("resources.Notepad", Locale.getDefault());
   } catch (MissingResourceException | IOException e) {
     System.err.println(
         "resources/Notepad.properties " + "or resources/NotepadSystem.properties not found");
     System.exit(1);
   }
 }
Ejemplo n.º 2
0
  private void loadConfiguration() throws RuntimeConfigException {
    trace(String.format("Loading configuration from [%s]", configFilePath));
    try {
      InputStream stream = new FileInputStream(configFilePath);
      // InputStream stream1 = new FileInputStream("config/ocsswws.config");
      try {
        Properties fileProperties = new Properties();
        fileProperties.load(stream);
        // @todo check tests - code was not backward compatible with Java 5
        // so i changed it - but this is not the only place of uncompatibilty
        // add default properties so that they override file properties
        // Set<String> propertyNames = fileProperties.stringPropertyNames();
        //                for (String propertyName : propertyNames) {
        //                    String propertyValue = fileProperties.getProperty(propertyName);
        //                    if (!isPropertySet(propertyName)) {
        //                        setProperty(propertyName, propertyValue);
        //                        trace(String.format("Configuration property [%s] added",
        // propertyName));
        //                    } else {
        //                        trace(String.format("Configuration property [%s] ignored",
        // propertyName));
        //                    }
        //                }

        Enumeration<?> enumeration = fileProperties.propertyNames();
        while (enumeration.hasMoreElements()) {
          final Object key = enumeration.nextElement();
          if (key instanceof String) {
            final Object value = fileProperties.get(key);
            if (value instanceof String) {
              final String keyString = (String) key;
              String propertyValue = fileProperties.getProperty(keyString);
              if (!isPropertySet(keyString)) {
                setProperty(keyString, propertyValue);
                trace(String.format("Configuration property [%s] added", keyString));
              } else {
                trace(String.format("Configuration property [%s] ignored", keyString));
              }
            }
          }
        }
      } finally {
        stream.close();
      }
    } catch (IOException e) {
      throw new RuntimeConfigException(
          String.format("Failed to load configuration [%s]", configFilePath), e);
    }
  }