Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
EditRulePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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.logicalimager.configuration;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JButton;
27 import javax.swing.JPanel;
28 import javax.swing.JTextArea;
29 import javax.swing.text.JTextComponent;
30 import static org.apache.commons.lang.StringUtils.isBlank;
31 import static org.apache.commons.lang3.StringUtils.strip;
32 import org.apache.commons.lang3.tuple.ImmutablePair;
33 import org.openide.util.NbBundle;
35 
39 final class EditRulePanel extends JPanel {
40 
41  private static final long serialVersionUID = 1L;
42  private final EditFullPathsRulePanel editFullPathsRulePanel;
43  private final EditNonFullPathsRulePanel editNonFullPathsRulePanel;
44 
48  EditRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule) {
49  if (rule.getFullPaths() != null && rule.getFullPaths().size() > 0) {
50  editFullPathsRulePanel = new EditFullPathsRulePanel(okButton, cancelButton, ruleName, rule, true);
51  editNonFullPathsRulePanel = null;
52  } else {
53  editNonFullPathsRulePanel = new EditNonFullPathsRulePanel(okButton, cancelButton, ruleName, rule, true);
54  editFullPathsRulePanel = null;
55  }
56  }
57 
58  JPanel getPanel() {
59  if (editFullPathsRulePanel != null) {
60  return editFullPathsRulePanel;
61  } else {
62  return editNonFullPathsRulePanel;
63  }
64  }
65 
66  ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
67  ImmutablePair<String, LogicalImagerRule> ruleMap;
68  if (editFullPathsRulePanel != null) {
69  ruleMap = editFullPathsRulePanel.toRule();
70  } else {
71  ruleMap = editNonFullPathsRulePanel.toRule();
72  }
73  return ruleMap;
74  }
75 
76  static void setTextFieldPrompts(JTextComponent textField, String text) {
80  TextPrompt textPrompt;
81  if (textField instanceof JTextArea) {
82  textPrompt = new TextPrompt(text, textField, BorderLayout.NORTH);
83  } else {
84  textPrompt = new TextPrompt(text, textField);
85  }
86 
90  textPrompt.setForeground(Color.LIGHT_GRAY);
91  textPrompt.changeAlpha(0.9f); // Mostly opaque
92  }
93 
94  @NbBundle.Messages({
95  "EditRulePanel.emptyRuleName.message=Rule name cannot be empty",
96  "# {0} - ruleName",
97  "EditRulePanel.reservedRuleName.message=Rule name \"{0}\" is reserved for use with a predefined rule"})
98  static String validRuleName(String name) throws IOException {
99  if (name.isEmpty()) {
100  throw new IOException(Bundle.EditRulePanel_emptyRuleName_message());
101  }
102  if (name.equals(EncryptionProgramsRule.getName())) {
103  throw new IOException(Bundle.EditRulePanel_reservedRuleName_message(name));
104  }
105  //TODO JIRA-5239 check if rule name exists already
106  return name;
107  }
108 
109  @NbBundle.Messages({
110  "# {0} - fieldName",
111  "EditRulePanel.blankLineException={0} cannot have a blank line",})
112  static List<String> validateTextList(JTextArea textArea, String fieldName) throws IOException {
113  if (isBlank(textArea.getText())) {
114  return null;
115  }
116  List<String> list = new ArrayList<>();
117  for (String line : textArea.getText().split("\\n")) { // NON-NLS
118  String strippedLine = strip(line);
119  if (strippedLine.isEmpty()) {
120  throw new IOException(Bundle.EditRulePanel_blankLineException(fieldName));
121  }
122  list.add(strippedLine);
123  }
124  if (list.isEmpty()) {
125  return null;
126  }
127  return list;
128  }
129 
130 }

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.