Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MapWaypoint.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
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.geolocation;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.image.BufferedImage;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.LinkedHashSet;
27 import java.util.List;
28 import java.util.Locale;
29 import java.util.Set;
30 import java.util.logging.Level;
31 import javax.swing.AbstractAction;
32 import javax.swing.Action;
33 import javax.swing.ImageIcon;
34 import javax.swing.JMenuItem;
35 import org.jxmapviewer.viewer.GeoPosition;
36 import org.openide.util.NbBundle.Messages;
52 import org.sleuthkit.datamodel.AbstractFile;
53 import org.sleuthkit.datamodel.BlackboardArtifact;
54 import org.sleuthkit.datamodel.Content;
55 import org.sleuthkit.datamodel.TskCoreException;
56 
62 final class MapWaypoint extends KdTree.XYZPoint implements org.jxmapviewer.viewer.Waypoint {
63 
64  private static final Logger logger = Logger.getLogger(MapWaypoint.class.getName());
65  private final static String HTML_PROP_FORMAT = "<b>%s: </b>%s<br>";
66  static private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.US);
67 
68  private final Waypoint dataModelWaypoint;
69  private final GeoPosition position;
70 
80  static Set<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
81  Set<MapWaypoint> mapPoints = new LinkedHashSet<>();
82 
83  if (dmWaypoints != null) {
84 
85  for (Waypoint point : dmWaypoints) {
86  mapPoints.add(new MapWaypoint(point));
87  }
88  }
89 
90  return mapPoints;
91  }
92 
102  static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
103  List<Waypoint> waypoints = new ArrayList<>();
104 
105  if (mapWaypoints != null) {
106  for (MapWaypoint point : mapWaypoints) {
107  waypoints.add(point.dataModelWaypoint);
108  }
109  }
110 
111  return waypoints;
112  }
113 
121  static MapWaypoint getDummyWaypoint(GeoPosition position) {
122  return new MapWaypoint(position);
123  }
124 
130  private MapWaypoint(Waypoint dataModelWaypoint) {
131  super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
132  this.dataModelWaypoint = dataModelWaypoint;
133  position = new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
134  }
135 
141  private MapWaypoint(GeoPosition position) {
142  super(position.getLatitude(), position.getLongitude());
143  dataModelWaypoint = null;
144  this.position = position;
145  }
146 
152  ImageIcon getImage() {
153  if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
154  BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
155  return new ImageIcon(buffImage);
156  }
157 
158  return null;
159  }
160 
164  @Override
165  public GeoPosition getPosition() {
166  return position;
167  }
168 
174  String getLabel() {
175  return dataModelWaypoint.getLabel();
176  }
177 
183  String getHTMLFormattedWaypointDetails() {
184  return getFormattedDetails(dataModelWaypoint);
185  }
186 
195  JMenuItem[] getMenuItems() throws TskCoreException {
196  List<JMenuItem> menuItems = new ArrayList<>();
197  BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
198  Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
199 
200  menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
201  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
202  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
203  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
204 
205  return menuItems.toArray(new JMenuItem[0]);
206  }
207 
215  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
216  List<JMenuItem> menuItems = new ArrayList<>();
217  //if this artifact has a time stamp add the action to view it in the timeline
218  try {
219  if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
220  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
221  }
222  } catch (TskCoreException ex) {
223  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
224  }
225 
226  return menuItems;
227  }
228 
239  @Messages({
240  "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
241  })
242  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
243  List<JMenuItem> menuItems = new ArrayList<>();
244 
245  List<Action> actions = DataModelActionsFactory.getActions(content, true);
246  for (Action action : actions) {
247  if (action == null) {
248  menuItems.add(null);
249  } else if (action instanceof ExportCSVAction) {
250  // Do nothing we don't need this menu item.
251  } else if (action instanceof AddContentTagAction) {
252  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
253  } else if (action instanceof AddBlackboardArtifactTagAction) {
254  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
255  } else if (action instanceof ExternalViewerShortcutAction) {
256  // Replace with an ExternalViewerAction
257  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(), new FileNode((AbstractFile) content));
258  menuItems.add(new JMenuItem(newAction));
259  } else if (action instanceof ExtractAction) {
260  menuItems.add(new JMenuItem(new WaypointExtractAction((AbstractFile) content)));
261  } else {
262  menuItems.add(new JMenuItem(action));
263  }
264  }
265  return menuItems;
266  }
267 
276  private String getFormattedDetails(Waypoint point) {
277  StringBuilder result = new StringBuilder(); //NON-NLS
278 
279  result.append("<html>").append(formatAttribute("Name", point.getLabel()));
280 
281  Long timestamp = point.getTimestamp();
282  if (timestamp != null) {
283  result.append(formatAttribute("Timestamp", getTimeStamp(timestamp)));
284  }
285 
286  result.append(formatAttribute("Latitude", point.getLatitude().toString()))
287  .append(formatAttribute("Longitude", point.getLongitude().toString()));
288 
289  if (point.getAltitude() != null) {
290  result.append(formatAttribute("Altitude", point.getAltitude().toString()));
291  }
292 
293  List<Waypoint.Property> list = point.getOtherProperties();
294  for (Waypoint.Property prop : list) {
295  String value = prop.getValue();
296  if (value != null && !value.isEmpty()) {
297  result.append(formatAttribute(prop.getDisplayName(), value));
298  }
299  }
300 
301  result.append("</html>");
302 
303  return result.toString();
304  }
305 
314  private String formatAttribute(String title, String value) {
315  return String.format(HTML_PROP_FORMAT, title, value);
316  }
317 
325  private String getTimeStamp(long timeStamp) {
326  return DATE_FORMAT.format(new java.util.Date(timeStamp * 1000));
327  }
328 
332  @Messages({
333  "WaypointExtractAction_label=Extract Files(s)"
334  })
335  final class WaypointExtractAction extends AbstractAction {
336 
337  private static final long serialVersionUID = 1L;
338  final private AbstractFile file;
339 
340  WaypointExtractAction(AbstractFile file) {
341  super(Bundle.WaypointExtractAction_label());
342  this.file = file;
343  }
344 
345  @Override
346  public void actionPerformed(ActionEvent e) {
347  ExtractActionHelper helper = new ExtractActionHelper();
348  helper.extract(e, Arrays.asList(file));
349 
350  }
351  }
352 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.