use of com.liferay.portal.kernel.zip.ZipReader in project liferay-ide by liferay.
the class MediaWikiImporter method processImages.
protected void processImages(long userId, WikiNode node, InputStream imagesInputStream) throws Exception {
if (imagesInputStream == null) {
return;
}
ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
int count = 0;
ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(imagesInputStream);
List<String> entries = zipReader.getEntries();
int total = entries.size();
if (total > 0) {
try {
WikiPageLocalServiceUtil.getPage(node.getNodeId(), SHARED_IMAGES_TITLE);
} catch (NoSuchPageException nspe) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
WikiPageLocalServiceUtil.addPage(userId, node.getNodeId(), SHARED_IMAGES_TITLE, SHARED_IMAGES_CONTENT, null, true, serviceContext);
}
}
List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<ObjectValuePair<String, InputStream>>();
try {
int percentage = 50;
for (int i = 0; i < entries.size(); i++) {
String entry = entries.get(i);
String key = entry;
InputStream inputStream = zipReader.getEntryAsInputStream(entry);
String[] paths = StringUtil.split(key, CharPool.SLASH);
if (!isValidImage(paths, inputStream)) {
if (_log.isInfoEnabled()) {
_log.info("Ignoring " + key);
}
continue;
}
String fileName = StringUtil.toLowerCase(paths[paths.length - 1]);
ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<String, InputStream>(fileName, inputStream);
inputStreamOVPs.add(inputStreamOVP);
count++;
if ((i % 5) == 0) {
WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
inputStreamOVPs.clear();
percentage = Math.min(50 + (i * 50) / total, 99);
progressTracker.setPercent(percentage);
}
}
if (!inputStreamOVPs.isEmpty()) {
WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
}
} finally {
for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {
InputStream inputStream = inputStreamOVP.getValue();
StreamUtil.cleanUp(inputStream);
}
}
zipReader.close();
if (_log.isInfoEnabled()) {
_log.info("Imported " + count + " images into " + node.getName());
}
}
use of com.liferay.portal.kernel.zip.ZipReader in project liferay-ide by liferay.
the class KBArticleImporter method processZipFile.
public int processZipFile(long userId, long groupId, long parentKBFolderId, boolean prioritizeByNumericalPrefix, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
if (inputStream == null) {
throw new KBArticleImportException("Input stream is null");
}
try {
ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(inputStream);
Map<String, String> metadata = getMetadata(zipReader);
return processKBArticleFiles(userId, groupId, parentKBFolderId, prioritizeByNumericalPrefix, zipReader, metadata, serviceContext);
} catch (IOException ioe) {
throw new KBArticleImportException(ioe);
}
}
Aggregations