@Override public Set<String> getResourcePaths(String path) { File root = getWebApplication().getResourceFile(path); Set<String> paths = new TreeSet<String>(); File[] files = root.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { paths.add(path + file.getName() + "/"); } else { paths.add(path + file.getName()); } } } return paths; }
@Override public Set<String> getResourcePaths(String path) { File root = getWebApplication().getResourceFile(path); Set<String> paths = new TreeSet<String>(); File[] files = root.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { paths.add(path + file.getName() + "/"); } else { paths.add(path + file.getName()); } } } return paths; }
/** * Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of * whatever file on the server's filesystem would be served by a request for "/index.html". * * The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, * including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for * any reason (such as when the content is being made available from a .war archive). **/ public String getRealPath( String path ) { return _application.getResourceFile( path ).getAbsolutePath(); }
/** * Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of * whatever file on the server's filesystem would be served by a request for "/index.html". * * The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, * including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for * any reason (such as when the content is being made available from a .war archive). **/ public String getRealPath( String path ) { return _application.getResourceFile( path ).getAbsolutePath(); }
/** * Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of * whatever file on the server's filesystem would be served by a request for "/index.html". * * The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, * including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for * any reason (such as when the content is being made available from a .war archive). **/ public String getRealPath( String path ) { return _application.getResourceFile( path ).getAbsolutePath(); }
/** * Returns the resource located at the named path as an InputStream object. * * The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. * This method returns null if no resource exists at the specified path. * Meta-information such as content length and content type that is available via getResource method is lost when using this method. * The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource. * This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet * containers to make a resource available to a servlet from any location, without using a class loader. **/ public java.io.InputStream getResourceAsStream( String path ) { try { File resourceFile = _application.getResourceFile( path ); return resourceFile == null ? null : new FileInputStream( resourceFile ); } catch (FileNotFoundException e) { return null; } }
/** * Returns the resource located at the named path as an InputStream object. * * The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. * This method returns null if no resource exists at the specified path. * Meta-information such as content length and content type that is available via getResource method is lost when using this method. * The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource. * This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet * containers to make a resource available to a servlet from any location, without using a class loader. **/ public java.io.InputStream getResourceAsStream( String path ) { try { File resourceFile = _application.getResourceFile( path ); return resourceFile == null ? null : new FileInputStream( resourceFile ); } catch (FileNotFoundException e) { return null; } }
/** * Returns the resource located at the named path as an InputStream object. * * The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. * This method returns null if no resource exists at the specified path. * Meta-information such as content length and content type that is available via getResource method is lost when using this method. * The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource. * This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet * containers to make a resource available to a servlet from any location, without using a class loader. **/ public java.io.InputStream getResourceAsStream( String path ) { try { File resourceFile = _application.getResourceFile( path ); return resourceFile == null ? null : new FileInputStream( resourceFile ); } catch (FileNotFoundException e) { return null; } }
/** * Returns a URL to the resource that is mapped to a specified path. The path must begin * with a "/" and is interpreted as relative to the current context root. * <p> * This method allows the servlet container to make a resource available to servlets from any source. * Resources can be located on a local or remote file system, in a database, or in a .war file. * <p> * The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. * <p> * This method returns null if no resource is mapped to the pathname. * * Some containers may allow writing to the URL returned by this method using the methods of the URL class. * * The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a * RequestDispatcher instead to include results of an execution. * * This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This * method does not use class loaders. **/ public java.net.URL getResource( String path ) { try { File resourceFile = _application.getResourceFile( path ); // PATCH proposal [ 1592532 ] Invalid ServletUnitServletContext#getResource(String path) // by Timo Westkmper // return !resourceFile.exists() ? null : resourceFile.toURL(); return resourceFile == null ? null : resourceFile.toURL(); } catch (MalformedURLException e) { return null; } }
/** * Returns a URL to the resource that is mapped to a specified path. The path must begin * with a "/" and is interpreted as relative to the current context root. * <p> * This method allows the servlet container to make a resource available to servlets from any source. * Resources can be located on a local or remote file system, in a database, or in a .war file. * <p> * The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. * <p> * This method returns null if no resource is mapped to the pathname. * * Some containers may allow writing to the URL returned by this method using the methods of the URL class. * * The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a * RequestDispatcher instead to include results of an execution. * * This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This * method does not use class loaders. **/ public java.net.URL getResource( String path ) { try { File resourceFile = _application.getResourceFile( path ); // PATCH proposal [ 1592532 ] Invalid ServletUnitServletContext#getResource(String path) // by Timo Westkmper // return !resourceFile.exists() ? null : resourceFile.toURL(); return resourceFile == null ? null : resourceFile.toURL(); } catch (MalformedURLException e) { return null; } }
/** * Returns a URL to the resource that is mapped to a specified path. The path must begin * with a "/" and is interpreted as relative to the current context root. * <p> * This method allows the servlet container to make a resource available to servlets from any source. * Resources can be located on a local or remote file system, in a database, or in a .war file. * <p> * The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. * <p> * This method returns null if no resource is mapped to the pathname. * * Some containers may allow writing to the URL returned by this method using the methods of the URL class. * * The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a * RequestDispatcher instead to include results of an execution. * * This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This * method does not use class loaders. **/ public java.net.URL getResource( String path ) { try { File resourceFile = _application.getResourceFile( path ); // PATCH proposal [ 1592532 ] Invalid ServletUnitServletContext#getResource(String path) // by Timo Westkmper // return !resourceFile.exists() ? null : resourceFile.toURL(); return resourceFile == null ? null : resourceFile.toURL(); } catch (MalformedURLException e) { return null; } }