Example #1
0
  // Grabs assets off the intarwebz and saves them to a local store/jail for hydration.
  private void fetch(JSONArray args) {
    String url;
    String username;
    String password;
    String id;
    try {
      id = args.getString(0);
      url = args.getString(1);
      username = args.getString(2);
      password = args.getString(3);

      // Create directory for app.
      local_path = "/data/data/" + ctx.getPackageName() + "/remote_app/" + id + "/";
      File fp = new File(local_path);
      fp.mkdirs();

      if (fetchApp(url, username, password)) {
        this.success(
            new PluginResult(PluginResult.Status.OK, "file://" + local_path + "index.html"),
            this.callback);
      } else {
        this.error(
            new PluginResult(
                PluginResult.Status.ERROR,
                "Error during app saving or fetching; protocol or IO error likely."),
            this.callback);
      }
    } catch (JSONException e) {
      this.error(
          new PluginResult(
              PluginResult.Status.JSON_EXCEPTION,
              "JSON exception during argument parsing; make sure the app ID, URL, username and password were passed as an argument."),
          this.callback);
    }
  }
Example #2
0
  public void loadProperty() {

    try {

      File file = new File(confFileName);

      log.debug("file=" + file.getAbsolutePath());

      confProperties = new Properties();
      confProperties.loadFromXML(new FileInputStream(file));

      bonitaApiHost = confProperties.getProperty("bonita.api.host");
      bonitaApiUsername = confProperties.getProperty("bonita.api.username");
      bonitaApiPassword = confProperties.getProperty("bonita.api.password");
      bonitaApiHttpUsername = confProperties.getProperty("bonita.api.http.username");
      bonitaApiHttpPassword = confProperties.getProperty("bonita.api.http.password");
      bonitaApiPath = confProperties.getProperty("bonita.api.path");

      rallyApiHost = confProperties.getProperty("rally.api.host");
      rallyApiHttpUsername = confProperties.getProperty("rally.api.http.username");
      rallyApiHttpPassword = confProperties.getProperty("rally.api.http.password");
      rallyProjectIds = confProperties.getProperty("rally.project.ids");

      // bonitaProcessId=properties.getProperty("bonita.process.xp_code.id");

      workflowServiceUrl = confProperties.getProperty("service.url");

    } catch (Exception e) {
      log.error("", e);
    }
  }
Example #3
0
  private void processDeletionQueue() {

    final int maxToDelete = 2;

    int deleted = 0;

    Long toDelete;

    while (maxToDelete > deleted++ && (toDelete = fileDeletionQueue.dequeue()) != null) {

      // Attempt to delete file
      final File f = getExistingCacheFile(toDelete);

      if (f != null && !f.delete()) {
        f.deleteOnExit();
      }
    }
  }
Example #4
0
  private static void pruneTemp(final File dir) {

    for (final String file : dir.list()) {

      if (file.endsWith(tempExt)) {
        new File(dir, file).delete();
      }
    }
  }
Example #5
0
  private File getExistingCacheFile(final long id) {

    final File externalCacheDir = context.getExternalCacheDir();

    if (externalCacheDir != null) {
      final File fExternal = new File(externalCacheDir, id + ext);

      if (fExternal.exists()) {
        return fExternal;
      }
    }

    final File fInternal = new File(context.getCacheDir(), id + ext);

    if (fInternal.exists()) {
      return fInternal;
    }

    return null;
  }
Example #6
0
  private void getCacheFileList(final File dir, final HashSet<Long> currentFiles) {

    for (final String file : dir.list()) {

      final Long cacheFileId = isCacheFile(file);

      if (cacheFileId != null) {
        currentFiles.add(cacheFileId);
      }
    }
  }
Example #7
0
 private boolean deleteDirectory(File path) {
   File[] files = path.listFiles();
   for (int i = 0; i < files.length; i++) {
     File f = files[i];
     if (f.isFile()) {
       if (!f.delete()) {
         return false;
       }
     } else {
       if (!deleteDirectory(f)) {
         return false;
       }
     }
   }
   if (path.delete()) {
     return true;
   } else {
     return false;
   }
 }
Example #8
0
  private boolean saveAndVerify(ZipInputStream data) throws IOException {
    try {
      ZipEntry ze;
      while ((ze = data.getNextEntry()) != null) {
        // Filename + reference to file.
        String filename = ze.getName();
        File output = new File(local_path + filename);

        if (filename.endsWith("/")) {
          output.mkdirs();
        } else {
          if (output.exists()) {
            // Delete the file if it already exists.
            if (!output.delete()) {
              return false;
            }
          }
          if (output.createNewFile()) {
            FileOutputStream out = new FileOutputStream(output);
            byte[] buffer = new byte[1024];
            int count;
            while ((count = data.read(buffer)) != -1) {
              out.write(buffer, 0, count);
            }
          } else {
            return false;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    } finally {
      data.close();
    }
    return true;
  }