org.artofsolving.jodconverter.util.PlatformUtils Java Examples

The following examples show how to use org.artofsolving.jodconverter.util.PlatformUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultOfficeManagerConfiguration.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
private ProcessManager findBestProcessManager() {
    if (isSigarAvailable()) {
        return new SigarProcessManager();
    } else if (PlatformUtils.isLinux()) {
    	LinuxProcessManager processManager = new LinuxProcessManager();
    	if (runAsArgs != null) {
    		processManager.setRunAsArgs(runAsArgs);
    	}
    	return processManager;
    } else {
        // NOTE: UnixProcessManager can't be trusted to work on Solaris
        // because of the 80-char limit on ps output there  
        return new PureJavaProcessManager();
    }
}
 
Example #2
Source File: OfficeProcess.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
public void start(boolean restart) throws IOException {
     ProcessQuery processQuery = new ProcessQuery("soffice.bin", unoUrl.getAcceptString());
     long existingPid = processManager.findPid(processQuery);
 	if (!(existingPid == PID_NOT_FOUND || existingPid == PID_UNKNOWN)) {
throw new IllegalStateException(String.format("a process with acceptString '%s' is already running; pid %d",
        unoUrl.getAcceptString(), existingPid));
     }
 	if (!restart) {
 	    prepareInstanceProfileDir();
 	}
     List<String> command = new ArrayList<String>();
     File executable = OfficeUtils.getOfficeExecutable(officeHome);
     if (runAsArgs != null) {
     	command.addAll(Arrays.asList(runAsArgs));
     }
     command.add(executable.getAbsolutePath());
     command.add("-accept=" + unoUrl.getAcceptString() + ";urp;");
     command.add("-env:UserInstallation=" + OfficeUtils.toUrl(instanceProfileDir));
     command.add("-headless");
     command.add("-nocrashreport");
     command.add("-nodefault");
     command.add("-nofirststartwizard");
     command.add("-nolockcheck");
     command.add("-nologo");
     command.add("-norestore");
     ProcessBuilder processBuilder = new ProcessBuilder(command);
     if (PlatformUtils.isWindows()) {
         addBasisAndUrePaths(processBuilder);
     }
     logger.info(String.format("starting process with acceptString '%s' and profileDir '%s'", unoUrl, instanceProfileDir));
     process = processBuilder.start();
     pid = processManager.findPid(processQuery);
     if (pid == PID_NOT_FOUND) {
         throw new IllegalStateException(String.format("process with acceptString '%s' started but its pid could not be found",
                 unoUrl.getAcceptString()));
     }
     logger.info("started process" + (pid != PID_UNKNOWN ? "; pid = " + pid : ""));
 }
 
Example #3
Source File: OfficeUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
public static File getDefaultOfficeHome() {
    if (System.getProperty("office.home") != null) {
        return new File(System.getProperty("office.home"));
    }
    if (PlatformUtils.isWindows()) {
        // %ProgramFiles(x86)% on 64-bit machines; %ProgramFiles% on 32-bit ones
        String programFiles = System.getenv("ProgramFiles(x86)");
        if (programFiles == null) {
            programFiles = System.getenv("ProgramFiles");
        }
        return findOfficeHome(
            programFiles + File.separator + "OpenOffice 4",
            programFiles + File.separator + "LibreOffice 4"
        );
    } else if (PlatformUtils.isMac()) {
        return findOfficeHome(
            "/Applications/OpenOffice.org.app/Contents",
            "/Applications/LibreOffice.app/Contents"
        );
    } else {
        // Linux or other *nix variants
        return findOfficeHome(
            "/opt/openoffice.org3",
            "/opt/libreoffice",
            "/usr/lib/openoffice",
            "/usr/lib/libreoffice"
        );
    }
}
 
Example #4
Source File: OfficeUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
public static File getOfficeExecutable(File officeHome) {
    if (PlatformUtils.isMac()) {
        return new File(officeHome, "MacOS/soffice.bin");
    } else {
        return new File(officeHome, "program/soffice.bin");
    }
}
 
