Rolled back CIFSComparator stuff incorrectly checked in

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@118826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2015-11-30 09:59:55 +00:00
parent c4fb6e6437
commit b87ce71ebf
2 changed files with 114 additions and 145 deletions

View File

@@ -313,146 +313,115 @@ public class CIFSContentComparator implements ContentComparator
private class PPTContentComparator implements ContentComparator private class PPTContentComparator implements ContentComparator
{ {
@Override @Override
public boolean isContentEqual(ContentReader existingContent, File newFile) public boolean isContentEqual(ContentReader existingContent, File newFile)
{
long fileSizesDifference = newFile.length() - existingContent.getSize();
if(logger.isDebugEnabled())
{
logger.debug("comparing two powerpoint files size:" + existingContent.getSize() + ", and " + newFile.length());
}
File tpm1 = null;
File tpm2 = null;
InputStream leftIs = null;
try
{
if(fileSizesDifference != 0)
{ {
// ALF-18793 long fileSizesDifference = newFile.length() - existingContent.getSize();
// Experience has shown that the size of opened/closed file increases to 3072 bytes.
// (That occurs only in case if the file has been created on one MS PowerPoint instance and opened/closed on another if(logger.isDebugEnabled())
// due to change of lastEditUsername property (if they are different)).
if (fileSizesDifference > 3072 && fileSizesDifference < 0)
{ {
logger.debug("powerpoint files are different size"); logger.debug("comparing two powerpoint files size:" + existingContent.getSize() + ", and " + newFile.length());
// Different size }
File tpm1 = null;
File tpm2 = null;
InputStream leftIs = null;
try
{
if(fileSizesDifference != 0)
{
// ALF-18793
// Experience has shown that the size of opened/closed file increases to 3072 bytes.
// (That occurs only in case if the file has been created on one MS PowerPoint instance and opened/closed on another
// due to change of lastEditUsername property (if they are different)).
if (fileSizesDifference > 3072 && fileSizesDifference < 0)
{
logger.debug("powerpoint files are different size");
// Different size
return false;
}
Collection<String> excludes = new HashSet<String>();
leftIs = existingContent.getContentInputStream();
HSLFSlideShow slideShow1 = new HSLFSlideShow(leftIs);
HSLFSlideShow slideShow2 = new HSLFSlideShow(new FileInputStream(newFile));
String lastEditUsername1 = slideShow1.getCurrentUserAtom().getLastEditUsername();
String lastEditUsername2 = slideShow2.getCurrentUserAtom().getLastEditUsername();
if (lastEditUsername1.equals(lastEditUsername2))
{
logger.debug("powerpoint files are different size");
// Different size
return false;
}
else
{
//make sure that nothing has been changed except lastEditUsername
tpm1 = TempFileProvider.createTempFile("CIFSContentComparator1", "ppt");
tpm2 = TempFileProvider.createTempFile("CIFSContentComparator2", "ppt");
slideShow1.write(new FileOutputStream(tpm1));
slideShow1.write(new FileOutputStream(tpm2));
NPOIFSFileSystem fs1 = new NPOIFSFileSystem(tpm1);
NPOIFSFileSystem fs2 = new NPOIFSFileSystem(tpm2);
return isContentIdentical(fs1, fs2, excludes);
}
}
return true;
}
catch (ContentIOException ce)
{
logger.debug("Unable to compare contents", ce);
return false; return false;
} }
Collection<String> excludes = new HashSet<String>();
leftIs = existingContent.getContentInputStream();
HSLFSlideShow slideShow1 = new HSLFSlideShow(leftIs);
HSLFSlideShow slideShow2 = new HSLFSlideShow(new FileInputStream(newFile));
String lastEditUsername1 = slideShow1.getCurrentUserAtom().getLastEditUsername();
String lastEditUsername2 = slideShow2.getCurrentUserAtom().getLastEditUsername();
if (lastEditUsername1.equals(lastEditUsername2))
{
logger.debug("powerpoint files are different size and same editor name");
// Different size
return false;
}
else
{
//make sure that nothing has been changed except lastEditUsername
tpm1 = TempFileProvider.createTempFile("CIFSContentComparator1", "ppt");
FileOutputStream os = new FileOutputStream(tpm1);
try
{
slideShow1.write(os);
}
finally
{
try
{
os.close();
}
catch (IOException ie)
{
// ignore
}
}
tpm2 = TempFileProvider.createTempFile("CIFSContentComparator2", "ppt");
FileOutputStream os2 = new FileOutputStream(tpm2);
try
{
slideShow2.write(os2);
}
finally
{
try
{
os2.close();
}
catch (IOException ie)
{
// ignore
}
}
NPOIFSFileSystem fs1 = new NPOIFSFileSystem(tpm1);
NPOIFSFileSystem fs2 = new NPOIFSFileSystem(tpm2);
return isContentIdentical(fs1, fs2, excludes);
}
}
return true;
}
catch (ContentIOException ce)
{
logger.debug("Unable to compare contents", ce);
return false;
}
catch (IOException e)
{
logger.debug("Unable to compare contents", e);
return false;
}
finally
{
if(tpm1 != null)
{
try
{
tpm1.delete();
}
catch (Exception e)
{
// ignore
}
}
if(tpm2 != null)
{
try
{
tpm2.delete();
}
catch (Exception e)
{
// ignore
}
}
if(leftIs != null)
{
try
{
leftIs.close();
}
catch (IOException e) catch (IOException e)
{ {
// Ignore logger.debug("Unable to compare contents", e);
return false;
}
finally
{
if(tpm1 != null)
{
try
{
tpm1.delete();
}
catch (Exception e)
{
// ignore
}
}
if(tpm2 != null)
{
try
{
tpm2.delete();
}
catch (Exception e)
{
// ignore
}
}
if(leftIs != null)
{
try
{
leftIs.close();
}
catch (IOException e)
{
// Ignore
}
}
} }
} }
} }
} }
}
}

View File

@@ -304,19 +304,19 @@ public class CIFSContentComparatorTest extends TestCase
ClassPathResource file5Resource = new ClassPathResource("filesys/ContentComparatorTestPowerPoint2003-5-edited-gt-3072bytes.ppt"); ClassPathResource file5Resource = new ClassPathResource("filesys/ContentComparatorTestPowerPoint2003-5-edited-gt-3072bytes.ppt");
assertNotNull("unable to find test resource filesys/ContentComparatorTestPowerPoint2003-5-edited-gt-3072bytes.ppt", file5Resource); assertNotNull("unable to find test resource filesys/ContentComparatorTestPowerPoint2003-5-edited-gt-3072bytes.ppt", file5Resource);
// /** /**
// * Compare different powerpoint files, should not be ignored * Compare different powerpoint files, should not be ignored
// */ */
// { {
// File file0 = file0Resource.getFile(); File file0 = file0Resource.getFile();
// File file1 = file1Resource.getFile(); File file1 = file1Resource.getFile();
//
// ContentReader reader = new FileContentReader(file0); ContentReader reader = new FileContentReader(file0);
// reader.setMimetype("application/vnd.ms-powerpoint"); reader.setMimetype("application/vnd.ms-powerpoint");
// reader.setEncoding("UTF-8"); reader.setEncoding("UTF-8");
// boolean result = contentComparator.isContentEqual(reader, file1); boolean result = contentComparator.isContentEqual(reader, file1);
// assertTrue("compare different powerpoint files, should not be equal", !result); assertTrue("compare different powerpoint files, should not be equal", !result);
// } }
/** /**
* Compare trivially different powerpoint files, should ignore trivial differences and be equal * Compare trivially different powerpoint files, should ignore trivial differences and be equal