Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractContentNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.datamodel;
20 
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.List;
24 import java.util.logging.Level;
25 
26 import org.openide.util.lookup.Lookups;
27 import org.openide.util.Lookup;
31 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
32 import org.sleuthkit.datamodel.Content;
33 import org.sleuthkit.datamodel.SleuthkitCase;
34 import org.sleuthkit.datamodel.TskCoreException;
35 import org.sleuthkit.datamodel.TskData;
36 import org.sleuthkit.datamodel.TskException;
37 
44 public abstract class AbstractContentNode<T extends Content> extends ContentNode {
45 
49  T content;
50  private static final Logger logger = Logger.getLogger(AbstractContentNode.class.getName());
51 
57  AbstractContentNode(T content) {
58  this(content, Lookups.singleton(content) );
59  }
60 
67  AbstractContentNode(T content, Lookup lookup) {
68  //TODO consider child factory for the content children
69  super(new ContentChildren(content), lookup);
70  this.content = content;
71  //super.setName(ContentUtils.getSystemName(content));
72  super.setName("content_" + Long.toString(content.getId())); //NON-NLS
73  }
74 
80  public T getContent() {
81  return content;
82  }
83 
84  @Override
85  public void setName(String name) {
86  super.setName(name);
87  }
88 
89  @Override
90  public String getName() {
91  return super.getName();
92  }
93 
100  public boolean hasVisibleContentChildren() {
101  return contentHasVisibleContentChildren(content);
102  }
103 
111  public static boolean contentHasVisibleContentChildren(Content c){
112  if (c != null) {
113 
114  try {
115  if( ! c.hasChildren()) {
116  return false;
117  }
118  } catch (TskCoreException ex) {
119 
120  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
121  return false;
122  }
123 
124  String query = "SELECT COUNT(obj_id) AS count FROM "
125  + " ( SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId() + " AND type = "
126  + TskData.ObjectType.ARTIFACT.getObjectType()
127  + " INTERSECT SELECT artifact_obj_id FROM blackboard_artifacts WHERE obj_id = " + c.getId()
128  + " AND (artifact_type_id = " + ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
129  + " OR artifact_type_id = " + ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() + ") "
130  + " UNION SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId()
131  + " AND type = " + TskData.ObjectType.ABSTRACTFILE.getObjectType() + ") AS OBJECT_IDS"; //NON-NLS;
132 
133 
134  try (SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query)) {
135  ResultSet resultSet = dbQuery.getResultSet();
136  if(resultSet.next()){
137  return (0 < resultSet.getInt("count"));
138  }
139  } catch (TskCoreException | SQLException | NoCurrentCaseException ex) {
140  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
141  }
142  }
143  return false;
144  }
145 
152  public boolean hasContentChildren() {
153  boolean hasChildren = false;
154 
155  if (content != null) {
156  try {
157  hasChildren = content.hasChildren();
158  } catch (TskCoreException ex) {
159  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + content, ex); //NON-NLS
160  }
161  }
162 
163  return hasChildren;
164  }
165 
172  public List<Long> getContentChildrenIds() {
173  List<Long> childrenIds = null;
174 
175  if (content != null) {
176  try {
177  childrenIds = content.getChildrenIds();
178  } catch (TskCoreException ex) {
179  logger.log(Level.SEVERE, "Error getting children ids, for content: " + content, ex); //NON-NLS
180  }
181  }
182 
183  return childrenIds;
184 
185  }
186 
192  public List<Content> getContentChildren() {
193  List<Content> children = null;
194 
195  if (content != null) {
196  try {
197  children = content.getChildren();
198  } catch (TskCoreException ex) {
199  logger.log(Level.SEVERE, "Error getting children, for content: " + content, ex); //NON-NLS
200  }
201  }
202 
203  return children;
204 
205  }
206 
214  public int getContentChildrenCount() {
215  int childrenCount = -1;
216 
217  if (content != null) {
218  try {
219  childrenCount = content.getChildrenCount();
220  } catch (TskCoreException ex) {
221  logger.log(Level.SEVERE, "Error checking node content children count, for content: " + content, ex); //NON-NLS
222  }
223  }
224 
225  return childrenCount;
226  }
227 
240  public int read(byte[] buf, long offset, long len) throws TskException {
241  return content.read(buf, offset, len);
242  }
243 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.