// copyright=> http://www.jxml.com/mdsax/License.txt

package com.jxml.quick.util.dtd2xml;

import java.io.*;
import java.util.*;
import com.wutka.dtd.*;
import com.jxml.quick.*;
import com.jxml.quick.ocm.*;
import org.xml.sax.*;

/**
 * Retrives DTD by file name.
<pre>
DTD:

&lt;!ELEMENT dtdOutput((<a href="../../ocm/OCMsinkSupport.html#source">source|sourceLink</a>)(,<a href="../../ocm/OCMsinkSupport.html#validator">validate|validateLink</a>)?,)>

&lt;!ATTLIST dtdOutput 
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMsinkSupport.html#prefix">docNamePrefix </a>CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMsinkSupport.html#expressDefaults">expressDefaults</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;ID CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../ocm/OCMtranscribe.html#schemaName">outputSchema </a>CDATA #IMPLIED
>
</pre>
 */
public class DTDexpress extends OCMtranscribe 
{
	// implements an OCMbase method
	public OCMbase.SubBase spawn(HashMap prior)
	{
		OCMbase.SubBase rv=(OCMbase.SubBase)prior.get(this);
		if (rv!=null)
			return rv;
		OCMbase.SubBase base=new SubDTDexpress(prior);
		prior.put(this,base);
		return base;
	}


	/**
	 * A processing object spawned from an OCMsourceByName object.
	 */
	public class SubDTDexpress extends OCMtranscribe.SubTranscribe 
	{
		public SubDTDexpress(HashMap prior)
		{
			super(prior);
		}

		// Implement SubSink method.
		public String express()
			throws SAXException, IOException
		{
			DTD dtd=(DTD)getDoc().getRoot();
			StringWriter sw=new StringWriter();
			PrintWriter pw=new PrintWriter(sw);
			dtd.write(pw);
			pw.close();
			return sw.toString();
		}

		// Implement SubSink method.
		public void express(PrintWriter pw)
			throws SAXException, IOException
		{
			DTD dtd=(DTD)getDoc().getRoot();
			dtd.write(pw);
		}
	}
}
