19 package org.sleuthkit.autopsy.contentviewers;
22 import com.google.common.base.Strings;
23 import java.awt.Component;
24 import java.util.HashMap;
26 import java.util.logging.Level;
27 import org.openide.nodes.Node;
28 import org.openide.util.NbBundle;
29 import org.openide.util.lookup.ServiceProvider;
38 @ServiceProvider(service = DataContentViewer.class, position = 3)
39 @SuppressWarnings(
"PMD.SingularField")
42 private static final int CONFIDENCE_LEVEL = 5;
43 private static final long serialVersionUID = 1L;
46 private final Map<String, FileTypeViewer> mimeTypeToViewerMap =
new HashMap<>();
49 private static final FileTypeViewer[] KNOWN_VIEWERS =
new FileTypeViewer[]{
63 for (FileTypeViewer cv : KNOWN_VIEWERS) {
64 cv.getSupportedMIMETypes().forEach((mimeType) -> {
65 if (mimeTypeToViewerMap.containsKey(mimeType) ==
false) {
66 mimeTypeToViewerMap.put(mimeType, cv);
68 LOGGER.log(Level.WARNING,
"Duplicate viewer for mimtype: {0}", mimeType);
75 LOGGER.log(Level.INFO,
"Created ApplicationContentViewer instance: {0}",
this);
86 return mimeTypeToViewerMap.get(mimeType);
94 @SuppressWarnings(
"unchecked")
96 private
void initComponents() {
98 setLayout(
new javax.swing.OverlayLayout(
this));
110 if (selectedNode == null) {
114 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
119 String mimeType = file.getMIMEType();
120 if (Strings.isNullOrEmpty(mimeType)) {
121 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
126 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
131 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
135 FileTypeViewer viewer = getSupportingViewer(mimeType);
136 if (viewer != null) {
139 viewer.setFile(file);
141 this.add(viewer.getComponent());
149 @NbBundle.Messages(
"ApplicationContentViewer.title=Application")
151 return Bundle.ApplicationContentViewer_title();
155 @NbBundle.Messages(
"ApplicationContentViewer.toolTip=Displays file contents.")
157 return Bundle.ApplicationContentViewer_toolTip();
173 if (lastViewer != null) {
174 lastViewer.resetComponent();
187 AbstractFile aFile = node.getLookup().lookup(AbstractFile.class);
192 String mimeType = aFile.getMIMEType();
193 if (Strings.isNullOrEmpty(mimeType)) {
194 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", aFile.getName());
199 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
204 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
207 return (getSupportingViewer(mimeType) != null);
214 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
215 String mimeType = file.getMIMEType();
217 if (Strings.isNullOrEmpty(mimeType)) {
218 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
223 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
228 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
231 if (null != getSupportingViewer(mimeType)) {
232 return CONFIDENCE_LEVEL;
FileTypeViewer lastViewer
String getMIMEType(AbstractFile file)
boolean isSupported(Node node)
int isPreferred(Node node)
FileTypeViewer getSupportingViewer(String mimeType)
void setNode(Node selectedNode)
DataContentViewer createInstance()
synchronized static Logger getLogger(String name)