Package com.artofsolving.jodconverter.openoffice.connection

Examples of com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection


            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp(syntax, OPTIONS);
            System.exit(EXIT_CODE_TOO_FEW_ARGS);
        }

        OpenOfficeConnection connection = new DokeosSocketOfficeConnection(port);
        try {
            if (verbose) {
                System.out.println("-- connecting to OpenOffice.org on port " + port);
            }
            connection.connect();
        } catch (ConnectException officeNotRunning) {
            System.err
                    .println("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                            + port + ".");
            System.exit(EXIT_CODE_CONNECTION_FAILED);
        }
        try {
         
         
          // choose the good constructor to deal with the conversion
          DocumentConverter converter;
          if(dokeosMode.equals("oogie")){
            converter = new OogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height);
          }
          else if(dokeosMode.equals("woogie")){
            converter = new WoogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height);
          }
          else {
            converter = new OpenOfficeDocumentConverter(connection);
          }
         
         
            if (outputFormat == null) {
                File inputFile = new File(fileNames[0]);
                File outputFile = new File(fileNames[1]);
                convertOne(converter, inputFile, outputFile, verbose);
            } else {
                for (int i = 0; i < fileNames.length; i++) {
                    File inputFile = new File(fileNames[i]);
                    File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                            + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                    convertOne(converter, inputFile, outputFile, verbose);
                }
            }
        }
        catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e)
        {
          connection.disconnect();
          System.err.println("ERROR: conversion failed.");
          System.exit(EXIT_CODE_CONVERSION_FAILED);
        }
        finally {
            if (verbose) {
                System.out.println("-- disconnecting");
            }
            connection.disconnect();
        }
    }
View Full Code Here


            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp(syntax, OPTIONS);
            System.exit(EXIT_CODE_TOO_FEW_ARGS);
        }

        OpenOfficeConnection connection = new SocketOpenOfficeConnection(port);
        try {
            if (verbose) {
                System.out.println("-- connecting to OpenOffice.org on port " + port);
            }
            connection.connect();
        } catch (ConnectException officeNotRunning) {
            System.err
                    .println("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                            + port + ".");
            System.exit(EXIT_CODE_CONNECTION_FAILED);
        }
        try {
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            if (outputFormat == null) {
                File inputFile = new File(fileNames[0]);
                File outputFile = new File(fileNames[1]);
                convertOne(converter, inputFile, outputFile, verbose);
            } else {
                for (int i = 0; i < fileNames.length; i++) {
                    File inputFile = new File(fileNames[i]);
                    File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                            + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                    convertOne(converter, inputFile, outputFile, verbose);
                }
            }
        } finally {
            if (verbose) {
                System.out.println("-- disconnecting");
            }
            connection.disconnect();
        }
    }
View Full Code Here

            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp(syntax, OPTIONS);
            System.exit(EXIT_CODE_TOO_FEW_ARGS);
        }

        OpenOfficeConnection connection = new SocketOpenOfficeConnection(port);
        try {
            if (verbose) {
                System.out.println("-- connecting to OpenOffice.org on port " + port);
            }
            connection.connect();
        } catch (ConnectException officeNotRunning) {
            System.err.println("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port " + port + ".");
            System.exit(EXIT_CODE_CONNECTION_FAILED);
        }
        try {
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry);
            if (outputFormat == null) {
                File inputFile = new File(fileNames[0]);
                File outputFile = new File(fileNames[1]);
                convertOne(converter, inputFile, outputFile, verbose);
            } else {
                for (int i = 0; i < fileNames.length; i++) {
                    File inputFile = new File(fileNames[i]);
                    File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                            + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                    convertOne(converter, inputFile, outputFile, verbose);
                }
            }
        } finally {
            if (verbose) {
                System.out.println("-- disconnecting");
            }
            connection.disconnect();
        }
    }
