Merge pull request #6972 from kellykelly3/7597-metadata-content-viewer-edt-change

7597 - Removed the db calls for metadata content pane from edt
This commit is contained in:
Richard Cordovano 2021-05-21 11:57:47 -04:00 committed by GitHub
commit 91cc8934f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 209 additions and 156 deletions

View File

@ -85,6 +85,7 @@ MediaViewVideoPanel.progressLabel.text=00:00
MediaViewVideoPanel.infoLabel.text=info MediaViewVideoPanel.infoLabel.text=info
MediaViewImagePanel.imgFileTooLarge.msg=Could not load image file (too large): {0} MediaViewImagePanel.imgFileTooLarge.msg=Could not load image file (too large): {0}
Metadata.nodeText.loading=Metadata loading...
Metadata.nodeText.none=None Metadata.nodeText.none=None
Metadata.nodeText.truncated=(results truncated) Metadata.nodeText.truncated=(results truncated)
Metadata.nodeText.unknown=Unknown Metadata.nodeText.unknown=Unknown

View File

@ -19,10 +19,14 @@
package org.sleuthkit.autopsy.contentviewers; package org.sleuthkit.autopsy.contentviewers;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.SwingWorker;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
@ -51,6 +55,8 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
private static final Logger LOGGER = Logger.getLogger(Metadata.class.getName()); private static final Logger LOGGER = Logger.getLogger(Metadata.class.getName());
private MetaDataWorker worker;
/** /**
* Creates new form Metadata * Creates new form Metadata
*/ */
@ -145,15 +151,137 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
"Metadata.tableRowTitle.acquisitionDetails=Acquisition Details", "Metadata.tableRowTitle.acquisitionDetails=Acquisition Details",
"Metadata.tableRowTitle.downloadSource=Downloaded From", "Metadata.tableRowTitle.downloadSource=Downloaded From",
"Metadata.nodeText.unknown=Unknown", "Metadata.nodeText.unknown=Unknown",
"Metadata.nodeText.none=None"}) "Metadata.nodeText.none=None",
"Metadata.nodeText.loading=Metadata loading..."})
@Override @Override
public void setNode(Node node) { public void setNode(Node node) {
if (worker != null) {
worker.cancel(true);
worker = null;
}
if (node != null) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
setText(Bundle.Metadata_nodeText_loading());
worker = new MetaDataWorker(node) {
@Override
public void done() {
try {
if (!isCancelled()) {
setText(get());
jTextPane1.setCaretPosition(0);
}
} catch (InterruptedException | ExecutionException ex) {
LOGGER.log(Level.SEVERE, "Failed to get metaData for node " + node.getName(), ex);
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
};
worker.execute();
} else {
setText("");
}
}
/**
* Adds a row for download source from the given associated artifact, if the
* associated artifacts specifies a source.
*
* @param sb string builder.
* @param associatedArtifact
*
* @throws TskCoreException if there is an error
*/
private void addDownloadSourceRow(StringBuilder sb, BlackboardArtifact associatedArtifact) throws TskCoreException {
if (associatedArtifact != null
&& ((associatedArtifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID())
|| (associatedArtifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID()))) {
BlackboardAttribute urlAttr = associatedArtifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_URL));
if (urlAttr != null) {
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.downloadSource"), urlAttr.getValueString());
}
}
}
/**
* Add the acquisition details to the results (if applicable)
*
* @param sb The output StringBuilder object
* @param dataSource The data source (may be null)
*/
private void addAcquisitionDetails(StringBuilder sb, DataSource dataSource) {
if (dataSource != null) {
try {
String details = dataSource.getAcquisitionDetails();
if (StringUtils.isEmpty(details)) {
details = Bundle.Metadata_nodeText_unknown();
}
details = details.replaceAll("\n", "<br>");
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.acquisitionDetails"), details);
} catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Error reading acquisition details from case database", ex); //NON-NLS
}
}
}
@Override
public String getTitle() {
return NbBundle.getMessage(this.getClass(), "Metadata.title");
}
@Override
public String getToolTip() {
return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
}
@Override
public DataContentViewer createInstance() {
return new Metadata();
}
@Override
public Component getComponent() {
return this;
}
@Override
public void resetComponent() {
setText("");
}
@Override
public boolean isSupported(Node node) {
Image image = node.getLookup().lookup(Image.class);
AbstractFile file = node.getLookup().lookup(AbstractFile.class);
return (file != null) || (image != null);
}
@Override
public int isPreferred(Node node) {
return 1;
}
/**
* SwingWorker for gathering the file metadata.
*/
private class MetaDataWorker extends SwingWorker<String, Void> {
private final Node node;
MetaDataWorker(Node node) {
this.node = node;
}
@Override
protected String doInBackground() throws Exception {
AbstractFile file = node.getLookup().lookup(AbstractFile.class); AbstractFile file = node.getLookup().lookup(AbstractFile.class);
Image image = node.getLookup().lookup(Image.class); Image image = node.getLookup().lookup(Image.class);
DataSource dataSource = node.getLookup().lookup(DataSource.class); DataSource dataSource = node.getLookup().lookup(DataSource.class);
if (file == null && image == null) { if (file == null && image == null) {
setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn")); return NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn");
return;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -176,7 +304,6 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file)); addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file)); addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
String md5 = file.getMd5Hash(); String md5 = file.getMd5Hash();
if (md5 == null) { if (md5 == null) {
md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc"); md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
@ -213,8 +340,8 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
endTable(sb); endTable(sb);
/* /*
* If we have a file system file, grab the more detailed metadata text * If we have a file system file, grab the more detailed
* too * metadata text too
*/ */
try { try {
if (file instanceof FsContent) { if (file instanceof FsContent) {
@ -227,8 +354,8 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
sb.append(str).append("<br />"); //NON-NLS sb.append(str).append("<br />"); //NON-NLS
/* /*
* Very long results can cause the UI to hang before displaying, * Very long results can cause the UI to hang before
* so truncate the results if necessary. * displaying, so truncate the results if necessary.
*/ */
if (sb.length() > 50000) { if (sb.length() > 50000) {
sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.truncated")); sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.truncated"));
@ -294,86 +421,11 @@ public class Metadata extends javax.swing.JPanel implements DataContentViewer {
} }
} }
setText(sb.toString()); if (isCancelled()) {
jTextPane1.setCaretPosition(0); return "";
this.setCursor(null);
} }
/** return sb.toString();
* Adds a row for download source from the given associated artifact,
* if the associated artifacts specifies a source.
*
* @param sb string builder.
* @param associatedArtifact
*
* @throws TskCoreException if there is an error
*/
private void addDownloadSourceRow(StringBuilder sb, BlackboardArtifact associatedArtifact ) throws TskCoreException {
if (associatedArtifact != null &&
((associatedArtifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()) ||
(associatedArtifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID())) ) {
BlackboardAttribute urlAttr = associatedArtifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_URL));
if (urlAttr != null) {
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.downloadSource"), urlAttr.getValueString());
} }
} }
} }
/**
* Add the acquisition details to the results (if applicable)
*
* @param sb The output StringBuilder object
* @param dataSource The data source (may be null)
*/
private void addAcquisitionDetails(StringBuilder sb, DataSource dataSource) {
if (dataSource != null) {
try {
String details = dataSource.getAcquisitionDetails();
if (StringUtils.isEmpty(details)) {
details = Bundle.Metadata_nodeText_unknown();
}
details = details.replaceAll("\n", "<br>");
addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.acquisitionDetails"), details);
} catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Error reading acquisition details from case database", ex); //NON-NLS
}
}
}
@Override
public String getTitle() {
return NbBundle.getMessage(this.getClass(), "Metadata.title");
}
@Override
public String getToolTip() {
return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
}
@Override
public DataContentViewer createInstance() {
return new Metadata();
}
@Override
public Component getComponent() {
return this;
}
@Override
public void resetComponent() {
setText("");
}
@Override
public boolean isSupported(Node node) {
Image image = node.getLookup().lookup(Image.class);
AbstractFile file = node.getLookup().lookup(AbstractFile.class);
return (file != null) || (image != null);
}
@Override
public int isPreferred(Node node) {
return 1;
}
}