SlideShare a Scribd company logo
1 of 11
Download to read offline
For this project your task is to update the RSS Reader program you wrote for the previous
project so that it reads multiple RSS feeds and generates the same nicely formatted HTML page
of links for each feed, plus an HTML index page with links to the individual feed pages.
Your new program should ask the user for the name of an XML file containing a list of URLs for
RSS v2.0 feeds (see below for the format of this file) and for the name of an output file in which
to generate an HTML page with links to the pages for the individual RSS feeds (see below for an
example). It should then read the input XML file into an XMLTree object and then process the
list of RSS feeds from the XMLTree. For each RSS feed, the program should generate an HTML
page with a table of links to all the news items in the feed (just like in the previous project). The
program should also generate an HTML page with an index of links to the individual feed pages.
Format of the Input XML Document
The input XML document is pretty simple. This is the general structure:
1
2
3
4
5
6
...
The top-level tag, , has a required attribute, title, whose value is the title to be used in the index
page; nested inside the top-level tag are 1 or more tags with the following required attributes:
url, the URL of the RSS feed, name, the name to use for the link to the feed in the index page,
and file, the name of the HTML file in which to generate the feed's table of links to news items
(with the same format as the output in the previous project).
Here is an example of a valid XML input file.
Format of the HTML Output Index Page
The HTML index page should include the following information:
the title as the page title
a header with the page title inside
an unordered list where each item is the name of a feed linked to the feed URL
You can see an example of the index output here.
Method
Create a new Eclipse project by copying your RSSReader project and name the new project
RSSAggregator.
Open the src folder of this project and then open (default package). Rename the RSSReader.java
file to RSSAggregator.java. Open the RSSAggregator.java file in the editor.
Edit RSSAggregator.java to satisfy the problem requirements stated above. You should factor
out the code in your previous project that processed the RSS feed into the following separate
static method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Processes one XML RSS (version 2.0) feed from a given URL converting it
* into the corresponding HTML output file.
*
* @param url
* the URL of the RSS feed
* @param file
* the name of the HTML output file
* @param out
* the output stream to report progress or errors
* @updates out.content
* @requires out.is_open
* @ensures
* [reads RSS feed from url, saves HTML document with table of news items
* to file, appends to out.content any needed messages]
*
*/
private static void processFeed(String url, String file, SimpleWriter out) {...}
1
2
3
4
5
6
...
Solution
import components.simplereader.SimpleReader;
import components.simplereader.SimpleReader1L;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;
import components.xmltree.XMLTree;
import components.xmltree.XMLTree1;
public final class RSSAggregator {
/**
* Private constructor so this utility class cannot be instantiated.
*/
private RSSAggregator() {
}
/**
* Outputs the "opening" tags in the generated HTML file. These are the
* expected elements generated by this method:
*
* the channel tag title as the page
* title
* the page title inside a link to the link
*
*
* the channel description
*
*
*
* Date
* Source
* News
*
*
* @param channel
* the channel element XMLTree
* @param out
* the output stream
* @updates out.content
* @requires [the root of channel is a tag] and out.is_open
* @ensures out.content = #out.content * [the HTML "opening" tags]
*/
private static void outputHeader(XMLTree channel, SimpleWriter out) {
assert channel != null : "Violation of: channel is not null";
assert out != null : "Violation of: out is not null";
assert channel.isTag() && channel.label().equals("channel") : ""
+ "Violation of: the label root of channel is a tag";
assert out.isOpen() : "Violation of: out.is_open";
// Initial title as Empty Title, initial description as No description
String title = "Empty Title";
String description = "No description available";
String link;
// Retrieve the index of each tag
int indexTitle = getChildElement(channel, "title");
int indexDescription = getChildElement(channel, "description");
int indexLink = getChildElement(channel, "link");
// Check if title is empty
if (channel.child(indexTitle).numberOfChildren() > 0) {
title = channel.child(indexTitle).child(0).label();
}
// Check if description is empty
if (channel.child(indexDescription).numberOfChildren() > 0) {
description = channel.child(indexDescription).child(0).label();
}
link = channel.child(indexLink).child(0).label();
// Print opening
out.print(" " + " " + "t" + title + " "
+ " " + " " + "t " + "tt" + title + " " + "t " + "t
"
+ description + " "
+ " " + "t "
+ "ttDate " + "ttSource "
+ "ttNews " + "t ");
}
/**
* Outputs the "closing" tags in the generated HTML file. These are the
* expected elements generated by this method:
*
*
*
*
* @param out
* the output stream
* @updates out.contents
* @requires out.is_open
* @ensures out.content = #out.content * [the HTML "closing" tags]
*/
private static void outputFooter(SimpleWriter out) {
assert out != null : "Violation of: out is not null";
assert out.isOpen() : "Violation of: out.is_open";
// Print footer
out.println("t " + " " + "");
}
/**
* Finds the first occurrence of the given tag among the children of the
* given {@code XMLTree} and return its index; returns -1 if not found.
*
* @param xml
* the {@code XMLTree} to search
* @param tag
* the tag to look for
* @return the index of the first child of type tag of the {@code XMLTree}
* or -1 if not found
* @requires [the label of the root of xml is a tag]
* @ensures
*
*
* getChildElement =
* [the index of the first child of type tag of the {@code XMLTree} or
* -1 if not found]
*
*/
private static int getChildElement(XMLTree xml, String tag) {
assert xml != null : "Violation of: xml is not null";
assert tag != null : "Violation of: tag is not null";
assert xml.isTag() : "Violation of: the label root of xml is a tag";
int index = -1;
// Using while loop to search the index
int i = 0;
while (i < xml.numberOfChildren() && index == -1) {
if (xml.child(i).label().equals(tag)) {
// Retrieve the index
index = i;
}
i++;
}
return index;
}
/**
* Processes one news item and outputs one table row. The row contains three
* elements: the publication date, the source, and the title (or
* description) of the item.
*
* @param item
* the news item
* @param out
* the output stream
* @updates out.content
* @requires
*
*
* [the label of the root of item is an tag] and out.is_open
*
*
* @ensures
*
*
* out.content = #out.content *
* [an HTML table row with publication date, source, and title of news item]
*
*/
private static void processItem(XMLTree item, SimpleWriter out) {
assert item != null : "Violation of: item is not null";
assert out != null : "Violation of: out is not null";
assert item.isTag() && item.label().equals("item") : ""
+ "Violation of: the label root of item is an tag";
assert out.isOpen() : "Violation of: out.is_open";
String link = "";
String sourceLink = "";
String pubDate = "No date available";
String source = "No source available";
String title = "No title avaialble";
// Retrieve the index of each tag
int indexPubDate = getChildElement(item, "pubDate");
int indexSource = getChildElement(item, "source");
int indexTitle = getChildElement(item, "title");
int indexLink = getChildElement(item, "link");
// Check if item has pubdate
if (indexPubDate != -1) {
// Check if pubdate is empty
if (item.child(indexPubDate).numberOfChildren() != 0) {
pubDate = item.child(indexPubDate).child(0).label();
}
}
// Check if item has source
if (indexSource != -1) {
source = item.child(indexSource).child(0).label();
sourceLink = item.child(indexSource).attributeValue("url");
}
// Check if item has title
if (item.child(indexTitle).numberOfChildren() != 0) {
title = item.child(indexTitle).child(0).label();
}
// Check if item has link
if (indexLink != -1) {
// Check if link is empty
if (item.child(indexLink).numberOfChildren() != 0) {
link = item.child(indexLink).child(0).label();
// Check if sourceLink is empty
if (sourceLink.length() != 0) {
// Print out table elements
out.println(" " + "t" + pubDate + " "
+ "t" + "t"
+ source + " " + " " + "t "
+ "tt" + title + " "
+ "t " + "");
} else {
// Print out table elements
out.println(" " + "t" + pubDate + " "
+ "t" + source + " " + "t "
+ "tt" + title + " "
+ "t " + "");
}
} else {
// Check if sourceLink is empty
if (sourceLink.length() != 0) {
// Print out table elements
out.println(" " + "t" + pubDate + " "
+ "t" + "t"
+ source + " " + " " + "t " + title
+ "t " + "");
} else {
// Print out table elements
out.println(" " + "t" + pubDate + " "
+ "t" + source + " " + "t " + title
+ "t " + "");
}
}
}
}
/**
* Processes one XML RSS (version 2.0) feed from a given URL converting it
* into the corresponding HTML output file.
*
* @param url
* the URL of the RSS feed
* @param file
* the name of the HTML output file
* @param out
* the output stream to report progress or errors
* @updates out.content
* @requires out.is_open
* @ensures
*
*
* [reads RSS feed from url, saves HTML document with table of news items
* to file, appends to out.content any needed messages]
*
*/
private static void processFeed(String url, String file, SimpleWriter out) {
// Output it into a html file
SimpleWriter fileOut = new SimpleWriter1L(file);
XMLTree root = new XMLTree1(url);
if (root.label().equals("rss")) {
// Check if version is 2.0
if (root.hasAttribute("version")) {
if (root.attributeValue("version").equals("2.0")) {
XMLTree channel = root.child(0);
// Generate the formatted page
outputHeader(channel, fileOut);
for (int i = 0; i < channel.numberOfChildren(); i++) {
if (channel.child(i).label().equals("item")) {
processItem(channel.child(i), fileOut);
}
}
outputFooter(fileOut);
}
}
} else {
out.println("Wrong file");
}
}
/**
* Main method.
*
* @param args
* the command line arguments; unused here
*/
public static void main(String[] args) {
SimpleReader in = new SimpleReader1L();
SimpleWriter out = new SimpleWriter1L();
// Ask for the index xml
out.println("Please enter an index xml: ");
String url0 = in.nextLine();
// Output it into a html file
SimpleWriter fileOut = new SimpleWriter1L("index.html");
XMLTree index = new XMLTree1(url0);
// Use a for loop to generate html pages of it
for (int i = 0; i < index.numberOfChildren(); i++) {
String fileName = index.child(i).attributeValue("file");
String urlName = index.child(i).attributeValue("url");
processFeed(urlName, fileName, out);
}
// Get the title name
String title = index.attributeValue("title");
// Print the index page
fileOut.print(" " + " " + "t" + title
+ " " + " " + " " + " "
+ "t " + title + "t " + " " + "t ");
for (int j = 0; j < index.numberOfChildren(); j++) {
String name = index.child(j).attributeValue("name");
String fileName = index.child(j).attributeValue("file");
fileOut.print("t " + "t
 " + "tt" + name + " " + "t " + "t ");
}
fileOut.print("t " + " " + "");
in.close();
out.close();
fileOut.close();
}
}
feeds.xml

More Related Content

Similar to For this project your task is to update the RSS Reader program you w.pdf

Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181Mahmoud Samir Fayed
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabszekeLabs Technologies
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationRandy Connolly
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7Akash Tyagi
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 

Similar to For this project your task is to update the RSS Reader program you w.pdf (20)

backend
backendbackend
backend
 
Django wrapper
Django wrapperDjango wrapper
Django wrapper
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Jsoup tutorial
Jsoup tutorialJsoup tutorial
Jsoup tutorial
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Using Dojo
Using DojoUsing Dojo
Using Dojo
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
HTML5
HTML5HTML5
HTML5
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Html
HtmlHtml
Html
 

More from fathimahardwareelect

Which one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdfWhich one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdffathimahardwareelect
 
Which of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdfWhich of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdffathimahardwareelect
 
What is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdfWhat is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdffathimahardwareelect
 
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdfWhat mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdffathimahardwareelect
 
using the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdfusing the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdffathimahardwareelect
 
True or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdfTrue or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdffathimahardwareelect
 
True or False. If H is a subgroup of the group G then H is one of it.pdf
True or False.  If H is a subgroup of the group G then H is one of it.pdfTrue or False.  If H is a subgroup of the group G then H is one of it.pdf
True or False. If H is a subgroup of the group G then H is one of it.pdffathimahardwareelect
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
Immunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdfImmunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdffathimahardwareelect
 
Question 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdfQuestion 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdffathimahardwareelect
 
Question 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdfQuestion 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdffathimahardwareelect
 
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdfQuestion 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdffathimahardwareelect
 
List and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdfList and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdffathimahardwareelect
 
Please write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdfPlease write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdffathimahardwareelect
 
Please help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdfPlease help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdffathimahardwareelect
 
Negligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdfNegligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdffathimahardwareelect
 
Incuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdfIncuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdffathimahardwareelect
 
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdfIdentify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdffathimahardwareelect
 
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdfHow many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdffathimahardwareelect
 
How does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdfHow does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdffathimahardwareelect
 

More from fathimahardwareelect (20)

Which one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdfWhich one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdf
 
Which of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdfWhich of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdf
 
What is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdfWhat is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdf
 
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdfWhat mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
 
using the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdfusing the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdf
 
True or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdfTrue or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdf
 
True or False. If H is a subgroup of the group G then H is one of it.pdf
True or False.  If H is a subgroup of the group G then H is one of it.pdfTrue or False.  If H is a subgroup of the group G then H is one of it.pdf
True or False. If H is a subgroup of the group G then H is one of it.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
Immunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdfImmunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdf
 
Question 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdfQuestion 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdf
 
Question 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdfQuestion 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdf
 
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdfQuestion 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
 
List and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdfList and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdf
 
Please write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdfPlease write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdf
 
Please help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdfPlease help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdf
 
Negligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdfNegligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdf
 
Incuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdfIncuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdf
 
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdfIdentify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
 
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdfHow many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
 
How does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdfHow does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdf
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

For this project your task is to update the RSS Reader program you w.pdf

