List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.commonjava.emb.boot.main.EMBMain.java
protected File resolveFile(final File file, final String workingDirectory) { if (file == null) { return null; } else if (file.isAbsolute()) { return file; } else if (file.getPath().startsWith(File.separator)) { // drive-relative Windows path return file.getAbsoluteFile(); } else {//from www .j ava 2 s.c o m return new File(workingDirectory, file.getPath()).getAbsoluteFile(); } }
From source file:com.npower.dm.setup.task.ModelTask.java
protected void processCPTemplates() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try {/*w w w . j a v a 2 s .com*/ factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); ClientProvTemplateBean cpBean = factory.createClientProvTemplateBean(); // Import Profile Mappings for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } this.getSetup().getConsole().println(" Loading file [ " + file.getAbsolutePath() + " ]"); List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem manufacturerItem : items) { List<ModelItem> modelItems = manufacturerItem.getModels(); Manufacturer manufacturer = modelBean .getManufacturerByExternalID(manufacturerItem.getExternalID()); for (ModelItem modelItem : modelItems) { // Copy information from family this.copyFromFamily(modelItem); Model model = modelBean.getModelByManufacturerModelID(manufacturer, modelItem.getExternalID()); if (!modelItem.getCpTemplatesFiles().isEmpty()) { this.getSetup().getConsole().println(" * Importing CP Templates for [ " + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + " ]"); } for (String templateFilename : modelItem.getCpTemplatesFiles()) { File templateFile = new File(templateFilename); if (!templateFile.isAbsolute()) { templateFile = new File(this.getSetup().getWorkDir(), templateFilename); } InputStream in = new FileInputStream(templateFile); List<ClientProvTemplate> templates = cpBean.importClientProvTemplates(in, this.getSetup().getWorkDir()); factory.beginTransaction(); for (ClientProvTemplate template : templates) { cpBean.attach(model, template); } factory.commit(); this.getSetup().getConsole().println(" [ " + templateFile + " ] imported!"); } } } } } catch (Exception ex) { if (factory != null) { factory.rollback(); } throw new SetupException("Error in import models.", ex); } finally { if (factory != null) { factory.release(); } } }
From source file:com.npower.dm.setup.task.ModelTask.java
protected void processProfileMappings() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try {// w w w . j a v a 2 s . c o m factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); ProfileMappingBean mappingBean = factory.createProfileMappingBean(); // Import Profile Mappings for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } this.getSetup().getConsole().println(" Loading file [ " + file.getAbsolutePath() + " ]"); List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem manufacturerItem : items) { List<ModelItem> modelItems = manufacturerItem.getModels(); Manufacturer manufacturer = modelBean .getManufacturerByExternalID(manufacturerItem.getExternalID()); for (ModelItem modelItem : modelItems) { // Copy information from family copyFromFamily(modelItem); Model model = modelBean.getModelByManufacturerModelID(manufacturer, modelItem.getExternalID()); if (!modelItem.getProfileMappingFiles().isEmpty()) { this.getSetup().getConsole().println(" * Importings DM Mapping for [ " + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + " ]"); } for (String mappingFilename : modelItem.getProfileMappingFiles()) { File mappingFile = new File(mappingFilename); if (!mappingFile.isAbsolute()) { mappingFile = new File(this.getSetup().getWorkDir(), mappingFilename); } List<ProfileMapping> mappings = mappingBean.importProfileMapping( new FileInputStream(mappingFile), manufacturer.getExternalId(), model.getManufacturerModelId()); factory.beginTransaction(); for (ProfileMapping mapping : mappings) { modelBean.attachProfileMapping(model, mapping.getID()); } factory.commit(); this.getSetup().getConsole() .println(" [ " + mappingFile.getAbsolutePath() + " ] imported!"); } } } } } catch (Exception ex) { if (factory != null) { factory.rollback(); } throw new SetupException("Error in import models.", ex); } finally { if (factory != null) { factory.release(); } } }
From source file:org.deegree.portal.portlet.modules.wfs.actions.portlets.WFSClientPortletPerform.java
/** * transforms the result of a WFS request using the XSLT script defined by an init parameter * * @param xml/* w ww .j av a2 s . c o m*/ * @return the transformed XML * @throws PortalException */ private XMLFragment transform(XMLFragment xml) throws PortalException { String xslF = getInitParam(INIT_XSLT); File file = new File(xslF); if (!file.isAbsolute()) { file = new File(sc.getRealPath(xslF)); } XSLTDocument xslt = new XSLTDocument(); try { xslt.load(file.toURI().toURL()); xml = xslt.transform(xml); } catch (Exception e) { LOG.logError(e.getMessage(), e); throw new PortalException("could not transform result of WFS request", e); } return xml; }
From source file:interactivespaces.workbench.tasks.WorkbenchTaskContext.java
/** * Get the controller directory which is supporting this workbench. * * @return the controller directory// w w w .jav a2s . c o m */ public File getControllerDirectory() { String controllerPath = workbenchConfig.getPropertyString(CONFIGURATION_CONTROLLER_BASEDIR); File controllerDirectory = new File(controllerPath); if (controllerDirectory.isAbsolute()) { return controllerDirectory; } File homeDir = fileSupport .newFile(workbenchConfig.getPropertyString(CoreConfiguration.CONFIGURATION_INTERACTIVESPACES_HOME)); return fileSupport.newFile(homeDir, controllerPath); }
From source file:com.brandroidtools.filemanager.activities.PickerActivity.java
private File getInitialDirectoryFromIntent(Intent intent) { if (!Intent.ACTION_PICK.equals(intent.getAction())) { return null; }//from ww w .j a va 2 s .co m final Uri data = intent.getData(); if (data == null) { return null; } final String path = data.getPath(); if (path == null) { return null; } final File file = new File(path); if (!file.exists() || !file.isAbsolute()) { return null; } if (file.isDirectory()) { return file; } return file.getParentFile(); }
From source file:psiprobe.AbstractTomcatContainer.java
@Override public File getAppBase() { File base = new File(host.getAppBase()); if (!base.isAbsolute()) { base = new File(System.getProperty("catalina.base"), host.getAppBase()); }//from w w w. j a v a 2s . c om return base; }
From source file:com.joseflavio.uxiamarelo.servlet.UxiAmareloServlet.java
@Override protected void doPost(HttpServletRequest requisicao, HttpServletResponse resposta) throws ServletException, IOException { String tipo = requisicao.getContentType(); if (tipo == null || tipo.isEmpty()) tipo = "text/plain"; String codificacao = requisicao.getCharacterEncoding(); if (codificacao == null || codificacao.isEmpty()) codificacao = "UTF-8"; resposta.setCharacterEncoding(codificacao); PrintWriter saida = resposta.getWriter(); try {/*from w ww . j a va 2 s .co m*/ JSON json; if (tipo.contains("json")) { json = new JSON(IOUtils.toString(requisicao.getInputStream(), codificacao)); } else { json = new JSON(); } Enumeration<String> parametros = requisicao.getParameterNames(); while (parametros.hasMoreElements()) { String chave = parametros.nextElement(); String valor = URLDecoder.decode(requisicao.getParameter(chave), codificacao); json.put(chave, valor); } if (tipo.contains("multipart")) { Collection<Part> arquivos = requisicao.getParts(); if (!arquivos.isEmpty()) { File diretorio = new File(uxiAmarelo.getDiretorio()); if (!diretorio.isAbsolute()) { diretorio = new File(requisicao.getServletContext().getRealPath("") + File.separator + uxiAmarelo.getDiretorio()); } if (!diretorio.exists()) diretorio.mkdirs(); String diretorioStr = diretorio.getAbsolutePath(); String url = uxiAmarelo.getDiretorioURL(); if (uxiAmarelo.isDiretorioURLRelativo()) { String url_esquema = requisicao.getScheme(); String url_servidor = requisicao.getServerName(); int url_porta = requisicao.getServerPort(); String url_contexto = requisicao.getContextPath(); url = url_esquema + "://" + url_servidor + ":" + url_porta + url_contexto + "/" + url; } if (url.charAt(url.length() - 1) == '/') { url = url.substring(0, url.length() - 1); } Map<String, List<JSON>> mapa_arquivos = new HashMap<>(); for (Part arquivo : arquivos) { String chave = arquivo.getName(); String nome_original = getNome(arquivo, codificacao); String nome = nome_original; if (nome == null || nome.isEmpty()) { try (InputStream is = arquivo.getInputStream()) { String valor = IOUtils.toString(is, codificacao); valor = URLDecoder.decode(valor, codificacao); json.put(chave, valor); continue; } } if (uxiAmarelo.getArquivoNome().equals("uuid")) { nome = UUID.randomUUID().toString(); } while (new File(diretorioStr + File.separator + nome).exists()) { nome = UUID.randomUUID().toString(); } arquivo.write(diretorioStr + File.separator + nome); List<JSON> lista = mapa_arquivos.get(chave); if (lista == null) { lista = new LinkedList<>(); mapa_arquivos.put(chave, lista); } lista.add((JSON) new JSON().put("nome", nome_original).put("endereco", url + "/" + nome)); } for (Entry<String, List<JSON>> entrada : mapa_arquivos.entrySet()) { List<JSON> lista = entrada.getValue(); if (lista.size() > 1) { json.put(entrada.getKey(), lista); } else { json.put(entrada.getKey(), lista.get(0)); } } } } String copaiba = (String) json.remove("copaiba"); if (StringUtil.tamanho(copaiba) == 0) { throw new IllegalArgumentException("copaiba = nome@classe@metodo"); } String[] copaibaParam = copaiba.split("@"); if (copaibaParam.length != 3) { throw new IllegalArgumentException("copaiba = nome@classe@metodo"); } String comando = (String) json.remove("uxicmd"); if (StringUtil.tamanho(comando) == 0) comando = null; if (uxiAmarelo.isCookieEnviar()) { Cookie[] cookies = requisicao.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { String nome = cookie.getName(); if (uxiAmarelo.cookieBloqueado(nome)) continue; if (!json.has(nome)) { try { json.put(nome, URLDecoder.decode(cookie.getValue(), "UTF-8")); } catch (UnsupportedEncodingException e) { json.put(nome, cookie.getValue()); } } } } } if (uxiAmarelo.isEncapsulamentoAutomatico()) { final String sepstr = uxiAmarelo.getEncapsulamentoSeparador(); final char sep0 = sepstr.charAt(0); for (String chave : new HashSet<>(json.keySet())) { if (chave.indexOf(sep0) == -1) continue; String[] caminho = chave.split(sepstr); if (caminho.length > 1) { Util.encapsular(caminho, json.remove(chave), json); } } } String resultado; if (comando == null) { try (CopaibaConexao cc = uxiAmarelo.conectarCopaiba(copaibaParam[0])) { resultado = cc.solicitar(copaibaParam[1], json.toString(), copaibaParam[2]); if (resultado == null) resultado = ""; } } else if (comando.equals("voltar")) { resultado = json.toString(); comando = null; } else { resultado = ""; } if (comando == null) { resposta.setStatus(HttpServletResponse.SC_OK); resposta.setContentType("application/json"); saida.write(resultado); } else if (comando.startsWith("redirecionar")) { resposta.sendRedirect(Util.obterStringDeJSON("redirecionar", comando, resultado)); } else if (comando.startsWith("base64")) { String url = comando.substring("base64.".length()); resposta.sendRedirect(url + Base64.getUrlEncoder().encodeToString(resultado.getBytes("UTF-8"))); } else if (comando.startsWith("html_url")) { HttpURLConnection con = (HttpURLConnection) new URL( Util.obterStringDeJSON("html_url", comando, resultado)).openConnection(); con.setRequestProperty("User-Agent", "Uxi-amarelo"); if (con.getResponseCode() != HttpServletResponse.SC_OK) throw new IOException("HTTP = " + con.getResponseCode()); resposta.setStatus(HttpServletResponse.SC_OK); resposta.setContentType("text/html"); try (InputStream is = con.getInputStream()) { saida.write(IOUtils.toString(is)); } con.disconnect(); } else if (comando.startsWith("html")) { resposta.setStatus(HttpServletResponse.SC_OK); resposta.setContentType("text/html"); saida.write(Util.obterStringDeJSON("html", comando, resultado)); } else { throw new IllegalArgumentException(comando); } } catch (Exception e) { resposta.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); resposta.setContentType("application/json"); saida.write(Util.gerarRespostaErro(e).toString()); } saida.flush(); }
From source file:org.datacleaner.util.FileResolver.java
public String toPath(File file) { if (file == null) { return null; }/* w w w. j av a 2 s . c o m*/ String path = file.getPath(); // Make relative if possible final String basePath = FilenameUtils.normalize(_baseDir.getAbsolutePath(), true); final String filePath = FilenameUtils.normalize(file.getAbsolutePath(), true); final boolean absolute; if (filePath.startsWith(basePath)) { path = filePath.substring(basePath.length()); absolute = false; } else { absolute = file.isAbsolute(); } path = StringUtils.replaceAll(path, "\\", "/"); if (!absolute) { // some normalization (because filenames are often used to compare // datastores) if (path.startsWith("/")) { path = path.substring(1); } if (path.startsWith("./")) { path = path.substring(2); } } return path; }
From source file:com.salmonllc.ideTools.Tomcat50Engine.java
/** * Return a File object representing our configuration file. */// ww w .ja va2 s .c o m protected File configFile() { File file = new File(_configFile); if (!file.isAbsolute()) file = new File(System.getProperty("catalina.base"), _configFile); return (file); }