protected DownloadingPackage getDownloadingPackage(String pkgId) { ConnectDownloadManager cdm = Framework.getLocalService(ConnectDownloadManager.class); List<DownloadingPackage> pkgs = cdm.listDownloadingPackages(); for (DownloadingPackage pkg : pkgs) { if (pkg.getId().equals(pkgId)) { return pkg; } } return null; }
@GET @Produces("application/json") @Path(value = "progressAsJSON") public String getDownloadsProgress() { ConnectDownloadManager cdm = Framework.getLocalService(ConnectDownloadManager.class); List<DownloadingPackage> pkgs = cdm.listDownloadingPackages(); StringBuffer sb = new StringBuffer(); sb.append("["); for (int i = 0; i < pkgs.size(); i++) { if (i > 0) { sb.append(","); } sb.append("{ \"pkgid\" : "); sb.append("\"" + pkgs.get(i).getId() + "\","); sb.append(" \"progress\" : "); sb.append(pkgs.get(i).getDownloadProgress() + "}"); } sb.append("]"); return sb.toString(); }