/*
 * Strings.java
 *
 * Created on October 8, 2007, 9:17 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package utils;

/**
 *
 * @author lluis
 */
public class Strings {
	public static String unicodeToHTML( String text )
	{
		if( text == null || text.length() < 6 )
		{
			return text;
		}

		String output = text;
		output = output.replace( "\\u0009", " " );
		output = output.replace( "\\u000a", "<br>" );

		output = output.replace( "\\u00a0", "&nbsp;" );
		output = output.replace( "\\u00aa", "&ordf;" );
		output = output.replace( "\\u00ba", "&ordm;" );

		output = output.replace( "\\u00c0", "À" );
		output = output.replace( "\\u00c1", "Á" );
		output = output.replace( "\\u00c2", "Â" );
		output = output.replace( "\\u00c3", "Ã" );
		output = output.replace( "\\u00c7", "Ç" );
		output = output.replace( "\\u00c8", "È" );
		output = output.replace( "\\u00c9", "É" );
                
		output = output.replace( "\\u00ca", "Ê" );
		output = output.replace( "\\u00cc", "Ì" );
		output = output.replace( "\\u00cd", "Í" );
		output = output.replace( "\\u00ce", "Î" );
		output = output.replace( "\\u00d2", "ò" );
		output = output.replace( "\\u00d3", "ó" );
		output = output.replace( "\\u00d4", "ô" );
		output = output.replace( "\\u00d5", "õ" );
		output = output.replace( "\\u00d9", "Ù" );
		output = output.replace( "\\u00da", "Ú" );
		output = output.replace( "\\u00db", "Û" );

		output = output.replace( "\\u00e0", "à" );
		output = output.replace( "\\u00e1", "á" );
		output = output.replace( "\\u00e2", "â" );
		output = output.replace( "\\u00e3", "ã" );
		output = output.replace( "\\u00e7", "ç" );
		output = output.replace( "\\u00e8", "è" );
		output = output.replace( "\\u00e9", "é" );
		output = output.replace( "\\u00ea", "ê" );
		output = output.replace( "\\u00ec", "ì" );
		output = output.replace( "\\u00ed", "í" );
		output = output.replace( "\\u00ee", "î" );
		output = output.replace( "\\u00f2", "ò" );
		output = output.replace( "\\u00f3", "ó" );
		output = output.replace( "\\u00f4", "ô" );
		output = output.replace( "\\u00f5", "õ" );
		output = output.replace( "\\u00f9", "ù" );
		output = output.replace( "\\u00fa", "ú" );
		output = output.replace( "\\u00fb", "û" );

		output = output.replace( "\\u0153", "&#156;" );

		output = output.replace( "\\u2013", "-" );
		output = output.replace( "\\u2014", "-" );
		output = output.replace( "\\u2018|\\u2019", "'" );
		output = output.replace( "\\u201c|\\u201d", "\"" );

		output = output.replace( "\\u2022", "*" );
		output = output.replace( "\\u2026", "..." );

		return output;
	}
        
	public static String textToUnicode( String text )
        {
		String output = text;    
		output = output.replace( "À", "\\u00c0" );
		output = output.replace( "Á", "\\u00c1" );
		output = output.replace( "Â", "\\u00c2" );
		output = output.replace( "Ã", "\\u00c3" );
		output = output.replace( "Ç", "\\u00c7" );
		output = output.replace( "È", "\\u00c8" );
		output = output.replace( "É", "\\u00c9" );
                
		output = output.replace( "Ê", "\\u00ca" );
		output = output.replace( "Ì", "\\u00cc" );
		output = output.replace( "Í", "\\u00cd" );
		output = output.replace( "Î", "\\u00ce" );
		output = output.replace( "ò", "\\u00d2" );
		output = output.replace( "ó", "\\u00d3" );
		output = output.replace( "ô", "\\u00d4" );
		output = output.replace( "õ", "\\u00d5" );
		output = output.replace( "Ù", "\\u00d9" );
		output = output.replace( "Ú", "\\u00da" );
		output = output.replace( "Û", "\\u00db" );

		output = output.replace( "à", "\\u00e0" );
		output = output.replace( "á", "\\u00e1" );
		output = output.replace( "â", "\\u00e2" );
		output = output.replace( "ã", "\\u00e3" );
		output = output.replace( "ç", "\\u00e7" );
		output = output.replace( "è", "\\u00e8" );
		output = output.replace( "é", "\\u00e9" );
		output = output.replace( "ê", "\\u00ea" );
		output = output.replace( "ì", "\\u00ec" );
		output = output.replace( "í", "\\u00ed" );
		output = output.replace( "î", "\\u00ee" );
		output = output.replace( "ò", "\\u00f2" );
		output = output.replace( "ó", "\\u00f3" );
		output = output.replace( "ô", "\\u00f4" );
		output = output.replace( "õ", "\\u00f5" );
		output = output.replace( "ù", "\\u00f9" );
		output = output.replace( "ú", "\\u00fa" );
		output = output.replace( "û", "\\u00fb" );    
                
		return output;                
        }
	
	public static String RTFToUnicode( String text )
	{
		if( text == null || text.length() < 4 )
		{
			return text;
		}
		String output = text;
		output = output.replaceAll( "\\'", "\\u00" );
		return output;
	}
	
	public static String unicodeToRTF( String text )
	{
		if( text == null || text.length() < 6 )
		{
			return text;
		}
		String output = text;
		output = output.replaceAll( "\\\\u00", "\\\\'" );
		return output;
	}
    
}
