package com.bizofficer.util.system;

import java.io.File;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

public class General {

	
/************************************************************
	CREATE HASH ENCRYPTED STRING SHA-512
************************************************************/	
	@SuppressWarnings("deprecation")
	public String getSHA(String str) {

		 MessageDigest md;
		String out = "";
		try {
			md = MessageDigest.getInstance("SHA-512");
			md.update(str.getBytes());
			byte[] mb = md.digest();

			for (int i = 0; i < mb.length; i++) {
				byte temp = mb[i];
				String s = Integer.toHexString(new Byte(temp));
				while (s.length() < 2) {
					s = "0" + s;
				}
				s = s.substring(s.length() - 2);
				out += s;
			}

		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return out; 

	}

	
	public String makeHashEncryption(String input)
    {
        try {
            // getInstance() method is called with algorithm SHA-512
            MessageDigest md = MessageDigest.getInstance("SHA-512");
  
            // digest() method is called
            // to calculate message digest of the input string
            // returned as array of byte
            byte[] messageDigest = md.digest(input.getBytes());
  
            // Convert byte array into signum representation
            BigInteger no = new BigInteger(1, messageDigest);
  
            // Convert message digest into hex value
            String hashtext = no.toString(16);
  
            // Add preceding 0s to make it 32 bit
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
  
            // return the HashText
            return hashtext;
        }
  
        // For specifying wrong message digest algorithms
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
	
/************************************************************
	CREATE JSON STRING FOR AJAX RESPONSE
************************************************************/	
	
	public String createJson(String[] arr){
		try{
			String json=null;
			//"[{\"info\":\"\"},{\"info\":\"\"}]"
			json="[";
			Integer arrCount=arr.length;
			for(int i=0; i<arrCount; i++){
					json+="{\"info\":\""+arr[i]+"\"}";
				if(i<arrCount-1){
					json+=",";
				}
			}
			json+="]";
			return json;		
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}

/************************************************************
	RANDOM TOKEN GENERATOR
************************************************************/	
	public String getTokenStr(int len) {	
		try{
			 
			// ASCII range � alphanumeric (0-9, a-z, A-Z)
	        final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	 
	        SecureRandom random = new SecureRandom();
	        StringBuilder sb = new StringBuilder();
	 
	        // each iteration of the loop randomly chooses a character from the given
	        // ASCII range and appends it to the `StringBuilder` instance
	        
	        if(len<1 || len>chars.length()){len=chars.length();}
	        
	        for (int i = 0; i < len ; i++)
	        {
	            int randomIndex = random.nextInt(chars.length());
	            sb.append(chars.charAt(randomIndex));
	        }
	 
	        return sb.toString();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}		

	public String getTokenStr() {	
		try{
			 
			// ASCII range � alphanumeric (0-9, a-z, A-Z)
	        final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	 
	        SecureRandom random = new SecureRandom();
	        StringBuilder sb = new StringBuilder();
	 
	        // each iteration of the loop randomly chooses a character from the given
	        // ASCII range and appends it to the `StringBuilder` instance
	        
	        for (int i = 0; i < chars.length(); i++)
	        {
	            int randomIndex = random.nextInt(chars.length());
	            sb.append(chars.charAt(randomIndex));
	        }
	 
	        return sb.toString();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}		
	
/************************************************************
	RANDOM NUMBER GENERATOR IN A SPECIFIC RANGE
************************************************************/	
	public Integer getRandomNumber(int aStart, int aEnd) {	
		try{
			Random random = new Random();
			if (aStart > aEnd) {
			   throw new IllegalArgumentException("Start cannot exceed End.");
			}
			//get the range, casting to long to avoid overflow problems
			long range = (long)aEnd - (long)aStart + 1;
			// compute a fraction of the range, 0 <= frac < range
			long fraction = (long)(range * random.nextDouble());
			int randomNumber =  (int)(fraction + aStart);    
			
			return randomNumber;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}		
/************************************************************
	GET REMOTE / client's IP ADDRESS
************************************************************/	
	public String getRemoteIpAddress() {
		String ipAddress = null;
		try{
			ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
			HttpServletRequest request = sra.getRequest();
            ipAddress = request.getRemoteAddr();
            return ipAddress;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}	

/************************************************************
	FILE HANDELING
************************************************************/
	public String uploadStrutsFile(File uploadedFile,String folderPath,String uploadedFileName,String newFileName){
		try{
			if(uploadedFile!=null){
				uploadedFileName=newFileName.replace(" ", "-")+uploadedFileName.substring(uploadedFileName.length()-6,uploadedFileName.length());						
				uploadedFileName=uploadedFileName.toLowerCase().trim();				
				File fileToCreate = new File(folderPath, uploadedFileName);// Create file name  same as original
				FileUtils.copyFile(uploadedFile, fileToCreate); // Just copy temp file content tos this file     
				return uploadedFileName;
			}
		} catch (Exception e) {
			e.printStackTrace();			
		}
		return null;
	}

	public List<String> uploadMultipleSpringFiles(List<MultipartFile> files,String folderPath,String renameFileName){
		try{
			if(files!=null){
				   List<String> fileNames = new ArrayList<String>();
				    if(null != files && files.size() > 0) {
						for (MultipartFile multipartFile : files) {
							String fileName = multipartFile.getOriginalFilename();
							if(fileName!=null && fileName.length()>2){
								renameFileName=(renameFileName+"-"+fileName.substring(fileName.length()-6,fileName.length())).toLowerCase().trim().replace(" ", "-").replace(")", "").replace("(", "").replace("{", "").replace("}", "").replace("[", "").replace("]", "");
								File convFile = new File(folderPath+renameFileName);
								if(convFile!=null) {									
									multipartFile.transferTo(convFile);
									fileNames.add(renameFileName+"#####"+fileName);
								}
							}
						}
					}          
				return fileNames;
			}
		} catch (Exception e) {
			e.printStackTrace();			
		}
		return null;
	}

	public void copyFile(String sourceFolder, String sourceFile, String destinationFolder, String destinationFile){
		try{
			if(sourceFile!=null && destinationFile!=null ){
		    	FileUtils.copyFile(new File(sourceFolder, sourceFile), new File(destinationFolder, destinationFile)); // Just copy temp file content tos this file 
			}
		} catch (Exception e) {
			e.printStackTrace();			
		}
	}

/************************************************************
	DELETE FILE
************************************************************/

	public Boolean deleteFile(String fileName){
		try{
			File file = new File(fileName);
			if(file.delete()){
    			return true;
    		}
		} catch (Exception e) {
			e.printStackTrace();			
		}
		return false;
	}

	
	/************************************************************
		GET get URL
	************************************************************/
	public String getCurrentActionURL(){
		String url = null;
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		url = request.getServletPath();
		return url;
	}
	
	public String getCurrentFullActionURL(){
		String url = null;
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		url = request.getServletPath();
		if(request.getQueryString()!=null){
			url+="?"+request.getQueryString();
		}
		return url;
	}

	/************************************************************
	   GET Header Information 
	   X-Forwarded-For > The IP address of the client.
	   X-Forwarded-Host > The original host requested by the client in the Host HTTP request header.
	   X-Forwarded-Server > The hostname of the proxy server.
	 ************************************************************/
	public String getHeaderRequest(String type){ 
		String rtn=null;
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();

		if(type!=null){
			rtn = request.getHeader(type); 
		}
		
		return rtn;
	}	
	
	public String getURLRequest(String type){ 
		String rtn=null;
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		
		if(type.equals("RequestURL")){
			rtn = request.getRequestURL().toString(); // Url: http://localhost:8080/urlinfo
		}else if(type.equals("RequestURI")){
			rtn = request.getRequestURI(); // Uri: /urlinfo
		}else if(type.equals("ServerName")){
			rtn = request.getServerName(); // localhost
		}else if(type.equals("QueryString")){
			rtn = request.getQueryString(); 
		}else if(type.equals("Scheme")){
			rtn = request.getScheme(); 
		}else if(type.equals("ServerPort")){
			rtn = String.valueOf(request.getServerPort()); 
		}else if(type.equals("ContextPath")){
			rtn = request.getContextPath(); 
		}else if(type.equals("ServletPath")){
			rtn = request.getServletPath(); 
		}else if(type.equals("PathInfo")){
			rtn = request.getPathInfo(); 
		}else if(type.equals("RemoteAddr")){
			rtn = request.getRemoteAddr();
		}else if(type.equals("RemoteHost")){
			rtn = request.getRemoteHost();
		}
		
		return rtn;
	}
	
	/************************************************************
		GET Sorting URL
	************************************************************/
	public String getSortingUrl(String columnKey){
		String currentURL="";
		
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		currentURL = request.getRequestURI();
		if(request.getQueryString()!=null){
			currentURL+="?"+request.getQueryString()+"&";
		}else{
			currentURL+="?";
		}
		
		if(currentURL!=null && currentURL.indexOf(columnKey)>-1){
			currentURL=currentURL.substring(0,currentURL.indexOf(columnKey));
		}
	
		return currentURL;
	}
	
	/************************************************************
		GET Paging
	************************************************************/
	public String getPaging(Integer totalRows,Integer rowsInPage,Integer currentPage,Boolean previousLink,Boolean nextLink,String pagerKey){
		String pagingTable = null;
		Integer pages,totalPages,extra,totalFound,previousPage,nextPages=0,loopStart,loopEnd,nextPage;
		String currentURL="";
		
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		currentURL = request.getRequestURI();
		if(request.getQueryString()!=null){
			currentURL+="?"+request.getQueryString()+"&";
		}else{
			currentURL+="?";
		}
		
		if(currentURL!=null && currentURL.indexOf(pagerKey)>-1){
			currentURL=currentURL.substring(0,currentURL.indexOf(pagerKey));
		}
		
		pages=totalRows/rowsInPage;
		
		extra=Integer.valueOf(totalRows) % Integer.valueOf(rowsInPage);
		
		if(extra > 0){
			pages++;	
		}
		
		totalPages=pages;
		totalFound=totalRows;
		
		if(totalPages>1){ // if more than one pages then numbering will be shown
			
			pagingTable="<ul>";			  
			
			if(currentPage==null || currentPage<1){currentPage=1;}
					
					//for previous click
					if(previousLink==true){
						previousPage=currentPage-1;
						if(currentPage>1){
							if(previousPage==1){
								pagingTable+="<li><a href='"+currentURL.substring(0,currentURL.length()-1)+"' >Back</a></li>";
							}else{
								pagingTable+="<li><a href='"+currentURL+pagerKey+"="+previousPage+"&totalrecords="+totalRows+"' >Back</a></li>";
							}	
						}
					}
					
					//************** FOR FIRST PAGE BLOCK START **************************************************************
					
						if(currentPage>6 && totalPages>10){
							pagingTable+="<li class='responsive400'><a href='"+currentURL+pagerKey+"=1' >1</a></li><li> ... </li>";
						}
						pagingTable+= "    ";
						
					//************** FOR FIRST PAGE BLOCK END **************************************************************
					
					if(totalPages>10){
						nextPages=totalPages-currentPage;
						
						if(currentPage<7){
							loopStart=1;
							loopEnd=10;
						}else if(nextPages<7){														
							loopStart=currentPage-(9-nextPages);
							loopEnd=currentPage+nextPages;
						}else{
							loopStart=currentPage-4;
							loopEnd=currentPage+5;
						}
					}else{
						loopStart=1;
						loopEnd=totalPages;
					}
					
					
					for(int i=loopStart; i<=loopEnd; i++){		
						if(currentPage==i){
							pagingTable+="<li><a class='active responsive400'>"+i+"</a></li>";
						}else{
							if(i==1){								
								pagingTable+="<li class='responsive400'><a href='"+currentURL.substring(0,currentURL.length()-1)+"'>"+i+"</a></li>";
							}else{
								pagingTable+="<li class='responsive400'><a href='"+currentURL+pagerKey+"="+i+"&totalrecords="+totalRows+"' >"+i+"</a></li>"; 
							}	
						}
						pagingTable+= "    ";
					}
					
					

					//************** FOR LAST PAGE BLOCK START **************************************************************
					
					if(nextPages>6){
						pagingTable+="<li class='responsive400'> ... </li><li class='responsive400'><a href='"+currentURL+pagerKey+"="+totalPages+"' >"+totalPages+"</a></li>";
					}
												
					//************** FOR LAST PAGE BLOCK END **************************************************************
					
					//for next click
					if(nextLink==true){	  
						nextPage=currentPage+1;
						if(currentPage<totalPages){
							pagingTable+="<li><a href='"+currentURL+pagerKey+"="+nextPage+"&totalrecords="+totalRows+"' >Next</a></li>";
						}
					}	
	
					
			pagingTable+="</ul>";		
			if(totalFound<rowsInPage){pagingTable="";}
			
		} // if more than one pages then numbering will be shown
	
		return pagingTable;
	}

	
	/************************************************************
		GET Paging
	************************************************************/
	public String getPaging(Long totalRows,Integer rowsInPage,Integer currentPage,Boolean previousLink,Boolean nextLink,String pagerKey){
		String pagingTable = null;
		long pages;
		Integer totalPages,extra,previousPage,nextPages=0,loopStart,loopEnd,nextPage;
		Long totalFound;
		String currentURL="";
		
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		currentURL = request.getRequestURI();
		if(request.getQueryString()!=null){
			currentURL+="?"+request.getQueryString()+"&";
		}else{
			currentURL+="?";
		}
		
		if(currentURL!=null && currentURL.indexOf(pagerKey)>-1){
			currentURL=currentURL.substring(0,currentURL.indexOf(pagerKey));
		}
		
		pages=totalRows/rowsInPage;
		
		extra=(int) (totalRows % rowsInPage);
		
		if(extra > 0){
			pages++;	
		}
		
		totalPages=(int) pages;
		totalFound=totalRows;
		
		if(totalPages>1){ // if more than one pages then numbering will be shown
			
			pagingTable="<ul>";			  
			
			if(currentPage==null || currentPage<1){currentPage=1;}
					
					//for previous click
					if(previousLink==true){
						previousPage=currentPage-1;
						if(currentPage>1){
							if(previousPage==1){
								pagingTable+="<li><a href='"+currentURL.substring(0,currentURL.length()-1)+"' >Back</a></li>";
							}else{
								pagingTable+="<li><a href='"+currentURL+pagerKey+"="+previousPage+"&totalrecords="+totalRows+"' >Back</a></li>";
							}	
						}
					}
					
					//************** FOR FIRST PAGE BLOCK START **************************************************************
					
						if(currentPage>6 && totalPages>10){
							pagingTable+="<li class='responsive400'><a href='"+currentURL+pagerKey+"=1' >1</a></li><li> ... </li>";
						}
						pagingTable+= "    ";
						
					//************** FOR FIRST PAGE BLOCK END **************************************************************
					
					if(totalPages>10){
						nextPages=totalPages-currentPage;
						
						if(currentPage<7){
							loopStart=1;
							loopEnd=10;
						}else if(nextPages<7){														
							loopStart=currentPage-(9-nextPages);
							loopEnd=currentPage+nextPages;
						}else{
							loopStart=currentPage-4;
							loopEnd=currentPage+5;
						}
					}else{
						loopStart=1;
						loopEnd=totalPages;
					}
					
					
					for(int i=loopStart; i<=loopEnd; i++){		
						if(currentPage==i){
							pagingTable+="<li><a class='active responsive400'>"+i+"</a></li>";
						}else{
							if(i==1){								
								pagingTable+="<li class='responsive400'><a href='"+currentURL.substring(0,currentURL.length()-1)+"'>"+i+"</a></li>";
							}else{
								pagingTable+="<li class='responsive400'><a href='"+currentURL+pagerKey+"="+i+"&totalrecords="+totalRows+"' >"+i+"</a></li>"; 
							}	
						}
						pagingTable+= "    ";
					}
					
					
	
					//************** FOR LAST PAGE BLOCK START **************************************************************
					
					if(nextPages>6){
						pagingTable+="<li class='responsive400'> ... </li><li class='responsive400'><a href='"+currentURL+pagerKey+"="+totalPages+"' >"+totalPages+"</a></li>";
					}
												
					//************** FOR LAST PAGE BLOCK END **************************************************************
					
					//for next click
					if(nextLink==true){	  
						nextPage=currentPage+1;
						if(currentPage<totalPages){
							pagingTable+="<li><a href='"+currentURL+pagerKey+"="+nextPage+"&totalrecords="+totalRows+"' >Next</a></li>";
						}
					}	
	
					
			pagingTable+="</ul>";		
			if(totalFound<rowsInPage){pagingTable="";}
			
		} // if more than one pages then numbering will be shown
	
		return pagingTable;
	}
	
	/************************************************************
		Return Absolute Path Of a File
	************************************************************/	
	public String getAbsolutePath(String fileName) {			
		File f = null;
	      String path = "";
	      boolean bool = false;
	      
	      try{
	         // create new files
	         f = new File(fileName);
	         
	         // returns true if the file exists
	         bool = f.exists();
	         
	         // if file exists
	         if(bool)
	         {
	            // get absolute path
	            path = f.getAbsolutePath();
	            
	            // prints
	            //System.out.print("Absolute Pathname "+ path);
	            return path;
	         }else{
	        	 return null;
	         }
	      }catch(Exception e){
	         // if any error occurs
	         e.printStackTrace();
	      }    
		
	     return null;
	}		

	/************************************************************
		CONVERT STRING TO MD5 
	 ************************************************************/	
	public String getMD5Hashing(String password){

		String md5str=null;
         
		try {
			MessageDigest md = null;
			md = MessageDigest.getInstance("MD5");
			md.update(password.getBytes());
	        
	        byte byteData[] = md.digest();
	 
	        //convert the byte to hex format method 1
	        StringBuffer sb = new StringBuffer();
	        for (int i = 0; i < byteData.length; i++) {
	        	sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
	        }
	        
	        md5str=sb.toString();
	        
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
        
		return md5str;
	}
	
	/************************************************************
	PASSWORD STRING 
	 ************************************************************/	
	public String getPassword(){
	
		String password=null;
	     
		try {
			String[] alpha = {"az1x@","by2e#","cx3f@","dw4h#","ev5d$","fu64$","gt7h#","sh8a@","ri9d#","qj1g@","pk2j#","ol3k3","nm4f@","mz5a#","aol6@","wpk7#","eqj8@#$","xegi9#@","#$sh8rfe","tg7gt#$","uf6ze@#","ve5ce@#","erywd3@#","xc4rf@#","by2fr@#$","rraz7#$"};
			password = this.getRandomNumber(10, 99)+alpha[this.getRandomNumber(0, 25)]+this.getRandomNumber(12, 97);                                   

		} catch (Exception e) {
			e.printStackTrace();
		}
	    
		return password;
	}
	
/************************************************************
	CONVERT First letter capitalize 
************************************************************/	
	public String getUCFirst(String original){
		if (original == null || original.length() == 0) {
	        return original;
	    }
	    return original.substring(0, 1).toUpperCase() + original.substring(1);		
	}
	
/************************************************************
	CONVERT First letter of all words in string 
************************************************************/	
	public String getUCWords(String original){
		String str = null;
		String[] originalArr = original.split(" ");
		
		for(int i=0; i<originalArr.length; i++){
			str+=originalArr[i].substring(0, 1).toUpperCase() + originalArr[i].substring(1) + " ";
		}
		
	    return str.trim();		
	}
	

/************************************************************
	get session variable value 
************************************************************/	
	/*public Object getSession(String sessionString){
		ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = sra.getRequest();
		return request.getSession().getAttribute(sessionString);
	}
*/
/************************************************************
	get String Encode & Decode 
************************************************************/	
	public String getEncode(String str){
		String bytesEncoded=null;
		if(str!=null){
			bytesEncoded = (String) Base64.encode(str.getBytes());
		}
		return bytesEncoded;
	}

	public String getDecode(String str){
		String decodeStr=null;
		if(str!=null){
			byte[] valueDecoded= Base64.decode(str);
			decodeStr = new String(valueDecoded);
		}
		return decodeStr; 
	}
	
/************************************************************
	get Email from Email String 
************************************************************/	
	public String getEmail(String emailStr){
		String emailId=null;		
		if(emailStr!=null){
			if(emailStr.indexOf("<")>-1){
				String[] emailArr=emailStr.split("<");
				emailId=emailArr[1].replace(">","");
			}else{
				emailId=emailStr;
			}
		}
		return emailId;
	}
	
	public String getEmailName(String emailStr){
		String emailName=null;
		if(emailStr!=null){
			if(emailStr.indexOf("<")>-1){
				String[] emailArr=emailStr.split("<");
				emailName=emailArr[0];
			}
		}		
		return emailName;
	}
	
	public String getEmailFromName(String emailStr){
		String emailFromName=null;
		if(emailStr!=null){
			if(emailStr.indexOf("<")>-1){
				String[] emailArr=emailStr.trim().split("<");
				emailFromName=emailArr[1].replaceAll("<", "").replaceAll(">", "").trim();
			}else{
				emailFromName=emailStr.trim().replaceAll("<", "").replaceAll(">", "").trim();
			}
		}		
		return emailFromName;
	}
	
	public Boolean checkValidEmail(String email){
		Boolean valid=false;		
		if(email!=null && email.length()>0) {
			Pattern pattern = Pattern.compile("^(.+)@(.+)$"); 
			Matcher matcher = pattern.matcher(email); 
			valid = matcher.matches();
		}		
		return valid;
	}

/************************************************************
	get Name Format for user 
************************************************************/	
	
	public String getNameFormat(String nameFormat, String  myName){
		String myReturnName=null;
		if(nameFormat!=null && nameFormat.length()>0 && myName!=null && myName.length()>0){
			myName = myName.trim().replace("  "," "); // remove double space
			String[] myNameArr = myName.trim().split(" ");
			if(myNameArr.length>2){
				myReturnName = nameFormat.replace("Ms.",myNameArr[0]);
				myReturnName = myReturnName.replace("FName",myNameArr[1]);
				myReturnName = myReturnName.replace("LName",myNameArr[2]);
				myReturnName = myReturnName.trim();
			}else{
				myReturnName = nameFormat.replace("Ms.","");
				myReturnName = myReturnName.replace("FName",myNameArr[0]);
				myReturnName = myReturnName.replace("LName",myNameArr[1]);
				myReturnName = myReturnName.trim();
			}
		}
		return myReturnName;
	}

	public String replaceNull(Object input) {
		return input == null ? "" : input.toString();
	}
	
	
}
