Package org.rometools.feed.module.itunes

Examples of org.rometools.feed.module.itunes.AbstractITunesObject


    public String getNamespaceUri() {
        return AbstractITunesObject.URI;
    }
   
    public com.sun.syndication.feed.module.Module parse(org.jdom2.Element element) {
        AbstractITunesObject module = null;
       
        if (element.getName().equals("channel")) {
            FeedInformationImpl feedInfo = new FeedInformationImpl();
            module = feedInfo;
           
            //Now I am going to get the channel specific tags
            Element owner = element.getChild("owner", ns);
           
            if (owner != null) {
                Element name = owner.getChild("name", ns);
               
                if (name != null) {
                    feedInfo.setOwnerName(name.getValue().trim());
                }
               
                Element email = owner.getChild("email", ns);
               
                if (email != null) {
                    feedInfo.setOwnerEmailAddress(email.getValue().trim());
                }
            }
           
            Element image = element.getChild("image", ns);
           
            if ((image != null) && (image.getAttributeValue("href") != null)) {
                try {
                    URL imageURL = new URL(image.getAttributeValue("href").trim());
                    feedInfo.setImage(imageURL);
                } catch (MalformedURLException e) {
                    log.finer("Malformed URL Exception reading itunes:image tag: " + image.getAttributeValue("href"));
                }
            }
           
            List categories = element.getChildren("category", ns);
            for (Iterator it = categories.iterator(); it.hasNext();) {
                Element category = (Element) it.next();
                if ((category != null) && (category.getAttribute("text") != null)) {
                    Category cat = new Category();
                    cat.setName(category.getAttribute("text").getValue().trim());
                   
                    Element subcategory = category.getChild("category", ns);
                   
                    if (subcategory != null && subcategory.getAttribute("text") != null) {
                        Subcategory subcat = new Subcategory();
                        subcat.setName(subcategory.getAttribute("text").getValue().trim());
                        cat.setSubcategory(subcat);
                    }
                   
                    feedInfo.getCategories().add(cat);
                }
            }
           
        } else if (element.getName().equals("item")) {
            EntryInformationImpl entryInfo = new EntryInformationImpl();
            module = entryInfo;
           
            //Now I am going to get the item specific tags
           
            Element duration = element.getChild("duration", ns);
           
            if (duration != null  && duration.getValue() != null ) {
                Duration dur = new Duration(duration.getValue().trim());
                entryInfo.setDuration(dur);
            }
        }
        if (module != null) {
            //All these are common to both Channel and Item
            Element author = element.getChild("author", ns);
           
            if (author != null && author.getText() != null ) {
                module.setAuthor(author.getText());
            }
           
            Element block = element.getChild("block", ns);
           
            if (block != null) {
                module.setBlock(true);
            }
           
            Element explicit = element.getChild("explicit", ns);
           
            if ((explicit != null) && explicit.getValue() != null
                    && explicit.getValue().trim().equalsIgnoreCase("yes")) {
                module.setExplicit(true);
            }
           
            Element keywords = element.getChild("keywords", ns);
           
            if (keywords != null) {
                StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ",");
                String[] keywordsArray = new String[tok.countTokens()];
               
                for (int i = 0; tok.hasMoreTokens(); i++) {
                    keywordsArray[i] = tok.nextToken();
                }
               
                module.setKeywords(keywordsArray);
            }
           
            Element subtitle = element.getChild("subtitle", ns);
           
            if (subtitle != null) {
                module.setSubtitle(subtitle.getTextTrim());
            }
           
            Element summary = element.getChild("summary", ns);
           
            if (summary != null) {
                module.setSummary(summary.getTextTrim());
            }         
        }
       
        return module;
    }
View Full Code Here


        if (!(module instanceof AbstractITunesObject)) {
            return;
        }

        AbstractITunesObject itunes = (AbstractITunesObject) module;

        if (itunes instanceof FeedInformationImpl) {
            //Do Channel Specific Stuff.
            FeedInformationImpl info = (FeedInformationImpl) itunes;
            Element owner = this.generateSimpleElement("owner", "");
            Element email = this.generateSimpleElement("email", info.getOwnerEmailAddress());
            owner.addContent(email);

            Element name = this.generateSimpleElement("name", info.getOwnerName());
            owner.addContent(name);
            element.addContent(owner);

            if (info.getImage() != null) {
                Element image = this.generateSimpleElement("image", "");
                image.setAttribute("href", info.getImage().toExternalForm());
                element.addContent(image);
            }

            for (Iterator it = info.getCategories().iterator(); it.hasNext();) {
          Category cat = (Category) it.next();
                Element category = this.generateSimpleElement("category", "");
                category.setAttribute("text", cat.getName());

                if (cat.getSubcategory() != null) {
                    Element subcat = this.generateSimpleElement("category", "");
                    subcat.setAttribute("text", cat.getSubcategory().getName());
                    category.addContent(subcat);
                }

                element.addContent(category);
            }
        } else if (itunes instanceof EntryInformationImpl) {
            EntryInformationImpl info = (EntryInformationImpl) itunes;

            if (info.getDuration() != null) {
                element.addContent(this.generateSimpleElement("duration", info.getDuration().toString()));
            }
        }

        if (itunes.getAuthor() != null) {
            element.addContent(this.generateSimpleElement("author", itunes.getAuthor()));
        }

        if (itunes.getBlock()) {
            element.addContent(this.generateSimpleElement("block", ""));
        }

        if (itunes.getExplicit()) {
            element.addContent(this.generateSimpleElement("explicit", "yes"));
        } else {
            element.addContent(this.generateSimpleElement("explicit", "no"));
        }

        if (itunes.getKeywords() != null) {
            StringBuffer sb = new StringBuffer();

            for (int i = 0; i < itunes.getKeywords().length; i++) {
                if (i != 0) {
                    sb.append(", ");
                }

                sb.append(itunes.getKeywords()[i]);
            }

            element.addContent(this.generateSimpleElement("keywords", sb.toString()));
        }

        if (itunes.getSubtitle() != null) {
            element.addContent(this.generateSimpleElement("subtitle", itunes.getSubtitle()));
        }

        if (itunes.getSummary() != null) {
            element.addContent(this.generateSimpleElement("summary", itunes.getSummary()));
        }
    }
View Full Code Here

TOP

Related Classes of org.rometools.feed.module.itunes.AbstractITunesObject

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.