List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:org.kuali.kfs.sys.service.impl.ReportGenerationServiceImpl.java
/** * complie the report template xml file into a Jasper report file if the compiled file does not exist or is out of update * //from ww w . j ava 2 s.co m * @param template the name of the template file, without an extension * @return an input stream where the intermediary report was written */ protected File compileReportTemplate(String template) throws JRException, IOException { ClassPathResource designTemplateResource = new ClassPathResource(template); if (!designTemplateResource.exists()) { throw new RuntimeException("The design template file does not exist: " + template); } File tempJasperDir = new File( System.getProperty("java.io.tmpdir") + File.separator + template.replaceAll("\\/[^\\/]+$", "")); if (!tempJasperDir.exists()) { FileUtils.forceMkdir(tempJasperDir); } File tempJasperFile = new File(System.getProperty("java.io.tmpdir") + File.separator + template.replace(ReportGeneration.DESIGN_FILE_EXTENSION, "") .concat(ReportGeneration.JASPER_REPORT_EXTENSION)); if (!tempJasperFile.exists()) { JasperCompileManager.compileReportToStream(designTemplateResource.getInputStream(), new FileOutputStream(tempJasperFile)); } return tempJasperFile; }
From source file:org.kuali.ole.select.service.impl.BibInfoServiceImpl.java
private Properties loadPropertiesFromClassPath(String classPath) throws Exception { ClassPathResource classPathResource = new ClassPathResource(classPath); Properties properties = new Properties(); try {/* w w w . j ava 2 s .c o m*/ properties.load(classPathResource.getInputStream()); } catch (IOException e) { throw new RuntimeException("Invalid class path: " + classPath, e); } return properties; }
From source file:org.metamorfosis.framework.SpringContextTest.java
public void testClassPathResource() throws IOException { ClassPathResource resource = new ClassPathResource("templates/internalTemplate.ftl"); File file = resource.getFile(); log.debug("classpath file: " + file); String filename = resource.getFilename(); log.debug("filename: " + filename); String path = resource.getPath(); log.debug("path: " + path); String absolutePath = file.getAbsolutePath(); log.debug("absolutePath: " + absolutePath); resource = new ClassPathResource("overview.html"); InputStream inputStream = resource.getInputStream(); log.debug(inputStream);/* w w w . j av a 2s .com*/ }
From source file:org.metamorfosis.template.freemarker.FreemarkerEngineTest.java
public void testCreateTemplateFromReader() throws IOException { Configuration cfg = new Configuration(); ClassPathResource resource = new ClassPathResource("templates/internalTemplate.ftl"); InputStream is = resource.getInputStream(); InputStreamReader reader = new InputStreamReader(is); Template template = new Template("nombreTemplate", reader, cfg); assertEquals("nombreTemplate", template.getName()); log.debug("template: " + template); }
From source file:org.muse.mneme.tool.PartEditView.java
/** * Final initialization, once all dependencies are set. */// w ww . j a va2 s . c o m public void init() { super.init(); // interface from XML in the class path if (this.viewPath != null) { try { ClassPathResource rsrc = new ClassPathResource(this.viewPath2); this.ui2 = uiService.newInterface(rsrc.getInputStream()); } catch (IOException e) { } } M_log.info("init()"); }
From source file:org.nema.medical.mint.server.ServerConfig.java
private Properties envSpecificProperties() throws IOException { if (properties == null) { final ClassPathResource classPathResource = new ClassPathResource("default.config"); final Properties defaultProperties = new Properties(); defaultProperties.load(classPathResource.getInputStream()); final File mintHome = mintHome(); final File customConfigFile = new File(mintHome, "mint-server.config"); if (!customConfigFile.exists()) { final Writer customConfigWriter = new BufferedWriter(new FileWriter(customConfigFile)); try { defaultProperties.store(customConfigWriter, null); } finally { customConfigWriter.close(); }/*from w ww .ja v a2 s. c o m*/ } final Properties customProperties = new Properties(); final Reader customConfigReader = new BufferedReader(new FileReader(customConfigFile)); try { customProperties.load(customConfigReader); } finally { customConfigReader.close(); } final Set<Object> defaultPropKeys = defaultProperties.keySet(); final Set<Object> customPropKeys = customProperties.keySet(); final Set<Object> defaultNotCustomKeys = new HashSet<Object>(defaultPropKeys); defaultNotCustomKeys.removeAll(customPropKeys); final Set<Object> customNotDefaultKeys = new HashSet<Object>(customPropKeys); customNotDefaultKeys.removeAll(defaultPropKeys); if (!customNotDefaultKeys.isEmpty()) { final StringBuilder diffKeysText = new StringBuilder( "The following properties exist in mint-server.config," + " but not in default.config:"); for (final Object key : customNotDefaultKeys) { diffKeysText.append(' '); diffKeysText.append(key); } LOG.warn(diffKeysText); } if (!defaultNotCustomKeys.isEmpty()) { final StringBuilder diffKeysText = new StringBuilder( "The following properties exist in default.config," + " but not in mint-server.config;" + " default values (in parentheses) will be used:"); for (final Object key : defaultNotCustomKeys) { final Object defaultPropValue = defaultProperties.get(key); diffKeysText.append(' '); diffKeysText.append(key); diffKeysText.append(" ("); diffKeysText.append(defaultPropValue); diffKeysText.append(')'); //Also add default property to custom properties customProperties.put(key, defaultPropValue); } LOG.warn(diffKeysText); } properties = customProperties; } return properties; }
From source file:org.openehealth.ipf.commons.xml.LSResourceResolverImpl.java
/** * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(String, String, * String, String, String)/*w w w . ja v a 2 s . co m*/ */ @Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { ClassPathResource resource = new ClassPathResource(systemId); LSInput lsInput = null; try { InputStream is = resource.getInputStream(); lsInput = new LSInputImpl(is); } catch (IOException e) { LOG.info("Referenced external file " + systemId + " could not be found. Falling back to " + "default resolution."); } return lsInput; }
From source file:org.openlegacy.AbstractTest.java
protected String readResource(String resourceName) throws IOException { ClassPathResource resource = new ClassPathResource(resourceName); return IOUtils.toString(resource.getInputStream()); }
From source file:org.openlmis.fulfillment.web.ProofOfDeliveryControllerIntegrationTest.java
@Test @Ignore("Current version *.jrxml have relations to different modules (like reference-data)") public void shouldPrintProofOfDeliveryToPdf() throws Exception { ClassPathResource podReport = new ClassPathResource("reports/podPrint.jrxml"); Template template = new Template(PRINT_POD, null, null, CONSISTENCY_REPORT, ""); JasperReport report = JasperCompileManager.compileReport(podReport.getInputStream()); JRParameter[] jrParameters = report.getParameters(); if (jrParameters != null && jrParameters.length > 0) { template.setTemplateParameters(Arrays.stream(jrParameters).filter(p -> !p.isSystemDefined()) .map(this::createParameter).collect(Collectors.toList())); }/* w w w . ja v a 2 s . c o m*/ given(templateRepository.findByName(PRINT_POD)).willReturn(template); restAssured.given().pathParam("id", proofOfDelivery.getId()).queryParam(ACCESS_TOKEN, getToken()).when() .get(PRINT_URL).then().statusCode(200); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.orcid.frontend.web.controllers.BaseController.java
/** * Return the path where the static content will be. If there is a cdn path * configured, it will return the cdn path; if it is not a cdn path it will * return a reference to the static folder "/static" * // w w w . j a va 2 s . c o m * @return the path to the CDN or the path to the local static content * */ @ModelAttribute("staticCdn") @Cacheable("staticContent") public String getStaticCdnPath() { if (StringUtils.isEmpty(this.cdnConfigFile)) { return getStaticContentPath(); } ClassPathResource configFile = new ClassPathResource(this.cdnConfigFile); if (configFile.exists()) { try (InputStream is = configFile.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String uri = br.readLine(); if (uri != null) this.staticCdnPath = uri; } catch (IOException e) { e.printStackTrace(); } } if (StringUtils.isBlank(this.staticCdnPath)) this.staticCdnPath = this.getStaticContentPath(); return staticCdnPath; }