Autopsy  4.19.3
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;
36 import org.sleuthkit.datamodel.ContentTag;
37 import org.sleuthkit.datamodel.TagName;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 public final class ReplaceContentTagAction extends ReplaceTagAction<ContentTag> {
44 
45  private static final Logger logger = Logger.getLogger(ReplaceContentTagAction.class.getName());
46 
47  private static final long serialVersionUID = 1L;
48 
49  // This class is a singleton to support multi-selection of nodes, since
50  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
51  // node in the array returns a reference to the same action object from Node.getActions(boolean).
53 
54  public static synchronized ReplaceContentTagAction getInstance() {
55  if (null == instance) {
56  instance = new ReplaceContentTagAction();
57  }
58  return instance;
59  }
60 
62  super(MENU_TEXT);
63  }
64 
65  @NbBundle.Messages({
66  "# {0} - old tag name",
67  "# {1} - content obj id",
68  "ReplaceContentTagAction.replaceTag.alert=Unable to replace tag {0} for {1}."})
69  @Override
70  protected void replaceTag(ContentTag oldTag, TagName newTagName, String newComment) {
71  new SwingWorker<Void, Void>() {
72 
73  @Override
74  protected Void doInBackground() throws Exception {
75  TagsManager tagsManager;
76  try {
78  } catch (NoCurrentCaseException ex) {
79  logger.log(Level.SEVERE, "Error replacing artifact tag. No open case found.", ex); //NON-NLS
80  Platform.runLater(()
81  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceContentTagAction_replaceTag_alert(oldTag.getName().getDisplayName(), oldTag.getContent().getName())).show()
82  );
83  return null;
84  }
85 
86  try {
87  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
88 
89  // Check if there is an image tag before deleting the content tag.
91  if(imageTag != null) {
93  }
94 
95  tagsManager.deleteContentTag(oldTag);
96  ContentTag newTag = tagsManager.addContentTag(oldTag.getContent(), newTagName, newComment);
97 
98  // Resave the image tag if present.
99  if(imageTag != null) {
100  ContentViewerTagManager.saveTag(newTag, imageTag.getDetails());
101  }
102  } catch (TskCoreException tskCoreException) {
103  logger.log(Level.SEVERE, "Error replacing artifact tag", tskCoreException); //NON-NLS
104  Platform.runLater(()
105  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceContentTagAction_replaceTag_alert(oldTag.getName().getDisplayName(), oldTag.getContent().getName())).show()
106  );
107  }
108  return null;
109  }
110 
111  @Override
112  protected void done() {
113  super.done();
114  try {
115  get();
116  } catch (InterruptedException | ExecutionException ex) {
117  logger.log(Level.SEVERE, "Unexpected exception while replacing content tag", ex); //NON-NLS
118  }
119  }
120  }.execute();
121  }
122 
128  @Override
129  Collection<? extends ContentTag> getTagsToReplace() {
130  return Utilities.actionsGlobalContext().lookupAll(ContentTag.class);
131  }
132 
133 }
static synchronized ReplaceContentTagAction getInstance()
static< T > ContentViewerTag< T > getTag(ContentTag contentTag, Class< T > clazz)
ContentTag addContentTag(Content content, TagName tagName)
void replaceTag(ContentTag oldTag, TagName newTagName, String newComment)
static< T > ContentViewerTag< T > saveTag(ContentTag contentTag, T tagDataBean)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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