use of org.pentaho.platform.api.repository2.unified.Converter in project pentaho-platform by pentaho.
the class SolutionImportHandlerNamingIT method init.
@Before
public void init() throws IOException, PlatformInitializationException, PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
// repository
File repoDir = new File(tempDir.getAbsolutePath() + REPO_PATH);
FileUtils.forceMkdir(repoDir);
FileUtils.cleanDirectory(repoDir);
repoRoot = repoDir;
repo = new FileSystemBackedUnifiedRepository();
repo = Mockito.spy(repo);
repo.setRootDir(repoRoot);
// mimeResolver
final Converter defaultConverter = new StreamConverter();
final List<IMimeType> solutionMimeList = java.util.Collections.singletonList(MIME_SOLUTION);
final List<IMimeType> contentMimeList = java.util.Arrays.asList(new IMimeType[] { MIME_PRPT, MIME_XML });
final List<IMimeType> allMimeTypes = new ArrayList<IMimeType>(solutionMimeList.size() + contentMimeList.size());
{
allMimeTypes.addAll(solutionMimeList);
allMimeTypes.addAll(contentMimeList);
for (IMimeType mimeType : allMimeTypes) {
mimeType.setConverter(defaultConverter);
}
}
final IPlatformMimeResolver mimeResolver = new NameBaseMimeResolver();
for (IMimeType mimeType : allMimeTypes) {
mimeResolver.addMimeType(mimeType);
}
// platform, import handlers
PentahoSystem.clearObjectFactory();
microPlatform = new MicroPlatform(getSolutionPath());
microPlatform.defineInstance(IUnifiedRepository.class, repo);
microPlatform.defineInstance(IPlatformMimeResolver.class, mimeResolver);
microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
RepositoryFileImportFileHandler contentImportFileHandler = new RepositoryFileImportFileHandler(contentMimeList);
contentImportFileHandler.setRepository(repo);
solutionImportHandler = new SolutionImportHandler(solutionMimeList);
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(contentImportFileHandler);
handlers.add(solutionImportHandler);
PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setDefaultHandler(contentImportFileHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
microPlatform.defineInstance(IPlatformImporter.class, importer);
microPlatform.start();
}
use of org.pentaho.platform.api.repository2.unified.Converter in project pentaho-platform by pentaho.
the class ActionSequenceResource method getInputStream.
@SuppressWarnings({ "resource", "deprecation" })
public static InputStream getInputStream(String filePath, Locale locale) {
InputStream inputStream = null;
if (filePath.startsWith("system")) {
File file = null;
filePath = PentahoSystem.getApplicationContext().getSolutionPath(filePath);
if (locale == null) {
file = new File(filePath);
} else {
String extension = FilenameUtils.getExtension(filePath);
String baseName = FilenameUtils.removeExtension(filePath);
if (extension.length() > 0) {
// $NON-NLS-1$
extension = "." + extension;
}
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
if (!variant.equals("")) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
file = new File(baseName + "_" + language + "_" + country + "_" + variant + extension);
}
if ((file == null) || !file.exists()) {
// $NON-NLS-1$//$NON-NLS-2$
file = new File(baseName + "_" + language + "_" + country + extension);
}
if ((file == null) || !file.exists()) {
// $NON-NLS-1$
file = new File(baseName + "_" + language + extension);
}
if ((file == null) || !file.exists()) {
file = new File(filePath);
}
}
if (file != null) {
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException ex) {
// Do nothing we'll just return a null input stream;
}
}
} else {
// This is not a file from the system folder. User is trying to access a resource in the repository.
// Get the RepositoryContentConverterHandler
IRepositoryContentConverterHandler converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
RepositoryFile repositoryFile = null;
if (locale == null) {
repositoryFile = getRepository().getFile(filePath);
String extension = FilenameUtils.getExtension(filePath);
try {
// assume simple type and will get the data that way
if (converterHandler != null) {
Converter converter = converterHandler.getConverter(extension);
if (converter != null) {
inputStream = converter.convert(repositoryFile.getId());
}
}
if (inputStream == null) {
inputStream = getRepository().getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
}
} catch (UnifiedRepositoryException ure) {
// ignored
}
} else {
String extension = FilenameUtils.getExtension(filePath);
String baseName = FilenameUtils.removeExtension(filePath);
if (extension.length() > 0) {
// $NON-NLS-1$
extension = "." + extension;
}
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
if (!variant.equals("")) {
// $NON-NLS-1$
repositoryFile = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
getRepository().getFile(baseName + "_" + language + "_" + country + "_" + variant + extension);
try {
if (repositoryFile != null) {
// assume simple type and will get the data that way
if (converterHandler != null) {
Converter converter = converterHandler.getConverter(FilenameUtils.getExtension(filePath));
if (converter != null) {
inputStream = converter.convert(repositoryFile.getId());
}
}
if (inputStream == null) {
inputStream = getRepository().getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
}
}
} catch (UnifiedRepositoryException ure) {
// ignored
}
}
if (inputStream == null) {
// $NON-NLS-1$//$NON-NLS-2$
repositoryFile = getRepository().getFile(baseName + "_" + language + "_" + country + extension);
try {
if (repositoryFile != null) {
// assume simple type and will get the data that way
if (converterHandler != null) {
Converter converter = converterHandler.getConverter(FilenameUtils.getExtension(filePath));
if (converter != null) {
inputStream = converter.convert(repositoryFile.getId());
}
}
if (inputStream == null) {
inputStream = getRepository().getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
}
}
} catch (UnifiedRepositoryException ure) {
// ignored
}
}
if (inputStream == null) {
// $NON-NLS-1$
repositoryFile = getRepository().getFile(baseName + "_" + language + extension);
try {
if (repositoryFile != null) {
// assume simple type and will get the data that way
if (converterHandler != null) {
Converter converter = converterHandler.getConverter(FilenameUtils.getExtension(filePath));
if (converter != null) {
inputStream = converter.convert(repositoryFile.getId());
}
}
if (inputStream == null) {
inputStream = getRepository().getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
}
}
} catch (UnifiedRepositoryException ure) {
// ignored
}
}
if (inputStream == null) {
repositoryFile = getRepository().getFile(filePath);
try {
if (repositoryFile != null) {
// assume simple type and will get the data that way
if (converterHandler != null) {
Converter converter = converterHandler.getConverter(FilenameUtils.getExtension(filePath));
if (converter != null) {
inputStream = converter.convert(repositoryFile.getId());
}
}
if (inputStream == null) {
inputStream = getRepository().getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
}
}
} catch (UnifiedRepositoryException ure) {
// ignored
}
}
}
}
return inputStream;
}
Aggregations