FileDocCategorySizeDatePackage
GenMML.javaAPI DocExample4181Tue Apr 18 14:56:32 BST 2000None

GenMML

public class GenMML extends Object implements XmlFormWalker
Class with code to walk a tree and convert it to MML (not MIF). WAY OUT OF DATE W.R.T. THE "DTD" -- DO NOT USE!!
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: GenMML.java,v 1.9 2000/04/18 17:56:32 ian Exp $

Fields Summary
PrintWriter
msg
The normal output writer
StyledWriter
smsg
Specialized PrintWriter for use by GetMark.
TreeWalker
tw
A tree walker object for walking the tree
GetMark
gm
A GetMark converter for source code.
Constructors Summary
GenMML(Document doc, PrintWriter pw)
Construct a converter object


	     
	    
		tw = new TreeWalker(doc);
		msg = new PrintWriter(pw);
		smsg = new StyledPrintStream(msg);
	
Methods Summary
public voidconvertAll()
Convert all the nodes in the current document.


		msg.println("<MML 1.00 -- MML produced by XmlForm>");
		msg.println("<Include \"xmlformat.mml\">");

		for (Node p = tw.getCurrent(); p != null; p = tw.getNext())
			doNode(p);
	
protected voiddoBold(org.w3c.dom.Element p)

		msg.print("<Bold>");
		doNodes(p);
		msg.print("<Plain>");
	
protected voiddoCData(org.w3c.dom.CharacterData p)

		String s = p.getData().trim();
		if (s.length() == 0)	// Suns parser returns extra 1-space "Text"s
			return;
		msg.println(s);
	
protected voiddoChapter(org.w3c.dom.Element p)

		msg.println("<ChapterTitle>");
	
protected voiddoElement(org.w3c.dom.Element p)

		String tag = p.getTagName().toLowerCase();
		if (tag.equals("ch")) {
			doChapter(p);
		} else if (tag.equals("sc")) {
			doSection(p);
		} else if (tag.equals("ss")) {
			doSubSection(p);
		} else if (tag.equals("p")) {
			doParagraph(p);
		} else if (tag.equals("pr")) {
			msg.println("<HeadB>Problem");
		} else if (tag.equals("so")) {
			msg.println("<HeadB>Solution");
		} else if (tag.equals("di")) {
			msg.println("<HeadB>Discussion");
		} else if (tag.equals("code")) {
			doCode(p);
		} else if (tag.equals("b")) {
			doBold(p);
		} else if (tag.equals("i")) {
			doItalic(p);
		} else if (tag.equals("example")) {
			doExample(p);
		} else
			System.err.println("IGNORING UNHANDLED TAG " + tag + ( +
				p.getClass() + @ + p.hashCode() + ));
	
protected voiddoExample(org.w3c.dom.Element p)

		NamedNodeMap attrs = p.getAttributes();
		Node href;
		if ((href = attrs.getNamedItem("HREF")) == null)
			throw new IllegalArgumentException(
				"node " + p + "lacks required HREF Attribute");
		String fname = href.getNodeValue();
		msg.println("<Example>");
		try {
			fname = "/javasrc/" + fname;
			LineNumberReader is = new LineNumberReader(new FileReader(fname));
			gm.process(fname, is, smsg);
		} catch(IOException e) {
			throw new IllegalArgumentException(e.toString());
		}
	
protected voiddoItalic(org.w3c.dom.Element p)

		msg.print("<Italic>");
		doNodes(p);
		msg.print("<Plain>");
	
public voiddoNode(org.w3c.dom.Node p)

		if (p instanceof com.sun.xml.tree.XmlDocument)
			return;	// nothing to do - structural object.
		// else if (p instanceof com.sun.xml.tree.Doctype)
		//	return;	// ditto
		else if (p instanceof Element)
			doElement((Element)p);
		else if (p instanceof org.w3c.dom.CharacterData)
			doCData((org.w3c.dom.CharacterData)p);
		else
			System.err.println("IGNORING non-Element: " +
				p.getClass() + : + p.toString() + "\n" +
				p.getNodeValue());
	
protected voiddoNodes(org.w3c.dom.Element p)

		NodeList nodes = p.getChildNodes();
		for (int i=0; i<nodes.getLength(); i++) {
			Node n = nodes.item(i);
			if (n instanceof CharacterData) {
				doCData((CharacterData)n);
				p.removeChild(n);
			}
		}
	
protected voiddoParagraph(org.w3c.dom.Element p)

		msg.println("<Body>");
	
protected voiddoSection(org.w3c.dom.Element p)

		msg.println("<HeadA>");
	
protected voiddoSubSection(org.w3c.dom.Element p)

		msg.println("<HeadB>");