Tabnine Logo
ServletContextResource
Code IndexAdd Tabnine to your IDE (free)

How to use
ServletContextResource
in
org.springframework.web.context.support

Best Java code snippets using org.springframework.web.context.support.ServletContextResource (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

/**
 * This implementation supports file paths beneath the root of the web application.
 * @see ServletContextResource
 */
@Override
protected Resource getResourceByPath(String path) {
  return new ServletContextResource(this.servletContext, path);
}
origin: spring-projects/spring-framework

/**
 * Overridden version which checks for ServletContextResource
 * and uses {@code ServletContext.getResourcePaths} to find
 * matching resources below the web application root directory.
 * In case of other resources, delegates to the superclass version.
 * @see #doRetrieveMatchingServletContextResources
 * @see ServletContextResource
 * @see javax.servlet.ServletContext#getResourcePaths
 */
@Override
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
    throws IOException {
  if (rootDirResource instanceof ServletContextResource) {
    ServletContextResource scResource = (ServletContextResource) rootDirResource;
    ServletContext sc = scResource.getServletContext();
    String fullPattern = scResource.getPath() + subPattern;
    Set<Resource> result = new LinkedHashSet<>(8);
    doRetrieveMatchingServletContextResources(sc, fullPattern, scResource.getPath(), result);
    return result;
  }
  else {
    return super.doFindPathMatchingFileResources(rootDirResource, subPattern);
  }
}
origin: geoserver/geoserver

if (resource != null && resource.exists()) {
  file = resource.getFile();
origin: org.springframework.extensions.surf/spring-webscripts

ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + path);
if (resource.exists())
origin: org.springframework.extensions.surf/spring-surf

  public InputStream loadInputStream() throws IOException
  {
    InputStream in = null;
    ServletContextResource resource = new ServletContextResource(servletContext, path);
    {
      if (resource.exists())
      {
        in = resource.getInputStream();
      }
    }
    return in;
  }
}
origin: apache/servicemix-bundles

/**
 * Return the file timestamp for the given resource.
 * @param resourceUrl the URL of the resource
 * @return the file timestamp in milliseconds, or -1 if not determinable
 */
protected long getFileTimestamp(String resourceUrl) {
  ServletContextResource resource = new ServletContextResource(getServletContext(), resourceUrl);
  try {
    long lastModifiedTime = resource.lastModified();
    if (logger.isDebugEnabled()) {
      logger.debug("Last-modified timestamp of " + resource + " is " + lastModifiedTime);
    }
    return lastModifiedTime;
  }
  catch (IOException ex) {
    if (logger.isWarnEnabled()) {
      logger.warn("Couldn't retrieve last-modified timestamp of " + resource +
          " - using ResourceServlet startup time");
    }
    return -1;
  }
}
origin: spring-projects/spring-framework

