--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+package com.pentila.entSavoie.utils;
+
+import java.io.UnsupportedEncodingException;
+
+import java.net.URLEncoder;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+
+public class MediaPlayerUtil {
+
+ /**
+ * Check if file need to be converted
+ * @param fileExtension a string which contains the file type
+ * @return the target type or the original if the file doesn't need to be converted
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static String getTargetExtension(String fileExtension) {
+
+ List<String> pdfTypeList = getPdfConversionTypeList();
+
+ if (pdfTypeList.contains(fileExtension)) {
+ return "pdf";
+ }
+
+ List<String> mp3TypeList = getMp3ConversionTypeList();
+
+ if (mp3TypeList.contains(fileExtension)) {
+ return "mp3";
+ }
+
+ List<String> mp4TypeList = getMp4ConversionTypeList();
+
+ if (mp4TypeList.contains(fileExtension)) {
+ return "mp4";
+ }
+
+ return fileExtension;
+ }
+
+ /**
+ * Check if file can be display in the viewer
+ * @param fileExtension a string which contains the file type
+ * @return true if the file is handled by the viewer
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static boolean hasViewer(String fileExtension) {
+
+ List<String> listContentTypeSupport = supportedTypeList();
+
+ if (listContentTypeSupport.contains(fileExtension)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get all file types which are converted to pdf
+ * @return a list which contains strings of all extensions converted to pdf
+ */
+ private static List<String> getImageTypeList() {
+ List<String> typeList = new ArrayList<String>();
+
+ typeList.add("gif");
+ typeList.add("jpeg");
+ typeList.add("jpg");
+ typeList.add("png");
+
+ return typeList;
+ }
+
+ /**
+ * Get all file types which are converted to pdf
+ * @return a list which contains strings of all extensions converted to pdf
+ */
+ private static List<String> getPdfConversionTypeList() {
+ List<String> typeList = new ArrayList<String>();
+
+ typeList.add("odp");
+ typeList.add("ppt");
+ typeList.add("sxi");
+ typeList.add("csv");
+ typeList.add("ods");
+ typeList.add("sxc");
+ typeList.add("tsv");
+ typeList.add("xls");
+ typeList.add("doc");
+ typeList.add("odt");
+ typeList.add("rtf");
+ typeList.add("sxw");
+ typeList.add("txt");
+ //typeList.add("wpd");
+ typeList.add("docx");
+ typeList.add("xlsx");
+ typeList.add("pptx");
+
+ return typeList;
+ }
+
+ /**
+ * Get all audio types which are converted to mp3
+ * @return a list which contains strings of all extensions converted to mp3
+ */
+ private static List<String> getMp3ConversionTypeList() {
+ List<String> typeList = new ArrayList<String>();
+
+ typeList.add("wav");
+ typeList.add("wma");
+
+ return typeList;
+ }
+
+ /**
+ * Get all video types which are converted to mp4
+ * @return a list which contains strings of all extensions converted to mp4
+ */
+ private static List<String> getMp4ConversionTypeList() {
+ List<String> typeList = new ArrayList<String>();
+
+ typeList.add("avi");
+ typeList.add("m4v");
+ typeList.add("wav");
+ typeList.add("mpg");
+ typeList.add("mpeg");
+ typeList.add("mov");
+
+ return typeList;
+ }
+
+ /**
+ * Get all file types that we can display in the viewer
+ * @return a list which contains strings of all the extensions handled
+ */
+ private static List<String> supportedTypeList() {
+ List<String> supportedTypeList = new ArrayList<String>();
+
+ //Document
+ supportedTypeList.add("pdf");
+ supportedTypeList.add("html");
+ supportedTypeList.addAll(getPdfConversionTypeList());
+
+ //Image
+ supportedTypeList.add("gif");
+ supportedTypeList.add("jpeg");
+ supportedTypeList.add("jpg");
+ supportedTypeList.add("png");
+
+ //Audio
+ supportedTypeList.add("mp3");
+ supportedTypeList.addAll(getMp3ConversionTypeList());
+
+ //Video
+ supportedTypeList.add("mp4");
+ supportedTypeList.addAll(getMp4ConversionTypeList());
+
+ // Epub
+ supportedTypeList.add("epub");
+
+ return supportedTypeList;
+ }
+
+ private static Log _log = LogFactoryUtil.getLog(MediaPlayerUtil.class);
+}