List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:com.aimluck.eip.util.ALTimelineUtils.java
private static void uploadTimelineImage(ServletContext servletContext, int uid, int index, String title, String filePath, String sFilePath, EipTTimeline timeline) throws FileNotFoundException, IOException { Date now = new Date(); String filename = index + "_" + String.valueOf(System.nanoTime()); File tmpFile = new File(servletContext.getRealPath(sFilePath)); byte[] imageInBytes = IOUtils.toByteArray(new FileInputStream(tmpFile)); EipTTimelineFile file = Database.create(EipTTimelineFile.class); file.setOwnerId(uid);/* w w w . j a v a 2 s.c o m*/ file.setFileName(title); file.setFilePath(getRelativePath(filename)); file.setFileThumbnail(imageInBytes); file.setEipTTimeline(timeline); file.setCreateDate(now); file.setUpdateDate(now); Database.commit(); tmpFile = new File(servletContext.getRealPath(filePath)); imageInBytes = IOUtils.toByteArray(new FileInputStream(tmpFile)); ALStorageService.createNewFile(new ByteArrayInputStream(imageInBytes), JetspeedResources.getString("aipo.filedir", "") + ALStorageService.separator() + Database.getDomainName() + ALStorageService.separator() + JetspeedResources.getString("aipo.timeline.categorykey", "") + ALStorageService.separator() + uid + ALStorageService.separator() + filename); }
From source file:nl.b3p.catalog.arcgis.ArcObjectsSynchronizerForker.java
public static Document synchronize(ServletContext context, /* HttpServletResponse response,*/ String dataset, String type, String sdeConnectionString, String metadata) throws Exception { String workingDir = context.getRealPath("/WEB-INF"); String cp = buildClasspath(context); String mainClass = ArcObjectsSynchronizerMain.class.getName(); List<String> args = new ArrayList<String>(); args.addAll(Arrays.asList("java", "-classpath", cp, mainClass, "-type", type, "-dataset", dataset)); if (metadata != null && !"".equals(metadata)) { args.add("-stdin"); }//from w ww .j a v a 2s .c o m if ("sde".equals(type)) { if (sdeConnectionString == null) { throw new IllegalArgumentException("SDE connection string is required"); } args.add("-sde"); args.add(sdeConnectionString); } final StringWriter output = new StringWriter(); final StringWriter errors = new StringWriter(); // response.getWriter(); errors.write(String.format("Werkdirectory: %s\nUitvoeren synchronizer proces: %s\n\n", workingDir, StringUtils.join(args, ' '))); //errors.flush(); int result; try { Process p = Runtime.getRuntime().exec(args.toArray(new String[] {}), null, new File(workingDir)); final BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); final BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); if (metadata != null && !"".equals(metadata)) { try { p.getOutputStream().write(metadata.getBytes("UTF-8")); p.getOutputStream().flush(); p.getOutputStream().close(); } catch (Exception e) { errors.write("Fout tijdens schrijven metadata XML met alle elementen naar stdin: " + e.getClass() + ": " + e.getMessage() + "\n"); } } // Threads vereist omdat streams blocken en pas verder gaan nadat je uit // de andere stream hebt gelezen Thread stderrReader = new Thread() { @Override public void run() { String line; try { while ((line = stderr.readLine()) != null) { errors.write(line + "\r\n"); //errors.flush(); } stderr.close(); } catch (Exception e) { throw new Error(e); } } }; Thread stdoutReader = new Thread() { @Override public void run() { String line; try { while ((line = stdout.readLine()) != null) { output.write(line + "\r\n"); } stdout.close(); } catch (Exception e) { throw new Error(e); } } }; stderrReader.start(); stdoutReader.start(); result = p.waitFor(); stderrReader.join(); stdoutReader.join(); errors.write("Resultaat: " + (result == 0 ? "succesvol gesynchroniseerd" : "fout opgetreden") + "\n\n"); } catch (Exception e) { throw new Exception( "Fout tijdens aanroepen extern proces voor synchroniseren, output: \n" + errors.toString(), e); } if (log.isDebugEnabled()) { log.debug("Synchroniseren via apart proces succesvol; output: " + errors.toString()); } if (result == 0) { return DocumentHelper.getMetadataDocument(output.toString()); } else { throw new Exception("Synchroniseren via apart process geeft error code " + result + "; output: \n" + errors.toString()); } }
From source file:gov.nih.nci.caintegrator.web.SessionHelper.java
/** * * @param context servlet context.//from w w w. j a va 2 s . c om * @return heatmap large bins file path. */ public static String getHeatmapLargeBinsFile(ServletContext context) { return context.getRealPath(WEBINF_CLASSES_DIR + HeatmapFileTypeEnum.LARGE_BINS_FILE.getFilename()); }
From source file:gov.nih.nci.caintegrator.web.SessionHelper.java
/** * * @param context servlet context./* ww w. jav a 2 s .com*/ * @return heatmap small bins file path. */ public static String getHeatmapSmallBinsFile(ServletContext context) { return context.getRealPath(WEBINF_CLASSES_DIR + HeatmapFileTypeEnum.SMALL_BINS_FILE.getFilename()); }
From source file:com.sifcoapp.report.util.ReportConfigUtil.java
public static void exportReportAsExcel(JasperPrint jasperPrint, PrintWriter out, ServletContext context, ExternalContext ec, String fileName) throws JRException, FileNotFoundException, IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); String ruta = context.getRealPath("WEB-INF") + "\\balance.xls"; //OutputStream outputfile = new FileOutputStream(new File("d:/output/JasperReport1.xls"));//make sure to have the directory. excel file will export here OutputStream outputfile = new FileOutputStream(new File(ruta));//make sure to have the directory. excel file will export here // coding For Excel: JRXlsExporter exporterXLS = new JRXlsExporter(); exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint); exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, output); exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporterXLS.exportReport();/* w ww .j av a 2 s.c o m*/ outputfile.write(output.toByteArray()); ec.responseReset(); ec.setResponseContentType(ec.getMimeType(ruta)); //ec.setResponseContentLength(contentLength); ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xls\""); InputStream input = new FileInputStream(ruta); OutputStream output2 = ec.getResponseOutputStream(); IOUtils.copy(input, output2); }
From source file:com.sinosoft.one.mvc.web.var.PrivateVar.java
/** * /* ww w.j a va 2 s . co m*/ * @param name * @return */ public static String getProperty(ServletContext servletContext, String name, String def) { if (mvcProperties == null) { String mvcPropertiesPath = "mvc.properties"; if (servletContext != null) { mvcPropertiesPath = "/WEB-INF/mvc.properties"; } Properties mvcProperties = new Properties(); File file = new File(servletContext.getRealPath(mvcPropertiesPath)); if (file.exists()) { InputStream in = null; try { in = new FileInputStream(file); mvcProperties.load(in); } catch (IOException e) { throw new IllegalArgumentException(mvcPropertiesPath, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block } } } PrivateVar.mvcProperties = mvcProperties; } else { PrivateVar.mvcProperties = new Properties(); } } return mvcProperties.getProperty(name, def); }
From source file:net.paoding.rose.web.var.PrivateVar.java
/** * //www . j a va 2 s. com * @param name * */ public static String getProperty(ServletContext servletContext, String name, String def) { if (roseProperties == null) { String rosePropertiesPath = "rose.properties"; if (servletContext != null) { rosePropertiesPath = "/WEB-INF/rose.properties"; } Properties roseProperties = new Properties(); File file = new File(servletContext.getRealPath(rosePropertiesPath)); if (file.exists()) { InputStream in = null; try { in = new FileInputStream(file); roseProperties.load(in); } catch (IOException e) { throw new IllegalArgumentException(rosePropertiesPath, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block } } } PrivateVar.roseProperties = roseProperties; } else { PrivateVar.roseProperties = new Properties(); } } return roseProperties.getProperty(name, def); }
From source file:com.laxser.blitz.web.var.PrivateVar.java
/** * /*ww w. j a va2s. c o m*/ * @param name * @return */ public static String getProperty(ServletContext servletContext, String name, String def) { if (blitzProperties == null) { String blitzPropertiesPath = "blitz.properties"; if (servletContext != null) { blitzPropertiesPath = "/WEB-INF/blitz.properties"; } Properties blitzProperties = new Properties(); File file = new File(servletContext.getRealPath(blitzPropertiesPath)); if (file.exists()) { InputStream in = null; try { in = new FileInputStream(file); blitzProperties.load(in); } catch (IOException e) { throw new IllegalArgumentException(blitzPropertiesPath, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block } } } PrivateVar.blitzProperties = blitzProperties; } else { PrivateVar.blitzProperties = new Properties(); } } return blitzProperties.getProperty(name, def); }
From source file:edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration.java
private static TemplateLoader createTemplateLoader(HttpServletRequest req, String themeDir) { ServletContext ctx = req.getSession().getServletContext(); List<TemplateLoader> loaders = new ArrayList<TemplateLoader>(); // Theme template loader - only if the theme has a template directory. String themeTemplatePath = ctx.getRealPath("/" + themeDir) + "/templates"; File themeTemplateDir = new File(themeTemplatePath); if (themeTemplateDir.exists()) { loaders.add(new FreemarkerTemplateLoader(themeTemplateDir)); }//w w w . ja v a2 s .c om // Vitro template loader String vitroTemplatePath = ctx.getRealPath("/templates/freemarker"); loaders.add(new FreemarkerTemplateLoader(new File(vitroTemplatePath))); // TODO VIVO-243 Why is this here? loaders.add(new ClassTemplateLoader(FreemarkerConfiguration.class, "")); TemplateLoader[] loaderArray = loaders.toArray(new TemplateLoader[loaders.size()]); TemplateLoader tl = new MultiTemplateLoader(loaderArray); // If requested, add delimiters to the templates. DeveloperSettings settings = DeveloperSettings.getInstance(); if (settings.getBoolean(Key.INSERT_FREEMARKER_DELIMITERS)) { tl = new DelimitingTemplateLoader(tl); } return tl; }
From source file:org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor.java
/** * Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory * * @param servletContext//ww w. j av a2s .c o m * @return null if cannot determin /WEB-INF/classes */ private static URL findWebInfClassesPath(ServletContext servletContext) { String path = servletContext.getRealPath("/WEB-INF/classes"); if (path == null) return null; File fp = new File(path); if (fp.exists() == false) return null; try { URI uri = fp.toURI(); return uri.toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }