Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added experimental javascript terminal for rss feeds (not used yet anywhere yet, expect the worst) .. possibly to be used as content for iframes within monitoring pages not ready yet!

orbitere90282da1ced
diff --git a/htroot/js/rss2.js b/htroot/js/rss2.js
new file mode 100755
index 000000000..68387d648
--- /dev/null
+++ b/htroot/js/rss2.js
@@ -0,0 +1,167 @@
+// parser for rss2
+
+function RSS2Enclosure(encElement) {
+ if (encElement == null) {
+ this.url = null;
+ this.length = null;
+ this.type = null;
+ } else {
+ this.url = encElement.getAttribute("url");
+ this.length = encElement.getAttribute("length");
+ this.type = encElement.getAttribute("type");
+ }
+}
+
+function RSS2Guid(guidElement) {
+ if (guidElement == null) {
+ this.isPermaLink = null;
+ this.value = null;
+ } else {
+ this.isPermaLink = guidElement.getAttribute("isPermaLink");
+ this.value = guidElement.childNodes[0].nodeValue;
+ }
+}
+
+function RSS2Source(souElement) {
+ if (souElement == null) {
+ this.url = null;
+ this.value = null;
+ } else {
+ this.url = souElement.getAttribute("url");
+ this.value = souElement.childNodes[0].nodeValue;
+ }
+}
+
+function RSS2Item(itemxml) {
+ //required
+ this.title;
+ this.link;
+ this.description;
+
+ //optional vars
+ this.author;
+ this.comments;
+ this.pubDate;
+
+ //optional objects
+ this.category;
+ this.enclosure;
+ this.guid;
+ this.source;
+
+ var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
+ //var properties = new Array("title", "link");
+ var tmpElement = null;
+ for (var i=0; i<properties.length; i++) {
+ tmpElement = itemxml.getElementsByTagName(properties[i])[0];
+ if ((tmpElement != null) && (tmpElement.firstChild))
+ eval("this."+properties[i]+"=tmpElement.firstChild.nodeValue");
+ }
+
+ this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
+ this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
+ this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
+ this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
+}
+
+function RSS2Category(catElement) {
+ if (catElement == null) {
+ this.domain = null;
+ this.value = null;
+ } else {
+ this.domain = catElement.getAttribute("domain");
+ this.value = catElement.childNodes[0].nodeValue;
+ }
+}
+
+function RSS2Image(imgElement) {
+ if (imgElement == null) {
+ this.url = null;
+ this.link = null;
+ this.width = null;
+ this.height = null;
+ this.description = null;
+ } else {
+ imgAttribs = new Array("url","title","link","width","height","description");
+ for (var i=0; i<imgAttribs.length; i++)
+ if (imgElement.getAttribute(imgAttribs[i]) != null)
+ eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
+ }
+}
+
+function RSS2Channel(rssxml) {
+ //required
+ this.title;
+ this.link;
+ this.description;
+
+ //array of RSS2Item objects
+ this.items = new Array();
+
+ //optional vars
+ this.language;
+ this.copyright;
+ this.managingEditor;
+ this.webMaster;
+ this.pubDate;
+ this.lastBuildDate;
+ this.generator;
+ this.docs;
+ this.ttl;
+ this.rating;
+
+ //optional objects
+ this.category;
+ this.image;
+
+ var chanElement = rssxml.getElementsByTagName("channel")[0];
+ var itemElements = rssxml.getElementsByTagName("item");
+
+ for (var i=0; i<itemElements.length; i++) {
+ Item = new RSS2Item(itemElements[i]);
+ this.items.push(Item);
+ //chanElement.removeChild(itemElements[i]);
+ }
+
+ var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
+ var tmpElement = null;
+ for (var i=0; i<properties.length; i++) {
+ tmpElement = chanElement.getElementsByTagName(properties[i])[0];
+ if ((tmpElement!= null) && (tmpElement.firstChild))
+ eval("this."+properties[i]+"=tmpElement.firstChild.nodeValue");
+ }
+
+ this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
+ this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
+}
+
+
+// loader and display method for rss
+// this needs ajax.js and a method showRSS(RSS) to display a rss file
+var xhr;
+
+function getRSS(url){
+ xhr = createRequestObject();
+ xhr.open("GET",url,true);
+ xhr.setRequestHeader("Cache-Control", "no-cache");
+ xhr.setRequestHeader("Pragma", "no-cache");
+ xhr.onreadystatechange = processRSS;
+ xhr.send(null);
+}
+
+function processRSS() {
+ if (xhr.readyState == 4) {
+ if (xhr.status == 200) {
+ if (xhr.responseText != null) {
+ RSS = new RSS2Channel(xhr.responseXML);
+ showRSS(RSS);
+ } else {
+ alert("rss file not found.");
+ return false;
+ }
+ }
+ else
+ alert("Error code " + xhr.status + " received: " + xhr.statusText);
+ }
+}
+
diff --git a/htroot/rssTerminal.html b/htroot/rssTerminal.html
new file mode 100755
index 000000000..f3b1ac225
--- /dev/null
+++ b/htroot/rssTerminal.html
@@ -0,0 +1,151 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>rss terminal</title>
+<style type="text/css">
+
+div#container {
+ padding:6px;
+ background:#fff;
+ border:1px solid #000;
+ width: 600px;
+ height: 360px;
+ margin:0 auto;
+ text-align:left;
+}
+
+div#container p {
+ margin:0px 0;
+}
+
+div#scrollObject {
+ position: absolute;
+ overflow: hidden;
+ width: 600px;
+ height: 360px;
+}
+
+div#content {
+ position:absolute;
+ font:9px 'Lucida Console', 'Courier New', monospace;
+ top:0;
+ left:0;
+}
+</style>
+
+<script type="text/javascript" src="/js/ajax.js"></script>
+<script type="text/javascript" src="/js/rss2.js"></script>
+<script type="text/javascript">
+
+var lines = new Array();
+var maxlines = 360 / 9;
+var maxwidth = 600 / 5;
+var maxtime = 30000; // time that should be wasted until everything is scrolled
+var minwait = 50; // if this is too short, the CPU will eat all performance
+var maxwait = 500;
+var scroller = null;
+var idleping = null;
+var lastwait = 1000;
+var tab = "&nbsp;&nbsp;";
+
+function fillLines() {
+ for (var i = 0; i < maxlines; i++) {
+ addLine("");
+ }
+}
+
+function addLine(line) {
+ while (line.length > maxwidth) {
+ lines.push(line.substring(0, maxwidth));
+ line = tab + line.substring(maxwidth);
+ }
+ lines.push(line);
+ if (lines.length > maxlines) {
+ if (scroller != null) {
+ window.clearInterval(scroller);
+ scroller = null;
+ }
+ scroller=window.setInterval("scroll()", newwait());
+ }
+ show();
+}
+
+function show() {
+ var doc = document.getElementById("content");
+ doc.innerHTML = "";
+ for (var i = 0; i < maxlines; i++) {
+ doc.innerHTML += lines[i] + "<br />";
+ }
+}
+
+function newwait() {
+ if (lines.length > maxlines) {
+ var time = maxtime / (lines.length - maxlines);
+ if (time < minwait) time = minwait;
+ if (time > maxwait) time = maxwait;
+ } else {
+ time = maxwait;
+ }
+ if (time < lastwait) time = (time + maxlines * lastwait) / (maxlines + 1);
+ lastwait = time;
+ return time;
+}
+
+function scroll() {
+ if (scroller != null) {
+ window.clearInterval(scroller);
+ scroller = null;
+ }
+ if (lines.length > maxlines) {
+ var factor = (lines.length - maxlines) / maxlines / 10;
+ if (factor < 0) factor = 1;
+ if (factor > 3) factor = 3;
+ for (var i = 0; i < factor; i++) {
+ lines.shift();
+ }
+ show();
+ scroller=window.setInterval("scroll()", newwait());
+ }
+}
+
+function showRSS(RSS) {
+ //populate the items
+ for (var i=0; i<RSS.items.length; i++) {
+ if (RSS.items[i].title != null) addLine(RSS.items[i].title);
+ if (RSS.items[i].link != null) addLine(tab + RSS.items[i].link);
+ if (RSS.items[i].description != null) addLine(tab + RSS.items[i].description);
+ }
+ return true;
+}
+
+function idlepingInit() {
+ idleping = window.setInterval("idlepingExec()", 10000);
+}
+
+function idlepingExec() {
+ if (lines.length <= maxlines) {
+ // feed in some empty lines to make the list appear alive
+ addLine("");
+ }
+}
+
+</script>
+
+</head>
+ <body>
+ <div id="container">
+ <div id="scrollObject">
+ <div id="content"></div>
+ </div>
+ </div>
+ </body>
+
+<script type="text/javascript">
+fillLines();
+idlepingInit();
+getRSS("http://localhost:8080/yacysearch.rss?search=java&count=100");
+//getRSS("http://news.google.com/news?output=rss");
+</script>
+
+</html>