/** * Internal method used by the {@link #addResourcesFromDirectory(String, URL)} to process 'file' protocol. * * @param resource * source directory. * @param baseDirectory * target virtual directory. */ protected void addResourcesFromFile(String resourcePath, URL resource) { File file = new File(resource.getPath()); if (!file.isDirectory()) { file = file.getParentFile(); } try { addFiles(resourcePath, file); } catch (MalformedURLException e) { throw new TestException(e); } }
/** * Internal method used by the {@link #addResourcesFromDirectory(String, URL)} to process 'file' protocol. * * @param resource * source directory. * @param baseDirectory * target virtual directory. */ protected void addResourcesFromFile(String resourcePath, URL resource) { File file = new File(resource.getPath()); if (!file.isDirectory()) { file = file.getParentFile(); } try { addFiles(resourcePath, file); } catch (MalformedURLException e) { throw new TestException(e); } }
/** * Internal reccursive method process directory content and all subdirectories. * * @param baseDirectory * @param file * @throws MalformedURLException */ protected void addFiles(String resourcePath, File file) throws MalformedURLException { File[] files = file.listFiles(); for (File subfile : files) { if (!subfile.isDirectory()) { addResource(resourcePath + "/" + subfile.getName(), subfile.toURI().toURL()); } else { String directoryPath = resourcePath + "/" + subfile.getName(); addDirectory(directoryPath); addFiles(directoryPath, subfile); } } }
/** * Internal reccursive method process directory content and all subdirectories. * * @param baseDirectory * @param file * @throws MalformedURLException */ protected void addFiles(String resourcePath, File file) throws MalformedURLException { File[] files = file.listFiles(); for (File subfile : files) { if (!subfile.isDirectory()) { addResource(resourcePath + "/" + subfile.getName(), subfile.toURI().toURL()); } else { String directoryPath = resourcePath + "/" + subfile.getName(); addDirectory(directoryPath); addFiles(directoryPath, subfile); } } }
/** * Add all files from the directory to the virtual web application content. * * @param path * name of the target directory in the virtual web application. If no such directory exists, it will be * created, as well as all parent directories as needed. * @param resource * {@code File} of the source directory or any file in the source directory. If this parameter points to * a file, it will be converted to a enclosing directory. */ public void addResourcesFromDirectory(String path, File directory) { if (!directory.exists()) { throw new TestException("directory does not exist:" + directory.getAbsolutePath()); } try { addFiles(path, directory); } catch (MalformedURLException e) { throw new TestException(e); } }
/** * Add all files from the directory to the virtual web application content. * * @param path * name of the target directory in the virtual web application. If no such directory exists, it will be * created, as well as all parent directories as needed. * @param resource * {@code File} of the source directory or any file in the source directory. If this parameter points to * a file, it will be converted to a enclosing directory. */ public void addResourcesFromDirectory(String path, File directory) { if (!directory.exists()) { throw new TestException("directory does not exist:" + directory.getAbsolutePath()); } try { addFiles(path, directory); } catch (MalformedURLException e) { throw new TestException(e); } }