Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReplaceContentTagAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.actions;
20 
21 import java.util.Collection;
22 import java.util.concurrent.ExecutionException;
23 import java.util.logging.Level;
24 import javafx.application.Platform;
25 import javafx.scene.control.Alert;
26 import javax.swing.SwingWorker;
27 import org.openide.util.NbBundle;
28 import org.openide.util.Utilities;
33 import org.sleuthkit.datamodel.ContentTag;
34 import org.sleuthkit.datamodel.TagName;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
40 public final class ReplaceContentTagAction extends ReplaceTagAction<ContentTag> {
41 
42  private static final Logger logger = Logger.getLogger(ReplaceContentTagAction.class.getName());
43 
44  private static final long serialVersionUID = 1L;
45 
46  // This class is a singleton to support multi-selection of nodes, since
47  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
48  // node in the array returns a reference to the same action object from Node.getActions(boolean).
50 
51  public static synchronized ReplaceContentTagAction getInstance() {
52  if (null == instance) {
53  instance = new ReplaceContentTagAction();
54  }
55  return instance;
56  }
57 
59  super(MENU_TEXT);
60  }
61 
62  @NbBundle.Messages({
63  "# {0} - old tag name",
64  "# {1} - content obj id",
65  "ReplaceContentTagAction.replaceTag.alert=Unable to replace tag {0} for {1}."})
66  @Override
67  protected void replaceTag(ContentTag oldTag, TagName newTagName, String newComment) {
68  new SwingWorker<Void, Void>() {
69 
70  @Override
71  protected Void doInBackground() throws Exception {
72  TagsManager tagsManager;
73  try {
75  } catch (NoCurrentCaseException ex) {
76  logger.log(Level.SEVERE, "Error replacing artifact tag. No open case found.", ex); //NON-NLS
77  Platform.runLater(()
78  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceContentTagAction_replaceTag_alert(oldTag.getName().getDisplayName(), oldTag.getContent().getName())).show()
79  );
80  return null;
81  }
82 
83  try {
84  logger.log(Level.INFO, "Replacing tag {0} with tag {1} for artifact {2}", new Object[]{oldTag.getName().getDisplayName(), newTagName.getDisplayName(), oldTag.getContent().getName()}); //NON-NLS
85 
86  tagsManager.deleteContentTag(oldTag);
87  tagsManager.addContentTag(oldTag.getContent(), newTagName, newComment);
88 
89  } catch (TskCoreException tskCoreException) {
90  logger.log(Level.SEVERE, "Error replacing artifact tag", tskCoreException); //NON-NLS
91  Platform.runLater(()
92  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceContentTagAction_replaceTag_alert(oldTag.getName().getDisplayName(), oldTag.getContent().getName())).show()
93  );
94  }
95  return null;
96  }
97 
98  @Override
99  protected void done() {
100  super.done();
101  try {
102  get();
103  } catch (InterruptedException | ExecutionException ex) {
104  logger.log(Level.SEVERE, "Unexpected exception while replacing content tag", ex); //NON-NLS
105  }
106  }
107  }.execute();
108  }
109 
115  @Override
116  Collection<? extends ContentTag> getTagsToReplace() {
117  return Utilities.actionsGlobalContext().lookupAll(ContentTag.class);
118  }
119 
120 }
static synchronized ReplaceContentTagAction getInstance()
ContentTag addContentTag(Content content, TagName tagName)
void replaceTag(ContentTag oldTag, TagName newTagName, String newComment)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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