Autopsy  4.13.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.List;
27 import java.util.Locale;
28 import java.util.logging.Level;
29 import javax.swing.AbstractAction;
30 import javax.swing.Action;
31 import javax.swing.ImageIcon;
32 import javax.swing.JMenuItem;
33 import org.jxmapviewer.viewer.GeoPosition;
34 import org.openide.util.NbBundle.Messages;
50 import org.sleuthkit.datamodel.SleuthkitCase;
54 import org.sleuthkit.datamodel.AbstractFile;
55 import org.sleuthkit.datamodel.BlackboardArtifact;
56 import org.sleuthkit.datamodel.Content;
57 import org.sleuthkit.datamodel.TskCoreException;
58 
64 final class MapWaypoint extends KdTree.XYZPoint implements org.jxmapviewer.viewer.Waypoint {
65 
66  private static final Logger logger = Logger.getLogger(MapWaypoint.class.getName());
67  private final static String HTML_PROP_FORMAT = "<b>%s: </b>%s<br>";
68  static private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.US);
69 
70  private final Waypoint dataModelWaypoint;
71  private final GeoPosition position;
72 
82  static List<MapWaypoint> getWaypoints(SleuthkitCase skCase) throws GeoLocationDataException {
83  List<Waypoint> points = WaypointBuilder.getAllWaypoints(skCase);
84 
85  List<Route> routes = Route.getRoutes(skCase);
86  for (Route route : routes) {
87  points.addAll(route.getRoute());
88  }
89 
90  List<MapWaypoint> mapPoints = new ArrayList<>();
91 
92  for (Waypoint point : points) {
93  mapPoints.add(new MapWaypoint(point));
94  }
95 
96  return mapPoints;
97  }
98 
108  static List<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
109  List<MapWaypoint> mapPoints = new ArrayList<>();
110 
111  if (dmWaypoints != null) {
112 
113  for (Waypoint point : dmWaypoints) {
114  mapPoints.add(new MapWaypoint(point));
115  }
116  }
117 
118  return mapPoints;
119  }
120 
130  static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
131  List<Waypoint> waypoints = new ArrayList<>();
132 
133  if (mapWaypoints != null) {
134  for (MapWaypoint point : mapWaypoints) {
135  waypoints.add(point.dataModelWaypoint);
136  }
137  }
138 
139  return waypoints;
140  }
141 
149  static MapWaypoint getDummyWaypoint(GeoPosition position) {
150  return new MapWaypoint(position);
151  }
152 
158  private MapWaypoint(Waypoint dataModelWaypoint) {
159  super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
160  this.dataModelWaypoint = dataModelWaypoint;
161  position = new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
162  }
163 
169  private MapWaypoint(GeoPosition position) {
170  super(position.getLatitude(), position.getLongitude());
171  dataModelWaypoint = null;
172  this.position = position;
173  }
174 
180  ImageIcon getImage() {
181  if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
182  BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
183  return new ImageIcon(buffImage);
184  }
185 
186  return null;
187  }
188 
192  @Override
193  public GeoPosition getPosition() {
194  return position;
195  }
196 
202  String getLabel() {
203  return dataModelWaypoint.getLabel();
204  }
205 
211  String getHTMLFormattedWaypointDetails() {
212  return getFormattedDetails(dataModelWaypoint);
213  }
214 
223  JMenuItem[] getMenuItems() throws TskCoreException {
224  List<JMenuItem> menuItems = new ArrayList<>();
225  BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
226  Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
227 
228  menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
229  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
230  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
231  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
232 
233  return menuItems.toArray(new JMenuItem[0]);
234  }
235 
243  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
244  List<JMenuItem> menuItems = new ArrayList<>();
245  //if this artifact has a time stamp add the action to view it in the timeline
246  try {
247  if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
248  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
249  }
250  } catch (TskCoreException ex) {
251  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
252  }
253 
254  return menuItems;
255  }
256 
267  @Messages({
268  "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
269  })
270  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
271  List<JMenuItem> menuItems = new ArrayList<>();
272 
273  List<Action> actions = DataModelActionsFactory.getActions(content, true);
274  for (Action action : actions) {
275  if (action == null) {
276  menuItems.add(null);
277  } else if (action instanceof ExportCSVAction) {
278  // Do nothing we don't need this menu item.
279  } else if (action instanceof AddContentTagAction) {
280  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
281  } else if (action instanceof AddBlackboardArtifactTagAction) {
282  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
283  } else if (action instanceof ExternalViewerShortcutAction) {
284  // Replace with an ExternalViewerAction
285  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(), new FileNode((AbstractFile) content));
286  menuItems.add(new JMenuItem(newAction));
287  } else if (action instanceof ExtractAction) {
288  menuItems.add(new JMenuItem(new WaypointExtractAction((AbstractFile) content)));
289  } else {
290  menuItems.add(new JMenuItem(action));
291  }
292  }
293  return menuItems;
294  }
295 
304  private String getFormattedDetails(Waypoint point) {
305  StringBuilder result = new StringBuilder(); //NON-NLS
306 
307  result.append("<html>").append(formatAttribute("Name", point.getLabel()));
308 
309  Long timestamp = point.getTimestamp();
310  if (timestamp != null) {
311  result.append(formatAttribute("Timestamp", getTimeStamp(timestamp)));
312  }
313 
314  result.append(formatAttribute("Latitude", point.getLatitude().toString()))
315  .append(formatAttribute("Longitude", point.getLongitude().toString()));
316 
317  if (point.getAltitude() != null) {
318  result.append(formatAttribute("Altitude", point.getAltitude().toString()));
319  }
320 
321  List<Waypoint.Property> list = point.getOtherProperties();
322  for (Waypoint.Property prop : list) {
323  String value = prop.getValue();
324  if (value != null && !value.isEmpty()) {
325  result.append(formatAttribute(prop.getDisplayName(), value));
326  }
327  }
328 
329  result.append("</html>");
330 
331  return result.toString();
332  }
333 
342  private String formatAttribute(String title, String value) {
343  return String.format(HTML_PROP_FORMAT, title, value);
344  }
345 
353  private String getTimeStamp(long timeStamp) {
354  return DATE_FORMAT.format(new java.util.Date(timeStamp * 1000));
355  }
356 
360  @Messages({
361  "WaypointExtractAction_label=Extract Files(s)"
362  })
363  final class WaypointExtractAction extends AbstractAction {
364 
365  private static final long serialVersionUID = 1L;
366  final private AbstractFile file;
367 
368  WaypointExtractAction(AbstractFile file) {
369  super(Bundle.WaypointExtractAction_label());
370  this.file = file;
371  }
372 
373  @Override
374  public void actionPerformed(ActionEvent e) {
375  ExtractActionHelper helper = new ExtractActionHelper();
376  helper.extract(e, Arrays.asList(file));
377 
378  }
379  }
380 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.