package com.jxml.protocol;

/**
 * Support logic for protocol packages.
 */
public class Protocol
{
	/**
	 * System property name for protocol packages.
	 */
		public static final String
	protocolProperty="java.protocol.handler.pkgs";

	/**
	 * Add a new protocol package.
	 */
		public static void
	addProtocolPackage(String protocolPackage)
	{
		if (haveProtocolPackage(protocolPackage))
			return;
		String value=System.getProperty(protocolProperty);
		if (value==null)
			value=protocolPackage;
		else
			value+="|"+protocolPackage;
		System.setProperty(protocolProperty,value);
	}

	/**
	 * Returns true if the protocol package is already included.
	 */
		public static boolean
	haveProtocolPackage(String protocolPackage)
	{
		int i=0;
		String value=System.getProperty(protocolProperty);
		if (value==null)
			return false;
		int l=value.length();
		while(i<l)
		{
			int j=value.indexOf("|",i);
			if (j==-1)
				j=l;
			if (protocolPackage.equals(value.substring(i,j)))
				return true;
			i=j+1;
		}
		return false;
	}

	/**
	 * Add the jxml protocol package.
	 */
		public static void
	addJXMLProtocolPackage()
	{
		addProtocolPackage("com.jxml.protocol");
	}
}
