Package org.apache.openmeetings.documents.beans

Examples of org.apache.openmeetings.documents.beans.ConverterProcessResult


import org.dom4j.io.XMLWriter;

public class CreateLibraryPresentation {
  public static ConverterProcessResult generateXMLDocument(File targetDirectory, String originalDocument,
      String pdfDocument, String swfDocument){
    ConverterProcessResult returnMap = new ConverterProcessResult();
    returnMap.setProcess("generateXMLDocument");   
    try {
     
          Document document = DocumentHelper.createDocument();
          Element root = document.addElement( "presentation" );

          File file = new File(targetDirectory, originalDocument);
          root.addElement( "originalDocument" )
        .addAttribute("lastmod", (new Long(file.lastModified())).toString())
        .addAttribute("size", (new Long(file.length())).toString())         
              .addText( originalDocument );
         
          if (pdfDocument!=null){
            File pdfDocumentFile = new File(targetDirectory, pdfDocument);
            root.addElement( "pdfDocument" )
          .addAttribute("lastmod", (new Long(pdfDocumentFile.lastModified())).toString())
          .addAttribute("size", (new Long(pdfDocumentFile.length())).toString())                
                .addText( pdfDocument );
          }
         
          if (swfDocument!=null){
            File swfDocumentFile = new File(targetDirectory, originalDocument);
            root.addElement( "swfDocument" )
          .addAttribute("lastmod", (new Long(swfDocumentFile.lastModified())).toString())
          .addAttribute("size", (new Long(swfDocumentFile.length())).toString())               
                .addText( swfDocument );   
          }
         
          Element thumbs = root.addElement( "thumbs" );
         
      //Secoond get all Files of this Folder
      FilenameFilter ff = new FilenameFilter() {
           public boolean accept(File b, String name) {
              File f = new File(b, name);
                return f.isFile();
           }
      }
     
      String[] allfiles = targetDirectory.list(ff);     
      if(allfiles!=null){
        Arrays.sort(allfiles);
        for(int i=0; i<allfiles.length; i++){
          File thumbfile = new File(targetDirectory, allfiles[i]);
          if (allfiles[i].startsWith("_thumb_")){
            thumbs.addElement( "thumb" )
              .addAttribute("lastmod", (new Long(thumbfile.lastModified())).toString())
              .addAttribute("size", (new Long(thumbfile.length())).toString())
                    .addText( allfiles[i] );
          }
        }
      }
         
          // lets write to a file
          XMLWriter writer = new XMLWriter(
              new FileOutputStream(new File(targetDirectory, OmFileHelper.libraryFileName))
          );
          writer.write( document );
          writer.close();
     
          returnMap.setExitValue("0");
         
      return returnMap;
    } catch (Exception err) {
      err.printStackTrace();
      returnMap.setError(err.getMessage());
      returnMap.setExitValue("-1");
      return returnMap;
    }
  }
View Full Code Here


    File destinationFile = OmFileHelper.getNewFile(OmFileHelper.getUploadRoomDir(roomName), fileName, ".jpg");

    log.debug("##### convertImage destinationFile: " + destinationFile);

    ConverterProcessResult processJPG = this.convertSingleJpg(
        fileFullPath.getCanonicalPath(), destinationFile);
    ConverterProcessResult processThumb = generateThumbs.generateThumb(
        "_thumb_", destinationFile, 50);

    returnMap.addItem("processJPG", processJPG);
    returnMap.addItem("processThumb", processThumb);
View Full Code Here

    File working_pptdir = OmFileHelper.getUploadTempProfilesUserDir(users_id);

    String fileFullPath = new File(working_pptdir, fileName + fileExt).getCanonicalPath();

    File destinationFile = OmFileHelper.getNewFile(OmFileHelper.getUploadProfilesUserDir(users_id), fileName, ".jpg");
    ConverterProcessResult processJPG = this.convertSingleJpg(
        fileFullPath, destinationFile);

    ConverterProcessResult processThumb1 = generateThumbs.generateThumb(
        "_chat_", destinationFile, 40);
    ConverterProcessResult processThumb2 = generateThumbs.generateThumb(
        "_profile_", destinationFile, 126);
    ConverterProcessResult processThumb3 = generateThumbs.generateThumb(
        "_big_", destinationFile, 240);

    returnMap.addItem("processJPG", processJPG);
    returnMap.addItem("processThumb1", processThumb1);
    returnMap.addItem("processThumb2", processThumb2);
View Full Code Here

      System.arraycopy(argv, 0, cmd, 2, argv.length);
      Map<String, String> env = new HashMap<String, String>();
      return executeScript(process, cmd, env);
    } catch (Exception t) {
      log.error("executeScriptWindows", t);
      return new ConverterProcessResult(process, t.getMessage(), t);
    }
  }
