19 package org.sleuthkit.autopsy.contentviewers;
21 import com.google.common.base.Strings;
22 import java.awt.Component;
23 import java.util.HashMap;
25 import java.util.logging.Level;
26 import org.openide.nodes.Node;
27 import org.openide.util.NbBundle;
28 import org.openide.util.lookup.ServiceProvider;
37 @ServiceProvider(service = DataContentViewer.class, position = 3)
38 @SuppressWarnings(
"PMD.SingularField")
41 private static final int CONFIDENCE_LEVEL = 5;
42 private static final long serialVersionUID = 1L;
45 private final Map<String, FileTypeViewer> mimeTypeToViewerMap =
new HashMap<>();
48 private final FileTypeViewer[] KNOWN_VIEWERS =
new FileTypeViewer[]{
51 new MediaFileViewer(),
53 new WindowsRegistryViewer()
64 for (FileTypeViewer cv : KNOWN_VIEWERS) {
65 cv.getSupportedMIMETypes().forEach((mimeType) -> {
66 if (mimeTypeToViewerMap.containsKey(mimeType) ==
false) {
67 mimeTypeToViewerMap.put(mimeType, cv);
69 LOGGER.log(Level.WARNING,
"Duplicate viewer for mimtype: {0}", mimeType);
76 LOGGER.log(Level.INFO,
"Created ApplicationContentViewer instance: {0}",
this);
88 FileTypeViewer viewer = mimeTypeToViewerMap.get(file.getMIMEType());
89 if (viewer == null || viewer.isSupported(file)) {
100 @SuppressWarnings(
"unchecked")
102 private
void initComponents() {
104 setLayout(
new javax.swing.OverlayLayout(
this));
115 if (selectedNode == null) {
119 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
124 String mimeType = file.getMIMEType();
125 if (Strings.isNullOrEmpty(mimeType)) {
126 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
131 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
136 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
139 FileTypeViewer viewer = getSupportingViewer(file);
140 if (viewer != null) {
143 viewer.setFile(file);
145 this.add(viewer.getComponent());
153 @NbBundle.Messages(
"ApplicationContentViewer.title=Application")
155 return Bundle.ApplicationContentViewer_title();
159 @NbBundle.Messages(
"ApplicationContentViewer.toolTip=Displays file contents.")
161 return Bundle.ApplicationContentViewer_toolTip();
177 if (lastViewer != null) {
178 lastViewer.resetComponent();
191 AbstractFile aFile = node.getLookup().lookup(AbstractFile.class);
196 String mimeType = aFile.getMIMEType();
197 if (Strings.isNullOrEmpty(mimeType)) {
198 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", aFile.getName());
203 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
208 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
211 return (getSupportingViewer(aFile) != null);
218 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
219 String mimeType = file.getMIMEType();
221 if (Strings.isNullOrEmpty(mimeType)) {
222 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
227 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
232 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
235 if (null != getSupportingViewer(file)) {
236 return CONFIDENCE_LEVEL;
FileTypeViewer lastViewer
String getMIMEType(AbstractFile file)
FileTypeViewer getSupportingViewer(AbstractFile file)
boolean isSupported(Node node)
int isPreferred(Node node)
void setNode(Node selectedNode)
DataContentViewer createInstance()
synchronized static Logger getLogger(String name)