Package org.apache.openmeetings.documents.beans

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


  private static final Logger log = Red5LoggerFactory.
      getLogger(CreateLibraryPresentation.class, OpenmeetingsVariables.webAppRootKey);
 
  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) {
      log.error("[generateXMLDocument]", err);
      returnMap.setError(err.getMessage());
      returnMap.setExitValue("-1");
      return returnMap;
    }
  }
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

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.