List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:org.cgiar.dapa.ccafs.tpe.action.BaseAction.java
@Override public void setServletContext(ServletContext arg0) { this.path = arg0.getRealPath("/"); }
From source file:psiprobe.controllers.apps.DownloadXmlConfController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { if (downloadTarget == null) { throw new RuntimeException("Download target is not set for " + getClass().getName()); }//from w ww. j a va 2s . co m String xmlPath; if (TARGET_WEB_XML.equals(downloadTarget)) { ServletContext sctx = context.getServletContext(); xmlPath = sctx.getRealPath("/WEB-INF/web.xml"); } else if (TARGET_CONTEXT_XML.equals(downloadTarget)) { xmlPath = this.getContainerWrapper().getTomcatContainer().getConfigFile(context).getPath(); } else { throw new RuntimeException("Unknown download target " + getDownloadTarget()); } if (xmlPath != null) { File xmlFile = new File(xmlPath); if (xmlFile.exists()) { Utils.sendFile(request, response, xmlFile); } else { logger.debug("File {} of {} application does not exists.", xmlPath, contextName); } } else { logger.debug("Cannot determine path to {} file of {} application.", getDownloadTarget(), contextName); } return null; }
From source file:nl.tue.gale.ae.config.GaleContextLoader.java
private void findInJar(ServletContext sc, String path, List<String> locations) { try {//from ww w . jav a2 s .c o m JarFile jar = new JarFile(sc.getRealPath(path)); for (JarEntry entry : enumIterable(jar.entries())) { if (entry.getName().endsWith("-galeconfig.xml")) locations.add("classpath:" + entry.getName()); } jar.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.intbit.PhantomImageConverter.java
public PhantomImageConverter(ServletContext context) throws Exception { path = context.getRealPath(""); templateJSFilePath = path + "/template.js"; templateHTMLFilePath = path + "/template.html"; tempPath = AppConstants.LAYOUT_IMAGES_HOME + File.separator; File tempPathDir = new File(tempPath); if (!tempPathDir.exists()) { tempPathDir.mkdirs();//ww w . j a va 2s .co m } }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Gets the realPath attribute of the ApplicationPrefs class * * @param context Description of the Parameter * @return The realPath value/*www . j a va 2s.c om*/ */ public static String getRealPath(ServletContext context) { String dir = context.getRealPath("/"); if (dir != null && !dir.endsWith(fs)) { dir += fs; } return dir; }
From source file:org.n52.sensorweb.series.policy.editor.ctrl.DownloadController.java
@Override public void setServletContext(ServletContext sc) { this.sc = sc; permissionsXmlPath = sc.getRealPath(permissionsXmlPath); }
From source file:org.openmrs.module.mapperoverridedemo.CopyLegacyUiContentToWebInf.java
@Override public void setServletContext(ServletContext servletContext) { String basePath = servletContext.getRealPath(""); try {//from w ww . j a v a 2 s. c o m // copy images into legacyui/.../resources/images folder // File destDir = new File(basePath + UILIBRARY_ROOT_DIR + "/resources/images".replace("/", File.separator)); File srcDir = new File(basePath + MODULE_ROOT_DIR + "/resources/images".replace("/", File.separator)); // FileUtils.copyDirectory(srcDir, destDir); String destDirPath = basePath + UILIBRARY_ROOT_DIR + "/resources/images".replace("/", File.separator); File testFile = new File(destDirPath); if (testFile.exists()) { iterateFiles(srcDir.listFiles(), destDirPath); } } catch (IOException ex) { log.error("Failed to copy mapperoverridedemo image files to uilibrary/.../resources/images", ex); } try { // copy images into legacyui/.../resources/images folder // File destDir = new File(basePath + LEGACYUI_ROOT_DIR + "/resources/images".replace("/", File.separator)); File srcDir = new File(basePath + MODULE_ROOT_DIR + "/resources/images".replace("/", File.separator)); // FileUtils.copyDirectory(srcDir, destDir); String destDirPath = basePath + LEGACYUI_ROOT_DIR + "/resources/images".replace("/", File.separator); File testFile = new File(destDirPath); if (testFile.exists()) { iterateFiles(srcDir.listFiles(), destDirPath); } } catch (IOException ex) { log.error("Failed to copy mapperoverridedemo image files to legacyui/.../resources/images", ex); } try { // copy images directly into basePath // File destDir = new File(basePath + "/images".replace("/", File.separator)); File srcDir = new File(basePath + MODULE_ROOT_DIR + "/resources/images".replace("/", File.separator)); //FileUtils.copyDirectory(srcDir, destDir); String destDirPath = basePath + "/images".replace("/", File.separator); iterateFiles(srcDir.listFiles(), destDirPath); } catch (IOException ex) { log.error("Failed to copy mapperoverridedemo image files to basePath", ex); } }
From source file:com.orchestra.portale.controller.UserRegistrationController.java
@RequestMapping(value = "/userSignIn", method = RequestMethod.POST) public ModelAndView addUser(HttpServletRequest request, @ModelAttribute("SpringWeb") User user, MultipartFile avatar) {/*from w w w. j a va2s . com*/ ModelAndView model2 = new ModelAndView("okpage"); User usertest = pm.findUserByUsername(user.getUsername()); if (usertest != null && usertest.getUsername().toLowerCase().equals(user.getUsername().toLowerCase())) { model2.addObject("err", "Esiste gi un utente con username: " + user.getUsername()); return model2; } //HASH PASSWORD user.setPassword(crypt(user.getPassword())); /*Create Role*/ Role new_user_role = new Role(); new_user_role.setRole("ROLE_USER"); new_user_role.setUser(user); ArrayList<Role> new_user_roles = new ArrayList<Role>(); new_user_roles.add(new_user_role); user.setRoles(new_user_roles); pm.saveUser(user); User user2 = pm.findUserByUsername(user.getUsername()); MultipartFile file = avatar; try { byte[] bytes = file.getBytes(); // Creating the directory to store file HttpSession session = request.getSession(); ServletContext sc = session.getServletContext(); File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "user" + File.separator + "img" + File.separator + user2.getId()); if (!dir.exists()) dir.mkdirs(); // Create the file on server File serverFile = new File(dir.getAbsolutePath() + File.separator + "avatar.jpg"); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); } catch (Exception e) { } model2.addObject("mess", "Registrazione completata con successo!<br><br><center> <a href='page?sec=home' class='btn btn-primary'>Torna alla Home</a></center> "); return model2; }
From source file:com.orchestra.portale.controller.UserEditController.java
@RequestMapping("userEditProfile") @Secured("ROLE_USER") public ModelAndView editUser(HttpServletRequest request) { ModelAndView model = new ModelAndView("userEditProfile", "command", new User()); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); User user = pm.findUserByUsername(auth.getName()); HttpSession session = request.getSession(); ServletContext sc = session.getServletContext(); File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "user" + File.separator + "img" + File.separator + user.getId() + File.separator + "avatar.jpg"); if (dir.exists()) { model.addObject("avatar", "./dist/user/img/" + user.getId() + "/avatar.jpg"); } else {/*from w w w.j av a2s.com*/ model.addObject("avatar", "./dist/img/default_avatar.png"); } model.addObject("user", user); return model; }
From source file:net.duckling.falcon.api.mstatic.VersionStartupListener.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); String versionFile = context.getInitParameter("version-file"); String fullpath = context.getRealPath(versionFile); try {/*from w ww . j a va 2 s. c o m*/ String version = FileUtils.readFileToString(new File(fullpath)); if (version != null) { version = version.trim(); } else { version = "N/A"; } VersionAttributeHelper.setVersion(context, version); } catch (IOException e) { log.error("Reading version file failed.", e); } }