/** * Copies the file bundle into the repository * * @param bundle * @param bundlePath * @param bundlePathName * @param file * @param comment */ protected boolean copyFileToRepository( final ImportSource.IRepositoryFileBundle bundle, final String bundlePathName, final String repositoryPath, final RepositoryFile file, final String comment) { // Compute the file extension final String name = bundle.getFile().getName(); final String ext = RepositoryFilenameUtils.getExtension(name); if (StringUtils.isEmpty(ext)) { log.debug("Skipping file without extension: " + bundlePathName); return false; } // Check the mime type final String mimeType = bundle.getMimeType(); if (mimeType == null) { log.debug("Skipping file without mime-type: " + bundlePathName); return false; } // Find the converter final Converter converter = converters.get(ext); if (converter == null) { log.debug("Skipping file without converter: " + bundlePathName); return false; } // Copy the file into the repository try { log.trace("copying file to repository: " + bundlePathName); IRepositoryFileData data = converter.convert(bundle.getInputStream(), bundle.getCharset(), mimeType); if (null == file) { final boolean hidden = !executableTypes.contains(ext.toLowerCase()); log.trace("\tsetting hidden=" + hidden + " for file with extension " + ext.toLowerCase()); createFile(bundle, repositoryPath, hidden, data, comment); } else { repository.updateFile(file, data, comment); } return true; } catch (IOException e) { log.warn( messages.getString("DefaultImportHandler.WARN_0003_IOEXCEPTION", name), e); // TODO make sure string // exists return false; } }
public OutputStream getOutputStream() throws Exception { String tempOutputFilePath = outputFilePath; String extension = RepositoryFilenameUtils.getExtension(tempOutputFilePath); if ("*".equals(extension)) { // $NON-NLS-1$ tempOutputFilePath = tempOutputFilePath.substring(0, tempOutputFilePath.lastIndexOf('.')); if (streamingAction != null) { String mimeType = streamingAction.getMimeType(null); if (mimeType != null && MimeHelper.getExtension(mimeType) != null) { tempOutputFilePath += MimeHelper.getExtension(mimeType); } } } RepositoryFileOutputStream outputStream = new RepositoryFileOutputStream(tempOutputFilePath, autoCreateUniqueFilename, true); outputStream.addListener(this); return outputStream; }