use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException 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