Autopsy  4.4
Graphical digital forensics platform for The Sleuth Kit and other tools.
ProfilePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.ingest;
20 
21 import java.beans.PropertyChangeListener;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle;
30 
34 class ProfilePanel extends IngestModuleGlobalSettingsPanel {
35 
36  @NbBundle.Messages({"ProfilePanel.profileDescLabel.text=Description:",
37  "ProfilePanel.profileNameLabel.text=Profile Name:",
38  "ProfilePanel.newProfileText=NewEmptyProfile",
39  "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
40  "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character"})
41 
42  private final IngestJobSettingsPanel ingestSettingsPanel;
43  private final IngestJobSettings settings;
44  private IngestProfile profile;
45  private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.newProfileText");
46  private static final List<String> ILLEGAL_NAME_CHARS = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("\\", "/", ":", "*", "?", "\"", "<", ">")));
47 
51  ProfilePanel() {
52  initComponents();
53  settings = new IngestJobSettings(NEW_PROFILE_NAME);
54  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
55  ingestSettingsPanel.setPastJobsButtonVisible(false);
56  jPanel1.add(ingestSettingsPanel, 0);
57 
58  }
59 
60  ProfilePanel(IngestProfile selectedProfile) {
61  initComponents();
62  profile = selectedProfile;
63  profileDescArea.setText(profile.getDescription());
64  profileNameField.setText(profile.getName());
65  settings = new IngestJobSettings(selectedProfile.getName());
66  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
67  ingestSettingsPanel.setPastJobsButtonVisible(false);
68  jPanel1.add(ingestSettingsPanel, 0);
69  }
70 
78  String getProfileName() {
79  return profileNameField.getText().trim();
80  }
81 
82  String getProfileDesc() {
83  return profileDescArea.getText();
84  }
85 
86  IngestJobSettings getSettings() {
87  return ingestSettingsPanel.getSettings();
88  }
89 
95  @SuppressWarnings("unchecked")
96  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
97  private void initComponents() {
98 
99  jScrollPane1 = new javax.swing.JScrollPane();
100  jPanel2 = new javax.swing.JPanel();
101  profileNameField = new javax.swing.JTextField();
102  profileDescLabel = new javax.swing.JLabel();
103  profileDescPane = new javax.swing.JScrollPane();
104  profileDescArea = new javax.swing.JTextArea();
105  profileNameLabel = new javax.swing.JLabel();
106  jPanel1 = new javax.swing.JPanel();
107 
108  jScrollPane1.setPreferredSize(new java.awt.Dimension(650, 323));
109 
110  org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileDescLabel.text")); // NOI18N
111 
112  profileDescArea.setColumns(20);
113  profileDescArea.setLineWrap(true);
114  profileDescArea.setRows(8);
115  profileDescArea.setWrapStyleWord(true);
116  profileDescArea.setMinimumSize(new java.awt.Dimension(164, 44));
117  profileDescArea.setName(""); // NOI18N
118  profileDescPane.setViewportView(profileDescArea);
119 
120  org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileNameLabel.text")); // NOI18N
121 
122  jPanel1.setMinimumSize(new java.awt.Dimension(625, 450));
123  jPanel1.setPreferredSize(new java.awt.Dimension(625, 450));
124  jPanel1.setLayout(new java.awt.BorderLayout());
125 
126  javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
127  jPanel2.setLayout(jPanel2Layout);
128  jPanel2Layout.setHorizontalGroup(
129  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
130  .addGroup(jPanel2Layout.createSequentialGroup()
131  .addGap(6, 6, 6)
132  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
133  .addComponent(profileDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
134  .addComponent(profileNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
135  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
136  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137  .addComponent(profileDescPane)
138  .addComponent(profileNameField))
139  .addGap(5, 5, 5))
140  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
141  );
142  jPanel2Layout.setVerticalGroup(
143  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144  .addGroup(jPanel2Layout.createSequentialGroup()
145  .addGap(8, 8, 8)
146  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
147  .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
148  .addComponent(profileNameLabel))
149  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
150  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151  .addComponent(profileDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
152  .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
153  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
154  .addGap(2, 2, 2))
155  );
156 
157  jScrollPane1.setViewportView(jPanel2);
158 
159  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
160  this.setLayout(layout);
161  layout.setHorizontalGroup(
162  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
164  );
165  layout.setVerticalGroup(
166  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
168  );
169  }// </editor-fold>//GEN-END:initComponents
170  @Override
171  public void removePropertyChangeListener(PropertyChangeListener l) {
172  ingestSettingsPanel.removePropertyChangeListener(l);
173  }
174 
175  @Override
176  public void addPropertyChangeListener(PropertyChangeListener l) {
177  ingestSettingsPanel.addPropertyChangeListener(l);
178  }
179  // Variables declaration - do not modify//GEN-BEGIN:variables
180  private javax.swing.JPanel jPanel1;
181  private javax.swing.JPanel jPanel2;
182  private javax.swing.JScrollPane jScrollPane1;
183  private javax.swing.JTextArea profileDescArea;
184  private javax.swing.JLabel profileDescLabel;
185  private javax.swing.JScrollPane profileDescPane;
186  private javax.swing.JTextField profileNameField;
187  private javax.swing.JLabel profileNameLabel;
188  // End of variables declaration//GEN-END:variables
189 
193  @Override
194  public void saveSettings() {
195  if (profile == null) {
196  IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
197  } else if (!profile.getName().equals(getProfileName())) {
198  IngestProfile.renameProfile(profile.getName(), getProfileName());
199  }
200  profile = new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileIngestFilter().getName());
201  IngestProfile.saveProfile(profile);
202  ingestSettingsPanel.getSettings().saveAs(getProfileName());
203  }
204 
208  void store() {
209  saveSettings();
210  }
211 
212  void load() {
213  }
214 
220  boolean isValidDefinition() {
221  if (getProfileName().isEmpty()) {
222  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
223  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profilesMustBeNamed"),
224  NotifyDescriptor.WARNING_MESSAGE);
225  DialogDisplayer.getDefault().notify(notifyDesc);
226  return false;
227  }
228  if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
229  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
230  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"),
231  NotifyDescriptor.WARNING_MESSAGE);
232  DialogDisplayer.getDefault().notify(notifyDesc);
233  return false;
234  }
235  return true;
236  }
237 
247  private static boolean containsOnlyLegalChars(String toBeChecked, List<String> illegalChars) {
248  for (String illegalChar : illegalChars) {
249  if (toBeChecked.contains(illegalChar)) {
250  return false;
251  }
252  }
253  return true;
254  }
255 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.