Skip to content

Commit

Permalink
close zipFile after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed May 1, 2024
1 parent 78bde52 commit 64d42fc
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public int countPages(File input, String filename) {
}

int pages = 1;
ZipUtil zipUtil = new ZipUtil();
try (InputStream is = zipUtil.getEntryStream(input, "meta.xml")) {

try (ZipUtil zipUtil = new ZipUtil(); InputStream is = zipUtil.getEntryStream(input, "meta.xml")) {
OpenOfficeMetadataHandler metadataHandler = new OpenOfficeMetadataHandler();
xmlReader.setContentHandler(metadataHandler);
xmlReader.parse(new InputSource(is));
Expand All @@ -250,7 +250,7 @@ public int countPages(File input, String filename) {
log.warn("Failed to extract OpenOffice meta.xml entry", t);
}

try (InputStream is = zipUtil.getEntryStream(input, "content.xml")) {
try (ZipUtil zipUtil = new ZipUtil(); InputStream is = zipUtil.getEntryStream(input, "content.xml")) {
OpenOfficePresentationMetadataHandler metadataHandler = new OpenOfficePresentationMetadataHandler();
xmlReader.setContentHandler(metadataHandler);
xmlReader.parse(new InputSource(is));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,46 @@ private void extractEntries(File sourceZipFile, Folder parent, String sessionId)
DocumentManager docManager = (DocumentManager) Context.get().getBean(DocumentManager.class);

// Open the Zip and list all the contents
ZipUtil zipUtil = new ZipUtil();
zipUtil.setFileNameCharset(fileNameCharset);
List<String> entries = zipUtil.listEntries(sourceZipFile);

for (String entry : entries) {
String fileName = FileUtil.getName(entry);
String title = FileUtil.getBaseName(fileName);

if (StringUtils.isEmpty(fileName) || StringUtils.isEmpty(title))
continue;

String relativePath = FileUtil.getPath(entry);
if (relativePath.startsWith("/"))
relativePath = relativePath.substring(1);
if (relativePath.endsWith("/"))
relativePath = relativePath.substring(0, relativePath.length() - 1);

// Ensure to have the proper folder to upload the file into
FolderHistory folderTransaction = new FolderHistory();
folderTransaction.setSessionId(sessionId);
folderTransaction.setUser(user);
Folder folder = fDao.createPath(parent, relativePath, true, folderTransaction);

// Create the document
Document doc = new Document(docVo);
doc.setId(0L);
doc.setFileName(fileName);
doc.setFolder(folder);

DocumentHistory history = new DocumentHistory();
history.setEvent(DocumentEvent.STORED.toString());
history.setComment("");
history.setUser(user);
history.setSessionId(sessionId);

try {
docManager.create(zipUtil.getEntryStream(sourceZipFile, entry), doc, history);
} catch (Exception e) {
logger.warn("InMemoryZipImport unable to import ZIP entry {}", entry, e);
try (ZipUtil zipUtil = new ZipUtil();) {
zipUtil.setFileNameCharset(fileNameCharset);
List<String> entries = zipUtil.listEntries(sourceZipFile);

for (String entry : entries) {
String fileName = FileUtil.getName(entry);
String title = FileUtil.getBaseName(fileName);

if (StringUtils.isEmpty(fileName) || StringUtils.isEmpty(title))
continue;

String relativePath = FileUtil.getPath(entry);
if (relativePath.startsWith("/"))
relativePath = relativePath.substring(1);
if (relativePath.endsWith("/"))
relativePath = relativePath.substring(0, relativePath.length() - 1);

// Ensure to have the proper folder to upload the file into
FolderHistory folderTransaction = new FolderHistory();
folderTransaction.setSessionId(sessionId);
folderTransaction.setUser(user);
Folder folder = fDao.createPath(parent, relativePath, true, folderTransaction);

// Create the document
Document doc = new Document(docVo);
doc.setId(0L);
doc.setFileName(fileName);
doc.setFolder(folder);

DocumentHistory history = new DocumentHistory();
history.setEvent(DocumentEvent.STORED.toString());
history.setComment("");
history.setUser(user);
history.setSessionId(sessionId);

try {
docManager.create(zipUtil.getEntryStream(sourceZipFile, entry), doc, history);
} catch (Exception e) {
logger.warn("InMemoryZipImport unable to import ZIP entry {}", entry, e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import com.logicaldoc.gui.common.client.widgets.grid.FileSizeListGridField;
import com.logicaldoc.gui.frontend.client.services.UpdateService;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ContentsType;
import com.smartgwt.client.types.ExpansionMode;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Progressbar;
Expand All @@ -42,7 +44,6 @@
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.CellContextClickEvent;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.menu.Menu;
Expand Down Expand Up @@ -162,9 +163,9 @@ protected String getCellCSSText(ListGridRecord rec, int rowNum, int colNum) {
list.setDetailField(DESCRIPTION);
list.setFields(id, name, rating, date, size, installed, restart, file, local);

list.addCellContextClickHandler((CellContextClickEvent event) -> {
list.addCellContextClickHandler(contextClick -> {
showContextMenu(list);
event.cancel();
contextClick.cancel();
});

List<ListGridRecord> records = new ArrayList<>();
Expand Down Expand Up @@ -193,7 +194,7 @@ protected String getCellCSSText(ListGridRecord rec, int rowNum, int colNum) {
addMember(listPanel);

upload.setAutoFit(true);
upload.addClickHandler(event -> new PatchUploader(this).show());
upload.addClickHandler(click -> new PatchUploader(this).show());
}

private void switchDetailView(GUIPatch patch) {
Expand Down Expand Up @@ -341,44 +342,43 @@ private VLayout prepareActionBar(GUIPatch patch) {
bar.setPercentDone(0);
download.setDisabled(true);

UpdateService.Instance.get().downloadPatch(patch.getId(), fileName, patch.getSize(),
new AsyncCallback<>() {
UpdateService.Instance.get().downloadPatch(patch.getId(), fileName, patch.getSize(), new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
download.setDisabled(false);
}
@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
download.setDisabled(false);
}

@Override
public void onSuccess(Void arg) {
confirmPatch.setVisible(false);

new Timer() {
public void run() {
UpdateService.Instance.get().checkDownloadStatus(new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
}

@Override
public void onSuccess(List<Integer> status) {
bar.setPercentDone(status.get(1));

@Override
public void onSuccess(Void arg) {
confirmPatch.setVisible(false);

new Timer() {
public void run() {
UpdateService.Instance.get().checkDownloadStatus(new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
}

@Override
public void onSuccess(List<Integer> status) {
bar.setPercentDone(status.get(1));

if (status.get(1) == 100) {
download.setDisabled(false);
confirmPatch.setVisible(true);
displayNotes(fileName);
} else
schedule(50);
}
});
if (status.get(1) == 100) {
download.setDisabled(false);
confirmPatch.setVisible(true);
displayNotes(fileName);
} else
schedule(50);
}
}.schedule(50);
});
}
});
}.schedule(50);
}
});
});

HLayout buttonCanvas = new HLayout();
Expand All @@ -403,22 +403,49 @@ public void onFailure(Throwable caught) {

@Override
public void onSuccess(List<String> infos) {
DynamicForm form = new DynamicForm();
form.setTitleOrientation(TitleOrientation.TOP);
form.setColWidths("*");
form.setNumCols(1);

TextAreaItem changelog = ItemFactory.newTextAreaItem("changelog", infos.get(0));
changelog.setWidth("100%");
changelog.setHeight(220);

TextAreaItem patchNotes = ItemFactory.newTextAreaItem("patchnotes", infos.get(1));
patchNotes.setWidth("100%");
patchNotes.setHeight(220);

form.setItems(patchNotes, changelog);

notesPanel.addMember(form);
VLayout panel = new VLayout();

Label notesLabel = new Label(I18N.message("patchnotes"));
notesLabel.setWrap(false);
notesLabel.setAutoFit(true);
notesLabel.setHeight(20);
notesLabel.setStyleName("update-notes");
String notesContent = infos.get(1);
if (!notesContent.contains("<p") && !notesContent.contains("<div") && !notesContent.contains("<br")
&& !notesContent.contains("<span") && !notesContent.contains("<table"))
notesContent = notesContent.replace("\n", "<br>");

HTMLPane notesContentPanel = new HTMLPane();
notesContentPanel.setWidth100();
notesContentPanel.setHeight("50%");
notesContentPanel.setShowEdges(true);
notesContentPanel.setContents(notesContent);
notesContentPanel.setContentsType(ContentsType.FRAGMENT);

Label changesLabel = new Label(I18N.message("changelog"));
changesLabel.setWrap(false);
changesLabel.setAutoFit(true);
changesLabel.setHeight(20);
changesLabel.setStyleName("update-changelog");
String changesContent = infos.get(0);
if (!changesContent.contains("<p") && !changesContent.contains("<div")
&& !changesContent.contains("<br") && !changesContent.contains("<span")
&& !changesContent.contains("<table"))
changesContent = changesContent.replace("\n", "<br>");

HTMLPane changesContentPanel = new HTMLPane();
changesContentPanel.setWidth100();
changesContentPanel.setHeight("50%");
changesContentPanel.setShowEdges(true);
changesContentPanel.setContents(changesContent);
changesContentPanel.setContentsType(ContentsType.FRAGMENT);

Label separator = new Label(" ");
separator.setHeight(10);

panel.setMembers(notesLabel, notesContentPanel, separator, changesLabel, changesContentPanel);

notesPanel.addMember(panel);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import com.logicaldoc.gui.common.client.widgets.FeatureDisabled;
import com.logicaldoc.gui.frontend.client.services.UpdateService;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ContentsType;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Progressbar;
Expand Down Expand Up @@ -279,22 +281,49 @@ public void onFailure(Throwable caught) {

@Override
public void onSuccess(List<String> infos) {
DynamicForm form = new DynamicForm();
form.setTitleOrientation(TitleOrientation.TOP);
form.setColWidths("*");
form.setNumCols(1);

TextAreaItem changelog = ItemFactory.newTextAreaItem("changelog", infos.get(0));
changelog.setWidth("100%");
changelog.setHeight(220);

TextAreaItem updatenotes = ItemFactory.newTextAreaItem("updatenotes", infos.get(1));
updatenotes.setWidth("100%");
updatenotes.setHeight(220);

form.setItems(updatenotes, changelog);

notesPanel.addMember(form);
VLayout panel = new VLayout();

Label notesLabel = new Label(I18N.message("updatenotes"));
notesLabel.setWrap(false);
notesLabel.setAutoFit(true);
notesLabel.setHeight(20);
notesLabel.setStyleName("update-notes");
String notesContent = infos.get(1);
if (!notesContent.contains("<p") && !notesContent.contains("<div") && !notesContent.contains("<br")
&& !notesContent.contains("<span") && !notesContent.contains("<table"))
notesContent = notesContent.replace("\n", "<br>");

HTMLPane notesContentPanel = new HTMLPane();
notesContentPanel.setWidth100();
notesContentPanel.setHeight("50%");
notesContentPanel.setShowEdges(true);
notesContentPanel.setContents(notesContent);
notesContentPanel.setContentsType(ContentsType.FRAGMENT);

Label changesLabel = new Label(I18N.message("changelog"));
changesLabel.setWrap(false);
changesLabel.setAutoFit(true);
changesLabel.setHeight(20);
changesLabel.setStyleName("update-changelog");
String changesContent = infos.get(0);
if (!changesContent.contains("<p") && !changesContent.contains("<div")
&& !changesContent.contains("<br") && !changesContent.contains("<span")
&& !changesContent.contains("<table"))
changesContent = changesContent.replace("\n", "<br>");

HTMLPane changesContentPanel = new HTMLPane();
changesContentPanel.setWidth100();
changesContentPanel.setHeight("50%");
changesContentPanel.setShowEdges(true);
changesContentPanel.setContents(changesContent);
changesContentPanel.setContentsType(ContentsType.FRAGMENT);

Label separator = new Label(" ");
separator.setHeight(10);

panel.setMembers(notesLabel, notesContentPanel, separator, changesLabel, changesContentPanel);

notesPanel.addMember(panel);
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions logicaldoc-gui/war/skin/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,11 @@
border-radius: 0px;
outline: none;
}

.update-changelog, .update-notes{
font-family: Arial, Bitstream Vera Sans, sans-serif;
font-size: 14pt;
font-weight: bold;
white-space: nowrap;
color: red;
}
Loading

0 comments on commit 64d42fc

Please sign in to comment.