private List<VcmFileData> getFiles(File directory, String outputPath) throws IOException, ZipException { ArrayList<VcmFileData> list = new ArrayList<VcmFileData>(); for (File file : directory.listFiles( (FileFilter) FileFilterUtils.suffixFileFilter("vcm", IOCase.INSENSITIVE))) { log.debug(String.format("Opening %s", file.getCanonicalPath())); File destFile = new File(outputPath, file.getName()); String relativePath = destFile .getCanonicalPath() .substring(new File(outputRootPath).getCanonicalPath().length() + 1); relativePath = StringUtils.replace(FilenameUtils.getPath(relativePath), "\\", "/"); VcmFileData vcmFile = new VcmFileData(file, relativePath); list.add(vcmFile); log.debug(String.format("Generating thumbnail for %s", file.getCanonicalPath())); createThumbnail(vcmFile.getModel(), new File(outputPath, vcmFile.getThumbnailName())); log.debug(String.format("Copying %s", file.getCanonicalPath())); FileUtils.copyFile(file, destFile); } return list; }
private void createSourceListFile(List<VcmFileData> result) throws IOException { log.debug("Creating sourcelist.xml"); long totalSize = 0; for (VcmFileData vcmFileData : result) { totalSize += vcmFileData.getFileSize(); } VelocityContext velocityContext = new VelocityContext(velocityToolManager.createContext()); velocityContext.put("totalSize", totalSize); velocityContext.put("baseURL", baseUrl); velocityContext.put("name", eCatName); velocityContext.put("description", eCatDescription); velocityContext.put("author", eCatAuthor); velocityContext.put("ecaturl", eCatUrl); velocityContext.put("guid", eCatGuid); OutputStreamWriter writer = null; try { writer = new OutputStreamWriter( new FileOutputStream(new File(outputRootPath, "sourcelist.xml")), "UTF-8"); velocitySourceListTemplate.merge(velocityContext, writer); } finally { IOUtils.closeQuietly(writer); } }