You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/03/01 13:15:45 UTC
[22/32] MARMOTTA-109: included org.rometools:rome:1.1.1-LMF and
org.rometools:rome-modules:1.5.1-LMF in source
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java
new file mode 100644
index 0000000..d83cb05
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java
@@ -0,0 +1,283 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Image;
+import com.sun.syndication.feed.rss.Item;
+import com.sun.syndication.io.FeedException;
+
+import org.jdom2.Attribute;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * Feed Generator for RSS 0.91
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+public class RSS091UserlandGenerator extends RSS090Generator {
+ private String _version;
+
+ public RSS091UserlandGenerator() {
+ this("rss_0.91U", "0.91");
+ }
+
+ protected RSS091UserlandGenerator(String type, String version) {
+ super(type);
+ _version = version;
+ }
+
+ protected Namespace getFeedNamespace() {
+ return Namespace.NO_NAMESPACE;
+ }
+
+ /**
+ * To be overriden by RSS 0.91 Netscape and RSS 0.94
+ */
+ protected boolean isHourFormat24() {
+ return true;
+ }
+
+ protected String getVersion() {
+ return _version;
+ }
+
+ protected void addChannel(Channel channel, Element parent)
+ throws FeedException {
+ super.addChannel(channel, parent);
+
+ Element eChannel = parent.getChild("channel", getFeedNamespace());
+
+ addImage(channel, eChannel);
+ addTextInput(channel, eChannel);
+ addItems(channel, eChannel);
+ }
+
+ protected void checkChannelConstraints(Element eChannel)
+ throws FeedException {
+ checkNotNullAndLength(eChannel, "title", 1, 100);
+ checkNotNullAndLength(eChannel, "description", 1, 500);
+ checkNotNullAndLength(eChannel, "link", 1, 500);
+ checkNotNullAndLength(eChannel, "language", 2, 5);
+
+ checkLength(eChannel, "rating", 20, 500);
+ checkLength(eChannel, "copyright", 1, 100);
+ checkLength(eChannel, "pubDate", 1, 100);
+ checkLength(eChannel, "lastBuildDate", 1, 100);
+ checkLength(eChannel, "docs", 1, 500);
+ checkLength(eChannel, "managingEditor", 1, 100);
+ checkLength(eChannel, "webMaster", 1, 100);
+
+ Element skipHours = eChannel.getChild("skipHours");
+
+ if (skipHours != null) {
+ List hours = skipHours.getChildren();
+
+ for (int i = 0; i < hours.size(); i++) {
+ Element hour = (Element) hours.get(i);
+ int value = Integer.parseInt(hour.getText().trim());
+
+ if (isHourFormat24()) {
+ if ((value < 1) || (value > 24)) {
+ throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24");
+ }
+ } else {
+ if ((value < 0) || (value > 23)) {
+ throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
+ }
+ }
+ }
+ }
+ }
+
+ protected void checkImageConstraints(Element eImage)
+ throws FeedException {
+ checkNotNullAndLength(eImage, "title", 1, 100);
+ checkNotNullAndLength(eImage, "url", 1, 500);
+
+ checkLength(eImage, "link", 1, 500);
+ checkLength(eImage, "width", 1, 3);
+ checkLength(eImage, "width", 1, 3);
+ checkLength(eImage, "description", 1, 100);
+ }
+
+ protected void checkItemConstraints(Element eItem)
+ throws FeedException {
+ checkNotNullAndLength(eItem, "title", 1, 100);
+ checkNotNullAndLength(eItem, "link", 1, 500);
+
+ checkLength(eItem, "description", 1, 500);
+ }
+
+ protected void checkTextInputConstraints(Element eTextInput)
+ throws FeedException {
+ checkNotNullAndLength(eTextInput, "title", 1, 100);
+ checkNotNullAndLength(eTextInput, "description", 1, 500);
+ checkNotNullAndLength(eTextInput, "name", 1, 20);
+ checkNotNullAndLength(eTextInput, "link", 1, 500);
+ }
+
+ protected Document createDocument(Element root) {
+ return new Document(root);
+ }
+
+ protected Element createRootElement(Channel channel) {
+ Element root = new Element("rss", getFeedNamespace());
+ Attribute version = new Attribute("version", getVersion());
+ root.setAttribute(version);
+ root.addNamespaceDeclaration(getContentNamespace());
+ generateModuleNamespaceDefs(root);
+
+ return root;
+ }
+
+ protected Element generateSkipDaysElement(List days) {
+ Element skipDaysElement = new Element("skipDays");
+
+ for (int i = 0; i < days.size(); i++) {
+ skipDaysElement.addContent(generateSimpleElement("day", days.get(i).toString()));
+ }
+
+ return skipDaysElement;
+ }
+
+ protected Element generateSkipHoursElement(List hours) {
+ Element skipHoursElement = new Element("skipHours", getFeedNamespace());
+
+ for (int i = 0; i < hours.size(); i++) {
+ skipHoursElement.addContent(generateSimpleElement("hour", hours.get(i).toString()));
+ }
+
+ return skipHoursElement;
+ }
+
+ protected void populateChannel(Channel channel, Element eChannel) {
+ super.populateChannel(channel, eChannel);
+
+ String language = channel.getLanguage();
+
+ if (language != null) {
+ eChannel.addContent(generateSimpleElement("language", language));
+ }
+
+ String rating = channel.getRating();
+
+ if (rating != null) {
+ eChannel.addContent(generateSimpleElement("rating", rating));
+ }
+
+ String copyright = channel.getCopyright();
+
+ if (copyright != null) {
+ eChannel.addContent(generateSimpleElement("copyright", copyright));
+ }
+
+ Date pubDate = channel.getPubDate();
+
+ if (pubDate != null) {
+ eChannel.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate)));
+ }
+
+ Date lastBuildDate = channel.getLastBuildDate();
+
+ if (lastBuildDate != null) {
+ eChannel.addContent(generateSimpleElement("lastBuildDate", DateParser.formatRFC822(lastBuildDate)));
+ }
+
+ String docs = channel.getDocs();
+
+ if (docs != null) {
+ eChannel.addContent(generateSimpleElement("docs", docs));
+ }
+
+ String managingEditor = channel.getManagingEditor();
+
+ if (managingEditor != null) {
+ eChannel.addContent(generateSimpleElement("managingEditor", managingEditor));
+ }
+
+ String webMaster = channel.getWebMaster();
+
+ if (webMaster != null) {
+ eChannel.addContent(generateSimpleElement("webMaster", webMaster));
+ }
+
+ List skipHours = channel.getSkipHours();
+
+ if ((skipHours != null) && (skipHours.size() > 0)) {
+ eChannel.addContent(generateSkipHoursElement(skipHours));
+ }
+
+ List skipDays = channel.getSkipDays();
+
+ if ((skipDays != null) && (skipDays.size() > 0)) {
+ eChannel.addContent(generateSkipDaysElement(skipDays));
+ }
+ }
+
+ protected void populateFeed(Channel channel, Element parent)
+ throws FeedException {
+ addChannel(channel, parent);
+ }
+
+ protected void populateImage(Image image, Element eImage) {
+ super.populateImage(image, eImage);
+
+ Integer width = image.getWidth();
+
+ if (width != null) {
+ eImage.addContent(generateSimpleElement("width", String.valueOf(width)));
+ }
+
+ Integer height = image.getHeight();
+
+ if (height != null) {
+ eImage.addContent(generateSimpleElement("height", String.valueOf(height)));
+ }
+
+ String description = image.getDescription();
+
+ if (description != null) {
+ eImage.addContent(generateSimpleElement("description", description));
+ }
+ }
+
+ protected void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item, eItem, index);
+
+ Description description = item.getDescription();
+
+ if (description != null) {
+ eItem.addContent(generateSimpleElement("description", description.getValue()));
+ }
+
+ if ((item.getModule(getContentNamespace().getURI()) == null) && (item.getContent() != null)) {
+ Element elem = new Element("encoded", getContentNamespace());
+ elem.addContent(item.getContent().getValue());
+ eItem.addContent(elem);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandParser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandParser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandParser.java
new file mode 100644
index 0000000..86a0157
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS091UserlandParser.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.WireFeed;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Content;
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Image;
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Attribute;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+import java.util.*;
+
+/**
+ */
+public class RSS091UserlandParser extends RSS090Parser {
+
+ public RSS091UserlandParser() {
+ this("rss_0.91U");
+ }
+
+ protected RSS091UserlandParser(String type) {
+ super(type, null);
+ }
+
+ public boolean isMyType(Document document) {
+ boolean ok;
+ Element rssRoot = document.getRootElement();
+ ok = rssRoot.getName().equals("rss");
+ if (ok) {
+ ok = false;
+ Attribute version = rssRoot.getAttribute("version");
+ if (version!=null) {
+ ok = version.getValue().equals(getRSSVersion());
+ }
+ }
+ return ok;
+ }
+
+ protected String getRSSVersion() {
+ return "0.91";
+ }
+
+ protected Namespace getRSSNamespace() {
+ return Namespace.getNamespace("");
+ }
+
+ /**
+ * To be overriden by RSS 0.91 Netscape and RSS 0.94
+ */
+ protected boolean isHourFormat24(Element rssRoot) {
+ return true;
+ }
+
+ /**
+ * Parses the root element of an RSS document into a Channel bean.
+ * <p/>
+ * It first invokes super.parseChannel and then parses and injects the following
+ * properties if present: language, pubDate, rating and copyright.
+ * <p/>
+ *
+ * @param rssRoot the root element of the RSS document to parse.
+ * @return the parsed Channel bean.
+ */
+ protected WireFeed parseChannel(Element rssRoot) {
+ Channel channel = (Channel) super.parseChannel(rssRoot);
+
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+
+ Element e = eChannel.getChild("language",getRSSNamespace());
+ if (e!=null) {
+ channel.setLanguage(e.getText());
+ }
+ e = eChannel.getChild("rating",getRSSNamespace());
+ if (e!=null) {
+ channel.setRating(e.getText());
+ }
+ e = eChannel.getChild("copyright",getRSSNamespace());
+ if (e!=null) {
+ channel.setCopyright(e.getText());
+ }
+ e = eChannel.getChild("pubDate",getRSSNamespace());
+ if (e!=null) {
+ channel.setPubDate(DateParser.parseDate(e.getText()));
+ }
+ e = eChannel.getChild("lastBuildDate",getRSSNamespace());
+ if (e!=null) {
+ channel.setLastBuildDate(DateParser.parseDate(e.getText()));
+ }
+ e = eChannel.getChild("docs",getRSSNamespace());
+ if (e!=null) {
+ channel.setDocs(e.getText());
+ }
+ e = eChannel.getChild("docs",getRSSNamespace());
+ if (e!=null) {
+ channel.setDocs(e.getText());
+ }
+ e = eChannel.getChild("managingEditor",getRSSNamespace());
+ if (e!=null) {
+ channel.setManagingEditor(e.getText());
+ }
+ e = eChannel.getChild("webMaster",getRSSNamespace());
+ if (e!=null) {
+ channel.setWebMaster(e.getText());
+ }
+ e = eChannel.getChild("skipHours");
+ if (e!=null) {
+ List skipHours = new ArrayList();
+ List eHours = e.getChildren("hour",getRSSNamespace());
+ for (int i=0;i<eHours.size();i++) {
+ Element eHour = (Element) eHours.get(i);
+ skipHours.add(new Integer(eHour.getText().trim()));
+ }
+ channel.setSkipHours(skipHours);
+ }
+
+ e = eChannel.getChild("skipDays");
+ if (e!=null) {
+ List skipDays = new ArrayList();
+ List eDays = e.getChildren("day",getRSSNamespace());
+ for (int i=0;i<eDays.size();i++) {
+ Element eDay = (Element) eDays.get(i);
+ skipDays.add(eDay.getText().trim());
+ }
+ channel.setSkipDays(skipDays);
+ }
+ return channel;
+ }
+
+ /**
+ * Parses the root element of an RSS document looking for image information.
+ * <p/>
+ * It first invokes super.parseImage and then parses and injects the following
+ * properties if present: url, link, width, height and description.
+ * <p/>
+ *
+ * @param rssRoot the root element of the RSS document to parse for image information.
+ * @return the parsed RSSImage bean.
+ */
+ protected Image parseImage(Element rssRoot) {
+ Image image = super.parseImage(rssRoot);
+ if (image!=null) {
+ Element eImage = getImage(rssRoot);
+ Element e = eImage.getChild("width",getRSSNamespace());
+ if (e!=null) {
+ Integer val = NumberParser.parseInt(e.getText());
+ if (val != null) {
+ image.setWidth(val.intValue());
+ }
+ }
+ e = eImage.getChild("height",getRSSNamespace());
+ if (e!=null) {
+ Integer val = NumberParser.parseInt(e.getText());
+ if (val != null) {
+ image.setHeight(val.intValue());
+ }
+ }
+ e = eImage.getChild("description",getRSSNamespace());
+ if (e!=null) {
+ image.setDescription(e.getText());
+ }
+ }
+ return image;
+ }
+
+
+ /**
+ * It looks for the 'item' elements under the 'channel' elemment.
+ */
+ protected List getItems(Element rssRoot) {
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+ return (eChannel!=null) ? eChannel.getChildren("item",getRSSNamespace()) : Collections.EMPTY_LIST;
+ }
+
+ /**
+ * It looks for the 'image' elements under the 'channel' elemment.
+ */
+ protected Element getImage(Element rssRoot) {
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+ return (eChannel!=null) ? eChannel.getChild("image",getRSSNamespace()) : null;
+ }
+
+ /**
+ * To be overriden by RSS 0.91 Netscape parser
+ */
+ protected String getTextInputLabel() {
+ return "textInput";
+ }
+
+ /**
+ * It looks for the 'textinput' elements under the 'channel' elemment.
+ */
+ protected Element getTextInput(Element rssRoot) {
+ String elementName = getTextInputLabel();
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+ return (eChannel!=null) ? eChannel.getChild(elementName,getRSSNamespace()) : null;
+ }
+
+ /**
+ * Parses an item element of an RSS document looking for item information.
+ * <p/>
+ * It first invokes super.parseItem and then parses and injects the description property if present.
+ * <p/>
+ *
+ * @param rssRoot the root element of the RSS document in case it's needed for context.
+ * @param eItem the item element to parse.
+ * @return the parsed RSSItem bean.
+ */
+ protected Item parseItem(Element rssRoot, Element eItem) {
+ Item item = super.parseItem(rssRoot,eItem);
+ Element e = eItem.getChild("description", getRSSNamespace());
+ if (e!=null) {
+ item.setDescription(parseItemDescription(rssRoot,e));
+ }
+ Element ce = eItem.getChild("encoded", getContentNamespace());
+ if (ce != null) {
+ Content content = new Content();
+ content.setType(Content.HTML);
+ content.setValue(ce.getText());
+ item.setContent(content);
+ }
+ return item;
+ }
+
+ protected Description parseItemDescription(Element rssRoot,Element eDesc) {
+ Description desc = new Description();
+ desc.setType("text/plain");
+ desc.setValue(eDesc.getText());
+ return desc;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Generator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Generator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Generator.java
new file mode 100644
index 0000000..12a03d5
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Generator.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.*;
+import com.sun.syndication.io.FeedException;
+import org.jdom2.Attribute;
+import org.jdom2.Element;
+
+import java.util.List;
+
+
+/**
+ * Feed Generator for RSS 0.92
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+
+public class RSS092Generator extends RSS091UserlandGenerator {
+
+ public RSS092Generator() {
+ this("rss_0.92","0.92");
+ }
+
+ protected RSS092Generator(String type,String version) {
+ super(type,version);
+ }
+
+ protected void populateChannel(Channel channel,Element eChannel) {
+ super.populateChannel(channel,eChannel);
+
+ Cloud cloud = channel.getCloud();
+ if (cloud!=null) {
+ eChannel.addContent(generateCloud(cloud));
+ }
+ }
+
+ protected Element generateCloud(Cloud cloud) {
+ Element eCloud = new Element("cloud",getFeedNamespace());
+
+ if (cloud.getDomain() != null) {
+ eCloud.setAttribute(new Attribute("domain", cloud.getDomain()));
+ }
+
+ if (cloud.getPort() != 0) {
+ eCloud.setAttribute(new Attribute("port", String.valueOf(cloud.getPort())));
+ }
+
+ if (cloud.getPath() != null) {
+ eCloud.setAttribute(new Attribute("path", cloud.getPath()));
+ }
+
+ if (cloud.getRegisterProcedure() != null) {
+ eCloud.setAttribute(new Attribute("registerProcedure", cloud.getRegisterProcedure()));
+ }
+
+ if (cloud.getProtocol() != null) {
+ eCloud.setAttribute(new Attribute("protocol", cloud.getProtocol()));
+ }
+ return eCloud;
+ }
+
+ // Another one to thanks DW for
+ protected int getNumberOfEnclosures(List enclosures) {
+ return (enclosures.size()>0) ? 1 : 0;
+ }
+
+ protected void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item,eItem, index);
+
+ Source source =item.getSource();
+ if (source != null) {
+ eItem.addContent(generateSourceElement(source));
+ }
+
+ List enclosures = item.getEnclosures();
+ for(int i = 0; i < getNumberOfEnclosures(enclosures); i++) {
+ eItem.addContent(generateEnclosure((Enclosure)enclosures.get(i)));
+ }
+
+ List categories = item.getCategories();
+ for(int i = 0; i < categories.size(); i++) {
+ eItem.addContent(generateCategoryElement((Category)categories.get(i)));
+ }
+ }
+
+ protected Element generateSourceElement(Source source) {
+ Element sourceElement = new Element("source",getFeedNamespace());
+ if (source.getUrl() != null) {
+ sourceElement.setAttribute(new Attribute("url", source.getUrl()));
+ }
+ sourceElement.addContent(source.getValue());
+ return sourceElement;
+ }
+
+ protected Element generateEnclosure(Enclosure enclosure) {
+ Element enclosureElement = new Element("enclosure",getFeedNamespace());
+ if (enclosure.getUrl() != null) {
+ enclosureElement.setAttribute("url", enclosure.getUrl());
+ }
+ if (enclosure.getLength() != 0) {
+ enclosureElement.setAttribute("length", String.valueOf(enclosure.getLength()));
+ }
+ if (enclosure.getType() != null) {
+ enclosureElement.setAttribute("type", enclosure.getType());
+ }
+ return enclosureElement;
+ }
+
+ protected Element generateCategoryElement(Category category) {
+ Element categoryElement = new Element("category",getFeedNamespace());
+ if (category.getDomain() != null) {
+ categoryElement.setAttribute("domain", category.getDomain());
+ }
+ categoryElement.addContent(category.getValue());
+ return categoryElement;
+ }
+
+
+ protected void checkChannelConstraints(Element eChannel) throws FeedException {
+ checkNotNullAndLength(eChannel,"title", 0, -1);
+ checkNotNullAndLength(eChannel,"description", 0, -1);
+ checkNotNullAndLength(eChannel,"link", 0, -1);
+ }
+
+ protected void checkImageConstraints(Element eImage) throws FeedException {
+ checkNotNullAndLength(eImage,"title", 0, -1);
+ checkNotNullAndLength(eImage,"url", 0, -1);
+ }
+
+ protected void checkTextInputConstraints(Element eTextInput) throws FeedException {
+ checkNotNullAndLength(eTextInput,"title", 0, -1);
+ checkNotNullAndLength(eTextInput,"description", 0, -1);
+ checkNotNullAndLength(eTextInput,"name", 0, -1);
+ checkNotNullAndLength(eTextInput,"link", 0, -1);
+ }
+
+ protected void checkItemsConstraints(Element parent) throws FeedException {
+ }
+
+ protected void checkItemConstraints(Element eItem) throws FeedException {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Parser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Parser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Parser.java
new file mode 100644
index 0000000..9eacee7
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS092Parser.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.WireFeed;
+import com.sun.syndication.feed.rss.Category;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Cloud;
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Enclosure;
+import com.sun.syndication.feed.rss.Item;
+import com.sun.syndication.feed.rss.Source;
+import org.jdom2.Element;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ */
+public class RSS092Parser extends RSS091UserlandParser {
+
+ public RSS092Parser() {
+ this("rss_0.92");
+ }
+
+ protected RSS092Parser(String type) {
+ super(type);
+ }
+
+ protected String getRSSVersion() {
+ return "0.92";
+ }
+
+ protected WireFeed parseChannel(Element rssRoot) {
+ Channel channel = (Channel) super.parseChannel(rssRoot);
+
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+ Element eCloud = eChannel.getChild("cloud",getRSSNamespace());
+ if (eCloud!=null) {
+ Cloud cloud = new Cloud();
+ String att = eCloud.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cloud.setDomain(att);
+ }
+ att = eCloud.getAttributeValue("port");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cloud.setPort(Integer.parseInt(att.trim()));
+ }
+ att = eCloud.getAttributeValue("path");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cloud.setPath(att);
+ }
+ att = eCloud.getAttributeValue("registerProcedure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cloud.setRegisterProcedure(att);
+ }
+ att = eCloud.getAttributeValue("protocol");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cloud.setProtocol(att);
+ }
+ channel.setCloud(cloud);
+ }
+ return channel;
+ }
+
+ protected Item parseItem(Element rssRoot,Element eItem) {
+ Item item = super.parseItem(rssRoot,eItem);
+
+ Element e = eItem.getChild("source",getRSSNamespace());
+ if (e!=null) {
+ Source source = new Source();
+ String url = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ source.setUrl(url);
+ source.setValue(e.getText());
+ item.setSource(source);
+ }
+
+ // 0.92 allows one enclosure occurrence, 0.93 multiple
+ // just saving to write some code.
+ List eEnclosures = eItem.getChildren("enclosure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (eEnclosures.size()>0) {
+ List enclosures = new ArrayList();
+ for (int i=0;i<eEnclosures.size();i++) {
+ e = (Element) eEnclosures.get(i);
+
+ Enclosure enclosure = new Enclosure();
+ String att = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ enclosure.setUrl(att);
+ }
+ att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ enclosure.setLength(NumberParser.parseLong(att,0L));
+
+ att = e.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ enclosure.setType(att);
+ }
+ enclosures.add(enclosure);
+ }
+ item.setEnclosures(enclosures);
+ }
+
+ List eCats = eItem.getChildren("category");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ item.setCategories(parseCategories(eCats));
+
+ return item;
+ }
+
+ protected List parseCategories(List eCats) {
+ List cats = null;
+ if (eCats.size()>0) {
+ cats = new ArrayList();
+ for (int i=0;i<eCats.size();i++) {
+ Category cat = new Category();
+ Element e = (Element) eCats.get(i);
+ String att = e.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ cat.setDomain(att);
+ }
+ cat.setValue(e.getText());
+ cats.add(cat);
+ }
+ }
+ return cats;
+ }
+
+ protected Description parseItemDescription(Element rssRoot,Element eDesc) {
+ Description desc = super.parseItemDescription(rssRoot,eDesc);
+ desc.setType("text/html");
+ return desc;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Generator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Generator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Generator.java
new file mode 100644
index 0000000..d0c5bee
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Generator.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Element;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * Feed Generator for RSS 0.93
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+public class RSS093Generator extends RSS092Generator {
+
+ public RSS093Generator() {
+ this("rss_0.93","0.93");
+ }
+
+ protected RSS093Generator(String feedType,String version) {
+ super(feedType,version);
+ }
+
+ protected void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item,eItem, index);
+
+ Date pubDate = item.getPubDate();
+ if (pubDate != null) {
+ eItem.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate)));
+ }
+
+ Date expirationDate = item.getExpirationDate();
+ if (expirationDate != null) {
+ eItem.addContent(generateSimpleElement("expirationDate", DateParser.formatRFC822(expirationDate)));
+ }
+ }
+
+ // Another one to thanks DW for
+ protected int getNumberOfEnclosures(List enclosures) {
+ return enclosures.size();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Parser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Parser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Parser.java
new file mode 100644
index 0000000..f5aaaee
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS093Parser.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Element;
+
+/**
+ */
+public class RSS093Parser extends RSS092Parser {
+
+ public RSS093Parser() {
+ this("rss_0.93");
+ }
+
+ protected RSS093Parser(String type) {
+ super(type);
+ }
+
+ protected String getRSSVersion() {
+ return "0.93";
+ }
+
+ protected Item parseItem(Element rssRoot,Element eItem) {
+ Item item = super.parseItem(rssRoot,eItem);
+ Element e = eItem.getChild("pubDate",getRSSNamespace());
+ if (e!=null) {
+ item.setPubDate(DateParser.parseDate(e.getText()));
+ }
+ e = eItem.getChild("expirationDate",getRSSNamespace());
+ if (e!=null) {
+ item.setExpirationDate(DateParser.parseDate(e.getText()));
+ }
+ e = eItem.getChild("description",getRSSNamespace());
+ if (e!=null) {
+ String type = e.getAttributeValue("type");
+ if (type!=null) {
+ item.getDescription().setType(type);
+ }
+ }
+ return item;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Generator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Generator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Generator.java
new file mode 100644
index 0000000..5009beb
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Generator.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Attribute;
+import org.jdom2.Element;
+
+/**
+ * Feed Generator for RSS 0.94
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+
+public class RSS094Generator extends RSS093Generator {
+
+ public RSS094Generator() {
+ this("rss_0.94","0.94");
+ }
+
+ protected RSS094Generator(String feedType,String version) {
+ super(feedType,version);
+ }
+
+ protected void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item,eItem, index);
+
+ Description description = item.getDescription();
+ if (description!=null && description.getType()!=null) {
+ Element eDescription = eItem.getChild("description",getFeedNamespace());
+ eDescription.setAttribute(new Attribute("type",description.getType()));
+ }
+ eItem.removeChild("expirationDate",getFeedNamespace());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Parser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Parser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Parser.java
new file mode 100644
index 0000000..61c5c86
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS094Parser.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.WireFeed;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Guid;
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Element;
+
+import java.util.List;
+
+/**
+ */
+public class RSS094Parser extends RSS093Parser {
+
+ public RSS094Parser() {
+ this("rss_0.94");
+ }
+
+ protected RSS094Parser(String type) {
+ super(type);
+ }
+
+ protected String getRSSVersion() {
+ return "0.94";
+ }
+
+ protected WireFeed parseChannel(Element rssRoot) {
+ Channel channel = (Channel) super.parseChannel(rssRoot);
+ Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
+
+ List eCats = eChannel.getChildren("category",getRSSNamespace());
+ channel.setCategories(parseCategories(eCats));
+
+ Element eTtl = eChannel.getChild("ttl",getRSSNamespace());
+ if (eTtl!=null && eTtl.getText() != null ) {
+ Integer ttlValue = null;
+ try{
+ ttlValue = new Integer(eTtl.getText());
+ } catch(NumberFormatException nfe ){
+ ; //let it go by
+ }
+ if (ttlValue != null) {
+ channel.setTtl(ttlValue.intValue());
+ }
+ }
+
+ return channel;
+ }
+
+ public Item parseItem(Element rssRoot,Element eItem) {
+ Item item = super.parseItem(rssRoot,eItem);
+ item.setExpirationDate(null);
+
+ Element e = eItem.getChild("author",getRSSNamespace());
+ if (e!=null) {
+ item.setAuthor(e.getText());
+ }
+
+ e = eItem.getChild("guid",getRSSNamespace());
+ if (e!=null) {
+ Guid guid = new Guid();
+ String att = e.getAttributeValue("isPermaLink");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att!=null) {
+ guid.setPermaLink(att.equalsIgnoreCase("true"));
+ }
+ guid.setValue(e.getText());
+ item.setGuid(guid);
+ }
+
+ e = eItem.getChild("comments",getRSSNamespace());
+ if (e!=null) {
+ item.setComments(e.getText());
+ }
+
+ return item;
+ }
+
+ protected Description parseItemDescription(Element rssRoot,Element eDesc) {
+ Description desc = super.parseItemDescription(rssRoot,eDesc);
+ String att = eDesc.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
+ if (att==null) {
+ att = "text/html";
+ }
+ desc.setType(att);
+ return desc;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Generator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Generator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Generator.java
new file mode 100644
index 0000000..9ffdc7d
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Generator.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Item;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.io.FeedException;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+import java.util.List;
+
+/**
+ * Feed Generator for RSS 1.0
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+
+public class RSS10Generator extends RSS090Generator {
+
+ private static final String RSS_URI = "http://purl.org/rss/1.0/";
+ private static final Namespace RSS_NS = Namespace.getNamespace(RSS_URI);
+
+ public RSS10Generator() {
+ super("rss_1.0");
+ }
+
+ protected RSS10Generator(String feedType) {
+ super(feedType);
+ }
+
+ protected Namespace getFeedNamespace() {
+ return RSS_NS;
+ }
+
+ protected void populateChannel(Channel channel,Element eChannel) {
+ super.populateChannel(channel,eChannel);
+ if (channel.getUri() != null) {
+ eChannel.setAttribute("about", channel.getUri(), getRDFNamespace());
+ }
+ List items = channel.getItems();
+ if (items.size()>0) {
+ Element eItems = new Element("items",getFeedNamespace());
+ Element eSeq = new Element("Seq",getRDFNamespace());
+ for (int i=0;i<items.size();i++) {
+ Item item = (Item) items.get(i);
+ Element eLi = new Element("li",getRDFNamespace());
+ String uri = item.getUri();
+ if (uri!=null) {
+ eLi.setAttribute("resource",uri,getRDFNamespace());
+ }
+ eSeq.addContent(eLi);
+ }
+ eItems.addContent(eSeq);
+ eChannel.addContent(eItems);
+ }
+ }
+
+ protected void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item,eItem, index);
+ String link = item.getLink();
+ String uri = item.getUri();
+
+ if (uri != null) {
+ eItem.setAttribute("about", uri, getRDFNamespace());
+ } else if (link != null) {
+ eItem.setAttribute("about", link, getRDFNamespace());
+ }
+
+ Description description = item.getDescription();
+ if (description!=null) {
+ eItem.addContent(generateSimpleElement("description", description.getValue()));
+ }
+ if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) {
+ Element elem = new Element("encoded", getContentNamespace());
+ elem.addContent(item.getContent().getValue());
+ eItem.addContent(elem);
+ }
+ }
+
+ protected void checkChannelConstraints(Element eChannel) throws FeedException {
+ checkNotNullAndLength(eChannel,"title", 0, -1);
+ checkNotNullAndLength(eChannel,"description", 0, -1);
+ checkNotNullAndLength(eChannel,"link", 0, -1);
+ }
+
+ protected void checkImageConstraints(Element eImage) throws FeedException {
+ checkNotNullAndLength(eImage,"title", 0, -1);
+ checkNotNullAndLength(eImage,"url", 0, -1);
+ checkNotNullAndLength(eImage,"link", 0, -1);
+ }
+
+ protected void checkTextInputConstraints(Element eTextInput) throws FeedException {
+ checkNotNullAndLength(eTextInput,"title", 0, -1);
+ checkNotNullAndLength(eTextInput,"description", 0, -1);
+ checkNotNullAndLength(eTextInput,"name", 0, -1);
+ checkNotNullAndLength(eTextInput,"link", 0, -1);
+ }
+
+ protected void checkItemsConstraints(Element parent) throws FeedException {
+ }
+
+ protected void checkItemConstraints(Element eItem) throws FeedException {
+ checkNotNullAndLength(eItem,"title", 0, -1);
+ checkNotNullAndLength(eItem,"link", 0, -1);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Parser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Parser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Parser.java
new file mode 100644
index 0000000..0547211
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS10Parser.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.WireFeed;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Content;
+import com.sun.syndication.feed.rss.Description;
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+import java.util.List;
+
+/**
+ */
+public class RSS10Parser extends RSS090Parser {
+
+ private static final String RSS_URI = "http://purl.org/rss/1.0/";
+ private static final Namespace RSS_NS = Namespace.getNamespace(RSS_URI);
+
+ public RSS10Parser() {
+ this("rss_1.0", RSS_NS);
+ }
+
+ protected RSS10Parser(String type, Namespace ns) {
+ super(type, ns);
+ }
+
+ /**
+ * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
+ * <p/>
+ * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
+ * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
+ *
+ * @param document document to check if it can be parsed with this parser implementation.
+ * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
+ */
+ public boolean isMyType(Document document) {
+ boolean ok = false;
+
+ Element rssRoot = document.getRootElement();
+ Namespace defaultNS = rssRoot.getNamespace();
+ List additionalNSs = rssRoot.getAdditionalNamespaces();
+
+ ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
+ if (ok) {
+ if (additionalNSs==null) {
+ ok = false;
+ }
+ else {
+ ok = false;
+ for (int i=0;!ok && i<additionalNSs.size();i++) {
+ ok = getRSSNamespace().equals(additionalNSs.get(i));
+ }
+ }
+ }
+ return ok;
+ }
+
+ /**
+ * Returns the namespace used by RSS elements in document of the RSS 1.0
+ * <P>
+ *
+ * @return returns "http://purl.org/rss/1.0/".
+ */
+ protected Namespace getRSSNamespace() {
+ return Namespace.getNamespace(RSS_URI);
+ }
+
+ /**
+ * Parses an item element of an RSS document looking for item information.
+ * <p/>
+ * It first invokes super.parseItem and then parses and injects the description property if present.
+ * <p/>
+ *
+ * @param rssRoot the root element of the RSS document in case it's needed for context.
+ * @param eItem the item element to parse.
+ * @return the parsed RSSItem bean.
+ */
+ protected Item parseItem(Element rssRoot,Element eItem) {
+ Item item = super.parseItem(rssRoot,eItem);
+ Element e = eItem.getChild("description", getRSSNamespace());
+ if (e!=null) {
+ item.setDescription(parseItemDescription(rssRoot,e));
+ }
+ Element ce = eItem.getChild("encoded", getContentNamespace());
+ if (ce != null) {
+ Content content = new Content();
+ content.setType(Content.HTML);
+ content.setValue(ce.getText());
+ item.setContent(content);
+ }
+
+ String uri = eItem.getAttributeValue("about", getRDFNamespace());
+ if (uri != null) {
+ item.setUri(uri);
+ }
+
+ return item;
+ }
+
+ protected WireFeed parseChannel(Element rssRoot) {
+ Channel channel = (Channel) super.parseChannel(rssRoot);
+
+ Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
+ String uri = eChannel.getAttributeValue("about", getRDFNamespace());
+ if (uri != null) {
+ channel.setUri(uri);
+ }
+
+ return channel;
+ }
+
+ protected Description parseItemDescription(Element rssRoot,Element eDesc) {
+ Description desc = new Description();
+ desc.setType("text/plain");
+ desc.setValue(eDesc.getText());
+ return desc;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Generator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Generator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Generator.java
new file mode 100644
index 0000000..14e23ab
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Generator.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Category;
+import com.sun.syndication.feed.rss.Channel;
+import com.sun.syndication.feed.rss.Guid;
+import com.sun.syndication.feed.rss.Item;
+import org.jdom2.Element;
+
+import java.util.List;
+
+
+/**
+ * Feed Generator for RSS 2.0
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+
+public class RSS20Generator extends RSS094Generator {
+
+ public RSS20Generator() {
+ this("rss_2.0","2.0");
+ }
+
+ protected RSS20Generator(String feedType,String version) {
+ super(feedType,version);
+ }
+
+ protected void populateChannel(Channel channel,Element eChannel) {
+ super.populateChannel(channel,eChannel);
+
+ String generator = channel.getGenerator();
+ if (generator != null) {
+ eChannel.addContent(generateSimpleElement("generator", generator));
+ }
+
+ int ttl = channel.getTtl();
+ if (ttl>-1) {
+ eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl)));
+ }
+
+ List categories = channel.getCategories();
+ for(int i = 0; i < categories.size(); i++) {
+ eChannel.addContent(generateCategoryElement((Category)categories.get(i)));
+ }
+
+ }
+
+ public void populateItem(Item item, Element eItem, int index) {
+ super.populateItem(item,eItem, index);
+
+ Element eDescription = eItem.getChild("description",getFeedNamespace());
+ if (eDescription != null) eDescription.removeAttribute("type");
+
+ String author = item.getAuthor();
+ if (author != null) {
+ eItem.addContent(generateSimpleElement("author", author));
+ }
+
+ String comments = item.getComments();
+ if (comments != null) {
+ eItem.addContent(generateSimpleElement("comments", comments));
+ }
+
+ Guid guid = item.getGuid();
+ if (guid != null) {
+ Element eGuid = generateSimpleElement("guid",guid.getValue());
+ if (!guid.isPermaLink()) {
+ eGuid.setAttribute("isPermaLink", "false");
+ }
+ eItem.addContent(eGuid);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Parser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Parser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Parser.java
new file mode 100644
index 0000000..e3e6e66
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20Parser.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.rss.Description;
+import org.jdom2.Attribute;
+import org.jdom2.Document;
+import org.jdom2.Element;
+
+/**
+ */
+public class RSS20Parser extends RSS094Parser {
+
+ public RSS20Parser() {
+ this("rss_2.0");
+ }
+
+ protected RSS20Parser(String type) {
+ super(type);
+ }
+
+ protected String getRSSVersion() {
+ return "2.0";
+ }
+
+ protected boolean isHourFormat24(Element rssRoot) {
+ return false;
+ }
+
+ protected Description parseItemDescription(Element rssRoot,Element eDesc) {
+ Description desc = super.parseItemDescription(rssRoot,eDesc);
+ desc.setType("text/html"); // change as per https://rome.dev.java.net/issues/show_bug.cgi?id=26
+ return desc;
+ }
+
+ public boolean isMyType(Document document) {
+ boolean ok;
+ Element rssRoot = document.getRootElement();
+ ok = rssRoot.getName().equals("rss");
+ if (ok) {
+ ok = false;
+ Attribute version = rssRoot.getAttribute("version");
+ if (version!=null) {
+ // At this point, as far ROME is concerned RSS 2.0, 2.00 and
+ // 2.0.X are all the same, so let's use startsWith for leniency.
+ ok = version.getValue().startsWith(getRSSVersion());
+ }
+ }
+ return ok;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20wNSParser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20wNSParser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20wNSParser.java
new file mode 100644
index 0000000..d981f0f
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/RSS20wNSParser.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+import com.sun.syndication.feed.WireFeed;
+
+
+/**
+ * To address issue with certain feeds (brought up by Charles Miller):
+ *
+ * "During the debacle that was the rollout of RSS2.0, this namespace was tried,
+ * and even appeared in Dave Winer's Scripting News feed for a while. It was
+ * then withdrawn, but the wonderful thing about standards is the moment you
+ * roll one out, even if it's marked as unfinished and subject to change,
+ * someone will end up stuck with it forever."
+ *
+ * Note that there is not counter part on the generator, we only generate the final RSS2
+ *
+ */
+public class RSS20wNSParser extends RSS20Parser {
+ private static String RSS20_URI = "http://backend.userland.com/rss2";
+
+ public RSS20wNSParser() {
+ this("rss_2.0wNS");
+ }
+
+ protected RSS20wNSParser(String type) {
+ super(type);
+ }
+
+ public boolean isMyType(Document document) {
+ Element rssRoot = document.getRootElement();
+ Namespace defaultNS = rssRoot.getNamespace();
+ boolean ok = defaultNS!=null && defaultNS.equals(getRSSNamespace());
+ if (ok) {
+ ok = super.isMyType(document);
+ }
+ return ok;
+ }
+
+ protected Namespace getRSSNamespace() {
+ return Namespace.getNamespace(RSS20_URI);
+ }
+
+ /**
+ * After we parse the feed we put "rss_2.0" in it (so converters and generators work)
+ * this parser is a phantom.
+ *
+ */
+ protected WireFeed parseChannel(Element rssRoot) {
+ WireFeed wFeed = super.parseChannel(rssRoot);
+ wFeed.setFeedType("rss_2.0");
+ return wFeed;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleGenerator.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleGenerator.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleGenerator.java
new file mode 100644
index 0000000..e432e1a
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleGenerator.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.module.Module;
+import com.sun.syndication.feed.module.SyModule;
+import com.sun.syndication.io.ModuleGenerator;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * Feed Generator for SY ModuleImpl
+ * <p/>
+ *
+ * @author Elaine Chien
+ *
+ */
+
+public class SyModuleGenerator implements ModuleGenerator {
+
+ private static final String SY_URI = "http://purl.org/rss/1.0/modules/syndication/";
+ private static final Namespace SY_NS = Namespace.getNamespace("sy", SY_URI);
+
+ private static final Set NAMESPACES;
+
+ static {
+ Set nss = new HashSet();
+ nss.add(SY_NS);
+ NAMESPACES = Collections.unmodifiableSet(nss);
+ }
+
+ public String getNamespaceUri() {
+ return SY_URI;
+ }
+
+ /**
+ * Returns a set with all the URIs (JDOM Namespace elements) this module generator uses.
+ * <p/>
+ * It is used by the the feed generators to add their namespace definition in
+ * the root element of the generated document (forward-missing of Java 5.0 Generics).
+ * <p/>
+ *
+ * @return a set with all the URIs (JDOM Namespace elements) this module generator uses.
+ */
+ public Set getNamespaces() {
+ return NAMESPACES;
+ }
+
+ public void generate(Module module, Element element) {
+
+ SyModule syModule = (SyModule)module;
+
+ if (syModule.getUpdatePeriod() != null) {
+ Element updatePeriodElement = new Element("updatePeriod", SY_NS);
+ updatePeriodElement.addContent(syModule.getUpdatePeriod());
+ element.addContent(updatePeriodElement);
+ }
+
+ Element updateFrequencyElement = new Element("updateFrequency", SY_NS);
+ updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency()));
+ element.addContent(updateFrequencyElement);
+
+ if (syModule.getUpdateBase() != null) {
+ Element updateBaseElement = new Element("updateBase", SY_NS);
+ updateBaseElement.addContent(DateParser.formatW3CDateTime(syModule.getUpdateBase()));
+ element.addContent(updateBaseElement);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f7a4e00f/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleParser.java
----------------------------------------------------------------------
diff --git a/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleParser.java b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleParser.java
new file mode 100644
index 0000000..ac1961a
--- /dev/null
+++ b/commons/sesame-tools-rio-rss/src/ext/java/com/sun/syndication/io/impl/SyModuleParser.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.sun.syndication.io.impl;
+
+import com.sun.syndication.feed.module.Module;
+import com.sun.syndication.feed.module.SyModule;
+import com.sun.syndication.feed.module.SyModuleImpl;
+import com.sun.syndication.io.ModuleParser;
+import org.jdom2.Element;
+import org.jdom2.Namespace;
+
+/**
+ */
+public class SyModuleParser implements ModuleParser {
+ public String getNamespaceUri() {
+ return SyModule.URI;
+ }
+
+ private Namespace getDCNamespace() {
+ return Namespace.getNamespace(SyModule.URI);
+ }
+
+ public Module parse(Element syndRoot) {
+ boolean foundSomething = false;
+ SyModule sm = new SyModuleImpl();
+
+ Element e = syndRoot.getChild("updatePeriod",getDCNamespace());
+ if (e!=null) {
+ foundSomething = true;
+ sm.setUpdatePeriod(e.getText());
+ }
+ e = syndRoot.getChild("updateFrequency",getDCNamespace());
+ if (e!=null) {
+ foundSomething = true;
+ sm.setUpdateFrequency(Integer.parseInt(e.getText().trim()));
+ }
+ e = syndRoot.getChild("updateBase",getDCNamespace());
+ if (e!=null) {
+ foundSomething = true;
+ sm.setUpdateBase(DateParser.parseDate(e.getText()));
+ }
+ return (foundSomething) ? sm : null;
+ }
+
+}