package com.jxml.quick.util.qdml2dtd;
import com.jxml.quick.model.qdml.*;
import com.jxml.quick.*;
import org.xml.sax.*;
import java.util.*;
import com.jxml.quick.ocm.*;
import java.io.*;

/**
 * Extracts DTD data.
 */
public class QCText extends OCMpeerSupport
{
	/**
	 * User-provided code to perform the conversion.
	 */
	public void cvt(Object param)
		throws SAXException, IOException
	{
		QDMText dm=(QDMText)dataModel;
		int i,s;
		ArrayList remList =dm.remList;
		s=remList.size();
		for(i=0;i<s;++i)
		{
			startElement("rem");
			QDMRem rem=(QDMRem)remList.get(i);
			addStringContent(rem.text);
			endElement("rem");
		}
		String label=dm.getLabel();
		QDMQDML qdmlDM=(QDMQDML)param;
		if (isElement(label,qdmlDM))
			genElement(dm);
	}

	boolean isElement(String label, QDMQDML qdmlDM)
	{
		TreeMap coinMap=qdmlDM.coinMap;
		Collection col=coinMap.values();
		Iterator it=col.iterator();
		while(it.hasNext())
		{
			QDMCoin c=(QDMCoin)it.next();
			if (c instanceof QDMBean)
			{
				QDMBean bean=(QDMBean)c;
				if (bean.isContainedBy(label,coinMap))
					return true;
			}
		}
		return false;
	}

	void genElement(QDMText dm)
		throws SAXException, IOException
	{
		addStringAttribute("name",dm.tag);
		startElement("element");
		startElement("mixed");
		startElement("pcData");
		endElement("pcData");
		endElement("mixed");
		endElement("element");
	}
}
