n this assignment, we will be creating an HTML Checker program that will check the syntax of HTML tags.  You will write a class that stores the contents of an HTML page as a queue of HTMLTags. Your class will also be able to fix invalid HTML tags. Your HTMLManager will use stacks and queues to figure out whether the tags match and fix the mistakes it finds.  There will also be a number of Instructor-provided files to help with this assignment in order to make your work a little less :-)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Overview:

In this assignment, we will be creating an HTML Checker program that will check the syntax of HTML tags. 

You will write a class that stores the contents of an HTML page as a queue of HTMLTags. Your class will also be able to fix invalid HTML tags. Your HTMLManager will use stacks and queues to figure out whether the tags match and fix the mistakes it finds. 

There will also be a number of Instructor-provided files to help with this assignment in order to make your work a little less :-)

Topics:

queues, stacks

Background on HTML:

Web pages are written in a language called “Hypertext Markup Language”, or HTML. An HTML file consists of text surrounded by markings called tags. Tags give information to the text, such as formatting (bold, italic, etc) or layout (paragraph, table, list, etc). Some tags specify comments or information about the document (header, title, document type).

A tag consists of a named element between less-than < and greater-than > symbols. For example, the tag for making text bold uses the element b and is written as <b>.

Many tags apply to a range of text, in which case a pair of tags is used:

  • An opening tag (indicating the start of the range), which is written as: <tagname>
  • A closing tag (indicating the end of the range), which is written as: </tagname>

So to make some text bold on a page, one would surround the text with opening and closing b tags:

  • HTML Code: <b>like             this</b>
  • Displayed on screen: like this

Tags can be nested to combine effects. For example:

  • HTML Code: <b><i>like this</i></b>
  • Displayed on screen: like this

Some tags, such as the br tag (which inserts a line break) or the img (which inserts an image), do not cover a range of text and are considered to be “self-closing.” Self-closing tags do not need a closing tag; for a line break, only <br> is needed. Some web developers write self-closing tags with an optional / before the >, such as <br />.

Checking HTML:

One problem on the web is that many developers make mistakes in their HTML code. All tags that cover a range must eventually be closed, but some developers forget to close their tags. Also, whenever a tag is nested inside another tag, <b><i>like this</i></b>, the inner tag (i for italic, here) must be closed before the outer tag is closed. So the following tags are not valid HTML, because the </i> should appear first: <b><i>this is invalid</b></i>

This might sound like a lot if you are unfamiliar with HTML, but Don't stress! You will be provided with an algorithm for checking the validity of a series of HTML tags using stacks and queues. You will just need to follow the algorithm.

Instructions

Part 1: Get the starter files:

For this assignment, you are provided with a number of starter files: HTMLChecker.zip Download HTMLChecker.zip

  • The only file that you will edit for this assignment is HTMLManager.java
  • The only file that you will run is HTMLChecker.java
  • The tests/ folder contains a few test HTML files
  • The expected_output/ folder contains the expected "fixed" HTML for the associated test files - these are called and compared in the HTMLChecker.java file
  • The other files you will mostly just ignore as they are used from the HTMLChecker, except for HTMLTag.  The file HTMLTag.java you will want to study.

The HTMLTag.java file:

There is a provided file called HTMLTag.java which is the base type for your Queue (and the Stack that you will create in fixHTML), so it is fundamental that you know what methods it contains, though you will not edit it.

An HTMLTag object corresponds to an HTML tag such as <p> or </table>. An HTMLTag can either be an opening tag, a closing tag, or a self-closing tag. You don’t need to construct HTMLTag objects in your code, but you will process them. The reason we use HTMLTag objects instead of just storing the tags as strings is that the class provides extra functionality that makes processing HTMLTags easier.

In particular, it provides the following methods:

