![]() |
![]() Spring Semester 2003 |
Suppose there's CompanyA and CompanyB.
CompanyA is essentially a Library: it receives and stores books.
CompanyB is in the process of selling books, second-hand.
We now investigate the companies one by one.
CompanyA allows its suppliers to enter new books on-line.
So we start with a portion of a file: interface.html
This is the entry point located at<html> <head> <title>CompanyA Public Library: Add Books Interface</title> <style> <!-- body { font-family: Arial } h1 { color: #000080 } --> </style> </head> <body link="#FFFF00" vlink="#FFFF00" alink="#FFFF00"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="15%" bgcolor="#000080" valign="top" align="center"> </td> <td width="*" valign="top" align="center"> <h1 align="center"> The CompanyA Public Library </h1> <h3 align="center"><i>- Add Books -</i></h3> <form method="POST" action="/cgi-bin/CompanyA/addBook.pl"> <p> <input type="submit" value="Add This Book" name="AddBook"> <input type="reset" value="Reset Form" name="reset"> <input type="button" value="Cancel" name="cancel"> </p> </form> </td> </tr> </table> </body> </html>
Let's add all there is to it and finish it./u/username/apache/apache_1.3.26/htdocs/interface.html
You can see it here. It calls an<html> <head> <title>CompanyA Public Library: Add Books Interface</title> <style> <!-- body { font-family: Arial } h1 { color: #000080 } --> </style> </head> <body link="#FFFF00" vlink="#FFFF00" alink="#FFFF00"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="15%" bgcolor="#000080" valign="top" align="center"> <b><i><font color="#FFFFFF" size="4">Options</font></i></b> <p><b><font color="#FFFFFF"><a href="mainMenu.html">Main Menu</a></font></b></p> <p><b><font color="#FFFFFF"><a href="/cgi-bin/CompanyA/catalog.pl">Catalog</a></font></b></p> <p><b><i><font color="#FFFF00">Add Books</font></i></b></p> <p><b><font color="#FFFFFF"><a href="logout.html">Log Out</a></font></b></p> </td> <td width="*" valign="top" align="center"> <h1 align="center"> The CompanyA Public Library </h1> <h3 align="center"><i>- Add Books -</i></h3> <form method="POST" action="/cgi-bin/CompanyA/addBook.pl"> <table border="0" cellpadding="5" width="100%"> <tr> <td width="100%" valign="top" align="center" colspan="2"> Title <input type="text" name="title" size="20"> <hr width="85%" /> </td> </tr><tr> <td width="50%" valign="top" align="right"> Author <input type="text" name="author" size="20"> </td> <td width="50%" valign="top" align="left"> Subject <select size="1" name="subject"> <option>Fiction</option> <option>Biography</option> <option>Science</option> <option>Industry</option> <option>Computers</option> </select> </td> </tr><tr> <td width="50%" valign="top" align="right"> Publisher <input type="text" name="publisher" size="20"> </td><td width="50%" valign="top" align="left"> ISBN <input type="text" name="isbn" size="20"> </td> </tr><tr> <td width="50%" valign="top" align="right"> Price <input type="text" name="price" size="20"> </td><td width="50%" valign="top" align="left"> Pages <input type="text" name="numPages" size="20"> </td> </tr><tr> <td width="100%" valign="top" align="center" colspan="2"> Description <textarea rows="3" name="description" cols="45"></textarea> </td> </tr> </table> <p> <input type="submit" value="Add This Book" name="AddBook"> <input type="reset" value="Reset Form" name="reset"> <input type="button" value="Cancel" name="cancel"> </p> </form> </td> </tr> </table> </body> </html>
addBook.pl
Perl script, so we better provide it, quickly.
This was very easy. Let's now store the results in a file.#!/usr/bin/perl use CGI; $query = new CGI; print $query->header, $query->start_html, "Hello, how are you?<p>"; $title = $query->param('title'); $author = $query->param('author') ; $subject = $query->param('subject'); $publisher = $query->param('publisher'); $isbn = $query->param('isbn'); $price = $query->param('price'); $pages = $query->param('pages'); $description = $query->param('description'); print qq{ You seem to be entering the following book: <dl> <dt>Title</dt> <dd> $title<p></dd> <dt>Author</dt> <dd> $author<p></dd> <dt>Subject</dt> <dd> $subject<p></dd> <dt>Publisher</dt> <dd> $publisher<p></dd> <dt>ISBN</dt> <dd> $isbn<p></dd> <dt>Price</dt> <dd> $price<p></dd> <dt>Pages</dt> <dd> $pages<p></dd> <dt>Description</dt> <dd> $description <p></dd> </dl> }; print $query->end_html;
Let's decide on these things first:
The format will be very simple. Here's an example:/u/username/CompanyA/data/dataFile.txt
Let's assume now (for the purpose of this exercise) that colon (title:author:subject:publisher:isbn:price:numPages:description
:
) is a character that
we own exclusively. We have bought this character and nobody can use it, except us. So we use it, as we
are now guaranteed to be the only ones to do so, as a delimiter. Total fabrication, but let's agree to it. Here's an example of a real book:
The ISBN will be the key.
- Title
- The Armchair Universe - An Exploration of Computer Worlds
- Author
- A. K. Dewdney
- Subject
- Science
- Publisher
- W. H. Freeman and Company, New York
- ISBN
- 0-7167-1939-8
- Price
- 19.90
- Number of Pages
- 330
- Description
- This is the first collection of A.K.Dewdney's popular "Computer Recreations" columns, drawn from Scientific American magazine between 1984 and 1987. Inspired by Martin Gardner's classic "Mathematical Games" column, which entertained millions of readers for more than 30 years, "Computer Recreations" has quickly become one of the most widely read and anticipated columns in Scientific American. The computer recreations described here range from purely entertaining brainteasers to more practical computer applications of scientific thought. And with Dewdney's lucid programming directions to follow, you can actually sit at your computer and try your hand at them all. Available in paperback and hardcover. Cover image shows Julia set bounding three basins of attraction on a Riemann sphere.
Which brings us to the last question.
The real model behind this file is a table in a RDBMS like MySQL.
By the way, you know (as I hope you remember) that readParse
taught us how we can make characters our own, anyway, so the story about needing
a guarantee for colon is a non-issue, really.
So let's get started.
Let's add two books, then use this script to see them. Here's the second book:#!/usr/bin/perl use CGI; $query = new CGI; print $query->header, $query->start_html, "Hello, and how are you doing? <p> "; $title = $query->param('title'); $author = $query->param('author') ; $subject = $query->param('subject'); $publisher = $query->param('publisher'); $isbn = $query->param('isbn'); $price = $query->param('price'); $numPages = $query->param('numPages'); $description = $query->param('description'); print qq{ You seem to be entering the following book: <dl> <dt>Title</dt> <dd> $title<p></dd> <dt>Author</dt> <dd> $author<p></dd> <dt>Subject</dt> <dd> $subject<p></dd> <dt>Publisher</dt> <dd> $publisher<p></dd> <dt>ISBN</dt> <dd> $isbn<p></dd> <dt>Price</dt> <dd> $price<p></dd> <dt>Number of Pages</dt> <dd> $numPages<p></dd> <dt>Description</dt> <dd> $description <p></dd> </dl> }; %library = (); open (AB, "/u/dgerman/CompanyA/data/dataFile.txt"); @x = <AB>; close(AB); foreach $line (@x) { @line = split(/:/, $line); $key = $line[4]; $library{$key} = $line; } #add new book $library{$isbn} = "$title:$author:$subject:$publisher:$isbn:$price:$numPages:$description"; $newline = chr(13); $library{$isbn} =~ s/[\n\r$newline]/ /g; $library{$isbn} =~ s/\s/ /g; open (AB, ">/u/dgerman/CompanyA/data/dataFile.txt"); foreach $key (sort (keys %library)) { print AB $library{$key}, "\n"; } close(AB); print "The book has been added, thank you. ", $query->end_html;
Hello, and how are you doing?There are a few issues that we won't even consider, such as:You seem to be entering the following book:
The book has been added, thank you.
- Title
- In Search of Lake Wobegon
- Author
- Garrison Keillor, Richard Olsenius (Photographer)
- Subject
- Biography
- Publisher
- Viking Press
- ISBN
- 0-6700-3037-6
- Price
- 29.95
- Number of Pages
- 128
- Description
- In the twenty-five years since Garrison Keillor first brought it to life, the rural Minnesota town of Lake Wobegon has become a national treasure. In this lavishly produced photography book, word and image combine to illuminate the real Minnesota town-life, landscapes, and people who inspired its creation. Taking us on a tour of Stearns County, the Minnesota county he deems most "Wobegonic," Keillor meditates on the origins of the place where, as a young writer, he found the inspiration for his fiction and his radio show. As an artful evocation of Keillor's beloved invention, Richard Olsenius's elegantly composed black-and-white photographs of rural Minnesota capture the dignity of his subjects, the beauties of the landscape as well as the enduring values and eccentricities of the communities rooted there.
And now the story.
Long, interesting, involving story about Best Book Buys comes here and touches the audience.
To summarize here are the facts:
Let's review servlets briefly, just so we know what we can count on.
We have this servlet,burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB burrowww.cs.indiana.edu% grep Company ../../conf/server.xml <Context path="/CompanyB" docBase="CompanyB" debug="0" reloadable="true" /> burrowww.cs.indiana.edu%
One
:
We have this servlet,import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class One extends HttpServlet { public void doGet(HttpServletRequest one, HttpServletResponse two) throws ServletException, IOException { two.setContentType("text/html"); PrintWriter out = two.getWriter(); out.println("How are you?"); } }
Two
:
We understand them well, we reviewed them just now.import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Two extends HttpServlet { public void doGet(HttpServletRequest one, HttpServletResponse two) throws ServletException, IOException { String p = one.getParameter("nom"); two.setContentType("text/html"); PrintWriter out = two.getWriter(); out.println("How are you, " + p + "?"); } }
So now let's look at the third one. (Recall the chat applet, if you will, it could be handy.)
You can try it here.import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; public class Three extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); URL getBooksURL = new URL("http", "burrowww.cs.indiana.edu", 10400, "/cgi-bin/CompanyA/catalog.pl"); URL url = new URL(getBooksURL.toExternalForm()); URLConnection con = url.openConnection(); con.setUseCaches(false); InputStream in = con.getInputStream(); DataInputStream data = new DataInputStream(new BufferedInputStream(in)); String line = data.readLine(); while (line != null) { out.println(line); line = data.readLine(); } out.println("<p> This is the end of the servlet"); } }
How do we become more systematic, so a computer program can figure it out for us?#!/usr/bin/perl use CGI; $query = new CGI; print $query->header, $query->start_html, "This is the CompanyA Library Catalog. <p> "; open (AB, "/u/dgerman/CompanyA/data/dataFile.txt"); @x = <AB>; close(AB); %library = (); foreach $line (@x) { if ($line =~ /^\s*$/) { next; } @line = split(/:/, $line); $isbn = $line[4]; $title = $line[0]; $author = $line[1]; $subject = $line[2]; $publisher = $line[3]; $isbn = $line[4]; $price = $line[5]; $numPages = $line[6]; $description = $line[7]; print qq{ <hr> <dl> <dt>Title</dt> <dd> $title<p></dd> <dt>Author</dt> <dd> $author<p></dd> <dt>Subject</dt> <dd> $subject<p></dd> <dt>Publisher</dt> <dd> $publisher<p></dd> <dt>ISBN</dt> <dd> $isbn<p></dd> <dt>Price</dt> <dd> $price<p></dd> <dt>Number of Pages</dt> <dd> $numPages<p></dd> <dt>Description</dt> <dd> $description <p></dd> </dl> }; } print "<hr> This is the catalog, thank you. ", $query->end_html;
Here's what we have thus far:
How do make it such thatburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.26/cgi-bin/CompanyA burrowww.cs.indiana.edu% ls -ld * -rwxr-xr-x 1 dgerman faculty 1454 Oct 19 19:36 addBook.pl -rwx------ 1 dgerman faculty 1055 Oct 19 22:08 catalog.pl -rwx------ 1 dgerman faculty 1055 Oct 19 21:53 report.pl burrowww.cs.indiana.edu% diff catalog.pl report.pl burrowww.cs.indiana.edu%
And,
So we switch to XML. First we need a report
script that transforms the database in XML.
But wait. Let's see some examples before we go too far, so we know what we're talking about.
Important Note:
You will need
This contains an archive of classes used for parsing./u/dgerman/public/xerces.jar
The parser (what's that?) we use is called Xerces.
Were does the name come from?
The Apache Xerces parser is called after the now extinct Xerces Blue Butterfly. Wiped out by urban expansion, the last known specimens were taken in 1941 at the Presidio military base in San Francisco. The butterfly was named after a king. A French entomologist named the butterfly for the Persian King Xerxes, but with the French spelling "Xerces," which was retained.
King Xerxes, son of Darius, ascended to the throne of Persia after his father's death in 486 BC. By 480 BC, the army he assembled had approximately 100,000 to 180,000 men and a fleet of nearly 600 ships, quite a large army by Greek standards and he decided to invade Greece. The plan was for his massive army to cross the Hellespont, and march around the Aegean sea and conquer Greece by land.
Crossing the Hellespont proved to be troublesome to Xerxes and his army. They tried to cross the Hellespont with a bridge of boats, but alas, the sea became rough and the bridge broke apart. When King Xerxes heard of this, he was furious, and gave orders that the sea should receive 300 lashes with whips. The sea did calm down and the second attempt to build a bridge was successful.
This, however, happened a long, long time ago.
Place the xerces.jar
file in $CATALINA_HOME/common/lib
.
Re-start your tomcat.
I use the following for starting and stopping Tomcat:
Also make sure yoursetenv startTomcat $CATALINA_HOME/bin/startup.sh setenv stopTomcat $CATALINA_HOME/bin/shutdown.sh
CLASSPATH
variable points to the xerces.jar
file.
And now we need to make sure we have checked the XML examples of yesterday.setenv CLASSPATH $CATALINA_HOME/common/lib/xerces.jar:$CLASSPATH
What you need to see now is two
:
Let's now return to CompanyA (CompanyA).burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.26/cgi-bin/CompanyA burrowww.cs.indiana.edu% ls -ld two -rwx------ 1 dgerman faculty 751 Dec 4 07:23 two burrowww.cs.indiana.edu% cat two #!/usr/bin/perl print "\n"; print qq{<?xml version="1.0"?> <document> <customer> <item> One </item> <item> Two </item> <item> Three </item> <item> Four </item> </customer> <customer> <item> One </item> </customer> <customer> <item> One </item> <item> Two </item> <item> Three </item> </customer> <customer> <item> One </item> <item> Two </item> <item> Three </item> <item> Four </item> </customer> <customer> <item> One </item> <item> Two </item> <item> Three </item> <item> Four </item> </customer> <customer> <item> One </item> <item> Two </item> </customer> </document>}; burrowww.cs.indiana.edu%
After much thought they produced the following output script.
Let's run it, so we can better see what's going on.Script started on Tue Dec 04 09:42:17 2001 burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.26/cgi-bin/CompanyA burrowww.cs.indiana.edu% ls -ld DOM*.pl -rwxr-xr-x 1 dgerman faculty 900 Dec 4 07:47 DOMreport.pl burrowww.cs.indiana.edu% cat DOMreport.pl #!/usr/bin/perl print "Content-type: plain/text\n\n"; open (AB, "/u/dgerman/CompanyA/data/dataFile.txt"); @x = <AB>; close(AB); print "<?xml version=\"1.0\"?>\n"; print "\n<document>\n"; %library = (); foreach $line (@x) { if ($line =~ /^\s*$/) { next; } @line = split(/:/, $line); $isbn = $line[4]; $title = $line[0]; $author = $line[1]; $subject = $line[2]; $publisher = $line[3]; $isbn = $line[4]; $price = $line[5]; $numPages = $line[6]; $description = $line[7]; print qq{ <book> <subject>$subject</subject> <title>$title</title> <author>$author</author> <publisher>$publisher</publisher> <numPages>$numPages</numPages> <saleDetails> <isbn>$isbn</isbn> <price>$price</price> </saleDetails> <description>$description</description> </book>}; } print "</document>";
burrowww.cs.indiana.edu% ./DOMreport.pl Content-type: plain/text <?xml version="1.0"?> <document> <book> <subject>Biography</subject> <title>In Search of Lake Wobegon</title> <author>Garrison Keillor, Richard Olsenius (Photographer)</author> <publisher>Viking Press</publisher> <numPages>128</numPages> <saleDetails> <isbn>0-6700-3037-6</isbn> <price>29.95</price> </saleDetails> <description>In the twenty-five years since Garrison Keillor first brought it to life, the rural Minnesota town of Lake Wobegon has become a national treasure. In this lavishly produced photography book, word and image combine to illuminate the real Minnesota town-life, landscapes, and people who inspired its creation. Taking us on a tour of Stearns County, the Minnesota county he deems most "Wobegonic," Keillor meditates on the origins of the place where, as a young writer, he found the inspiration for his fiction and his radio show. As an artful evocation of Keillor's beloved invention, Richard Olsenius's elegantly composed black-and-white photographs of rural Minnesota capture the dignity of his subjects, the beauties of the landscape as well as the enduring values and eccentricities of the communities rooted there. </description> </book> <book> <subject>Science</subject> <title>The Armchair Universe - An Exploration of Computer Worlds </title> <author>A. K. Dewdney </author> <publisher>W. H. Freeman and Company, New York </publisher> <numPages>330</numPages> <saleDetails> <isbn>0-7167-1939-8</isbn> <price>19.90</price> </saleDetails> <description>This is the first collection of A.K.Dewdney's popular "Computer Recreations" columns, drawn from Scientific American magazine between 1984 and 1987. Inspired by Martin Gardner's classic "Mathematical Games" column, which entertained millions of readers for more than 30 years, "Computer Recreations" has quickly become one of the most widely read and anticipated columns in Scientific American. The computer recreations described here range from purely entertaining brainteasers to more practical computer applications of scientific thought. And with Dewdney's lucid programming directions to follow, you can actually sit at your computer and try your hand at them all. Available in paperback and hardcover. Cover image shows Julia set bounding three basins of attraction on a Riemann sphere. </description> </book></document>burrowww.cs.indiana.edu% exit burrowww.cs.indiana.edu% script done on Tue Dec 04 09:42:43 2001
(Sometimes raw data can be in just the right format.)
CompanyB can now easily interact with CompanyA.
The question is: how do we prove it.
Take a look at this:
That's CompanyB settting things up for reception.burrowww.cs.indiana.edu% java org.apache.xalan.xslt.Process Xalan-J command line Process class options: -IN inputXMLURL [-XSL XSLTransformationURL] [-OUT outputFileName] [-E (Do not expand entity refs)] [-QC (Quiet Pattern Conflicts Warnings)] [-TT (Trace the templates as they are being called.)] [-TG (Trace each generation event.)] [-TS (Trace each selection event.)] [-TTC (Trace the template children as they are being processed.)] [-TCLASS (TraceListener class for trace extensions.)] [-EDUMP {optional filename} (Do stackdump on error.)] [-XML (Use XML formatter and add XML header.)] [-TEXT (Use simple Text formatter.)] [-HTML (Use HTML formatter.)] [-PARAM name expression (Set a stylesheet parameter)] [-L use line numbers for source document] [-MEDIA mediaType (use media attribute to find stylesheet associated with a document.)] [-FLAVOR flavorName (Explicitly use s2s=SAX or d2d=DOM to do transform.)] [-DIAG (Print overall milliseconds transform took.)] [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)] [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entities)] [-CONTENTHANDLER full class name (ContentHandler to be used to serialize output)] burrowww.cs.indiana.edu%
Here's a test they make (read this in conjunction with the notes for next week).
Note that the contents of the two files is as follows:burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls -ld * -rw-r--r-- 1 dgerman faculty 1044 Oct 19 22:30 Nine.java -rw-r--r-- 1 dgerman faculty 1350 Oct 19 21:24 Three.class -rw-r--r-- 1 dgerman faculty 1119 Oct 19 21:24 Three.java -rw-r--r-- 1 dgerman faculty 296 Oct 20 11:05 one.xml -rw-r--r-- 1 dgerman faculty 674 Oct 20 11:08 one.xslt burrowww.cs.indiana.edu% java org.apache.xalan.xslt.Process \ -IN one.xml \ -XSL one.xslt \ -OUT one.html burrowww.cs.indiana.edu% ls one* one.html one.xml one.xslt burrowww.cs.indiana.edu% cat one.html <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Discussion Forum Home Page</title> </head> <body> <h1>Discussion Forum Home Page</h1> <h3>Please select a message board to view:</h3> <ul> <li> <a href="viewForum?id=1">Java Programming</a> </li> <li> <a href="viewForum?id=2">XML Programming</a> </li> <li> <a href="viewForum?id=3">XSLT Questions</a> </li> </ul> </body> </html> burrowww.cs.indiana.edu%
So when this works CompanyB says: 'CompanyA could you please give this over the network?'burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls -ld * -rw-r--r-- 1 dgerman faculty 1044 Oct 19 22:30 Nine.java -rw-r--r-- 1 dgerman faculty 1350 Oct 19 21:24 Three.class -rw-r--r-- 1 dgerman faculty 1119 Oct 19 21:24 Three.java -rw-r--r-- 1 dgerman faculty 418 Oct 20 11:19 one.html -rw-r--r-- 1 dgerman faculty 296 Oct 20 11:05 one.xml -rw-r--r-- 1 dgerman faculty 674 Oct 20 11:08 one.xslt burrowww.cs.indiana.edu% cat one.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="discussionForumHome.xslt"?> <discussionForumHome> <messageBoard id="1" name="Java Programming"/> <messageBoard id="2" name="XML Programming"/> <messageBoard id="3" name="XSLT Questions"/> </discussionForumHome> burrowww.cs.indiana.edu% cat one.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title>Discussion Forum Home Page</title> </head> <body> <h1>Discussion Forum Home Page</h1> <h3>Please select a message board to view:</h3> <ul> <xsl:apply-templates select="discussionForumHome/messageBoard"/> </ul> </body> </html> </xsl:template> <xsl:template match="messageBoard"> <li><a href="viewForum?id={@id}"><xsl:value-of select="@name"/></a></li> </xsl:template> </xsl:stylesheet> burrowww.cs.indiana.edu%
So Company A says: 'Yo, this will only take one
moment!'
Here's what CompanyA immediately puts up:
Meanwhile CompanyB's waiting to test things out and when they do:burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.26/cgi-bin/CompanyA burrowww.cs.indiana.edu% ls -ld * -rwx------ 1 dgerman faculty 891 Oct 19 22:18 DOMReport.pl -rwx------ 1 dgerman faculty 1454 Oct 19 19:36 addBook.pl -rwx------ 1 dgerman faculty 1055 Oct 19 22:08 catalog.pl -rwx------ 1 dgerman faculty 325 Oct 20 11:39 one -rwx------ 1 dgerman faculty 1055 Oct 19 21:53 report.pl -rwx------ 1 dgerman faculty 692 Oct 19 22:32 two burrowww.cs.indiana.edu% cat one #!/usr/bin/perl print qq{ <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="discussionForumHome.xslt"?> <discussionForumHome> <messageBoard id="1" name="Java Programming"/> <messageBoard id="2" name="XML Programming"/> <messageBoard id="3" name="XSLT Questions"/> </discussionForumHome>}; burrowww.cs.indiana.edu% ./one <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="discussionForumHome.xslt"?> <discussionForumHome> <messageBoard id="1" name="Java Programming"/> <messageBoard id="2" name="XML Programming"/> <messageBoard id="3" name="XSLT Questions"/> </discussionForumHome>burrowww.cs.indiana.edu%
Things seem to be working very well thus far.burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls -ld *.html No match burrowww.cs.indiana.edu% java org.apache.xalan.xslt.Process \ -IN http://burrowww.cs.indiana.edu:10400/cgi-bin/CompanyA/one \ -OUT alpha.html \ -XSL one.xslt burrowww.cs.indiana.edu% cat alpha.html <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Discussion Forum Home Page</title> </head> <body> <h1>Discussion Forum Home Page</h1> <h3>Please select a message board to view:</h3> <ul> <li> <a href="viewForum?id=1">Java Programming</a> </li> <li> <a href="viewForum?id=2">XML Programming</a> </li> <li> <a href="viewForum?id=3">XSLT Questions</a> </li> </ul> </body> </html> burrowww.cs.indiana.edu%
So CompanyB says: 'We are going to test your other script, OK?'
And here's how this goes:
You see how we are getting closer to wrapping things up.burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls Nine.java Three.class Three.java one.xml one.xslt testing.xslt burrowww.cs.indiana.edu% cat testing.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title>Company B representing Company A Home Page</title> </head> <body> <h1>Discussion Forum Home Page</h1> <h3>Please select a message board to view:</h3> <ul> <xsl:apply-templates select="document/book"/> </ul> </body> </html> </xsl:template> <xsl:template match="book"> <li> I can see a book! </li> </xsl:template> </xsl:stylesheet> burrowww.cs.indiana.edu% java org.apache.xalan.xslt.Process \ -IN http://burrowww.cs.indiana.edu:10400/cgi-bin/CompanyA/DOMReport.pl \ -XSL testing.xslt \ -OUT testing.html burrowww.cs.indiana.edu% cat testing.html <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Company B representing Company A Home Page</title> </head> <body> <h1>Discussion Forum Home Page</h1> <h3>Please select a message board to view:</h3> <ul> <li> I can see a book! </li> <li> I can see a book! </li> </ul> </body> </html> burrowww.cs.indiana.edu%
Now the final servlet:burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls -l total 10 -rw-r--r-- 1 dgerman faculty 1044 Oct 19 22:30 Nine.java -rw-r--r-- 1 dgerman faculty 1350 Oct 19 21:24 Three.class -rw-r--r-- 1 dgerman faculty 1119 Oct 19 21:24 Three.java -rw-r--r-- 1 dgerman faculty 296 Oct 20 11:05 one.xml -rw-r--r-- 1 dgerman faculty 674 Oct 20 11:08 one.xslt -rw-r--r-- 1 dgerman faculty 324 Oct 20 12:02 testing.html -rw-r--r-- 1 dgerman faculty 624 Oct 20 12:00 testing.xslt burrowww.cs.indiana.edu% mkdir ../xslt burrowww.cs.indiana.edu% cp testing.xslt ../xslt burrowww.cs.indiana.edu% cat One.java import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class One extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("How are you?"); } } burrowww.cs.indiana.edu% javac One.java burrowww.cs.indiana.edu%
And there's a key element to all of this (for the servlet to compile):burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% ls -ld One.java -rw-r--r-- 1 dgerman faculty 1391 Oct 20 19:59 One.java burrowww.cs.indiana.edu% cat One.java import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class One extends HttpServlet { private Templates stylesheet; public void init() throws UnavailableException { try { URL xsltURL = getServletContext().getResource("/WEB-INF/xslt/testing.xslt"); String xsltSystemID = xsltURL.toExternalForm(); TransformerFactory transfact = TransformerFactory.newInstance(); this.stylesheet = transfact.newTemplates(new StreamSource(xsltSystemID)); } catch (Exception e) { } } public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); try { Transformer trans = stylesheet.newTransformer(); res.setContentType("text/html"); PrintWriter writer = res.getWriter(); trans.transform(new StreamSource("http://burrowww.cs.indiana.edu:10400/cgi-bin/CompanyA/DOMReport.pl"), new StreamResult(writer)); } catch (Exception e) { PrintWriter out = res.getWriter(); out.println("Error: " + e.getMessage()); out.close(); } } } burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/classes burrowww.cs.indiana.edu% cd ../xslt burrowww.cs.indiana.edu% ls -l total 2 -rw-r--r-- 1 dgerman faculty 638 Oct 20 20:02 testing.xslt burrowww.cs.indiana.edu% cat testing.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title>Company B representing Company A Home Page</title> </head> <body> <h1>Welcome to Company B BDP </h1> <h3>BDP means Book Distribution Page, as indicated below:</h3> <ul> <xsl:apply-templates select="document/book"/> </ul> </body> </html> </xsl:template> <xsl:template match="book"> <li> I can see a book! </li> </xsl:template> </xsl:stylesheet> burrowww.cs.indiana.edu%
For the meaning ofburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/CompanyB/WEB-INF/xslt burrowww.cs.indiana.edu% cd ../lib burrowww.cs.indiana.edu% ls -l total 1024 -rw-r--r-- 1 dgerman faculty 1037500 Oct 20 19:55 everything.jar burrowww.cs.indiana.edu%
everything
don't forget to check the notes for next week.