use of org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler in project pentaho-platform by pentaho.
the class FileResourceTest method initTest.
@BeforeClass
public static void initTest() {
IRepositoryContentConverterHandler handler = mock(IRepositoryContentConverterHandler.class);
when(handler.getConverter(XML_EXTENSION)).thenReturn(new StreamConverter());
PentahoSystem.registerObject(handler);
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler in project pentaho-platform by pentaho.
the class LocaleImportHandlerTest method setUp.
@Before
public void setUp() throws Exception {
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
PentahoSystem.registerObject(nameResolver);
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
localeMimeList.add(new MimeType("text/locale", "locale"));
nameResolver.addMimeType(new MimeType("text/prptMimeType", "prpt"));
nameResolver.addMimeType(new MimeType("text/xactionMimeType", "xaction"));
MimeType mimeType = new MimeType("text/xml", "xml");
mimeType.setHidden(true);
nameResolver.addMimeType(mimeType);
mimeType = new MimeType("image/png", "png");
mimeType.setHidden(true);
nameResolver.addMimeType(mimeType);
List<String> allowedArtifacts = new ArrayList<String>();
allowedArtifacts.add("xaction");
allowedArtifacts.add("url");
LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
LocaleImportHandler spylocaleImportHandler = spy(localeImportHandler);
Log log = mock(Log.class);
doReturn(log).when(spylocaleImportHandler).getLogger();
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(spylocaleImportHandler);
importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
localeFilesProcessor = new LocaleFilesProcessor();
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler in project pentaho-platform by pentaho.
the class RepositoryFileHelper method getFileData.
public static IRepositoryFileData getFileData(RepositoryFile repositoryFile) {
IRepositoryContentConverterHandler converterHandler;
Map<String, Converter> converters;
IPlatformMimeResolver mimeResolver;
IRepositoryFileData repositoryFileData = null;
if (!repositoryFile.isFolder()) {
// Get the extension
final String ext = RepositoryFilenameUtils.getExtension(repositoryFile.getName());
if ((ext == null) || (ext.isEmpty())) {
return null;
}
// Find the converter
// If we have not been given a handler, try PentahoSystem
converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
// fail if we have no converter handler
if (converterHandler == null) {
return null;
}
converters = converterHandler.getConverters();
final Converter converter = converters.get(ext);
if (converter == null) {
return null;
}
// Check the mime type
mimeResolver = PentahoSystem.get(IPlatformMimeResolver.class);
// fail if we have no mime resolver
if (mimeResolver == null) {
return null;
}
final String mimeType = mimeResolver.resolveMimeTypeForFileName(repositoryFile.getName()).getName();
if ((mimeType == null) || (mimeType.isEmpty())) {
return null;
}
// Get the input stream
InputStream inputStream = converter.convert(repositoryFile.getId());
if (inputStream == null) {
return null;
}
// Get the file data
repositoryFileData = converter.convert(inputStream, "UTF-8", mimeType);
if (repositoryFileData == null) {
return null;
}
}
return repositoryFileData;
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler in project pentaho-platform by pentaho.
the class DefaultExportHandler method doExport.
/**
* Perform export with registered handlers
*/
@Override
public InputStream doExport(RepositoryFile repositoryFile, String filePath) throws ExportException, IOException {
InputStream is = null;
// Compute the file extension
final String name = repositoryFile.getName();
final String ext = RepositoryFilenameUtils.getExtension(name);
if (StringUtils.isEmpty(ext)) {
log.debug("Skipping file without extension: " + name);
}
// Find the converter - defined in spring xml by import handlers
if (converters == null) {
IRepositoryContentConverterHandler converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
converters = converterHandler.getConverters();
}
final Converter converter = converters.get(ext);
if (converter == null) {
log.debug("Skipping file without converter: " + name);
return null;
}
// since it is already based on the file extension
return converter.convert(repositoryFile.getId());
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler in project pentaho-platform by pentaho.
the class LocaleFilesProcessorTest method testProcessLocaleFilesTwoLocaleFiles.
@Test
public void testProcessLocaleFilesTwoLocaleFiles() throws Exception {
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
localeMimeList.add(new MimeType("text/locale", "locale"));
LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, null);
LocaleImportHandler localeImportHandlerSpy = spy(localeImportHandler);
Log log = mock(Log.class);
doReturn(log).when(localeImportHandlerSpy).getLogger();
String localeFileName = "SampleTransformationWithParameters";
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(localeImportHandlerSpy);
importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
localeFilesProcessor = new LocaleFilesProcessor();
StringBuffer localePropertiesContent = new StringBuffer();
localePropertiesContent.append("description=This runs a simple Kettle transformation filtering records from the Quandrant_Actuals sample data " + "table, and sending a Hello message to each position.\n");
localePropertiesContent.append("name=1. Hello ETL");
assertTrue(processIsLocalFile("SampleTransformation.properties", localePropertiesContent));
StringBuffer localeContent = new StringBuffer();
localeContent.append("file.title=" + localeFileName + "\n");
localeContent.append("title=SampleTransformation\n");
localeContent.append("file.description=");
assertTrue(processIsLocalFile("SampleTransformation.xaction.locale", localeContent));
localeFilesProcessor.processLocaleFiles(importer);
// verify that in case of both .properties and .locale files are at input the only one proceeded is .locale
Mockito.verify(localeImportHandlerSpy, times(1)).importFile(any(IPlatformImportBundle.class));
ArgumentCaptor<IPlatformImportBundle> argument = ArgumentCaptor.forClass(IPlatformImportBundle.class);
Mockito.verify(localeImportHandlerSpy).importFile(argument.capture());
assertEquals(localeFileName, argument.getValue().getName());
}
Aggregations