Q2: Use an XPage as RSS source

Thanks for all the help I got on this post. However I have some remaining questions how to build an RSS feed based on an XPage.

Here is the code so far:

/******************** START SAMPLE CODE ********************/
var con:javax.faces.context.ExternalContext = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
var writer = response.getWriter();

response.setHeader(“Cache-Control”, “no-cache”);
response.setContentType(“text/xml”);

writer.write(“<?xml version=\”1.0\” encoding=\”utf-8\”?>”);

var domDoc:DOMDocument = DOMUtil.createDocument();

var rootNode:DOMElement = domDoc.createElement(“rss”);
rootNode.setAttribute(“version”, “2.0”);

var channelnode:DOMElement = domDoc.createElement(“channel”);
rootNode.appendChild(channelnode);

var itemnode:DOMElement = domDoc.createElement(“title”);
itemnode.setStringValue(database.getTitle());
channelnode.appendChild(itemnode);

var itemnode:DOMElement = domDoc.createElement(“description”);
itemnode.setStringValue(“Broadcast your daily business”);
channelnode.appendChild(itemnode);

var itemnode:DOMElement = domDoc.createElement(“link”);
itemnode.setStringValue(“http://&#8221; + @Name(“[CN]”,session.getServerName()) + “.domain.com/” + @ReplaceSubstring(database.getFilePath(),”\\”,”/”));
channelnode.appendChild(itemnode);

var v:NotesView = database.getView(“$v-rss”);
var doc:NotesDocument = v.getFirstDocument();
var counter=0;

while ( doc != null && counter < 20){

var itemnode:DOMElement = domDoc.createElement(“item”);
channelnode.appendChild(itemnode);

var node:DOMElement = domDoc.createElement(“title”);
node.setStringValue(doc.getItemValueString(“Tx_MovieTitle”));
itemnode.appendChild(node);

var node:DOMElement = domDoc.createElement(“pubDate”);
var dt:NotesDateTime = doc.getCreated();
node.setStringValue(dt.getDateOnly());
itemnode.appendChild(node);

var node:DOMElement = domDoc.createElement(“description”);
var descr = “File: “+ doc.getItemValueString(“Tx_DspMovie”) + “. Description: ” + doc.getItemValueString(“Tx_MovieDescription”);
node.setStringValue(descr);
itemnode.appendChild(node);

var node:DOMElement = domDoc.createElement(“link”);
node.setStringValue(“./0/” + doc.getUniversalID() + “?OpenDocument”);
itemnode.appendChild(node);

var node:DOMElement = domDoc.createElement(“author”);
var person = @Name(“[Abbreviate]”,doc.getItemValueString(“Na_MovieAuthor”));
node.setStringValue(person);
itemnode.appendChild(node);

var node:DOMElement = domDoc.createElement(“guid”);
node.setStringValue(doc.getUniversalID());
itemnode.appendChild(node);

var counter = counter + 1;
var tmpdoc = v.getNextDocument(doc);

doc.recycle();
doc = tmpdoc;
}

domDoc.appendChild(rootNode);

writer.write( domDoc.getXMLString() );
writer.endDocument();
facesContext.responseComplete();
/******************** END SAMPLE CODE ********************/

 

Questions I have:

  • How to get the dates in RFC 822 format? Anyone know a variant for the following LotusScript:

‘Mike Golding’s code
Function RFC822DateFormat(aDate As NotesDateTime) As String
Dim vRFC822 As String
Dim vSign As String
Dim vZoneOffset As Integer
Dim vZoneOffsetH As String
Dim vZoneOffsetM As String
‘CREATE A GMT VERSION OF THE DATE
Dim bDate As New NotesDateTime(aDate.LSGMTTime)
‘FORMAT LOCAL DATE TO UTC
vRFC822 = Format$(aDate.LSLocalTime, “ddd, dd mmm yyyy hh:nn:ss”)
‘WORKOUT THE TIMEZONE OFFSET FROM GMT
vZoneOffset = bDate.TimeDifference(aDate)/3600
‘GET OFFSET POSITIVE OR NEGATIVE
If vZoneOffset > 0 Then vSign = “-” Else vSign = “+”
‘OFFSET HOURS
vZoneOffsetH = Right(“0” + Cstr(Int(Abs(vZoneOffset))),2)
‘OFFSET MINUTES
vZoneOffsetM = Right(“0″ + Cstr(Fraction(vZoneOffset)*60),2)
‘RETURN FULLY FORMATTED DATE
RFC822DateFormat = vRFC822 + ” ” + vSign + vZoneOffsetH + vZoneOffsetM
End Function

  • In case my RSS contains HTML how to include CDATA? The following code is valid but does not give the wanted result:

var node:DOMElement = domDoc.createElement(“description”);
var descr = “!&lt;[CDATA[File: ” + doc.getItemValueString(“Tx_DspMovie”) + “. Description: ” + doc.getItemValueString(“Tx_MovieDescription”) + “]]&gt;”;
node.setStringValue(descr);
itemnode.appendChild(node);

Advertisements

2 thoughts on “Q2: Use an XPage as RSS source

  1. Stephan H. Wissel 2011-January-25 / 5:37 pm

    Don’t use a DOM. Use SAX to create the document (code on my Blog: http://www.wissel.net/blog/d6plinks/SHWL-8B3G7U – unless you plan to cache the DOM and only rebuild it on change). It will take care of encoding when you add a text element. In your code example you have to add a TextNode or CDATA section see http://download.oracle.com/javase/1.5.0/docs/api/org/w3c/dom/CDATASection.html that also does encoding. java.text.simpleDateformat does the trick: http://www.dynamicobjects.com/d2r/archives/003057.html

  2. Angela Mcclory 2011-November-11 / 9:33 am

    Bin auf der Suche nach einem Kontakt Portal was aber übersichtlicher sein muß wie Ladies den dort hat es zwar Anzeigen noch und nöcher aber total unübersichtlich jemand ein guten Tipp danke

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s