use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class LocaleFilesProcessor method isLocaleFile.
/**
* @param file
* @param parentPath
* @param bytes
* @return false - means discard the file extension type
* @throws IOException
*/
public boolean isLocaleFile(IRepositoryFileBundle file, String parentPath, byte[] bytes) throws IOException {
boolean isLocale = false;
String fileName = file.getFile().getName();
String actualFilePath = file.getPath();
RepositoryFile localeRepositoryFile = file.getFile();
if (ImportSession.getSession().getManifest() != null && ImportSession.getSession().getManifest().getManifestInformation().getManifestVersion() != null) {
fileName = ExportFileNameEncoder.decodeZipFileName(fileName);
actualFilePath = ExportFileNameEncoder.decodeZipFileName(actualFilePath);
localeRepositoryFile = new RepositoryFile.Builder(localeRepositoryFile).name(ExportFileNameEncoder.decodeZipFileName(localeRepositoryFile.getName())).build();
}
// 0 = Not a local file, 1 = 4.8 .properties file, 2= Sugar 5.0 .local file
int sourceVersion = 0;
if (fileName.endsWith(PROPERTIES_EXT)) {
sourceVersion = 1;
} else if (fileName.endsWith(LOCALE_EXT)) {
sourceVersion = 2;
}
if (sourceVersion != 0) {
InputStream inputStream = new ByteArrayInputStream(bytes);
Properties properties = loadProperties(inputStream);
String name = getProperty(properties, NAME, sourceVersion);
String title = getProperty(properties, TITLE, sourceVersion);
String description = getProperty(properties, DESCRIPTION, sourceVersion);
String url_name = getProperty(properties, URL_NAME, sourceVersion);
String url_description = getProperty(properties, URL_DESCRIPTION, sourceVersion);
if (!StringUtils.isEmpty(url_name)) {
name = url_name;
}
if (!StringUtils.isEmpty(title)) {
name = title;
}
description = !StringUtils.isEmpty(description) ? description : "";
if (!StringUtils.isEmpty(url_description)) {
description = url_description;
}
if (!StringUtils.isEmpty(name)) {
String filePath = (actualFilePath.equals("/") || actualFilePath.equals("\\")) ? "" : actualFilePath;
filePath = RepositoryFilenameUtils.concat(parentPath, filePath);
LocaleFileDescriptor localeFile;
switch(sourceVersion) {
case 1:
localeFile = new LocaleFileDescriptor(name, PROPERTIES_EXT, description, filePath, localeRepositoryFile, inputStream);
break;
case 2:
localeFile = new LocaleFileDescriptor(name, LOCALE_EXT, description, filePath, localeRepositoryFile, inputStream);
break;
default:
localeFile = new LocaleFileDescriptor(name, description, filePath, localeRepositoryFile, inputStream);
}
localeFiles.add(localeFile);
/**
* assumes that the properties file has additional localization attributes and should be imported
*/
if (properties.size() <= 2 || sourceVersion == 2) {
isLocale = true;
}
}
}
return isLocale;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class Exporter method exportDirectoryAsZip.
/**
* @param repositoryDir
* @param zos
*/
private void exportDirectoryAsZip(RepositoryFile repositoryDir, ZipOutputStream zos) throws IOException {
List<RepositoryFile> children = unifiedRepository.getChildren(repositoryDir.getId());
for (RepositoryFile repoFile : children) {
if (repoFile.isFolder()) {
ZipEntry entry = new ZipEntry(repoFile.getPath().substring(filePath.length() + 1) + "/");
zos.putNextEntry(entry);
exportDirectoryAsZip(repoFile, zos);
} else {
exportFileAsZip(repoFile, zos);
}
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class Exporter method exportDirectory.
/**
* @param repositoryDir
* @param parentDir
* @throws java.io.IOException
*/
public void exportDirectory(RepositoryFile repositoryDir, File parentDir) throws IOException {
if (repositoryDir == null || !repositoryDir.isFolder()) {
throw new IllegalArgumentException(Messages.getInstance().getErrorString("Exporter.ERROR_0001_INVALID_SOURCE_DIRECTORY", repositoryDir == null ? "Null" : repositoryDir.getPath()));
}
if (parentDir == null) {
throw new FileNotFoundException(Messages.getInstance().getErrorString("Exporter.ERROR_0002_MISSING_DESTINATION"));
}
parentDir = new File(parentDir, repositoryDir.getName());
if (!parentDir.mkdirs()) {
throw (new IOException());
}
List<RepositoryFile> children = unifiedRepository.getChildren(repositoryDir.getId());
for (RepositoryFile repoFile : children) {
if (repoFile.isFolder()) {
exportDirectory(repoFile, parentDir);
} else {
exportFile(repoFile, parentDir);
}
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class Exporter method doExportAsZip.
/**
* @param exportRepositoryFile
* @return
* @throws java.io.IOException
*/
public File doExportAsZip(RepositoryFile exportRepositoryFile) throws IOException {
File zipFile = File.createTempFile("repoExport", ".zip");
zipFile.deleteOnExit();
filePath = new File(repoPath).getParent();
if (exportRepositoryFile == null) {
throw new FileNotFoundException(Messages.getInstance().getErrorString("Exporter.ERROR_0001_INVALID_SOURCE_DIRECTORY", repoPath));
}
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
try {
if (exportRepositoryFile.isFolder()) {
// Handle recursive export
ZipEntry entry = new ZipEntry(exportRepositoryFile.getPath().substring(filePath.length() + 1) + "/");
zos.putNextEntry(entry);
exportDirectoryAsZip(exportRepositoryFile, zos);
} else {
exportFileAsZip(exportRepositoryFile, zos);
}
} finally {
zos.close();
}
return zipFile;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class ZipExportProcessor method exportDirectory.
/**
* @param repositoryDir
* @param outputStream
*/
@Override
public void exportDirectory(RepositoryFile repositoryDir, OutputStream outputStream, String filePath) throws ExportException, IOException {
addToManifest(repositoryDir);
List<RepositoryFile> children = getUnifiedRepository().getChildren(new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
for (RepositoryFile repositoryFile : children) {
// exclude 'etc' folder - datasources and etc.
if (isExportCandidate(repositoryFile.getPath())) {
if (repositoryFile.isFolder()) {
if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
ZipOutputStream zos = (ZipOutputStream) outputStream;
String zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
ZipEntry entry = new ZipEntry(zipEntryName);
zos.putNextEntry(entry);
}
exportDirectory(repositoryFile, outputStream, filePath);
} else {
try {
exportFile(repositoryFile, outputStream, filePath);
} catch (ZipException e) {
// possible duplicate entry, log it and continue on with the other files in the directory
log.debug(e.getMessage(), e);
}
}
}
}
createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
}
Aggregations