the compression mode changes depending on the first file in the archive
// CHECKSTYLE:FileLength:OFF
package org.apache.hop.pipeline.transforms.fileinput.text;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
import org.apache.hop.core.compress.CompressionInputStream;
+import org.apache.hop.core.compress.CompressionPluginType;
import org.apache.hop.core.compress.CompressionProviderFactory;
import org.apache.hop.core.compress.ICompressionProvider;
import org.apache.hop.core.exception.HopException;
@@ -356,6 +359,7 @@ public class TextFileInputDialog extends BaseTransformDialog
wFilenameList.removeEmptyRows();
wFilenameList.setRowNums();
wFilenameList.optWidth(true);
+ checkCompressedFile();
}
};
wbaFilename.addSelectionListener(selA);
@@ -370,6 +374,7 @@ public class TextFileInputDialog extends BaseTransformDialog
wFilenameList.remove(idx);
wFilenameList.removeEmptyRows();
wFilenameList.setRowNums();
+ checkCompressedFile();
}
});
@@ -454,6 +459,25 @@ public class TextFileInputDialog extends BaseTransformDialog
return transformName;
}
+ /*check the compressed extension of the first file in the archive and change the
+ * compression mode in the content tab depending on it*/
+ private void checkCompressedFile(){
+ if(wFilenameList.getItemCount() > 0) {
+ String[] fileRecord = wFilenameList.getItem(0);
+ String fileExtension = FilenameUtils.getExtension(fileRecord[0]);
+ Collection<ICompressionProvider> compProviders = CompressionProviderFactory.getInstance().getCompressionProviders();
+ for (ICompressionProvider provider : compProviders) {
+ if (provider.getDefaultExtension() != null && provider.getDefaultExtension().equals(fileExtension)) {
+ int toBeSelected = ArrayUtils.indexOf(wCompression.getItems(), provider.getName());
+ wCompression.select(toBeSelected);
+ wCompression.setEnabled(true);
+ return;
+ }
+ }
+ wCompression.select(ArrayUtils.indexOf(wCompression.getItems(), CompressionProviderFactory.getInstance().getCompressionProviderByName("None").getName()));
+ }
+ }
+
private void showFiles() {
TextFileInputMeta tfii = new TextFileInputMeta();
getInfo(tfii, true);
@@ -1111,6 +1135,7 @@ public class TextFileInputDialog extends BaseTransformDialog
fdCompression.top = new FormAttachment(wNrLinesDocHeader, margin);
fdCompression.right = new FormAttachment(100, 0);
wCompression.setLayoutData(fdCompression);
+ wCompression.setEnabled(false);
Label wlNoempty = new Label(wContentComp, SWT.RIGHT);
wlNoempty.setText(BaseMessages.getString(PKG, "TextFileInputDialog.NoEmpty.Label"));
