Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentViewerMedia.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *s
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.corecomponents;
20 
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.util.Arrays;
25 import java.util.Set;
26 import java.util.SortedSet;
27 import java.util.TreeSet;
28 import java.util.logging.Level;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.util.lookup.ServiceProviders;
39 
43 @ServiceProviders(value = {
44  @ServiceProvider(service = DataContentViewer.class, position = 5)
45 })
46 public class DataContentViewerMedia extends javax.swing.JPanel implements DataContentViewer {
47 
48  private static final Set<String> AUDIO_EXTENSIONS = new TreeSet<>(Arrays.asList(".mp3", ".wav", ".wma")); //NON-NLS
49  private static final Logger logger = Logger.getLogger(DataContentViewerMedia.class.getName());
51  //UI
53  private final SortedSet<String> videoExtensions; // get them from the panel
54  private final SortedSet<String> imageExtensions;
55  private final SortedSet<String> videoMimes;
56  private final SortedSet<String> imageMimes;
58  private boolean videoPanelInited;
59  private boolean imagePanelInited;
60  private static final String IMAGE_VIEWER_LAYER = "IMAGE"; //NON-NLS
61  private static final String VIDEO_VIEWER_LAYER = "VIDEO"; //NON-NLS
62 
67 
68  initComponents();
69 
70  // get the right panel for our platform
72  videoPanelInited = videoPanel.isInited();
73  videoExtensions = new TreeSet<>(Arrays.asList(videoPanel.getExtensions()));
74  videoMimes = new TreeSet<>(videoPanel.getMimeTypes());
75 
76  imagePanel = new MediaViewImagePanel();
77  imagePanelInited = imagePanel.isInited();
78  imageMimes = new TreeSet<>(imagePanel.getMimeTypes());
79  imageExtensions = new TreeSet<>(imagePanel.getExtensions());
80 
81  customizeComponents();
82  logger.log(Level.INFO, "Created MediaView instance: " + this); //NON-NLS
83  }
84 
85  private void customizeComponents() {
86  add(imagePanel, IMAGE_VIEWER_LAYER);
87  add(videoPanel, VIDEO_VIEWER_LAYER);
88 
89  showVideoPanel(false);
90  }
91 
97  @SuppressWarnings("unchecked")
98  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
99  private void initComponents() {
100 
101  setLayout(new java.awt.CardLayout());
102  getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(DataContentViewerMedia.class, "DataContentViewerMedia.AccessibleContext.accessibleDescription")); // NOI18N
103  }// </editor-fold>//GEN-END:initComponents
104  // Variables declaration - do not modify//GEN-BEGIN:variables
105  // End of variables declaration//GEN-END:variables
106 
107  @Override
108  public void setNode(Node selectedNode) {
109  try {
110  if (selectedNode == null) {
111  resetComponent();
112  return;
113  }
114 
115  AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
116  if (file == null) {
117  resetComponent();
118  return;
119  }
120 
121  if (file.equals(lastFile)) {
122  return; //prevent from loading twice if setNode() called mult. times
123  }
124 
125  lastFile = file;
126 
127  final Dimension dims = DataContentViewerMedia.this.getSize();
128  //logger.info("setting node on media viewer"); //NON-NLS
129  if (imagePanelInited && isImageSupported(file)) {
130  imagePanel.showImageFx(file, dims);
131  this.showVideoPanel(false);
132  } else if (videoPanelInited && isVideoSupported(file)) {
133  videoPanel.setupVideo(file, dims);
134  this.showVideoPanel(true);
135  }
136  } catch (Exception e) {
137  logger.log(Level.SEVERE, "Exception while setting node", e); //NON-NLS
138  }
139  }
140 
146  private void showVideoPanel(boolean showVideo) {
147  CardLayout layout = (CardLayout) this.getLayout();
148  if (showVideo) {
149  layout.show(this, VIDEO_VIEWER_LAYER);
150  } else {
151  layout.show(this, IMAGE_VIEWER_LAYER);
152  }
153  }
154 
155  @Override
156  public String getTitle() {
157  return NbBundle.getMessage(this.getClass(), "DataContentViewerMedia.title");
158  }
159 
160  @Override
161  public String getToolTip() {
162  return NbBundle.getMessage(this.getClass(), "DataContentViewerMedia.toolTip");
163  }
164 
165  @Override
167  return new DataContentViewerMedia();
168  }
169 
170  @Override
171  public Component getComponent() {
172  return this;
173  }
174 
175  @Override
176  public void resetComponent() {
177  videoPanel.reset();
178  imagePanel.reset();
179  lastFile = null;
180  }
181 
187  private boolean isVideoSupported(AbstractFile file) {
188  String name = file.getName().toLowerCase();
189 
190  if ((containsExt(name, AUDIO_EXTENSIONS) || containsExt(name, videoExtensions)) &&
191  (!videoMimes.isEmpty() && file.isMimeType(videoMimes) == MimeMatchEnum.TRUE)) {
192  return true;
193  }
194  return false;
195  }
196 
202  private boolean isImageSupported(AbstractFile file) {
203  String name = file.getName().toLowerCase();
204 
205  // blackboard
206  if (!imageMimes.isEmpty()) {
207  MimeMatchEnum mimeMatch = file.isMimeType(imageMimes);
208  if (mimeMatch == MimeMatchEnum.TRUE) {
209  return true;
210  }
211  else if (mimeMatch == MimeMatchEnum.FALSE) {
212  return false;
213  }
214  }
215 
216  // extension
217  if (containsExt(name, imageExtensions)) {
218  return true;
219  }
220  // our own signature checks for important types
221  else if (ImageUtils.isJpegFileHeader(file)) {
222  return true;
223  }
224  else if (ImageUtils.isPngFileHeader(file)) {
225  return true;
226  }
227 
228  //for gstreamer formats, check if initialized first, then
229  //support audio formats, and video formats
230  return false;
231  }
232 
233  @Override
234  public boolean isSupported(Node node) {
235  if (node == null) {
236  return false;
237  }
238 
239  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
240  if (file == null) {
241  return false;
242  }
243 
244  if (file.getSize() == 0) {
245  return false;
246  }
247 
248  if (imagePanelInited) {
249  if (isImageSupported(file))
250  return true;
251  }
252 
253  if (videoPanelInited && videoPanel.isInited()) {
254  if (isVideoSupported(file))
255  return true;
256  }
257 
258  return false;
259  }
260 
261  @Override
262  public int isPreferred(Node node) {
263  //special case, check if deleted video, then do not make it preferred
264  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
265  if (file == null) {
266  return 0;
267  }
268  String name = file.getName().toLowerCase();
269  boolean deleted = file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC);
270 
271  if (containsExt(name, videoExtensions) && deleted) {
272  return 0;
273  }
274  else {
275  return 7;
276  }
277 
278  }
279 
280  private static boolean containsExt(String name, Set<String> exts) {
281  int extStart = name.lastIndexOf(".");
282  String ext = "";
283  if (extStart != -1) {
284  ext = name.substring(extStart, name.length()).toLowerCase();
285  }
286  return exts.contains(ext);
287  }
288 }
boolean isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM flag)
static boolean isPngFileHeader(AbstractFile file)
static boolean containsExt(String name, Set< String > exts)
MimeMatchEnum isMimeType(SortedSet< String > mimeTypes)
static boolean isJpegFileHeader(AbstractFile file)
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.