/*
 * Autopsy Forensic Browser
 * 
 * Copyright 2011 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.datamodel;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.ContentVisitor;
import org.sleuthkit.datamodel.DerivedFile;
import org.sleuthkit.datamodel.File;
import org.sleuthkit.datamodel.FsContent;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;

/**
 *
 * @author dfickling
 */
class FileSearchFilterChildren extends ChildFactory<Content> {

    SleuthkitCase skCase;
    SearchFilters.SearchFilterInterface filter;
    Logger logger = Logger.getLogger(FileSearchFilterChildren.class.getName());
    //private final static int MAX_OBJECTS = 2000;

    public FileSearchFilterChildren(SearchFilters.SearchFilterInterface filter, SleuthkitCase skCase) {
        this.filter = filter;
        this.skCase = skCase;
    }

    @Override
    protected boolean createKeys(List<Content> list) {
        list.addAll(runQuery());
        return true;
    }

    
    private String createQuery(){
        String query = "known <> 1 AND (0";
        for(String s : filter.getFilter()){
            query += " OR name LIKE '%" + s + "'";
        }
        query += ')';
        //query += " LIMIT " + MAX_OBJECTS;
        return query;
    }

    
    private List<FsContent> runQuery(){
        List<FsContent> list = new ArrayList<FsContent>();
        try {
            List<FsContent> res = skCase.findFilesWhere(createQuery());
            for(FsContent c : res){
                if(c.isFile()){
                    list.add(c);
                }
            }
        } catch (TskCoreException ex) {
            logger.log(Level.WARNING, "Couldn't get search results", ex);
        }

        return list;
        
    }

    @Override
    protected Node createNodeForKey(Content key) {
        return key.accept(new ContentVisitor.Default<AbstractNode>() {
            @Override
            public FileNode visit(File f) {
                return new FileNode(f, false);
            }

            @Override
            public DerivedFileNode visit(DerivedFile df) {
                return new DerivedFileNode(df);
            }

            @Override
            protected AbstractNode defaultVisit(Content di) {
                throw new UnsupportedOperationException("Not supported for this type of Displayable Item: " + di.toString());
            }
        });
    }
}

@@ -725,65 +725,8 @@
 l;%0A%0A
-import java.sql.ResultSet;%0Aimport java.sql.SQLException;%0A
 impo
@@ -956,24 +956,69 @@
 nodes.Node;%0A
+import org.sleuthkit.datamodel.AbstractFile;%0A
 import org.s
@@ -1204,25 +1204,26 @@
 tamodel.
-FsContent
+LayoutFile
 ;%0Aimport
@@ -1322,29 +1322,63 @@
 *%0A *
-%0A * @author dfickling
+ Children factory for the file by type view in dir tree
 %0A */
@@ -1446,16 +1446,24 @@
  %7B%0A%0A    
+private 
 Sleuthki
@@ -1480,16 +1480,24 @@
 se;%0A    
+private 
 SearchFi
@@ -1536,16 +1536,37 @@
 er;%0A    
+private static final 
 Logger l
@@ -2291,25 +2291,28 @@
 te List%3C
-FsContent
+AbstractFile
 %3E runQue
@@ -2330,25 +2330,28 @@
    List%3C
-FsContent
+AbstractFile
 %3E list =
@@ -2365,25 +2365,28 @@
 rayList%3C
-FsContent
+AbstractFile
 %3E();%0A   
@@ -2413,25 +2413,28 @@
    List%3C
-FsContent
+AbstractFile
 %3E res = 
@@ -2444,16 +2444,19 @@
 ase.find
+All
 FilesWhe
@@ -2494,17 +2494,20 @@
 for(
-FsContent
+AbstractFile
  c :
@@ -3027,32 +3027,207 @@
 ;%0A            %7D%0A
+            %0A            @Override%0A            public LayoutFileNode visit(LayoutFile lf) %7B%0A                return new LayoutFileNode(lf);%0A            %7D%0A                      
 %0A            @Ov

add support for carved files in file by type view