From b87ce71ebf32797d00dbcad857c852a30fb6ec7f Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Mon, 30 Nov 2015 09:59:55 +0000 Subject: [PATCH] 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 --- .../filesys/repo/CIFSContentComparator.java | 233 ++++++++---------- .../repo/CIFSContentComparatorTest.java | 26 +- 2 files changed, 114 insertions(+), 145 deletions(-) diff --git a/source/java/org/alfresco/filesys/repo/CIFSContentComparator.java b/source/java/org/alfresco/filesys/repo/CIFSContentComparator.java index 57651ff4d0..9e8f3bf0a3 100644 --- a/source/java/org/alfresco/filesys/repo/CIFSContentComparator.java +++ b/source/java/org/alfresco/filesys/repo/CIFSContentComparator.java @@ -312,147 +312,116 @@ public class CIFSContentComparator implements ContentComparator // Comparator for MS PowerPoint private class PPTContentComparator implements ContentComparator { - -@Override -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) + + @Override + public boolean isContentEqual(ContentReader existingContent, File newFile) { - // 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) + long fileSizesDifference = newFile.length() - existingContent.getSize(); + + if(logger.isDebugEnabled()) { - logger.debug("powerpoint files are different size"); - // Different size - return false; + logger.debug("comparing two powerpoint files size:" + existingContent.getSize() + ", and " + newFile.length()); } - Collection excludes = new HashSet(); - - 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) - { + File tpm1 = null; + File tpm2 = null; + InputStream leftIs = null; try { - leftIs.close(); - } + 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 excludes = new HashSet(); + + 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; + } 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 + } + } } } } } - - - - } -} diff --git a/source/test-java/org/alfresco/filesys/repo/CIFSContentComparatorTest.java b/source/test-java/org/alfresco/filesys/repo/CIFSContentComparatorTest.java index e2957c8a57..880f9d50a0 100644 --- a/source/test-java/org/alfresco/filesys/repo/CIFSContentComparatorTest.java +++ b/source/test-java/org/alfresco/filesys/repo/CIFSContentComparatorTest.java @@ -304,19 +304,19 @@ public class CIFSContentComparatorTest extends TestCase 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); -// /** -// * Compare different powerpoint files, should not be ignored -// */ -// { -// File file0 = file0Resource.getFile(); -// File file1 = file1Resource.getFile(); -// -// ContentReader reader = new FileContentReader(file0); -// reader.setMimetype("application/vnd.ms-powerpoint"); -// reader.setEncoding("UTF-8"); -// boolean result = contentComparator.isContentEqual(reader, file1); -// assertTrue("compare different powerpoint files, should not be equal", !result); -// } + /** + * Compare different powerpoint files, should not be ignored + */ + { + File file0 = file0Resource.getFile(); + File file1 = file1Resource.getFile(); + + ContentReader reader = new FileContentReader(file0); + reader.setMimetype("application/vnd.ms-powerpoint"); + reader.setEncoding("UTF-8"); + boolean result = contentComparator.isContentEqual(reader, file1); + assertTrue("compare different powerpoint files, should not be equal", !result); + } /** * Compare trivially different powerpoint files, should ignore trivial differences and be equal