<%@ include file= "../../EgTrackerAJSON.jsp"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.*"%>
<%@ page import="com.eg.EgURLEncoder" %>
<%@ page import = "com.eg.EgURLDecoder"%>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.EgTimeZoneConverter"%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.text.SimpleDateFormat"%>
<%@ page import = "java.text.DateFormat"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "java.util.StringTokenizer"%>
<%@ page import = "java.util.TreeSet"%>
<%@ page import = "java.util.Iterator"%>
<%@ page import = "java.util.Hashtable"%>
<%@ page import = "java.util.Date"%>
<%@ page import = "java.util.Comparator"%>
<%@ page import = "java.util.*"%>
<%@ page import="net.sf.json.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%!
	String userDateFormat = "";

	public ArrayList addFiles(File[] list)
	{
		ArrayList filesList = new ArrayList();
		try
		{
			if(list != null && list.length > 0)
			{
				for(int i=0;i<list.length;i++)
				{
					if(list[i].isFile())
					{
						String mgrLog  = list[i].getName();
						filesList.add(mgrLog);
					}
				}
				Collections.sort(filesList);
			}
		}
		catch(Exception e)
		{
			return filesList;
		}
		return filesList;
	}
%>
<%
	response.setHeader("Cache-Control","no-store");
	response.setDateHeader("Expires", -1);
	JSONObject rootJson = new JSONObject();
	JSONObject commonObject = new JSONObject();
	JSONArray array =new  JSONArray();
	JSONObject commonObjectNick = new JSONObject();
	JSONArray arrayNick =new  JSONArray();
	JSONObject commonObjectFiles = new JSONObject();
	JSONArray arrayFiles =new  JSONArray();
	JSONObject commonObjectDates = new JSONObject();
	JSONArray arrayDates =new  JSONArray();
	String wholeLine = "";
	try
	{
		String uiFile = "eg_ui.ini";
		String ui_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
		IniFile uiIniFile = new IniFile(ui_iniFile_dir + uiFile);

		String currentDateFormat = uiIniFile.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
		String mgrLogFilePath1 = EgInstallInfo.getInstallDir()+"/manager/logs";
		String mgrLogFilePath2 = EgInstallInfo.getInstallDir()+"/manager/tomcat/logs";

		//get the selected managerIP & log file name
		String filter=request.getParameter("filter");
		if(filter==null)filter="";
		java.util.Date date=null;
		ArrayList textFormatFile=new ArrayList();
		String managerID = request.getParameter("managerIP");
		String mgrLogFile = request.getParameter("mgrLogFile");
		String downloadFlag = request.getParameter("download");
		ArrayList logsDir = new ArrayList();
		logsDir.add("manager/logs");
		File path2 =new File(mgrLogFilePath2);
		if(path2.isDirectory())
		{
			if( path2 != null && path2.listFiles().length > 0)
				logsDir.add("tomcat/logs");
		}
		String logsDirectory = request.getParameter("logsDir");
		if(logsDirectory == null)
			logsDirectory = (String)logsDir.get(0);

		if (!logsDirectory.equals("manager/logs") && !logsDirectory.equals("tomcat/logs"))
		{
			out.println("Not authorized to access the " + logsDirectory + " directory.");
			return;
		}

		//Create the instace for getting the manager ip
		EgSpecsInfo specsObj = new EgSpecsInfo("manager");
		if(managerID == null || managerID.length() <= 0)
			managerID = specsObj.getEGServer();

		ArrayList mgrsIPList = new ArrayList();
		ArrayList mgrLogsList = new ArrayList();
		TreeSet DateDuplication=new  TreeSet();
		Hashtable outputTable=new Hashtable();
		StringTokenizer dateDupicate;
		boolean isStandalone = true;
		boolean isPrimary = false;
		boolean isSecondaryManagagerRunning = false;

		//Checking for the manager is cluster supported or not
		if(EgInstallInfo.isClusterSupported)
		{
			EgManagersIniForManager mi = EgManagersIniForManager.getInstance();
			isStandalone = false;
			String pMgrIP = mi.getPrimaryManagerIP();
			ArrayList sec_mgrs = mi.getSecondaryManagers();
			for(int i=0;i<sec_mgrs.size();i++)
			{
				mgrsIPList.add((String)sec_mgrs.get(i)+" (Secondary)");
			}
			mgrsIPList.add(pMgrIP+" (Primary)");
			if(managerID != null && !managerID.equalsIgnoreCase(pMgrIP))
			{
				EgManagerInfo managerInfo = mi.getManagerlInfo(managerID);
				isSecondaryManagagerRunning = managerInfo.isManagerRunning();
				if(isSecondaryManagagerRunning)
				{
					logsDir.clear();
					if(mgrLogFile != null)
					{
						mgrLogFile = EgURLDecoder.decode(request.getParameter("mgrLogFile"),"UTF-8");
					}
					ArrayList list1 = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile, "list","false","manager/logs");
					ArrayList list2 = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile, "list","false","tomcat/logs");
					if(list1 != null && list1.size() >0)
					{
						logsDir.add("manager/logs");
					}
					if(list2 != null && list2.size() >0)
					{
						logsDir.add("tomcat/logs");
					}
					mgrLogsList = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile, "list","false",logsDirectory);

					if(mgrLogFile == null)
						mgrLogFile = (String)mgrLogsList.get(0);
				}
			}
			else
			{
				isPrimary = true;
			}
		}
		if(isPrimary || isStandalone)
		{
			File mgrLogsPath1 = new File(mgrLogFilePath1);
			File mgrLogsPath2 = new File(mgrLogFilePath2);
			File[] listOfMgrLogFiles1 = mgrLogsPath1.listFiles();
			File[] listOfMgrLogFiles2 = mgrLogsPath2.listFiles();
			if(logsDirectory.equals("tomcat/logs"))
				mgrLogsList = addFiles(listOfMgrLogFiles2);
			else
				mgrLogsList = addFiles(listOfMgrLogFiles1);

			//Remove the extention type files from manager log filess list(mgrLogsList)
			String fileExtention = uiIniFile.getValue("LOG_FILE_LENGTH", "FileExtention");
			StringTokenizer str = new StringTokenizer(fileExtention , ",");
			while(str.hasMoreTokens())
			{
				String ext = str.nextToken();
				for(int j = 0; j < mgrLogsList.size(); j++)
				{
					String mgrLog = (String)mgrLogsList.get(j);
					if(mgrLog.endsWith(ext))
					{
						mgrLogsList.remove(j);
						j--;
					}
				}
			}
			if(mgrLogFile == null)
				mgrLogFile = (String)mgrLogsList.get(0);
		}

		if(downloadFlag != null && downloadFlag.equalsIgnoreCase("true"))
		{
			String filepath = "";
			if(logsDirectory.equalsIgnoreCase("tomcat/logs"))
				filepath = mgrLogFilePath2+"/"+mgrLogFile;
			else
				filepath = mgrLogFilePath1+"/"+mgrLogFile;
			BufferedReader buf=null;
			PrintWriter myOut=null;
			try
			{
				myOut = response.getWriter();
				//read from the file; write to the ServletOutputStream
				if(isSecondaryManagagerRunning)
				{
					response.setContentType("application/text");
					response.setHeader("Content-Disposition","attachment; filename="+mgrLogFile );
					ArrayList resultData = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile,"file","true",logsDirectory);
					long byteSize = 0;
					if(resultData != null && resultData.size() > 0)
					{
						if(!filter.equals("-1") && filter!=null && filter.length() > 0)
						{
							for(int i = 1;i<resultData.size();i++)
							{
								String data = (String)resultData.get(i);
								if(data.startsWith(filter))
								{
									data = data.substring(0,data.lastIndexOf("<br>"));
									myOut.write(data+"\n");
									byteSize += (data+"\n").length() * 2;
								}
							}
						}
						else
						{
							for(int i = 1;i<resultData.size();i++)
							{
								String data = (String)resultData.get(i);
								data = data.substring(0,data.lastIndexOf("<br>"));
								myOut.write(data+"\n");
								byteSize += (data+"\n").length() * 2;
							}
						}
					}
					response.setContentLength((int)byteSize);
				}
				else
				{
					File myfile = new File(filepath);
					//set response headers
					response.setContentType("application/text");
					response.setHeader("Content-Disposition","attachment; filename="+mgrLogFile );
					response.setContentLength((int) myfile.length());
					buf = new BufferedReader(new InputStreamReader(new FileInputStream(myfile),"UTF-8"));
					boolean isLineSkip = false;
					String valStr = uiIniFile.getValue("LOG_FILE_LENGTH", "LengthLimit");
					int value = Integer.parseInt(valStr);
					long skipBytes = 0;
					long fileSize = myfile.length();
					long limitLength = value * 1024 * 1024;
					
					if(fileSize > limitLength)
					{
						skipBytes = fileSize-limitLength;
						buf.skip(skipBytes);
						isLineSkip=true;
					}
					String readBytes = "";
					//read from the file; write to the ServletOutputStream	
					if(!filter.equals("-1") && filter!=null && filter.length() > 0)
					{
						while((readBytes = buf.readLine( )) != null)
						{
							if(readBytes.startsWith(filter))
							{
								myOut.write(readBytes+"\n");
							}
						}
					}
					else
					{
						while((readBytes = buf.readLine( )) != null)
						{
							if(isLineSkip)
							{
								isLineSkip=false;
							}
							else
							{
								myOut.write(readBytes+"\n");
							}
						}
					}
				}
			}
			catch (IOException ioe)
			{
				throw new ServletException(ioe.getMessage());
			}
			finally
			{
				if (myOut != null)
					myOut.close();
				if (buf != null)
					buf.close();
			}
			return;
		}

		if(EgInstallInfo.isClusterSupported)
		{
			for(int k=0;k<mgrsIPList.size();k++)
			{
				String ip = (String)mgrsIPList.get(k);
				String name = ip;
				if(name.indexOf(" (") > 0)
				{
					name = name.substring(0,name.indexOf(" (")+1).trim();
				}
				if(name.equals(managerID))
				{
					if(ip.indexOf(" (") > 0)
					{
						commonObjectNick.put("displayField",ip);
						commonObjectNick.put("valueField",name);
						arrayNick.add(commonObjectNick);
					}
					else
					{
						commonObjectNick.put("displayField",ip);
						commonObjectNick.put("valueField",name);
						arrayNick.add(commonObjectNick);
					}
					mgrsIPList.remove(ip);
				}
			}
			for(int k=0;k<mgrsIPList.size();k++)
			{
				String ip = (String)mgrsIPList.get(k);
				String name = ip;
				if(name.indexOf(" (") > 0)
				{
					name = name.substring(0,name.indexOf(" (")+1).trim();
				}
				if(ip.indexOf(" (") > 0)
				{
					commonObjectNick.put("displayField",ip);
					commonObjectNick.put("valueField",name);
					arrayNick.add(commonObjectNick);
				}
				else
				{
					commonObjectNick.put("displayField",ip);
					commonObjectNick.put("valueField",name);
					arrayNick.add(commonObjectNick);
				}
			}
		//Cluster manager (End)
		}
		else
		{
			commonObjectNick.put("displayField",managerID);
			commonObjectNick.put("valueField",managerID);
			arrayNick.add(commonObjectNick);
		}
		rootJson.put("allowToShowMgrIP",EgInstallInfo.isClusterSupported);
		rootJson.put("nickNameList",arrayNick);

		if(mgrLogsList == null || mgrLogsList.size() <= 0)
		{
			commonObject.put("displayField","No log file found");
			commonObject.put("valueField","-1");
			array.add(commonObject);
		}
		else
		{
			for(int k=0;k<logsDir.size();k++)
			{
				String name = (String)logsDir.get(k);
				commonObject.put("displayField",name);
				commonObject.put("valueField",name);
				array.add(commonObject);
			}
		}
		rootJson.put("logFileDirectoryList",array);

		File f = null;
		long time = 0;
		java.util.Date dt = null;
		if(isPrimary || isStandalone)
		{
			if(logsDirectory.equals("tomcat/logs"))
			{
				f = new File(mgrLogFilePath2+"/"+mgrLogFile);
				if(!f.exists())
				{
					mgrLogFile = (String)mgrLogsList.get(0);
					f = new File(mgrLogFilePath2+"/"+mgrLogFile);
				}
				time = f.lastModified();
				dt = new Date(time);
			}
			else
			{
				f = new File(mgrLogFilePath1+"/"+mgrLogFile);
				if(!f.exists())
				{
					mgrLogFile = (String)mgrLogsList.get(0);
					f = new File(mgrLogFilePath1+"/"+mgrLogFile);
				}
				time = f.lastModified();
				dt = new Date(time);
			}
		}
		else
		{
			if(isSecondaryManagagerRunning)
			{
				try
				{
					ArrayList resultData = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile,"file","false",logsDirectory);
					String timeString = (String)resultData.get(0);
					if(timeString != null && timeString.length() > 0)
						time = Long.parseLong(timeString.substring(timeString.indexOf("@#")+2));
				}
				catch(Exception eg)
				{

				}
				dt = new Date(time);
			}
		}
		if(dt != null)
		{
			SimpleDateFormat sdf = new SimpleDateFormat(currentDateFormat+" "+"HH:mm:ss");
			userDateFormat = sdf.format(dt);
		}
		if(mgrLogsList != null && mgrLogsList.size()>0)
		{
			for(int k=0;k<mgrLogsList.size();k++)
			{
				String name = (String)mgrLogsList.get(k);
				commonObjectFiles.put("displayField",name);
				commonObjectFiles.put("valueField",name);
				arrayFiles.add(commonObjectFiles);
			}
			rootJson.put("logFileNameList",arrayFiles);
		}
		if(isPrimary || isStandalone)
		{
			String lines="";
			String key="";
			String selected="";
			Boolean b=true;
			String filepath = "";

			if(logsDirectory.equalsIgnoreCase("tomcat/logs"))
				filepath = mgrLogFilePath2+"/"+mgrLogFile;
			else
				filepath = mgrLogFilePath1+"/"+mgrLogFile;
			boolean isLineSkip = false;
			File fi = new File(filepath);
			String valStr = uiIniFile.getValue("LOG_FILE_LENGTH", "LengthLimit");
			int value = Integer.parseInt(valStr);
			long skipBytes = 0;
			long fileSize = fi.length();
			long limitLength = value * 1024 * 1024;
			BufferedReader br1 = new BufferedReader(new InputStreamReader(new FileInputStream(fi),"UTF-8"));
			if(fileSize > limitLength)
			{
				skipBytes = fileSize-limitLength;
				br1.skip(skipBytes);
				isLineSkip = true;
			}
			if(mgrLogFile.endsWith(".ini"))
			{
				b=false;
			}
			while((lines=br1.readLine()) != null )
			{
				if(isLineSkip)
				{
					isLineSkip = false;
				}
				else
				{
					textFormatFile.add(lines);
					if(lines!=null && !lines.equals("") && lines.indexOf(" ") >0)
					{
						dateDupicate=new StringTokenizer(lines," ");
						String selectDate=dateDupicate.nextToken();
						if(selectDate.length()==10)
						{
							b=selectDate.indexOf("/") == 2 && selectDate.lastIndexOf("/") == 5;
							if(b)
							{
								DateDuplication.add(selectDate);
							}
						}
					}
					if(lines.indexOf(" ") > -1)
					{
						key=lines.substring(0,lines.indexOf(" "));
						b=key.indexOf("/") == 2 && key.lastIndexOf("/") == 5;
					}
					if(b==true)
					{
						if(outputTable.containsKey(key))
						{
							if(lines.startsWith(key))
							{
								ArrayList temp=(ArrayList)outputTable.get(key);
								temp.add(lines);
								outputTable.put(key,temp);
							}
						}
						else
						{
							ArrayList temp=new ArrayList();
							temp.add(lines);
							outputTable.put(key,temp);
						}
					}
				}
			}
			br1.close();
			ArrayList sortedDate = new ArrayList(DateDuplication);
			if(sortedDate != null && sortedDate.size()>0)
			{
				Collections.sort(sortedDate, new Comparator()
				{
					DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
					public int compare(Object obj1, Object obj2)
					{
						try
						{
							int i = f.parse((String)obj2).compareTo(f.parse((String)obj1));
							return i;
						}
						catch (Exception e)
						{
							throw new IllegalArgumentException(e);
						}
					}
				});
			}
			if(b==false)
			{
				if (filter==null || filter.length() == 0)
				filter="";
			}
			if(b==true)
			{
				if (filter == null || filter.length() == 0 && sortedDate.size() > 0)
				{
					commonObjectDates.put("displayField","No Filter");
					commonObjectDates.put("valueField","");
					arrayDates.add(commonObjectDates);
				}
				for(int k=0 ; k < sortedDate.size(); k++)
				{
					String dateValue=(String)sortedDate.get(k);
					{
						date=new java.text.SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(dateValue);
						SimpleDateFormat sdf = new SimpleDateFormat(currentDateFormat);
						String UI_DATE_FORMAT=(String)sdf.format(date);
						commonObjectDates.put("displayField",UI_DATE_FORMAT);
						commonObjectDates.put("valueField",dateValue);
						arrayDates.add(commonObjectDates);
					}
				}
				if(arrayDates.size()==0)
				{
					commonObjectDates.put("displayField","Please choose a date");
					commonObjectDates.put("valueField","-1");
					arrayDates.add(commonObjectDates);
				}
			}
			else if(b== false)
			{
				commonObjectDates.put("displayField","Please choose a date");
				commonObjectDates.put("valueField","-1");
				arrayDates.add(commonObjectDates);
			}
			rootJson.put("dateFilterList",arrayDates);
			if(b==false && textFormatFile.size() > 0)
			{
				int size = textFormatFile.size();
				StringBuffer wholeLine1 = new StringBuffer();
				String currentDateLog = null;
				for(int x=0;x<size;x++)
				{
					currentDateLog=(String)textFormatFile.get(x);
					wholeLine1.append(currentDateLog);
					wholeLine1.append("\n");
				}
				wholeLine = wholeLine1.toString();
			}
			if(filter!=null && filter.length()>0)
			{
				ArrayList FilterList=(ArrayList)outputTable.get(filter);
				if(FilterList != null && FilterList.size()>0)
				{
					int size = FilterList.size();
					StringBuffer wholeLine1 = new StringBuffer();
					String currentDateLog = null;
					for(int i=0; i < size;i++)
					{
						currentDateLog=(String)FilterList.get(i);
						wholeLine1.append(currentDateLog);
						wholeLine1.append("\n");
					}
					wholeLine = wholeLine1.toString();
				}
			}
			else
			{
				if(b== true && textFormatFile!=null && textFormatFile.size() > 0)
				{
					int size = textFormatFile.size();
					StringBuffer wholeLine1 = new StringBuffer();
					String currentDateLog = null;
					for(int x=0;x<size;x++)
					{
						currentDateLog=(String)textFormatFile.get(x);
						wholeLine1.append(currentDateLog);
						wholeLine1.append("\n");
					}
					wholeLine = wholeLine1.toString();
				}
			}
			out.println(rootJson.toString() + "~#~" + userDateFormat+"^^^"+wholeLine);
		}
		else
		{
			if(!isSecondaryManagagerRunning)
			{
				out.println("#$#The secondary manager is not running" + "^$^"+rootJson.toString() + "~#~" + userDateFormat);
			}
			else
			{
				Boolean b=true;
				String key="";
				if(mgrLogFile.endsWith(".ini"))
				{
					b=false;
				}
				ArrayList resultData = PMClusterHelper.getSecondaryManagerLogFiles(managerID ,mgrLogFile,"file","false",logsDirectory);
				StringBuffer wholeLine1 = new StringBuffer();
				String currentDateLog = null;
				String lines="";
				if(resultData != null && resultData.size() > 0)
				{
					for(int i = 1;i<resultData.size();i++)
					{
						lines=(String)resultData.get(i);
						if(lines!=null && !lines.equals("") && lines.indexOf(" ") >0)
						{
							dateDupicate=new StringTokenizer(lines," ");
							String selectDate=dateDupicate.nextToken();
							if(selectDate.length()==10)
							{
								b=selectDate.indexOf("/") == 2 && selectDate.lastIndexOf("/") == 5;
								if(b)
								{
									DateDuplication.add(selectDate);
								}
							}
						}
						if(lines.indexOf(" ") > -1)
						{
							key=lines.substring(0,lines.indexOf(" "));
							b=key.indexOf("/") == 2 && key.lastIndexOf("/") == 5;
						}
						if(b==true)
						{
							if(outputTable.containsKey(key))
							{
								if(lines.startsWith(key))
								{
									ArrayList temp=(ArrayList)outputTable.get(key);
									temp.add(lines);
									outputTable.put(key,temp);
								}
							}
							else
							{
								ArrayList temp=new ArrayList();
								temp.add(lines);
								outputTable.put(key,temp);
							}
						}
					}
					ArrayList sortedDate = new ArrayList(DateDuplication);
					if(sortedDate != null && sortedDate.size()> 0)
					{
						Collections.sort(sortedDate, new Comparator()
						{
							DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
							public int compare(Object obj1, Object obj2)
							{
								try
								{
									int i = f.parse((String)obj2).compareTo(f.parse((String)obj1));
									return i;
								}
								catch (Exception e)
								{
									throw new IllegalArgumentException(e);
								}
							}
						});
					}
					if(b==true)
					{
						if (filter==null || filter.length() == 0 && sortedDate.size() > 0)
						{
							commonObjectDates.put("displayField","No Filter");
							commonObjectDates.put("valueField","");
							arrayDates.add(commonObjectDates);
						}
					}
					if(b==false)
					{
						if (filter==null || filter.length() == 0)
						filter="";
					}
					if(b==true)
					{
						for(int k=0 ; k < sortedDate.size(); k++)
						{
							String dateValue=(String)sortedDate.get(k);
							{
								date=new java.text.SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(dateValue);
								SimpleDateFormat sdf = new SimpleDateFormat(currentDateFormat);
								String UI_DATE_FORMAT=(String)sdf.format(date);
								commonObjectDates.put("displayField",UI_DATE_FORMAT);
								commonObjectDates.put("valueField",dateValue);
								arrayDates.add(commonObjectDates);
							}
						}
						if(arrayDates.size()==0)
						{
							commonObjectDates.put("displayField","Please choose a date");
							commonObjectDates.put("valueField","-1");
							arrayDates.add(commonObjectDates);
						}
					}
					else if(b== false)
					{
						commonObjectDates.put("displayField","Please choose a date");
						commonObjectDates.put("valueField","-1");
						arrayDates.add(commonObjectDates);
					}
					rootJson.put("dateFilterList",arrayDates);
					if( b==false && resultData.size() > 0)
					{
						for(int i = 1;i<resultData.size();i++)
						{
							currentDateLog=(String)resultData.get(i);
							if(currentDateLog.lastIndexOf("<br>")> -1)
							{
								currentDateLog = currentDateLog.substring(0,currentDateLog.lastIndexOf("<br>"));
							}
							wholeLine1.append(currentDateLog);
							wholeLine1.append("\n");
						}
					}
					if(filter!=null && filter.length()> 0)
					{
						ArrayList FilterList=(ArrayList)outputTable.get(filter);
						if(FilterList != null && FilterList.size()> 0)
						{
							int size = FilterList.size();
							for(int i=0; i < size;i++)
							{
								currentDateLog=(String)FilterList.get(i);
								if(currentDateLog.lastIndexOf("<br>")> -1)
								{
									currentDateLog = currentDateLog.substring(0,currentDateLog.lastIndexOf("<br>"));
								}
								wholeLine1.append(currentDateLog);
								wholeLine1.append("\n");
							}
						}
					}
					else
					{
						if(b== true && resultData!=null && resultData.size() > 0)
						{
							for(int i = 1;i<resultData.size();i++)
							{
								currentDateLog=(String)resultData.get(i);
								if(currentDateLog.lastIndexOf("<br>")> -1)
								{
									currentDateLog = currentDateLog.substring(0,currentDateLog.lastIndexOf("<br>"));
								}
								wholeLine1.append(currentDateLog);
								wholeLine1.append("\n");
							}
						}
					}
					out.println(rootJson.toString() + "~#~" + userDateFormat+"^^^"+wholeLine1.toString());
				}
				else
				{
					out.println("#$#No data found"+ "^$^"+rootJson.toString() + "~#~" + userDateFormat);
				}
			}
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}

	if(request.getQueryString()!= null)
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgManagerLogView.jsp?"+request.getQueryString());
	}
	else
	{
		session.setAttribute("adminLastAccessedURL","/final/admin/EgManagerLogView.jsp");
	}
%>



