private Downloader getDownloader(DownloadRequest request) {
   if (URLUtil.isHttpUrl(request.getSource()) || URLUtil.isHttpsUrl(request.getSource())) {
     return new HttpDownloader(request);
   }
   Log.e(TAG, "Could not find appropriate downloader for " + request.getSource());
   return null;
 }
Exemple #2
0
  private DownloadResult processRequest(ManagedDownloadRequest mRequest) {
    DownloadResult result = null;
    DownloadRequest request = null;
    if (!stop) {
      try {
        request = mRequest.getOriginalRequest();
        result = new DownloadResult();
        if (request == null) {
          throw new Exception("Request is null");
        }

        if (!request.getSource().isWellFormed()) {
          throw new Exception("Datasource in not WellFormed");
        }

        String pageContent = HttpTools.getPageContent(request);

        if (pageContent != null) {
          // try loading Marker data
          List<Marker> markers =
              DataConvertor.getInstance()
                  .load(request.getSource().getUrl(), pageContent, request.getSource());
          result.setAccomplish(mRequest.getUniqueKey(), markers, request.getSource());
          //				Log.d("test", request.getSource().getType().name());
        }
      } catch (Exception ex) {
        result.setError(ex, request);
        Log.w(MixContext.TAG, "ERROR ON DOWNLOAD REQUEST", ex);
      }
    }
    return result;
  }
Exemple #3
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.mixare.mgr.downloader.DownloadManager#submitJob(org.mixare.mgr.downloader
  * .DownloadRequest)
  */
 public String submitJob(DownloadRequest job) {
   String jobId = null;
   if (job != null && job.getSource().isWellFormed()) {
     ManagedDownloadRequest mJob;
     if (!todoList.contains(job)) {
       mJob = new ManagedDownloadRequest(job);
       todoList.add(mJob);
       Log.i(MixView.TAG, "Submitted " + job.toString());
       jobId = mJob.getUniqueKey();
     }
   }
   return jobId;
 }
    public void run() {
      Feed savedFeed = null;

      Feed feed = new Feed(request.getSource(), new Date());
      feed.setFile_url(request.getDestination());
      feed.setDownloaded(true);

      reason = null;
      String reasonDetailed = null;
      successful = true;
      FeedHandler feedHandler = new FeedHandler();

      try {
        feed = feedHandler.parseFeed(feed);
        if (AppConfig.DEBUG) Log.d(TAG, feed.getTitle() + " parsed");
        if (checkFeedData(feed) == false) {
          throw new InvalidFeedException();
        }
        // Save information of feed in DB
        savedFeed = DBTasks.updateFeed(DownloadService.this, feed);
        // Download Feed Image if provided and not downloaded
        if (savedFeed.getImage() != null && savedFeed.getImage().isDownloaded() == false) {
          if (AppConfig.DEBUG) Log.d(TAG, "Feed has image; Downloading....");
          savedFeed.getImage().setFeed(savedFeed);
          final Feed savedFeedRef = savedFeed;
          try {
            requester.downloadImage(DownloadService.this, savedFeedRef.getImage());
          } catch (DownloadRequestException e) {
            e.printStackTrace();
            DBWriter.addDownloadStatus(
                DownloadService.this,
                new DownloadStatus(
                    savedFeedRef.getImage(),
                    savedFeedRef.getImage().getHumanReadableIdentifier(),
                    DownloadError.ERROR_REQUEST_ERROR,
                    false,
                    e.getMessage()));
          }
        }

      } catch (SAXException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (IOException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (ParserConfigurationException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (UnsupportedFeedtypeException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
        reasonDetailed = e.getMessage();
      } catch (InvalidFeedException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      }

      // cleanup();
      if (savedFeed == null) {
        savedFeed = feed;
      }

      saveDownloadStatus(
          new DownloadStatus(
              savedFeed,
              savedFeed.getHumanReadableIdentifier(),
              reason,
              successful,
              reasonDetailed));
      sendDownloadHandledIntent();
      numberOfDownloads.decrementAndGet();
      queryDownloadsAsync();
    }
    private Feed parseFeed(DownloadRequest request) {
      Feed savedFeed = null;

      Feed feed = new Feed(request.getSource(), new Date());
      feed.setFile_url(request.getDestination());
      feed.setId(request.getFeedfileId());
      feed.setDownloaded(true);
      feed.setPreferences(
          new FeedPreferences(0, true, request.getUsername(), request.getPassword()));

      DownloadError reason = null;
      String reasonDetailed = null;
      boolean successful = true;
      FeedHandler feedHandler = new FeedHandler();

      try {
        feed = feedHandler.parseFeed(feed).feed;
        if (BuildConfig.DEBUG) Log.d(TAG, feed.getTitle() + " parsed");
        if (checkFeedData(feed) == false) {
          throw new InvalidFeedException();
        }

      } catch (SAXException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (IOException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (ParserConfigurationException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (UnsupportedFeedtypeException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
        reasonDetailed = e.getMessage();
      } catch (InvalidFeedException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      }

      // cleanup();
      if (savedFeed == null) {
        savedFeed = feed;
      }

      if (successful) {
        return savedFeed;
      } else {
        saveDownloadStatus(
            new DownloadStatus(
                savedFeed,
                savedFeed.getHumanReadableIdentifier(),
                reason,
                successful,
                reasonDetailed));
        return null;
      }
    }