private ProcessManager findBestProcessManager() { if (isSigarAvailable()) return new SigarProcessManager(); else if (PlatformUtils.isLinux()) { final 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(); }
/** @param aLauncher Launcher being used in background */ public NuxeoLauncherGUI(NuxeoLauncher aLauncher) { launcher = aLauncher; // Set OS-specific decorations if (PlatformUtils.isMac()) { System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); System.setProperty("com.apple.mrj.application.live-resize", "true"); System.setProperty("com.apple.macos.smallTabs", "true"); } initFrame(); dumpedConfigMonitor = new DefaultFileMonitor( new FileListener() { @Override public void fileDeleted(FileChangeEvent event) { // Ignore } @Override public void fileCreated(FileChangeEvent event) { updateNuxeoFrame(); } @Override public void fileChanged(FileChangeEvent event) { updateNuxeoFrame(); } private synchronized void updateNuxeoFrame() { waitForFrameLoaded(); log.debug("Configuration changed. Reloading frame..."); launcher.init(); updateServerStatus(); try { Properties props = new Properties(); props.load(new FileReader(getConfigurationGenerator().getDumpedConfig())); nuxeoFrame.updateLogsTab(props.getProperty("log.id")); } catch (IOException e) { log.error(e); } } }); try { dumpedConfigMonitor.setRecursive(false); FileObject dumpedConfig = VFS.getManager().resolveFile(getConfigurationGenerator().getDumpedConfig().getPath()); dumpedConfigMonitor.addFile(dumpedConfig); dumpedConfigMonitor.start(); } catch (FileSystemException e) { throw new RuntimeException("Couldn't find " + getConfigurationGenerator().getNuxeoConf(), e); } }
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 : "")); }
@Override public void afterPropertiesSet() throws Exception { System.out.println("******************"); // 启动libreoffice进程 Windows平台需要启动,linux不需要启动 if (PlatformUtils.isWindows()) { String command = "cmd /c soffice --headless --accept=\"socket,host=127.0.0.1,port=8100;urp\" --nofirststartwizard"; Runtime runtime = Runtime.getRuntime(); runtime.exec(command); } officeManager = configuration.buildOfficeManager(); converter = new OfficeDocumentConverter(officeManager); customDocumentFormatRegistry = (SimpleDocumentFormatRegistry) converter.getFormatRegistry(); /* * // TODO:这里可以增加OpenOffice支持的文件类型 异常json * customDocumentFormatRegistry.addFormat(new * DocumentFormat("OpenOffice.org 1.0 Template", "sxd", * "application/vnd.sun.xml.draw")); * customDocumentFormatRegistry.addFormat(new * DocumentFormat("OpenOffice.org 1.0 Template", "odf", * "application/vnd.oasis.opendocument.formula")); */ DocumentFormat txt = new DocumentFormat("Java", "java", "text/plain"); txt.setInputFamily(DocumentFamily.TEXT); Map<String, Object> txtLoadAndStoreProperties = new LinkedHashMap<String, Object>(); txtLoadAndStoreProperties.put("FilterName", "Text (encoded)"); txtLoadAndStoreProperties.put("FilterOptions", "utf8"); txt.setLoadProperties(txtLoadAndStoreProperties); txt.setStoreProperties(DocumentFamily.TEXT, txtLoadAndStoreProperties); customDocumentFormatRegistry.addFormat(txt); // 添加wps格式 customDocumentFormatRegistry.addFormat( new DocumentFormat("wps文字", "wps", "application/msword")); // wps文字 customDocumentFormatRegistry.addFormat( new DocumentFormat("wps表格", "et", "application/msword")); // wps表格 customDocumentFormatRegistry.addFormat( new DocumentFormat("wps演示", "dps", "application/msword")); // wps演示 // 启动officeManager,保持在Bean的生命周期中一直在启动状态 officeManager.start(); }