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

@ -1,44 +1,54 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2011-2016 Basis Technology Corp. * Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; 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.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 NO_COMMENT = "";
private static final String BOOKMARK = NbBundle.getMessage(BookmarkFileAction.class, "BookmarkFileAction.bookmark.text"); private static final String BOOKMARK = NbBundle.getMessage(BookmarkFileAction.class, "BookmarkFileAction.bookmark.text");
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Map<String, TagName> tagNamesMap = Case.getCurrentCase().getServices().getTagsManager().getPredefinedTagNamesMap(); Map<String, TagName> tagNamesMap = null;
for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) { try {
if (entry.getKey().equals(BOOKMARK)) { tagNamesMap = Case.getCurrentCase().getServices().getTagsManager().getDisplayNamesToTagNamesMap();
AddContentTagAction.getInstance().addTag(entry.getValue(), NO_COMMENT); TagName bookmarkTagName = tagNamesMap.get(BOOKMARK);
return; 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
} }
}
}
} }