if ( doc != null && doc.getFirstChild( ) != null && doc.getFirstChild( ) instanceof Element ) {  ( (Element) ( doc.getFirstChild( ) ) ).setAttribute( "text-type", textType ); }  return doc;
	public Document parse( String text, String textType )	{		// Handle null case		if ( text == null || text.length( ) == 0 )			return null;		//If the type is null or auto, resets the text type based on the		// content prefix		if ( null == textType || TEXT_TYPE_AUTO.equalsIgnoreCase( textType ) )		{			int index = 0;			int len = text.length( );			// remove white spaces			while ( index < len					&& Character.isWhitespace( text.charAt( index ) ) )			{				index++;			}			// Checks if the first six characters are "<html>"			if ( ( len - index ) >= 6					&& text.substring( index, index + 6 ).equalsIgnoreCase(							HTML_PREFIX ) )				textType = TEXT_TYPE_HTML;			else if ( ( len - index ) >= 4					&& text.substring( index, index + 4 ).equalsIgnoreCase(							RTF_PREFIX ) )				textType = TEXT_TYPE_RTF;			else				textType = TEXT_TYPE_PLAIN; // Assume plain text in any other											// cases		}		if ( TEXT_TYPE_HTML.equalsIgnoreCase( textType ) )		{			try			{				//Convert input string to an input stream because JTidy accepts				// a stream only				return new HTMLTextParser( )						.parseHTML( new ByteArrayInputStream( text								.getBytes( "UTF-8" ) ) );			}			catch ( UnsupportedEncodingException e )			{			    logger.log( Level.SEVERE, e.getMessage(),  e );				return null;			}		}		else if ( TEXT_TYPE_RTF.equalsIgnoreCase( textType ) )		{			assert false; // Not supported yet			return null;		}		else		{		    if ( !TEXT_TYPE_PLAIN.equalsIgnoreCase( textType ) )		        logger.log( Level.WARNING, "Invalid text type. The content is treated as plain text." );			return new PlainTextParser( ).parsePlainText( text );		    					}	}