View Full Code Here

    return executeScript(process, argv, env);
  }
 
  public static ConverterProcessResult executeScript(String process,
      String[] argv, Map<? extends String, ? extends String> env) {
    ConverterProcessResult returnMap = new ConverterProcessResult();
    returnMap.setProcess(process);
    log.debug("process: " + process);
    log.debug("args: " + Arrays.toString(argv));
 
    try {
      returnMap.setCommand(Arrays.toString(argv));
      returnMap.setOut("");
 
      // By using the process Builder we have access to modify the
      // environment variables
      // that is handy to set variables to run it inside eclipse
      ProcessBuilder pb = new ProcessBuilder(argv);
      pb.environment().putAll(env);
 
      Process proc = pb.start();
 
      // 20-minute timeout for command execution
      // FFMPEG conversion of Recordings may take a real long time until
      // its finished
      long timeout = 60000 * 20;
 
      StreamWatcher errorWatcher = new StreamWatcher(proc, true);
      Worker worker = new Worker(proc);
      StreamWatcher inputWatcher = new StreamWatcher(proc, false);
      errorWatcher.start();
      inputWatcher.start();
      worker.start();
     
      try {
        worker.join(timeout);
        if (worker.exitCode != null) {
          returnMap.setExitValue(""+worker.exitCode);
          log.debug("exitVal: " + worker.exitCode);
          returnMap.setError(errorWatcher.output.toString());
        } else {
          returnMap.setException("timeOut");
          returnMap.setError(errorWatcher.output.toString());
          returnMap.setExitValue("-1");
 
          throw new TimeoutException();
        }
      } catch (InterruptedException ex) {
        worker.interrupt();
        errorWatcher.interrupt();
        inputWatcher.interrupt();
        Thread.currentThread().interrupt();
 
        returnMap.setError(ex.getMessage());
        returnMap.setExitValue("-1");
 
        throw ex;
      } finally {
        proc.destroy();
      }
     
    } catch (TimeoutException e) {
      // Timeout exception is processed above
      log.error("executeScript",e);
      returnMap.setError(e.getMessage());
      returnMap.setException(e.toString());
      returnMap.setExitValue("-1");
    } catch (Throwable t) {
      // Any other exception is shown in debug window
      log.error("executeScript",t);
      returnMap.setError(t.getMessage());
      returnMap.setException(t.toString());
      returnMap.setExitValue("-1");
    }
   
    return returnMap;
  }
View Full Code Here

      // Add empty pieces at the beginning and end of the wav
      // FIXME: Is this really needed anymore?!

    } catch (Exception err) {
      log.error("[startConversion]", err);
      returnLog.add(new ConverterProcessResult("startConversion", err.getMessage(), err));
    }

    return returnLog;

  }
View Full Code Here

        // log.debug(" i " + i + " argv-i " + argv_fullFLV[i]);
      }
      log.debug(tString);
      log.debug("END generateFullFLV ################# ");
     
      ConverterProcessResult returnMapConvertFLV = ProcessHelper.executeScript("uploadFLV ID :: "
          + fileExplorerItem.getFileExplorerItemId(), argv_fullFLV);
     
      //Parse the width height from the FFMPEG output
      FlvDimension flvDimension = getFlvDimension(returnMapConvertFLV.getError());
      int flvWidth = flvDimension.width;
      int flvHeight = flvDimension.height;
     
     
      fileExplorerItem.setFlvWidth(flvWidth);
      fileExplorerItem.setFlvHeight(flvHeight);

      returnLog.add(returnMapConvertFLV);

      String hashFileFullNameJPEG = "UPLOADFLV_"
          + fileExplorerItem.getFileExplorerItemId() + ".jpg";
      File outPutJpeg = new File(getStreamFolder(), name + ".jpg");

      fileExplorerItem.setPreviewImage(hashFileFullNameJPEG);

      String[] argv_previewFLV = new String[] { getPathToFFMPEG(), "-i",
          outputFullFlv.getCanonicalPath(), "-vcodec", "mjpeg", "-vframes", "1", "-an",
          "-f", "rawvideo", "-s", flvWidth + "x" + flvHeight,
          outPutJpeg.getCanonicalPath() };

      log.debug("START previewFullFLV ################# ");
      log.debug(argv_previewFLV.toString());
      String kString = "";
      for (int i = 0; i < argv_previewFLV.length; i++) {
        kString += argv_previewFLV[i] + " ";
        // log.debug(" i " + i + " argv-i " + argv_previewFLV[i]);
      }
      log.debug(kString);
      log.debug("END previewFullFLV ################# ");

      returnLog.add(ProcessHelper.executeScript("previewUpload ID :: "
              + fileExplorerItem.getFileExplorerItemId(),
              argv_previewFLV));

      this.fileExplorerItemDaoImpl.updateFileOrFolder(fileExplorerItem);

      for (ConverterProcessResult returnMap : returnLog) {
        this.flvRecordingLogDaoImpl.addFLVRecordingLog(
            "generateFFMPEG", null, returnMap);
      }
     
     

    } catch (Exception err) {
      log.error("[convertToFLV]", err);
      returnLog.add(new ConverterProcessResult("convertToFLV", err.getMessage(), err));
    }

    return returnLog;
  }
