Package org.rssowl.contrib.podcast.model

Examples of org.rssowl.contrib.podcast.model.IPersonalAttachment


    }
  }

  public Image getColumnImage(Object element, int columnIndex) {
    if (element instanceof IPersonalAttachment) {
      IPersonalAttachment lEnclosure = (IPersonalAttachment) element;
      switch (columnIndex) {
      case 0: {
        if (this.mPreparator != null) {
          return mPreparator.getImage(lEnclosure);
        }
View Full Code Here


      }
      }
    }

    if (element instanceof IPersonalAttachment) {
      IPersonalAttachment lEncl = (IPersonalAttachment) element;
      Object lObj = getValueAt(lEncl, columnIndex);
      if (lObj instanceof String) {
        return (String) lObj;
      }
      if (lObj instanceof Boolean) {
View Full Code Here

    case 0: {
      return new Integer(mPreparator.indexOf(pFile)).toString();
    }
    case 1: {
      if (pFile instanceof IPersonalAttachment) {
        IPersonalAttachment lEncl = (IPersonalAttachment) pFile;
        return lEncl.getNews().getTitle();
      }
      return pFile.getName();
    }
    case 2: {// Size web
      if (pFile instanceof IPersonalAttachment) {
        lReturn = new Integer(pFile.getFileLength());
      } else {
        lReturn = new Integer(0);
      }
      break;
    }
    case 3: {// Size disk
      File localFile = pFile.getFile();
      if (localFile != null && !localFile.getPath().equals("null")) {
        lReturn = new Integer((int) localFile.length());
      } else {
        lReturn = "";
      }
      break;
    }
    case 4: { // If in player.
      lReturn = new Boolean(pFile.getInPlayer());
      break;
    }
    case 5: { // Last modified
      if (pFile instanceof IPersonalAttachment) {
        IPersonalAttachment lEnclosure = (IPersonalAttachment) pFile;
        Date lDate = lEnclosure.getNews().getPublishDate();
        lReturn = Util.formatDate(lDate, "EEEE, MMM d hh:mm a");
      } else {
        Date lDate = pFile.getDate();
        lReturn = Util.formatDate(lDate, "EEEE, MMM d hh:mm a");
      }
View Full Code Here

      IXFile lFile = (IXFile)lTableItem.getData();
      if(arg2 instanceof Boolean){
        Boolean lValue = (Boolean)arg2;
        lFile.setMarked(lValue.booleanValue());
        if(lFile instanceof IPersonalAttachment ){
          IPersonalAttachment lEncl = (IPersonalAttachment)lFile;

// CB TODO,migrate the parameter which tells about the marking strategy.          
//          lEncl.getFeed().updateAllCandidates(Configuration
//                          .getInstance().getMarkMax());
View Full Code Here

    int lState = pDownload.getState();
    if (lState != DownloadService.QUEUED) {
      return;
    }

    IPersonalAttachment pPAttachment = pDownload.getAttachment();

    URI lLink = pPAttachment.getLink();
    URL lUrl;
    try {
      lUrl = lLink.toURL();
    } catch (MalformedURLException e) {
      // mmmhh bad link. let's exist.
      throw new NetworkException(e.getMessage());
    }

     sLog.info("Starting download: "
     + pDownload.getAttachment().getName());

    GetMethod gMethod = null;
    FileOutputStream lOutputStream = null;
    InputStream lInputStream = null;
    int lCount = 0; // Downloaded bytes count

    // STATUS CHANGE CONNECTING
    pDownload.setState(DownloadService.CONNECTING);
    notifyNetworkEvent(new NetTaskEvent(pDownload,
        NetTaskEvent.DOWNLOAD_STATUS_CHANGED));
    boolean lRedirect = false;

    try {
      boolean append = false;

      if ("http".equals(lUrl.getProtocol())) {
        HttpClient hClient = new HttpClient();
        // CB TODO, get this from core preferences.
        hClient.getParams().setSoTimeout(
            NetPropertiesHandler.timeoutValue);
        HostConfiguration hc = hClient.getHostConfiguration();
        hc = setProxySetttings(hClient, hc);
        gMethod = new GetMethod(lUrl.toExternalForm());

        // Add a byte range header asking for partial content.
        if (pDownload.getAttachment().isIncomplete()) {
          append = true;
          addByteRangeHeader(pDownload.getAttachment(), gMethod);
          gMethod.setFollowRedirects(true);
        } else {
          gMethod.setFollowRedirects(false);
        }
       
        // Need to do redirects manually to get the filename for
        // storage. We follow the redirections until a 200 OK.
        // we break in case of error.

        boolean lContinue = true;
        while (lContinue) {

          int status = hClient.executeMethod(gMethod);
          switch (status) { // Switch the result.
          case HttpStatus.SC_OK: {
            lContinue = false;
          }
            break;
          case HttpStatus.SC_MOVED_PERMANENTLY:
          case HttpStatus.SC_MOVED_TEMPORARILY:
          case HttpStatus.SC_SEE_OTHER:
          case HttpStatus.SC_TEMPORARY_REDIRECT: {
            lRedirect = true;
            // The redirection code fails for
            // localhost, use IP address as a workaround.
            String redirectLocation;
            Header locationHeader = gMethod
                .getResponseHeader("location");

            if (locationHeader != null) {
              redirectLocation = locationHeader.getValue();
              gMethod.setFollowRedirects(true);
              lUrl = new URL(redirectLocation);
            } else {

            }
          }
            break;
          case HttpStatus.SC_PARTIAL_CONTENT:
            // sLog.info("(1) Partial download granted for: "
            // + pUrl.toExternalForm());
            // sLog.info("(2) Start at byte: "
            // + gMethod.getRequestHeader("Range")
            // .getValue());
            lContinue = false;
            break;
          case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE: {
            // 28-07-2006, Duh? OK let's try again without
            // Range.
            // sLog.warn("(1) Partial download denied for: "
            // + pUrl.toExternalForm());

            Header lRHeader = gMethod
                .getResponseHeader("Content-Range");
            if (lRHeader != null) {
              // sLog.warn("(2) The content-range is: "
              // + lRHeader.getValue());
            }

            // sLog.warn(gMethod.getResponseBodyAsString());

            Header h = gMethod.getRequestHeader("Range");
            gMethod.removeRequestHeader(h);
            append = false;
          }
            break;
          case HttpStatus.SC_UNAUTHORIZED: {
            // Retry with password.
            hc = hClient.getHostConfiguration();
            hc = setProxySetttings(hClient, hc);
            hClient.getState()
                .setCredentials(
                    new AuthScope(AuthScope.ANY_HOST,
                        AuthScope.ANY_PORT,
                        AuthScope.ANY_REALM),
                    getCredentials(pDownload
                        .getAttachment().getNews()
                        .getFeedReference().resolve()));

            gMethod = new GetMethod(lUrl.toString());
            gMethod.setDoAuthentication(true);
          }
            break;
          case HttpStatus.SC_METHOD_NOT_ALLOWED: {
            // This sometimes happens, we exit with an error
            // message.
             sLog.warn(gMethod.getStatusLine().getReasonPhrase()
             + " to URL " + lUrl.toExternalForm());
          }
            break;
          default: {
            pDownload.setState(DownloadService.ERROR);
            pDownload.setMessage(gMethod.getStatusLine()
                .getReasonPhrase());

            throw new NetworkException(pDownload.getMessage());
          }
          }
        }
       
        // CB TODO Asser the HEADER information.
        HTTPHEADInfo lInfo = getHeadInfo(gMethod);
        if (!append) {
          try {
            pDownload.getAttachment().setContentSize(lInfo.length);
          } catch (IllegalArgumentException iae) {
            // Likely parsing of the HEAD Date failed.
          }
        } else {
          pDownload.getAttachment().setContentSize(
              (int) pDownload.getAttachment().getLength());
        }
        pDownload.getAttachment().setContentDate(
            lInfo.getModifiedLong());

        pDownload.setLength(pDownload.getAttachment().getContentSize());
        lInputStream = gMethod.getResponseBodyAsStream();
      } else {
        pDownload.setLength(0);
        lInputStream = lUrl.openStream();
      }

      // REDIRECT Handling.
      // In case of re-direct we re-create a download file.
      // We don't store the re-direct URL. (It is volatile).
      // The volatile redirect URL is used to generate the file name.
      // if it can't be generated, we create a filename from the
      // the RSS entry and set it in the enclosure object. Before we
      // redownload
      // the file, we also want to
      // check if the file is by chance an already existing file in
      // the folder, cache or player. If so we cancel the download.
      // We fire a change event.

      boolean lInspect = false;
      if (lRedirect) {
        File lFile = pPAttachment.getFile(true);
        pPAttachment.setFileName(lFile.getName());
      }

      File lF = pPAttachment.getFile();
      if (!lF.exists()) {
        lF.createNewFile();
        lInspect = false;
      }

      // --- File Inspection.
      // CB FIXME Do we have to inspect only after redirect?
      // We don't inspect a file with a random number.
      if (lInspect) {
        // If we re-inspect and remark, we ignore the
        // candidate restriction has we are already
        // in the download phase. The enclosure was either
        // a candidate before or downloaded manually.
        pPAttachment.setCandidate(false);

        // CB TODO, migrate inspections.
        // XFeedLogic.getInstance().inspectSingleFile(pEncl);
        // XFeedLogic.getInstance().markSingleEnclosure(pEncl);

        if (pPAttachment.isIncomplete()) {
          // CB FIXME This is a problem, as we
          // need to execute again to get the byte range.
          // Rethink the whole redirect handling.
        }

        // CB TODO, this is very jPodder specific.
        // updating the candidate, can likely be done
        // in the model.

        // pEncl.getFeed().updateSingleCandidate(pEncl,
        // Configuration.getInstance().getMarkMax());

        if (!pPAttachment.isMarked()) {
          pDownload.setState(DownloadService.CANCELLED);
          pDownload.setMessage("Redirect leads to existing file");
          throw new NetworkException(
              "Redirect leads to existing file");
        }
      }

      // THE ENCLOSURE FILE IS NEVER NULL, AND EXISTS FROM HERE!
      // WE ARE IN DEEP SHIT OTHERWISE.

       sLog.info(Messages.getString("tasks.download.newDownload")
       + pPAttachment.getFile());

      lOutputStream = new FileOutputStream(lF, append);

      if (append) {
        lCount = (int) pPAttachment.getFile().length();
      }
      if (pDownload.getLength() != 0) {
      } else {
        // Length of the file is unknown.
        // This not good. (only for HTTP)
View Full Code Here

      // We have to reset the candidate count, as the count
      // is regenerated here.
      pPBookMark.setCandidateCount(0);
      for (IXFile lFile : lFiles) {
        if (lFile instanceof IPersonalAttachment) {
          IPersonalAttachment lPAttachment = (IPersonalAttachment) lFile;
          if (!lPAttachment.isInspected()) {
            if (lPAttachment.getFile() != null) {

             
             
// TODO Linked STEP. if (pPBookMark.getInstruction().isInspect()) {
// inspectAttachment(lPAttachment);
View Full Code Here

   * @param shell
   */
  public void queueJob(IPersonalAttachment pAttachment, final Shell shell) {

    Download lTask = null;
    IPersonalAttachment lPAttachment;
    if (!(pAttachment instanceof IPersonalAttachment)) {
      lPAttachment = (IPersonalAttachment) pAttachment;
    }else{
      lPAttachment = pAttachment;
    }
View Full Code Here

      // pauzed.
    }
    if(!mDownloadList.contains(pDownload)){
      mDownloadList.add(mDownloadList.size(), pDownload)
      notifyDownloadEvent(new DownloadEvent(this));
      IPersonalAttachment lAttach = pDownload.getAttachment();
    }

    try {
      int lState = pDownload.getState();
      if (lState == CANCELLED) {
View Full Code Here

   */
  public void netActionPerformed(NetTaskEvent event) {

    Download lDownload = (Download) event.getSource();
    int lState = lDownload.getState();
    IPersonalAttachment lAttachment = lDownload.getAttachment();

    if (event.getNetEvent() == NetTaskEvent.DOWNLOAD_SUCCESS) {

      // CB TODO, decide what to do with the cache.
      // Cache.getInstance().addTrack(lEnclosure.getFile());
      lAttachment.setCached(true);
      lAttachment.setDownloadCompleted(true);

      lAttachment.setLocal(true);

      lAttachment.setMarked(false);
      lAttachment.setCandidate(false);

      // CB TODO, review if this is the option.
      // lEnclosure.getFeed().setCandidatesCount(
      // lEnclosure.getFeed().getCandidatesCount() - 1);

      mLog.info("Download of: " + lAttachment.getFile() + " completed");

      // CB TODO Migrate post-download handling.
      // if (ContentLogic.isTorrent(lEnclosure.getFile().getName())) {
      // mLog.info("Process torrent file.");
      // lEnclosure.setTorrent();
      // } else {
      // mLog.info("Process file (non-torrent).");
      //
      // // CB TODO In Concurrency, we would like to exit this thread and
      // // let another thread post-process the download. Using
      // // semaphores? Also which tasks are executed should be
      // // configurable.
      //
      // ID3Logic.getInstance().rewriteTags(lEnclosure);
      // PlayerLogic.getInstance().storeInPlayer(lEnclosure);
      // }
    }

    if (event.getNetEvent() == NetTaskEvent.DOWNLOAD_STATUS_CHANGED) {
      mLog.info("Download of: " + lAttachment + " changed state to: "
          + STATE_DESCRIPTION[lState]);
      if (event.getNetEvent() == NetTaskEvent.DOWNLOAD_FAILED) {
        mLog.error("Error while downloading " + lAttachment);
        // retry the download.
        if (event.getException() != null) {
          String message = event.getException().getMessage();
          mLog.error(message);
          if (message != null) {
            if (message.startsWith("Read timed")
                || message.startsWith("Partial content")
                || message.startsWith("Connection reset")
                || message.startsWith("Connection timed out")) {
              DownloadsRetry lRetry = new DownloadsRetry();
              lRetry.retryLater(lDownload);
            }
          }
        }
        // Delete the file if the download failed totally (size =0).
        File file = lAttachment.getFile();
        if (file != null && file.exists() && file.length() == 0) {
          file.delete();
        }
      }

View Full Code Here

TOP

Related Classes of org.rssowl.contrib.podcast.model.IPersonalAttachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.