List of usage examples for org.apache.commons.lang3 SystemUtils getUserHome
public static File getUserHome()
Gets the user home directory as a File .
From source file:me.ineson.testing.utils.GradleConfig.java
private static synchronized String readGradleConfig(String key) { if (GRADLE_PROPERTIES == null) { File filename = new File(SystemUtils.getUserHome(), ".gradle/gradle.properties"); if (!filename.exists() || !filename.isFile() || !filename.canRead()) { throw new IllegalStateException("Failed to access gradle configuration: " + filename.getAbsolutePath() + ", exists " + filename.exists() + ", isFile " + filename.isFile() + ", canRead " + filename.canRead()); }// w w w. ja v a 2 s .co m Properties properties = new Properties(); try { properties.load(new FileInputStream(filename)); } catch (FileNotFoundException e) { throw new IllegalStateException( "Failed to access gradle configuration: " + filename.getAbsolutePath(), e); } catch (IOException e) { throw new IllegalStateException( "Failed to access gradle configuration: " + filename.getAbsolutePath(), e); } GRADLE_PROPERTIES = properties; } String fullKey = "systemProp." + key; String value = GRADLE_PROPERTIES.getProperty(fullKey); if (value != null) { System.setProperty(key, value); } return value; }
From source file:de.mirkosertic.desktopsearch.DesktopSearch.java
@Override public void start(Stage aStage) throws Exception { // This is our base directory File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir"); theBaseDirectory.mkdirs();/*from w w w . j a v a 2s .c om*/ configurationManager = new ConfigurationManager(theBaseDirectory); Notifier theNotifier = new Notifier(); stage = aStage; // Create the known preview processors PreviewProcessor thePreviewProcessor = new PreviewProcessor(); try { // Boot the search backend and set it up for listening to configuration changes backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor); configurationManager.addChangeListener(backend); // Boot embedded JSP container embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor, configurationManager); embeddedWebServer.start(); } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) { // In this case, there is already an instance of DesktopSearch running // Inform the instance to bring it to front end terminate the current process. URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl()); // Retrieve the content, but it can be safely ignored // There must only be the get request Object theContent = theURL.getContent(); // Terminate the JVM. The window of the running instance is visible now. System.exit(0); } aStage.setTitle("Free Desktop Search"); aStage.setWidth(800); aStage.setHeight(600); aStage.initStyle(StageStyle.TRANSPARENT); FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml")); AnchorPane theMainScene = theLoader.load(); final DesktopSearchController theController = theLoader.getController(); theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner()); Undecorator theUndecorator = new Undecorator(stage, theMainScene); theUndecorator.getStylesheets().add("/skin/undecorator.css"); Scene theScene = new Scene(theUndecorator); // Hacky, but works... theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);"); theScene.setFill(Color.TRANSPARENT); aStage.setScene(theScene); aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png"))); if (SystemTray.isSupported()) { Platform.setImplicitExit(false); SystemTray theTray = SystemTray.getSystemTray(); // We need to reformat the icon according to the current tray icon dimensions // this depends on the underlying OS java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit() .getImage(getClass().getResource("/fds_small.png")); int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width; TrayIcon theTrayIcon = new TrayIcon( theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH), "Free Desktop Search"); theTrayIcon.setImageAutoSize(true); theTrayIcon.setToolTip("FXDesktopSearch"); theTrayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { Platform.runLater(() -> { if (stage.isIconified()) { stage.setIconified(false); } stage.show(); stage.toFront(); }); } } }); theTray.add(theTrayIcon); aStage.setOnCloseRequest(aEvent -> stage.hide()); } else { aStage.setOnCloseRequest(aEvent -> shutdown()); } aStage.setMaximized(true); aStage.show(); }
From source file:com.mirth.connect.client.ui.MessageExportDialog.java
private void export() { String errorMessage = messageExportPanel.validate(true); if (StringUtils.isNotEmpty(errorMessage)) { parent.alertError(this, errorMessage); return;//ww w .j ava2s .com } int exportCount = 0; MessageWriterOptions writerOptions = messageExportPanel.getMessageWriterOptions(); if (StringUtils.isBlank(writerOptions.getRootFolder())) { parent.alertError(parent, "Please enter a valid root path to store exported files."); setVisible(true); return; } setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if (messageExportPanel.isExportLocal()) { PaginatedMessageList messageList = new PaginatedMessageList(); messageList.setChannelId(channelId); messageList.setClient(parent.mirthClient); messageList.setMessageFilter(messageFilter); messageList.setPageSize(pageSize); messageList.setIncludeContent(true); writerOptions.setBaseFolder(SystemUtils.getUserHome().getAbsolutePath()); MessageWriter messageWriter = MessageWriterFactory.getInstance().getMessageWriter(writerOptions, encryptor); AttachmentSource attachmentSource = null; if (writerOptions.includeAttachments()) { attachmentSource = new AttachmentSource() { @Override public List<Attachment> getMessageAttachments(Message message) throws ClientException { return PlatformUI.MIRTH_FRAME.mirthClient .getAttachmentsByMessageId(message.getChannelId(), message.getMessageId()); } }; } try { exportCount = new MessageExporter().exportMessages(messageList, messageWriter, attachmentSource); messageWriter.finishWrite(); } finally { messageWriter.close(); } } else { writerOptions.setIncludeAttachments(messageExportPanel.isIncludeAttachments()); exportCount = parent.mirthClient.exportMessagesServer(channelId, messageFilter, pageSize, writerOptions); } setVisible(false); setCursor(Cursor.getDefaultCursor()); parent.alertInformation(parent, exportCount + " message" + ((exportCount == 1) ? " has" : "s have") + " been successfully exported to: " + writerOptions.getRootFolder()); } catch (Exception e) { setCursor(Cursor.getDefaultCursor()); Throwable cause = (e.getCause() == null) ? e : e.getCause(); parent.alertThrowable(parent, cause); } }
From source file:cz.lbenda.rcp.config.ConfigurationRW.java
private File userConfigDirectoryPath() { // Windows//ww w . j av a 2s . co m String dataFolder = System.getenv("LOCALAPPDATA"); if (dataFolder == null) { dataFolder = System.getenv("APPDATA"); } if (dataFolder != null) { File parent = new File(dataFolder); if (parent.exists()) { new File(parent, lastConfigDirectory()); } } // Mac File home = SystemUtils.getUserHome(); if (SystemUtils.IS_OS_MAC) { File f = new File(home, "Library/Application Support/"); if (f.exists()) { return new File(f, lastConfigDirectory()); } } // Linux/*NIX File configDirectory = new File(home, ".config"); if (configDirectory.exists()) { return new File(configDirectory, lastConfigDirectory()); } File localDirectory = new File(home, ".local"); if (localDirectory.exists()) { return new File(localDirectory, lastConfigDirectory()); } return new File(home, "." + lastConfigDirectory()); }
From source file:com.mirth.connect.client.ui.MessageImportDialog.java
private void importMessages() { if (StringUtils.isBlank(fileTextField.getText())) { fileTextField.setBackground(UIConstants.INVALID_COLOR); parent.alertError(parent, "Please enter a file/folder to import."); setVisible(true);/* ww w. j ava2 s . c o m*/ return; } else { fileTextField.setBackground(null); } setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); MessageImportResult result; try { if (importLocalRadio.isSelected()) { MessageWriter messageWriter = new MessageWriter() { @Override public boolean write(Message message) throws MessageWriterException { try { parent.mirthClient.importMessage(channelId, message); } catch (ClientException e) { throw new MessageWriterException(e); } return true; } @Override public void finishWrite() { } @Override public void close() throws MessageWriterException { } }; try { result = new MessageImporter().importMessages(fileTextField.getText(), subfoldersCheckbox.isSelected(), messageWriter, SystemUtils.getUserHome().getAbsolutePath()); } catch (MessageImportInvalidPathException e) { setCursor(Cursor.getDefaultCursor()); parent.alertError(parent, e.getMessage()); setVisible(true); return; } } else { result = parent.mirthClient.importMessagesServer(channelId, fileTextField.getText(), subfoldersCheckbox.isSelected()); } setVisible(false); setCursor(Cursor.getDefaultCursor()); if (result.getSuccessCount() == 0 && result.getTotalCount() == 0) { parent.alertInformation(parent, "No messages were found to import"); } else { if (result.getSuccessCount() > 0 && messageBrowser != null) { messageBrowser.updateFilterButtonFont(Font.BOLD); } parent.alertInformation(parent, result.getSuccessCount() + " out of " + result.getTotalCount() + " message(s) have been successfully imported from " + fileTextField.getText() + "."); } } catch (Exception e) { setCursor(Cursor.getDefaultCursor()); Throwable cause = (e.getCause() == null) ? e : e.getCause(); parent.alertThrowable(parent, cause); } }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
/** * Speichert Daten lokal auf dem Datentraeger * * @return 'true' wenn alles fehlerfrei lief *///from w w w. ja v a 2 s.c om private boolean localSaveData() { if (loadedFile == null) { loadedFile = fileToLoad; } File file = loadedFile; if (file == null) { file = new File(getProgrammLocationDir(), DATA_FILE_NAME); } try { System.out.println("Save to " + file.getAbsolutePath()); core.saveDatabase(file); loadedFile = file; } catch (Exception e) { System.out.println("Save failed: " + e.getLocalizedMessage()); /* * Speichern fehlgeschlagen evt wegen schreibgeschutzten Ordner oder * Datei. */ if (loadedFile != null) { /* * Da von dieser Datei schon geladen wurde, mit einer * Fehlermeldung abbrechen und nicht versuchen in eine * alternative Lokation zu speichern */ showError(e); return false; } file = new File(SystemUtils.getUserHome(), DATA_FILE_NAME); try { System.out.println("Save to " + file.getAbsolutePath()); core.saveDatabase(file); loadedFile = file; } catch (Exception e1) { System.out.println("Save failed: " + e.getLocalizedMessage()); showError(e); return false; } } return true; }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
/** * Methode versucht zuletzt gespeicherte Datei zu finden. Zuerst wird in dem * gleichem Ordner gesucht wo die JAR-Datei selbst liegt. Als Ausweichstelle * wird in dem Home-Ordner des Benutzers gesucht * * @return// w w w. j a v a 2 s .c o m */ private File findDatabaseFile() { if (fileToLoad != null) { /* * Zieldatei, die als Programmargument mitgegeben wurde hat oberstes * Prioritaet. Alle Dateien werden ignoriert. */ if (fileToLoad.exists() && fileToLoad.canRead()) { return fileToLoad; } return null; } File dataFile = null; File runningDir = getProgrammLocationDir(); if (runningDir != null) { dataFile = new File(runningDir, DATA_FILE_NAME); if (dataFile.exists() && dataFile.canRead()) { return dataFile; } } File homeDir = SystemUtils.getUserHome(); dataFile = new File(homeDir, DATA_FILE_NAME); if (dataFile.exists() && dataFile.canRead()) { return dataFile; } return null; }
From source file:org.pgptool.gui.config.impl.ConfigsBasePathResolverUserHomeImpl.java
@Override public String getConfigsBasePath() { if (chosenLocation == null) { String[] options = new String[] { System.getenv("USERPROFILE"), SystemUtils.getUserHome().getAbsolutePath(), "~" }; log.debug("Base path options: " + Arrays.toString(options)); for (int i = 0; i < options.length; i++) { if (tryAccept(options[i])) { return chosenLocation; }// ww w . ja va2 s.com } Preconditions.checkState(false, "No config path was chosen as acceptable. Check application have rights to write files on the disk"); } return chosenLocation; }
From source file:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java
protected void suggestInitialDirectory(JFileChooser ofd) { try {//from ww w . j av a 2 s.c o m String lastChosenDestination = configPairs.find(configPairNameToRemember, null); String pathname = StringUtils.hasText(lastChosenDestination) ? lastChosenDestination : SystemUtils.getUserHome().getAbsolutePath(); ofd.setCurrentDirectory(new File(pathname)); } catch (Throwable t) { log.warn("Failed to set suggested location by key " + configPairNameToRemember, t); } }
From source file:org.pgptool.gui.ui.tools.browsefs.SaveFileChooserDialog.java
protected void suggestTarget(JFileChooser ofd) { if (configPairs == null || configId == null) { return;//from ww w. j a va 2s . c o m } try { String lastChosenDestination = configPairs.find(configId, null); String pathname = StringUtils.hasText(lastChosenDestination) ? lastChosenDestination : SystemUtils.getUserHome().getAbsolutePath(); ofd.setCurrentDirectory(new File(pathname)); } catch (Throwable t) { log.warn("Failed to set suggested location for dialog " + dialogTitleCode, t); } }