List of usage examples for org.springframework.core.io ClassPathResource getPath
public final String getPath()
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);/* ww w .jav a 2 s . c o m*/ }
From source file:piecework.content.concrete.ClasspathContentProvider.java
@Override public ContentResource findByLocation(ContentProfileProvider modelProvider, String rawPath) throws PieceworkException { if (!rawPath.startsWith(ClasspathContentResource.PREFIX)) { LOG.error("Should not be looking for a classpath resource without the classpath prefix"); return null; }//from w w w . j a v a2 s . com String path = rawPath.substring(ClasspathContentResource.PREFIX.length()); ContentProfile contentProfile = modelProvider.contentProfile(); // Show never use ClasspathContentProvider unless the content profile explicitly // specifies a base classpath if (contentProfile == null || StringUtils.isEmpty(contentProfile.getBaseClasspath())) return null; String baseClasspath = contentProfile.getBaseClasspath(); if (!ContentUtility.validateClasspath(baseClasspath, path)) { accessTracker.alarm(AlarmSeverity.MINOR, "Attempt to access classpath " + path + " outside of " + baseClasspath + " forbidden", modelProvider.principal()); throw new ForbiddenError(); } ClassPathResource resource = new ClassPathResource(path); if (!resource.exists()) { LOG.warn("No classpath resource exists for " + resource.getPath()); return null; } return new ClasspathContentResource(resource); }