Skip to content

Commit

Permalink
Merge pull request #3957 from apache/3956
Browse files Browse the repository at this point in the history
Add more file types #3956
  • Loading branch information
hansva authored May 28, 2024
2 parents 0df4d9a + 15fea8d commit 1ca8eea
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.hop.ui.hopgui.perspective.explorer.file;

import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.file.IHasFilename;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.context.IGuiContextHandler;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
import org.apache.hop.ui.hopgui.file.IHopFileType;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
import org.apache.hop.ui.hopgui.file.empty.EmptyHopFileTypeHandler;

@HopFileTypePlugin(
id = "ParquetFileType",
name = "Parquet File Type",
description = "Apache Parquet file handling in the explorer perspective",
image = "parquet.svg")
public class ParquetFileType implements IHopFileType {

private static final String[] EXTENSIONS = new String[] {"*.parquet"};
private static final String[] FILTER_EXTENSIONS = new String[] {"*.parquet"};
private static final String[] FILTER_NAMES = new String[] {"Parquet files"};

@Override
public String getName() {
return "Parquet";
}

@Override
public String getDefaultFileExtension() {
return "parquet";
}

@Override
public String[] getFilterExtensions() {
return FILTER_EXTENSIONS;
}

@Override
public String[] getFilterNames() {
return FILTER_NAMES;
}

@Override
public Properties getCapabilities() {
return new Properties();
}

@Override
public boolean hasCapability(String capability) {
return false;
}

@Override
public IHopFileTypeHandler openFile(HopGui hopGui, String filename, IVariables variables)
throws HopException {
return new EmptyHopFileTypeHandler();
}

@Override
public IHopFileTypeHandler newFile(HopGui hopGui, IVariables variables) throws HopException {
return new EmptyHopFileTypeHandler();
}

@Override
public boolean isHandledBy(String filename, boolean checkContent) throws HopException {
try {
FileObject fileObject = HopVfs.getFileObject(filename);
FileName fileName = fileObject.getName();
String fileExtension = fileName.getExtension().toLowerCase();

// No extension
if (Utils.isEmpty(fileExtension)) return false;

// Verify the extension
//
for (String typeExtension : EXTENSIONS) {
if (typeExtension.toLowerCase().endsWith(fileExtension)) {
return true;
}
}
return false;
} catch (Exception e) {
throw new HopException(
"Unable to verify file handling of file '" + filename + "' by extension", e);
}
}

@Override
public boolean supportsFile(IHasFilename metaObject) {
return false;
}

@Override
public List<IGuiContextHandler> getContextHandlers() {
return Collections.emptyList();
}

@Override
public String getFileTypeImage() {
return getClass().getAnnotation(HopFileTypePlugin.class).image();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.hop.ui.hopgui.perspective.explorer.file;

import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.file.IHasFilename;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.ui.hopgui.HopGui;
import org.apache.hop.ui.hopgui.context.IGuiContextHandler;
import org.apache.hop.ui.hopgui.file.HopFileTypePlugin;
import org.apache.hop.ui.hopgui.file.IHopFileType;
import org.apache.hop.ui.hopgui.file.IHopFileTypeHandler;
import org.apache.hop.ui.hopgui.file.empty.EmptyHopFileTypeHandler;

@HopFileTypePlugin(
id = "ExcelFileType",
name = "Excel File Type",
description = "Excel file handling in the explorer perspective",
image = "excel.svg")
public class ExcelFileType implements IHopFileType {

private static final String[] EXTENSIONS = new String[] {"*.xls", "*.xlsx"};
private static final String[] FILTER_EXTENSIONS = new String[] {"*.xls;*.xlsx"};
private static final String[] FILTER_NAMES = new String[] {"Excel files"};

@Override
public String getName() {
return "Excel";
}

@Override
public String getDefaultFileExtension() {
return "xlsx";
}

@Override
public String[] getFilterExtensions() {
return FILTER_EXTENSIONS;
}

@Override
public String[] getFilterNames() {
return FILTER_NAMES;
}

@Override
public Properties getCapabilities() {
return new Properties();
}

@Override
public boolean hasCapability(String capability) {
return false;
}

@Override
public IHopFileTypeHandler openFile(HopGui hopGui, String filename, IVariables variables)
throws HopException {
return new EmptyHopFileTypeHandler();
}

@Override
public IHopFileTypeHandler newFile(HopGui hopGui, IVariables variables) throws HopException {
return new EmptyHopFileTypeHandler();
}

@Override
public boolean isHandledBy(String filename, boolean checkContent) throws HopException {
try {
FileObject fileObject = HopVfs.getFileObject(filename);
FileName fileName = fileObject.getName();
String fileExtension = fileName.getExtension().toLowerCase();

// No extension
if (Utils.isEmpty(fileExtension)) return false;

// Verify the extension
//
for (String typeExtension : EXTENSIONS) {
if (typeExtension.toLowerCase().endsWith(fileExtension)) {
return true;
}
}
return false;
} catch (Exception e) {
throw new HopException(
"Unable to verify file handling of file '" + filename + "' by extension", e);
}
}

@Override
public boolean supportsFile(IHasFilename metaObject) {
return false;
}

@Override
public List<IGuiContextHandler> getContextHandlers() {
return Collections.emptyList();
}

@Override
public String getFileTypeImage() {
return getClass().getAnnotation(HopFileTypePlugin.class).image();
}
}
2 changes: 2 additions & 0 deletions plugins/transforms/excel/src/main/resources/excel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

@HopFileTypePlugin(
id = "CsvExplorerFileType",
name = "JSON File Type",
description = "JSON file handling in the explorer perspective",
name = "CSV File Type",
description = "CSV file handling in the explorer perspective",
image = "textfile.svg")
public class CsvExplorerFileType extends BaseTextExplorerFileType<TextExplorerFileTypeHandler>
implements IExplorerFileType<TextExplorerFileTypeHandler> {
Expand Down
21 changes: 9 additions & 12 deletions plugins/transforms/textfile/src/main/resources/textfile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1ca8eea

Please sign in to comment.