Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
CustomWebCategorizer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.url.analytics.domaincategorization;
20 
21 import java.sql.SQLException;
22 import java.util.logging.Level;
23 import org.apache.commons.lang3.StringUtils;
24 import org.openide.util.lookup.ServiceProvider;
29 
35 @ServiceProvider(service = DomainCategorizer.class)
36 public class CustomWebCategorizer implements DomainCategorizer {
37 
38  private static final Logger logger = Logger.getLogger(CustomWebCategorizer.class.getName());
39 
40  private final WebCategoriesDataModel dataModel;
41 
47  CustomWebCategorizer(WebCategoriesDataModel dataModel) {
48  this.dataModel = dataModel;
49  }
50 
57  this(WebCategoriesDataModel.getInstance());
58  }
59 
60  @Override
61  public DomainCategory getCategory(String domain, String host) throws DomainCategorizerException {
62  if (!dataModel.isInitialized()) {
63  return null;
64  }
65  String hostToUse = (StringUtils.isBlank(host)) ? domain : host;
66  if (StringUtils.isBlank(hostToUse)) {
67  return null;
68  }
69 
70  hostToUse = hostToUse.toLowerCase();
71 
72  try {
73  return dataModel.getMatchingRecord(hostToUse);
74  } catch (SQLException ex) {
75  logger.log(Level.WARNING, "There was an error while retrieving data for: " + hostToUse, ex);
76  return null;
77  }
78  }
79 
80  @Override
81  public void initialize() throws DomainCategorizerException {
82  try {
83  dataModel.initialize();
84  } catch (SQLException ex) {
85  throw new DomainCategorizerException("Unable to initialize.", ex);
86  }
87  }
88 
89  @Override
90  public void close() throws SQLException {
91  dataModel.close();
92  }
93 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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