Author: tyrell
Date: Tue May 6 10:50:30 2008
New Revision: 16575
Log:
Fixing MASHUP-788
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Entry.java
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Feed.java
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/IEntry.java
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Entry.java
==============================================================================
---
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Entry.java
(original)
+++
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Entry.java
Tue May 6 10:50:30 2008
@@ -20,21 +20,36 @@
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndLink;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.module.mediarss.MediaEntryModuleImpl;
import com.sun.syndication.feed.module.mediarss.types.MediaContent;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.FeedException;
import org.apache.abdera.i18n.iri.IRISyntaxException;
import org.apache.axis2.AxisFault;
+import org.apache.xerces.parsers.DOMParser;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Function;
import org.wso2.mashup.MashupFault;
-
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.io.IOException;
+import java.io.StringReader;
/**
* <p/>
@@ -47,6 +62,8 @@
private SyndEntry entry;
+ private String type; // Stores the type of Feed this entry belongs to
+
/**
* Constructor the user will be using inside javaScript
*/
@@ -122,12 +139,12 @@
}
}
- if(retContent.compareTo("")==0){
+ if (retContent.compareTo("") == 0) {
// Let's check whether entry.description holds a payload
retContent = jsGet_description();
}
- return retContent;
+ return retContent;
}
public void jsSet_contributor(String contributor) {
@@ -307,12 +324,55 @@
/**
* @return the E4X XML of the contents in this AtomEntry object
*/
- public Scriptable jsGet_XML() {
+ public Scriptable jsGet_XML() throws MashupFault {
+
Context cx = Context.getCurrentContext();
- if (entry != null) {
- Object[] objects = { entry };
- return cx.newObject(this, "XML", objects);
+
+ //Creating a bogus feed
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setFeedType(this.getType());
+ feed.setTitle("placeHolderTitle");
+ feed.setDescription("placeHoldeDescription");
+ feed.setLink("http://place.holder.link");
+ List entries = feed.getEntries();
+ entries.add(entry);
+ feed.setEntries(entries);
+
+ SyndFeedOutput output = new SyndFeedOutput();
+ try {
+ String xmlRep = output.outputString(feed);
+
+
+ if (this.getType().contains("rss")) {
+ int start = xmlRep.indexOf("<item>") + "</item>".length();
+ int end = xmlRep.indexOf("</item>");
+ String entry = xmlRep.substring(start, end);
+
+ // Injecting the required namespace declarations
+ entry =
+ "<item
xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
xmlns:taxo=\"http://purl.org/rss/1.0/modules/taxonomy/\"
xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
xmlns:media=\"http://search.yahoo.com/mrss/\"
xmlns:dc=\"http://purl.org/dc/elements/1.1/\">" +
+ entry + "</item>";
+
+ Object[] objects = { entry };
+ return cx.newObject(this, "XML", objects);
+ } else if (this.getType().contains("atom")) {
+ // Extracting just the entry xml required
+ int start = xmlRep.indexOf("<entry>") + "</entry>".length();
+ int end = xmlRep.indexOf("</entry>");
+ String entry = xmlRep.substring(start, end);
+
+ // Injecting the required namespace declarations
+ entry =
+ "<entry xmlns=\"http://www.w3.org/2005/Atom\"
xmlns:taxo=\"http://purl.org/rss/1.0/modules/taxonomy/\"
xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\"
xmlns:dc=\"http://purl.org/dc/elements/1.1/\">" +
+ entry + "</entry>";
+
+ Object[] objects = { entry };
+ return cx.newObject(this, "XML", objects);
+ }
+ } catch (FeedException e) {
+ throw new MashupFault(e.getMessage());
}
+
return null;
}
@@ -327,4 +387,12 @@
SyndEntry getEntry() {
return entry;
}
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
}
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Feed.java
==============================================================================
---
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Feed.java
(original)
+++
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/Feed.java
Tue May 6 10:50:30 2008
@@ -264,6 +264,10 @@
currentEntry = (SyndEntry) tempEntryIterator.next();
Entry newEntry = (Entry) cx.newObject(feedObject, "Entry", new
Object[0]);
newEntry.setEntry(currentEntry);
+
+ // Storing the feed type of the entry so that it is self aware
+ newEntry.setType(feedObject.getFeed().getFeedType());
+
convertedEntries.add(newEntry);
}
@@ -303,6 +307,9 @@
if (arguments[0] instanceof Entry) {
Entry newEntry = (Entry) arguments[0];
+ // Storing the Feed type of this entry, so that it is self aware
+ newEntry.setType(feedObject.getFeed().getFeedType());
+
//getting the existing set of entries from the feed and adding the
passed entry
List currentEntries = feedObject.feed.getEntries();
currentEntries.add(newEntry.getEntry());
Modified:
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/IEntry.java
==============================================================================
---
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/IEntry.java
(original)
+++
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/IEntry.java
Tue May 6 10:50:30 2008
@@ -18,6 +18,7 @@
import org.apache.abdera.i18n.iri.IRISyntaxException;
import org.apache.axis2.AxisFault;
import org.mozilla.javascript.Scriptable;
+import org.wso2.mashup.MashupFault;
import java.util.Date;
@@ -69,7 +70,7 @@
/**
* @return the E4X XML of the contents in this AtomEntry object
*/
- Scriptable jsGet_XML();
+ Scriptable jsGet_XML() throws MashupFault;
String jsFunction_toString();
}
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev