Skip to content

Commit

Permalink
filter special characters when exporting documents. issue #2207.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 23, 2023
1 parent 5635eaa commit 5d6bc97
Showing 1 changed file with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand All @@ -796,15 +796,15 @@ public String exportReviews() throws Exception {
excelStr.append(CELL_BREAK);
excelStr.append(escape(rev.getArchiveFileKey().getCustom3()));
excelStr.append(CELL_BREAK);
Collection<ArchiveFileTagsBean> tags=this.caseFacade.getTagsUnrestricted(rev.getArchiveFileKey().getId());
StringBuilder tagBuffer=new StringBuilder();
for(ArchiveFileTagsBean tag: tags) {
Collection<ArchiveFileTagsBean> 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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5d6bc97

Please sign in to comment.