Example #5
Source File: DefaultOfficeManagerConfiguration.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
private ProcessManager findBestProcessManager() {
    if (isSigarAvailable()) {
        return new SigarProcessManager();
    } else if (PlatformUtils.isLinux()) {
    	LinuxProcessManager processManager = new LinuxProcessManager();
    	if (runAsArgs != null) {
    		processManager.setRunAsArgs(runAsArgs);
    	}
    	return processManager;
    } else {
        // NOTE: UnixProcessManager can't be trusted to work on Solaris
        // because of the 80-char limit on ps output there  
        return new PureJavaProcessManager();
    }
}
 
Example #6
Source File: OfficeProcess.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
public void start(boolean restart) throws IOException {
     ProcessQuery processQuery = new ProcessQuery("soffice.bin", unoUrl.getAcceptString());
     long existingPid = processManager.findPid(processQuery);
 	if (!(existingPid == PID_NOT_FOUND || existingPid == PID_UNKNOWN)) {
throw new IllegalStateException(String.format("a process with acceptString '%s' is already running; pid %d",
        unoUrl.getAcceptString(), existingPid));
     }
 	if (!restart) {
 	    prepareInstanceProfileDir();
 	}
     List<String> command = new ArrayList<String>();
     File executable = OfficeUtils.getOfficeExecutable(officeHome);
     if (runAsArgs != null) {
     	command.addAll(Arrays.asList(runAsArgs));
     }
     command.add(executable.getAbsolutePath());
     command.add("-accept=" + unoUrl.getAcceptString() + ";urp;");
     command.add("-env:UserInstallation=" + OfficeUtils.toUrl(instanceProfileDir));
     command.add("-headless");
     command.add("-nocrashreport");
     command.add("-nodefault");
     command.add("-nofirststartwizard");
     command.add("-nolockcheck");
     command.add("-nologo");
     command.add("-norestore");
     ProcessBuilder processBuilder = new ProcessBuilder(command);
     if (PlatformUtils.isWindows()) {
         addBasisAndUrePaths(processBuilder);
     }
     logger.info(String.format("starting process with acceptString '%s' and profileDir '%s'", unoUrl, instanceProfileDir));
     process = processBuilder.start();
     pid = processManager.findPid(processQuery);
     if (pid == PID_NOT_FOUND) {
         throw new IllegalStateException(String.format("process with acceptString '%s' started but its pid could not be found",
                 unoUrl.getAcceptString()));
     }
     logger.info("started process" + (pid != PID_UNKNOWN ? "; pid = " + pid : ""));
 }
 
Example #7
Source File: OfficeUtils.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
public static File getOfficeExecutable(File officeHome) {
    if (PlatformUtils.isMac()) {
        return new File(officeHome, "MacOS/soffice");
    } else {
        return new File(officeHome, "program/soffice.bin");
    }
}
 
Example #8
Source File: DefaultOfficeManagerConfiguration.java    From wenku with MIT License 5 votes vote down vote up
private ProcessManager findBestProcessManager() {
    if (PlatformUtils.isLinux()) {
    	LinuxProcessManager processManager = new LinuxProcessManager();
    	if (runAsArgs != null) {
    		processManager.setRunAsArgs(runAsArgs);
    	}
    	return processManager;
    } else {
        // NOTE: UnixProcessManager can't be trusted to work on Solaris
        // because of the 80-char limit on ps output there  
        return new PureJavaProcessManager();
    }
}
 
