forked from alkacon/opencms-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added virus scanner interface for scanning uploaded files.
- Loading branch information
1 parent
d334e9d
commit db17c18
Showing
23 changed files
with
722 additions
and
470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
src-gwt/org/opencms/ade/upload/client/ui/CmsVirusReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* This library is part of OpenCms - | ||
* the Open Source Content Management System | ||
* | ||
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* For further information about Alkacon Software, please see the | ||
* company website: http://www.alkacon.com | ||
* | ||
* For further information about OpenCms, please see the | ||
* project website: http://www.opencms.org | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
package org.opencms.ade.upload.client.ui; | ||
|
||
import org.opencms.gwt.client.CmsCoreProvider; | ||
import org.opencms.gwt.client.ui.CmsFieldSet; | ||
import org.opencms.gwt.client.ui.CmsList; | ||
import org.opencms.gwt.client.ui.CmsListItem; | ||
import org.opencms.gwt.client.ui.CmsListItemWidget; | ||
import org.opencms.gwt.client.ui.CmsMessageWidget; | ||
import org.opencms.gwt.client.ui.CmsPopup; | ||
import org.opencms.gwt.client.ui.CmsPushButton; | ||
import org.opencms.gwt.client.ui.CmsScrollPanel; | ||
import org.opencms.gwt.shared.CmsListInfoBean; | ||
import org.opencms.gwt.shared.I_CmsUploadConstants; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.gwt.core.client.GWT; | ||
import com.google.gwt.dom.client.Style.Unit; | ||
import com.google.gwt.json.client.JSONArray; | ||
import com.google.gwt.json.client.JSONObject; | ||
import com.google.gwt.json.client.JSONString; | ||
import com.google.gwt.json.client.JSONValue; | ||
import com.google.gwt.uibinder.client.UiBinder; | ||
import com.google.gwt.uibinder.client.UiField; | ||
import com.google.gwt.user.client.ui.Composite; | ||
import com.google.gwt.user.client.ui.Widget; | ||
|
||
/** | ||
* Shows which viruses were found in files the user tried to upload. | ||
*/ | ||
public class CmsVirusReport extends Composite { | ||
|
||
/** The UiBinder interface for this widget. */ | ||
protected interface I_CmsVirusReportUiBinder extends UiBinder<Widget, CmsVirusReport> { | ||
// empty | ||
} | ||
|
||
/** The UIBinder for this class. */ | ||
static final I_CmsVirusReportUiBinder UI_BINDER = GWT.create(I_CmsVirusReportUiBinder.class); | ||
|
||
/** Displays the warning message to the user. */ | ||
@UiField | ||
protected CmsMessageWidget m_message; | ||
|
||
/** Contains the resource boxes with the virus information. */ | ||
@UiField | ||
protected CmsFieldSet m_fieldset; | ||
|
||
/** | ||
* Creates a new virus report widget. | ||
* | ||
* @param viruses a map from file names to lists of virus names found in the corresponding files | ||
*/ | ||
public CmsVirusReport(Map<String, List<String>> viruses) { | ||
|
||
Widget content = UI_BINDER.createAndBindUi(this); | ||
initWidget(content); | ||
CmsScrollPanel scroll = new CmsScrollPanel(); | ||
scroll.getElement().getStyle().setProperty("maxHeight", 500, Unit.PX); | ||
CmsList<?> list = new CmsList<>(); | ||
m_fieldset.add(scroll); | ||
scroll.add(list); | ||
m_message.setMessageText( | ||
org.opencms.ade.upload.client.Messages.get().key( | ||
org.opencms.ade.upload.client.Messages.GUI_UPLOAD_VIRUSES_FOUND_WARNING_0)); | ||
|
||
for (Map.Entry<String, List<String>> entry : viruses.entrySet()) { | ||
String commaSeparatedViruses = Joiner.on(", ").join(entry.getValue()); | ||
CmsListInfoBean infoBean = new CmsListInfoBean(entry.getKey(), commaSeparatedViruses, null); | ||
CmsListItemWidget listItemWidget = new CmsListItemWidget(infoBean); | ||
listItemWidget.setIcon(CmsCoreProvider.get().getResourceTypeIcon(entry.getKey())); | ||
list.add(new CmsListItem(listItemWidget)); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a popup containing a virus report. | ||
* | ||
* @param viruses a map from file names to lists of viruses found in the corresponding files | ||
* @param callback the callback to executing after closing the dialog | ||
* @return | ||
*/ | ||
public static CmsPopup createPopup(Map<String, List<String>> viruses, Runnable callback) { | ||
|
||
CmsPopup popup = new CmsPopup(); | ||
popup.setModal(true); | ||
popup.setGlassEnabled(true); | ||
popup.setMainContent(new CmsVirusReport(viruses)); | ||
popup.setCaption( | ||
org.opencms.ade.upload.client.Messages.get().key( | ||
org.opencms.ade.upload.client.Messages.GUI_UPLOAD_VIRUSES_FOUND_TITLE_0)); | ||
CmsPushButton ok = new CmsPushButton(); | ||
ok.setText(org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_OK_0)); | ||
ok.addClickHandler(event -> { | ||
popup.hide(); | ||
callback.run(); | ||
}); | ||
popup.addButton(ok); | ||
return popup; | ||
} | ||
|
||
/** | ||
* Extracts virus warnings from a JSON object. | ||
* | ||
* @param jsonObject the JSON object | ||
* @return the map of virus warnings, which maps file names to lists of viruses found in the corresponding file | ||
*/ | ||
public static Map<String, List<String>> getVirusWarnings(JSONObject jsonObject) { | ||
|
||
Map<String, List<String>> viruses = new HashMap<>(); | ||
JSONValue virusWarnings = jsonObject.get(I_CmsUploadConstants.ATTR_VIRUS_WARNINGS); | ||
if (virusWarnings != null) { | ||
JSONObject virusWarningsObj = (JSONObject)virusWarnings; | ||
for (String key : virusWarningsObj.keySet()) { | ||
List<String> virusList = new ArrayList<>(); | ||
viruses.put(key, virusList); | ||
JSONArray virusesForFile = (JSONArray)virusWarningsObj.get(key); | ||
for (int i = 0; i < virusesForFile.size(); i++) { | ||
JSONString jsv = (JSONString)virusesForFile.get(i); | ||
virusList.add(jsv.stringValue()); | ||
} | ||
} | ||
} | ||
return viruses; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src-gwt/org/opencms/ade/upload/client/ui/CmsVirusReport.ui.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> | ||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" | ||
xmlns:g="urn:import:com.google.gwt.user.client.ui" | ||
xmlns:cmsi="urn:import:org.opencms.gwt.client.ui.input" | ||
xmlns:cms="urn:import:org.opencms.gwt.client.ui"> | ||
|
||
<ui:with field="input" type="org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle" /> | ||
<ui:with field="main" type="org.opencms.gwt.client.ui.css.I_CmsLayoutBundle" /> | ||
<ui:style> | ||
</ui:style> | ||
<g:FlowPanel> | ||
<cms:CmsMessageWidget ui:field="m_message" /> | ||
<cms:CmsFieldSet ui:field="m_fieldset" /> | ||
</g:FlowPanel> | ||
</ui:UiBinder> |
Oops, something went wrong.