Updated BookmarkFileAction to work with new version of TagsManager

This commit is contained in:
Sophie Mori 2016-10-04 13:38:48 -04:00
parent 83afd06486
commit e8c8d6c8d3

View File

@ -20,25 +20,35 @@ package org.sleuthkit.autopsy.actions;
import java.awt.event.ActionEvent;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.services.TagsManager;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.TagName;
import org.sleuthkit.datamodel.TskCoreException;
class BookmarkFileAction extends AbstractAction {
public class BookmarkFileAction extends AbstractAction {
private static final String NO_COMMENT = "";
private static final String BOOKMARK = NbBundle.getMessage(BookmarkFileAction.class, "BookmarkFileAction.bookmark.text");
@Override
public void actionPerformed(ActionEvent e) {
Map<String, TagName> tagNamesMap = Case.getCurrentCase().getServices().getTagsManager().getPredefinedTagNamesMap();
for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
if (entry.getKey().equals(BOOKMARK)) {
AddContentTagAction.getInstance().addTag(entry.getValue(), NO_COMMENT);
return;
}
Map<String, TagName> tagNamesMap = null;
try {
tagNamesMap = Case.getCurrentCase().getServices().getTagsManager().getDisplayNamesToTagNamesMap();
TagName bookmarkTagName = tagNamesMap.get(BOOKMARK);
if (bookmarkTagName == null) {
bookmarkTagName = Case.getCurrentCase().getServices().getTagsManager().addTagName(BOOKMARK);
}
AddContentTagAction.getInstance().addTag(bookmarkTagName, NO_COMMENT);
} catch (TskCoreException ex) {
Logger.getLogger(BookmarkFileAction.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
} catch (TagsManager.TagNameAlreadyExistsException ex) {
Logger.getLogger(BookmarkFileAction.class.getName()).log(Level.SEVERE, BOOKMARK + " already exists in database.", ex); //NON-NLS
}
}
}