diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java index 9bf28e0d81..3c681439cc 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java @@ -22,6 +22,7 @@ import java.awt.Cursor; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import java.util.prefs.Preferences; import org.sleuthkit.autopsy.coreutils.Logger; import javax.swing.JTabbedPane; @@ -36,9 +37,8 @@ import org.openide.util.NbPreferences; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; -import org.sleuthkit.autopsy.datamodel.ContentUtils; -import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskCoreException; /** * Top component that organizes all of the data content viewers. Doing a lookup on this class will @@ -46,6 +46,8 @@ import org.sleuthkit.datamodel.Content; */ // Registered as a service provider in layer.xml public final class DataContentTopComponent extends TopComponent implements DataContent, ChangeListener { + + private static Logger logger = Logger.getLogger(DataContentTopComponent.class.getName()); // reference to the "default" TC that always stays open private static DataContentTopComponent defaultInstance; @@ -170,14 +172,13 @@ public final class DataContentTopComponent extends TopComponent implements DataC public static synchronized DataContentTopComponent findInstance() { TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); if (win == null) { - Logger.getLogger(DataContentTopComponent.class.getName()).warning( - "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); + logger.warning("Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); return getDefault(); } if (win instanceof DataContentTopComponent) { return (DataContentTopComponent) win; } - Logger.getLogger(DataContentTopComponent.class.getName()).warning( + logger.warning( "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior."); return getDefault(); @@ -242,7 +243,13 @@ public final class DataContentTopComponent extends TopComponent implements DataC } else { Content content = selectedNode.getLookup().lookup(Content.class); if (content != null) { - String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); + //String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); + String path = defaultName; + try { + path = content.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Exception while calling Content.getUniquePath() for " + content); + } setName(path); } else { setName(defaultName); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java index 9e576bbca1..8c0d476d3b 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java @@ -18,21 +18,21 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Set; +import java.util.logging.Level; import org.openide.nodes.Sheet; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.TskData.TSK_FS_META_FLAG_ENUM; -import org.sleuthkit.datamodel.TskData.TSK_FS_META_MODE_ENUM; -import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM; +import org.sleuthkit.datamodel.TskCoreException; /** * Abstract class that implements the commonality between File and Directory * Nodes (same properties). */ public abstract class AbstractFsContentNode extends AbstractAbstractFileNode { + + private static Logger logger = Logger.getLogger(AbstractFsContentNode.class.getName()); // Note: this order matters for the search result, changed it if the order of property headers on the "KeywordSearchNode"changed public static enum FsContentPropertyType { @@ -208,8 +208,15 @@ public abstract class AbstractFsContentNode extends Abstrac */ public static void fillPropertyMap(Map map, FsContent content) { + String path = ""; + try { + path = content.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + content); + } + map.put(FsContentPropertyType.NAME.toString(), getFsContentName(content)); - map.put(FsContentPropertyType.LOCATION.toString(), DataConversion.getformattedPath(ContentUtils.getDisplayPath(content), 0, 1)); + map.put(FsContentPropertyType.LOCATION.toString(), path); map.put(FsContentPropertyType.MOD_TIME.toString(), ContentUtils.getStringTime(content.getMtime(), content)); map.put(FsContentPropertyType.CHANGED_TIME.toString(), ContentUtils.getStringTime(content.getCtime(), content)); map.put(FsContentPropertyType.ACCESS_TIME.toString(), ContentUtils.getStringTime(content.getAtime(), content)); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java b/Core/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java index ef75b1de5d..a52bf2399a 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java @@ -27,6 +27,7 @@ import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskException; /** @@ -105,18 +106,26 @@ public class ArtifactStringContent implements StringContent { buffer.append(""); } + final Content content = getAssociatedContent(wrapped); + + String path = ""; + try { + path = content.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + content); + } + //add file path buffer.append(""); buffer.append("Source File"); buffer.append(""); - final Content content = getAssociatedContent(wrapped); buffer.append(content.getName()); buffer.append(""); buffer.append(""); buffer.append(""); buffer.append("Source File Path"); buffer.append(""); - buffer.append(DataConversion.getformattedPath(ContentUtils.getDisplayPath(content), 0, 1)); + buffer.append(path); buffer.append(""); buffer.append(""); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java index ecb955911c..edc943f4ef 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; -import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Sheet; import org.openide.util.Lookup; @@ -33,6 +32,7 @@ import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskException; /** @@ -101,13 +101,19 @@ public class BlackboardArtifactNode extends DisplayableItemNode { entry.getValue())); } + String path = ""; + try { + path = associated.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + associated); + } final int artifactTypeID = artifact.getArtifactTypeID(); if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID() || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) { ss.put(new NodeProperty("File Path", "File Path", NO_DESCR, - DataConversion.getformattedPath(ContentUtils.getDisplayPath(associated), 0, 1))); + path)); } return s; diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java b/Core/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java index 0fec1e31a0..ac942b94b2 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java @@ -22,29 +22,19 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; import java.util.TimeZone; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; import javax.swing.SwingWorker; import org.netbeans.api.progress.ProgressHandle; -import org.openide.util.Exceptions; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentVisitor; import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.Image; -import org.sleuthkit.datamodel.VirtualDirectory; import org.sleuthkit.datamodel.LayoutFile; import org.sleuthkit.datamodel.ReadContentInputStream; -import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.datamodel.Volume; -import org.sleuthkit.datamodel.VolumeSystem; /** * Static class of utility methods for Content objects @@ -60,18 +50,7 @@ public final class ContentUtils { private ContentUtils() { throw new AssertionError(); } - private static final ShortNameVisitor shortName = new ShortNameVisitor(); - private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public static String[] getDisplayPath(Content content) { - return content.accept(getDisplayPath).toArray(new String[]{}); - } - + /** * Convert epoch seconds to a string value in the given time zone * @@ -131,17 +110,7 @@ public final class ContentUtils { } } private static final SystemNameVisitor systemName = new SystemNameVisitor(); - private static final GetPathVisitor getSystemPath = new GetPathVisitor(systemName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public static String[] getSystemPath(Content content) { - return content.accept(getSystemPath).toArray(new String[]{}); - } - + static String getSystemName(Content content) { return content.accept(systemName); } @@ -153,148 +122,10 @@ public final class ContentUtils { @Override protected String defaultVisit(Content cntnt) { - return cntnt.accept(shortName) + ":" + Long.toString(cntnt.getId()); + return cntnt.getName() + ":" + Long.toString(cntnt.getId()); } } - private static class ShortNameVisitor extends ContentVisitor.Default { - - ShortNameVisitor() { - } - - @Override - protected String defaultVisit(Content cntnt) { - return cntnt.getName(); - } - } - - private static class GetPathVisitor implements ContentVisitor> { - - ContentVisitor toString; - - GetPathVisitor(ContentVisitor toString) { - this.toString = toString; - } - - @Override - public List visit(LayoutFile lay) { - Content parent = null; - try { - parent = lay.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + LayoutFile.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(lay)); - } - return path; - } - - @Override - public List visit(VirtualDirectory ld) { - Content parent = null; - try { - parent = ld.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + VirtualDirectory.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(ld)); - } - return path; - } - - @Override - public List visit(Directory dir) { - Content parent = null; - try { - parent = dir.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + Directory.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(dir)); - } - return path; - } - - @Override - public List visit(File file) { - Content parent = null; - try { - parent = file.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + File.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(file)); - } - return path; - } - - @Override - public List visit(FileSystem fs) { - Content parent = null; - try { - parent = fs.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + FileSystem.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(fs)); - } - return path; - } - - @Override - public List visit(Image image) { - List path = new LinkedList(); - path.add(toString.visit(image)); - return path; - } - - @Override - public List visit(Volume volume) { - Content parent = null; - try { - parent = volume.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + Volume.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(volume)); - } - return path; - } - - @Override - public List visit(VolumeSystem vs) { - Content parent = null; - try { - parent = vs.getParent(); - } catch (TskCoreException ex) { - throw new RuntimeException("Problem getting parent from " + VolumeSystem.class.getName(), ex); - } - List path = Collections.EMPTY_LIST; - if (parent != null) { - path = parent.accept(this); - path.add(toString.visit(vs)); - } - return path; - } - } private static final int TO_FILE_BUFFER_SIZE = 8192; /** diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataConversion.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataConversion.java index 292fbe68fa..876feaefad 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataConversion.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataConversion.java @@ -108,29 +108,4 @@ public class DataConversion { return Arrays.toString(binary); } } - - - /** - * Converts the given paths into the formatted path. This mainly used for - * the paths for the "new directory table" and "new output view". - * Will return path from beginIndex to ((length of paths) - endIndex) - * - * @param paths the given paths - * @param beginIndex the starting index of the given paths - * @param endIndex the ending index - * @return path the formatted path - * - * @author jantonius - */ - public static String getformattedPath(String[] paths, int beginIndex, int endIndex) { - String result = ""; - for (int i = beginIndex; i < (paths.length - endIndex); i++) { - result = result + "\\" + paths[i]; - } - return result; - } - - public static String getformattedPath(String[] paths, int index) { - return getformattedPath(paths, index, 0); - } } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/VirtualDirectoryNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/VirtualDirectoryNode.java index 5e9ab5dc8c..0bc44c0c8d 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/VirtualDirectoryNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/VirtualDirectoryNode.java @@ -20,8 +20,11 @@ package org.sleuthkit.autopsy.datamodel; import java.util.LinkedHashMap; import java.util.Map; +import java.util.logging.Level; import org.openide.nodes.Sheet; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.LayoutFileNode.LayoutContentPropertyType; +import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.VirtualDirectory; import org.sleuthkit.datamodel.TskData; @@ -29,6 +32,8 @@ import org.sleuthkit.datamodel.TskData; * Node for layout dir */ public class VirtualDirectoryNode extends AbstractAbstractFileNode { + + private static Logger logger = Logger.getLogger(VirtualDirectoryNode.class.getName()); public static String nameForLayoutFile(VirtualDirectory ld) { return ld.getName(); @@ -87,10 +92,18 @@ public class VirtualDirectoryNode extends AbstractAbstractFileNode map, VirtualDirectory content) { + + String path = ""; + try { + path = content.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + content); + } + map.put(LayoutContentPropertyType.NAME.toString(), content.getName()); map.put(LayoutContentPropertyType.SIZE.toString(), content.getSize()); - map.put(AbstractFsContentNode.FsContentPropertyType.LOCATION.toString(), DataConversion.getformattedPath(ContentUtils.getDisplayPath(content), 0, 1)); + map.put(AbstractFsContentNode.FsContentPropertyType.LOCATION.toString(), path); map.put(AbstractFsContentNode.FsContentPropertyType.MOD_TIME.toString(), ContentUtils.getStringTime(0, content)); map.put(AbstractFsContentNode.FsContentPropertyType.CHANGED_TIME.toString(), ContentUtils.getStringTime(0, content)); map.put(AbstractFsContentNode.FsContentPropertyType.ACCESS_TIME.toString(), ContentUtils.getStringTime(0, content)); diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java index 8f491040fa..32fba54b80 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java @@ -20,21 +20,22 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; +import java.util.logging.Level; import javax.swing.AbstractAction; import org.openide.nodes.Node; import org.openide.windows.Mode; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.datamodel.ContentUtils; -import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskCoreException; /** * Opens new ContentViewer pane in a detached window */ public class NewWindowViewAction extends AbstractAction{ + + private static Logger logger = Logger.getLogger(NewWindowViewAction.class.getName()); private Node contentNode ; @@ -48,14 +49,19 @@ public class NewWindowViewAction extends AbstractAction{ Logger.noteAction(this.getClass()); String name = "DataContent"; - Content c = contentNode.getLookup().lookup(Content.class); - if (c != null) { - String[] filePaths = ContentUtils.getDisplayPath(c); - name = DataConversion.getformattedPath(filePaths, 0); - } String s = contentNode.getLookup().lookup(String.class); - if (s != null) + if (s != null) { name = s; + } else { + Content c = contentNode.getLookup().lookup(Content.class); + if (c != null) { + try { + name = c.getUniquePath(); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + c); + } + } + } DataContentTopComponent dctc = DataContentTopComponent.createUndocked(name, this.contentNode);