List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.cloudifysource.esc.driver.provisioning.byon.ByonProvisioningDriver.java
private void setKeyFile(final MachineDetails md, final String keyFileName, final String parentFolder) throws CloudProvisioningException { File keyFile = new File(keyFileName); if (!keyFile.isAbsolute()) { keyFile = new File(parentFolder, keyFileName); }/* www .j a va 2 s . c om*/ if (!keyFile.isFile()) { throw new CloudProvisioningException( "The specified key file could not be found: " + keyFile.getAbsolutePath()); } md.setKeyFile(keyFile); }
From source file:org.dita.dost.platform.Integrator.java
private void writeEnvShell(final Collection<File> jars) { Writer out = null;/* w ww. j av a 2s . c o m*/ try { final File outFile = new File(ditaDir, "resources" + File.separator + "env.sh"); if (!(outFile.getParentFile().exists()) && !outFile.getParentFile().mkdirs()) { throw new RuntimeException("Failed to make directory " + outFile.getParentFile().getAbsolutePath()); } logger.debug("Generate environment shell " + outFile.getPath()); out = new BufferedWriter(new FileWriter(outFile)); out.write("#!/bin/sh\n"); for (final File relativeLib : jars) { out.write("CLASSPATH=\"$CLASSPATH:"); if (!relativeLib.isAbsolute()) { out.write("$DITA_HOME" + UNIX_SEPARATOR); } out.write(relativeLib.toString().replace(File.separator, UNIX_SEPARATOR)); out.write("\"\n"); } } catch (final Exception e) { if (strict) { throw new RuntimeException("Failed to write environment shell: " + e.getMessage(), e); } else { logger.error(e.getMessage(), e); } } finally { closeQuietly(out); } }
From source file:org.dita.dost.platform.Integrator.java
private void writeEnvBatch(final Collection<File> jars) { Writer out = null;/*from ww w. j a va2 s . c o m*/ try { final File outFile = new File(ditaDir, "resources" + File.separator + "env.bat"); if (!(outFile.getParentFile().exists()) && !outFile.getParentFile().mkdirs()) { throw new RuntimeException("Failed to make directory " + outFile.getParentFile().getAbsolutePath()); } logger.debug("Generate environment batch " + outFile.getPath()); out = new BufferedWriter(new FileWriter(outFile)); for (final File relativeLib : jars) { out.write("set \"CLASSPATH=%CLASSPATH%;"); if (!relativeLib.isAbsolute()) { out.write("%DITA_HOME%" + WINDOWS_SEPARATOR); } out.write(relativeLib.toString().replace(File.separator, WINDOWS_SEPARATOR)); out.write("\"\r\n"); } } catch (final Exception e) { if (strict) { throw new RuntimeException("Failed to write environment batch: " + e.getMessage(), e); } else { logger.error(e.getMessage(), e); } } finally { closeQuietly(out); } }
From source file:org.dita.dost.platform.Integrator.java
/** * Execute point of Integrator./*w w w . ja va2 s . c o m*/ */ public void execute() throws Exception { if (logger == null) { logger = new DITAOTJavaLogger(); } // Read the properties file, if it exists. properties = new Properties(); if (propertiesFile != null) { FileInputStream propertiesStream = null; try { propertiesStream = new FileInputStream(propertiesFile); properties.load(propertiesStream); } catch (final Exception e) { if (strict) { throw new RuntimeException(e); } else { logger.error(e.getMessage(), e); } } finally { if (propertiesStream != null) { try { propertiesStream.close(); } catch (final IOException e) { logger.error(e.getMessage(), e); } } } } else { properties.putAll(Configuration.configuration); } if (!properties.containsKey(CONF_PLUGIN_DIRS)) { properties.setProperty(CONF_PLUGIN_DIRS, configuration.containsKey(CONF_PLUGIN_DIRS) ? configuration.get(CONF_PLUGIN_DIRS) : "plugins;demo"); } if (!properties.containsKey(CONF_PLUGIN_IGNORES)) { properties.setProperty(CONF_PLUGIN_IGNORES, configuration.containsKey(CONF_PLUGIN_IGNORES) ? configuration.get(CONF_PLUGIN_IGNORES) : ""); } // Get the list of plugin directories from the properties. final String[] pluginDirs = properties.getProperty(CONF_PLUGIN_DIRS).split(PARAM_VALUE_SEPARATOR); final Set<String> pluginIgnores = new HashSet<>(); if (properties.getProperty(CONF_PLUGIN_IGNORES) != null) { pluginIgnores.addAll( Arrays.asList(properties.getProperty(CONF_PLUGIN_IGNORES).split(PARAM_VALUE_SEPARATOR))); } final String pluginOrderProperty = properties.getProperty(CONF_PLUGIN_ORDER); if (pluginOrderProperty != null) { final List<String> plugins = asList(pluginOrderProperty.trim().split("\\s+")); Collections.reverse(plugins); int priority = 1; for (final String plugin : plugins) { pluginOrder.put(plugin, priority++); } } for (final String tmpl : properties.getProperty(CONF_TEMPLATES, "").split(PARAM_VALUE_SEPARATOR)) { final String t = tmpl.trim(); if (t.length() != 0) { templateSet.add(t); } } for (final String pluginDir2 : pluginDirs) { File pluginDir = new File(pluginDir2); if (!pluginDir.isAbsolute()) { pluginDir = new File(ditaDir, pluginDir.getPath()); } final File[] pluginFiles = pluginDir.listFiles(); for (int i = 0; (pluginFiles != null) && (i < pluginFiles.length); i++) { final File f = pluginFiles[i]; final File descFile = new File(pluginFiles[i], "plugin.xml"); if (pluginFiles[i].isDirectory() && !pluginIgnores.contains(f.getName()) && descFile.exists()) { descSet.add(descFile); } } } parsePlugin(); integrate(); }
From source file:it.geosolutions.geobatch.flow.event.consumer.file.FileBasedEventConsumer.java
private File initConfigDir(ActionConfiguration actionCfg, File flowConfigDir) { File ret = null;/* w w w . java 2 s . c om*/ File ovr = actionCfg.getOverrideConfigDir(); if (ovr != null) { if (!ovr.isAbsolute()) ret = new File(flowConfigDir, ovr.getPath()); else ret = ovr; } else ret = new File(flowConfigDir, actionCfg.getId()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Action config dir set to " + ret); return ret; }
From source file:org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin.java
@Override public IndexingContext createIndexContext(ManagedRepository repository) throws RepositoryAdminException { IndexingContext context = indexer.getIndexingContexts().get(repository.getId()); if (context != null) { log.debug("skip creating repository indexingContent with id {} as already exists", repository.getId()); return context; }/* ww w. j av a 2s .com*/ // take care first about repository location as can be relative File repositoryDirectory = new File(repository.getLocation()); if (!repositoryDirectory.isAbsolute()) { repositoryDirectory = new File( getRegistry().getString("appserver.base") + File.separatorChar + "repositories", repository.getLocation()); } if (!repositoryDirectory.exists()) { repositoryDirectory.mkdirs(); } try { String indexDir = repository.getIndexDirectory(); //File managedRepository = new File( repository.getLocation() ); File indexDirectory = null; if (StringUtils.isNotBlank(indexDir)) { indexDirectory = new File(repository.getIndexDirectory()); // not absolute so create it in repository directory if (!indexDirectory.isAbsolute()) { indexDirectory = new File(repositoryDirectory, repository.getIndexDirectory()); } repository.setIndexDirectory(indexDirectory.getAbsolutePath()); } else { indexDirectory = new File(repositoryDirectory, ".indexer"); if (!repositoryDirectory.isAbsolute()) { indexDirectory = new File(repositoryDirectory, ".indexer"); } repository.setIndexDirectory(indexDirectory.getAbsolutePath()); } if (!indexDirectory.exists()) { indexDirectory.mkdirs(); } context = indexer.getIndexingContexts().get(repository.getId()); if (context == null) { context = indexer.addIndexingContext(repository.getId(), repository.getId(), repositoryDirectory, indexDirectory, repositoryDirectory.toURI().toURL().toExternalForm(), indexDirectory.toURI().toURL().toString(), indexCreators); context.setSearchable(repository.isScanned()); } return context; } catch (MalformedURLException e) { throw new RepositoryAdminException(e.getMessage(), e); } catch (IOException e) { throw new RepositoryAdminException(e.getMessage(), e); } catch (UnsupportedExistingLuceneIndexException e) { throw new RepositoryAdminException(e.getMessage(), e); } }
From source file:catalina.users.MemoryUserDatabase.java
/** * Save any updated information to the persistent storage location for * this user database./*w ww .j a v a 2 s . c o m*/ * * @exception Exception if any exception is thrown during saving */ public void save() throws Exception { // Write out contents to a temporary file File fileNew = new File(pathnameNew); if (!fileNew.isAbsolute()) { fileNew = new File(System.getProperty("catalina.base"), pathnameNew); } PrintWriter writer = null; try { // Configure our PrintWriter FileOutputStream fos = new FileOutputStream(fileNew); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8"); writer = new PrintWriter(osw); // Print the file prolog writer.println("<?xml version='1.0' encoding='utf-8'?>"); writer.println("<tomcat-users>"); // Print entries for each defined role, group, and user Iterator values = null; values = getRoles(); while (values.hasNext()) { writer.print(" "); writer.println(values.next()); } values = getGroups(); while (values.hasNext()) { writer.print(" "); writer.println(values.next()); } values = getUsers(); while (values.hasNext()) { writer.print(" "); writer.println(values.next()); } // Print the file epilog writer.println("</tomcat-users>"); // Check for errors that occurred while printing if (writer.checkError()) { writer.close(); fileNew.delete(); throw new IOException(sm.getString("memoryUserDatabase.writeException", fileNew.getAbsolutePath())); } writer.close(); } catch (IOException e) { if (writer != null) { writer.close(); } fileNew.delete(); throw e; } // Perform the required renames to permanently save this file File fileOld = new File(pathnameNew); if (!fileOld.isAbsolute()) { fileOld = new File(System.getProperty("catalina.base"), pathnameOld); } fileOld.delete(); File fileOrig = new File(pathname); if (!fileOrig.isAbsolute()) { fileOrig = new File(System.getProperty("catalina.base"), pathname); } if (fileOrig.exists()) { fileOld.delete(); if (!fileOrig.renameTo(fileOld)) { throw new IOException(sm.getString("memoryUserDatabase.renameOld", fileOld.getAbsolutePath())); } } if (!fileNew.renameTo(fileOrig)) { if (fileOld.exists()) { fileOld.renameTo(fileOrig); } throw new IOException(sm.getString("memoryUserDatabase.renameNew", fileOrig.getAbsolutePath())); } fileOld.delete(); }
From source file:charvax.swing.JFileChooser.java
public void setSelectedFile(File file_) { if (!file_.isAbsolute()) { file_ = new File(_currentDirectory, file_.getPath()); }/*w w w . ja va 2 s. com*/ File parent = file_.getParentFile(); if (!file_.isDirectory() && (parent != null)) { _currentDirectory = parent; _location = file_.getAbsolutePath(); } else if (file_.isDirectory()) { _currentDirectory = file_; _location = file_.getAbsolutePath(); } fireFileChooserEvent(); }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** Checks to see if the absolute path is availabe thru an application * global static variable or thru a system variable. If so, appends * the relative path to the absolute path and returns the String. *//*from www. ja v a2 s .c om*/ private String processSrcPath(String src) { String val = src; File imageFile = new File(src); if (imageFile.isAbsolute()) { return src; } boolean found = false; Document doc = getDocument(); if (doc != null) { String pv = (String) doc.getProperty("com.hexidec.ekit.docsource"); if (pv != null) { File f = new File(pv); val = (new File(f.getParent(), imageFile.getPath().toString())).toString(); found = true; } } if (!found) { String imagePath = System.getProperty("system.image.path.key"); if (imagePath != null) { val = (new File(imagePath, imageFile.getPath())).toString(); } } return val; }
From source file:org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin.java
private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) { ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration(); stagingRepository.setId(repository.getId() + STAGE_REPO_ID_END); stagingRepository.setLayout(repository.getLayout()); stagingRepository.setName(repository.getName() + STAGE_REPO_ID_END); stagingRepository.setBlockRedeployments(repository.isBlockRedeployments()); stagingRepository.setDaysOlder(repository.getDaysOlder()); stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots()); String path = repository.getLocation(); int lastIndex = path.replace('\\', '/').lastIndexOf('/'); stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId()); if (StringUtils.isNotBlank(repository.getIndexDir())) { File indexDir = new File(repository.getIndexDir()); // in case of absolute dir do not use the same if (indexDir.isAbsolute()) { stagingRepository.setIndexDir(stagingRepository.getLocation() + "/.index"); } else {/*w w w.ja v a 2 s .c o m*/ stagingRepository.setIndexDir(repository.getIndexDir()); } } stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression()); stagingRepository.setReleases(repository.isReleases()); stagingRepository.setRetentionCount(repository.getRetentionCount()); stagingRepository.setScanned(repository.isScanned()); stagingRepository.setSnapshots(repository.isSnapshots()); stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation()); // do not duplicate description //stagingRepository.getDescription("") return stagingRepository; }