private boolean isResourceUnderLocation(Resource resource, Resource location) throws IOException {
  if (resource.getClass() != location.getClass()) {
    return false;
  }
  String resourcePath;
  String locationPath;
  if (resource instanceof UrlResource) {
    resourcePath = resource.getURL().toExternalForm();
    locationPath = StringUtils.cleanPath(location.getURL().toString());
  }
  else if (resource instanceof ClassPathResource) {
    resourcePath = ((ClassPathResource) resource).getPath();
    locationPath = StringUtils.cleanPath(((ClassPathResource) location).getPath());
  }
  else if (resource instanceof ServletContextResource) {
    resourcePath = ((ServletContextResource) resource).getPath();
    locationPath = StringUtils.cleanPath(((ServletContextResource) location).getPath());
  }
  else {
    resourcePath = resource.getURL().getPath();
    locationPath = StringUtils.cleanPath(location.getURL().getPath());
  }
  if (locationPath.equals(resourcePath)) {
    return true;
  }
  locationPath = (locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/");
  return (resourcePath.startsWith(locationPath) && !isInvalidEncodedPath(resourcePath));
}
origin: spring-projects/spring-framework

/**
 * This implementation delegates to {@code ServletContext.getResourceAsStream},
 * but throws a FileNotFoundException if no resource found.
 * @see javax.servlet.ServletContext#getResourceAsStream(String)
 */
@Override
public InputStream getInputStream() throws IOException {
  InputStream is = this.servletContext.getResourceAsStream(this.path);
  if (is == null) {
    throw new FileNotFoundException("Could not open " + getDescription());
  }
  return is;
}
origin: Red5/red5-server

/**
 * Returns the context path.
 * 
 * @param rootFile
 * @return context path
 */
private String getContextPath(Resource rootFile) {
  String contextPath = null;
  if (rootFile instanceof ServletContextResource) {
    ServletContextResource servletResource = (ServletContextResource) rootFile;
    contextPath = servletResource.getServletContext().getContextPath();
    if ("/".equals(contextPath)) {
      contextPath = "/root";
    }
  } else if (resources instanceof IScope) {
    contextPath = ((IScope) resources).getContextPath();
    if (contextPath == null) {
      contextPath = "/root";
    }
  }
  log.debug("Persistence context path: {}", contextPath);
  return contextPath;
}
origin: org.alfresco.surf/spring-webscripts

ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + path);
if (resource.exists())
origin: org.alfresco.surf/spring-surf

  public InputStream loadInputStream() throws IOException
  {
    InputStream in = null;
    ServletContextResource resource = new ServletContextResource(servletContext, path);
    {
      if (resource.exists())
      {
        in = resource.getInputStream();
      }
    }
    return in;
  }
}
origin: org.springframework/spring-webmvc

private boolean isResourceUnderLocation(Resource resource, Resource location) throws IOException {
  if (resource.getClass() != location.getClass()) {
    return false;
  }
  String resourcePath;
  String locationPath;
  if (resource instanceof UrlResource) {
    resourcePath = resource.getURL().toExternalForm();
    locationPath = StringUtils.cleanPath(location.getURL().toString());
  }
  else if (resource instanceof ClassPathResource) {
    resourcePath = ((ClassPathResource) resource).getPath();
    locationPath = StringUtils.cleanPath(((ClassPathResource) location).getPath());
  }
  else if (resource instanceof ServletContextResource) {
    resourcePath = ((ServletContextResource) resource).getPath();
    locationPath = StringUtils.cleanPath(((ServletContextResource) location).getPath());
  }
  else {
    resourcePath = resource.getURL().getPath();
    locationPath = StringUtils.cleanPath(location.getURL().getPath());
  }
  if (locationPath.equals(resourcePath)) {
    return true;
  }
  locationPath = (locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/");
  return (resourcePath.startsWith(locationPath) && !isInvalidEncodedPath(resourcePath));
}
origin: spring-projects/spring-framework

/**
 * This implementation delegates to {@code ServletContext.getResource},
 * but throws a FileNotFoundException if no resource found.
 * @see javax.servlet.ServletContext#getResource(String)
 */
@Override
public URL getURL() throws IOException {
  URL url = this.servletContext.getResource(this.path);
  if (url == null) {
    throw new FileNotFoundException(
        getDescription() + " cannot be resolved to URL because it does not exist");
  }
  return url;
}
origin: spring-projects/spring-framework

/**
 * This implementation supports file paths beneath the root of the ServletContext.
 * @see ServletContextResource
 */
@Override
protected Resource getResourceByPath(String path) {
  Assert.state(this.servletContext != null, "No ServletContext available");
  return new ServletContextResource(this.servletContext, path);
}
origin: deas/alfresco

ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + path);
if (resource.exists())
origin: org.springframework/spring-web

