List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:org.b3log.solo.service.ImportService.java
/** * Imports markdowns files as articles. See <a href="https://hacpai.com/article/1498490209748">Solo ? Hexo/Jekyll ?</a> for * more details.// ww w. j ava2s .c o m */ public void importMarkdowns() { new Thread(() -> { final ServletContext servletContext = SoloServletListener.getServletContext(); final String markdownsPath = servletContext.getRealPath("markdowns"); LOGGER.debug("Import directory [" + markdownsPath + "]"); JSONObject admin; try { admin = userQueryService.getAdmin(); } catch (final Exception e) { return; } if (null == admin) { // Not init yet return; } final String adminId = admin.optString(Keys.OBJECT_ID); int succCnt = 0, failCnt = 0; final Set<String> failSet = new TreeSet<>(); final Collection<File> mds = FileUtils.listFiles(new File(markdownsPath), new String[] { "md" }, true); if (null == mds || mds.isEmpty()) { return; } for (final File md : mds) { final String fileName = md.getName(); if (StringUtils.equalsIgnoreCase(fileName, "README.md")) { continue; } try { final String fileContent = FileUtils.readFileToString(md, "UTF-8"); final JSONObject article = parseArticle(fileName, fileContent); article.put(Article.ARTICLE_AUTHOR_ID, adminId); final JSONObject request = new JSONObject(); request.put(Article.ARTICLE, article); final String id = articleMgmtService.addArticle(request); FileUtils.moveFile(md, new File(md.getPath() + "." + id)); LOGGER.info("Imported article [" + article.optString(Article.ARTICLE_TITLE) + "]"); succCnt++; } catch (final Exception e) { LOGGER.log(Level.ERROR, "Import file [" + fileName + "] failed", e); failCnt++; failSet.add(fileName); } } if (0 == succCnt && 0 == failCnt) { return; } final StringBuilder logBuilder = new StringBuilder(); logBuilder.append("[").append(succCnt).append("] imported, [").append(failCnt).append("] failed"); if (failCnt > 0) { logBuilder.append(": ").append(Strings.LINE_SEPARATOR); for (final String fail : failSet) { logBuilder.append(" ").append(fail).append(Strings.LINE_SEPARATOR); } } else { logBuilder.append(" :p"); } LOGGER.info(logBuilder.toString()); }).start(); }
From source file:org.CloudOps.laas.ws.login.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); String apikeysPropertiesFilename = config.getServletContext().getInitParameter("apikeys.properties"); if (apikeysPropertiesFilename != null) { if (!apikeysPropertiesFilename.startsWith("/")) { String hd = System.getProperty("user.dir"); if (!hd.endsWith("/")) hd += "/"; apikeysPropertiesFilename = hd + apikeysPropertiesFilename; }//from w w w . j a va 2 s . co m apikeysProperties = new File(apikeysPropertiesFilename); reloadApikeys(); } else { ServletContext context = config.getServletContext(); String path = context.getRealPath("/"); log.info("No API keys defined parameter must be defined 'apikeys.properties', webapp deployed at '" + path + "'"); } }
From source file:laboratorios.CreatePDF.java
/** * Renders an XML file into a PDF file by applying a stylesheet * that converts the XML to XSL-FO. The PDF is written to a byte array * that is returned as the method's result. * @param xml the XML file// w w w .j a va 2 s . c o m * @param xslt the XSLT file * @param response HTTP response object * @throws FOPException If an error occurs during the rendering of the * XSL-FO * @throws TransformerException If an error occurs during XSL * transformation * @throws IOException In case of an I/O problem */ public void renderXML(String xml, String xsl, HttpServletResponse response, ServletContext context) throws FOPException, TransformerException, IOException { URIResolver uriResolver = new ServletContextURIResolver(context); //Setup sources Source xmlSrc = new StreamSource(new StringReader(xml)); String realpath = context.getRealPath(xsl); Source xsltSrc = new StreamSource(new File(realpath)); //Le damos el path real de la aplicacion para que encuentre los ficheros realpath = context.getRealPath("."); //this.transFactory.setURIResolver(uriResolver); Transformer transformer = this.transFactory.newTransformer(xsltSrc); transformer.setURIResolver(uriResolver); //Start transformation and rendering process render(xmlSrc, transformer, response, realpath); }
From source file:managedBeans.informes.InformeSeparadoMB.java
public void generarReporte() throws IOException, JRException { int separado = determinarNumSeparado(); List<FacDocumentosmaster> separados = separadoFacade.buscarSeparados(sedeActual, fechaInicial, fechaFinal, clienteSeleccionado, separado); List<InformeSeparado> lista = generarLista(separados); JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(lista); FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse httpServletResponse = (HttpServletResponse) facesContext.getExternalContext() .getResponse();//ww w . j ava2 s . c o m ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String rutaReportes = servletContext.getRealPath("/informes/reportes/");//ubicacion para los subreportes try (ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream()) { httpServletResponse.setContentType("application/pdf"); servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String ruta = servletContext.getRealPath("/informes/reportes/informeSeparado.jasper"); Map<String, Object> parametros = new HashMap<>(); if (sedeActual.getLogo() != null) { InputStream logo = new ByteArrayInputStream(sedeActual.getLogo()); parametros.put("logo", logo); } parametros.put("SUBREPORT_DIR", rutaReportes); JasperPrint jasperPrint = JasperFillManager.fillReport(ruta, parametros, beanCollectionDataSource); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); FacesContext.getCurrentInstance().responseComplete(); } }
From source file:org.archive.wayback.webapp.RequestMapper.java
/** * @param configPath// w w w.ja v a 2s .c o m * @param servletContext * @throws ConfigurationException */ @SuppressWarnings("unchecked") public RequestMapper(ServletContext servletContext) throws ConfigurationException { String configPath = servletContext.getInitParameter(CONFIG_PATH); if (configPath == null) { throw new ConfigurationException("Missing " + CONFIG_PATH + " parameter"); } String resolvedPath = servletContext.getRealPath(configPath); Resource resource = new FileSystemResource(resolvedPath); factory = new XmlBeanFactory(resource); Map map = factory.getBeansOfType(PropertyPlaceholderConfigurer.class); if (map != null) { Collection<PropertyPlaceholderConfigurer> macros = map.values(); for (PropertyPlaceholderConfigurer macro : macros) { macro.postProcessBeanFactory(factory); } } factory.preInstantiateSingletons(); }
From source file:stella.stella.Bean.java
public void gerarBoletocaixa() { Datas datas = Datas.novasDatas().comDocumento(22, 04, 2013).comProcessamento(22, 04, 2013).comVencimento(29, 04, 2013);//from w ww .j av a 2s.c o m Beneficiario beneficiario = Beneficiario.novoBeneficiario().comNomeBeneficiario("Rodrigo Turini") .comAgencia("2873").comCarteira("1").comCodigoBeneficiario("2359") .comNossoNumero("990000000003994458").comDigitoNossoNumero("0"); Pagador pagador = Pagador.novoPagador().comNome("Mario Amaral"); Caixa banco = new Caixa(); Boleto boletoc = Boleto.novoBoleto().comDatas(datas).comBeneficiario(beneficiario).comBanco(banco) .comPagador(pagador).comValorBoleto(4016.10).comNumeroDoDocumento("3084373"); GeradorDeBoleto gerador = new GeradorDeBoleto(boletoc); File pdf = new File(System.getProperty("user.home") + File.separator + "caixa.pdf"); gerador.geraPDF(pdf.getAbsolutePath()); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String absoluteDiskPath = servletContext.getRealPath("/resources/arquivos"); File a = new File(absoluteDiskPath + File.separator + "caixa.pdf"); byte[] bytes = gerador.geraPDF(); try { FileUtils.writeByteArrayToFile(a, bytes); } catch (IOException ex) { Logger.getLogger(Bean.class.getName()).log(Level.SEVERE, null, ex); } this.boleto = pdf.getAbsolutePath(); }
From source file:tsuboneSystem.action.admin.SettingsEditAction.java
@Execute(validator = true, validate = "validateUpload", input = "ruleUpdateView", stopOnValidationError = false) public String ruleUpdateComplete() { //ServletContext ?? ServletContext app = ServletContextUtil.getServletContext(); //????(DB?????????) String path = app.getRealPath("/pdf/kaisoku.pdf"); //??????????/*www . j av a2 s .co m*/ UploadUtil.write(path, settingsEditForm.rulePdf); return "ruleUpdateComplete.jsp"; }
From source file:ntut.csie.ezScrum.web.InitialPlugIn.java
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { log.info("*************Plugin Initail***********"); // ?Server//from w w w. j a v a2 s.c o m ServletContext application = servlet.getServletContext(); String WebRootPath = application.getRealPath("/"); //??WebRootPath??/ // ? linux ?? // ? xxxxx\ezScrum\/RoleBase.xml ? // if((!WebRootPath.endsWith("/"))||(!WebRootPath.endsWith("\\"))) // { // WebRootPath = WebRootPath.concat("/"); // } if (!WebRootPath.endsWith(File.separator)) { WebRootPath = WebRootPath.concat(File.separator); } this.configManager = new InitialConfigManager(WebRootPath); // Start Set Properties System.setProperty(ISystemPropertyEnum.JOB_SCHEDULER, configManager.getConfig(ISystemPropertyEnum.JOB_SCHEDULER)); System.setProperty(ISystemPropertyEnum.APP_PATH, WebRootPath); /*----------------------------------------------------------- * Workspace Path??? -------------------------------------------------------------*/ String WebRootPath_Workspace = System.getProperty(ISystemPropertyEnum.WORKSPACE_PATH); if (WebRootPath_Workspace == null) { System.setProperty(ISystemPropertyEnum.WORKSPACE_PATH, WebRootPath + "Workspace"); } System.setProperty(ISystemPropertyEnum.LIB_PATH, WebRootPath + "WEB-INF" + File.separator + "lib"); //jake, mantis task 616, jcis 632 System.setProperty(ISystemPropertyEnum.SNAPSHOT_NAME, "MySnapshot"); System.setProperty(ISystemPropertyEnum.SNAPSHOT_PATH, WebRootPath + System.getProperty(ISystemPropertyEnum.SNAPSHOT_NAME)); ////jake, mantis task 616, jcis 632 end System.setProperty(ISystemPropertyEnum.INTEGRATOR_REPORT_XSLPATH, WebRootPath + "IntegrationReport.xsl"); System.setProperty(ISystemPropertyEnum.BUILDER_REPORT_XSLPATH, WebRootPath + "xsl"); System.setProperty(ISystemPropertyEnum.ACCOUT_MANAGER, "ntut.csie.jcis.account.core.internal.XMLAccountManager"); System.setProperty(ISystemPropertyEnum.ACCOUT_MANAGER_PATH, WebRootPath + "RoleBase.xml"); System.setProperty(ISystemPropertyEnum.WEB_APP_NAME, "ezScrum"); System.setProperty(ISystemPropertyEnum.REMOTE_MACHINE_LINUX, "127.0.0.1"); System.setProperty(ISystemPropertyEnum.FULL_WEB_APP_NAME, "http://localhost:8080/JCIS/"); // ?web serverip address try { System.setProperty(ISystemPropertyEnum.WEB_ROOT_ADDRESS, "http://" + InetAddress.getLocalHost().getHostAddress() + ":8080/ezScrum/"); } catch (UnknownHostException e) { e.printStackTrace(); String ip = this.configManager.getConfig(ISystemPropertyEnum.WEB_ROOT_ADDRESS); System.setProperty(ISystemPropertyEnum.WEB_ROOT_ADDRESS, "http://" + ip + ":8080/ezScrum/"); } System.setProperty(ISystemPropertyEnum.RSS_PATH, WebRootPath + File.separator + "Pages" + File.separator + "RSS"); // ezScrum system version information this.configManager.ezScrumConfigLoad(); System.setProperty("System_Version", this.configManager.getConfig("System_Version")); log.info("ezScrum Version: " + System.getProperty("System_Version")); // update ezScrum server url System.setProperty("System_UpdateURL", this.configManager.getConfig("ezScrum.update.server.url")); log.info("ezScrum Update Server: " + System.getProperty("System_UpdateURL")); // update ezScrum workspace path System.setProperty("System_UpdateWorkspace", System.getProperty("user.home") + File.separator + ".ezScrum" + File.separator + "updates"); log.info("ezScrum Update Download Path: " + System.getProperty("System_UpdateWorkspace")); // ezScrum System.setProperty("System_Start_Time", (new Date()).toString()); log.info("ezScrum Start Time: " + System.getProperty("System_Start_Time")); // ProjectLogic projectLogic = new ProjectLogic(); // projectLogic.cloneDefaultFile(); ezSCrum v1.8?? // ============================================= // ? v1.2 ?? // ? RoleBase // projectLogic.check_default_role(); ezSCrum v1.8?? // ? ScrumRole ? guest // projectLogic.check_role_guest(); ezSCrum v1.8?? // ============================================= /* * ezScrum system information * ?? String systemTeam = this.configManager.getConfig("System_Team"); String contactInformation = this.configManager.getConfig("contact_information"); try { systemTeam = new String(systemTeam.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { contactInformation = new String(contactInformation.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.setProperty("System_Team",systemTeam); System.setProperty("contact_information",contactInformation); */ // log.info("ntut.csie.jcis.ApplicationRoot=\t" // + System.getProperty("ntut.csie.jcis.ApplicationRoot")); // log.info("ntut.csie.jcis.resource.WorkspaceRoot=\t" // + System.getProperty("ntut.csie.jcis.resource.WorkspaceRoot")); // log.info("ntut.csie.jcis.LibPath=\t" // + System.getProperty("ntut.csie.jcis.LibPath")); // log.info("ntut.csie.jcis.SnapshotName=\t" // + System.getProperty("ntut.csie.jcis.SnapshotName")); // log.info("ntut.csie.jcis.SnapshotPath=\t" // + System.getProperty("ntut.csie.jcis.SnapshotPath")); // log // .info("ntut.csie.jcis.integrationReport.xslPath=\t" // + System // .getProperty("ntut.csie.jcis.integrationReport.xslPath")); // log.info("ntut.csie.jcis.builderReport.xslPath=\t" // + System.getProperty("ntut.csie.jcis.builderReport.xslPath")); // log.info("ntut.csie.jcis.WebAppName=\t" // + System.getProperty("ntut.csie.jcis.WebAppName")); // log.info("ntut.csie.jcis.accountManager=\t" // + System.getProperty("ntut.csie.jcis.accountManager")); // log.info("ntut.csie.jcis.accountManager.path=\t" // + System.getProperty("ntut.csie.jcis.accountManager.path")); // // System.setProperty(ISystemPropertyEnum.BACKUP_PATH, WebRootPath // + "Backup"); // log.info("ntut.csie.jcis.UseVirtualEnvironment=\t" // + System.getProperty("ntut.csie.jcis.UseVirtualEnvironment")); // log.info("ntut.csie.jcis.VMMSIPAddress=\t" // + System.getProperty("ntut.csie.jcis.VMMSIPAddress")); // log.info("ntut.csie.jcis.temp.workspaceRoot=\t" // + System.getProperty("ntut.csie.jcis.temp.workspaceRoot")); // log.info("ntut.csie.jcis.tempDownloadURL=\t" // + System.getProperty("ntut.csie.jcis.tempDownloadURL")); // log.info("ntut.csie.jcis.UploadPath=\t" // + System.getProperty("ntut.csie.jcis.UploadPath")); // log.info("ntut.csie.jcis.UploadUrl=\t" // + System.getProperty("ntut.csie.jcis.UploadUrl")); // log.info("ntut.csie.jcis.SourceServerPath=\t" // + System.getProperty("ntut.csie.jcis.SourceServerPath")); // log.info("ntut.csie.jcis.SourceServerUrl=\t" // + System.getProperty("ntut.csie.jcis.SourceServerUrl")); // log.info("Create PIC"); // ProjectInfoCenter.getInstance(); log.info("*************Plugin Initail END***********"); // log.info("*************Start Patch***********"); // Patcher patcher = new Patcher(WebRootPath+"Patch", WebRootPath+"..", WebRootPath+"Backup"); // patcher.patchAll(); // log.info("*************Start End***********"); }
From source file:org.apache.axis.transport.http.AxisServletBase.java
/** * our initialize routine; subclasses should call this if they override it *//*w ww .ja v a 2 s.c om*/ public void init() throws javax.servlet.ServletException { ServletContext context = getServletConfig().getServletContext(); webInfPath = context.getRealPath("/WEB-INF"); homeDir = context.getRealPath("/"); isDebug = log.isDebugEnabled(); if (log.isDebugEnabled()) log.debug("In AxisServletBase init"); isDevelopment = JavaUtils.isTrueExplicitly(getOption(context, INIT_PROPERTY_DEVELOPMENT_SYSTEM, null)); }
From source file:stella.stella.Bean.java
public void gerarBoleto() { Datas datas = Datas.novasDatas().comDocumento(1, 5, 2008).comProcessamento(1, 5, 2008).comVencimento(2, 1, 2015);/*from w w w .j a va2 s . c o m*/ Endereco enderecoBeneficiario = Endereco.novoEndereco().comLogradouro("Av das Empresas, 555") .comBairro("Bairro Grande").comCep("01234-555").comCidade("So Paulo").comUf("SP"); //Quem emite o boleto Beneficiario beneficiario = Beneficiario.novoBeneficiario().comNomeBeneficiario("Fulano de Tal") .comAgencia("1824").comDigitoAgencia("4").comCodigoBeneficiario("76000") .comDigitoCodigoBeneficiario("5").comNumeroConvenio("1207113").comCarteira("18") .comEndereco(enderecoBeneficiario).comNossoNumero("9000206"); Endereco enderecoPagador = Endereco.novoEndereco().comLogradouro("Av dos testes, 111 apto 333") .comBairro("Bairro Teste").comCep("01234-111").comCidade("So Paulo").comUf("SP"); //Quem paga o boleto Pagador pagador = Pagador.novoPagador().comNome("Fulano da Silva").comDocumento("111.222.333-12") .comEndereco(enderecoPagador); Banco banco = new BancoDoBrasil(); Boleto boleto2 = Boleto.novoBoleto().comBanco(banco).comDatas(datas).comBeneficiario(beneficiario) .comPagador(pagador).comValorBoleto("2036.47").comNumeroDoDocumento("1234") .comInstrucoes("instrucao 1", "instrucao 2", "instrucao 3", "instrucao 4", "instrucao 5") .comLocaisDePagamento("local 1", "local 2"); GeradorDeBoleto gerador = new GeradorDeBoleto(boleto2); File pdf = new File(System.getProperty("user.home") + File.separator + "brasil.pdf"); gerador.geraPDF(pdf.getAbsolutePath()); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String absoluteDiskPath = servletContext.getRealPath("/resources/arquivos"); File a = new File(absoluteDiskPath + File.separator + "brasil.pdf"); byte[] bytes = gerador.geraPDF(); try { FileUtils.writeByteArrayToFile(a, bytes); } catch (IOException ex) { Logger.getLogger(Bean.class.getName()).log(Level.SEVERE, null, ex); } this.boleto = pdf.getAbsolutePath(); }