public ExportReport export(ResourcesWrapper resource) throws QuestionReplyException, ParseException { StringBuilder sb = new StringBuilder("exportFAQ"); Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH'H'mm'm'ss's'"); String dateFormatee = dateFormat.format(date); sb.append("_").append(dateFormatee); sb.append("_").append(getUserDetail().getId()); ExportReport exportReport = new ExportReport(); // Stockage de la date de démarage de l'export dans l'objet rapport exportReport.setDateDebut(new Date()); String thisExportDir = sb.toString(); // Création du dossier d'export exportFAQ_aaaa-mm-jj-hhHmmmsss_userId.zip String tempDir = FileRepositoryManager.getTemporaryPath(); File fileExportDir = new File(tempDir + thisExportDir); if (!fileExportDir.exists()) { try { FileFolderManager.createFolder(fileExportDir); } catch (UtilException ex) { throw new QuestionReplyException( "QuestionReplySessionController.export()", SilverpeasRuntimeException.ERROR, "root.MSG_FOLDER_NOT_CREATE", ex); } } // création du dossier "files" String dir = tempDir + thisExportDir; String nameForFiles = "files"; File forFiles = new File(dir + File.separator + nameForFiles); try { FileFolderManager.createFolder(forFiles); } catch (UtilException ex) { throw new QuestionReplyException( "QuestionReplySessionController.export()", SilverpeasRuntimeException.ERROR, "root.MSG_FOLDER_NOT_CREATE", ex); } // intégrer la css du disque dans "files" ResourceLocator settings = new ResourceLocator("com.silverpeas.questionReply.settings.questionReplySettings", ""); try { String chemin = (settings.getString("mappingDir")); if (chemin.startsWith("file:")) { chemin = chemin.substring(8); } Collection<File> files = FileFolderManager.getAllFile(chemin); for (File file : files) { File newFile = new File(dir + File.separator + nameForFiles + File.separator + file.getName()); FileRepositoryManager.copyFile(file.getPath(), newFile.getPath()); } } catch (Exception ex) { throw new QuestionReplyException( "QuestionReplySessionController.export()", SilverpeasRuntimeException.ERROR, "QuestionReply.EX_CANT_COPY_FILE", ex); } // création du fichier html File fileHTML = new File(dir + File.separator + thisExportDir + ".html"); FileWriter fileWriter = null; try { fileHTML.createNewFile(); fileWriter = new FileWriter(fileHTML.getPath()); fileWriter.write(toHTML(fileHTML, resource)); } catch (IOException ex) { throw new QuestionReplyException( "QuestionReplySessioncontroller.export()", SilverpeasRuntimeException.ERROR, "QuestionReply.MSG_CAN_WRITE_FILE", ex); } finally { try { fileWriter.close(); } catch (Exception ex) { } } // Création du zip try { String zipFileName = fileExportDir.getName() + ".zip"; long zipFileSize = ZipManager.compressPathToZip(fileExportDir.getPath(), tempDir + zipFileName); exportReport.setZipFileName(zipFileName); exportReport.setZipFileSize(zipFileSize); exportReport.setZipFilePath(FileServerUtils.getUrlToTempDir(zipFileName)); } catch (Exception ex) { throw new QuestionReplyException( "QuestionReplySessioncontroller.export()", SilverpeasRuntimeException.ERROR, "QuestionReply.MSG_CAN_CREATE_ZIP", ex); } // Stockage de la date de fin de l'export dans l'objet rapport exportReport.setDateFin(new Date()); return exportReport; }