Skip to content

Commit

Permalink
Merge pull request #5803 from sVarma1992/BACKLOG-42169
Browse files Browse the repository at this point in the history
[BACKLOG-42169] - Changes for enabling plugin to register new file type extensions
  • Loading branch information
sVarma1992 authored Dec 9, 2024
2 parents 90632bf + 15c4bd5 commit 363fe02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -119,4 +120,32 @@ public List<IMimeType> createMimeTypeList( String handlerClass ) {
}
return mimeTypeList;
}

public ImportHandlerMimeTypeDefinitionsDto getImportHandlerMimeTypeDefinitions() {
return importHandlerMimeTypeDefinitions;
}

/**
* Register a mime type definition file with the ImportHandlerMimeTypeDefinitions from plugins
* @param pathToMimeTypeDefinitionFile
* @param importHandlerClass
* @return list of mime types that were registered
*/
public List<IMimeType> registerMimeTypeDefinition( String pathToMimeTypeDefinitionFile, String importHandlerClass ) {
try ( FileInputStream inputStream = new FileInputStream(
PentahoSystem.getApplicationContext().getSolutionPath( "" ) + pathToMimeTypeDefinitionFile ) ) {
ImportHandlerMimeTypeDefinitionsDto pluginMimeTypeDefinitionDto = fromXml( inputStream );
getImportHandlerMimeTypeDefinitions().registerImportHandler( pluginMimeTypeDefinitionDto.getImportHandler() );
log.info( "Successfully registered mime type definition " + pathToMimeTypeDefinitionFile );
return createMimeTypeList( importHandlerClass );
} catch ( FileNotFoundException e ) {
log.error( "ImportHandlerMimeTypeDefinition File \"" + pathToMimeTypeDefinitionFile + "\" not found", e );
} catch ( JAXBException e ) {
log.error( "Could not marshal the ImportHandlerMimeTypeDefinition file \"" + pathToMimeTypeDefinitionFile + "\"", e );
} catch ( IOException e ) {
log.error( "Could not close the FileInputStream for the ImportHandlerMimeTypeDefinition file \"" + pathToMimeTypeDefinitionFile + "\"", e );
}
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ public List<ImportHandlerDto> getImportHandler() {
return this.importHandler;
}

/**
* Register a list of import handlers
* @param importHandlers
*/
public void registerImportHandler( List<ImportHandlerDto> importHandlers ) {
getImportHandler().addAll( importHandlers );
}

}

0 comments on commit 363fe02

Please sign in to comment.