List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:com.rometools.modules.itunes.io.ITunesGenerator.java
License:Open Source License
@Override public void generate(final Module module, final Element element) { Element root = element;// w w w . j a va2 s . c o m while (root.getParent() != null && root.getParent() instanceof Element) { root = (Element) root.getParent(); } root.addNamespaceDeclaration(NAMESPACE); if (!(module instanceof AbstractITunesObject)) { return; } final AbstractITunesObject itunes = (AbstractITunesObject) module; if (itunes instanceof FeedInformationImpl) { // Do Channel Specific Stuff. final FeedInformationImpl info = (FeedInformationImpl) itunes; final Element owner = generateSimpleElement("owner", ""); final Element email = generateSimpleElement("email", info.getOwnerEmailAddress()); owner.addContent(email); final Element name = generateSimpleElement("name", info.getOwnerName()); owner.addContent(name); element.addContent(owner); if (info.getImage() != null) { final Element image = generateSimpleElement("image", ""); image.setAttribute("href", info.getImage().toExternalForm()); element.addContent(image); } final List<Category> categories = info.getCategories(); for (final Category cat : categories) { final Element category = generateSimpleElement("category", ""); category.setAttribute("text", cat.getName()); if (cat.getSubcategory() != null) { final Element subcat = generateSimpleElement("category", ""); subcat.setAttribute("text", cat.getSubcategory().getName()); category.addContent(subcat); } element.addContent(category); } } else if (itunes instanceof EntryInformationImpl) { final EntryInformationImpl info = (EntryInformationImpl) itunes; if (info.getDuration() != null) { element.addContent(generateSimpleElement("duration", info.getDuration().toString())); } } if (itunes.getAuthor() != null) { element.addContent(generateSimpleElement("author", itunes.getAuthor())); } if (itunes.getBlock()) { element.addContent(generateSimpleElement("block", "")); } if (itunes.getExplicit()) { element.addContent(generateSimpleElement("explicit", "yes")); } else { element.addContent(generateSimpleElement("explicit", "no")); } if (itunes.getKeywords() != null) { final 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(generateSimpleElement("keywords", sb.toString())); } if (itunes.getSubtitle() != null) { element.addContent(generateSimpleElement("subtitle", itunes.getSubtitle())); } if (itunes.getSummary() != null) { element.addContent(generateSimpleElement("summary", itunes.getSummary())); } }
From source file:com.rometools.modules.itunes.io.ITunesGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, NAMESPACE); element.addContent(value); return element; }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateContent(final MediaContent c, final Element e) { final Element mc = new Element("content", NS); addNotNullAttribute(mc, "medium", c.getMedium()); addNotNullAttribute(mc, "channels", c.getAudioChannels()); addNotNullAttribute(mc, "bitrate", c.getBitrate()); addNotNullAttribute(mc, "duration", c.getDuration()); addNotNullAttribute(mc, "expression", c.getExpression()); addNotNullAttribute(mc, "fileSize", c.getFileSize()); addNotNullAttribute(mc, "framerate", c.getFramerate()); addNotNullAttribute(mc, "height", c.getHeight()); addNotNullAttribute(mc, "lang", c.getLanguage()); addNotNullAttribute(mc, "samplingrate", c.getSamplingrate()); addNotNullAttribute(mc, "type", c.getType()); addNotNullAttribute(mc, "width", c.getWidth()); if (c.isDefaultContent()) { addNotNullAttribute(mc, "isDefault", "true"); }//from w ww. j a v a 2 s .c o m if (c.getReference() instanceof UrlReference) { addNotNullAttribute(mc, "url", c.getReference()); generatePlayer(c.getPlayer(), mc); } else { generatePlayer(c.getPlayer(), mc); } generateMetadata(c.getMetadata(), mc); e.addContent(mc); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateGroup(final MediaGroup g, final Element e) { final Element t = new Element("group", NS); final MediaContent[] c = g.getContents(); for (final MediaContent element : c) { generateContent(element, t);//www . j a v a 2 s .c o m } generateMetadata(g.getMetadata(), t); e.addContent(t); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generateMetadata(final Metadata m, final Element e) { if (m == null) { return;//from ww w . j a va 2 s .c o m } final Category[] cats = m.getCategories(); for (final Category cat : cats) { final Element c = generateSimpleElement("category", cat.getValue()); addNotNullAttribute(c, "scheme", cat.getScheme()); addNotNullAttribute(c, "label", cat.getLabel()); e.addContent(c); } final Element copyright = addNotNullElement(e, "copyright", m.getCopyright()); addNotNullAttribute(copyright, "url", m.getCopyrightUrl()); final Credit[] creds = m.getCredits(); for (final Credit cred : creds) { final Element c = generateSimpleElement("credit", cred.getName()); addNotNullAttribute(c, "role", cred.getRole()); addNotNullAttribute(c, "scheme", cred.getScheme()); e.addContent(c); } final Element desc = addNotNullElement(e, "description", m.getDescription()); addNotNullAttribute(desc, "type", m.getDescriptionType()); if (m.getHash() != null) { final Element hash = addNotNullElement(e, "hash", m.getHash().getValue()); addNotNullAttribute(hash, "algo", m.getHash().getAlgorithm()); } final String[] keywords = m.getKeywords(); if (keywords.length > 0) { String keyword = keywords[0]; for (int i = 1; i < keywords.length; i++) { keyword += ", " + keywords[i]; } addNotNullElement(e, "keywords", keyword); } final Rating[] rats = m.getRatings(); for (final Rating rat2 : rats) { final Element rat = addNotNullElement(e, "rating", rat2.getValue()); addNotNullAttribute(rat, "scheme", rat2.getScheme()); if (rat2.equals(Rating.ADULT)) { addNotNullElement(e, "adult", "true"); } else if (rat2.equals(Rating.NONADULT)) { addNotNullElement(e, "adult", "false"); } } final Text[] text = m.getText(); for (final Text element : text) { final Element t = addNotNullElement(e, "text", element.getValue()); addNotNullAttribute(t, "type", element.getType()); addNotNullAttribute(t, "start", element.getStart()); addNotNullAttribute(t, "end", element.getEnd()); } final Thumbnail[] thumbs = m.getThumbnail(); for (final Thumbnail thumb : thumbs) { final Element t = new Element("thumbnail", NS); addNotNullAttribute(t, "url", thumb.getUrl()); addNotNullAttribute(t, "width", thumb.getWidth()); addNotNullAttribute(t, "height", thumb.getHeight()); addNotNullAttribute(t, "time", thumb.getTime()); e.addContent(t); } final Element title = addNotNullElement(e, "title", m.getTitle()); addNotNullAttribute(title, "type", m.getTitleType()); final Restriction[] r = m.getRestrictions(); for (final Restriction element : r) { final Element res = addNotNullElement(e, "restriction", element.getValue()); addNotNullAttribute(res, "type", element.getType()); addNotNullAttribute(res, "relationship", element.getRelationship()); } }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
public void generatePlayer(final PlayerReference p, final Element e) { if (p == null) { return;/*from w w w.j a v a2 s. c o m*/ } final Element t = new Element("player", NS); addNotNullAttribute(t, "url", p.getUrl()); addNotNullAttribute(t, "width", p.getWidth()); addNotNullAttribute(t, "height", p.getHeight()); e.addContent(t); }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
protected Element addNotNullElement(final Element target, final String name, final Object value) { if (value == null) { return null; } else {/* w w w. ja va 2 s . c o m*/ final Element e = generateSimpleElement(name, value.toString()); target.addContent(e); return e; } }
From source file:com.rometools.modules.mediarss.io.MediaModuleGenerator.java
License:Open Source License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, NS); element.addContent(value); return element; }
From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleGenerator.java
License:Apache License
@Override public void generate(final Module module, final Element element) { final OpenSearchModule osm = (OpenSearchModule) module; if (osm.getItemsPerPage() > -1) { element.addContent(generateSimpleElement("itemsPerPage", Integer.toString(osm.getItemsPerPage()))); }/*from ww w .ja v a 2 s .c om*/ if (osm.getTotalResults() > -1) { element.addContent(generateSimpleElement("totalResults", Integer.toString(osm.getTotalResults()))); } final int startIndex = osm.getStartIndex() > 0 ? osm.getStartIndex() : 1; element.addContent(generateSimpleElement("startIndex", Integer.toString(startIndex))); if (osm.getQueries() != null) { final List<OSQuery> queries = osm.getQueries(); for (final OSQuery query : queries) { if (query != null) { element.addContent(generateQueryElement(query)); } } } if (osm.getLink() != null) { element.addContent(generateLinkElement(osm.getLink())); } }
From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleGenerator.java
License:Apache License
protected Element generateSimpleElement(final String name, final String value) { final Element element = new Element(name, OS_NS); element.addContent(value); return element; }