diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/ImageToSwfSlide.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/ImageToSwfSlide.java index b4185ce789f07082844534c507c280e959be1687..b39875d4dcda483abcd62b3e5118ce636f90ca9e 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/ImageToSwfSlide.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/ImageToSwfSlide.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation; @@ -27,68 +27,68 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ImageToSwfSlide { - private static Logger log = LoggerFactory.getLogger(ImageToSwfSlide.class); - - private UploadedPresentation pres; - private int page; - - private PageConverter imageToSwfConverter; - private String BLANK_SLIDE; - - private boolean done = false; - private File slide; - - public ImageToSwfSlide(UploadedPresentation pres, int page) { - this.pres = pres; - this.page = page; - } - - public ImageToSwfSlide createSlide() { - File presentationFile = pres.getUploadedFile(); - slide = new File(presentationFile.getParent() + File.separatorChar + "slide-" + page + ".swf"); - log.debug("Creating slide " + slide.getAbsolutePath()); - imageToSwfConverter.convert(presentationFile, slide, page, pres); - - // If all fails, generate a blank slide. - if (!slide.exists()) { - log.warn("Creating blank slide for " + slide.getAbsolutePath()); - generateBlankSlide(); - } - - done = true; - - return this; - } - - public void generateBlankSlide() { - if (BLANK_SLIDE != null) { - copyBlankSlide(slide); - } else { - log.error("Blank slide has not been set"); - } - } - - private void copyBlankSlide(File slide) { - try { - FileUtils.copyFile(new File(BLANK_SLIDE), slide); - } catch (IOException e) { - log.error("IOException while copying blank slide."); - } - } - - public void setPageConverter(PageConverter converter) { - this.imageToSwfConverter = converter; - } - - public void setBlankSlide(String blankSlide) { - this.BLANK_SLIDE = blankSlide; - } - - public boolean isDone() { - return done; - } - - public int getPageNumber() { - return page; - } + private static Logger log = LoggerFactory.getLogger(ImageToSwfSlide.class); + + private UploadedPresentation pres; + private int page; + + private PageConverter imageToSwfConverter; + private String BLANK_SLIDE; + + private boolean done = false; + private File slide; + + public ImageToSwfSlide(UploadedPresentation pres, int page) { + this.pres = pres; + this.page = page; + } + + public ImageToSwfSlide createSlide() { + File presentationFile = pres.getUploadedFile(); + slide = new File(presentationFile.getParent() + File.separatorChar + "slide-" + page + ".swf"); + log.debug("Creating slide " + slide.getAbsolutePath()); + imageToSwfConverter.convert(presentationFile, slide, page, pres); + + // If all fails, generate a blank slide. + if (!slide.exists()) { + log.warn("Creating blank slide for " + slide.getAbsolutePath()); + generateBlankSlide(); + } + + done = true; + + return this; + } + + public void generateBlankSlide() { + if (BLANK_SLIDE != null) { + copyBlankSlide(slide); + } else { + log.error("Blank slide has not been set"); + } + } + + private void copyBlankSlide(File slide) { + try { + FileUtils.copyFile(new File(BLANK_SLIDE), slide); + } catch (IOException e) { + log.error("IOException while copying blank slide."); + } + } + + public void setPageConverter(PageConverter converter) { + this.imageToSwfConverter = converter; + } + + public void setBlankSlide(String blankSlide) { + this.BLANK_SLIDE = blankSlide; + } + + public boolean isDone() { + return done; + } + + public int getPageNumber() { + return page; + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/PdfToSwfSlide.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/PdfToSwfSlide.java index e78f742156c18911981bd724ddcf74e21fc61917..7abc43627377763ca46e4c9c4f683cb27dba86eb 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/PdfToSwfSlide.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/PdfToSwfSlide.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation; @@ -32,117 +32,117 @@ import org.slf4j.LoggerFactory; import com.google.gson.Gson; public class PdfToSwfSlide { - private static Logger log = LoggerFactory.getLogger(PdfToSwfSlide.class); - - private UploadedPresentation pres; - private int page; - private PageConverter pdfToSwfConverter; - private PdfPageToImageConversionService imageConvertService; - private String BLANK_SLIDE; - private int MAX_SWF_FILE_SIZE; - - private volatile boolean done = false; - private File slide; - - public PdfToSwfSlide(UploadedPresentation pres, int page) { - this.pres = pres; - this.page = page; - } - - public PdfToSwfSlide createSlide() { - File presentationFile = pres.getUploadedFile(); - slide = new File(presentationFile.getParent() + File.separatorChar + "slide-" + page + ".swf"); - if (! pdfToSwfConverter.convert(presentationFile, slide, page, pres)) { + private static Logger log = LoggerFactory.getLogger(PdfToSwfSlide.class); + + private UploadedPresentation pres; + private int page; + private PageConverter pdfToSwfConverter; + private PdfPageToImageConversionService imageConvertService; + private String BLANK_SLIDE; + private int MAX_SWF_FILE_SIZE; + + private volatile boolean done = false; + private File slide; + + public PdfToSwfSlide(UploadedPresentation pres, int page) { + this.pres = pres; + this.page = page; + } + + public PdfToSwfSlide createSlide() { + File presentationFile = pres.getUploadedFile(); + slide = new File(presentationFile.getParent() + File.separatorChar + "slide-" + page + ".swf"); + if (! pdfToSwfConverter.convert(presentationFile, slide, page, pres)) { Map<String, Object> logData = new HashMap<String, Object>(); logData.put("meetingId", pres.getMeetingId()); logData.put("presId", pres.getId()); logData.put("filename", pres.getName()); logData.put("page", page); logData.put("size(KB)", slide.length()/1024); - + Gson gson = new Gson(); String logStr = gson.toJson(logData); - + log.warn("Failed to convert slide: data={}", logStr); - imageConvertService.convertPageAsAnImage(presentationFile, slide, page, pres); - } - - // If all fails, generate a blank slide. - if (!slide.exists()) { - log.warn("Failed to create slide. Creating blank slide for " + slide.getAbsolutePath()); - generateBlankSlide(); - } - - done = true; - - return this; - } - - private boolean slideMayHaveTooManyObjects(File slide) { - // If the resulting swf file is greater than 500K, it probably contains a lot of objects - // that it becomes very slow to render on the client. Take an image snapshot instead and - // use it to generate the SWF file. (ralam Sept 2, 2009) - return slide.length() > MAX_SWF_FILE_SIZE; - } - - public void generateBlankSlide() { - if (BLANK_SLIDE != null) { + imageConvertService.convertPageAsAnImage(presentationFile, slide, page, pres); + } + + // If all fails, generate a blank slide. + if (!slide.exists()) { + log.warn("Failed to create slide. Creating blank slide for " + slide.getAbsolutePath()); + generateBlankSlide(); + } + + done = true; + + return this; + } + + private boolean slideMayHaveTooManyObjects(File slide) { + // If the resulting swf file is greater than 500K, it probably contains a lot of objects + // that it becomes very slow to render on the client. Take an image snapshot instead and + // use it to generate the SWF file. (ralam Sept 2, 2009) + return slide.length() > MAX_SWF_FILE_SIZE; + } + + public void generateBlankSlide() { + if (BLANK_SLIDE != null) { Map<String, Object> logData = new HashMap<String, Object>(); logData.put("meetingId", pres.getMeetingId()); logData.put("presId", pres.getId()); logData.put("filename", pres.getName()); logData.put("page", page); - + Gson gson = new Gson(); String logStr = gson.toJson(logData); - + log.warn("Creating blank slide: data={}", logStr); - - copyBlankSlide(slide); - } else { + + copyBlankSlide(slide); + } else { Map<String, Object> logData = new HashMap<String, Object>(); logData.put("meetingId", pres.getMeetingId()); logData.put("presId", pres.getId()); logData.put("filename", pres.getName()); logData.put("page", page); - + Gson gson = new Gson(); String logStr = gson.toJson(logData); - + log.warn("Failed to create blank slide: data={}", logStr); - } - } - - private void copyBlankSlide(File slide) { - try { - FileUtils.copyFile(new File(BLANK_SLIDE), slide); - } catch (IOException e) { - log.error("IOException while copying blank slide."); - } - } - - public void setPageConverter(PageConverter converter) { - this.pdfToSwfConverter = converter; - } - - public void setPdfPageToImageConversionService(PdfPageToImageConversionService service) { - this.imageConvertService = service; - } - - public void setBlankSlide(String blankSlide) { - this.BLANK_SLIDE = blankSlide; - } - - public void setMaxSwfFileSize(int size) { - this.MAX_SWF_FILE_SIZE = size; - } - - public boolean isDone() { - return done; - } - - public int getPageNumber() { - return page; - } + } + } + + private void copyBlankSlide(File slide) { + try { + FileUtils.copyFile(new File(BLANK_SLIDE), slide); + } catch (IOException e) { + log.error("IOException while copying blank slide."); + } + } + + public void setPageConverter(PageConverter converter) { + this.pdfToSwfConverter = converter; + } + + public void setPdfPageToImageConversionService(PdfPageToImageConversionService service) { + this.imageConvertService = service; + } + + public void setBlankSlide(String blankSlide) { + this.BLANK_SLIDE = blankSlide; + } + + public void setMaxSwfFileSize(int size) { + this.MAX_SWF_FILE_SIZE = size; + } + + public boolean isDone() { + return done; + } + + public int getPageNumber() { + return page; + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/ImageMagickPageConverter.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/ImageMagickPageConverter.java index 99e5d0a5ab6210d19efbd6c2227b5cae73a2f8e3..05985617a3c4d4fe0aafaabfbd1dadf5803d0478 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/ImageMagickPageConverter.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/ImageMagickPageConverter.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -27,28 +27,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ImageMagickPageConverter implements PageConverter { - private static Logger log = LoggerFactory.getLogger(ImageMagickPageConverter.class); - - private String IMAGEMAGICK_DIR; - - public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ - - String COMMAND = IMAGEMAGICK_DIR + "/convert -depth 8 " + presentationFile.getAbsolutePath() + " " + output.getAbsolutePath(); - - boolean done = new ExternalProcessExecutor().exec(COMMAND, 60000); - - if (done && output.exists()) { - return true; - } else { - log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); - return false; - } - - } - - public void setImageMagickDir(String dir) { - IMAGEMAGICK_DIR = dir; - } + private static Logger log = LoggerFactory.getLogger(ImageMagickPageConverter.class); + + private String IMAGEMAGICK_DIR; + + public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ + + String COMMAND = IMAGEMAGICK_DIR + "/convert -depth 8 " + presentationFile.getAbsolutePath() + " " + output.getAbsolutePath(); + + boolean done = new ExternalProcessExecutor().exec(COMMAND, 60000); + + if (done && output.exists()) { + return true; + } else { + log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); + return false; + } + + } + + public void setImageMagickDir(String dir) { + IMAGEMAGICK_DIR = dir; + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Office2PdfPageConverter.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Office2PdfPageConverter.java index 27bbd2a2f0148acc34c96016206d88c6246b4de6..9a0eeadb8db8c87c6f619d52f1fa5b09088299ad 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Office2PdfPageConverter.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Office2PdfPageConverter.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -33,39 +33,39 @@ import com.artofsolving.jodconverter.openoffice.connection.*; import com.artofsolving.jodconverter.openoffice.converter.*; public class Office2PdfPageConverter implements PageConverter { - private static Logger log = LoggerFactory.getLogger(Office2PdfPageConverter.class); - - public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ - SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); + private static Logger log = LoggerFactory.getLogger(Office2PdfPageConverter.class); - try { - connection.connect(); - - log.debug("Converting " + presentationFile.getAbsolutePath() + " to " + output.getAbsolutePath()); - - DefaultDocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); - OpenOfficeDocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry); + public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ + SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); - DocumentFormat pdf = registry.getFormatByFileExtension("pdf"); - Map<String, Object> pdfOptions = new HashMap<String, Object>(); - pdfOptions.put("ReduceImageResolution", Boolean.TRUE); - pdfOptions.put("MaxImageResolution", Integer.valueOf(300)); - pdf.setExportOption(DocumentFamily.TEXT, "FilterData", pdfOptions); - - converter.convert(presentationFile, output, pdf); - connection.disconnect(); - - if (output.exists()) { - return true; - } else { - log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); - return false; - } - - } catch(Exception e) { - log.error("Exception: Failed to convert " + output.getAbsolutePath()); - return false; - } - } + try { + connection.connect(); + + log.debug("Converting " + presentationFile.getAbsolutePath() + " to " + output.getAbsolutePath()); + + DefaultDocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); + OpenOfficeDocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry); + + DocumentFormat pdf = registry.getFormatByFileExtension("pdf"); + Map<String, Object> pdfOptions = new HashMap<String, Object>(); + pdfOptions.put("ReduceImageResolution", Boolean.TRUE); + pdfOptions.put("MaxImageResolution", Integer.valueOf(300)); + pdf.setExportOption(DocumentFamily.TEXT, "FilterData", pdfOptions); + + converter.convert(presentationFile, output, pdf); + connection.disconnect(); + + if (output.exists()) { + return true; + } else { + log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); + return false; + } + + } catch(Exception e) { + log.error("Exception: Failed to convert " + output.getAbsolutePath()); + return false; + } + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java index 24fbacdea9ab063933244003d832cd1e018a29ab..9dd17f4f17f7478dfb9173a569f0a21c6c86b20f 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/OfficeToPdfConversionService.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -27,44 +27,44 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class OfficeToPdfConversionService { - private static Logger log = LoggerFactory.getLogger(OfficeToPdfConversionService.class); - - /* - * Convert the Office document to PDF. If successful, update - * UploadPresentation.uploadedFile with the new PDF out and - * UploadPresentation.lastStepSuccessful to TRUE. - */ - public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) { - initialize(pres); - if (SupportedFileTypes.isOfficeFile(pres.getFileType())) { - File pdfOutput = setupOutputPdfFile(pres); - if (convertOfficeDocToPdf(pres, pdfOutput)) { - log.info("Successfully converted office file to pdf."); - makePdfTheUploadedFileAndSetStepAsSuccess(pres, pdfOutput); - } else { - log.warn("Failed to convert " + pres.getUploadedFile().getAbsolutePath() + " to Pdf."); - } - } - return pres; - } - - public void initialize(UploadedPresentation pres) { - pres.setLastStepSuccessful(false); - } - - private File setupOutputPdfFile(UploadedPresentation pres) { - File presentationFile = pres.getUploadedFile(); - String filenameWithoutExt = presentationFile.getAbsolutePath().substring(0, presentationFile.getAbsolutePath().lastIndexOf(".")); - return new File(filenameWithoutExt + ".pdf"); - } - - private boolean convertOfficeDocToPdf(UploadedPresentation pres, File pdfOutput) { - PageConverter converter = new Office2PdfPageConverter(); - return converter.convert(pres.getUploadedFile(), pdfOutput, 0, pres); - } - - private void makePdfTheUploadedFileAndSetStepAsSuccess(UploadedPresentation pres, File pdf) { - pres.setUploadedFile(pdf); - pres.setLastStepSuccessful(true); - } + private static Logger log = LoggerFactory.getLogger(OfficeToPdfConversionService.class); + + /* + * Convert the Office document to PDF. If successful, update + * UploadPresentation.uploadedFile with the new PDF out and + * UploadPresentation.lastStepSuccessful to TRUE. + */ + public UploadedPresentation convertOfficeToPdf(UploadedPresentation pres) { + initialize(pres); + if (SupportedFileTypes.isOfficeFile(pres.getFileType())) { + File pdfOutput = setupOutputPdfFile(pres); + if (convertOfficeDocToPdf(pres, pdfOutput)) { + log.info("Successfully converted office file to pdf."); + makePdfTheUploadedFileAndSetStepAsSuccess(pres, pdfOutput); + } else { + log.warn("Failed to convert " + pres.getUploadedFile().getAbsolutePath() + " to Pdf."); + } + } + return pres; + } + + public void initialize(UploadedPresentation pres) { + pres.setLastStepSuccessful(false); + } + + private File setupOutputPdfFile(UploadedPresentation pres) { + File presentationFile = pres.getUploadedFile(); + String filenameWithoutExt = presentationFile.getAbsolutePath().substring(0, presentationFile.getAbsolutePath().lastIndexOf(".")); + return new File(filenameWithoutExt + ".pdf"); + } + + private boolean convertOfficeDocToPdf(UploadedPresentation pres, File pdfOutput) { + PageConverter converter = new Office2PdfPageConverter(); + return converter.convert(pres.getUploadedFile(), pdfOutput, 0, pres); + } + + private void makePdfTheUploadedFileAndSetStepAsSuccess(UploadedPresentation pres, File pdf) { + pres.setUploadedFile(pdf); + pres.setLastStepSuccessful(true); + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Pdf2SwfPageConverter.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Pdf2SwfPageConverter.java index 5183da079f44cf6704c9fafc16d8be5aee724e37..42ae5dcfbf46b5070cac2aba5daaa08c3ab36853 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Pdf2SwfPageConverter.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Pdf2SwfPageConverter.java @@ -54,7 +54,7 @@ public class Pdf2SwfPageConverter implements PageConverter { private long imageTagThreshold; private String convTimeout = "5s"; private int WAIT_FOR_SEC = 6; - + public boolean convert(File presentation, File output, int page, UploadedPresentation pres) { long convertStart = System.currentTimeMillis(); @@ -69,23 +69,23 @@ public class Pdf2SwfPageConverter implements PageConverter { "/bin/sh", "-c", SWFTOOLS_DIR - + File.separator - + "pdf2swf" - + " -vv " - + AVM2SWF - + " -F " - + fontsDir - + " -p " - + String.valueOf(page) - + " " - + source - + " -o " - + dest - + " | egrep 'shape id|Updating font|Drawing' | sed 's/ / /g' | cut -d' ' -f 1-3 | sort | uniq -cw 15")); + + File.separator + + "pdf2swf" + + " -vv " + + AVM2SWF + + " -F " + + fontsDir + + " -p " + + String.valueOf(page) + + " " + + source + + " -o " + + dest + + " | egrep 'shape id|Updating font|Drawing' | sed 's/ / /g' | cut -d' ' -f 1-3 | sort | uniq -cw 15")); Pdf2SwfPageConverterHandler pHandler = new Pdf2SwfPageConverterHandler(); pb.setProcessListener(pHandler); - + long pdf2SwfStart = System.currentTimeMillis(); NuProcess process = pb.start(); @@ -94,10 +94,10 @@ public class Pdf2SwfPageConverter implements PageConverter { } catch (InterruptedException e) { log.error(e.getMessage()); } - + long pdf2SwfEnd = System.currentTimeMillis(); log.debug("Pdf2Swf conversion duration: {} sec", (pdf2SwfEnd - pdf2SwfStart)/1000); - + File destFile = new File(dest); if (pHandler.isConversionSuccessfull() && destFile.exists() && pHandler.numberOfPlacements() < placementsThreshold @@ -117,9 +117,9 @@ public class Pdf2SwfPageConverter implements PageConverter { logData.put("numImageTags", pHandler.numberOfImageTags()); Gson gson = new Gson(); String logStr = gson.toJson(logData); - + log.warn("Potential problem with generated SWF: data={}", logStr); - + File tempPdfPage = null; File tempPng = null; String basePresentationame = FilenameUtils.getBaseName(presentation.getName()); @@ -151,9 +151,9 @@ public class Pdf2SwfPageConverter implements PageConverter { long gsEnd = System.currentTimeMillis(); log.debug("Ghostscript conversion duration: {} sec", (gsStart - gsEnd)/1000); - + long magickStart = System.currentTimeMillis(); - + // Step 2: Convert a PDF page to PNG NuProcessBuilder pbPng = new NuProcessBuilder(Arrays.asList("timeout", convTimeout, IMAGEMAGICK_DIR + File.separator + "convert", "-density", "150", @@ -175,13 +175,13 @@ public class Pdf2SwfPageConverter implements PageConverter { logData.put("filename", pres.getName()); logData.put("page", page); logData.put("conversionTime(sec)", (magickEnd - magickStart)/1000); - + logStr = gson.toJson(logData); - + log.debug("ImageMagick conversion duration: {} sec", (magickEnd - magickStart)/1000); - + long png2swfStart = System.currentTimeMillis(); - + // Step 3: Convert a PNG image to SWF source = tempPng.getAbsolutePath(); NuProcessBuilder pbSwf = new NuProcessBuilder(Arrays.asList("timeout", convTimeout, SWFTOOLS_DIR @@ -194,10 +194,10 @@ public class Pdf2SwfPageConverter implements PageConverter { } catch (InterruptedException e) { log.error(e.getMessage()); } - + long png2swfEnd = System.currentTimeMillis(); log.debug("ImageMagick conversion duration: {} sec", (png2swfEnd - png2swfStart)/1000); - + // Delete the temporary PNG and PDF files after finishing the image // conversion tempPdfPage.delete(); @@ -213,12 +213,12 @@ public class Pdf2SwfPageConverter implements PageConverter { logData.put("filename", pres.getName()); logData.put("page", page); logData.put("conversionTime(sec)", (convertEnd - convertStart)/1000); - + logStr = gson.toJson(logData); - + log.debug("Problem page conversion duration: {} sec", (convertEnd - convertStart)/1000); - - + + if (doneSwf && destFile.exists()) { return true; } else { diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfPageToImageConversionService.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfPageToImageConversionService.java index 25d345c1a30d4246fc28967f05d6f19e15f1be03..6d6bac69853ae699a52f09fa0c0c78c26e08cbbc 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfPageToImageConversionService.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfPageToImageConversionService.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -28,40 +28,40 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PdfPageToImageConversionService { - private static Logger log = LoggerFactory.getLogger(PdfPageToImageConversionService.class); - - private PageExtractor extractor; - private PageConverter pdfToImageConverter; - private PageConverter imageToSwfConverter; - - public boolean convertPageAsAnImage(File presentationFile, File output, int page, UploadedPresentation pres) { - File tempDir = new File(presentationFile.getParent() + File.separatorChar + "temp"); - tempDir.mkdir(); + private static Logger log = LoggerFactory.getLogger(PdfPageToImageConversionService.class); - File tempPdfFile = new File(tempDir.getAbsolutePath() + File.separator + "temp-" + page + ".pdf"); + private PageExtractor extractor; + private PageConverter pdfToImageConverter; + private PageConverter imageToSwfConverter; - if (extractor.extractPage(presentationFile, tempPdfFile, page)) { - File tempPngFile = new File(tempDir.getAbsolutePath() + "/temp-" + page + ".svg"); + public boolean convertPageAsAnImage(File presentationFile, File output, int page, UploadedPresentation pres) { + File tempDir = new File(presentationFile.getParent() + File.separatorChar + "temp"); + tempDir.mkdir(); - if (pdfToImageConverter.convert(tempPdfFile, tempPngFile, 1, pres)) { - if (imageToSwfConverter.convert(tempPngFile, output, 1, pres)) { - return true; - } - } - } - - return false; - } - - public void setPageExtractor(PageExtractor extractor) { - this.extractor = extractor; - } - - public void setPdfToImageConverter(PageConverter imageConverter) { - this.pdfToImageConverter = imageConverter; - } - - public void setImageToSwfConverter(PageConverter swfConverter) { - this.imageToSwfConverter = swfConverter; - } + File tempPdfFile = new File(tempDir.getAbsolutePath() + File.separator + "temp-" + page + ".pdf"); + + if (extractor.extractPage(presentationFile, tempPdfFile, page)) { + File tempPngFile = new File(tempDir.getAbsolutePath() + "/temp-" + page + ".svg"); + + if (pdfToImageConverter.convert(tempPdfFile, tempPngFile, 1, pres)) { + if (imageToSwfConverter.convert(tempPngFile, output, 1, pres)) { + return true; + } + } + } + + return false; + } + + public void setPageExtractor(PageExtractor extractor) { + this.extractor = extractor; + } + + public void setPdfToImageConverter(PageConverter imageConverter) { + this.pdfToImageConverter = imageConverter; + } + + public void setImageToSwfConverter(PageConverter swfConverter) { + this.imageToSwfConverter = swfConverter; + } } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfToSwfSlidesGenerationService.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfToSwfSlidesGenerationService.java index 6ec9b50d68f1f27c4315e93d2bb3ce21bd56881b..a4e3369bd04e2b39a2e6806bb1c912a4cbf9ada2 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfToSwfSlidesGenerationService.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/PdfToSwfSlidesGenerationService.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -49,254 +49,254 @@ import org.slf4j.LoggerFactory; import com.google.gson.Gson; public class PdfToSwfSlidesGenerationService { - private static Logger log = LoggerFactory.getLogger(PdfToSwfSlidesGenerationService.class); - - private SwfSlidesGenerationProgressNotifier notifier; - private PageCounterService counterService; - private PageConverter pdfToSwfConverter; - private PdfPageToImageConversionService imageConvertService; - private ExecutorService executor; - private ThumbnailCreator thumbnailCreator; - private TextFileCreator textFileCreator; - private SvgImageCreator svgImageCreator; - private long MAX_CONVERSION_TIME = 5*60*1000; - private String BLANK_SLIDE; - private int MAX_SWF_FILE_SIZE; - private boolean svgImagesRequired; - private final long CONVERSION_TIMEOUT = 20000000000L; // 20s - private int NUM_CONVERSION_THREADS = 2; - - public PdfToSwfSlidesGenerationService(int numConversionThreads) { - executor = Executors.newFixedThreadPool(numConversionThreads); - } - - public void generateSlides(UploadedPresentation pres) { - determineNumberOfPages(pres); - if (pres.getNumberOfPages() > 0) { - convertPdfToSwf(pres); - createTextFiles(pres); - createThumbnails(pres); - - // only create SVG images if the configuration requires it - if (svgImagesRequired) { - createSvgImages(pres); - } - - notifier.sendConversionCompletedMessage(pres); - } - } - - private boolean determineNumberOfPages(UploadedPresentation pres) { - try { - counterService.determineNumberOfPages(pres); - return true; - } catch (CountingPageException e) { - sendFailedToCountPageMessage(e, pres); - } - return false; - } - - private void sendFailedToCountPageMessage(CountingPageException e, UploadedPresentation pres) { - MessageBuilder builder = new ConversionUpdateMessage.MessageBuilder(pres); - - if (e.getExceptionType() == CountingPageException.ExceptionType.PAGE_COUNT_EXCEPTION) { - builder.messageKey(ConversionMessageConstants.PAGE_COUNT_FAILED_KEY); - } else if (e.getExceptionType() == CountingPageException.ExceptionType.PAGE_EXCEEDED_EXCEPTION) { - builder.numberOfPages(e.getPageCount()); - builder.maxNumberPages(e.getMaxNumberOfPages()); - builder.messageKey(ConversionMessageConstants.PAGE_COUNT_EXCEEDED_KEY); - } - notifier.sendConversionUpdateMessage(builder.build().getMessage()); - } - - private void createThumbnails(UploadedPresentation pres) { - notifier.sendCreatingThumbnailsUpdateMessage(pres); - thumbnailCreator.createThumbnails(pres); - } - - private void createTextFiles(UploadedPresentation pres) { - notifier.sendCreatingTextFilesUpdateMessage(pres); - textFileCreator.createTextFiles(pres); - } - - private void createSvgImages(UploadedPresentation pres) { - notifier.sendCreatingSvgImagesUpdateMessage(pres); - svgImageCreator.createSvgImages(pres); - } - - private void convertPdfToSwf(UploadedPresentation pres) { - int numPages = pres.getNumberOfPages(); - List<PdfToSwfSlide> slides = setupSlides(pres, numPages); - - CompletionService<PdfToSwfSlide> completionService = new ExecutorCompletionService<PdfToSwfSlide>(executor); - - generateSlides(pres, slides, completionService); - } - - private void generateSlides(UploadedPresentation pres, List<PdfToSwfSlide> slides, CompletionService<PdfToSwfSlide> completionService) { - long MAXWAIT = MAX_CONVERSION_TIME * 60 /*seconds*/ * 1000 /*millis*/; - int slidesCompleted = 0; - - long presConvStart = System.currentTimeMillis(); - - for (final PdfToSwfSlide slide : slides) { - long pageConvStart = System.currentTimeMillis(); - - Callable<PdfToSwfSlide> c = new Callable<PdfToSwfSlide>() { - public PdfToSwfSlide call() { - return slide.createSlide(); - }; - }; - - Future<PdfToSwfSlide> f = executor.submit(c); - long endNanos = System.nanoTime() + CONVERSION_TIMEOUT; - try { - // Only wait for the remaining time budget - long timeLeft = endNanos - System.nanoTime(); - PdfToSwfSlide s = f.get(timeLeft, TimeUnit.NANOSECONDS); - slidesCompleted++; - notifier.sendConversionUpdateMessage(slidesCompleted, pres); - } catch (ExecutionException e) { - Map<String, Object> logData = new HashMap<String, Object>(); - logData.put("meetingId", pres.getMeetingId()); - logData.put("presId", pres.getId()); - logData.put("filename", pres.getName()); - logData.put("page", slide.getPageNumber()); - - Gson gson = new Gson(); - String logStr = gson.toJson(logData); - - log.warn("ExecutionException while converting page: data={}", logStr); - log.error(e.getMessage()); - } catch (InterruptedException e) { - Map<String, Object> logData = new HashMap<String, Object>(); - logData.put("meetingId", pres.getMeetingId()); - logData.put("presId", pres.getId()); - logData.put("filename", pres.getName()); - logData.put("page", slide.getPageNumber()); - - Gson gson = new Gson(); - String logStr = gson.toJson(logData); - - log.warn("InterruptedException while converting page: data={}", logStr); - Thread.currentThread().interrupt(); - } catch (TimeoutException e) { - Map<String, Object> logData = new HashMap<String, Object>(); - logData.put("meetingId", pres.getMeetingId()); - logData.put("presId", pres.getId()); - logData.put("filename", pres.getName()); - logData.put("page", slide.getPageNumber()); - - Gson gson = new Gson(); - String logStr = gson.toJson(logData); - - log.warn("TimeoutException while converting page: data={}", logStr); - f.cancel(true); - } - - long pageConvEnd = System.currentTimeMillis(); - Map<String, Object> logData = new HashMap<String, Object>(); - logData.put("meetingId", pres.getMeetingId()); - logData.put("presId", pres.getId()); - logData.put("filename", pres.getName()); - logData.put("page", slide.getPageNumber()); - logData.put("conversionTime(sec)", (pageConvEnd - pageConvStart)/1000); - Gson gson = new Gson(); - String logStr = gson.toJson(logData); - - log.debug("Page conversion duration(sec): data={}", logStr); - - } - - for (final PdfToSwfSlide slide : slides) { - if (! slide.isDone()){ - - slide.generateBlankSlide(); - - Map<String, Object> logData = new HashMap<String, Object>(); - logData.put("meetingId", pres.getMeetingId()); - logData.put("presId", pres.getId()); - logData.put("filename", pres.getName()); - - Gson gson = new Gson(); - String logStr = gson.toJson(logData); - - log.warn("Creating blank slide: data={}", logStr); - - notifier.sendConversionUpdateMessage(slidesCompleted++, pres); - } - } - - long presConvEnd = System.currentTimeMillis(); + private static Logger log = LoggerFactory.getLogger(PdfToSwfSlidesGenerationService.class); + + private SwfSlidesGenerationProgressNotifier notifier; + private PageCounterService counterService; + private PageConverter pdfToSwfConverter; + private PdfPageToImageConversionService imageConvertService; + private ExecutorService executor; + private ThumbnailCreator thumbnailCreator; + private TextFileCreator textFileCreator; + private SvgImageCreator svgImageCreator; + private long MAX_CONVERSION_TIME = 5*60*1000; + private String BLANK_SLIDE; + private int MAX_SWF_FILE_SIZE; + private boolean svgImagesRequired; + private final long CONVERSION_TIMEOUT = 20000000000L; // 20s + private int NUM_CONVERSION_THREADS = 2; + + public PdfToSwfSlidesGenerationService(int numConversionThreads) { + executor = Executors.newFixedThreadPool(numConversionThreads); + } + + public void generateSlides(UploadedPresentation pres) { + determineNumberOfPages(pres); + if (pres.getNumberOfPages() > 0) { + convertPdfToSwf(pres); + createTextFiles(pres); + createThumbnails(pres); + + // only create SVG images if the configuration requires it + if (svgImagesRequired) { + createSvgImages(pres); + } + + notifier.sendConversionCompletedMessage(pres); + } + } + + private boolean determineNumberOfPages(UploadedPresentation pres) { + try { + counterService.determineNumberOfPages(pres); + return true; + } catch (CountingPageException e) { + sendFailedToCountPageMessage(e, pres); + } + return false; + } + + private void sendFailedToCountPageMessage(CountingPageException e, UploadedPresentation pres) { + MessageBuilder builder = new ConversionUpdateMessage.MessageBuilder(pres); + + if (e.getExceptionType() == CountingPageException.ExceptionType.PAGE_COUNT_EXCEPTION) { + builder.messageKey(ConversionMessageConstants.PAGE_COUNT_FAILED_KEY); + } else if (e.getExceptionType() == CountingPageException.ExceptionType.PAGE_EXCEEDED_EXCEPTION) { + builder.numberOfPages(e.getPageCount()); + builder.maxNumberPages(e.getMaxNumberOfPages()); + builder.messageKey(ConversionMessageConstants.PAGE_COUNT_EXCEEDED_KEY); + } + notifier.sendConversionUpdateMessage(builder.build().getMessage()); + } + + private void createThumbnails(UploadedPresentation pres) { + notifier.sendCreatingThumbnailsUpdateMessage(pres); + thumbnailCreator.createThumbnails(pres); + } + + private void createTextFiles(UploadedPresentation pres) { + notifier.sendCreatingTextFilesUpdateMessage(pres); + textFileCreator.createTextFiles(pres); + } + + private void createSvgImages(UploadedPresentation pres) { + notifier.sendCreatingSvgImagesUpdateMessage(pres); + svgImageCreator.createSvgImages(pres); + } + + private void convertPdfToSwf(UploadedPresentation pres) { + int numPages = pres.getNumberOfPages(); + List<PdfToSwfSlide> slides = setupSlides(pres, numPages); + + CompletionService<PdfToSwfSlide> completionService = new ExecutorCompletionService<PdfToSwfSlide>(executor); + + generateSlides(pres, slides, completionService); + } + + private void generateSlides(UploadedPresentation pres, List<PdfToSwfSlide> slides, CompletionService<PdfToSwfSlide> completionService) { + long MAXWAIT = MAX_CONVERSION_TIME * 60 /*seconds*/ * 1000 /*millis*/; + int slidesCompleted = 0; + + long presConvStart = System.currentTimeMillis(); + + for (final PdfToSwfSlide slide : slides) { + long pageConvStart = System.currentTimeMillis(); + + Callable<PdfToSwfSlide> c = new Callable<PdfToSwfSlide>() { + public PdfToSwfSlide call() { + return slide.createSlide(); + }; + }; + + Future<PdfToSwfSlide> f = executor.submit(c); + long endNanos = System.nanoTime() + CONVERSION_TIMEOUT; + try { + // Only wait for the remaining time budget + long timeLeft = endNanos - System.nanoTime(); + PdfToSwfSlide s = f.get(timeLeft, TimeUnit.NANOSECONDS); + slidesCompleted++; + notifier.sendConversionUpdateMessage(slidesCompleted, pres); + } catch (ExecutionException e) { + Map<String, Object> logData = new HashMap<String, Object>(); + logData.put("meetingId", pres.getMeetingId()); + logData.put("presId", pres.getId()); + logData.put("filename", pres.getName()); + logData.put("page", slide.getPageNumber()); + + Gson gson = new Gson(); + String logStr = gson.toJson(logData); + + log.warn("ExecutionException while converting page: data={}", logStr); + log.error(e.getMessage()); + } catch (InterruptedException e) { + Map<String, Object> logData = new HashMap<String, Object>(); + logData.put("meetingId", pres.getMeetingId()); + logData.put("presId", pres.getId()); + logData.put("filename", pres.getName()); + logData.put("page", slide.getPageNumber()); + + Gson gson = new Gson(); + String logStr = gson.toJson(logData); + + log.warn("InterruptedException while converting page: data={}", logStr); + Thread.currentThread().interrupt(); + } catch (TimeoutException e) { + Map<String, Object> logData = new HashMap<String, Object>(); + logData.put("meetingId", pres.getMeetingId()); + logData.put("presId", pres.getId()); + logData.put("filename", pres.getName()); + logData.put("page", slide.getPageNumber()); + + Gson gson = new Gson(); + String logStr = gson.toJson(logData); + + log.warn("TimeoutException while converting page: data={}", logStr); + f.cancel(true); + } + + long pageConvEnd = System.currentTimeMillis(); Map<String, Object> logData = new HashMap<String, Object>(); logData.put("meetingId", pres.getMeetingId()); logData.put("presId", pres.getId()); logData.put("filename", pres.getName()); - logData.put("conversionTime(sec)", (presConvEnd - presConvStart)/1000); + logData.put("page", slide.getPageNumber()); + logData.put("conversionTime(sec)", (pageConvEnd - pageConvStart)/1000); Gson gson = new Gson(); String logStr = gson.toJson(logData); - - log.debug("Presentation conversion duration (sec): data={}", logStr); - } - - - private List<PdfToSwfSlide> setupSlides(UploadedPresentation pres, int numPages) { - List<PdfToSwfSlide> slides = new ArrayList<PdfToSwfSlide>(numPages); - - for (int page = 1; page <= numPages; page++) { - PdfToSwfSlide slide = new PdfToSwfSlide(pres, page); - slide.setBlankSlide(BLANK_SLIDE); - slide.setMaxSwfFileSize(MAX_SWF_FILE_SIZE); - slide.setPageConverter(pdfToSwfConverter); - slide.setPdfPageToImageConversionService(imageConvertService); - - slides.add(slide); - } - - return slides; - } - - - - public void setCounterService(PageCounterService counterService) { - this.counterService = counterService; - } - - public void setPageConverter(PageConverter converter) { - this.pdfToSwfConverter = converter; - } - - public void setPdfPageToImageConversionService(PdfPageToImageConversionService service) { - this.imageConvertService = service; - } - - public void setBlankSlide(String blankSlide) { - this.BLANK_SLIDE = blankSlide; - } - - public void setMaxSwfFileSize(int size) { - this.MAX_SWF_FILE_SIZE = size; - } - - public void setSvgImagesRequired(boolean svg) { - this.svgImagesRequired = svg; - } - - public void setThumbnailCreator(ThumbnailCreator thumbnailCreator) { - this.thumbnailCreator = thumbnailCreator; - } - public void setTextFileCreator(TextFileCreator textFileCreator) { - this.textFileCreator = textFileCreator; - } - public void setSvgImageCreator(SvgImageCreator svgImageCreator) { - this.svgImageCreator = svgImageCreator; - } - public void setMaxConversionTime(int minutes) { - MAX_CONVERSION_TIME = minutes * 60 * 1000; - } - - public void setSwfSlidesGenerationProgressNotifier(SwfSlidesGenerationProgressNotifier notifier) { - this.notifier = notifier; - } - + + log.debug("Page conversion duration(sec): data={}", logStr); + + } + + for (final PdfToSwfSlide slide : slides) { + if (! slide.isDone()){ + + slide.generateBlankSlide(); + + Map<String, Object> logData = new HashMap<String, Object>(); + logData.put("meetingId", pres.getMeetingId()); + logData.put("presId", pres.getId()); + logData.put("filename", pres.getName()); + + Gson gson = new Gson(); + String logStr = gson.toJson(logData); + + log.warn("Creating blank slide: data={}", logStr); + + notifier.sendConversionUpdateMessage(slidesCompleted++, pres); + } + } + + long presConvEnd = System.currentTimeMillis(); + Map<String, Object> logData = new HashMap<String, Object>(); + logData.put("meetingId", pres.getMeetingId()); + logData.put("presId", pres.getId()); + logData.put("filename", pres.getName()); + logData.put("conversionTime(sec)", (presConvEnd - presConvStart)/1000); + Gson gson = new Gson(); + String logStr = gson.toJson(logData); + + log.debug("Presentation conversion duration (sec): data={}", logStr); + } + + + private List<PdfToSwfSlide> setupSlides(UploadedPresentation pres, int numPages) { + List<PdfToSwfSlide> slides = new ArrayList<PdfToSwfSlide>(numPages); + + for (int page = 1; page <= numPages; page++) { + PdfToSwfSlide slide = new PdfToSwfSlide(pres, page); + slide.setBlankSlide(BLANK_SLIDE); + slide.setMaxSwfFileSize(MAX_SWF_FILE_SIZE); + slide.setPageConverter(pdfToSwfConverter); + slide.setPdfPageToImageConversionService(imageConvertService); + + slides.add(slide); + } + + return slides; + } + + + + public void setCounterService(PageCounterService counterService) { + this.counterService = counterService; + } + + public void setPageConverter(PageConverter converter) { + this.pdfToSwfConverter = converter; + } + + public void setPdfPageToImageConversionService(PdfPageToImageConversionService service) { + this.imageConvertService = service; + } + + public void setBlankSlide(String blankSlide) { + this.BLANK_SLIDE = blankSlide; + } + + public void setMaxSwfFileSize(int size) { + this.MAX_SWF_FILE_SIZE = size; + } + + public void setSvgImagesRequired(boolean svg) { + this.svgImagesRequired = svg; + } + + public void setThumbnailCreator(ThumbnailCreator thumbnailCreator) { + this.thumbnailCreator = thumbnailCreator; + } + public void setTextFileCreator(TextFileCreator textFileCreator) { + this.textFileCreator = textFileCreator; + } + public void setSvgImageCreator(SvgImageCreator svgImageCreator) { + this.svgImageCreator = svgImageCreator; + } + public void setMaxConversionTime(int minutes) { + MAX_CONVERSION_TIME = minutes * 60 * 1000; + } + + public void setSwfSlidesGenerationProgressNotifier(SwfSlidesGenerationProgressNotifier notifier) { + this.notifier = notifier; + } + } diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Png2SwfPageConverter.java b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Png2SwfPageConverter.java index ffa7359bc5b1c7462f7ac5071f9f1aa77d5d70b6..e7c72f6703eeaae771459d422da97fecfb45819f 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Png2SwfPageConverter.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/presentation/imp/Png2SwfPageConverter.java @@ -1,21 +1,21 @@ /** -* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ -* -* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). -* -* This program is free software; you can redistribute it and/or modify it under the -* terms of the GNU Lesser General Public License as published by the Free Software -* Foundation; either version 3.0 of the License, or (at your option) any later -* version. -* -* BigBlueButton 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 GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License along -* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. -* -*/ + * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/ + * + * Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BigBlueButton 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 GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. + * + */ package org.bigbluebutton.presentation.imp; @@ -27,25 +27,25 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Png2SwfPageConverter implements PageConverter { - private static Logger log = LoggerFactory.getLogger(Png2SwfPageConverter.class); - - private String SWFTOOLS_DIR; - - public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ - String COMMAND = SWFTOOLS_DIR + "/png2swf -o " + output.getAbsolutePath() + " " + presentationFile.getAbsolutePath(); - - boolean done = new ExternalProcessExecutor().exec(COMMAND, 60000); - - if (done && output.exists()) { - return true; - } else { - log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); - return false; - } - } - - public void setSwfToolsDir(String dir) { - SWFTOOLS_DIR = dir; - } + private static Logger log = LoggerFactory.getLogger(Png2SwfPageConverter.class); + + private String SWFTOOLS_DIR; + + public boolean convert(File presentationFile, File output, int page, UploadedPresentation pres){ + String COMMAND = SWFTOOLS_DIR + "/png2swf -o " + output.getAbsolutePath() + " " + presentationFile.getAbsolutePath(); + + boolean done = new ExternalProcessExecutor().exec(COMMAND, 60000); + + if (done && output.exists()) { + return true; + } else { + log.warn("Failed to convert: " + output.getAbsolutePath() + " does not exist."); + return false; + } + } + + public void setSwfToolsDir(String dir) { + SWFTOOLS_DIR = dir; + } }