View Full Code Here

      catch(NumberFormatException nfe)
      {
        // Do nothing. Use the default value of 20 instead.
      }
     
      OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);     
     
      //------------------------
      // Setup the output files
      //------------------------
     
      String fileName     = aDocFile.getName().substring(0, aDocFile.getName().indexOf("."));
      int idIndex       = fileName.indexOf("_");
      String digitalAssetPath = CmsPropertyHandler.getDigitalAssetPath();
      String folderName    = "";
     
      if(idIndex > -1)
      {
        String fileIdString = fileName.substring(0, idIndex);
        int fileId       = Integer.parseInt(fileIdString);
        folderName   = "" + (fileId / 1000);
        digitalAssetPath  = digitalAssetPath + File.separator + folderName;
      }
               
      //----------------------------------------
      // Add the name of the folder to the path
      //----------------------------------------
     
      digitalAssetPath     = digitalAssetPath + File.separator + fileName;
     
      logger.info("Directory to write files to: " + digitalAssetPath);     
     
      //-------------------------------------------------
      // Add a folder where the files are to be written.
      //-------------------------------------------------
     
      String newFilePath     = digitalAssetPath + File.separator + fileName;
           
      File pdfFile       = new File(newFilePath + ".pdf");
      File odtFile       = new File(newFilePath + ".odt");
      File htmlFile       = new File(newFilePath + ".html");
      File contentXmlFile   = new File(digitalAssetPath + File.separator + "content.xml");;
     
      //----------------------------------------------
      // Check if the doc has already been converted.
      // If it has, we don't need another conversion.
      //----------------------------------------------
     
      File documentDir = new File(digitalAssetPath);
      if (!documentDir.exists() || rewrite.equals("true"))
      {
        logger.info("The directory " + digitalAssetPath + " does not exist. Creating it.");
       
        documentDir.mkdir();
       
        logger.info("The directory " + digitalAssetPath + " was successfully created.");
       
        logger.info("Connecting to server...");               
       
        connection.connect();
       
        logger.info("Connection ok");
       
        logger.info("Conversion START");
         
        convertDocument(aDocFile, htmlFile, connection);
        if(!aDocFile.getName().substring(aDocFile.getName().indexOf(".") + 1).equalsIgnoreCase("odt"))
        {
          convertDocument(aDocFile, odtFile, connection);
        }
        else
        {
          odtFile = aDocFile;
        }

        convertDocument(aDocFile, pdfFile, connection);
        connection.disconnect();
       
        logger.info("Conversion END");     
       
        //------------------------------------------------
        // Extract the content.xml file from the ODT file
View Full Code Here

        if (outputFormats.length == 0) {
            getLog().warn("No outputFormat specified.");
            return;
        }
       
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(port);
        try {
            connection.connect();
        } catch (ConnectException connectException) {
            throw new MojoExecutionException(
                "Could not connect to OpenOffice.org on port " + port + ". " +
                "Start with: soffice -accept=\"socket,host=127.0.0.1,port=" + port + ";urp;\"", connectException);
        }
       
        getLog().info("Converting documents from " + sourceDirectory + " to " + outputDirectory + " ...");
        try {
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            for (int inputIndex = 0; inputIndex < sourceNames.length; inputIndex++) {
                String inputName = sourceNames[inputIndex];
                File inputFile = FileUtils.resolveFile(sourceDirectory, inputName);
                for (int formatIndex = 0; formatIndex < outputFormats.length; formatIndex++) {
                    String format = outputFormats[formatIndex];
                    String outputName = FileUtils.removeExtension(inputName) + "." + format;
                    File outputFile = FileUtils.resolveFile(outputDirectory, outputName);
                    getLog().info("converting " + inputName + " to " + outputName);
                    converter.convert(inputFile, outputFile);
                }
            }
        } finally {
            connection.disconnect();
        }
    }
View Full Code Here

            System.err.println("USAGE: "+ ConvertDocument.class.getName() +" <input-file> <output-file>");
            return EXIT_CODE_TOO_FEW_ARGS;
        }
        File inputFile = new File(args[0]);
        File outputFile = new File(args[1]);
        OpenOfficeConnection connection = new SocketOpenOfficeConnection();
        try {
            connection.connect();
        } catch (ConnectException officeNotRunning) {
            System.err.println("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "+ SocketOpenOfficeConnection.DEFAULT_PORT +".");
            return EXIT_CODE_CONNECTION_FAILED;
        }
        try {
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, outputFile);
        } finally {
            connection.disconnect();
        }
        return EXIT_CODE_SUCCESS;
    }
View Full Code Here

TOP

Related Classes of com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection

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.