Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EditRulePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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 EditFullPathsRulePanel editFullPathsRulePanel = null;
42  private EditNonFullPathsRulePanel editNonFullPathsRulePanel = null;
43 
47  EditRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule) {
48  if (rule.getFullPaths() != null && rule.getFullPaths().size() > 0) {
49  editFullPathsRulePanel = new EditFullPathsRulePanel(okButton, cancelButton, ruleName, rule, true);
50  } else {
51  editNonFullPathsRulePanel = new EditNonFullPathsRulePanel(okButton, cancelButton, ruleName, rule, true);
52  }
53  }
54 
55  JPanel getPanel() {
56  if (editFullPathsRulePanel != null) {
57  return editFullPathsRulePanel;
58  } else {
59  return editNonFullPathsRulePanel;
60  }
61  }
62 
63  ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
64  ImmutablePair<String, LogicalImagerRule> ruleMap;
65  if (editFullPathsRulePanel != null) {
66  ruleMap = editFullPathsRulePanel.toRule();
67  } else {
68  ruleMap = editNonFullPathsRulePanel.toRule();
69  }
70  return ruleMap;
71  }
72 
73  static void setTextFieldPrompts(JTextComponent textField, String text) {
77  TextPrompt textPrompt;
78  if (textField instanceof JTextArea) {
79  textPrompt = new TextPrompt(text, textField, BorderLayout.NORTH);
80  } else {
81  textPrompt = new TextPrompt(text, textField);
82  }
83 
87  textPrompt.setForeground(Color.LIGHT_GRAY);
88  textPrompt.changeAlpha(0.9f); // Mostly opaque
89  }
90 
91  @NbBundle.Messages({
92  "EditRulePanel.validateRuleNameExceptionMsg=Rule name cannot be empty"
93  })
94  static String validRuleName(String name) throws IOException {
95  if (name.isEmpty()) {
96  throw new IOException(Bundle.EditRulePanel_validateRuleNameExceptionMsg());
97  }
98  return name;
99  }
100 
101  @NbBundle.Messages({
102  "# {0} - fieldName",
103  "EditRulePanel.blankLineException={0} cannot have a blank line",
104  })
105  static List<String> validateTextList(JTextArea textArea, String fieldName) throws IOException {
106  if (isBlank(textArea.getText())) {
107  return null;
108  }
109  List<String> list = new ArrayList<>();
110  for (String line : textArea.getText().split("\\n")) { // NON-NLS
111  line = strip(line);
112  if (line.isEmpty()) {
113  throw new IOException(Bundle.EditRulePanel_blankLineException(fieldName));
114  }
115  list.add(line);
116  }
117  if (list.isEmpty()) {
118  return null;
119  }
120  return list;
121  }
122 
123 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.