View Full Code Here

        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;
        }

        File completeName = new File(
          isAsIs ? OmFileHelper.getUploadFilesDir() : OmFileHelper.getUploadTempFilesDir()
          , newFileSystemName + newFileExtDot);
        log.debug("writing file to: " + completeName);
        FileHelper.copy(is, completeName);
        is.close();

        Long ownerId = null;
        if (parentFolderId == -2) {
            parentFolderId = 0L;
            ownerId = userId;
        }
        if (isOwner) {
            ownerId = userId;
        }

        String fileHashName = newFileSystemName + newFileExtDot;
        Boolean isPresentation = false;
        if (canBeConverted || isPdf) {
            // In case of a presentation the hash is a folder-name
            fileHashName = newFileSystemName;
            isPresentation = true;
        }
        if (isImage) {
            fileHashName = newFileSystemName + ".jpg";
        }
        if (isVideo) {
            fileHashName = newFileSystemName + ".flv";
        }

        FileExplorerItem fileExplorerItem = fileExplorerItemDao.getFileExplorerItemsById(parentFolderId);

        if (fileExplorerItem != null) {
            if (fileExplorerItem.getIsFolder() == null
                    || !fileExplorerItem.getIsFolder()) {
                parentFolderId = 0L;
            }
        }

        Long fileExplorerItemId = fileExplorerItemDao.add(
                fileSystemName, fileHashName, // The Hashname of the file
                parentFolderId, ownerId, room_id, userId, false, // isFolder
                isImage, isPresentation, "", false, isChart,
                externalFileId, externalType);
        log.debug("fileExplorerItemId: " + fileExplorerItemId);
       
       
       
        log.debug("canBeConverted: " + canBeConverted);
        if (canBeConverted) {
            // convert to pdf, thumbs, swf and xml-description
            returnError = generatePDF.convertPDF(newFileSystemName, "files", true, completeName);
        } else if (isPdf) {
            // convert to thumbs, swf and xml-description
            returnError = generatePDF.convertPDF(newFileSystemName, "files", false, completeName);
        } else if (isChart) {
            log.debug("uploaded chart file");
        } else if (isImage && !isAsIs) {
            // convert it to JPG
            log.debug("##### convert it to JPG: ");
            returnError = generateImage.convertImage(newFileSystemName, newFileExtDot, "files",
                    newFileSystemName, false);
        } else if (isAsIs) {
          ConverterProcessResult processThumb = generateThumbs.generateThumb("_thumb_", completeName, 50);
            returnError.addItem("processThumb", processThumb);
        } else if (isVideo) {
          List<ConverterProcessResult> returnList = flvExplorerConverter.startConversion(fileExplorerItemId, completeName.getCanonicalPath());
         
          int i=0;
View Full Code Here

    File fileFullPath = new File(OmFileHelper.getUploadTempRoomDir(roomName), inFileName);
    File destinationFolder = OmFileHelper.getNewDir(OmFileHelper.getUploadRoomDir(roomName), fileName);

    log.debug("fullProcessing: " + fullProcessing);
    if (fullProcessing) {
      ConverterProcessResult processOpenOffice = doJodConvert(
          fileFullPath, destinationFolder, fileName);
      returnError.addItem("processOpenOffice", processOpenOffice);
      ConverterProcessResult processThumb = generateThumbs
          .generateBatchThumb(new File(destinationFolder, fileName + ".pdf"), destinationFolder, 80, "thumb");
      returnError.addItem("processThumb", processThumb);
      ConverterProcessResult processSWF = generateSWF
          .generateSwf(destinationFolder, destinationFolder, fileName);
      returnError.addItem("processSWF", processSWF);
    } else {

      log.debug("-- generateBatchThumb --");

      ConverterProcessResult processThumb = generateThumbs
          .generateBatchThumb(fileFullPath, destinationFolder, 80, "thumb");
      returnError.addItem("processThumb", processThumb);

      ConverterProcessResult processSWF = generateSWF.generateSwf(
          fileFullPath.getParentFile(), destinationFolder, fileName);
      returnError.addItem("processSWF", processSWF);
    }

    // now it should be completed so copy that file to the expected location
    File fileWhereToMove = new File(destinationFolder, inFileName);
    fileWhereToMove.createNewFile();
    FileHelper.moveRec(inFile, fileWhereToMove);

    if (fullProcessing) {
      ConverterProcessResult processXML = CreateLibraryPresentation
          .generateXMLDocument(destinationFolder,
              inFileName, fileName + ".pdf",
              fileName + ".swf");
      returnError.addItem("processXML", processXML);
    } else {
      ConverterProcessResult processXML = CreateLibraryPresentation
          .generateXMLDocument(destinationFolder,
              inFileName, null, fileName + ".swf");
      returnError.addItem("processXML", processXML);
    }
View Full Code Here

      return ProcessHelper.executeScript("doJodConvert",
          argv.toArray(new String[argv.size()]));

    } catch (Exception ex) {
      log.error("doJodConvert", ex);
      return new ConverterProcessResult("doJodConvert", ex.getMessage(), ex);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.openmeetings.documents.beans.ConverterProcessResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.