Пример #1
0
  static {
    config = new Utf8Properties();
    mediaProperties = new Utf8Properties();
    profiles = new Utf8Properties();

    allProps = new Hashtable<String, Utf8Properties>();

    InputStream f = null;

    try {
      // first, we load the general Config
      URL url = PropertiesLoader.class.getResource("Config.properties");
      f = url.openStream();
      config.load(f);

      // the media associated to each property
      url = PropertiesLoader.class.getResource(config.getProperty("media"));
      f = url.openStream();
      mediaProperties.load(f);

      // profiles
      url = PropertiesLoader.class.getResource(config.getProperty("profilesProperties"));

      f = url.openStream();
      profiles.load(f);

      // Load the default profile
      String defaultProfile = config.getProperty("defaultProfile");
      String defaultPath = (String) profiles.get(defaultProfile);
      DEFAULT_PROFILE = loadProfile(defaultProfile, defaultPath);

      if (Util.onDebug) {
        System.out.println("Default profile (" + defaultProfile + ") loaded");
      }
    } catch (Exception e) {
      System.err.println(PropertiesLoader.class + ": Error while loading default config");
      e.printStackTrace();
    } finally {
      try {
        if (f != null) {
          f.close();
          f = null;
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #2
0
  /**
   * Loads our CSS profile.
   *
   * @throws IOException if profile loading fails
   */
  private static void loadAptanaCSSProfile() {
    InputStream configStream = CSSValidator.class.getResourceAsStream(CONFIG_FILE);
    InputStream profilesStream = CSSValidator.class.getResourceAsStream(PROFILES_CONFIG_FILE);

    try {
      // loads our config
      PropertiesLoader.config.load(configStream);

      // loads our profile
      Utf8Properties profiles = new Utf8Properties();
      profiles.load(profilesStream);
      // a hack, but no other way since PropertiesLoader provides no public access to stored
      // profiles
      Field field = PropertiesLoader.class.getDeclaredField("profiles"); // $NON-NLS-1$
      field.setAccessible(true);
      field.set(null, profiles);
    } catch (Exception e) {
      IdeLog.logError(CSSPlugin.getDefault(), Messages.CSSValidator_ERR_FailToLoadProfile, e);
    } finally {
      try {
        configStream.close();
      } catch (IOException e) {
      }
      try {
        profilesStream.close();
      } catch (IOException e) {
      }
    }
  }
Пример #3
0
  private static Utf8Properties loadProfile(String profile, String profilePath) throws IOException {
    Utf8Properties result = new Utf8Properties();
    InputStream f = null;

    URL url = null;

    // the url of the properties file of the selected profile
    if (profilePath != null) {
      url = PropertiesLoader.class.getResource(profilePath);
    }

    f = url.openStream();

    // we load the properties
    result.load(f);
    // we add the profile to the profiles Hashtable
    allProps.put(new String(profile), result);

    if (Util.onDebug) {
      System.out.println(profile + " profile loaded");
    }
    return result;
  }