List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:org.jbpcc.admin.beans.navigation.TreeBean.java
private Document readDOM() { Document dom = null;/*from w w w . j ava 2 s . c om*/ FacesContext facesContext = FacesContext.getCurrentInstance(); ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String filename = servletContext.getRealPath(TREE_MENU_CONFIG_FILE); try { FileInputStream istream = new FileInputStream(filename); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); dom = docBuilder.parse(istream); } catch (Exception e) { e.printStackTrace(); } return dom; }
From source file:org.jboss.bpm.report.ReportFacade.java
@GET @Path("view/image/{fileName}") public Response getImage(@PathParam("fileName") String fileName, @Context HttpServletRequest request, @Context ServletContext servletContext) { assertBirtAvailability();//from www.j a va 2 s .c o m String imageDir = servletContext .getRealPath("/WEB-INF" + birtService.getIntegrationConfig().getImageDirectory() + "/"); String absName = imageDir + "/" + fileName; File imageFile = new File(absName); if (!imageFile.exists()) { throw new IllegalArgumentException("Image " + absName + " doesn't exist"); } return Response.ok(imageFile).build(); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.ApplicationModelSetup.java
/** * Load the RDF found in the directory DISPLAY_MODEL_LOAD_AT_STARTUP_DIR * a sub-models of displayModel. The RDF from thes files will not be saved * in the database and it will be reloaded each time the system starts up. *///from w w w . ja v a 2s . c o m private void initializeDisplayLoadedAtStartup(ServletContext ctx, OntModel displayModel) { log.info("loading display model from files in " + ctx.getRealPath(DISPLAY_MODEL_LOAD_AT_STARTUP_DIR)); Model displayLoadAtStartup = readInDisplayModelLoadAtStartup(ctx); if (log.isDebugEnabled()) { log.debug("loaded display model from files in " + ctx.getRealPath(DISPLAY_MODEL_LOAD_AT_STARTUP_DIR)); displayLoadAtStartup.write(System.out, "N3-PP"); } checkForOldListViews(ctx, displayModel, displayLoadAtStartup); displayModel.addSubModel(displayLoadAtStartup); }
From source file:com.hzc.framework.ssh.controller.WebUtil.java
/** * //www . j a v a2 s .c o m * * @param path * @param ufc * @return * @throws Exception */ public static void upload(String path, UploadFileCall ufc) throws RuntimeException { try { HttpServletRequest request = getReq(); ServletContext servletContext = getServletContext(); File file = new File(servletContext.getRealPath(path)); if (!file.exists()) file.mkdirs(); MultipartRequest multi = new MultipartRequest(request, file.getAbsolutePath(), 1024 * 1024 * 1024, "UTF-8", new DefaultFileRenamePolicy()); Enumeration files = multi.getFileNames(); while (files.hasMoreElements()) { String name = (String) files.nextElement(); String filename = multi.getFilesystemName(name); String originalFilename = multi.getOriginalFileName(name); String type = multi.getContentType(name); File f = multi.getFile(name); ufc.file(null, f, filename, originalFilename, type); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:addhandler.ProductMB.java
@SuppressWarnings({ "RedundantStringToString", "CallToPrintStackTrace" }) public void uploadImageFile() { if (file != null) { try {//w ww .ja v a 2 s . c o m FacesContext context = FacesContext.getCurrentInstance(); ServletContext sc = (ServletContext) context.getExternalContext().getContext(); // arrange image file from url String dbpath = sc.getRealPath("/"); // cut from url path convert to image path String webcut = dbpath.substring(0, dbpath.lastIndexOf("\\")); String buildcut = webcut.substring(0, webcut.lastIndexOf("\\")); String mainURLPath = buildcut.substring(0, buildcut.lastIndexOf("\\")); // file generate using inputstream InputStream istrm = file.getInputstream(); // get local machine directory String path = mainURLPath + "\\Shop_Online\\web\\resources\\images\\" + file.getFileName(); File destfile = new File(path); if (!destfile.exists()) { FileUtils.copyInputStreamToFile(istrm, destfile); } // finally setproduct URL variable product.setProUrl(file.getFileName().toString()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.appeligo.config.ConfigurationInitializer.java
/** * Expected to initialize n servlet initializaton. *///from www . j ava 2 s .c o m public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); String rootPath = context.getInitParameter("ConfigurationRootDir"); if (rootPath == null) { rootPath = "WEB-INF/config"; } File rootDir = new File(context.getRealPath(rootPath)); ConfigurationService.setRootDir(rootDir); String baseName = context.getInitParameter("ConfigurationBaseName"); if (baseName != null) { ConfigurationService.setBaseName(baseName); } //configure the environment String envName = new EnvironmentLookup().getEnvironmentName(); if (envName == null) { //look it up in the web.xml envName = context.getInitParameter("ConfigurationEnvName"); } if (envName != null) { ConfigurationService.setEnvName(envName); } else { log.warn( "Cannot find envName from \"deploymentEnvironment\" JNDI variable or \"ConfigurationEnvName\" init param in web.xml. Using default name..."); } ConfigurationService.init(); }
From source file:de.adorsys.jwebsane.controller.WebsaneController.java
private File getFilePath(String fileName) { ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); ServletContext sc = (ServletContext) ec.getContext(); File outputfile = new File(sc.getRealPath("/content/"), fileName); return outputfile; }
From source file:com.hzc.framework.ssh.controller.WebUtil.java
/** * //from w w w .j a v a 2s . co m * * @param path * @param ufc * @return * @throws Exception */ public static void uploadMulti(String path, UploadFileCall ufc) throws RuntimeException { try { HttpServletRequest request = getReq(); ServletContext servletContext = getServletContext(); File file = new File(servletContext.getRealPath(path)); if (!file.exists()) file.mkdir(); DiskFileItemFactory fac = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(fac); upload.setHeaderEncoding("UTF-8"); List<FileItem> fileItems = upload.parseRequest(request); for (FileItem item : fileItems) { if (!item.isFormField()) { String name = item.getName(); String type = item.getContentType(); if (StringUtils.isNotBlank(name)) { File f = new File(file + File.separator + name); item.write(f); ufc.file(null, f, name, name, type); } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:br.com.travelmate.util.Ftp.java
public String enviarArquivoRemessa(File file, String arquivoFTP, String pasta) throws IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); ServletContext request = (ServletContext) facesContext.getExternalContext().getContext(); String destino = request.getRealPath(""); destino = destino + "\\remessa\\" + file.getName(); File f = new File(destino); ftpClient.setControlEncoding("UTF-8"); try {// w w w. jav a 2 s . co m ftpClient.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE); ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE); } catch (IOException e) { } ftpClient.changeWorkingDirectory(pasta); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); FileInputStream arqEnviar = new FileInputStream(f); arquivoFTP = new String(arquivoFTP.getBytes("ISO-8859-1"), "UTF-8"); //arquivoFTP = String.format("mov", file); if (ftpClient.storeFile(arquivoFTP, arqEnviar)) { arqEnviar.close(); return "Arquivo Salvo com Sucesso"; } else { arqEnviar.close(); return "Erro Salvar Arquivo"; } }