From 5d6bc97b7e5a154f57ded1a758b0571565ea14fb Mon Sep 17 00:00:00 2001 From: j-dimension Date: Thu, 23 Nov 2023 11:33:44 +0100 Subject: [PATCH] filter special characters when exporting documents. issue #2207. --- .../jdimension/jlawyer/export/HTMLExport.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/export/HTMLExport.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/export/HTMLExport.java index 9ca7d014e..00bad82be 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/export/HTMLExport.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/export/HTMLExport.java @@ -713,7 +713,7 @@ public class HTMLExport { public HTMLExport(File targetDirectory, ArchiveFileServiceLocal caseFacade, CalendarServiceLocal calendarFacade) { this.targetDirectory = targetDirectory; this.caseFacade = caseFacade; - this.calendarFacade=calendarFacade; + this.calendarFacade = calendarFacade; } public File getExportFolderName(ArchiveFileBean dto) { @@ -784,7 +784,7 @@ public String exportReviews() throws Exception { excelStr.append(CELL_BREAK); excelStr.append(escape(rev.getSummary())); excelStr.append(CELL_BREAK); - if(rev.getArchiveFileKey().getArchivedBoolean()) { + if (rev.getArchiveFileKey().getArchivedBoolean()) { excelStr.append("ja"); } else { excelStr.append("nein"); @@ -796,15 +796,15 @@ public String exportReviews() throws Exception { excelStr.append(CELL_BREAK); excelStr.append(escape(rev.getArchiveFileKey().getCustom3())); excelStr.append(CELL_BREAK); - Collection tags=this.caseFacade.getTagsUnrestricted(rev.getArchiveFileKey().getId()); - StringBuilder tagBuffer=new StringBuilder(); - for(ArchiveFileTagsBean tag: tags) { + Collection tags = this.caseFacade.getTagsUnrestricted(rev.getArchiveFileKey().getId()); + StringBuilder tagBuffer = new StringBuilder(); + for (ArchiveFileTagsBean tag : tags) { tagBuffer.append(tag); tagBuffer.append(" / "); } - String tagString=tagBuffer.toString(); - if(tagString.endsWith(" / ")) { - tagString=tagString.substring(0, tagString.length()-3); + String tagString = tagBuffer.toString(); + if (tagString.endsWith(" / ")) { + tagString = tagString.substring(0, tagString.length() - 3); } excelStr.append(escape(tagString)); excelStr.append(LINE_BREAK); @@ -866,7 +866,7 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { Collection documents = null; Collection parties = null; Collection reviews = null; - + history = caseFacade.getHistoryForArchiveFileUnrestricted(dto.getId()); parties = caseFacade.getInvolvementDetailsForCaseUnrestricted(dto.getId()); reviews = calendarFacade.getReviewsUnrestricted(dto.getId()); @@ -918,6 +918,30 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { String dbNewName = removeSonderzeichen(db.getName()); + dbNewName = dbNewName.replaceAll(",", ""); + dbNewName = dbNewName.replaceAll("\"", ""); + dbNewName = dbNewName.replaceAll("ยง", ""); + dbNewName = dbNewName.replaceAll("%", ""); + dbNewName = dbNewName.replaceAll("&", ""); + dbNewName = dbNewName.replaceAll("/", ""); + dbNewName = dbNewName.replaceAll("=", ""); + dbNewName = dbNewName.replaceAll("\\?", ""); + dbNewName = dbNewName.replaceAll("\\{", ""); + dbNewName = dbNewName.replaceAll("\\}", ""); + dbNewName = dbNewName.replaceAll("\\[", ""); + dbNewName = dbNewName.replaceAll("\\]", ""); + dbNewName = dbNewName.replaceAll("\\\\", ""); + dbNewName = dbNewName.replaceAll("\\*", ""); + dbNewName = dbNewName.replaceAll("#", ""); + dbNewName = dbNewName.replaceAll("'", ""); + dbNewName = dbNewName.replaceAll(":", ""); + dbNewName = dbNewName.replaceAll(";", ""); + + if(dbNewName.length()==0) { + log.warn("invalid file name: " + dbNewName); + dbNewName=""+System.currentTimeMillis(); + } + try { byte[] docContent = caseFacade.getDocumentContentUnrestricted(db.getId()); try (FileOutputStream docOut = new FileOutputStream(newDir3.getAbsolutePath() + System.getProperty("file.separator") + dbNewName)) { @@ -979,8 +1003,7 @@ private String toDate(SimpleDateFormat dateFormat, Date d) { } public void zipDirectory(String dirToZip, String targetFile) throws Exception { - try (FileOutputStream fos = new FileOutputStream(targetFile); - ZipOutputStream zos = new ZipOutputStream(fos)) { + try (FileOutputStream fos = new FileOutputStream(targetFile); ZipOutputStream zos = new ZipOutputStream(fos)) { addDirToZipArchive(zos, new File(dirToZip), null); zos.flush(); fos.flush(); @@ -1055,8 +1078,7 @@ private String getPartiesList(Collection parties) { } private void copyToLocal(String resource, String name, File dir, String subDir) throws Exception { - try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource); - FileOutputStream fOut = new FileOutputStream(dir.getAbsolutePath() + System.getProperty("file.separator") + subDir + name);) { + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource); FileOutputStream fOut = new FileOutputStream(dir.getAbsolutePath() + System.getProperty("file.separator") + subDir + name);) { byte[] buffer = new byte[256]; int len = 0; while ((len = is.read(buffer)) > 0) {