コード例 #1
0
ファイル: FirefoxProfile.java プロジェクト: santiycr/selenium
  public File addExtension(Class<?> loadResourcesUsing, String loadFrom) throws IOException {
    // Is loadFrom a file?
    File file = new File(loadFrom);
    if (file.exists()) {
      addExtension(file);
      return file;
    }

    // Try and load it from the classpath
    InputStream resource = loadResourcesUsing.getResourceAsStream(loadFrom);
    if (resource == null && !loadFrom.startsWith("/")) {
      resource = loadResourcesUsing.getResourceAsStream("/" + loadFrom);
    }
    if (resource == null) {
      resource = FirefoxProfile.class.getResourceAsStream(loadFrom);
    }
    if (resource == null && !loadFrom.startsWith("/")) {
      resource = FirefoxProfile.class.getResourceAsStream("/" + loadFrom);
    }
    if (resource == null) {
      throw new FileNotFoundException("Cannot locate resource with name: " + loadFrom);
    }

    File root;
    if (FileHandler.isZipped(loadFrom)) {
      root = FileHandler.unzip(resource);
    } else {
      throw new WebDriverException("Will only install zipped extensions for now");
    }

    addExtension(root);
    return root;
  }
コード例 #2
0
ファイル: FirefoxProfile.java プロジェクト: santiycr/selenium
 private File obtainRootDirectory(File extensionToInstall) throws IOException {
   File root = extensionToInstall;
   if (!extensionToInstall.isDirectory()) {
     BufferedInputStream bis = new BufferedInputStream(new FileInputStream(extensionToInstall));
     try {
       root = FileHandler.unzip(bis);
     } finally {
       bis.close();
     }
   }
   return root;
 }