Autopsy  4.4.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 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;
30 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.SleuthkitCase;
33 import org.sleuthkit.datamodel.TskCoreException;
34 import org.sleuthkit.datamodel.TskData;
35 import org.sleuthkit.datamodel.TskException;
36 
43 public abstract class AbstractContentNode<T extends Content> extends ContentNode {
44 
48  T content;
49  private static final Logger logger = Logger.getLogger(AbstractContentNode.class.getName());
50 
56  AbstractContentNode(T content) {
57  this(content, Lookups.singleton(content) );
58  }
59 
66  AbstractContentNode(T content, Lookup lookup) {
67  //TODO consider child factory for the content children
68  super(new ContentChildren(content), lookup);
69  this.content = content;
70  //super.setName(ContentUtils.getSystemName(content));
71  super.setName("content_" + Long.toString(content.getId())); //NON-NLS
72  }
73 
79  public T getContent() {
80  return content;
81  }
82 
83  @Override
84  public void setName(String name) {
85  super.setName(name);
86  }
87 
88  @Override
89  public String getName() {
90  return super.getName();
91  }
92 
99  public boolean hasVisibleContentChildren() {
100  return contentHasVisibleContentChildren(content);
101  }
102 
110  public static boolean contentHasVisibleContentChildren(Content c){
111  if (c != null) {
112  String query = "SELECT COUNT(obj_id) AS count FROM "
113  + " ( SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId() + " AND type = "
114  + TskData.ObjectType.ARTIFACT.getObjectType()
115  + " INTERSECT SELECT artifact_obj_id FROM blackboard_artifacts WHERE obj_id = " + c.getId()
116  + " AND (artifact_type_id = " + ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
117  + " OR artifact_type_id = " + ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() + ") "
118  + " UNION SELECT obj_id FROM tsk_objects WHERE par_obj_id = " + c.getId()
119  + " AND type = " + TskData.ObjectType.ABSTRACTFILE.getObjectType() + ") AS OBJECT_IDS"; //NON-NLS;
120 
121 
122  try (SleuthkitCase.CaseDbQuery dbQuery = Case.getCurrentCase().getSleuthkitCase().executeQuery(query)) {
123  ResultSet resultSet = dbQuery.getResultSet();
124  if(resultSet.next()){
125  return (0 < resultSet.getInt("count"));
126  }
127  } catch (TskCoreException | SQLException ex) {
128  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + c, ex); //NON-NLS
129  }
130  }
131  return false;
132  }
133 
140  public boolean hasContentChildren() {
141  boolean hasChildren = false;
142 
143  if (content != null) {
144  try {
145  hasChildren = content.hasChildren();
146  } catch (TskCoreException ex) {
147  logger.log(Level.SEVERE, "Error checking if the node has children, for content: " + content, ex); //NON-NLS
148  }
149  }
150 
151  return hasChildren;
152  }
153 
160  public List<Long> getContentChildrenIds() {
161  List<Long> childrenIds = null;
162 
163  if (content != null) {
164  try {
165  childrenIds = content.getChildrenIds();
166  } catch (TskCoreException ex) {
167  logger.log(Level.SEVERE, "Error getting children ids, for content: " + content, ex); //NON-NLS
168  }
169  }
170 
171  return childrenIds;
172 
173  }
174 
180  public List<Content> getContentChildren() {
181  List<Content> children = null;
182 
183  if (content != null) {
184  try {
185  children = content.getChildren();
186  } catch (TskCoreException ex) {
187  logger.log(Level.SEVERE, "Error getting children, for content: " + content, ex); //NON-NLS
188  }
189  }
190 
191  return children;
192 
193  }
194 
202  public int getContentChildrenCount() {
203  int childrenCount = -1;
204 
205  if (content != null) {
206  try {
207  childrenCount = content.getChildrenCount();
208  } catch (TskCoreException ex) {
209  logger.log(Level.SEVERE, "Error checking node content children count, for content: " + content, ex); //NON-NLS
210  }
211  }
212 
213  return childrenCount;
214  }
215 
228  public int read(byte[] buf, long offset, long len) throws TskException {
229  return content.read(buf, offset, len);
230  }
231 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.