/**
 * Overridden version which checks for ServletContextResource
 * and uses {@code ServletContext.getResourcePaths} to find
 * matching resources below the web application root directory.
 * In case of other resources, delegates to the superclass version.
 * @see #doRetrieveMatchingServletContextResources
 * @see ServletContextResource
 * @see javax.servlet.ServletContext#getResourcePaths
 */
@Override
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
    throws IOException {
  if (rootDirResource instanceof ServletContextResource) {
    ServletContextResource scResource = (ServletContextResource) rootDirResource;
    ServletContext sc = scResource.getServletContext();
    String fullPattern = scResource.getPath() + subPattern;
    Set<Resource> result = new LinkedHashSet<>(8);
    doRetrieveMatchingServletContextResources(sc, fullPattern, scResource.getPath(), result);
    return result;
  }
  else {
    return super.doFindPathMatchingFileResources(rootDirResource, subPattern);
  }
}
origin: spring-projects/spring-framework

@Test
public void testServletContextResourcePatternResolverWithAbsolutePaths() throws IOException {
  final Set<String> paths = new HashSet<>();
  paths.add("C:/webroot/WEB-INF/context1.xml");
  paths.add("C:/webroot/WEB-INF/context2.xml");
  paths.add("C:/webroot/someOtherDirThatDoesntContainPath");
  MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
    @Override
    public Set<String> getResourcePaths(String path) {
      if ("/WEB-INF/".equals(path)) {
        return paths;
      }
      return null;
    }
  };
  ServletContextResourcePatternResolver rpr = new ServletContextResourcePatternResolver(sc);
  Resource[] found = rpr.getResources("/WEB-INF/*.xml");
  Set<String> foundPaths = new HashSet<>();
  for (Resource resource : found) {
    foundPaths.add(((ServletContextResource) resource).getPath());
  }
  assertEquals(2, foundPaths.size());
  assertTrue(foundPaths.contains("/WEB-INF/context1.xml"));
  assertTrue(foundPaths.contains("/WEB-INF/context2.xml"));
}
origin: org.springframework/spring-web

/**
 * This implementation delegates to {@code ServletContext.getResourceAsStream},
 * but throws a FileNotFoundException if no resource found.
 * @see javax.servlet.ServletContext#getResourceAsStream(String)
 */
@Override
public InputStream getInputStream() throws IOException {
  InputStream is = this.servletContext.getResourceAsStream(this.path);
  if (is == null) {
    throw new FileNotFoundException("Could not open " + getDescription());
  }
  return is;
}
origin: spring-projects/spring-framework

/**
 * This implementation supports file paths beneath the root of the ServletContext.
 * @see ServletContextResource
 */
@Override
protected Resource getResourceByPath(String path) {
  Assert.state(this.servletContext != null, "No ServletContext available");
  return new ServletContextResource(this.servletContext, path);
}
origin: org.alfresco.surf/spring-surf

ServletContextResource resource = new ServletContextResource(this.servletContext, p);
  if (resource.exists())
org.springframework.web.context.supportServletContextResource

Javadoc

org.springframework.core.io.Resource implementation for javax.servlet.ServletContext resources, interpreting relative paths within the web application root directory.

Always supports stream access and URL access, but only allows java.io.File access when the web application archive is expanded.

Most used methods

  • <init>
    Create a new ServletContextResource.The Servlet spec requires that resource paths start with a slash
  • getPath
    Return the path for this resource.
  • exists
    This implementation checks ServletContext.getResource.
  • getServletContext
    Return the ServletContext for this resource.
  • getDescription
    This implementation returns a description that includes the ServletContext resource location.
  • getInputStream
    This implementation delegates to ServletContext.getResourceAsStream, but throws a FileNotFoundExcept
  • getPathWithinContext
  • getFile
    This implementation resolves "file:" URLs or alternatively delegates to ServletContext.getRealPath,
  • lastModified

Popular in Java

  • Reading from database using SQL prepared statement
  • findViewById (Activity)
  • setScale (BigDecimal)
  • addToBackStack (FragmentTransaction)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now