still working DOM

git-svn-id: svn://anubis/gvsu@122 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-06-10 22:05:31 +00:00
parent 0b903670ee
commit 77191b37be

View File

@ -40,7 +40,7 @@ public class JDOM
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(file); doc = db.parse(file);
if (doc != null) if (doc != null)
printHTMLSchedule(doc); printHTMLSchedule(doc, System.out);
} }
catch (Exception e) catch (Exception e)
{ {
@ -48,9 +48,8 @@ public class JDOM
} }
} }
private void printHTMLSchedule(Node n) private void printHTMLSchedule(Node n, PrintStream out)
{ {
PrintStream out = System.out;
int type = n.getNodeType(); int type = n.getNodeType();
switch (type) switch (type)
{ {
@ -65,7 +64,7 @@ public class JDOM
out.println("</head><body>"); out.println("</head><body>");
out.println("<table><caption>Daily Planner</caption><tr><th>&nbsp;</th><th>AM</th><th>PM</th></tr>"); out.println("<table><caption>Daily Planner</caption><tr><th>&nbsp;</th><th>AM</th><th>PM</th></tr>");
printHTMLSchedule( ((Document) n).getDocumentElement() ); printHTMLSchedule( ((Document) n).getDocumentElement(), out );
out.println("</table>\n</body>\n</html>"); out.println("</table>\n</body>\n</html>");
break; break;
@ -76,7 +75,7 @@ public class JDOM
if (name.equals("dailyplanner")) if (name.equals("dailyplanner"))
{ {
for (int i = 0; i < children.getLength(); i++) for (int i = 0; i < children.getLength(); i++)
printHTMLSchedule(children.item(i)); printHTMLSchedule(children.item(i), out);
} }
else if (m_weekDayNames.containsKey(name)) else if (m_weekDayNames.containsKey(name))
{ {
@ -85,9 +84,12 @@ public class JDOM
out.println("</td>"); out.println("</td>");
for (int i = 0; i < children.getLength(); i++) for (int i = 0; i < children.getLength(); i++)
{ {
out.print("<td>"); if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
printAMPM(children.item(i)); {
out.print("</td>"); out.print("<td>");
printAMPM(children.item(i), out);
out.print("</td>");
}
} }
out.println("</tr>"); out.println("</tr>");
} }
@ -95,14 +97,15 @@ public class JDOM
} }
} }
private void printAMPM(Node n) private void printAMPM(Node n, PrintStream out)
{ {
NodeList children = n.getChildren(); NodeList children = n.getChildNodes();
for (int i = 0; i < children.getLength(); i++) for (int i = 0; i < children.getLength(); i++)
{ {
Node c = children.item(i); Node c = children.item(i);
if (c.getType() == Node.TEXT_NODE) if (c.getNodeType() == Node.TEXT_NODE)
{ {
out.print(c.getNodeValue());
} }
} }
} }