/** * Set the podcast's publication date to the episode's if it is more recent * * @param episode * @param podcast * @param episodePublicationDate */ private void updatePodcastPublicationDateAndLastMediaUrl(Episode episode, Podcast podcast) { Date podcastPublicationDate = podcast.getPublicationDate(); boolean episodePubDateIsMoreRecent = episode.getPublicationDate() != null && (podcastPublicationDate == null || podcastPublicationDate.before(episode.getPublicationDate())); if (episodePubDateIsMoreRecent) { podcast.setPublicationDate(episode.getPublicationDate()); podcast.setLastEpisodeMediaUrl(episode.getMediaUrl()); } }
@SuppressWarnings("unchecked") public void setPodcastFeedAttributes(Podcast podcast, boolean feedPropertyHasBeenSet) throws IllegalArgumentException, FeedException, IOException { SyndFeed syndFeed = null; if (!feedPropertyHasBeenSet) { syndFeed = syndFeedService.getSyndFeedForUrl(podcast.getUrl()); podcast.setPodcastFeed(syndFeed); } if (syndFeed != null) { // set DESCRIPTION for podcast - used in search if (syndFeed.getDescription() != null && !syndFeed.getDescription().equals("")) { String description = syndFeed.getDescription(); // out of description remove tags if any exist and store also // short description String descWithoutTabs = description.replaceAll("\\<[^>]*>", ""); if (descWithoutTabs.length() > MAX_LENGTH_DESCRIPTION) { podcast.setDescription(descWithoutTabs.substring(0, MAX_LENGTH_DESCRIPTION)); } else { podcast.setDescription(descWithoutTabs); } } // set TITLE - used in search String podcastTitle = syndFeed.getTitle(); podcast.setTitle(podcastTitle); // build the title that will appear in the URL when accessing a // podcast from the main application String titleInUrl = podcastTitle.trim().replaceAll("[^a-zA-Z0-9\\-\\s\\.]", ""); titleInUrl = titleInUrl.replaceAll("[\\-| |\\.]+", "-"); if (titleInUrl.length() > TITLE_IN_URL_MAX_LENGTH) { podcast.setTitleInUrl(titleInUrl.substring(0, TITLE_IN_URL_MAX_LENGTH)); } else { podcast.setTitleInUrl(titleInUrl); } // set author podcast.setAuthor(syndFeed.getAuthor()); // set COPYRIGHT podcast.setCopyright(syndFeed.getCopyright()); // set LINK podcast.setLink(syndFeed.getLink()); // set url link of the podcast's image when selecting the podcast in // the main application - mostly used through <a // href="urlOfImageToDisplay".... SyndImage podcastImage = syndFeed.getImage(); if (null != podcastImage) { if (podcastImage.getUrl() != null) { podcast.setUrlOfImageToDisplay(podcastImage.getUrl()); } else if (podcastImage.getLink() != null) { podcast.setUrlOfImageToDisplay(podcastImage.getLink()); } else { podcast.setUrlOfImageToDisplay(configBean.get("NO_IMAGE_LOCAL_URL")); } } else { podcast.setUrlOfImageToDisplay(configBean.get("NO_IMAGE_LOCAL_URL")); } podcast.setPublicationDate(null); // default value is null, if cannot // be set // set url media link of the last episode - this is used when // generating the ATOM and RSS feeds from the Start page for example for (SyndEntry entry : (List<SyndEntry>) syndFeed.getEntries()) { // get the list of enclosures List<SyndEnclosure> enclosures = (List<SyndEnclosure>) entry.getEnclosures(); if (null != enclosures) { // if in the enclosure list is a media type (either audio or // video), this will set as the link of the episode for (SyndEnclosure enclosure : enclosures) { if (null != enclosure) { podcast.setLastEpisodeMediaUrl(enclosure.getUrl()); break; } } } if (entry.getPublishedDate() == null) { LOG.warn( "PodURL[" + podcast.getUrl() + "] - " + "COULD NOT SET publication date for podcast, default date 08.01.1983 will be used "); } else { podcast.setPublicationDate(entry.getPublishedDate()); } // first episode in the list is last episode - normally (are // there any exceptions?? TODO -investigate) break; } } }