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;
38 @ServiceProvider(service = DataContentViewer.class, position = 3)
39 @SuppressWarnings(
"PMD.SingularField")
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(),
65 for (FileTypeViewer cv : KNOWN_VIEWERS) {
66 cv.getSupportedMIMETypes().forEach((mimeType) -> {
67 if (mimeTypeToViewerMap.containsKey(mimeType) ==
false) {
68 mimeTypeToViewerMap.put(mimeType, cv);
70 LOGGER.log(Level.WARNING,
"Duplicate viewer for mimtype: {0}", mimeType);
77 LOGGER.log(Level.INFO,
"Created ApplicationContentViewer instance: {0}",
this);
89 FileTypeViewer viewer = mimeTypeToViewerMap.get(file.getMIMEType());
90 if (viewer == null || viewer.isSupported(file)) {
101 @SuppressWarnings(
"unchecked")
103 private
void initComponents() {
105 setLayout(
new javax.swing.OverlayLayout(
this));
116 if (selectedNode == null) {
120 AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
121 if ((file == null) || (file.isDir())) {
125 String mimeType = file.getMIMEType();
126 if (Strings.isNullOrEmpty(mimeType)) {
127 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
132 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
137 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
140 FileTypeViewer viewer = getSupportingViewer(file);
141 if (viewer != null) {
144 viewer.setFile(file);
146 this.add(viewer.getComponent());
154 @NbBundle.Messages(
"ApplicationContentViewer.title=Application")
156 return Bundle.ApplicationContentViewer_title();
160 @NbBundle.Messages(
"ApplicationContentViewer.toolTip=Displays file contents.")
162 return Bundle.ApplicationContentViewer_toolTip();
178 if (lastViewer != null) {
179 lastViewer.resetComponent();
192 AbstractFile aFile = node.getLookup().lookup(AbstractFile.class);
193 if ((aFile == null) || (aFile.isDir())) {
197 String mimeType = aFile.getMIMEType();
198 if (Strings.isNullOrEmpty(mimeType)) {
199 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", aFile.getName());
204 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
209 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
212 return (getSupportingViewer(aFile) != null);
219 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
220 String mimeType = file.getMIMEType();
222 if (Strings.isNullOrEmpty(mimeType)) {
223 LOGGER.log(Level.INFO,
"Mimetype not known for file: {0}", file.getName());
228 LOGGER.log(Level.SEVERE,
"Failed to initialize FileTypeDetector.", ex);
233 if (mimeType.equalsIgnoreCase(
"application/octet-stream")) {
236 if (null != getSupportingViewer(file)) {
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)