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 b2ade3570..2151ae222 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 @@ -687,6 +687,8 @@ import java.nio.file.attribute.FileTime; import java.text.NumberFormat; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.log4j.Logger; @@ -725,7 +727,7 @@ public File getExportFolderName(ArchiveFileBean dto) { afs = dto.getId(); } afs = ServerStringUtils.removeSonderzeichen(afs); - File newDir = new File(this.targetDirectory.getAbsolutePath() + System.getProperty("file.separator") + afs); + File newDir = new File(this.targetDirectory.getAbsolutePath() + File.separator + afs); return newDir; } @@ -743,7 +745,7 @@ public String exportReviews() throws Exception { this.targetDirectory.mkdirs(); } - File revCsv = new File(this.targetDirectory.getAbsolutePath() + System.getProperty("file.separator") + "wiedervorlagen-fristen.csv"); + File revCsv = new File(this.targetDirectory.getAbsolutePath() + File.separator + "wiedervorlagen-fristen.csv"); if (revCsv.exists()) { revCsv.delete(); } @@ -831,7 +833,7 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { copyToLocal("templates/exporthtml/index.html", "index.html", newDir, ""); copyToLocal("templates/exporthtml/j-lawyer_style.css", "j-lawyer_style.css", newDir, ""); - File newDir2 = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "images"); + File newDir2 = new File(newDir.getAbsolutePath() + File.separator + "images"); newDir2.mkdirs(); copyToLocal("templates/exporthtml/images/j-lawyer_body.jpg", "j-lawyer_body.jpg", newDir, "images/"); @@ -842,10 +844,7 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { copyToLocal("templates/exporthtml/images/j-lawyer_menu_hover.jpg", "j-lawyer_menu_hover.jpg", newDir, "images/"); copyToLocal("templates/exporthtml/images/j-lawyer_sidebar_section_bottom.jpg", "j-lawyer_sidebar_section_bottom.jpg", newDir, "images/"); - File newDir3 = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "documents"); - newDir3.mkdirs(); - - File indexFile = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "index.html"); + File indexFile = new File(newDir.getAbsolutePath() + File.separator + "index.html"); byte[] content = ServerFileUtils.readFile(indexFile); String sContent = new String(content, "UTF-8"); sContent = sContent.replaceAll("\\{\\{filenumber\\}\\}", dto.getFileNumber()); @@ -912,42 +911,38 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { ArrayList docList = new ArrayList(documents); Collections.sort(docList, new DocumentsComparator()); sb = new StringBuffer(); + HashMap> folderHierarchies=new HashMap<>(); for (Object d : docList) { if (d instanceof ArchiveFileDocumentsBean) { ArchiveFileDocumentsBean db = (ArchiveFileDocumentsBean) d; String dbNewName = removeSonderzeichen(db.getName()); - - dbNewName = dbNewName.replace(",", ""); - dbNewName = dbNewName.replace("\"", ""); - dbNewName = dbNewName.replace("ยง", ""); - dbNewName = dbNewName.replace("%", ""); - dbNewName = dbNewName.replace("&", ""); - dbNewName = dbNewName.replace("/", ""); - dbNewName = dbNewName.replace("=", ""); - dbNewName = dbNewName.replace("\\?", ""); - dbNewName = dbNewName.replace("\\{", ""); - dbNewName = dbNewName.replace("\\}", ""); - dbNewName = dbNewName.replace("\\[", ""); - dbNewName = dbNewName.replace("\\]", ""); - dbNewName = dbNewName.replace("\\\\", ""); - dbNewName = dbNewName.replace("\\*", ""); - dbNewName = dbNewName.replace("#", ""); - dbNewName = dbNewName.replace("'", ""); - dbNewName = dbNewName.replace(":", ""); - dbNewName = dbNewName.replace(";", ""); + dbNewName=ServerFileUtils.sanitizeFileName(dbNewName); if(dbNewName.length()==0) { log.warn("invalid file name: " + dbNewName); dbNewName=""+System.currentTimeMillis(); } + + + List hierarchy = new ArrayList<>(); + if (db.getFolder() != null) { + if(!folderHierarchies.containsKey(db.getFolder().getId())) { + hierarchy=caseFacade.getFolderHierarchy(db.getFolder().getId()); + folderHierarchies.put(db.getFolder().getId(), hierarchy); + } + hierarchy=folderHierarchies.get(db.getFolder().getId()); + } + String subPath=toFilePath(hierarchy); try { byte[] docContent = caseFacade.getDocumentContentUnrestricted(db.getId()); - try (FileOutputStream docOut = new FileOutputStream(newDir3.getAbsolutePath() + System.getProperty("file.separator") + dbNewName)) { + File docFolders=new File(newDir.getAbsolutePath() + subPath); + docFolders.mkdirs(); + try (FileOutputStream docOut = new FileOutputStream(newDir.getAbsolutePath() + subPath + File.separator + dbNewName)) { docOut.write(docContent); } - File docOutFile = new File(newDir3.getAbsolutePath() + System.getProperty("file.separator") + dbNewName); + File docOutFile = new File(newDir.getAbsolutePath() + subPath + File.separator + dbNewName); if (db.getChangeDate() != null) { docOutFile.setLastModified(db.getChangeDate().getTime()); } @@ -957,9 +952,16 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { } // + + sb.append("

"); sb.append(toDate(df, db.getChangeDate())); - sb.append("

1) + subPath=subPath.substring(1); + sb.append("

"); sb.append(dbNewName); @@ -967,14 +969,10 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { if (db.getDictateSign() != null) { sb.append(db.getDictateSign()); } - sb.append("

"); - sb.append("

"); - if (db.getFolder() != null) { - sb.append("Ordner: ").append(removeSonderzeichen(db.getFolder().getName())); - } else { - sb.append(""); - } - sb.append("

"); + sb.append("

"); + sb.append("

"); + sb.append(toFolderPath(hierarchy)); + sb.append("

"); sb.append(""); } } @@ -993,6 +991,28 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception { return newDir.getAbsolutePath(); } + + private String toFolderPath(List hierarchy) { + StringBuilder sb=new StringBuilder(); + for(CaseFolder f: hierarchy) { + sb.append(" > ").append(f.getName()); + } + String path=sb.toString().trim(); + if(path.isEmpty()) + path=">"; + return path; + } + + private String toFilePath(List hierarchy) { + StringBuilder sb=new StringBuilder(); + for(CaseFolder f: hierarchy) { + String fName=ServerFileUtils.sanitizeFileName(f.getName()); + if(fName.isEmpty()) + fName="---"; + sb.append(File.separator).append(fName); + } + return sb.toString(); + } private String toDate(SimpleDateFormat dateFormat, Date d) { if (d == null) { @@ -1078,7 +1098,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() + File.separator + subDir + name);) { byte[] buffer = new byte[256]; int len = 0; while ((len = is.read(buffer)) > 0) { diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileService.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileService.java index 9c108a803..130306ad9 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileService.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileService.java @@ -4559,6 +4559,31 @@ public CaseFolder applyFolderTemplateById(String caseId, String templateId) thro public DocumentFolderTemplate getFolderTemplateById(String id) { return this.folderTemplateFacade.find(id); } + + /** + * Returns a list of folder representing a hierarchy. First element in the list is the root folder. + * @param folderId + * @return + */ + @Override + @RolesAllowed({"loginRole"}) + public List getFolderHierarchy(String folderId) { + List hierarchy=new ArrayList<>(); + if(folderId==null) + return hierarchy; + + CaseFolder cf=this.caseFolderFacade.find(folderId); + if(cf!=null) { + hierarchy.add(cf); + while(!cf.isRoot()) { + cf=this.caseFolderFacade.find(cf.getParentId()); + hierarchy.add(cf); + + } + } + Collections.reverse(hierarchy); + return hierarchy; + } @Override @RolesAllowed({"readArchiveFileRole"}) diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileServiceLocal.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileServiceLocal.java index a68513c1e..e05723d76 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileServiceLocal.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/ArchiveFileServiceLocal.java @@ -791,6 +791,8 @@ public interface ArchiveFileServiceLocal { CaseFolder applyFolderTemplateById(String id, String templateId) throws Exception; DocumentFolderTemplate getFolderTemplateById(String id); + + List getFolderHierarchy(String folderId); void purgeDocumentBin() throws Exception; diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/templates/exporthtml/j-lawyer_style.css b/j-lawyer-server/j-lawyer-server-ejb/src/java/templates/exporthtml/j-lawyer_style.css index 6fc288ad4..7a0b60d84 100755 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/templates/exporthtml/j-lawyer_style.css +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/templates/exporthtml/j-lawyer_style.css @@ -242,6 +242,12 @@ h3 { font-weight: normal; } +.content_box .folder_info { + font-size: 9px; + color: #666666; + font-weight: bold; +} + .news_box a{ color: #000000; font-weight: normal;