ZipExportProcessor extends BaseExportProcessor { public File performExport( RepositoryFile exportRepositoryFile ) throws ExportException, IOException { File exportFile = null; exportFile = File.createTempFile( EXPORT_TEMP_FILENAME_PREFIX, EXPORT_TEMP_FILENAME_EXT ); exportFile.deleteOnExit(); String filePath = new File( this.path ).getParent(); if ( filePath == null ) { filePath = "/"; } if ( exportRepositoryFile == null ) { throw new FileNotFoundException( "JCR file not found: " + this.path ); } try ( ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( exportFile ) ) ) { if ( exportRepositoryFile.isFolder() ) { exportManifest.getManifestInformation().setRootFolder( path.substring( 0, path.lastIndexOf( "/" ) + 1 ) ); if ( !ClientRepositoryPaths.getRootFolderPath().equals( exportRepositoryFile.getPath() ) ) { zos.putNextEntry( new ZipEntry( getFixedZipEntryName( exportRepositoryFile, filePath ) ) ); } exportDirectory( exportRepositoryFile, zos, filePath ); } else { exportManifest.getManifestInformation().setRootFolder( path.substring( 0, path.lastIndexOf( "/" ) + 1 ) ); exportFile( exportRepositoryFile, zos, filePath ); } if ( this.withManifest ) { ZipEntry entry = new ZipEntry( EXPORT_MANIFEST_FILENAME ); zos.putNextEntry( entry ); try { exportManifest.toXml( zos ); } catch ( Exception e ) { log.error( "Error generating export XML" ); } zos.closeEntry(); } } exportManifest = null; return exportFile; } ZipExportProcessor( String path, IUnifiedRepository repository, boolean withManifest ); File performExport( RepositoryFile exportRepositoryFile ); void exportFile( RepositoryFile repositoryFile, OutputStream outputStream, String filePath ); @Override void exportDirectory( RepositoryFile repositoryDir, OutputStream outputStream, String filePath ); List<String> getLocaleExportList(); void setLocaleExportList( List<String> localeExportList ); ExportManifest getExportManifest(); void setExportManifest( ExportManifest exportManifest );  }
@Test public void testPerformExport_withoutManifest() throws Exception { String expFolderPath = "/home/test user/two words/"; ZipExportProcessor zipNoMF = new ZipExportProcessor( expFolderPath, repo, false ); exportHandler.setConverters( assignConverterForExt( defaultConverter, "prpt" ) ); zipNoMF.addExportHandler( exportHandler ); RepositoryFile expFolder = repo.getFile( expFolderPath ); assertNotNull( expFolder ); File result = zipNoMF.performExport( repo.getFile( expFolderPath ) ); Set<String> zipEntriesFiles = extractZipEntries( result ); final String[] expectedEntries = new String[] { "two words/eval (+)%.prpt", "two words/eval (+)%.prpt_en.locale", "two words/index_en.locale" }; for ( String e : expectedEntries ) { assertTrue( "expected entry: [" + e + "]", zipEntriesFiles.contains( e ) ); } assertEquals( "entries count", expectedEntries.length, zipEntriesFiles.size() ); }
@Test public void testPerformExport_withManifest() throws Exception { String expFolderPath = "/home/test user/two words/"; ZipExportProcessor zipMF = new ZipExportProcessor( expFolderPath, repo, true ); exportHandler.setConverters( assignConverterForExt( defaultConverter, "prpt" ) ); zipMF.addExportHandler( exportHandler ); RepositoryFile expFolder = repo.getFile( expFolderPath ); assertNotNull( expFolder ); File result = zipMF.performExport( repo.getFile( expFolderPath ) ); Set<String> zipEntriesFiles = extractZipEntries( result ); final String[] expectedEntries = new String[] { "two+words/eval+%28%2B%29%25.prpt", "two+words/eval+%28%2B%29%25.prpt_en.locale", "two+words/index_en.locale", "exportManifest.xml" }; for ( String e : expectedEntries ) { assertTrue( "expected entry: [" + e + "]", zipEntriesFiles.contains( e ) ); } assertEquals( "entries count", expectedEntries.length, zipEntriesFiles.size() ); }