63 lines
1.9 KiB
Java
63 lines
1.9 KiB
Java
|
package org.gcube.application.cms.sdi.model;
|
||
|
|
||
|
import lombok.*;
|
||
|
import lombok.extern.slf4j.Slf4j;
|
||
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile;
|
||
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
@Getter
|
||
|
@RequiredArgsConstructor
|
||
|
public abstract class SupportedFormat {
|
||
|
|
||
|
public static ArrayList<SupportedFormat> getByExtension(String... extensions){
|
||
|
ArrayList<SupportedFormat> toReturn = new ArrayList<>();
|
||
|
|
||
|
for (String extension : extensions) {
|
||
|
extension=extension.toLowerCase();
|
||
|
switch (extension){
|
||
|
case ".tif" : {toReturn.add(new SupportedFormat(".tif") {
|
||
|
@Override
|
||
|
public void consider(RegisteredFile f) {
|
||
|
if (f.getName().endsWith(getFileExtension())){
|
||
|
getToUseFileSet().add(f);
|
||
|
isProposedFilesetValid=true;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
case ".shp":{toReturn.add(new SupportedFormat(".shp") {
|
||
|
@Override
|
||
|
public void consider(RegisteredFile f) {
|
||
|
getToUseFileSet().add(f);
|
||
|
if (f.getName().endsWith(getFileExtension())){
|
||
|
isProposedFilesetValid=true;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return toReturn;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
private String fileExtension;
|
||
|
|
||
|
protected Boolean isProposedFilesetValid=false;
|
||
|
|
||
|
private ArrayList<RegisteredFile> toUseFileSet = new ArrayList<>();
|
||
|
|
||
|
public abstract void consider(RegisteredFile f);
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public String toString() {
|
||
|
return fileExtension ;
|
||
|
}
|
||
|
}
|