Use apache commongs FilenameUtils.getExtension to extract the extension from the file name.

This commit is contained in:
Ghazi Triki 2016-09-29 18:47:11 +01:00
parent 7b6abc1dbe
commit a9acf9e3e5
3 changed files with 8 additions and 8 deletions

View File

@ -19,6 +19,7 @@
package org.bigbluebutton.web.controllers
import javax.servlet.ServletRequest;
import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -28,7 +29,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.bigbluebutton.api.domain.Config;
@ -2057,9 +2060,8 @@ class ApiController {
}
}
def processDocumentFromRawBytes(bytes, presFilename, meetingId) {
def filenameExt = Util.getFilenameExt(presFilename);
def filenameExt = FilenameUtils.getExtension(presFilename);
String presentationDir = presentationService.getPresentationDir()
def presId = Util.generatePresentationId(presFilename)
File uploadDir = Util.createPresentationDirectory(meetingId, presentationDir, presId)
@ -2080,7 +2082,7 @@ class ApiController {
def downloadAndProcessDocument(address, meetingId) {
log.debug("ApiController#downloadAndProcessDocument(${address}, ${meetingId})");
String presFilename = address.tokenize("/")[-1];
def filenameExt = presDownloadService.getFilenameExt(presFilename);
def filenameExt = FilenameUtils.getExtension(presFilename);
String presentationDir = presentationService.getPresentationDir()
def presId = presDownloadService.generatePresentationId(presFilename)

View File

@ -19,6 +19,8 @@
package org.bigbluebutton.web.controllers
import grails.converters.*
import org.apache.commons.io.FilenameUtils;
import org.bigbluebutton.web.services.PresentationService
import org.bigbluebutton.presentation.UploadedPresentation
import org.bigbluebutton.api.MeetingService;
@ -48,7 +50,7 @@ class PresentationController {
if (file && !file.empty) {
flash.message = 'Your file has been uploaded'
def presFilename = file.getOriginalFilename()
def filenameExt = Util.getFilenameExt(presFilename);
def filenameExt = FilenameUtils.getExtension(presFilename);
String presentationDir = presentationService.getPresentationDir()
def presId = Util.generatePresentationId(presFilename)
File uploadDir = Util.createPresentationDirectory(meetingId, presentationDir, presId)

View File

@ -10,10 +10,6 @@ public final class Util {
return DigestUtils.shaHex(name) + "-" + timestamp;
}
public static String getFilenameExt(String filename) {
return filename.substring(filename.lastIndexOf("."));
}
public static String createNewFilename(String presId, String fileExt) {
return presId + fileExt;
}