Autopsy  4.7.0
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  String query = "SELECT COUNT(obj_id) AS count FROM "
114  + " ( SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId() + " AND type = "
115  + TskData.ObjectType.ARTIFACT.getObjectType()
116  + " INTERSECT SELECT artifact_obj_id FROM blackboard_artifacts WHERE obj_id = " + c.getId()
117  + " AND (artifact_type_id = " + ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
118  + " OR artifact_type_id = " + ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() + ") "
119  + " UNION SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId()
120  + " AND type = " + TskData.ObjectType.ABSTRACTFILE.getObjectType() + ") AS OBJECT_IDS"; //NON-NLS;
121 
122 
123  try (SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCaseThrows().getSleuthkitCase().executeQuery(query)) {
124  ResultSet resultSet = dbQuery.getResultSet();
125  if(resultSet.next()){
126  return (0 < resultSet.getInt("count"));
127  }
128  } catch (TskCoreException | SQLException | NoCurrentCaseException ex) {
129  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
130  }
131  }
132  return false;
133  }
134 
141  public boolean hasContentChildren() {
142  boolean hasChildren = false;
143 
144  if (content != null) {
145  try {
146  hasChildren = content.hasChildren();
147  } catch (TskCoreException ex) {
148  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + content, ex); //NON-NLS
149  }
150  }
151 
152  return hasChildren;
153  }
154 
161  public List<Long> getContentChildrenIds() {
162  List<Long> childrenIds = null;
163 
164  if (content != null) {
165  try {
166  childrenIds = content.getChildrenIds();
167  } catch (TskCoreException ex) {
168  logger.log(Level.SEVERE, "Error getting children ids, for content: " + content, ex); //NON-NLS
169  }
170  }
171 
172  return childrenIds;
173 
174  }
175 
181  public List<Content> getContentChildren() {
182  List<Content> children = null;
183 
184  if (content != null) {
185  try {
186  children = content.getChildren();
187  } catch (TskCoreException ex) {
188  logger.log(Level.SEVERE, "Error getting children, for content: " + content, ex); //NON-NLS
189  }
190  }
191 
192  return children;
193 
194  }
195 
203  public int getContentChildrenCount() {
204  int childrenCount = -1;
205 
206  if (content != null) {
207  try {
208  childrenCount = content.getChildrenCount();
209  } catch (TskCoreException ex) {
210  logger.log(Level.SEVERE, "Error checking node content children count, for content: " + content, ex); //NON-NLS
211  }
212  }
213 
214  return childrenCount;
215  }
216 
229  public int read(byte[] buf, long offset, long len) throws TskException {
230  return content.read(buf, offset, len);
231  }
232 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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