List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:org.apache.axis.transport.http.AxisServletBase.java
/** * extract information from the servlet configuration files * @param servlet/*from www . j a v a 2 s. com*/ * @return */ protected static Map getEngineEnvironment(HttpServlet servlet) { Map environment = new HashMap(); String attdir = servlet.getInitParameter(AxisEngine.ENV_ATTACHMENT_DIR); if (attdir != null) environment.put(AxisEngine.ENV_ATTACHMENT_DIR, attdir); ServletContext context = servlet.getServletContext(); environment.put(AxisEngine.ENV_SERVLET_CONTEXT, context); String webInfPath = context.getRealPath("/WEB-INF"); if (webInfPath != null) environment.put(AxisEngine.ENV_SERVLET_REALPATH, webInfPath + File.separator + "attachments"); EngineConfiguration config = EngineConfigurationFactoryFinder.newFactory(servlet).getServerEngineConfig(); if (config != null) { environment.put(EngineConfiguration.PROPERTY_NAME, config); } return environment; }
From source file:org.jbpm.designer.server.EditorHandler.java
/** * @return read the files to be placed as core scripts * from a configuration file in a json file. * @throws java.io.IOException//from w ww . j av a 2 s . c o m */ private static String readEnvFiles(ServletContext context) throws IOException { FileInputStream core_scripts = new FileInputStream(context.getRealPath(designer_path + "js/js_files.json")); try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read; while ((read = core_scripts.read(buffer)) != -1) { stream.write(buffer, 0, read); } return stream.toString(); } finally { try { core_scripts.close(); } catch (IOException e) { _logger.error(e.getMessage(), e); } } }
From source file:ostepu.cconfig.control.java
/** * ruft die existierende Konfiguration ab und gibt sie aus * * @param context der Kontext des Servlet * @param request die eingehende Anfrage * @param response das Antwortobjekt// w ww .j a v a 2 s.com */ public static void getControl(ServletContext context, HttpServletRequest request, HttpServletResponse response) { PrintWriter out; try { out = response.getWriter(); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); return; } Path cconfigPath = Paths.get(context.getRealPath("/data/CConfig.json")); try { if (Files.exists(cconfigPath)) { List<String> content = Files.readAllLines(cconfigPath); JsonElement obj = new JsonParser().parse(String.join("", content)); JsonObject newObject = obj.getAsJsonObject(); if (newObject.has("prefix")) { newObject.remove("prefix"); newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } else { newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } out.print(newObject.toString()); response.setStatus(200); } else { response.setStatus(404); out.print("[]"); } } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } finally { out.close(); } }
From source file:org.openlaszlo.utils.LZHttpUtils.java
/** * Replace real path forward slash characters to back-slash for Windoze. * This is to get around a WebSphere problem (see bug 988). Note that if the * web application content is being served directly from a .war file, this * method will return null. See ServletContext.getRealPath() for more * details.//from w w w. j ava 2s . c o m * * @param ctxt servlet context * @param path virtual webapp path to resolve into a real path * @return the real path, or null if the translation cannot be performed */ static public String getRealPath(ServletContext ctxt, String path) { String realPath = ctxt.getRealPath(path); if (realPath != null && File.separatorChar == '\\') realPath = realPath.replace('/', '\\'); try { return new File(realPath).getCanonicalPath(); } catch (java.io.IOException e) { throw new org.openlaszlo.utils.ChainedException(e); } }
From source file:ostepu.cconfig.control.java
/** * setzt die Konfiguration der Komponente anhand der eingehenden Daten * * @param context der Kontext des Servlet * @param request die eingehende Anfrage * @param response das Antwortobjekt//from w w w . j av a2 s. co m */ public static void setControl(ServletContext context, HttpServletRequest request, HttpServletResponse response) { PrintWriter out; try { out = response.getWriter(); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); return; } Path cconfigPath = Paths.get(context.getRealPath("/data/CConfig.json")); try { String q = IOUtils.toString(request.getReader()); JsonElement obj = new JsonParser().parse(q); JsonObject newObject = obj.getAsJsonObject(); if (newObject.has("prefix")) { newObject.remove("prefix"); newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } else { newObject.add("prefix", (JsonElement) new JsonPrimitive(context.getAttribute("prefix").toString())); } Files.write(cconfigPath, newObject.toString().getBytes()); cconfig.myConf = null; response.setStatus(201); } catch (IOException | JsonSyntaxException e) { try { response.sendError(500); } catch (IOException ex) { Logger.getLogger(control.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } } finally { if (out != null) { out.close(); } } }
From source file:com.valco.utility.FacturasUtility.java
public static void guardaPdf(Integer facturaId, String name, String path) throws Exception { try {//from w w w . j a v a 2 s . c om Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (ClassNotFoundException ex) { Logger.getLogger(ReportesXls.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(ReportesXls.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(ReportesXls.class.getName()).log(Level.SEVERE, null, ex); } try (Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/valco", "admin3ZheGrA", "1VtHQW5M-3g-");) { JasperReport jasperReport = null; JasperReport subreporte = null; ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String realPath = servletContext.getRealPath("//pagina//reportes//factura//Factura.jrxml"); jasperReport = JasperCompileManager.compileReport(realPath); JasperPrint jasperPrint = null; Map mapa = new HashMap(); mapa.put("FacturaId", facturaId); jasperPrint = JasperFillManager.fillReport(jasperReport, mapa, conn); JasperExportManager.exportReportToPdfFile(jasperPrint, path + name); } catch (Exception ex) { throw new Exception("Factura " + facturaId + ": Ocurrio un error al generar el PDF."); } }
From source file:edu.cornell.mannlib.vitro.webapp.utils.jena.ExtendedLinkedDataUtils.java
public static Model createModelFromQueries(ServletContext sc, String rootDir, OntModel sourceModel, String subject) {/*from ww w. ja v a2 s .c o m*/ log.debug("Exploring queries in directory '" + rootDir + "'"); Model model = ModelFactory.createDefaultModel(); @SuppressWarnings("unchecked") Set<String> pathSet = sc.getResourcePaths(rootDir); if (pathSet == null) { log.warn(rootDir + " not found."); return model; } for (String path : pathSet) { File file = new File(sc.getRealPath(path)); if (file.isDirectory()) { model.add(createModelFromQueries(sc, path, sourceModel, subject)); } else if (file.isFile()) { if (!path.endsWith(".sparql")) { log.warn("Ignoring file " + path + " because the file extension is not sparql."); continue; } model.add(createModelFromQuery(file, sourceModel, subject)); log.debug("model size is " + model.size() + " after query in '" + path + "'"); } else { log.warn("path is neither a directory nor a file " + path); } } // end - for return model; }
From source file:nl.strohalm.cyclos.utils.WebImageHelper.java
/** * Return the real path for a given image nature */// ww w . j a v a 2 s .c om public static File imagePath(final Image.Nature nature, final ServletContext context) { String path = null; switch (nature) { case SYSTEM: path = WebImageHelper.SYSTEM_IMAGES_PATH; break; case CUSTOM: path = WebImageHelper.CUSTOM_IMAGES_PATH; break; case STYLE: path = WebImageHelper.STYLE_IMAGES_PATH; break; default: return null; } return new File(context.getRealPath(path)); }
From source file:org.wapama.web.EditorHandler.java
/** * @return read the files to be placed as core scripts * from a configuration file in a json file. * @throws IOException /*from w w w .j a va 2 s . c o m*/ */ private static String readEnvFiles(ServletContext context) throws IOException { FileInputStream core_scripts = new FileInputStream(context.getRealPath("/js/js_files.json")); try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read; while ((read = core_scripts.read(buffer)) != -1) { stream.write(buffer, 0, read); } return stream.toString(); } finally { try { core_scripts.close(); } catch (IOException e) { _logger.error(e.getMessage(), e); } } }
From source file:fr.paris.lutece.portal.service.util.AppPathService.java
/** * Initialize The path service/*from ww w . j av a2 s .co m*/ * * @param context The servlet context */ public static void init(ServletContext context) { String strRealPath = context.getRealPath("/"); _strWebAppPath = normalizeWebappPath(strRealPath); }