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

public class QCSelection extends OCMtemplate
{
	public QMSelection  ed;
	StringBuffer sb;
	QCParm p;
	QMCoin mCoin=null;
	Map properties;

	public void cvt(Object param) 
		throws SAXException, IOException 
	{
		OCMcontextSupport.SubContextSupport scs=(OCMcontextSupport.SubContextSupport)context;
		sb=scs.sb;
		ed=(QMSelection)dataModel;
		properties=scs.properties;
		if (param==null)
		{
			names();
		}
		else
		{
			QCParm parm=(QCParm)param;
			p=new QCParm(parm,ed.repeating,ed.optional,ed.access);
			if (p.access!=null)
				mCoin=p.access.mCoin;
			super.cvt(ed);
		}
 	}

	public void names()
		throws SAXException, IOException
	{
		List contentList=ed.contentList;
		int s,i;
		s=contentList.size();
		if (s>0)
		{
			sb.append("(");
       			for(i=0;i<s;i++)
			{
				if(i>0)
				sb.append("|");
				doCvt(contentList.get(i),null );
			}
			sb.append(")");

		}
	}
	public String process(String templateName, String arg)
		throws SAXException, IOException
	{

		if("attributeName".equals(arg))
		{
			names();
		}

		if("urls".equals(arg))
		{
			expand("urls");		
		}

		if("beanDescription".equals(arg) && mCoin!=null)
		{
			doCvt(mCoin,"");
		}

		if("javaVar".equals(arg))
		{
			doCvt(p.access,"");
		}
		if("color".equals(arg))
		{
			if(p.repeating)
			{
				if (p.optional)
					sb.append("tan");
			}
			else
			{
				if (!p.optional)
					sb.append("pink");
					
				else
					sb.append("tan");
			}
		}

		if("repeating".equals(arg))
		{
			if(p.repeating)
			{
				if (p.optional)
					sb.append("0 or more");
				else
					sb.append("1 or more");
			}
			else
			{
				if (p.optional)
					sb.append("optional");
				else
					sb.append("required");
			}

		}

		if("schemaName".equals(arg))
		{
			sb.append((String)(properties.get("schemaName")));
		}

		if("elements".equals(arg))
		{
			//sb.append(ed.coinName);	
		}

		if("pathName".equals(arg))
		{
			sb.append("http://quickutil.sourceforge.net/view/Main/");
		}

	        return"";   
	}
}




