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;
 
   39 final class XRYContactsFileParser 
extends AbstractSingleEntityParser {
 
   41     private static final Logger logger = Logger.getLogger(XRYContactsFileParser.class.getName());
 
   44     boolean canProcess(XRYKeyValuePair pair) {
 
   45         return XryKey.contains(pair.getKey());
 
   49     boolean isNamespace(String nameSpace) {
 
   55     void makeArtifact(List<XRYKeyValuePair> keyValuePairs, Content parent, SleuthkitCase currentCase) 
throws TskCoreException, Blackboard.BlackboardException {
 
   58         String contactName = null;
 
   59         String phoneNumber = null;
 
   60         String homePhoneNumber = null;
 
   61         String mobilePhoneNumber = null;
 
   62         String emailAddr = null;
 
   63         boolean hasAnEmail = 
false;
 
   64         final Collection<BlackboardAttribute> additionalAttributes = 
new ArrayList<>();
 
   66         for (XRYKeyValuePair pair : keyValuePairs) {
 
   67             XryKey xryKey = XryKey.fromDisplayName(pair.getKey());
 
   70                     if (contactName != null) {
 
   71                         additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, PARSER_NAME, pair.getValue()));
 
   73                         contactName = pair.getValue();
 
   77                     if (!XRYUtils.isPhoneValid(pair.getValue())) {
 
   81                     if (phoneNumber != null) {
 
   82                         additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, PARSER_NAME, pair.getValue()));
 
   84                         phoneNumber = pair.getValue();
 
   88                     if (!XRYUtils.isPhoneValid(pair.getValue())) {
 
   92                     if (mobilePhoneNumber != null) {
 
   93                         additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_MOBILE, PARSER_NAME, pair.getValue()));
 
   95                         mobilePhoneNumber = pair.getValue();
 
   99                     if (!XRYUtils.isPhoneValid(pair.getValue())) {
 
  103                     if (homePhoneNumber != null) {
 
  104                         additionalAttributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_HOME, PARSER_NAME, pair.getValue()));
 
  106                         homePhoneNumber = pair.getValue();
 
  110                     if (!XRYUtils.isEmailValid(pair.getValue())) {
 
  115                     additionalAttributes.add(
new BlackboardAttribute(
 
  116                             BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_HOME,
 
  117                             PARSER_NAME, pair.getValue()));
 
  122                     if (xryKey.getType() != null) {
 
  123                         additionalAttributes.add(
new BlackboardAttribute(xryKey.getType(),
 
  124                                 PARSER_NAME, pair.getValue()));
 
  127                     logger.log(Level.INFO, String.format(
"[XRY DSP] Key value pair " 
  128                             + 
"(in brackets) [ %s ] was recognized but " 
  129                             + 
"more data or time is needed to finish implementation. Discarding... ",
 
  136         if (phoneNumber != null || homePhoneNumber != null || mobilePhoneNumber != null || hasAnEmail) {
 
  137             CommunicationArtifactsHelper helper = 
new CommunicationArtifactsHelper(
 
  138                     currentCase, PARSER_NAME, parent, Account.Type.DEVICE, null);
 
  140             helper.addContact(contactName, phoneNumber, homePhoneNumber,
 
  141                     mobilePhoneNumber, emailAddr, additionalAttributes);
 
  144             if (!additionalAttributes.isEmpty()) {
 
  145                 BlackboardArtifact artifact = parent.newDataArtifact(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT), additionalAttributes);
 
  147                 currentCase.getBlackboard().postArtifact(artifact, PARSER_NAME, null);
 
  193             } 
catch (IllegalArgumentException ex) {
 
  206             String normalizedKey = key.trim().toLowerCase();
 
  208                 if (normalizedKey.equals(keyChoice.name)) {
 
  213             throw new IllegalArgumentException(String.format(
"Key [%s] was not found." 
  214                     + 
" All keys should be tested with contains.", key));