Example #9
Source File: OfficeProcess.java    From wenku with MIT License 5 votes vote down vote up
public void start(boolean restart) throws IOException {
    ProcessQuery processQuery = new ProcessQuery("soffice.bin", unoUrl.getAcceptString());
    long existingPid = processManager.findPid(processQuery);
    if (!(existingPid == PID_NOT_FOUND || existingPid == PID_UNKNOWN)) {
        throw new IllegalStateException(String.format("a process with acceptString '%s' is already running; pid %d", unoUrl.getAcceptString(), existingPid));
    }
    if (!restart) {
        prepareInstanceProfileDir();
    }
    List<String> command = new ArrayList<String>();
    File executable = OfficeUtils.getOfficeExecutable(officeHome);
    if (runAsArgs != null) {
        command.addAll(Arrays.asList(runAsArgs));
    }
    command.add(executable.getAbsolutePath());
    command.add("-accept=" + unoUrl.getAcceptString() + ";urp;");
    command.add("-env:UserInstallation=" + OfficeUtils.toUrl(instanceProfileDir));
    command.add("-headless");
    command.add("-nocrashreport");
    command.add("-nodefault");
    command.add("-nofirststartwizard");
    command.add("-nolockcheck");
    command.add("-nologo");
    command.add("-norestore");
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    if (PlatformUtils.isWindows()) {
        addBasisAndUrePaths(processBuilder);
    }
    logger.info(String.format("starting process with acceptString '%s' and profileDir '%s'", unoUrl, instanceProfileDir));
    process = processBuilder.start();
    pid = processManager.findPid(processQuery);
    if (pid == PID_NOT_FOUND) {
        throw new IllegalStateException(String.format("process with acceptString '%s' started but its pid could not be found", unoUrl.getAcceptString()));
    }
    logger.info("started process" + (pid != PID_UNKNOWN ? "; pid = " + pid : ""));
}
 
Example #10
Source File: OfficeUtils.java    From wenku with MIT License 5 votes vote down vote up
public static File getDefaultOfficeHome() {
    if (System.getProperty("office.home") != null) {
        return new File(System.getProperty("office.home"));
    }
    if (PlatformUtils.isWindows()) {
        // %ProgramFiles(x86)% on 64-bit machines; %ProgramFiles% on 32-bit ones
        String programFiles = System.getenv("ProgramFiles(x86)");
        if (programFiles == null) {
            programFiles = System.getenv("ProgramFiles");
        }
        return findOfficeHome(
            programFiles + File.separator + "OpenOffice.org 3",
            programFiles + File.separator + "LibreOffice 3"
        );
    } else if (PlatformUtils.isMac()) {
        return findOfficeHome(
            "/Applications/OpenOffice.org.app/Contents",
            "/Applications/LibreOffice.app/Contents"
        );
    } else {
        // Linux or other *nix variants
        return findOfficeHome(
            "/opt/openoffice.org3",
            "/opt/libreoffice",
            "/usr/lib/openoffice",
            "/usr/lib/libreoffice"
        );
    }
}
 
Example #11
Source File: OfficeUtils.java    From wenku with MIT License 5 votes vote down vote up
public static File getOfficeExecutable(File officeHome) {
    if (PlatformUtils.isMac()) {
        return new File(officeHome, "MacOS/soffice.bin");
    } else {
        return new File(officeHome, "program/soffice.bin");
    }
}
 
Example #12
Source File: OfficeUtils.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
public static File getDefaultOfficeHome() {
    Properties properties = new Properties();
    String customizedConfigPath = getCustomizedConfigPath();
    try {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(customizedConfigPath));
        properties.load(bufferedReader);
        restorePropertiesFromEnvFormat(properties);
    } catch (Exception e) {}
    String officeHome = properties.getProperty(OFFICE_HOME_KEY);
    if (officeHome != null && !DEFAULT_OFFICE_HOME_VALUE.equals(officeHome)) {
        return new File(officeHome);
    }
    if (PlatformUtils.isWindows()) {
        // %ProgramFiles(x86)% on 64-bit machines; %ProgramFiles% on 32-bit ones
        String homePath = OfficeUtils.getHomePath();
        String programFiles = System.getenv("ProgramFiles(x86)");
        if (programFiles == null) {
            programFiles = System.getenv("ProgramFiles");
        }
        return findOfficeHome(
            programFiles + File.separator + "OpenOffice 4",
            programFiles + File.separator + "LibreOffice 4",
            homePath + File.separator + "office"
        );
    } else if (PlatformUtils.isMac()) {
        return findOfficeHome(
            "/Applications/OpenOffice.org.app/Contents",
            "/Applications/OpenOffice.app/Contents",
            "/Applications/LibreOffice.app/Contents"
        );
    } else {
        // Linux or other *nix variants
        return findOfficeHome(
            "/opt/openoffice.org3",
            "/opt/openoffice",
            "/opt/libreoffice",
            "/opt/openoffice4",
            "/usr/lib/openoffice",
            "/usr/lib/libreoffice"
        );
    }
}