Repository: openmeetings Updated Branches: refs/heads/master e2eae747e -> 4a5e859f8
no jira: file type guesser is improved Project: http://git-wip-us.apache.org/repos/asf/openmeetings/repo Commit: http://git-wip-us.apache.org/repos/asf/openmeetings/commit/4a5e859f Tree: http://git-wip-us.apache.org/repos/asf/openmeetings/tree/4a5e859f Diff: http://git-wip-us.apache.org/repos/asf/openmeetings/diff/4a5e859f Branch: refs/heads/master Commit: 4a5e859f886253086e51a2ac26bbc501d621e590 Parents: e2eae74 Author: Maxim Solodovnik <[email protected]> Authored: Tue Jun 20 10:26:26 2017 +0700 Committer: Maxim Solodovnik <[email protected]> Committed: Tue Jun 20 10:34:12 2017 +0700 ---------------------------------------------------------------------- .../core/converter/DocumentConverter.java | 16 +- .../core/converter/ImageConverter.java | 7 +- .../core/data/file/FileProcessor.java | 146 +++++++++-------- .../org/apache/openmeetings/util/Logger.java | 48 ------ .../openmeetings/util/OmFileDetector.java | 38 ----- .../apache/openmeetings/util/StoredFile.java | 164 +++++++++++++------ .../services/java.nio.file.spi.FileTypeDetector | 12 -- .../org/apache/tika/mime/custom-mimetypes.xml | 37 +++++ .../openmeetings/util/TestStoredFile.java | 22 ++- .../web/common/UploadableImagePanel.java | 30 ++-- .../web/room/sidebar/UploadDialog.java | 3 + 11 files changed, 284 insertions(+), 239 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/DocumentConverter.java ---------------------------------------------------------------------- diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/DocumentConverter.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/DocumentConverter.java index a3881ed..dcae322 100644 --- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/DocumentConverter.java +++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/DocumentConverter.java @@ -18,6 +18,7 @@ */ package org.apache.openmeetings.core.converter; +import static org.apache.commons.io.FileUtils.copyFile; import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_PDF; import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; @@ -25,6 +26,7 @@ import java.io.File; import org.apache.openmeetings.db.dao.basic.ConfigurationDao; import org.apache.openmeetings.db.entity.file.FileItem; +import org.apache.openmeetings.util.StoredFile; import org.apache.openmeetings.util.process.ConverterProcessResult; import org.apache.openmeetings.util.process.ConverterProcessResultList; import org.apache.wicket.util.string.Strings; @@ -44,20 +46,22 @@ public class DocumentConverter { @Autowired private ImageConverter imageConverter; - public ConverterProcessResultList convertPDF(FileItem f, String ext) throws Exception { - ConverterProcessResultList list = new ConverterProcessResultList(); + public ConverterProcessResultList convertPDF(FileItem f, StoredFile sf) throws Exception { + ConverterProcessResultList result = new ConverterProcessResultList(); - boolean fullProcessing = !EXTENSION_PDF.equals(ext); - File original = f.getFile(ext); + boolean fullProcessing = !sf.isPdf(); + File original = f.getFile(sf.getExt()); File pdf = f.getFile(EXTENSION_PDF); log.debug("fullProcessing: " + fullProcessing); if (fullProcessing) { log.debug("-- running JOD --"); - list.addItem("processOpenOffice", doJodConvert(original, pdf)); + result.addItem("processOpenOffice", doJodConvert(original, pdf)); + } else if (!EXTENSION_PDF.equals(sf.getExt())) { + copyFile(original, pdf); } log.debug("-- generate page images --"); - return imageConverter.convertDocument(list, f, pdf); + return imageConverter.convertDocument(result, f, pdf); } /** http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/ImageConverter.java ---------------------------------------------------------------------- diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/ImageConverter.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/ImageConverter.java index 4367b14..5bbf9be 100644 --- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/ImageConverter.java +++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/converter/ImageConverter.java @@ -37,6 +37,7 @@ import org.apache.openmeetings.db.dao.user.UserDao; import org.apache.openmeetings.db.entity.file.FileItem; import org.apache.openmeetings.db.entity.user.User; import org.apache.openmeetings.util.OmFileHelper; +import org.apache.openmeetings.util.StoredFile; import org.apache.openmeetings.util.process.ConverterProcessResult; import org.apache.openmeetings.util.process.ConverterProcessResultList; import org.apache.openmeetings.util.process.ProcessHelper; @@ -53,12 +54,12 @@ public class ImageConverter extends BaseConverter { @Autowired private ConfigurationDao cfgDao; - public ConverterProcessResultList convertImage(FileItem f, String ext) throws IOException { + public ConverterProcessResultList convertImage(FileItem f, StoredFile sf) throws IOException { ConverterProcessResultList returnMap = new ConverterProcessResultList(); File jpg = f.getFile(EXTENSION_JPG); - if (!EXTENSION_JPG.equals(ext)) { - File img = f.getFile(ext); + if (!sf.isJpg()) { + File img = f.getFile(sf.getExt()); log.debug("##### convertImage destinationFile: " + jpg); returnMap.addItem("processJPG", convertSingleJpg(img, jpg)); http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java ---------------------------------------------------------------------- diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java index f48f0c2..8c4b620 100644 --- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java +++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/data/file/FileProcessor.java @@ -18,6 +18,8 @@ */ package org.apache.openmeetings.core.data.file; +import static org.apache.commons.io.FileUtils.copyFile; +import static org.apache.commons.io.FileUtils.copyInputStreamToFile; import static org.apache.openmeetings.util.OmFileHelper.getFileExt; import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; @@ -26,7 +28,6 @@ import java.io.InputStream; import java.util.List; import java.util.UUID; -import org.apache.commons.io.FileUtils; import org.apache.openmeetings.core.converter.DocumentConverter; import org.apache.openmeetings.core.converter.FlvExplorerConverter; import org.apache.openmeetings.core.converter.ImageConverter; @@ -55,80 +56,93 @@ public class FileProcessor { //FIXME TODO this method need to be refactored to throw exceptions public ConverterProcessResultList processFile(FileExplorerItem f, InputStream is) throws Exception { - ConverterProcessResultList returnError = new ConverterProcessResultList(); - + ConverterProcessResultList result = new ConverterProcessResultList(); // Generate a random string to prevent any problems with // foreign characters and duplicates String hash = UUID.randomUUID().toString(); - String ext = getFileExt(f.getName()); - log.debug("file extension: " + ext); - StoredFile storedFile = new StoredFile(hash, ext); - - // Check variable to see if this file is a presentation - // check if this is a a file that can be converted by - // openoffice-service - boolean canBeConverted = storedFile.isConvertable(); - boolean isPdf = storedFile.isPdf(); - boolean isImage = storedFile.isImage(); - boolean isChart = storedFile.isChart(); - boolean isAsIs = storedFile.isAsIs(); - boolean isVideo = storedFile.isVideo(); - - log.debug("isAsIs: " + isAsIs); - - // add outputfolders for profiles - // if it is a presenation it will be copied to another place - if (!(canBeConverted || isPdf || isImage || isVideo || isAsIs)) { - returnError.addItem("wrongType", new ConverterProcessResult("The file type cannot be converted")); - return returnError; - } - if (isImage) { - f.setType(Type.Image); - } else if (isVideo) { - f.setType(Type.Video); - } else if (isChart) { - f.setType(Type.PollChart); - } else if (isPdf || canBeConverted) { - f.setType(Type.Presentation); - } - f.setHash(hash); + File temp = null; + try { + temp = File.createTempFile(String.format("upload_%s", hash), ".tmp"); + copyInputStreamToFile(is, temp); + + String ext = getFileExt(f.getName()); + log.debug("file extension: " + ext); + StoredFile sf = new StoredFile(hash, ext, temp); + // Check variable to see if this file is a presentation + // check if this is a a file that can be converted by + // openoffice-service + boolean isOffice = sf.isOffice(); + boolean isPdf = sf.isPdf(); + boolean isImage = sf.isImage(); + boolean isChart = sf.isChart(); + boolean isAsIs = sf.isAsIs(); + boolean isVideo = sf.isVideo(); + + log.debug("isAsIs: " + isAsIs); + + // add outputfolders for profiles + // if it is a presenation it will be copied to another place + if (!(isOffice || isPdf || isImage || isVideo || isAsIs)) { + result.addItem("wrongType", new ConverterProcessResult("The file type cannot be converted")); + return result; + } + if (isImage) { + f.setType(Type.Image); + } else if (isVideo) { + f.setType(Type.Video); + } else if (isChart) { + f.setType(Type.PollChart); + } else if (isPdf || isOffice) { + f.setType(Type.Presentation); + } + f.setHash(hash); - File file = f.getFile(ext); - log.debug("writing file to: " + file); - if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { - returnError.addItem("No parent", new ConverterProcessResult("Unable to create parent for file: " + file.getCanonicalPath())); - return returnError; - } - FileUtils.copyInputStreamToFile(is, file); + f = fileDao.update(f); + log.debug("fileId: " + f.getId()); + File file = f.getFile(ext); + log.debug("writing file to: " + file); + if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { + result.addItem("No parent", new ConverterProcessResult("Unable to create parent for file: " + file.getCanonicalPath())); + return result; + } - log.debug("canBeConverted: " + canBeConverted); - if (canBeConverted || isPdf) { - // convert to pdf and images - returnError = generatePDF.convertPDF(f, ext); - } else if (isChart) { - log.debug("uploaded chart file"); - } else if (isImage) { - // convert it to JPG - log.debug("##### convert it to JPG: "); - returnError = imageConverter.convertImage(f, ext); - } else if (isVideo) { - List<ConverterProcessResult> returnList = flvExplorerConverter.convertToMP4(f, ext); + log.debug("canBeConverted: " + isOffice); + if (isOffice || isPdf) { + copyFile(temp, file); + // convert to pdf, thumbs, swf and xml-description + result = generatePDF.convertPDF(f, sf); + } else if (isChart) { + //TODO should be implemented copyFile(temp, file); + log.debug("uploaded chart file"); + } else if (isImage) { + // convert it to JPG + log.debug("##### convert it to JPG: "); + copyFile(temp, file); + result = imageConverter.convertImage(f, sf); + } else if (isVideo) { + copyFile(temp, file); + List<ConverterProcessResult> returnList = flvExplorerConverter.convertToMP4(f, ext); + + int i = 0; + for (ConverterProcessResult returnMap : returnList) { + result.addItem("processVideo " + i++, returnMap); + } + } - int i = 0; - for (ConverterProcessResult returnMap : returnList) { - returnError.addItem("processVideo " + i++, returnMap); + // has to happen at the end, otherwise it will be overwritten + //cause the variable is new initialized + result.setCompleteName(file.getName()); + result.setFileItemId(f.getId()); + } catch (Exception e) { + result.addItem("exception", new ConverterProcessResult("Unexpected exception: " + e.getMessage())); + throw e; + } finally { + if (temp != null && temp.exists() && temp.isFile()) { + log.debug("Clean up was successful ? {}", temp.delete()); } } - f = fileDao.update(f); - log.debug("fileId: " + f.getId()); - - // has to happen at the end, otherwise it will be overwritten - //cause the variable is new initialized - returnError.setCompleteName(file.getName()); - returnError.setFileItemId(f.getId()); - - return returnError; + return result; } } http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/main/java/org/apache/openmeetings/util/Logger.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/Logger.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/Logger.java deleted file mode 100644 index a33e69c..0000000 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/Logger.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.util; - -import org.red5.logging.Red5LoggerFactory; - -public class Logger { - private org.slf4j.Logger log; - - public Logger() { - StackTraceElement ste = Thread.currentThread().getStackTrace()[1]; - log = Red5LoggerFactory.getLogger(ste.getClass(), - OpenmeetingsVariables.webAppRootKey); - } - - private static String getMethodMessage() { - StackTraceElement ste = Thread.currentThread().getStackTrace()[2]; - return "In the method " + ste.getMethodName(); - } - - public void debug(String s, Object o) { - log.debug(s, o); - } - - public void debug(Object o) { - log.debug(getMethodMessage(), o); - } - - public void error(Object o) { - log.error(getMethodMessage(), o); - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileDetector.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileDetector.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileDetector.java deleted file mode 100644 index 1b7042f..0000000 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileDetector.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") + you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.openmeetings.util; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.spi.FileTypeDetector; - -public class OmFileDetector extends FileTypeDetector { - private final static String[] KNOWN_EXTS = {"dpx", "exr", "pcd", "pcds", "xcf", "wpg", "tga"}; - private final static String OTHER = "image/other"; - - @Override - public String probeContentType(Path path) throws IOException { - for (String ext : KNOWN_EXTS) { - if (("" + path).endsWith(ext)) { - return OTHER; - } - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java index 76e43f7..5431fa4 100644 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java @@ -19,103 +19,173 @@ package org.apache.openmeetings.util; import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_JPG; +import static org.apache.openmeetings.util.OmFileHelper.getFileExt; +import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; +import static org.apache.tika.mime.MediaType.application; +import static org.apache.tika.mime.MediaType.image; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; -import java.nio.file.Files; +import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; -import javax.activation.MimetypesFileTypeMap; - +import org.apache.tika.Tika; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.mime.MediaType; import org.apache.wicket.util.string.Strings; +import org.red5.logging.Red5LoggerFactory; +import org.slf4j.Logger; public class StoredFile { - private final static MimetypesFileTypeMap MIMES_MAP = new MimetypesFileTypeMap(); + private static final Logger log = Red5LoggerFactory.getLogger(StoredFile.class, webAppRootKey); private final static String MIME_AUDIO = "audio"; private final static String MIME_VIDEO = "video"; private final static String MIME_IMAGE = "image"; - private static final Set<String> convertExtensions = new HashSet<>( - Arrays.asList("ppt", "odp", "odt", "sxw", "wpd", "doc", "rtf", "txt", "ods", "sxc", "xls", "sxi", "pptx", "docx", "xlsx")); + private final static String MIME_TEXT = "text"; + private final static String MIME_APP = "application"; + private static final Set<MediaType> CONVERT_TYPES = new HashSet<>(Arrays.asList( + application("x-tika-msoffice"), application("x-tika-ooxml"), application("msword") + , application("vnd.wordperfect"), application("rtf"))); + + private static final MediaType MIME_JPG = image(EXTENSION_JPG); + private static final Set<MediaType> PDF_TYPES = new HashSet<>(Arrays.asList(application("pdf"), application("postscript"))); + private static final Set<MediaType> CHART_TYPES = new HashSet<>(/* TODO have to be tested and re-added Arrays.asList("xchart")*/); + private static final Set<MediaType> AS_IS_TYPES = new HashSet<>(Arrays.asList(MIME_JPG/* TODO have to be tested and re-added, "xchart"*/)); + private static final String ACCEPT_STRING; + static { + Set<MediaType> types = new LinkedHashSet<>(); + types.addAll(CONVERT_TYPES); + types.addAll(PDF_TYPES); + //TODO have to be tested and re-added ext.addAll(chartExtensions); + StringBuilder sb = new StringBuilder("audio/*,video/*,image/*,text/*"); + sb.append(",application/vnd.oasis.opendocument.*"); + sb.append(",application/vnd.sun.xml.*"); + sb.append(",application/vnd.stardivision.*"); + sb.append(",application/x-star*"); + for (MediaType mt : types) { + sb.append(',').append(mt.toString()); + } + ACCEPT_STRING = sb.toString(); + } - private static final Set<String> pdfExtensions = new HashSet<>(Arrays.asList("pdf", "ps")); + private String name; + private String ext; + private MediaType mime; - private static final Set<String> chartExtensions = new HashSet<>(Arrays.asList("xchart")); + public StoredFile(String fullname, InputStream is) { + this(fullname, null, is); + } - private static final Set<String> asIsExtensions = new HashSet<>(Arrays.asList(EXTENSION_JPG, "xchart")); //mp4 removed to get video size + public StoredFile(String name, String ext, InputStream is) { + init(name, ext, is); + } - private final String name; - private final String ext; + public StoredFile(String fullname, File f) throws FileNotFoundException, IOException { + this(fullname, null, f); + } - public StoredFile(String fullname) { - int idx = fullname.lastIndexOf('.'); - name = idx < 0 ? fullname : fullname.substring(0, idx); - ext = idx < 0 ? "" : fullname.substring(idx + 1).toLowerCase(); + public StoredFile(String name, String ext, File f) throws FileNotFoundException, IOException { + try (InputStream fis = new FileInputStream(f)) { + init(name, ext, fis); + } } - public StoredFile(String name, String ext) { - this.name = name; - this.ext = ext != null ? ext.toLowerCase() : ""; + private void init(String name, String ext, InputStream is) { + if (Strings.isEmpty(ext)) { + int idx = name.lastIndexOf('.'); + this.name = idx < 0 ? name : name.substring(0, idx); + this.ext = getFileExt(name); + } else { + this.name = name; + this.ext = ext.toLowerCase(); + } + Tika tika = new Tika(); + Metadata md = new Metadata(); + md.add(Metadata.RESOURCE_NAME_KEY, String.format("%s.%s", name, ext)); + try { + mime = MediaType.parse(tika.detect(is, md)); + } catch (Exception e) { + mime = null; + log.error("Unexpected exception while detecting mime type", e); + } } public static String getAcceptAttr() { - Set<String> ext = new LinkedHashSet<>(); - ext.addAll(convertExtensions); - ext.addAll(pdfExtensions); - ext.addAll(chartExtensions); - StringBuilder sb = new StringBuilder("audio/*,video/*,image/*,."); - sb.append(String.join(",.", ext)); - return sb.toString(); + return ACCEPT_STRING; } - public boolean isConvertable() { - return convertExtensions.contains(ext); + public boolean isOffice() { + if (mime == null) { + return false; + } + return MIME_TEXT.equals(mime.getType()) + || (MIME_APP.equals(mime.getType()) && + (mime.getSubtype().startsWith("vnd.oasis.opendocument") + || mime.getSubtype().startsWith("vnd.sun.xml") + || mime.getSubtype().startsWith("vnd.stardivision") + || mime.getSubtype().startsWith("x-star") + || mime.getSubtype().startsWith("vnd.ms-") + || mime.getSubtype().startsWith("vnd.openxmlformats-officedocument") + )) + || CONVERT_TYPES.contains(mime); } public boolean isPresentation() { - return isConvertable() || isPdf(); + return isOffice() || isPdf(); } public boolean isPdf() { - return pdfExtensions.contains(ext); + if (mime == null) { + return false; + } + return PDF_TYPES.contains(mime); } - private static String getMimeType(StoredFile f) { - String filename = String.format("%s%s%s", f.name, Strings.isEmpty(f.ext) ? "" : ".", f.ext); - String type = ""; - try { - type = Files.probeContentType(new File(filename).toPath()); - } catch (IOException e) { - //no-op + public boolean isJpg() { + if (mime == null) { + return false; } - if (Strings.isEmpty(type)) { - type = MIMES_MAP.getContentType(filename); - } - String[] mime = type.split("/"); - return mime[0]; + return MIME_JPG.equals(mime); } public boolean isImage() { - String mime = getMimeType(this); - return MIME_IMAGE.equals(mime); + if (mime == null) { + return false; + } + return MIME_IMAGE.equals(mime.getType()); } public boolean isVideo() { - String mime = getMimeType(this); - return MIME_AUDIO.equals(mime) || MIME_VIDEO.equals(mime); + if (mime == null) { + return false; + } + return MIME_AUDIO.equals(mime.getType()) || MIME_VIDEO.equals(mime.getType()); } public boolean isChart() { - return chartExtensions.contains(ext); + if (mime == null) { + return false; + } + return CHART_TYPES.contains(mime); } public boolean isAsIs() { - return asIsExtensions.contains(ext); + if (mime == null) { + return false; + } + return AS_IS_TYPES.contains(mime); } public String getName() { return name; } + + public String getExt() { + return ext; + } } http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/main/resources/META-INF/services/java.nio.file.spi.FileTypeDetector ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/resources/META-INF/services/java.nio.file.spi.FileTypeDetector b/openmeetings-util/src/main/resources/META-INF/services/java.nio.file.spi.FileTypeDetector deleted file mode 100644 index 18a017f..0000000 --- a/openmeetings-util/src/main/resources/META-INF/services/java.nio.file.spi.FileTypeDetector +++ /dev/null @@ -1,12 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -org.apache.openmeetings.util.OmFileDetector http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/main/resources/org/apache/tika/mime/custom-mimetypes.xml ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/resources/org/apache/tika/mime/custom-mimetypes.xml b/openmeetings-util/src/main/resources/org/apache/tika/mime/custom-mimetypes.xml new file mode 100644 index 0000000..4f8fa6e --- /dev/null +++ b/openmeetings-util/src/main/resources/org/apache/tika/mime/custom-mimetypes.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<mime-info> + <mime-type type="image/other"> + <glob pattern="*.dpx"/> + </mime-type> + <mime-type type="image/other"> + <glob pattern="*.exr"/> + </mime-type> + <mime-type type="image/other"> + <glob pattern="*.pcd"/> + </mime-type> + <mime-type type="image/other"> + <glob pattern="*.pcds"/> + </mime-type> + <mime-type type="image/other"> + <glob pattern="*.wpg"/> + </mime-type> + <mime-type type="image/other"> + <glob pattern="*.tga"/> + </mime-type> +</mime-info> http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestStoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestStoredFile.java b/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestStoredFile.java index 6e1df19..ac74054 100644 --- a/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestStoredFile.java +++ b/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestStoredFile.java @@ -21,16 +21,16 @@ package org.apache.openmeetings.util; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.InputStream; + import org.junit.Test; -import org.junit.experimental.categories.Category; -@Category({NonJenkinsTests.class}) public class TestStoredFile { @Test public void testAudio() { final String[] exts = {"aif", "aifc", "aiff", "au", "mp3", "flac", "wav"}; //TODO enlarge for (String ext : exts) { - StoredFile sf = new StoredFile("test", ext); + StoredFile sf = new StoredFile("test", ext, (InputStream)null); assertTrue(String.format("Files of type '%s' should be treated as Video", ext), sf.isVideo()); assertFalse(String.format("Files of type '%s' should NOT be treated as Image", ext), sf.isImage()); } @@ -40,7 +40,7 @@ public class TestStoredFile { public void testVideo() { final String[] exts = {"avi", "mov", "flv", "mp4"}; //TODO enlarge for (String ext : exts) { - StoredFile sf = new StoredFile("test", ext); + StoredFile sf = new StoredFile("test", ext, (InputStream)null); assertTrue(String.format("Files of type '%s' should be treated as Video", ext), sf.isVideo()); assertFalse(String.format("Files of type '%s' should NOT be treated as Image", ext), sf.isImage()); } @@ -59,9 +59,21 @@ public class TestStoredFile { "tga", // Truevision Targa "jpg", "jpeg"}; //TODO enlarge for (String ext : exts) { - StoredFile sf = new StoredFile("test", ext); + StoredFile sf = new StoredFile("test", ext, (InputStream)null); assertTrue(String.format("Files of type '%s' should be treated as Image", ext), sf.isImage()); assertFalse(String.format("Files of type '%s' should NOT be treated as Video", ext), sf.isVideo()); } } + + @Test + public void testOffice() { + final String[] exts = { + "ppt", "odp", "odt", "sxw", "wpd", "doc", "rtf", "txt", "ods", "sxc", "xls", "sxi", "pptx", "docx", "xlsx" + }; + for (String ext : exts) { + StoredFile sf = new StoredFile("test", ext, (InputStream)null); + assertTrue(String.format("Files of type '%s' should be treated as Convertible", ext), sf.isOffice()); + assertFalse(String.format("Files of type '%s' should NOT be treated as Video", ext), sf.isVideo()); + } + } } http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java index beb07d1..ebeaca5 100644 --- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java +++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/UploadableImagePanel.java @@ -81,22 +81,24 @@ public abstract class UploadableImagePanel extends ImagePanel { protected void onSubmit(AjaxRequestTarget target) { FileUpload fu = fileUploadField.getFileUpload(); if (fu != null) { - StoredFile sf = new StoredFile(fu.getClientFileName()); - if (sf.isImage()) { - File temp = null; - try { - temp = fu.writeToTempFile(); + File temp = null; + try { + temp = fu.writeToTempFile(); + StoredFile sf = new StoredFile(fu.getClientFileName(), temp); + if (sf.isImage()) { processImage(sf, temp); - } catch (Exception e) { - // TODO display error - log.error("Error", e); - } finally { - if (temp != null && temp.exists()) { - temp.delete(); - } + } else { + //TODO display error } - } else { - //TODO display error + } catch (Exception e) { + // TODO display error + log.error("Error", e); + } finally { + if (temp != null && temp.exists()) { + log.debug("Temp file was deleted ? {}", temp.delete()); + } + fu.closeStreams(); + fu.delete(); } } update(); http://git-wip-us.apache.org/repos/asf/openmeetings/blob/4a5e859f/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/UploadDialog.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/UploadDialog.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/UploadDialog.java index e47b6d4..47974e9 100644 --- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/UploadDialog.java +++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/UploadDialog.java @@ -215,6 +215,9 @@ public class UploadDialog extends AbstractFormDialog<String> { } } catch (Exception e) { form.error(e.getMessage()); + } finally { + fu.closeStreams(); + fu.delete(); } } if (form.hasError()) {
