19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.logging.Level;
35 import org.
sleuthkit.datamodel.blackboardutils.CommunicationArtifactsHelper;
40 final class XRYContactsFileParser
extends AbstractSingleEntityParser {
42 private static final Logger logger = Logger.getLogger(XRYContactsFileParser.class.getName());
45 boolean canProcess(XRYKeyValuePair pair) {
46 return XryKey.contains(pair.getKey());
50 boolean isNamespace(String nameSpace) {
56 void makeArtifact(List<XRYKeyValuePair> keyValuePairs, Content parent, SleuthkitCase currentCase)
throws TskCoreException, Blackboard.BlackboardException {
59 String contactName = null;
60 String phoneNumber = null;
61 String homePhoneNumber = null;
62 String mobilePhoneNumber = null;
63 String emailAddr = null;
64 boolean hasAnEmail =
false;
65 final Collection<BlackboardAttribute> additionalAttributes =
new ArrayList<>();
67 for (XRYKeyValuePair pair : keyValuePairs) {
68 XryKey xryKey = XryKey.fromDisplayName(pair.getKey());
71 if (contactName != null) {
72 additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, PARSER_NAME, pair.getValue()));
74 contactName = pair.getValue();
78 if (!XRYUtils.isPhoneValid(pair.getValue())) {
82 if (phoneNumber != null) {
83 additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, PARSER_NAME, pair.getValue()));
85 phoneNumber = pair.getValue();
89 if (!XRYUtils.isPhoneValid(pair.getValue())) {
93 if (mobilePhoneNumber != null) {
94 additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_MOBILE, PARSER_NAME, pair.getValue()));
96 mobilePhoneNumber = pair.getValue();
100 if (!XRYUtils.isPhoneValid(pair.getValue())) {
104 if (homePhoneNumber != null) {
105 additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_HOME, PARSER_NAME, pair.getValue()));
107 homePhoneNumber = pair.getValue();
111 if (!XRYUtils.isEmailValid(pair.getValue())) {
116 additionalAttributes.add(
new BlackboardAttribute(
117 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_HOME,
118 PARSER_NAME, pair.getValue()));
123 if (xryKey.getType() != null) {
124 additionalAttributes.add(
new BlackboardAttribute(xryKey.getType(),
125 PARSER_NAME, pair.getValue()));
128 logger.log(Level.INFO, String.format(
"[XRY DSP] Key value pair "
129 +
"(in brackets) [ %s ] was recognized but "
130 +
"more data or time is needed to finish implementation. Discarding... ",
137 if (phoneNumber != null || homePhoneNumber != null || mobilePhoneNumber != null || hasAnEmail) {
138 CommunicationArtifactsHelper helper =
new CommunicationArtifactsHelper(
139 currentCase, PARSER_NAME, parent, Account.Type.DEVICE);
141 helper.addContact(contactName, phoneNumber, homePhoneNumber,
142 mobilePhoneNumber, emailAddr, additionalAttributes);
145 if (!additionalAttributes.isEmpty()) {
146 BlackboardArtifact artifact = parent.newDataArtifact(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT), additionalAttributes);
148 currentCase.getBlackboard().postArtifact(artifact, PARSER_NAME);
165 ADDRESS_HOME(
"address home", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION),
167 DELETED(
"deleted", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ISDELETED),
176 private final BlackboardAttribute.ATTRIBUTE_TYPE
type;
178 XryKey(String name, BlackboardAttribute.ATTRIBUTE_TYPE type) {
183 BlackboardAttribute.ATTRIBUTE_TYPE
getType() {
194 }
catch (IllegalArgumentException ex) {
207 String normalizedKey = key.trim().toLowerCase();
209 if (normalizedKey.equals(keyChoice.name)) {
214 throw new IllegalArgumentException(String.format(
"Key [%s] was not found."
215 +
" All keys should be tested with contains.", key));