From: <jbo...@li...> - 2006-01-08 01:16:50
|
Author: wrzep Date: 2006-01-07 20:16:44 -0500 (Sat, 07 Jan 2006) New Revision: 2026 Modified: trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java Log: itunes parsing (not finished) http://jira.jboss.com/jira/browse/JBLAB-540 Pawel Modified: trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java =================================================================== --- trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java 2006-01-07 20:03:08 UTC (rev 2025) +++ trunk/forge/portal-extensions/forge-podcast/src/java/org/jboss/forge/podcast/Podcast.java 2006-01-08 01:16:44 UTC (rev 2026) @@ -34,7 +34,6 @@ import java.util.SimpleTimeZone; import java.net.URL; -import java.net.HttpURLConnection; import java.io.IOException; import org.jboss.forge.common.XmlTools; @@ -134,9 +133,35 @@ */ private void fillItemInfo(DelegateContext nodeContext, ItemIF item) { - nodeContext.put("title", item.getTitle()); - nodeContext.put("description", item.getDescription()); + if (item == null) { + return; + } + // item title + String title = item.getTitle(); + if ((title == null) || (title.length() == 0) || (title.equals("<No Title>"))) { + title = item.getElementValue("itunes:subtitle"); + } + nodeContext.put("title", title); + + // item autor + String author = item.getElementValue("itunes:author"); + if ((author == null) || (author.length() == 0)) { + ChannelIF channel = item.getChannel(); + if (channel != null) { + author = channel.getElementValue("itunes:author"); + } + } + nodeContext.put("author", author); + + // item descritpion + String description = item.getDescription(); + if ((description == null) || (description.length() == 0)) { + description = item.getElementValue("itunes:summary"); + } + nodeContext.put("description", description); + + // item date Date date = item.getDate(); if (date != null) { DateFormat dateFormat = DateFormat.getInstance(); @@ -145,21 +170,34 @@ nodeContext.put("date", dateString); } + // item link URL link = item.getLink(); if (link != null) { nodeContext.put("link", link.toString()); } + // item image // For unknown reasons there is not item.getImage() method (informa version 0.6.5) String[] imageProperties = item.getElementValues("image", new String[] {"title", "url", "link", "width", "height", "description"} ); - if (imageProperties != null) { - nodeContext.put("image", imageProperties[1]); + String image = null; + if (imageProperties != null) + image = imageProperties[1]; + + if ((image == null) || (image.length() == 0)) { + image = item.getElementValue("itunes:image"); + } + + if ((image != null) && (image.length() != 0)) { + nodeContext.put("image", image); nodeContext.next("hasImage"); } else { nodeContext.next("hasNotImage"); } + + // duration, usually in dd:hh:mm or hh:mm format + nodeContext.put("duration", item.getElementValue("itunes:duration")); } /** @@ -169,6 +207,7 @@ * @param item ItemEnclosureIF to get information from */ private void fillEnclosureInfo(DelegateContext nodeContext, ItemEnclosureIF enclosure) { + URL enclosureLocation = null; if (enclosure != null) { @@ -190,8 +229,14 @@ */ private void fillChannelInfo(DelegateContext nodeContext, ChannelIF channel) { - nodeContext.put("channel-title", channel.getTitle()); + // channel title + String title = channel.getTitle(); + if ((title == null) || (title.length() == 0) || (title.equals("<No Title>"))) { + title = channel.getElementValue("itunes:subtitle"); + } + nodeContext.put("channel-title", title); + // channel link URL channelLocation = channel.getLocation(); String channelStringLink = null; @@ -201,18 +246,30 @@ channelStringLink = channel.getElementValue("link"); } - if (channelStringLink != null) { - nodeContext.put("channel-link", channelStringLink); - } + nodeContext.put("channel-link", channelStringLink); + // channel image ImageIF channelImage = channel.getImage(); + String image = null; if ((channelImage != null) && (channelImage.getLocation() != null)) { + image = channelImage.getLocation().toString(); + } + + if ((image == null) || (image.length() == 0)) { + image = channel.getElementValue("itunes:image"); + } + + if ((image != null) && (image.length() != 0)) { nodeContext.put("channel-image", channelImage.getLocation().toString()); nodeContext.next("channel-hasImage"); } else { nodeContext.next("channel-hasNotImage"); } + + // channel category + String category = channel.getElementValue("itunes:category"); + nodeContext.put("category", category); } /** @@ -236,12 +293,6 @@ fillChannelInfo(nodeContext, item.getChannel()); - // TODO itunes tags parsing - /* - System.out.println("channel / element value / author = " + channel.getElementValue("itunes:author")); - System.out.println("item / element value / image = " + item.getElementValue("itunes:image")); - */ - context.append("podcast", nodeContext); } } @@ -318,19 +369,14 @@ } URL url = new URL(urlString); - - /*TODO updating when change registred only (using http protocol) - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - Date date = new Date(connection.getDate()); - - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("HEAD"); - con.connect(); - date = new Date(con.getDate()); - */ - + ChannelIF channel = FeedParser.parse(new ChannelBuilder(), url.openStream()); - ret.addAll(channel.getItems()); + if (channel != null) { + Collection items = channel.getItems(); + if ((items != null) && (!items.isEmpty())) { + ret.addAll(items); + } + } } catch (IOException e) { log.warn(urlString + " could not be found."); |