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 QCItem extends OCMtemplate
{
	public QMItem  ed;
	StringBuffer sb;
	QCParm p;
	Map properties;

	public void cvt(Object param) 
		throws SAXException, IOException 
	{
		OCMcontextSupport.SubContextSupport scs=(OCMcontextSupport.SubContextSupport)context;
		sb=scs.sb;
		ed=(QMItem)dataModel;
		properties=scs.properties;

		if (param==null)
		{
			expand("urls");
		}

		else if (param instanceof QCParm)
		{
			QCParm parm=(QCParm)param;
			p=new QCParm(parm,ed.repeating,ed.optional,ed.access);
			expand("contentDetails");

		}
		else if ("".equals(param))
		{
			p=new QCParm(ed.repeating,ed.optional,ed.access);
			expand("attributesDetails");
		}
	}
	public String process(String templateName, String arg)
		throws SAXException, IOException
	{
		if("usage".equals(arg))
		{
			expand("usage");
		}

		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("attributeName".equals(arg))
		{
			sb.append(ed.getAttributeTagName());
		}

		if("beanDescription".equals(arg))
		{
			doCvt(ed.coin,"");
		}

		if("javaVar".equals(arg))
		{
			doCvt(p.access,"");
		}

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

		if("usageDescription".equals(arg))
		{

			if(p.optional)
				 sb.append("optional");
			else
				 sb.append("required");

			if((ed.coin) instanceof QMText)
			{
				QMText txt=(QMText)ed.coin;

				int s,i;
				ArrayList validList=txt.validList;
				s=validList.size();
				if (s>0)
				{
 					sb.append("(");
 	        			for(i=0;i<s;i++)
					{
						if (i>0)
							sb.append("|");
						QMEnum valid=(QMEnum)validList.get(i);
						sb.append(valid.value);
					}
					sb.append(")");
					
				}
			}
		}

		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"";   
	}
}