boolean isOpening()
Returns true if this HTML tag is an "opening" (starting) tag.
boolean isClosing()
Returns true if this HTML tag is an "closing" (closing) tag.
boolean isSelfClosing()
Returns true if this HTML tag is an "self-closing" tag.
Returns true if the given other tag matches (has the same tag
type as) this tag; e.g., <a> and </a>.
boolean matches(other)
Returns a new tag that matches this tag but has opposite type
(e.g. if this is <a>, then this method will return </a> and vice
versa)
HTMLTag getMatching()
Returns true if the given other tag equals this tag. The other
tag is equal if the internal element is the same as this tag's
element and has the same opening or closing state; e.g. <a>
and <a>.
boolean equals(other)
Returns a string representation of this HTML tag, such as
"</a>".
String toString()
Part 2: Write your HTMLManager.java file:
When developing your HTMLManager file follow the specification and algorithm below. You
will know you did it correctly when you can make the HTMLChecker program run correctly.
Additionally, here is a visual walk through of the fixHTML algorithm t.
Transcribed Image Text:boolean isOpening() Returns true if this HTML tag is an "opening" (starting) tag. boolean isClosing() Returns true if this HTML tag is an "closing" (closing) tag. boolean isSelfClosing() Returns true if this HTML tag is an "self-closing" tag. Returns true if the given other tag matches (has the same tag type as) this tag; e.g., <a> and </a>. boolean matches(other) Returns a new tag that matches this tag but has opposite type (e.g. if this is <a>, then this method will return </a> and vice versa) HTMLTag getMatching() Returns true if the given other tag equals this tag. The other tag is equal if the internal element is the same as this tag's element and has the same opening or closing state; e.g. <a> and <a>. boolean equals(other) Returns a string representation of this HTML tag, such as "</a>". String toString() Part 2: Write your HTMLManager.java file: When developing your HTMLManager file follow the specification and algorithm below. You will know you did it correctly when you can make the HTMLChecker program run correctly. Additionally, here is a visual walk through of the fixHTML algorithm t.
Part 3: Test your HTMLManager using HTMLChecker
Run the HTMLChecker and see if your code passes all the test cases. If it does not - mine
didn't on the first few tries ;-), I recommend using the debugger to
• set a breakpoint on the loop inside your HTMLManager's fixHTML()
• pull out your stack and queue variables from the debug panel
• step through your code over and over until you figure out when things go wrong
Here is an example of what your final output will look like:
=======
Processing tests/test1.html...
==-- ====
HTML: <b><i><br /></b></i>
Checking HTML for errors...
HTML after fix: <b><i><br /></i></b>
----> Result matches Expected Output!
Processing tests/test2.html...
=========:
HTML: <a><a><a></a>
Checking HTML for errors...
HTML after fix: <a><a><a></a></a></a>
----> Result matches Expected Output!
All tests passed!
What to Submit
• Your completed HTMLManager.java
• Please include at the end of this file your final output from HTMLChecker.java
Submission Requirements
You should do the following for _all_ assignments submitted for this course.
Program Comment
Transcribed Image Text:Part 3: Test your HTMLManager using HTMLChecker Run the HTMLChecker and see if your code passes all the test cases. If it does not - mine didn't on the first few tries ;-), I recommend using the debugger to • set a breakpoint on the loop inside your HTMLManager's fixHTML() • pull out your stack and queue variables from the debug panel • step through your code over and over until you figure out when things go wrong Here is an example of what your final output will look like: ======= Processing tests/test1.html... ==-- ==== HTML: <b><i><br /></b></i> Checking HTML for errors... HTML after fix: <b><i><br /></i></b> ----> Result matches Expected Output! Processing tests/test2.html... =========: HTML: <a><a><a></a> Checking HTML for errors... HTML after fix: <a><a><a></a></a></a> ----> Result matches Expected Output! All tests passed! What to Submit • Your completed HTMLManager.java • Please include at the end of this file your final output from HTMLChecker.java Submission Requirements You should do the following for _all_ assignments submitted for this course. Program Comment
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education