still working DOM
git-svn-id: svn://anubis/gvsu@122 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
0b903670ee
commit
77191b37be
@ -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> </th><th>AM</th><th>PM</th></tr>");
|
out.println("<table><caption>Daily Planner</caption><tr><th> </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))
|
||||||
{
|
{
|
||||||
@ -84,25 +83,29 @@ public class JDOM
|
|||||||
out.print(m_weekDayNames.get(name));
|
out.print(m_weekDayNames.get(name));
|
||||||
out.println("</td>");
|
out.println("</td>");
|
||||||
for (int i = 0; i < children.getLength(); i++)
|
for (int i = 0; i < children.getLength(); i++)
|
||||||
|
{
|
||||||
|
if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
|
||||||
{
|
{
|
||||||
out.print("<td>");
|
out.print("<td>");
|
||||||
printAMPM(children.item(i));
|
printAMPM(children.item(i), out);
|
||||||
out.print("</td>");
|
out.print("</td>");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
out.println("</tr>");
|
out.println("</tr>");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user