Package org.rometools.feed.module.mediarss.types

Examples of org.rometools.feed.module.mediarss.types.Metadata


                    createIntProperty(r_media, NS_MA + "frameWidth", content.getWidth());

                createStringProperty(r_media, NS_MA + "hasLanguage", content.getLanguage());

                if(content.getMetadata() != null) {
                    Metadata metadata = content.getMetadata();

                    createStringProperty(r_media, NS_MA + "title", metadata.getTitle());
                    createStringProperty(r_media, NS_MA + "copyright", metadata.getCopyright());
                    createStringProperty(r_media, NS_MA + "description", metadata.getDescription());

                    for(String keyword : metadata.getKeywords()) {
                        createStringProperty(r_media, NS_MA + "hasKeyword", keyword);
                    }

                }
View Full Code Here


       
        return (MediaGroup[]) values.toArray(new MediaGroup[values.size()]);
    }
   
    private Metadata parseMetadata(Element e) {
        Metadata md = new Metadata();
        // categories
        {
            List categories = e.getChildren("category", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; (categories != null) && (i < categories.size());
            i++) {
                try {
                    Element cat = (Element) categories.get(i);
                    values.add(new Category(cat.getAttributeValue("scheme"),
                            cat.getAttributeValue("label"), cat.getText()));
                } catch (Exception ex) {
                    LOG.log(Level.WARNING, "Exception parsing category tag.", ex);
                }
            }
           
            md.setCategories((Category[]) values.toArray(
                    new Category[values.size()]));
        }
       
        // copyright
        try {
            Element copy = e.getChild("copyright", getNS());
           
            if (copy != null) {
                md.setCopyright(copy.getText());
                md.setCopyrightUrl((copy.getAttributeValue("url") != null)
                ? new URI(copy.getAttributeValue("url")) : null);
            }
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Exception parsing copyright tag.", ex);
        }
        // credits
        {
            List credits = e.getChildren("credit", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; (credits != null) && (i < credits.size()); i++) {
                try {
                    Element cred = (Element) credits.get(i);
                    values.add(new Credit(cred.getAttributeValue("scheme"),
                            cred.getAttributeValue("role"), cred.getText()));
                    md.setCredits( (Credit[]) values.toArray( new Credit[ values.size()]));
                } catch (Exception ex) {
                    LOG.log(Level.WARNING, "Exception parsing credit tag.", ex);
                }
            }
        }
       
        // description
        try {
            Element description = e.getChild("description", getNS());
           
            if (description != null) {
                md.setDescription(description.getText());
                md.setDescriptionType(description.getAttributeValue("type"));
            }
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Exception parsing description tag.", ex);
        }
       
        // hash
        try {
            Element hash = e.getChild("hash", getNS());
           
            if (hash != null) {
                md.setHash(new Hash(hash.getAttributeValue("algo"),
                        hash.getText()));
            }
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Exception parsing hash tag.", ex);
        }
        // keywords
        {
            Element keywords = e.getChild("keywords", getNS());
           
            if (keywords != null) {
                StringTokenizer tok = new StringTokenizer(keywords.getText(),
                        ",");
                String[] value = new String[tok.countTokens()];
               
                for (int i = 0; tok.hasMoreTokens(); i++) {
                    value[i] = tok.nextToken().trim();
                }
               
                md.setKeywords(value);
            }
        }
        // ratings
        {
            List ratings = e.getChildren("rating", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; (ratings != null) && (i < ratings.size()); i++) {
                try {
                    Element rat = (Element) ratings.get(i);
                    values.add(new Rating(rat.getAttributeValue("scheme"),
                            rat.getText()));
                } catch (Exception ex) {
                    LOG.log(Level.WARNING, "Exception parsing rating tag.", ex);
                }
            }
           
            md.setRatings((Rating[]) values.toArray(new Rating[values.size()]));
        }
        // text
        {
            List texts = e.getChildren("text", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; (texts != null) && (i < texts.size()); i++) {
                try {
                    Element text = (Element) texts.get(i);
                    Time start = (text.getAttributeValue("start") == null)
                    ? null : new Time(text.getAttributeValue("start"));
                    Time end = (text.getAttributeValue("end") == null) ? null
                            : new Time(text.getAttributeValue(
                            "end"));
                    values.add(new Text(text.getAttributeValue("type"),
                            text.getTextTrim(), start, end));
                } catch (Exception ex) {
                    LOG.log(Level.WARNING, "Exception parsing text tag.", ex);
                }
            }
           
            md.setText((Text[]) values.toArray(new Text[values.size()]));
        }
        // thumbnails
        {
            List thumbnails = e.getChildren("thumbnail", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; (thumbnails != null) && (i < thumbnails.size());
            i++) {
                try {
                    Element thumb = (Element) thumbnails.get(i);
                    Time t = (thumb.getAttributeValue("time") == null) ? null
                            : new Time(thumb.getAttributeValue(
                            "time"));
                    Integer width = (thumb.getAttributeValue("width") == null)
                    ? null : new Integer(thumb.getAttributeValue("width"));
                    Integer height = (thumb.getAttributeValue("height") == null)
                    ? null : new Integer(thumb.getAttributeValue("height"));
                    values.add(new Thumbnail(
                            new URI(thumb.getAttributeValue("url")), width,
                            height, t));
                } catch (Exception ex) {
                    LOG.log(Level.WARNING, "Exception parsing thumbnail tag.",
                            ex);
                }
            }
           
            md.setThumbnail((Thumbnail[]) values.toArray(
                    new Thumbnail[values.size()]));
        }
        // title
        {
            Element title = e.getChild("title", getNS());
           
            if (title != null) {
                md.setTitle(title.getText());
                md.setTitleType(title.getAttributeValue("type"));
            }
        }
        // restrictions
        {
            List restrictions = e.getChildren("restriction", getNS());
            ArrayList values = new ArrayList();
           
            for (int i = 0; i < restrictions.size(); i++) {
                Element r = (Element) restrictions.get(i);
                Restriction.Type type = null;
               
                if (r.getAttributeValue("type").equalsIgnoreCase("uri")) {
                    type = Restriction.Type.URI;
                } else if (r.getAttributeValue("type").equalsIgnoreCase("country")) {
                    type = Restriction.Type.COUNTRY;
                }
               
                Restriction.Relationship relationship = null;
               
                if (r.getAttributeValue("relationship").equalsIgnoreCase("allow")) {
                    relationship = Restriction.Relationship.ALLOW;
                } else if (r.getAttributeValue("relationship").equalsIgnoreCase("deny")) {
                    relationship = Restriction.Relationship.DENY;
                }
               
                Restriction value = new Restriction(relationship, type,
                        r.getTextTrim());
                values.add(value);
            }
           
            md.setRestrictions((Restriction[]) values.toArray(
                    new Restriction[values.size()]));
        }
        // handle adult
        {
            Element adult = e.getChild("adult", getNS());
           
            if ((adult != null) && (md.getRatings().length == 0)) {
                Rating[] r = new Rating[1];
               
                if (adult.getTextTrim().equals("true")) {
                    r[0] = new Rating("urn:simple", "adult");
                } else {
                    r[0] = new Rating("urn:simple", "nonadult");
                }
               
                md.setRatings(r);
            }
        }
       
        return md;
    }
View Full Code Here

TOP

Related Classes of org.rometools.feed.module.mediarss.types.Metadata

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.