1 17 package com.sun.syndication.io.impl; 18 19 import com.sun.syndication.feed.rss.*; 20 import com.sun.syndication.io.FeedException; 21 import org.jdom.Attribute; 22 import org.jdom.Element; 23 24 import java.util.List ; 25 26 27 34 35 public class RSS092Generator extends RSS091UserlandGenerator { 36 37 public RSS092Generator() { 38 this("rss_0.92","0.92"); 39 } 40 41 protected RSS092Generator(String type,String version) { 42 super(type,version); 43 } 44 45 protected void populateChannel(Channel channel,Element eChannel) { 46 super.populateChannel(channel,eChannel); 47 48 Cloud cloud = channel.getCloud(); 49 if (cloud!=null) { 50 eChannel.addContent(generateCloud(cloud)); 51 } 52 } 53 54 protected Element generateCloud(Cloud cloud) { 55 Element eCloud = new Element("cloud",getFeedNamespace()); 56 57 if (cloud.getDomain() != null) { 58 eCloud.setAttribute(new Attribute("domain", cloud.getDomain())); 59 } 60 61 if (cloud.getPort() != 0) { 62 eCloud.setAttribute(new Attribute("port", String.valueOf(cloud.getPort()))); 63 } 64 65 if (cloud.getRegisterProcedure() != null) { 66 eCloud.setAttribute(new Attribute("registerProcedure", cloud.getRegisterProcedure())); 67 } 68 69 if (cloud.getProtocol() != null) { 70 eCloud.setAttribute(new Attribute("protocol", cloud.getProtocol())); 71 } 72 return eCloud; 73 } 74 75 protected int getNumberOfEnclosures(List enclosures) { 77 return (enclosures.size()>0) ? 1 : 0; 78 } 79 80 protected void populateItem(Item item, Element eItem, int index) { 81 super.populateItem(item,eItem, index); 82 83 Source source =item.getSource(); 84 if (source != null) { 85 eItem.addContent(generateSourceElement(source)); 86 } 87 88 List enclosures = item.getEnclosures(); 89 for(int i = 0; i < getNumberOfEnclosures(enclosures); i++) { 90 eItem.addContent(generateEnclosure((Enclosure)enclosures.get(i))); 91 } 92 93 List categories = item.getCategories(); 94 for(int i = 0; i < categories.size(); i++) { 95 eItem.addContent(generateCategoryElement((Category)categories.get(i))); 96 } 97 } 98 99 protected Element generateSourceElement(Source source) { 100 Element sourceElement = new Element("source",getFeedNamespace()); 101 if (source.getUrl() != null) { 102 sourceElement.setAttribute(new Attribute("url", source.getUrl())); 103 } 104 sourceElement.addContent(source.getValue()); 105 return sourceElement; 106 } 107 108 protected Element generateEnclosure(Enclosure enclosure) { 109 Element enclosureElement = new Element("enclosure",getFeedNamespace()); 110 if (enclosure.getUrl() != null) { 111 enclosureElement.setAttribute("url", enclosure.getUrl()); 112 } 113 if (enclosure.getLength() != 0) { 114 enclosureElement.setAttribute("length", String.valueOf(enclosure.getLength())); 115 } 116 if (enclosure.getType() != null) { 117 enclosureElement.setAttribute("type", enclosure.getType()); 118 } 119 return enclosureElement; 120 } 121 122 protected Element generateCategoryElement(Category category) { 123 Element categoryElement = new Element("category",getFeedNamespace()); 124 if (category.getDomain() != null) { 125 categoryElement.setAttribute("domain", category.getDomain()); 126 } 127 categoryElement.addContent(category.getValue()); 128 return categoryElement; 129 } 130 131 132 protected void checkChannelConstraints(Element eChannel) throws FeedException { 133 checkNotNullAndLength(eChannel,"title", 0, -1); 134 checkNotNullAndLength(eChannel,"description", 0, -1); 135 checkNotNullAndLength(eChannel,"link", 0, -1); 136 } 137 138 protected void checkImageConstraints(Element eImage) throws FeedException { 139 checkNotNullAndLength(eImage,"title", 0, -1); 140 checkNotNullAndLength(eImage,"url", 0, -1); 141 } 142 143 protected void checkTextInputConstraints(Element eTextInput) throws FeedException { 144 checkNotNullAndLength(eTextInput,"title", 0, -1); 145 checkNotNullAndLength(eTextInput,"description", 0, -1); 146 checkNotNullAndLength(eTextInput,"name", 0, -1); 147 checkNotNullAndLength(eTextInput,"link", 0, -1); 148 } 149 150 protected void checkItemsConstraints(Element parent) throws FeedException { 151 } 152 153 protected void checkItemConstraints(Element eItem) throws FeedException { 154 } 155 156 } 157 | Popular Tags |