/********************************************************************
 *  Oracle JDeveloper
 *  Copyright (c) 1997, 1999, Oracle Corporation. All rights reserved.
 ********************************************************************/


package oracle.jdeveloper.html;

import java.io.PrintWriter;
import java.util.Vector;

/**
 *
 * Provides functions for encoding the value portion of form fields
 *
 * @author  Juan Oropeza
 * @version PUBLIC
 */
public class FormFieldValueEncoder
{
    /**
	*	Encode field value for embedding in an HTML document.
	*/
	static public String encode(String sValue)
	{
      StringBuffer  sBuffer = new StringBuffer();
      int           nIndex;
      int           nLength;

      if(sValue == null)
         return null;
       
      nLength =  sValue.length();
       
      // replace all ' with ''
      for(nIndex = 0 ; nIndex < nLength ; nIndex++)
      {
         if(sValue.charAt(nIndex) == '"')
         {
            sBuffer.append("&quot");
         }
         else if(sValue.charAt(nIndex) == '<')
         {
            sBuffer.append("&lt");
         }
         else if(sValue.charAt(nIndex) == '>')
         {
            sBuffer.append("&gt");
         }
         else
            sBuffer.append(sValue.charAt(nIndex));
      }

      return sBuffer.toString();		
	}
}