Merge pull request #470 from shahit2/timeline2

changed timezone and times to UTC for display
This commit is contained in:
Richard Cordovano 2014-03-06 12:25:41 -05:00
commit 66cb306c92
4 changed files with 61 additions and 15 deletions

View File

@ -148,6 +148,9 @@
<ResourceString bundle="org/sleuthkit/autopsy/corecomponents/Bundle.properties" key="GeneralPanel.useGMTTimeRB.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="org/sleuthkit/autopsy/corecomponents/Bundle.properties" key="GeneralPanel.useGMTTimeRB.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="useGMTTimeRBActionPerformed"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel3"> <Component class="javax.swing.JLabel" name="jLabel3">
<Properties> <Properties>

View File

@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.corecomponents;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
import org.openide.util.NbPreferences; import org.openide.util.NbPreferences;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
final class GeneralPanel extends javax.swing.JPanel { final class GeneralPanel extends javax.swing.JPanel {
@ -33,6 +34,7 @@ final class GeneralPanel extends javax.swing.JPanel {
GeneralPanel(GeneralOptionsPanelController controller) { GeneralPanel(GeneralOptionsPanelController controller) {
this.controller = controller; this.controller = controller;
initComponents(); initComponents();
ContentUtils.setDisplayInLocalTime(useLocalTimeRB.isSelected());
// TODO listen to changes in form fields and call controller.changed() // TODO listen to changes in form fields and call controller.changed()
} }
@ -80,6 +82,11 @@ final class GeneralPanel extends javax.swing.JPanel {
buttonGroup3.add(useGMTTimeRB); buttonGroup3.add(useGMTTimeRB);
org.openide.awt.Mnemonics.setLocalizedText(useGMTTimeRB, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.useGMTTimeRB.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(useGMTTimeRB, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.useGMTTimeRB.text")); // NOI18N
useGMTTimeRB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
useGMTTimeRBActionPerformed(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel3.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GeneralPanel.class, "GeneralPanel.jLabel3.text")); // NOI18N
@ -144,6 +151,10 @@ final class GeneralPanel extends javax.swing.JPanel {
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_useBestViewerRBActionPerformed }//GEN-LAST:event_useBestViewerRBActionPerformed
private void useGMTTimeRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useGMTTimeRBActionPerformed
ContentUtils.setDisplayInLocalTime(useLocalTimeRB.isSelected());
}//GEN-LAST:event_useGMTTimeRBActionPerformed
void load() { void load() {
boolean keepPreferredViewer = prefs.getBoolean(KEEP_PREFERRED_VIEWER, false); boolean keepPreferredViewer = prefs.getBoolean(KEEP_PREFERRED_VIEWER, false);
keepCurrentViewerRB.setSelected(keepPreferredViewer); keepCurrentViewerRB.setSelected(keepPreferredViewer);

View File

@ -50,7 +50,7 @@ public final class ContentUtils {
private final static Logger logger = Logger.getLogger(ContentUtils.class.getName()); private final static Logger logger = Logger.getLogger(ContentUtils.class.getName());
private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
private static final SimpleDateFormat dateFormatterISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); private static final SimpleDateFormat dateFormatterISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private static boolean displayInLocalTime;
// don't instantiate // don't instantiate
private ContentUtils() { private ContentUtils() {
throw new AssertionError(); throw new AssertionError();
@ -104,12 +104,11 @@ public final class ContentUtils {
public static String getStringTimeISO8601(long epochSeconds, Content c) { public static String getStringTimeISO8601(long epochSeconds, Content c) {
return getStringTimeISO8601(epochSeconds, getTimeZone(c)); return getStringTimeISO8601(epochSeconds, getTimeZone(c));
} }
public static TimeZone getTimeZone(Content c) { public static TimeZone getTimeZone(Content c) {
Preferences generalPanelPrefs = NbPreferences.root().node("/org/sleuthkit/autopsy/core");
boolean useLocalTime = generalPanelPrefs.getBoolean("useLocalTime", true);
try { try {
if (!useLocalTime) { if (!getDisplayInLocalTime()) {
return TimeZone.getTimeZone("GMT"); return TimeZone.getTimeZone("GMT");
} }
else { else {
@ -360,4 +359,18 @@ public final class ContentUtils {
+ cntnt.getClass().getSimpleName()); + cntnt.getClass().getSimpleName());
} }
} }
/**sets displayInlocalTime value based on button in GeneralPanel.java
*
* @param flag
*/
public static void setDisplayInLocalTime(boolean flag) {
displayInLocalTime = flag;
}
/** get global timezone setting for displaying time values
*
* @return
*/
public static boolean getDisplayInLocalTime(){
return displayInLocalTime;
}
} }

View File

@ -41,7 +41,9 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Scanner; import java.util.Scanner;
import java.util.Stack; import java.util.Stack;
import java.util.TimeZone;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.prefs.Preferences;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
@ -75,11 +77,11 @@ import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences; import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration; import org.openide.awt.ActionRegistration;
import org.openide.modules.InstalledFileLocator; import org.openide.modules.InstalledFileLocator;
import org.openide.modules.ModuleInstall;
import org.openide.nodes.Children; import org.openide.nodes.Children;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.util.HelpCtx; import org.openide.util.HelpCtx;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.CallableSystemAction;
import org.openide.util.actions.Presenter; import org.openide.util.actions.Presenter;
import org.openide.util.lookup.Lookups; import org.openide.util.lookup.Lookups;
@ -97,6 +99,7 @@ import org.sleuthkit.autopsy.datamodel.DisplayableItemNodeVisitor;
import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.FileNode;
import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.coreutils.ExecUtil; import org.sleuthkit.autopsy.coreutils.ExecUtil;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
@ -112,7 +115,7 @@ import org.sleuthkit.datamodel.TskCoreException;
* *
*/ */
public class Timeline extends CallableSystemAction implements Presenter.Toolbar, PropertyChangeListener { public class Timeline extends CallableSystemAction implements Presenter.Toolbar, PropertyChangeListener {
private static final Logger logger = Logger.getLogger(Timeline.class.getName()); private static final Logger logger = Logger.getLogger(Timeline.class.getName());
private final java.io.File macRoot = InstalledFileLocator.getDefault().locate("mactime", Timeline.class.getPackage().getName(), false); private final java.io.File macRoot = InstalledFileLocator.getDefault().locate("mactime", Timeline.class.getPackage().getName(), false);
private TimelineFrame mainFrame; //frame for holding all the elements private TimelineFrame mainFrame; //frame for holding all the elements
@ -142,12 +145,11 @@ public class Timeline extends CallableSystemAction implements Presenter.Toolbar,
private EventHandler<MouseEvent> fxMouseExitedListener; private EventHandler<MouseEvent> fxMouseExitedListener;
private SleuthkitCase skCase; private SleuthkitCase skCase;
private boolean fxInited = false; private boolean fxInited = false;
public Timeline() { public Timeline() {
super(); super();
fxInited = Installer.isJavaFxInited(); fxInited = Installer.isJavaFxInited();
// TimeZone.setDefault(TimeZone.getTimeZone("UTC")); //sets the default timezone to UTC unless otherwise stated
} }
//Swing components and JavafX components don't play super well together //Swing components and JavafX components don't play super well together
@ -914,17 +916,35 @@ public class Timeline extends CallableSystemAction implements Presenter.Toolbar,
int prevYear = -1; int prevYear = -1;
YearEpoch ye = null; YearEpoch ye = null;
while (scan.hasNextLine()) { while (scan.hasNextLine()) {
String[] s = scan.nextLine().split(","); //1999-02-08T11:08:08Z, 78706, m..b, rrwxrwxrwx, 0, 0, 8355, /img... String[] s = scan.nextLine().split(","); //1999-02-08T11:08:08Z, 78706, m..b, rrwxrwxrwx, 0, 0, 8355, /img...
// break the date into mon, day and year: Note that the ISO times are in GMT // break the date into year,month,day,hour,minute, and second: Note that the ISO times are in GMT
String[] datetime = s[0].split("T"); //{1999-02-08, 11:08:08Z} String delims = "[T:Z\\-]+"; //split by the delimiters
String[] date = datetime[0].split("-"); // {1999, 02, 08} String[] date = s[0].split(delims); //{1999,02,08,11,08,08,...}
int year = Integer.valueOf(date[0]); int year = Integer.valueOf(date[0]);
int month = Integer.valueOf(date[1]) - 1; //Months are zero indexed: 1 = February, 6 = July, 11 = December int month = Integer.valueOf(date[1]) - 1; //Months are zero indexed: 1 = February, 6 = July, 11 = December
int day = Integer.valueOf(date[2]); //Days are 1 indexed int day = Integer.valueOf(date[2]); //Days are 1 indexed
int hour=Integer.valueOf(date[3]);
int minute=Integer.valueOf(date[4]);
int second=Integer.valueOf(date[5]);
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); //set calendar to GMT due to ISO format
calendar.set(year, month, day, hour, minute, second);
day=calendar.get(Calendar.DAY_OF_MONTH); // this is needed or else timezone change wont work. probably incorrect optimization by compiler
//conversion to GMT
if (!ContentUtils.getDisplayInLocalTime()) {
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
}
else{
calendar.setTimeZone(TimeZone.getDefault());// local timezone OF the user. should be what the user SETS at startup
}
// get the object id out of the modified outpu day=calendar.get(Calendar.DAY_OF_MONTH);//get the day which may be affected by timezone change
long ObjId = Long.valueOf(s[4]); long ObjId = Long.valueOf(s[4]);
// when the year changes, create and add a new YearEpoch object to the list // when the year changes, create and add a new YearEpoch object to the list
@ -961,7 +981,6 @@ public class Timeline extends CallableSystemAction implements Presenter.Toolbar,
// Get report path // Get report path
String bodyFilePath = moduleDir.getAbsolutePath() String bodyFilePath = moduleDir.getAbsolutePath()
+ java.io.File.separator + currentCase.getName() + "-" + datenotime + ".txt"; + java.io.File.separator + currentCase.getName() + "-" + datenotime + ".txt";
// Run query to get all files // Run query to get all files
final String filesAndDirs = "name != '.' " final String filesAndDirs = "name != '.' "
+ "AND name != '..'"; + "AND name != '..'";
@ -1107,7 +1126,7 @@ public class Timeline extends CallableSystemAction implements Presenter.Toolbar,
public void performAction() { public void performAction() {
initTimeline(); initTimeline();
} }
private void initTimeline() { private void initTimeline() {
if (!Case.existsCurrentCase()) { if (!Case.existsCurrentCase()) {
return; return;