  • 1. For this project your task is to update the RSS Reader program you wrote for the previous project so that it reads multiple RSS feeds and generates the same nicely formatted HTML page of links for each feed, plus an HTML index page with links to the individual feed pages. Your new program should ask the user for the name of an XML file containing a list of URLs for RSS v2.0 feeds (see below for the format of this file) and for the name of an output file in which to generate an HTML page with links to the pages for the individual RSS feeds (see below for an example). It should then read the input XML file into an XMLTree object and then process the list of RSS feeds from the XMLTree. For each RSS feed, the program should generate an HTML page with a table of links to all the news items in the feed (just like in the previous project). The program should also generate an HTML page with an index of links to the individual feed pages. Format of the Input XML Document The input XML document is pretty simple. This is the general structure: 1 2 3 4 5 6 ... The top-level tag, , has a required attribute, title, whose value is the title to be used in the index page; nested inside the top-level tag are 1 or more tags with the following required attributes: url, the URL of the RSS feed, name, the name to use for the link to the feed in the index page, and file, the name of the HTML file in which to generate the feed's table of links to news items (with the same format as the output in the previous project). Here is an example of a valid XML input file. Format of the HTML Output Index Page The HTML index page should include the following information: the title as the page title a header with the page title inside an unordered list where each item is the name of a feed linked to the feed URL You can see an example of the index output here. Method Create a new Eclipse project by copying your RSSReader project and name the new project
  • 2. RSSAggregator. Open the src folder of this project and then open (default package). Rename the RSSReader.java file to RSSAggregator.java. Open the RSSAggregator.java file in the editor. Edit RSSAggregator.java to satisfy the problem requirements stated above. You should factor out the code in your previous project that processed the RSS feed into the following separate static method: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /** * Processes one XML RSS (version 2.0) feed from a given URL converting it * into the corresponding HTML output file. * * @param url * the URL of the RSS feed * @param file * the name of the HTML output file * @param out * the output stream to report progress or errors * @updates out.content * @requires out.is_open
  • 3. * @ensures * [reads RSS feed from url, saves HTML document with table of news items * to file, appends to out.content any needed messages] * */ private static void processFeed(String url, String file, SimpleWriter out) {...} 1 2 3 4 5 6 ... Solution import components.simplereader.SimpleReader; import components.simplereader.SimpleReader1L; import components.simplewriter.SimpleWriter; import components.simplewriter.SimpleWriter1L; import components.xmltree.XMLTree; import components.xmltree.XMLTree1; public final class RSSAggregator { /** * Private constructor so this utility class cannot be instantiated. */ private RSSAggregator() { } /** * Outputs the "opening" tags in the generated HTML file. These are the * expected elements generated by this method: * * the channel tag title as the page * title * the page title inside a link to the link
  • 4. * * * the channel description * * * * Date * Source * News * * * @param channel * the channel element XMLTree * @param out * the output stream * @updates out.content * @requires [the root of channel is a tag] and out.is_open * @ensures out.content = #out.content * [the HTML "opening" tags] */ private static void outputHeader(XMLTree channel, SimpleWriter out) { assert channel != null : "Violation of: channel is not null"; assert out != null : "Violation of: out is not null"; assert channel.isTag() && channel.label().equals("channel") : "" + "Violation of: the label root of channel is a tag"; assert out.isOpen() : "Violation of: out.is_open"; // Initial title as Empty Title, initial description as No description String title = "Empty Title"; String description = "No description available"; String link; // Retrieve the index of each tag int indexTitle = getChildElement(channel, "title"); int indexDescription = getChildElement(channel, "description"); int indexLink = getChildElement(channel, "link"); // Check if title is empty if (channel.child(indexTitle).numberOfChildren() > 0) {
  • 5. title = channel.child(indexTitle).child(0).label(); } // Check if description is empty if (channel.child(indexDescription).numberOfChildren() > 0) { description = channel.child(indexDescription).child(0).label(); } link = channel.child(indexLink).child(0).label(); // Print opening out.print(" " + " " + "t" + title + " " + " " + " " + "t " + "tt" + title + " " + "t " + "t " + description + " " + " " + "t " + "ttDate " + "ttSource " + "ttNews " + "t "); } /** * Outputs the "closing" tags in the generated HTML file. These are the * expected elements generated by this method: * * * * * @param out * the output stream * @updates out.contents * @requires out.is_open * @ensures out.content = #out.content * [the HTML "closing" tags] */ private static void outputFooter(SimpleWriter out) { assert out != null : "Violation of: out is not null"; assert out.isOpen() : "Violation of: out.is_open"; // Print footer out.println("t " + " " + ""); } /**
  • 6. * Finds the first occurrence of the given tag among the children of the * given {@code XMLTree} and return its index; returns -1 if not found. * * @param xml * the {@code XMLTree} to search * @param tag * the tag to look for * @return the index of the first child of type tag of the {@code XMLTree} * or -1 if not found * @requires [the label of the root of xml is a tag] * @ensures * * * getChildElement = * [the index of the first child of type tag of the {@code XMLTree} or * -1 if not found] * */ private static int getChildElement(XMLTree xml, String tag) { assert xml != null : "Violation of: xml is not null"; assert tag != null : "Violation of: tag is not null"; assert xml.isTag() : "Violation of: the label root of xml is a tag"; int index = -1; // Using while loop to search the index int i = 0; while (i < xml.numberOfChildren() && index == -1) { if (xml.child(i).label().equals(tag)) { // Retrieve the index index = i; } i++; } return index; } /** * Processes one news item and outputs one table row. The row contains three
  • 7. * elements: the publication date, the source, and the title (or * description) of the item. * * @param item * the news item * @param out * the output stream * @updates out.content * @requires * * * [the label of the root of item is an tag] and out.is_open * * * @ensures * * * out.content = #out.content * * [an HTML table row with publication date, source, and title of news item] * */ private static void processItem(XMLTree item, SimpleWriter out) { assert item != null : "Violation of: item is not null"; assert out != null : "Violation of: out is not null"; assert item.isTag() && item.label().equals("item") : "" + "Violation of: the label root of item is an tag"; assert out.isOpen() : "Violation of: out.is_open"; String link = ""; String sourceLink = ""; String pubDate = "No date available"; String source = "No source available"; String title = "No title avaialble"; // Retrieve the index of each tag int indexPubDate = getChildElement(item, "pubDate"); int indexSource = getChildElement(item, "source"); int indexTitle = getChildElement(item, "title");
  • 8. int indexLink = getChildElement(item, "link"); // Check if item has pubdate if (indexPubDate != -1) { // Check if pubdate is empty if (item.child(indexPubDate).numberOfChildren() != 0) { pubDate = item.child(indexPubDate).child(0).label(); } } // Check if item has source if (indexSource != -1) { source = item.child(indexSource).child(0).label(); sourceLink = item.child(indexSource).attributeValue("url"); } // Check if item has title if (item.child(indexTitle).numberOfChildren() != 0) { title = item.child(indexTitle).child(0).label(); } // Check if item has link if (indexLink != -1) { // Check if link is empty if (item.child(indexLink).numberOfChildren() != 0) { link = item.child(indexLink).child(0).label(); // Check if sourceLink is empty if (sourceLink.length() != 0) { // Print out table elements out.println(" " + "t" + pubDate + " " + "t" + "t" + source + " " + " " + "t " + "tt" + title + " " + "t " + ""); } else { // Print out table elements out.println(" " + "t" + pubDate + " " + "t" + source + " " + "t " + "tt" + title + " " + "t " + "");
  • 9. } } else { // Check if sourceLink is empty if (sourceLink.length() != 0) { // Print out table elements out.println(" " + "t" + pubDate + " " + "t" + "t" + source + " " + " " + "t " + title + "t " + ""); } else { // Print out table elements out.println(" " + "t" + pubDate + " " + "t" + source + " " + "t " + title + "t " + ""); } } } } /** * Processes one XML RSS (version 2.0) feed from a given URL converting it * into the corresponding HTML output file. * * @param url * the URL of the RSS feed * @param file * the name of the HTML output file * @param out * the output stream to report progress or errors * @updates out.content * @requires out.is_open * @ensures * * * [reads RSS feed from url, saves HTML document with table of news items * to file, appends to out.content any needed messages] *
  • 10. */ private static void processFeed(String url, String file, SimpleWriter out) { // Output it into a html file SimpleWriter fileOut = new SimpleWriter1L(file); XMLTree root = new XMLTree1(url); if (root.label().equals("rss")) { // Check if version is 2.0 if (root.hasAttribute("version")) { if (root.attributeValue("version").equals("2.0")) { XMLTree channel = root.child(0); // Generate the formatted page outputHeader(channel, fileOut); for (int i = 0; i < channel.numberOfChildren(); i++) { if (channel.child(i).label().equals("item")) { processItem(channel.child(i), fileOut); } } outputFooter(fileOut); } } } else { out.println("Wrong file"); } } /** * Main method. * * @param args * the command line arguments; unused here */ public static void main(String[] args) { SimpleReader in = new SimpleReader1L(); SimpleWriter out = new SimpleWriter1L(); // Ask for the index xml out.println("Please enter an index xml: "); String url0 = in.nextLine();
  • 11. // Output it into a html file SimpleWriter fileOut = new SimpleWriter1L("index.html"); XMLTree index = new XMLTree1(url0); // Use a for loop to generate html pages of it for (int i = 0; i < index.numberOfChildren(); i++) { String fileName = index.child(i).attributeValue("file"); String urlName = index.child(i).attributeValue("url"); processFeed(urlName, fileName, out); } // Get the title name String title = index.attributeValue("title"); // Print the index page fileOut.print(" " + " " + "t" + title + " " + " " + " " + " " + "t " + title + "t " + " " + "t "); for (int j = 0; j < index.numberOfChildren(); j++) { String name = index.child(j).attributeValue("name"); String fileName = index.child(j).attributeValue("file"); fileOut.print("t " + "t " + "tt" + name + " " + "t " + "t "); } fileOut.print("t " + " " + ""); in.close(); out.close(); fileOut.close(); } } feeds.xml