EAR Utility 1.1
Very useful tool for J2EE programmers.
This is a tool to compare the two EAR files, which is developed in Java Swing.
This can be used to compare the production EAR and the modified EAR files before deploying the new EAR into productions. This will help to find the missing and modified files easily.
The html and text report gives the full details.
The main class is EARUtility.class.
To know how to use this tool please sees the following document. http://www.geocities.com/jjprojects/EARUtility.doc, which gives the full details about the programs.
//CustomAbstractTableModel.java
/*******************************************************************************
*
* Designed by : A. Augustine Joseph Starting Date : 11-01-2003 Last modified by :
* A. Augustine Joseph Last modified Date : 17-01-2003 Total number of Class : 1
* Total number of Methods : 6 Class Description : The class is used for
* creating a sub class that use the Abstract Table model.
*
******************************************************************************/
package com.jjprojects.earutility;
import javax.swing.table.AbstractTableModel;
public class CustomAbstractTableModel extends AbstractTableModel
{
int x = 0, y = 0;
String cells[][];
boolean option = false;
int TableNo = 0;
int clsid = 0;
EARFilesComparingTool objEARFilesCompare = null;
FilesComparingTool objFilesComparingTool = null;
/***************************************************************************
*
* Method Description : Constructor used for diffencating the calling class
* and gettig some property from the calling class Method Parameter1 :
* IndividualTeacherSchedule Method Parameter1 Value : Calling Class Method
* Parameter2 : int Method Parameter2 Value : Number of rows in the table
* Method Parameter3 : int Method Parameter3 Value : Number of columns in
* the table Method Parameter4 : boolean Method Parameter4 Value : Weather
* the table is editable or not Method Parameter5 : int Method Parameter5
* Value : Calling class Id
*
* Method Return Type : No Use of Return Value : No
*
**************************************************************************/
public CustomAbstractTableModel(EARFilesComparingTool i, int rows, int cols,
boolean editable, int CalledBy)
{
objEARFilesCompare = i;
option = editable;
x = rows;
y = cols;
clsid = CalledBy;
cells = new String[x][y];
}
public CustomAbstractTableModel(FilesComparingTool i, int rows, int cols,
boolean editable, int CalledBy)
{
objFilesComparingTool = i;
option = editable;
x = rows;
y = cols;
clsid = CalledBy;
cells = new String[x][y];
}
/***************************************************************************
*
* Method Description : This method is set for setting weather the cell is
* edited or not Method Parameter1 : int Method Parameter1 Value : Current
* Row Method Parameter2 : int Method Parameter2 Value : Current Column
*
* Method Return Type : boolean Use of Return Value : Weather the cell is
* edited or not.
*
**************************************************************************/
public boolean isCellEditable(int row, int col)
{
return false;
}
/***************************************************************************
*
* Method Description : This method is used for getting row count Method
* Parameter : No Method Parameter Value : No
*
* Method Return Type : int Use of Return Value : Total Number of Row.
* //
**************************************************************************/
public int getRowCount()
{
return x;
}
/***************************************************************************
*
* Method Description : This method is used for getting column count Method
* Parameter : No Method Parameter Value : No
*
* Method Return Type : int Use of Return Value : Total Number of column.
*
**************************************************************************/
public int getColumnCount()
{
return y;
}
/***************************************************************************
*
* Method Description : This method is used for getting the value at a
* purticular cell Method Parameter1 : int Method Parameter1 Value : Current
* Row Method Parameter2 : int Method Parameter2 Value : Current Column
*
* Method Return Type : Object Use of Return Value : The condents of the
* Cell
*
**************************************************************************/
public Object getValueAt(int r, int c)
{
return cells[r][c];
}
/***************************************************************************
*
* Method Description : This method is set for setting weather the cell is
* edited or not Method Parameter1 : Object Method Parameter1 Value : The
* value to set in the Row Method Parameter2 : int Method Parameter2 Value :
* Current Row Method Parameter3 : int Method Parameter3 Value : Current
* Column
*
* Method Return Type : Void Use of Return Value : No
*
**************************************************************************/
public void setValueAt(Object value, int row, int column)
{
cells[row][column] = (String) value;
fireTableRowsUpdated(row, column);
}
}
//custom**********.java
/*
* Created on Apr 14, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import java.io.File;
import javax.swing.filechooser.FileFilter;
/**
* @author U678864 TODO To change the template for this generated type comment
* go to Window - Preferences - Java - Code Style - Code Templates
*/
public class CustomFileChooserFilter extends FileFilter
{
String strExtention = null;
String strDisplayValue = null;
public CustomFileChooserFilter(String strDisplayValue, String strExtention)
{
this.strExtention = strExtention;
this.strDisplayValue = strDisplayValue;
}
public boolean accept(File file)
{
String filename = file.getName();
if (file.isDirectory())
{
return true;
}
else if (filename.endsWith(this.strExtention))
{
return true;
}
else
{
if(this.strExtention.equals("*"))
{
if(filename.endsWith(".ear"))
{
return true;
}
else if(filename.endsWith(".war"))
{
return true;
}
else if(filename.endsWith(".jar"))
{
return true;
}
else if(filename.endsWith(".zip"))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
public String getDescription()
{
return this.strDisplayValue;
}
}
//custom********.java
/*******************************************************************************
*
* Designed by : A. Augustine Joseph Starting Date : 11-01-2003 Last modified by :
* A. Augustine Joseph Last modified Date : 17-01-2003 Total number of Class : 1
* Total number of Methods : 3 Class Description : The class is used for
* changing the font and color of the table
*
******************************************************************************/
package com.jjprojects.earutility;
import java.awt.*;
import javax.swing.table.TableCellRenderer;
import javax.swing.*;
import javax.swing.border.LineBorder;
public class CustomTableRenderer extends JLabel implements TableCellRenderer
{
Font font = new Font("Times New Roman", Font.PLAIN, 15);
Color colrEqual = new Color(0,128,64);
Color colrNotEqual = new Color(164,0,0);
Color colrFileMissing = new Color(0,0,160);
ImageIcon imgicnEqual = new ImageIcon("images/Equal.gif");
ImageIcon imgicnNotEqual = new ImageIcon("images/NotEqual.gif");
ImageIcon imgicnFileMissing = new ImageIcon("images/Star.gif");
ImageIcon imgicnBlank = new ImageIcon();
// Font fontBold = new Font("Times New Roman", Font.BOLD, 15);
// Font fontMargin = new Font("Times New Roman", Font.BOLD, 25);
int classid = 0;
EARFilesComparingTool objEARFilesCompare = null;
FilesComparingTool objFilesComparingTool = null;
/******************************************************************************
Method Description : Constructor used for diffencating the calling class and gettig some property from the calling class
Method Parameter1 : IndividualTeacherSchedule
Method Parameter1 Value : Calling Class
Method Parameter2 : int
Method Parameter2 Value : Calling Class ID
Method Return Type : No
Use of Return Value : No
******************************************************************************/
public CustomTableRenderer(EARFilesComparingTool i,int ctrl)
{
objEARFilesCompare = i;
classid=ctrl;
setOpaque(true);
setFont(font);
}
public CustomTableRenderer(FilesComparingTool i,int ctrl)
{
objFilesComparingTool = i;
classid=ctrl;
setOpaque(true);
setFont(font);
}
/***************************************************************************
*
* Method Description : This method is used for displaying the cell value
* correctly
*
* Method Parameter1 : JTable Method Parameter1 Value : Curent Table Method
* Parameter2 : Object Method Parameter2 Value : Current Value Method
* Parameter3 : boolean Method Parameter3 Value : Checking weather the
* current cell is selected Method Parameter4 : boolean Method Parameter4
* Value : Checking weather the current cell is focus Method Parameter5 :
* int Method Parameter5 Value : Current Row Method Parameter6 : int Method
* Parameter6 Value : Current Column
*
* Method Return Type : Component Use of Return Value : The Current Cell
* Value
*
**************************************************************************/
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
this.setFont(font);
setBackground(Color.white);
this.setHorizontalAlignment(JLabel.LEFT);
if (classid == 1)
{
String strEqualityStatus = (String) objEARFilesCompare.vecEqualityStatus.get(row);
if(strEqualityStatus.equals("EQUAL"))
{
if(column == 1)
{
setIcon(imgicnEqual);
String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
this.setToolTipText(strEqualityStatusDetails);
setValue(null);
}
else
{
setForeground(colrEqual);
setIcon(imgicnBlank);
setValue(value);
this.setToolTipText(null);
}
}
else if(strEqualityStatus.equals("NOT EQUAL"))
{
if(column == 1)
{
setIcon(imgicnNotEqual);
String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
this.setToolTipText(strEqualityStatusDetails);
setValue(null);
}
else
{
setForeground(colrNotEqual);
setIcon(imgicnBlank);
setValue(value);
this.setToolTipText(null);
}
}
else if(strEqualityStatus.equals("FILE MISSING"))
{
if(column == 1)
{
setIcon(imgicnFileMissing);
String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
this.setToolTipText(strEqualityStatusDetails);
setValue(null);
}
else
{
setForeground(colrFileMissing);
setIcon(imgicnBlank);
setValue(value);
this.setToolTipText(null);
}
}
if (isSelected)
{
setForeground(Color.BLACK);
}
}
else if (classid == 2)
{
String strFirstFileName = (String) objFilesComparingTool.vecFirstFileContent.get(row);
String strSecondFileName = (String) objFilesComparingTool.vecSecondFileContent.get(row);
if(strFirstFileName.equals(strSecondFileName))
{
setForeground(Color.MAGENTA);
}
else
{
setForeground(Color.GREEN);
}
setValue(value);
}
return this;
}
/***************************************************************************
*
* Method Description : This method is used for displaying the cell value
* correctly
*
* Method Parameter : Object Method Parameter Value : Current Value
*
* Method Return Type : Void Use of Return Value : No
*
**************************************************************************/
protected void setValue(Object value)
{
setText((value == null) ? "" : value.toString());
}
}
//CustomTreeRender
package com.jjprojects.earutility;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.border.LineBorder;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
class CustomTreeRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer
{
JLabel lblTableColumn;
int classid=0;
Font fontPlain = new Font("Sans Serif", Font.PLAIN, 11);
ImageIcon imgicnRoot = null;
ImageIcon imgicnProject = null;
ImageIcon imgicnTestType = null;
ImageIcon imgicnModule = null;
ImageIcon imgicnTestCase = null;
String strLabelText = null;
EARFileViewingTool objEARCompareAndViewTool = null;
public CustomTreeRenderer(EARFileViewingTool parent,int clsid)
{
imgicnRoot = new ImageIcon("images/Root.gif");
imgicnProject = new ImageIcon("images/Project.gif");
imgicnTestType = new ImageIcon("images/TestType.gif");
imgicnModule = new ImageIcon("images/Module.gif");
imgicnTestCase = new ImageIcon("images/TestCase.gif");
objEARCompareAndViewTool = parent;
classid=clsid;
}
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean selected, boolean expanded,
boolean leaf,int row, boolean hasFocus)
{
setBackgroundSelectionColor(Color.WHITE);
setTextNonSelectionColor(Color.BLACK);
setTextSelectionColor(Color.BLUE);
if(classid==1)
{
Component c = (super.getTreeCellRendererComponent(tree,value, selected, expanded, leaf, row, hasFocus));
lblTableColumn = (JLabel)c;
lblTableColumn.setFont(fontPlain);
// if(row == 0)
// {
// lblTableColumn.setIcon(imgicnRoot);
// }
String strValue = lblTableColumn.getText();
if(selected)
{
strLabelText = lblTableColumn.getText();
lblTableColumn.setText("" + strLabelText + "");
}
}
return (lblTableColumn);
}
}
//EarfilescomparingTool
package com.jjprojects.earutility;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class EARFilesComparingTool implements ActionListener
{
private ImageIcon imgicnExcel = new ImageIcon("images/Excel.gif");
private ImageIcon imgicnInternerExplore = new ImageIcon("images/InternerExplore.gif");
private ImageIcon imgicnNotepad = new ImageIcon("images/Notepad.gif");
JDialog dlgEARFileCompareTool = null;
JTable tableEARCompare = null;
Vector vecFirstEARFilesContent = null;
Vector vecSecondEARFilesContent = null;
Vector vecFirstEARFilesLastModifiedDate = null;
Vector vecSecondEARFilesLastModifiedDate = null;
Vector vecFirstEARFilesSize = null;
Vector vecSecondEARFilesSize = null;
Vector vecEqualityStatus = null;
Vector vecEqualityStatusDetails = null;
String strGlobleFirstEARFileName = null;
String strGlobleSecondEARFileName = null;
private JButton btnGenerateReport;
JCheckBox chkMissingFiles;
JCheckBox chkChangedFiles;
JCheckBox chkSimilarFiles;
JDialog dlgReportSelection;
int intSimilarFileCount;
int intModifiedFileCount;
int intMissingFirstFileCount;
int intMissingSecondFileCount;
private String strReportType;
private JButton btnHtmlReport;
private JButton btnTextReport;
String strFirstParentFileName = null;
String strSecondParentFileName = null;
public void compareFilesinEar(String strFirstParentFileName, String strSecondParentFileName,
String strFirstEARFileName, String strSecondEARFileName)
{
strGlobleFirstEARFileName = strFirstEARFileName;
strGlobleSecondEARFileName = strSecondEARFileName;
this.strFirstParentFileName = strFirstParentFileName;
this.strSecondParentFileName = strSecondParentFileName;
vecFirstEARFilesContent = new Vector(10000);
vecSecondEARFilesContent = new Vector(10000);
vecFirstEARFilesLastModifiedDate = new Vector(10000);
vecSecondEARFilesLastModifiedDate = new Vector(10000);
vecFirstEARFilesSize = new Vector(10000);
vecSecondEARFilesSize = new Vector(10000);
vecEqualityStatus = new Vector();
vecEqualityStatusDetails = new Vector();
try
{
ZipFile zipfilFirstEAR = new ZipFile(strFirstEARFileName);
for (Enumeration enmEntries = zipfilFirstEAR.entries(); enmEntries.hasMoreElements();)
{
ZipEntry zipEtyEARFiles = ((ZipEntry) enmEntries.nextElement());
String strEARFileDetails = zipEtyEARFiles.getName();
if(strEARFileDetails.contains("."))
{
vecFirstEARFilesContent.add(strEARFileDetails);
vecFirstEARFilesLastModifiedDate.add(zipEtyEARFiles.getTime()+"");
vecFirstEARFilesSize.add(zipEtyEARFiles.getSize()+"");
}
}
}
catch (IOException e)
{
JOptionPane.showMessageDialog(dlgEARFileCompareTool, "Error in opening the file"
, "File selection error", JOptionPane.ERROR_MESSAGE);
EARUtility.log4jEARUtility.fatal("Exception", e);
return;
}
//Storing the second ear file details
try
{
ZipFile zipfilSecondEAR = new ZipFile(strSecondEARFileName);
for (Enumeration enmEntries = zipfilSecondEAR.entries(); enmEntries.hasMoreElements();)
{
ZipEntry zipEtyEARFiles = ((ZipEntry) enmEntries.nextElement());
String strEARFileDetails = zipEtyEARFiles.toString();
if(strEARFileDetails.contains("."))
{
vecSecondEARFilesContent.add(strEARFileDetails);
vecSecondEARFilesLastModifiedDate.add(zipEtyEARFiles.getTime()+"");
vecSecondEARFilesSize.add(zipEtyEARFiles.getSize()+"");
}
}
}
catch (IOException e)
{
EARUtility.log4jEARUtility.fatal("Exception", e);
}
int intReturnValue = arrangeVectorsInCorrectOrder();
if(intReturnValue == 0)
{
setEARFilesComparisonDetails();
showEARFilesCompareDialog();
}
}
public int arrangeVectorsInCorrectOrder()
{
int intFirstEarSize = vecFirstEARFilesContent.size();
int intSecondEarSize = vecSecondEARFilesContent.size();
Vector vecMissedFilesBasicDetails = new Vector(1000);
if(intFirstEarSize < intSecondEarSize)
{
//Take the Second ear file as Reference
for(int i=0;i
String strSecondEarContent = (String) vecSecondEARFilesContent.get(i);
if(vecFirstEARFilesContent.contains(strSecondEarContent))
{
int intPositionOfValueInFirstJar = vecFirstEARFilesContent.indexOf(strSecondEarContent);
if(intPositionOfValueInFirstJar >= 0)
{
if(intPositionOfValueInFirstJar > i)
{
int intRowsNeedToInsert = intPositionOfValueInFirstJar - i;
for(int j=0;j
vecSecondEARFilesContent.insertElementAt("", i);
vecSecondEARFilesLastModifiedDate.insertElementAt("", i);
vecSecondEARFilesSize.insertElementAt("", i);
i++;
intSecondEarSize++;
}
}
}
}
else
{
vecMissedFilesBasicDetails.add(strSecondEarContent + " is missing in first file");
vecFirstEARFilesContent.insertElementAt("", i);
vecFirstEARFilesLastModifiedDate.insertElementAt("", i);
vecFirstEARFilesSize.insertElementAt("", i);
}
}
intFirstEarSize = vecFirstEARFilesContent.size();
intSecondEarSize = vecSecondEARFilesContent.size();
int intSizeDifference = intFirstEarSize - intSecondEarSize;
if(intSizeDifference > 0)
{
for(int i=0;i
String strFirstFileContent = vecFirstEARFilesContent.get((intSecondEarSize + i)).toString();
strFirstFileContent = strFirstFileContent.replaceAll("/", ".");
vecMissedFilesBasicDetails.add(strFirstFileContent + " is missing in second file");
vecSecondEARFilesContent.add("");
vecSecondEARFilesLastModifiedDate.add("");
vecSecondEARFilesSize.add("");
}
}
}
else if(intFirstEarSize > intSecondEarSize)
{
//Take the First ear file as Reference
for(int i=0;i
String strFirstEarContent = (String) vecFirstEARFilesContent.get(i);
if(vecSecondEARFilesContent.contains(strFirstEarContent))
{
int intPositionOfValueInSecondJar = vecSecondEARFilesContent.indexOf(strFirstEarContent);
if(intPositionOfValueInSecondJar >= 0)
{
if(intPositionOfValueInSecondJar > i)
{
int intRowsNeedToInsert = intPositionOfValueInSecondJar - i;
for(int j=0;j
vecFirstEARFilesContent.insertElementAt("", i);
vecFirstEARFilesLastModifiedDate.insertElementAt("", i);
vecFirstEARFilesSize.insertElementAt("", i);
i++;
intFirstEarSize++;
}
}
}
}
else
{
vecMissedFilesBasicDetails.add(strFirstEarContent + " is missing in second file");
vecSecondEARFilesContent.insertElementAt("", i);
vecSecondEARFilesLastModifiedDate.insertElementAt("", i);
vecSecondEARFilesSize.insertElementAt("", i);
}
}
intFirstEarSize = vecFirstEARFilesContent.size();
intSecondEarSize = vecSecondEARFilesContent.size();
int intSizeDifference = intSecondEarSize - intFirstEarSize;
if(intSizeDifference > 0)
{
for(int i=0;i
String strSecondFileContent = vecSecondEARFilesContent.get((intFirstEarSize + i)).toString();
strSecondFileContent = strSecondFileContent.replaceAll("/", ".");
vecMissedFilesBasicDetails.add(strSecondFileContent + " is missing in first file");
vecFirstEARFilesContent.add("");
vecFirstEARFilesLastModifiedDate.add("");
vecFirstEARFilesSize.add("");
}
}
}
else if(intFirstEarSize == intSecondEarSize)
{
String strFirstEarContent = null;
String strSecondEarContent = null;
for(int i=0;i
strFirstEarContent = (String) vecFirstEARFilesContent.get(i);
strSecondEarContent = (String) vecSecondEARFilesContent.get(i);
if(!(vecSecondEARFilesContent.contains(strFirstEarContent)))
{
vecFirstEARFilesContent.insertElementAt("", i);
vecFirstEARFilesLastModifiedDate.insertElementAt("", i);
vecFirstEARFilesSize.insertElementAt("", i);
}
}
intFirstEarSize = vecFirstEARFilesContent.size();
int intSizeDifference = intFirstEarSize - intSecondEarSize;
int intFinalTotalSize = intFirstEarSize + intSizeDifference;
if(intSizeDifference > 0)
{
for(int i=intFirstEarSize;i
vecSecondEARFilesContent.add("");
vecSecondEARFilesLastModifiedDate.add("");
vecSecondEARFilesSize.add("");
}
}
for(int i=0;i
strFirstEarContent = (String) vecFirstEARFilesContent.get(i);
strSecondEarContent = (String) vecSecondEARFilesContent.get(i);
if(strFirstEarContent.equals(""))
{
vecMissedFilesBasicDetails.add(strSecondEarContent + " is missing in first file");
}
if(strSecondEarContent.equals(""))
{
vecMissedFilesBasicDetails.add(strFirstEarContent + " is missing in second file");
}
}
}
int intReturnValue = showErrorMessageDialog(vecMissedFilesBasicDetails);
return intReturnValue;
}
public int showErrorMessageDialog(Vector vecMissedFilesBasicDetails)
{
System.out.println("vecMissedFilesBasicDetails->" + vecMissedFilesBasicDetails);
int intSize = vecMissedFilesBasicDetails.size();
if(intSize > 20)
{
StringBuffer strbufHTMLContent = new StringBuffer("More than 20 files are missing in the files.
");
strbufHTMLContent.append("Do you want to see the full details?");
strbufHTMLContent.append("");
int intDialogSelection = JOptionPane.showConfirmDialog(dlgEARFileCompareTool, strbufHTMLContent.toString()
, "Missing file details", JOptionPane.YES_NO_OPTION);
return intDialogSelection;
}
else if(intSize <= 0)
{
StringBuffer strbufHTMLContent = new StringBuffer("The file names and count are same in both files
");
strbufHTMLContent.append("Do you want to see the full details?");
strbufHTMLContent.append("");
int intDialogSelection = JOptionPane.showConfirmDialog(dlgEARFileCompareTool, strbufHTMLContent
, "Missing file details", JOptionPane.YES_NO_OPTION);
return intDialogSelection;
}
else
{
StringBuffer strbufHTMLContent = new StringBuffer("Missing File Details.
");
strbufHTMLContent.append("
- ");
- " + vecMissedFilesBasicDetails.get(i) + " ");
for(int i=0;i
strbufHTMLContent.append("
}
strbufHTMLContent.append("
strbufHTMLContent.append("Do you want to see the full details?");
strbufHTMLContent.append("");
int intDialogSelection = JOptionPane.showConfirmDialog(dlgEARFileCompareTool, strbufHTMLContent
, "Missing file details", JOptionPane.YES_NO_OPTION);
return intDialogSelection;
}
}
public void setEARFilesComparisonDetails()
{
int intSize = vecFirstEARFilesContent.size();
String strFirstEarContent = null;
String strSecondEarContent = null;
for(int i=0;i
strFirstEarContent = (String) vecFirstEARFilesContent.get(i);
strSecondEarContent = (String) vecSecondEARFilesContent.get(i);
if(strFirstEarContent != null && strFirstEarContent.trim().length() != 0
&& strSecondEarContent != null && strSecondEarContent.trim().length() != 0)
{
String strFirstEARFilesLastModifiedDate = (String) vecFirstEARFilesLastModifiedDate.get(i);
String strSecondEARFilesLastModifiedDate = (String) vecSecondEARFilesLastModifiedDate.get(i);
String strFirstEARFilesSize = (String) vecFirstEARFilesSize.get(i);
String strSecondEARFilesSize = (String) vecSecondEARFilesSize.get(i);
if(strFirstEARFilesLastModifiedDate.equals(strSecondEARFilesLastModifiedDate) &&
strFirstEARFilesSize.equals(strSecondEARFilesSize))
{
vecEqualityStatus.add("EQUAL");
vecEqualityStatusDetails.add("Files have same size and last modified date");
}
else
{
if(!(strFirstEARFilesSize.equals(strSecondEARFilesSize)))
{
vecEqualityStatus.add("NOT EQUAL");
vecEqualityStatusDetails.add("Files have different file size");
}
else if(!(strFirstEARFilesLastModifiedDate.equals(strSecondEARFilesLastModifiedDate)))
{
vecEqualityStatus.add("NOT EQUAL");
vecEqualityStatusDetails.add("Files have different last modified date");
}
}
}
else
{
if(strFirstEarContent != null && strFirstEarContent.trim().length() == 0)
{
vecEqualityStatus.add("FILE MISSING");
vecEqualityStatusDetails.add("File " + strSecondEarContent + " is missing in First JAR file");
}
else if (strSecondEarContent != null && strSecondEarContent.trim().length() == 0)
{
vecEqualityStatus.add("FILE MISSING");
vecEqualityStatusDetails.add("File " + strFirstEarContent + " is missing in Second JAR file");
}
}
}
}
public void showEARFilesCompareDialog()
{
int intTotalNumberOfRecords = vecSecondEARFilesContent.size();
dlgEARFileCompareTool = new JDialog(EARUtility.frmEARUtility, "EAR Compare details", true);
JPanel panlFirstEARFile = new JPanel();
JPanel panlSecondEARFile = new JPanel();
CustomAbstractTableModel cstbAddFields = new CustomAbstractTableModel(
this, intTotalNumberOfRecords, 3, true, 1);//rows,cols
int intWidthForEachColumn = (EARUtility.intActualWidth - 16) / 2;
TableColumn tabcolFirstEarContent = null;
TableColumn tabcolEqualOrNot = null;
TableColumn tabcolSecondEarContent = null;
if(this.strFirstParentFileName.equals("") || this.strSecondParentFileName.equals(""))
{
tabcolFirstEarContent = TableDesigner.createColumn(0, intWidthForEachColumn, strGlobleFirstEARFileName);
tabcolEqualOrNot = TableDesigner.createColumn(1, 16, "");
tabcolSecondEarContent = TableDesigner.createColumn(2, intWidthForEachColumn, strGlobleSecondEARFileName);
}
else
{
int intFirstFileLastIndex = strGlobleFirstEARFileName.lastIndexOf("\\");
int intSecondFileLastIndex = strGlobleSecondEARFileName.lastIndexOf("\\");
String strOnlyCurrentFirstFileName = strGlobleFirstEARFileName.substring(intFirstFileLastIndex);
String strOnlyCurrentSecondFileName = strGlobleSecondEARFileName.substring(intSecondFileLastIndex);
strFirstParentFileName = strFirstParentFileName + strOnlyCurrentFirstFileName;
strSecondParentFileName = strSecondParentFileName + strOnlyCurrentSecondFileName;
tabcolFirstEarContent = TableDesigner.createColumn(0, intWidthForEachColumn, strFirstParentFileName);
tabcolEqualOrNot = TableDesigner.createColumn(1, 16, "");
tabcolSecondEarContent = TableDesigner.createColumn(2, intWidthForEachColumn, strSecondParentFileName);
}
tabcolFirstEarContent.setMinWidth(intWidthForEachColumn);
tabcolEqualOrNot.setMinWidth(16);
tabcolEqualOrNot.setMaxWidth(16);
tabcolSecondEarContent.setMinWidth(intWidthForEachColumn);
TableColumnModel tabcolmdlRecycleBinManager = TableDesigner
.createColumnModelForThreeRow(tabcolFirstEarContent, tabcolEqualOrNot, tabcolSecondEarContent);
JTableHeader tabheadRecycleBinManager = TableDesigner
.createTableHeader(tabcolmdlRecycleBinManager);
tableEARCompare = TableDesigner.createTable(cstbAddFields,
tabcolmdlRecycleBinManager, tabheadRecycleBinManager, 0, 20,
true, false, true, 0);
tableEARCompare.setBackground(Color.WHITE);
tableEARCompare.setForeground(Color.WHITE);
CustomTableRenderer trpref = new CustomTableRenderer(this, 1);
tableEARCompare.setDefaultRenderer(Object.class, trpref);
tableEARCompare.setCursor(EARUtility.curHand);
int intSize = vecFirstEARFilesContent.size();
String strFirstEarContent = null;
String strSecondEarContent = null;
for(int i=0;i
strFirstEarContent = (String) vecFirstEARFilesContent.get(i);
strSecondEarContent = (String) vecSecondEARFilesContent.get(i);
strFirstEarContent = strFirstEarContent.replaceAll("/", ".");
strSecondEarContent = strSecondEarContent.replaceAll("/", ".");
tableEARCompare.setValueAt(strFirstEarContent,i,0);
tableEARCompare.setValueAt(strSecondEarContent,i,2);
}
JScrollPane sclpanEARCompare = new JScrollPane(
tableEARCompare, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableEARCompare.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
int intClickCount = e.getClickCount();
if(intClickCount == 2)
{
int intSelectedRow = tableEARCompare.getSelectedRow();
if(intSelectedRow >= 0)
{
String strFirstEarContent = (String)tableEARCompare.getValueAt(intSelectedRow,0);
String strSecondEarContent = (String)tableEARCompare.getValueAt(intSelectedRow,2);
if((strFirstEarContent != null && strFirstEarContent.trim().length() > 0)
&& (strSecondEarContent != null && strSecondEarContent.trim().length() > 0))
{
int intFirstEARContentDotLastIndex = strFirstEarContent.lastIndexOf(".");
int intSecondEARContentDotLastIndex = strSecondEarContent.lastIndexOf(".");
String strFirstEARContentExtention = strFirstEarContent.substring(++intFirstEARContentDotLastIndex);
String strSecondEARContentExtention = strSecondEarContent.substring(++intSecondEARContentDotLastIndex);
String strFileDestinationPath1 = null;
String strFileDestinationPath2 = null;
if((strFirstEARContentExtention.equals("jar") ||
strFirstEARContentExtention.equals("ear") ||
strFirstEARContentExtention.equals("war") ||
strFirstEARContentExtention.equals("zip")) &&
(strSecondEARContentExtention.equals("jar") ||
strSecondEARContentExtention.equals("ear") ||
strSecondEARContentExtention.equals("war") ||
strSecondEARContentExtention.equals("zip")))
{
//Getting the exacte value from the ear file
try
{
ZipInputStream in = new ZipInputStream(new FileInputStream(strGlobleFirstEARFileName));
// Get the first entry
ZipEntry entry = in.getNextEntry();
String strFileDestinationPath = EARUtility.strGlobleTemperoryDirectoryLocation + new Date().getTime();
while(entry != null)
{
String strFilePath = entry.getName();
if(strFilePath.equals(strFirstEarContent))
{
strFileDestinationPath1 = strFileDestinationPath + "\\1";
extractInnerFiles(strFirstEarContent, in, strFileDestinationPath1);
}
entry = in.getNextEntry();
}
//Extracting the second file
ZipInputStream in1 = new ZipInputStream(new FileInputStream(strGlobleSecondEARFileName));
// Get the first entry
ZipEntry entry1 = in1.getNextEntry();
while(entry1 != null)
{
String strFilePath = entry1.getName();
if(strFilePath.equals(strSecondEarContent))
{
strFileDestinationPath2 = strFileDestinationPath + "\\2";
extractInnerFiles(strSecondEarContent, in1, strFileDestinationPath2);
}
entry1 = in1.getNextEntry();
}
in.close();
in1.close();
String strFinalPathForFirstContent = strFileDestinationPath1 + "\\" + strFirstEarContent;
String strFinalPathForSecondContent = strFileDestinationPath2 + "\\" + strSecondEarContent;
File f = new File(strFinalPathForFirstContent);
new EARFilesComparingTool().compareFilesinEar(strGlobleFirstEARFileName, strGlobleSecondEARFileName,
strFinalPathForFirstContent, strFinalPathForSecondContent);
}
catch (IOException ioe)
{
EARUtility.log4jEARUtility.fatal("Exception", ioe);
}
}
}
}
}
}
});
panlFirstEARFile.setLayout(new BorderLayout());
panlFirstEARFile.add(sclpanEARCompare, BorderLayout.CENTER);
btnHtmlReport = new JButton(imgicnInternerExplore);
btnTextReport = new JButton(imgicnNotepad);
btnHtmlReport.addActionListener(this);
btnTextReport.addActionListener(this);
panlSecondEARFile.setLayout(new FlowLayout(FlowLayout.LEFT));
panlSecondEARFile.add(btnHtmlReport);
panlSecondEARFile.add(btnTextReport);
dlgEARFileCompareTool.add(panlFirstEARFile);
dlgEARFileCompareTool.add(panlSecondEARFile, BorderLayout.NORTH);
dlgEARFileCompareTool.setSize(EARUtility.intActualWidth, EARUtility.intActualHeight);
dlgEARFileCompareTool.setVisible(true);
}
public void extractInnerFiles(String strEarFileContent, ZipInputStream in, String strFileDestinationPath)
{
File fileDestination = new File(strFileDestinationPath);
boolean boolProjectAlreadyExists = fileDestination.exists();
if(!boolProjectAlreadyExists)
{
boolean boolProjectCreated = fileDestination.mkdirs();
try
{
String strOutputFileName = strFileDestinationPath + "\\" + strEarFileContent;
OutputStream out = new FileOutputStream(strOutputFileName);
byte[] byteFileBuffer = new byte[1024];
int intFileContent;
while ((intFileContent = in.read(byteFileBuffer)) > 0)
{
out.write(byteFileBuffer, 0, intFileContent);
}
out.close();
}
catch(Exception e)
{
e.printStackTrace();
EARUtility.log4jEARUtility.fatal("Exception", e);
}
}
}
public void showReportGenerateDialog()
{
dlgReportSelection = new JDialog(dlgEARFileCompareTool, "Report Generation", true);
JPanel panlFileSelection = new JPanel();
chkMissingFiles = new JCheckBox("Missing Files");
chkChangedFiles = new JCheckBox("Changed Files");
chkSimilarFiles = new JCheckBox("Similar Files");
btnGenerateReport = new JButton("Generate");
btnGenerateReport.addActionListener(this);
panlFileSelection.setLayout(null);
chkSimilarFiles.setBounds(20, 20, 100, 20);
chkMissingFiles.setBounds(20, 45, 100, 20);
chkChangedFiles.setBounds(20, 70, 110, 20);
panlFileSelection.add(chkMissingFiles);
panlFileSelection.add(chkChangedFiles);
panlFileSelection.add(chkSimilarFiles);
TitledBorder titledBorder = BorderFactory.createTitledBorder("File Selection");
panlFileSelection.setBorder(titledBorder);
dlgReportSelection.setLayout(null);
panlFileSelection.setBounds(10, 10, 140, 100);
btnGenerateReport.setBounds(30, 117, 100, 20);
dlgReportSelection.add(panlFileSelection);
dlgReportSelection.add(btnGenerateReport);
dlgReportSelection.setResizable(false);
dlgReportSelection.setSize(170, 180);
dlgReportSelection.setLocationRelativeTo(dlgEARFileCompareTool);
dlgReportSelection.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btnHtmlReport)
{
strReportType = "Html";
showReportGenerateDialog();
}
else if(e.getSource() == btnTextReport)
{
strReportType = "Text";
showReportGenerateDialog();
}
else if(e.getSource() == btnGenerateReport)
{
if(strReportType.equals("Html"))
{
HtmlReportCreator objHtmlReportCreator = new HtmlReportCreator(this);
objHtmlReportCreator.generateHTMLReport(EARUtility.strGlobleHTMLReportLocation);
}
else if(strReportType.equals("Text"))
{
TextReportCreator objTextReportCreator = new TextReportCreator(this);
objTextReportCreator.generateTextReport(EARUtility.strGlobleTextReportLocation);
}
}
}
}
//earviewingtool.java
/*
* Created on Mar 29, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.*;
import javax.swing.JTree;
import javax.swing.tree.*;
import java.io.BufferedWriter;
public class EARFileViewingTool implements ActionListener
{
static Cursor curHand = new Cursor(Cursor.HAND_CURSOR);
LinkedHashMap lnkhmapFullEARDetails = new LinkedHashMap();
static JDialog dlgEARExploreTool = null;
JTree treeEARFileDetails = null;
DefaultMutableTreeNode root = null;
JButton btnClose = null;
JScrollPane jspRecycleBinManager = null;
String strGlobleCurrentFileDestinationPath = null;
String strGlobleCurrentSelectedEARFile = null;
JTextArea txtaraTreeNodeDetails = null;
String strLastSelectedNode = null;
String strCurrentSelectedNode= null;
DefaultMutableTreeNode[] dmtnodeCurrent = new DefaultMutableTreeNode[10000];
int intTreeRowCount = 0;
public void showEARExploreDialog(String strEARFile)
{
strGlobleCurrentSelectedEARFile = strEARFile;
dlgEARExploreTool = new JDialog(EARUtility.frmEARUtility, "EAR Explorer", true);
treeEARFileDetails = new JTree(new DefaultMutableTreeNode());
treeEARFileDetails.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeEARFileDetails.setCellRenderer(new CustomTreeRenderer(this,1));
jspRecycleBinManager = new JScrollPane(
treeEARFileDetails, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
dlgEARExploreTool.add(jspRecycleBinManager);
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
treeEARFileDetails = new JTree(new DefaultMutableTreeNode());
treeEARFileDetails.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeEARFileDetails.setCellRenderer(new CustomTreeRenderer(this,1));
String strFileDestinationPath = "\\Temp\\" + new Date().getTime() + "/";
extractCurrentFile(strEARFile, strFileDestinationPath);
root = showFiles(root, strFileDestinationPath);
root.setUserObject(strEARFile);
treeEARFileDetails = new JTree(root);
treeEARFileDetails.setCursor(curHand);
treeEARFileDetails.setBackground(Color.WHITE);
treeEARFileDetails.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{}
});
btnClose = new JButton("Close");
btnClose.addActionListener(this);
jspRecycleBinManager = new JScrollPane(
treeEARFileDetails, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
txtaraTreeNodeDetails = new JTextArea();
JScrollPane jspTreeNodeDetails = new JScrollPane(
txtaraTreeNodeDetails, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JSplitPane spltpanEARFileView = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT, false, jspRecycleBinManager,
jspTreeNodeDetails);
spltpanEARFileView.setDividerLocation(300);
spltpanEARFileView.setDividerSize(2);
dlgEARExploreTool.getContentPane().add(spltpanEARFileView);
dlgEARExploreTool.add(spltpanEARFileView, BorderLayout.CENTER);
JPanel panlButton = new JPanel();
panlButton.setLayout(new FlowLayout(FlowLayout.RIGHT));
panlButton.add(btnClose);
dlgEARExploreTool.add(panlButton, BorderLayout.NORTH);
dlgEARExploreTool.setSize(EARUtility.intActualWidth, EARUtility.intActualHeight);
dlgEARExploreTool.setVisible(true);
}
public DefaultMutableTreeNode showFiles(DefaultMutableTreeNode dmtnodeParent, String strCurrentFileStructure)
{
File fileCurrent = new File(strCurrentFileStructure);
File[] filearrCurrentChilds = fileCurrent.listFiles();
for(int i=0;i
if(filearrCurrentChilds[i].isDirectory())
{
String strCurrentFile = filearrCurrentChilds[i].toString();
int intLastSlashIndex = strCurrentFile.lastIndexOf("\\");
String strCurrentFileNameAlone = strCurrentFile.substring(++intLastSlashIndex);
dmtnodeCurrent[intTreeRowCount] = new DefaultMutableTreeNode(strCurrentFileNameAlone);
dmtnodeParent.add(dmtnodeCurrent[intTreeRowCount]);
intTreeRowCount++;
getChildNodeDetails(dmtnodeCurrent[(intTreeRowCount - 1)], filearrCurrentChilds[i]);
}
else
{
String strCurrentFile = filearrCurrentChilds[i].toString();
int intLastSlashIndex = strCurrentFile.lastIndexOf("\\");
String strOnlyFileName = strCurrentFile.substring(++intLastSlashIndex);
dmtnodeCurrent[intTreeRowCount] = new DefaultMutableTreeNode(strOnlyFileName);
dmtnodeParent.add(dmtnodeCurrent[intTreeRowCount]);
}
}
return dmtnodeParent;
}
public void getChildNodeDetails(DefaultMutableTreeNode dmtnodeParent, File fileCurrent)
{
File[] filearrCurrentChildNodes = fileCurrent.listFiles();
for(int i=0;i
if(filearrCurrentChildNodes[i].isDirectory())
{
String strCurrentFile = filearrCurrentChildNodes[i].toString();
int intLastSlashIndex = strCurrentFile.lastIndexOf("\\");
String strCurrentFileNameAlone = strCurrentFile.substring(++intLastSlashIndex);
dmtnodeCurrent[intTreeRowCount] = new DefaultMutableTreeNode(strCurrentFileNameAlone);
dmtnodeParent.add(dmtnodeCurrent[intTreeRowCount]);
intTreeRowCount++;
getChildNodeDetails(dmtnodeCurrent[(intTreeRowCount - 1)], filearrCurrentChildNodes[i]);
}
else
{
String strCurrentFile = filearrCurrentChildNodes[i].toString();
int intLastSlashIndex = strCurrentFile.lastIndexOf("\\");
String strOnlyFileName = strCurrentFile.substring(++intLastSlashIndex);
dmtnodeCurrent[intTreeRowCount] = new DefaultMutableTreeNode(strOnlyFileName);
dmtnodeParent.add(dmtnodeCurrent[intTreeRowCount]);
intTreeRowCount++;
}
}
}
public void extractCurrentFile(String strEarFilePathAndName, String strFileDestinationPath)
{
try
{
// Open the ZIP file
ZipInputStream in = new ZipInputStream(new FileInputStream(strEarFilePathAndName));
// Get the first entry
ZipEntry entry = in.getNextEntry();
int i = 0;
while(entry != null)
{
String strZipFileEntity = entry.getName();
if(!(strZipFileEntity.contains(".")))
{
entry = in.getNextEntry();
continue;
}
//Check for destination path
File fileDestination = new File(strFileDestinationPath);
boolean boolDestinationAlreadyExists = fileDestination.exists();
// boolDestinationAlreadyExists);
if(!boolDestinationAlreadyExists)
{
boolean boolProjectCreated = fileDestination.mkdir();
// "boolProjectCreated = " + boolProjectCreated);
}
//Open the output file
String strFileNameAndDirectoryWithoutDrive = strEarFilePathAndName.substring(2);
String strOutputFileName = fileDestination + "/" + strZipFileEntity;
// "strOutputFileNamestrOutputFileName->" + strOutputFileName);
//Check for existince
int intLastIndex = strOutputFileName.lastIndexOf("/");
if(intLastIndex >= 0)
{
String strOnlyDirectory = strOutputFileName.substring(0, ++intLastIndex);
// "!!!!!!!!!!!!!" + strOnlyDirectory);
File fileToCheck = new File(strOnlyDirectory);
if(!(fileToCheck.exists()))
{
fileToCheck.mkdirs();
}
}
OutputStream out = new FileOutputStream(strOutputFileName);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
i++;
out.close();
entry = in.getNextEntry();
}
in.close();
}
catch (IOException e)
{
EARUtility.log4jEARUtility.fatal("Exception", e);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btnClose)
{
dlgEARExploreTool.setVisible(false);
}
}
public static void main(String[] args)
{
new EARFileViewingTool().showEARExploreDialog("JPMCDEPENDENTS.jar");
}
}
//Earutility.java
/*
* Created on Apr 14, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Properties;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
public class EARUtility implements ActionListener
{
static Cursor curHand = new Cursor(Cursor.HAND_CURSOR);
static Logger log4jEARUtility = null;
static JFrame frmEARUtility = null;
JDialog dlgEarCompareFileCollect = null;
RoundTextField txtFirstEARFile = null;
RoundTextField txtSecondEARFile = null;
JButton btnBrowseFirstEarFile = null;
JButton btnBrowseSecondEarFile = null;
JButton btnCompare = null;
JButton btnCancel = null;
JButton btnEARViewer = null;
JButton btnEARCompare = null;
static int intActualHeight = 0;
static int intActualWidth = 0;
JMenuItem mitemFileViewEARFile = null;
JMenuItem mitemFileCompareEARFiles = null;
JMenuItem mitemFileExit = null;
JMenuItem mitemHelpContents = null;
JMenuItem mitemHelpAbout = null;
public static String strGlobleExcelReportLocation;
public static String strGlobleHTMLReportLocation;
public static String strGlobleTextReportLocation;
public static String strGlobleTemperoryDirectoryLocation;
public void showEARUtilityFrame()
{
try
{
WindowsLookAndFeel w = new WindowsLookAndFeel();
UIManager.setLookAndFeel(w);
}
catch(Exception e)
{
e.printStackTrace();
}
//Initializing Log4J
PatternLayout myLayout = new PatternLayout("%-4r [%t] %-5p %c %x - %m%n");
ConsoleAppender consoleAppender = new ConsoleAppender(myLayout);
RollingFileAppender rollingFileAppender = null;
try
{
rollingFileAppender = new RollingFileAppender(myLayout,"\\log4joutput.log",true);
rollingFileAppender.setMaxFileSize("100KB");
}
catch(Exception e)
{
e.printStackTrace();
}
log4jEARUtility = Logger.getLogger("EARUtility");
log4jEARUtility.addAppender(consoleAppender);
log4jEARUtility.addAppender(rollingFileAppender);
log4jEARUtility.setLevel(Level.INFO);
log4jEARUtility.info("Starting EAR Utility Program.");
Toolkit tolkitEARCompare = Toolkit.getDefaultToolkit();
Dimension dimEARCompare = tolkitEARCompare.getScreenSize();
intActualHeight = dimEARCompare.height - 27;
intActualWidth = dimEARCompare.width;
frmEARUtility = new JFrame("EAR Utility 1.0");
frmEARUtility.getContentPane().setBackground(Color.WHITE);
frmEARUtility.setResizable(false);
JLabel lblHeading = new JLabel("EAR Utility 1.1");
Font fontHeading = new Font("Times New Roman", Font.BOLD, 35);
lblHeading.setForeground(Color.BLUE);
lblHeading.setFont(fontHeading);
btnEARViewer = new JButton("
EAR");
btnEARCompare = new JButton("
EAR");
lblHeading.setBounds(60, 20, 300, 50);
btnEARViewer.setBounds(50, 80, 100, 70);
btnEARCompare.setBounds(200, 80, 100, 70);
btnEARViewer.addActionListener(this);
btnEARCompare.addActionListener(this);
createMenuBar();
frmEARUtility.setLayout(null);
frmEARUtility.add(lblHeading);
frmEARUtility.add(btnEARViewer);
frmEARUtility.add(btnEARCompare);
frmEARUtility.setSize(350, 250);
frmEARUtility.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmEARUtility.setLocationRelativeTo(new JFrame());
frmEARUtility.setVisible(true);
}
public void createMenuBar()
{
JMenuBar mbarJGUITester = new JMenuBar();
JMenu menuFile = new JMenu("File");
menuFile.setMnemonic('F');
JMenu menuHelp = new JMenu("Help");
menuHelp.setMnemonic('H');
mbarJGUITester.add(menuFile);
mbarJGUITester.add(menuHelp);
mitemFileViewEARFile = new JMenuItem("View EAR File");
mitemFileCompareEARFiles = new JMenuItem("Compare EAR Files");
mitemFileExit = new JMenuItem("Exit");
mitemFileViewEARFile.setMnemonic('V');
mitemFileCompareEARFiles.setMnemonic('C');
mitemFileExit.setMnemonic('x');
mitemHelpContents = new JMenuItem("Contents");
mitemHelpAbout = new JMenuItem("About");
mitemHelpContents.addActionListener(this);
mitemHelpAbout.addActionListener(this);
mitemHelpContents.setMnemonic('C');
mitemHelpAbout.setMnemonic('A');
mitemFileViewEARFile.addActionListener(this);
mitemFileCompareEARFiles.addActionListener(this);
mitemFileExit.addActionListener(this);
menuFile.add(mitemFileViewEARFile);
menuFile.add(mitemFileCompareEARFiles);
menuFile.add(mitemFileExit);
menuHelp.add(mitemHelpContents);
menuHelp.add(mitemHelpAbout);
frmEARUtility.setJMenuBar(mbarJGUITester);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btnEARCompare || e.getSource() == mitemFileCompareEARFiles)
{
showEARFilesDetailCollectingDialog();
}
else if(e.getSource() == btnEARViewer || e.getSource() == mitemFileViewEARFile)
{
String strFileToOpen = showEAROpeningFileChooser();
if(strFileToOpen != null)
{
new EARFileViewingTool().showEARExploreDialog(strFileToOpen);
}
}
else if(e.getSource() == btnBrowseFirstEarFile)
{
String strFileName = showEARSelectingFileChooser();
if(strFileName != null)
{
txtFirstEARFile.setText(strFileName);
}
}
else if(e.getSource() == btnBrowseSecondEarFile)
{
String strFileName = showEARSelectingFileChooser();
if(strFileName != null)
{
txtSecondEARFile.setText(strFileName);
}
}
else if(e.getSource() == btnCompare)
{
String strFirstEarFile = txtFirstEARFile.getText();
String strSecondEarFile = txtSecondEARFile.getText();
if((strFirstEarFile != null && strFirstEarFile.trim().length() <= 0))
{
JOptionPane.showMessageDialog(dlgEarCompareFileCollect, "Please select the frist file to compare");
return;
}
if((strSecondEarFile != null && strSecondEarFile.trim().length() <= 0))
{
JOptionPane.showMessageDialog(dlgEarCompareFileCollect, "Please select the second file to compare");
return;
}
if(strFirstEarFile.equals(strSecondEarFile))
{
JOptionPane.showMessageDialog(dlgEarCompareFileCollect, "Please select two different files to compare");
return;
}
dlgEarCompareFileCollect.setVisible(false);
new EARFilesComparingTool().compareFilesinEar("", "", strFirstEarFile, strSecondEarFile);
}
else if(e.getSource() == btnCancel)
{
dlgEarCompareFileCollect.setVisible(false);
}
else if(e.getSource() == mitemFileExit)
{
System.exit(0);
}
else if(e.getSource() == mitemHelpContents)
{
JOptionPane.showMessageDialog(frmEARUtility, "Under Construction
Will added in the next version", "Under Construction", JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource() == mitemHelpAbout)
{
String strAboutDetails = new StringBuffer()
.append("EAR UtilityVersion 1.1")
.append("
Developed By
")
.append("A.Augustine Joseph
")
.append("Cognizant Technology Solutions
")
.append("Augustine.Joseph@cognizant.com
").toString();
JOptionPane.showMessageDialog(frmEARUtility, strAboutDetails
, "About...", JOptionPane.INFORMATION_MESSAGE);
}
}
public void showEARFilesDetailCollectingDialog()
{
dlgEarCompareFileCollect = new JDialog(frmEARUtility, "Compare EAR File", true);
txtFirstEARFile = new RoundTextField(0, Color.PINK, Color.WHITE, true);
txtSecondEARFile = new RoundTextField(0, Color.PINK, Color.WHITE, true);
txtFirstEARFile.setEditable(false);
txtSecondEARFile.setEditable(false);
btnBrowseFirstEarFile = new JButton("Browse...");
btnBrowseSecondEarFile = new JButton("Browse...");
btnCompare = new JButton("Compare");
btnCancel = new JButton("Cancel");
btnBrowseFirstEarFile.addActionListener(this);
btnBrowseSecondEarFile.addActionListener(this);
btnCompare.addActionListener(this);
btnCancel.addActionListener(this);
dlgEarCompareFileCollect.setLayout(null);
dlgEarCompareFileCollect.getContentPane().add(txtFirstEARFile);
dlgEarCompareFileCollect.getContentPane().add(txtSecondEARFile);
dlgEarCompareFileCollect.getContentPane().add(btnBrowseFirstEarFile);
dlgEarCompareFileCollect.getContentPane().add(btnBrowseSecondEarFile);
dlgEarCompareFileCollect.getContentPane().add(btnCompare);
dlgEarCompareFileCollect.getContentPane().add(btnCancel);
txtFirstEARFile.setBounds(10, 10, 400, 20);
btnBrowseFirstEarFile.setBounds(420, 10, 100, 20);
txtSecondEARFile.setBounds(10, 40, 400, 20);
btnBrowseSecondEarFile.setBounds(420, 40, 100, 20);
btnCompare.setBounds(420, 70, 100, 20);
btnCancel.setBounds(310, 70, 100, 20);
dlgEarCompareFileCollect.setSize(540, 135);
dlgEarCompareFileCollect.setLocationRelativeTo(frmEARUtility);
dlgEarCompareFileCollect.setVisible(true);
}
public String showEARSelectingFileChooser()
{
JFileChooser filcsrSelectEARFile = new JFileChooser();
filcsrSelectEARFile.setAcceptAllFileFilterUsed(false);
filcsrSelectEARFile.setApproveButtonText("Select File");
filcsrSelectEARFile.setApproveButtonMnemonic('S');
filcsrSelectEARFile.setApproveButtonToolTipText("Select an EAR ,WAR ,JAR or ZIP File to Compare");
filcsrSelectEARFile.setDialogTitle("Select an EAR ,WAR ,JAR or ZIP File to Compare");
filcsrSelectEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Enterprise Archive (*.ear)", "ear"));
filcsrSelectEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Web Archive (*.war)", "war"));
filcsrSelectEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Java Archive (*.jar)", "jar"));
filcsrSelectEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Zip Archive (*.zip)", "zip"));
filcsrSelectEARFile.addChoosableFileFilter(new CustomFileChooserFilter("All Archive (*.ear, *.war, *.jar, &.zip)", "*"));
filcsrSelectEARFile.showSaveDialog(dlgEarCompareFileCollect);
// Get the currently selected file
File fileSelected = filcsrSelectEARFile.getSelectedFile();
String strSelectedFile = null;
if(fileSelected != null)
{
strSelectedFile = fileSelected.toString();
// System.out.println("strSelectedFile->" + strSelectedFile);
}
return strSelectedFile;
}
public String showEAROpeningFileChooser()
{
JFileChooser filcsrOpenEARFile = new JFileChooser();
filcsrOpenEARFile.setAcceptAllFileFilterUsed(false);
filcsrOpenEARFile.setApproveButtonText("Open File");
filcsrOpenEARFile.setApproveButtonMnemonic('O');
filcsrOpenEARFile.setApproveButtonToolTipText("Open an EAR ,WAR ,JAR or ZIP File to Explore");
filcsrOpenEARFile.setDialogTitle("Open an EAR ,WAR ,JAR or ZIP File to Explore");
filcsrOpenEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Enterprise Archive (*.ear)", "ear"));
filcsrOpenEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Web Archive (*.war)", "war"));
filcsrOpenEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Java Archive (*.jar)", "jar"));
filcsrOpenEARFile.addChoosableFileFilter(new CustomFileChooserFilter("Zip Archive (*.zip)", "zip"));
filcsrOpenEARFile.addChoosableFileFilter(new CustomFileChooserFilter("All Archive (*.ear, *.war, *.jar, &.zip)", "*"));
filcsrOpenEARFile.showOpenDialog(frmEARUtility);
// Get the currently selected file
File fileToOpen = filcsrOpenEARFile.getSelectedFile();
String strFileToOpen = null;
if(fileToOpen != null)
{
strFileToOpen = fileToOpen.toString();
}
return strFileToOpen;
}
public void loadFromPropertyFile()
{
Properties propEARCompare = new Properties();
String strDeletedFileProperties = "EARCompare.properties";
try
{
FileInputStream flinstDeleteProject = new FileInputStream(strDeletedFileProperties);
propEARCompare.load(flinstDeleteProject);
System.out.println("->" + propEARCompare);
Enumeration enumEARCompare = propEARCompare.keys();
while(enumEARCompare.hasMoreElements())
{
String strKey = enumEARCompare.nextElement().toString();
if(strKey.equals("ExcelReport"))
{
strGlobleExcelReportLocation = propEARCompare.get(strKey).toString();
}
else if(strKey.equals("HTMLReport"))
{
strGlobleHTMLReportLocation = propEARCompare.get(strKey).toString();
}
else if(strKey.equals("TextReport"))
{
strGlobleTextReportLocation = propEARCompare.get(strKey).toString();
}
else if(strKey.equals("TemperoryDirectory"))
{
strGlobleTemperoryDirectoryLocation = propEARCompare.get(strKey).toString();
}
}
flinstDeleteProject.close();
}
catch(Exception re)
{
re.printStackTrace();
}
}
public static void main(String[] args)
{
EARUtility objEARUtility = new EARUtility();
objEARUtility.loadFromPropertyFile();
objEARUtility.showEARUtilityFrame();
}
}
//filescomparingtool.java
package com.jjprojects.earutility;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FilesComparingTool
{
JDialog dlgEARFileCompareTool = null;
JTable tableFileCompare = null;
Vector vecFirstFileContent = new Vector();
Vector vecSecondFileContent = new Vector();
public void compareFileContents(String strFirstFileName, String strSecondFileName)
{
vecFirstFileContent = extractAllLinesFromFile(strFirstFileName);
vecSecondFileContent = extractAllLinesFromFile(strSecondFileName);
System.out.println("First Vector->" + vecFirstFileContent);
System.out.println("SecondVector->" + vecSecondFileContent);
arrangeVectorsInCorrectOrder();
System.out.println("First Vector->" + vecFirstFileContent);
System.out.println("SecondVector->" + vecSecondFileContent);
System.out.println("First Vector SIZE->" + vecFirstFileContent.size());
System.out.println("SecondVector SIZE->" + vecSecondFileContent.size());
//Displaying the Dialog
showEARFilesCompareDialog();
}
public Vector extractAllLinesFromFile(String strFileName)
{
Vector vecFileContent = new Vector();
String strCurrentRecord = null;
try
{
BufferedReader bufrdrInputData = new BufferedReader(new FileReader(strFileName));
while ((strCurrentRecord = bufrdrInputData.readLine()) != null)
{
vecFileContent.add(strCurrentRecord);
}
}
catch(Exception e)
{
EARUtility.log4jEARUtility.fatal("Error in extracting file for file comparision", e);
}
return vecFileContent;
}
public void arrangeVectorsInCorrectOrder()
{
int intFirstEarSize = vecFirstFileContent.size();
int intSecondEarSize = vecSecondFileContent.size();
// Vector vecMissedFilesBasicDetails = new Vector(1000);
if(intFirstEarSize < intSecondEarSize)
{
//Take the Second ear file as Reference
for(int i=0;i
String strSecondEarContent = (String) vecSecondFileContent.get(i);
int intPositionOfValueInFirstJar = checkSameLineAfterCurrentLine(vecFirstFileContent, strSecondEarContent, i);
System.out.println("Jesus" + intPositionOfValueInFirstJar);
if(intPositionOfValueInFirstJar < 0)
{
continue;
}
if(intPositionOfValueInFirstJar >= 0)
{
if(intPositionOfValueInFirstJar > i)
{
int intRowsNeedToInsert = intPositionOfValueInFirstJar - i;
for(int j=0;j
vecSecondFileContent.insertElementAt("", i);
i++;
intSecondEarSize++;
}
}
}
else
{
vecFirstFileContent.insertElementAt("", i);
}
}
intFirstEarSize = vecFirstFileContent.size();
intSecondEarSize = vecSecondFileContent.size();
int intSizeDifference = intSecondEarSize - intFirstEarSize;
if(intSizeDifference > 0)
{
for(int i=0;i
vecFirstFileContent.add("");
}
}
}
else if(intFirstEarSize > intSecondEarSize)
{
//Take the First ear file as Reference
for(int i=0;i
String strFirstEarContent = (String) vecFirstFileContent.get(i);
int intPositionOfValueInSecondJar = checkSameLineAfterCurrentLine(vecSecondFileContent, strFirstEarContent, i);
if(intPositionOfValueInSecondJar >= 0)
{
if(intPositionOfValueInSecondJar >= 0)
{
if(intPositionOfValueInSecondJar > i)
{
int intRowsNeedToInsert = intPositionOfValueInSecondJar - i;
for(int j=0;j
vecFirstFileContent.insertElementAt("", i);
i++;
intFirstEarSize++;
}
}
}
}
else if(intPositionOfValueInSecondJar < 0)
{
vecSecondFileContent.insertElementAt("", i);
}
else
{
continue;
}
}
intFirstEarSize = vecFirstFileContent.size();
intSecondEarSize = vecSecondFileContent.size();
int intSizeDifference = intFirstEarSize - intSecondEarSize;
if(intSizeDifference > 0)
{
for(int i=0;i
vecSecondFileContent.add("");
}
}
}
else if(intFirstEarSize == intSecondEarSize)
{
for(int i=0;i
String strFirstEarContent = (String) vecFirstFileContent.get(i);
String strSecondEarContent = (String) vecSecondFileContent.get(i);
if(strFirstEarContent.equals(strSecondEarContent))
{
continue;
}
if(strFirstEarContent.trim().length() > 0)
{
int intPositionOfValueInSecondJar = checkSameLineAfterCurrentLine(vecSecondFileContent, strFirstEarContent, i);
if(intPositionOfValueInSecondJar < 0)
{
vecSecondFileContent.insertElementAt("", i);
continue;
}
}
//Check in the First Jar
if(strSecondEarContent.trim().length() > 0)
{
int intPositionOfValueInFirstJar = checkSameLineAfterCurrentLine(vecFirstFileContent, strSecondEarContent, i);
if(intPositionOfValueInFirstJar < 0)
{
vecFirstFileContent.insertElementAt("", i);
}
}
// System.out.println("I Value->" + i);
// System.out.println("FirstFileContent inside if->" + vecFirstFileContent);
// System.out.println("SecondFileContent inside if->" + vecSecondFileContent);
}
intSecondEarSize = vecSecondFileContent.size();
int intSizeDifference = intSecondEarSize - intFirstEarSize;
int intFinalTotalSize = intFirstEarSize + intSizeDifference;
if(intSizeDifference > 0)
{
for(int i=intFirstEarSize;i
vecFirstFileContent.add("");
}
}
}
// int intReturnValue = showErrorMessageDialog(vecMissedFilesBasicDetails);
// return intReturnValue;
}
public int checkSameLineAfterCurrentLine(Vector vecToCheck, String strLineToCheck, int intIndex)
{
int intReturnValue = -1;
int intSize = vecToCheck.size();
String strCurrentData = null;
for(int i=intIndex;i
strCurrentData = (String) vecToCheck.get(i);
if(strCurrentData.startsWith(strLineToCheck))
{
intReturnValue = i;
break;
}
}
return intReturnValue;
}
public void showEARFilesCompareDialog()
{
int intTotalNumberOfRecords = vecSecondFileContent.size();
dlgEARFileCompareTool = new JDialog(EARUtility.frmEARUtility, "EAR Compare details", false);
JPanel panlFirstEARFile = new JPanel();
JPanel panlSecondEARFile = new JPanel();
panlFirstEARFile.setBackground(Color.WHITE);
panlSecondEARFile.setBackground(Color.BLACK);
CustomAbstractTableModel cstbAddFields = new CustomAbstractTableModel(
this, intTotalNumberOfRecords, 3, true, 1);//rows,cols
int intWidthForEachColumn = (EARUtility.intActualWidth - 20) / 2;
TableColumn tabcolFirstEarContent = TableDesigner.createColumn(0, 450, "");
TableColumn tabcolEqualOrNot = TableDesigner.createColumn(1, 20, "");
TableColumn tabcolSecondEarContent = TableDesigner.createColumn(2, 450, "");
tabcolFirstEarContent.setMinWidth(intWidthForEachColumn);
tabcolEqualOrNot.setMinWidth(20);
tabcolEqualOrNot.setMaxWidth(20);
tabcolSecondEarContent.setMinWidth(intWidthForEachColumn);
TableColumnModel tabcolmdlRecycleBinManager = TableDesigner
.createColumnModelForThreeRow(tabcolFirstEarContent, tabcolEqualOrNot, tabcolSecondEarContent);
JTableHeader tabheadRecycleBinManager = TableDesigner
.createTableHeader(tabcolmdlRecycleBinManager);
tableFileCompare = TableDesigner.createTable(cstbAddFields,
tabcolmdlRecycleBinManager, tabheadRecycleBinManager, 0, 20,
true, false, true, 0);
tableFileCompare.setBackground(Color.WHITE);
tableFileCompare.setForeground(Color.WHITE);
CustomTableRenderer trpref = new CustomTableRenderer(this, 2);
tableFileCompare.setDefaultRenderer(Object.class, trpref);
tableFileCompare.setColumnSelectionAllowed(true);
int intSize = vecFirstFileContent.size();
// System.out.println("intSize = ->" + intSize);
String strFirstFileContent = null;
String strSecondFileContent = null;
for(int i=0;i
strFirstFileContent = (String) vecFirstFileContent.get(i);
strSecondFileContent = (String) vecSecondFileContent.get(i);
// System.out.println(strFirstFileContent + "<->" + strSecondFileContent);
tableFileCompare.setValueAt(strFirstFileContent,i,0);
tableFileCompare.setValueAt(strSecondFileContent,i,2);
}
tableFileCompare.update(tableFileCompare.getGraphics());
JScrollPane sclpanEARCompare = new JScrollPane(
tableFileCompare, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tableFileCompare.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{}
});
panlFirstEARFile.setLayout(new BorderLayout());
panlFirstEARFile.add(sclpanEARCompare);
dlgEARFileCompareTool.getContentPane().add(panlFirstEARFile);
// dlgEARFileCompareTool.setSize(EARUtility.intActualWidth, EARUtility.intActualHeight);
dlgEARFileCompareTool.setSize(900,700);
dlgEARFileCompareTool.setVisible(true);
}
public static void main(String[] args)
{
new FilesComparingTool().compareFileContents("a.txt", "b.txt");
// new FilesComparingTool().compareFileContents("b.txt", "a.txt");
}
}
//htmlreportcreator.java
/*
* Created on Jun 2, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Date;
import javax.swing.JOptionPane;
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class HtmlReportCreator
{
private StringBuffer strbufHtmlReport;
String strFirstFileNameForReport = null;
String strSecondFileNameForReport = null;
EARFilesComparingTool objEARFilesComparingTool = null;
private boolean boolSimilarFiles = false;
private boolean boolChangedFiles = false;
private boolean boolMissingFiles = false;
public HtmlReportCreator(EARFilesComparingTool objEARFilesComparingTool)
{
this.objEARFilesComparingTool = objEARFilesComparingTool;
}
public void generateHTMLReport(String strHtmlReportFile)
{
boolSimilarFiles = objEARFilesComparingTool.chkSimilarFiles.isSelected();
boolChangedFiles = objEARFilesComparingTool.chkChangedFiles.isSelected();
boolMissingFiles = objEARFilesComparingTool.chkMissingFiles.isSelected();
String strCurrentRecord = null;
strbufHtmlReport = new StringBuffer(10000);
//Adding Header Part
strbufHtmlReport.append("
//Adding Body
strbufHtmlReport.append("");
//Adding Main Heading
strbufHtmlReport.append("
EAR FILES COMPARE DETAILS | ");
//Adding Basic Body Content
generateHtmlLinkMenu(1);
generateBasicDetails();
generateHtmlLinkMenu(2);
generateAllFilesDetails();
if(boolMissingFiles)
{
generateHtmlLinkMenu(3);
generateMissingFileDetails();
}
if(boolChangedFiles)
{
generateHtmlLinkMenu(4);
generateChangedFileDetails();
}
if(boolSimilarFiles)
{
generateHtmlLinkMenu(5);
generateSimilarFileDetails();
}
try
{
File fileToSave = new File(strHtmlReportFile);
FileOutputStream fi = new FileOutputStream(fileToSave);
PrintWriter pw = new PrintWriter(fi);
pw.println(strbufHtmlReport);
pw.flush();
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
int intDialogSelection = JOptionPane.showConfirmDialog(objEARFilesComparingTool.dlgReportSelection,
"The report is generated\nDo you want to open it now", "Open Html Report File", JOptionPane.YES_NO_OPTION);
if(intDialogSelection == 0)
{
objEARFilesComparingTool.dlgReportSelection.setVisible(false);
String cmd = "cmd /c start iexplore \""+ strHtmlReportFile + "\"";
try
{
Runtime.getRuntime().exec(cmd);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public void generateHtmlLinkMenu(int intSelectedIndex)
{
if(intSelectedIndex == 1)
{
strbufHtmlReport.append("");
strbufHtmlReport.append("
Basic Details | ");");
strbufHtmlReport.append("All File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Missing File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Changed File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Similar File Details"); strbufHtmlReport.append(" | ");
}
else if(intSelectedIndex == 2)
{
strbufHtmlReport.append("");
strbufHtmlReport.append("
");
strbufHtmlReport.append("Basic Details"); strbufHtmlReport.append(" | ");
All File Details | ");");
strbufHtmlReport.append("Missing File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Changed File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Similar File Details"); strbufHtmlReport.append(" | ");
}
else if(intSelectedIndex == 3)
{
strbufHtmlReport.append("");
strbufHtmlReport.append("
");
strbufHtmlReport.append("Basic Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("All File Details"); strbufHtmlReport.append(" | ");
Missing File Details | ");");
strbufHtmlReport.append("Changed File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Similar File Details"); strbufHtmlReport.append(" | ");
}
else if(intSelectedIndex == 4)
{
strbufHtmlReport.append("");
strbufHtmlReport.append("
");
strbufHtmlReport.append("Basic Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("All File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Missing File Details"); strbufHtmlReport.append(" | ");
Changed File Details | ");");
strbufHtmlReport.append("Similar File Details"); strbufHtmlReport.append(" | ");
}
else if(intSelectedIndex == 5)
{
strbufHtmlReport.append("");
strbufHtmlReport.append("
");
strbufHtmlReport.append("Basic Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("All File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Missing File Details"); strbufHtmlReport.append(" | ");
");
strbufHtmlReport.append("Changed File Details"); strbufHtmlReport.append(" | ");
Similar File Details | ");
}
strbufHtmlReport.append("
");
}
public void generateBasicDetails()
{
objEARFilesComparingTool.intSimilarFileCount = 0;
objEARFilesComparingTool.intModifiedFileCount = 0;
objEARFilesComparingTool.intMissingFirstFileCount = 0;
objEARFilesComparingTool.intMissingSecondFileCount = 0;
//Getting the Basic Details
int intSize = objEARFilesComparingTool.vecEqualityStatus.size();
String strFileCompareStatus = null;
for(int i=0;i
strFileCompareStatus = objEARFilesComparingTool.vecEqualityStatus.get(i).toString();
if(strFileCompareStatus.equals("EQUAL"))
{
objEARFilesComparingTool.intSimilarFileCount++;
}
else if(strFileCompareStatus.equals("NOT EQUAL"))
{
objEARFilesComparingTool.intModifiedFileCount++;
}
else if(strFileCompareStatus.equals("FILE MISSING"))
{
String strStatusDetails = objEARFilesComparingTool.vecEqualityStatusDetails.get(i).toString();
if(strStatusDetails.endsWith("First JAR file"))
{
objEARFilesComparingTool.intMissingFirstFileCount++;
}
else if(strStatusDetails.endsWith("Second JAR file"))
{
objEARFilesComparingTool.intMissingSecondFileCount++;
}
}
}
if(objEARFilesComparingTool.strFirstParentFileName.trim().length() == 0)
{
strFirstFileNameForReport = objEARFilesComparingTool.strGlobleFirstEARFileName;
}
else
{
int intFirstFileLastIndex = objEARFilesComparingTool.strGlobleFirstEARFileName.lastIndexOf("\\");
String strOnlyCurrentFirstFileName = objEARFilesComparingTool.strGlobleFirstEARFileName.substring(intFirstFileLastIndex);
if(!(objEARFilesComparingTool.strGlobleFirstEARFileName.endsWith(strOnlyCurrentFirstFileName)))
{
strFirstFileNameForReport = objEARFilesComparingTool.strFirstParentFileName + strOnlyCurrentFirstFileName;
}
else
{
strFirstFileNameForReport = objEARFilesComparingTool.strFirstParentFileName;
}
}
if(objEARFilesComparingTool.strSecondParentFileName.trim().length() == 0)
{
strSecondFileNameForReport = objEARFilesComparingTool.strGlobleSecondEARFileName;
}
else
{
int intSecondFileLastIndex = objEARFilesComparingTool.strGlobleSecondEARFileName.lastIndexOf("\\");
String strOnlyCurrentSecondFileName = objEARFilesComparingTool.strGlobleSecondEARFileName.substring(intSecondFileLastIndex);
if(!(objEARFilesComparingTool.strGlobleSecondEARFileName.endsWith(strOnlyCurrentSecondFileName)))
{
strSecondFileNameForReport = objEARFilesComparingTool.strSecondParentFileName + strOnlyCurrentSecondFileName;
}
else
{
strSecondFileNameForReport = objEARFilesComparingTool.strSecondParentFileName;
}
}
strbufHtmlReport.append("
BASIC DETAILS | ");|
Left File Name | ");" + strFirstFileNameForReport + " | ");
Right File Name | ");" + strSecondFileNameForReport + " | ");
Files removed from " + strFirstFileNameForReport + " | ");" + objEARFilesComparingTool.intMissingFirstFileCount + " | ");
Files removed from " + strSecondFileNameForReport + " | ");" + objEARFilesComparingTool.intMissingSecondFileCount + " | ");
Number of Files Modified | ");" + objEARFilesComparingTool.intModifiedFileCount + " | ");
Number of Similar Files | ");" + objEARFilesComparingTool.intSimilarFileCount + " | ");
strbufHtmlReport.append("
");
}
public void generateAllFilesDetails()
{
strbufHtmlReport.append("
No. | ");" + strFirstFileNameForReport + " | ");. | ");" + strSecondFileNameForReport + " | ");Compare Details | ");
" + intLineNumber + " | ");" + strFirstFileContent + " | ");" + strFileCompareStatusCode + " | ");" + strSecondFileContent + " | ");" + strFileCompareDetails + " | ");
" + intLineNumber + " | ");" + strFirstFileContent + " | ");" + strFileCompareStatusCode + " | ");" + strSecondFileContent + " | ");" + strFileCompareDetails + " | ");
" + intLineNumber + " | ");" + strFirstFileContent + " | ");" + strFileCompareStatusCode + " | ");" + strSecondFileContent + " | ");" + strFileCompareDetails + " | ");
strbufHtmlReport.append("
");
}
public void generateMissingFileDetails()
{
strbufHtmlReport.append("
No. | ");File Missing in " + strFirstFileNameForReport + " | ");
" + intLineNumber + " | ");" + strFileContent + " | ");
strbufHtmlReport.append("
");
strbufHtmlReport.append("
No. | ");File Missing in " + strSecondFileNameForReport + " | ");
" + intLineNumber + " | ");" + strFileContent + " | ");
strbufHtmlReport.append("
");
}
public void generateChangedFileDetails()
{
strbufHtmlReport.append("
No. | ");Changed File Name | ");File Change Details | ");
" + intLineNumber + " | ");" + strEARFileContent + " | ");" + strbufEARCompareDetails.toString() + " | ");
strbufHtmlReport.append("
");
}
public void generateSimilarFileDetails()
{
strbufHtmlReport.append("
No. | ");Similar File Name | ");
" + intLineNumber + " | ");" + strEARFileContent + " | ");
strbufHtmlReport.append("
");
}
}
//Loading.java
/*
* Created on Jun 8, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import javax.swing.*;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class LoadingDialog implements Runnable
{
private JDialog dlgProgressBar = null;
public void run()
{
dlgProgressBar = new JDialog(EARUtility.frmEARUtility, "Comparing Files Please Wait...", false);
dlgProgressBar.add(new JButton("JESUS"));
dlgProgressBar.setLocationRelativeTo(new JFrame());
dlgProgressBar.setSize(400, 100);
dlgProgressBar.setVisible(true);
}
public void hideProgressBarDialog()
{
dlgProgressBar.setVisible(false);
}
public static void main(String[] args)
{
}
}
//roundtexfield.java
/*
* Created on May 19, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.jjprojects.earutility;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.border.Border;
/**
* @author U678864 TODO To change the template for this generated type comment
* go to Window - Preferences - Java - Code Style - Code Templates
*/
public class RoundTextField extends JTextField
{
private Color colStartGradient = Color.WHITE;
private Color colEndGradient = Color.BLACK;
private boolean boolGradientText = false;
public RoundTextField(int cols, Color colStartGradient, Color colEndGradient
, boolean boolGradientTextField)
{
super(cols);
this.boolGradientText = boolGradientTextField;
this.colStartGradient = colStartGradient;
this.colEndGradient = colEndGradient;
setOpaque(false);
setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
}
public Color getGradientEndColor()
{
return colEndGradient;
}
public void setGradientEndColor(Color colGradientEnd)
{
this.colEndGradient = colGradientEnd;
}
public Color getGradientStartColor()
{
return colStartGradient;
}
public void setGradientStartColor(Color colGradientStart)
{
this.colStartGradient = colGradientStart;
}
public boolean isGradientText()
{
return boolGradientText;
}
protected void paintComponent(Graphics g)
{
int width = getWidth();
int height = getHeight();
if(this.boolGradientText)
{
GradientPaint gradient = new GradientPaint(0, 0, colStartGradient, width, height, colEndGradient);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(gradient);
g2d.fillRoundRect(0, 0, width, height, height, height);
}
else
{
g.fillRoundRect(0, 0, width, height, height, height);
}
super.paintComponent(g);
}
public void setBorder(){}
public void setBorder(Border b){}
}
//tabledesigner.java
/*******************************************************************************
*
* Designed by : A. Augustine Joseph Starting Date : 11-01-2003 Last modified by :
* A. Augustine Joseph Last modified Date : 17-01-2003 Total number of Class : 1
* Total number of Methods : 3 Class Description : This is the main class for
* designing the table components
*
******************************************************************************/
package com.jjprojects.earutility;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
public class TableDesigner
{
//Simply Constructor
public TableDesigner()
{
}
/***************************************************************************
*
* Method Description : This is used for designing the Tables header Method
* Parameter : TableColumnModel Method Parameter Value : TableColumnModel
* Method Return Type : JTableHeader Use of Return Value : JTableHeader
*
**************************************************************************/
public static JTableHeader createTableHeader(TableColumnModel tcm)
{
Font font = new Font("Sans Serif", Font.PLAIN, 12);
JTableHeader jth = new JTableHeader(tcm);
jth.setReorderingAllowed(false);
jth.setResizingAllowed(true);
jth.setBackground(Color.BLACK);
jth.setForeground(Color.BLUE);
jth.setFont(font);
jth.setVisible(true);
jth.setBorder(null);
jth.resizeAndRepaint();
jth.validate();
return jth;
}
/***************************************************************************
*
* Method Description : This is used for designing the Tables
*
* Method Parameter1 : SubTable Method Parameter1 Value : A Class with
* extends AbstractTableModal Method Parameter2 : TableColumnModel Method
* Parameter2 Value : A TableColumnModel class used for designing the table
* Method Parameter3 : JTableHeader Method Parameter3 Value : A TableHeader
* class used for designing the table Method Parameter4 : int Method
* Parameter4 Value : Resizing mode of the table Method Parameter5 : int
* Method Parameter5 Value : Row height of the table Method Parameter6 :
* boolean Method Parameter6 Value : Set weather the grid is show or not for
* the table Method Parameter7 : boolean Method Parameter7 Value : Set
* weather cell selection is allowed or not for the table Method Parameter8 :
* boolean Method Parameter8 Value : Set weather row selection is allowed or
* not for the table Method Parameter9 : int Method Parameter9 Value : Set
* the Row Selection mode
*
* Method Return Type : JTable Use of Return Value : The designed table
*
**************************************************************************/
public static JTable createTable(CustomAbstractTableModel stm,
TableColumnModel tm, JTableHeader jth, int rsz, int rh,
boolean sgr, boolean csel, boolean rsel, int smd)
{
Font font = new Font("Sans Serif", Font.PLAIN, 11);
JTable tab = new JTable(stm, tm);
tab.setTableHeader(jth);
tab.setFont(font);
tab.setAutoResizeMode(rsz);
tab.setRowHeight(rh);
tab.setShowGrid(sgr);
tab.setCellSelectionEnabled(csel);
tab.setRowSelectionAllowed(rsel);
tab.setSelectionMode(smd);
return tab;
}
// New added for adding 1 column table
public static TableColumnModel createColumnModelForOneRow(TableColumn tc1)
{
TableColumnModel tcm = new DefaultTableColumnModel();
tcm.addColumn(tc1);
tcm.setColumnSelectionAllowed(true);
return tcm;
}
//New added for adding 2 column table
public static TableColumnModel createColumnModelForThreeRow(TableColumn tc1,
TableColumn tc2, TableColumn tc3)
{
TableColumnModel tcm = new DefaultTableColumnModel();
tcm.addColumn(tc1);
tcm.addColumn(tc2);
tcm.addColumn(tc3);
tcm.setColumnSelectionAllowed(true);
return tcm;
}
/***************************************************************************
*
* Method Description : This is used for designing the Table's Column model
*
* Method Parameter1 : TableColumn Method Parameter1 Value : First Table
* Column Method Parameter2 : TableColumn Method Parameter2 Value : Second
* Table Column Method Parameter3 : TableColumn Method Parameter3 Value :
* Third Table Column Method Parameter4 : TableColumn Method Parameter4
* Value : Fourth Table Column Method Parameter5 : TableColumn Method
* Parameter5 Value : Fifth Table Column Method Parameter6 : TableColumn
* Method Parameter6 Value : Sixth Table Column Method Parameter7 :
* TableColumn Method Parameter7 Value : Seventh Table Column Method
* Parameter8 : TableColumn Method Parameter8 Value : Eight Table Column
*
* Method Return Type : TableColumnModel Use of Return Value :
* TableColumnModel
*
**************************************************************************/
public static TableColumnModel createColumnModel(TableColumn tc,
TableColumn tc1, TableColumn tc2, TableColumn tc3, TableColumn tc4,
TableColumn tc5, TableColumn tc6, TableColumn tc7)
{
TableColumnModel tcm = new DefaultTableColumnModel();
tcm.addColumn(tc);
tcm.addColumn(tc1);
tcm.addColumn(tc2);
tcm.addColumn(tc3);
tcm.addColumn(tc4);
tcm.addColumn(tc5);
tcm.addColumn(tc6);
tcm.addColumn(tc7);
tcm.setColumnSelectionAllowed(true);
return tcm;
}
/***************************************************************************
*
* Method Description : This is used for designing the Table's Column
*
* Method Parameter1 : int Method Parameter1 Value : The Column number
* Method Parameter2 : int Method Parameter2 Value : The width of the column
* Method Parameter3 : String Method Parameter3 Value : Column Value
*
* Method Return Type : TableColumn Use of Return Value : TableColumn
*
**************************************************************************/
public static TableColumn createColumn(int index, int width, String val)
{
TableColumn tbc = new TableColumn(index, width);
tbc.setHeaderValue(val);
return tbc;
}
}
//textareawriter.java
package com.jjprojects.earutility;
import javax.swing.JTextArea;
import java.io.IOException;
import java.io.Writer;
/*
* Created on Apr 18, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author U678864
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class TextAreaWriter extends Writer
{
boolean boolTextAreaInitialized = false;
private JTextArea txtaraEARFileViewer;
public TextAreaWriter(JTextArea a)
{
txtaraEARFileViewer = a;
}
public void write(char[] chararrToWrite, int intOffset, int intLength) throws IOException
{
if (!boolTextAreaInitialized)
{
txtaraEARFileViewer.setText("");
boolTextAreaInitialized = true;
}
txtaraEARFileViewer.append(new String(chararrToWrite, intOffset, intLength));
}
public void flush()
{}
public void close()
{}
}
2 comments:
can you give me your email id i wanted to speak to you regarding this code
Post a Comment