Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
HostNameValidator.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.datamodel.hosts;
20 
21 import java.util.Collection;
22 import java.util.Set;
23 import java.util.stream.Collectors;
24 import java.util.stream.Stream;
25 import org.apache.commons.lang3.StringUtils;
26 import org.openide.util.NbBundle;
27 import org.sleuthkit.datamodel.Host;
28 
32 public class HostNameValidator {
33 
45  @NbBundle.Messages({
46  "HostNameValidator_getValidationMessage_onEmpty=Please provide some text for the host name.",
47  "HostNameValidator_getValidationMessage_sameAsOriginal=Please provide a new name for this host.",
48  "HostNameValidator_getValidationMessage_onDuplicate=Another host already has the same name. Please choose a different name.",})
49  public static String getValidationMessage(String curName, String initialName, Set<String> currentHostsTrimmedUpper) {
50 
51  if (StringUtils.isBlank(curName)) {
52  return Bundle.HostNameValidator_getValidationMessage_onEmpty();
53  }
54 
55  if (StringUtils.equalsIgnoreCase(initialName, curName)) {
56  return Bundle.HostNameValidator_getValidationMessage_sameAsOriginal();
57  }
58 
59  if (currentHostsTrimmedUpper.contains(curName.trim().toUpperCase())) {
60  return Bundle.HostNameValidator_getValidationMessage_onDuplicate();
61  }
62 
63  return null;
64  }
65 
73  public static Set<String> getSanitizedHostNames(Collection<Host> hosts) {
74  Stream<Host> hostsStream = hosts != null ? hosts.stream() : Stream.empty();
75  return hostsStream
76  .map(h -> h == null ? null : h.getName())
77  .filter(hName -> StringUtils.isNotBlank(hName))
78  .map(hName -> hName.trim().toUpperCase())
79  .collect(Collectors.toSet());
80  }
81 }
static String getValidationMessage(String curName, String initialName, Set< String > currentHostsTrimmedUpper)
static Set< String > getSanitizedHostNames(Collection< Host > hosts)

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