Revision: 22563
          http://sourceforge.net/p/bibdesk/svn/22563
Author:   hofman
Date:     2018-09-07 18:49:02 +0000 (Fri, 07 Sep 2018)
Log Message:
-----------
Add doi linked url when doing is a url field and user wants linked files

Modified Paths:
--------------
    trunk/bibdesk/BDSKArxivParser.m
    trunk/bibdesk/BDSKCOinSParser.m
    trunk/bibdesk/BDSKSpringerParser.m

Modified: trunk/bibdesk/BDSKArxivParser.m
===================================================================
--- trunk/bibdesk/BDSKArxivParser.m     2018-09-07 18:30:27 UTC (rev 22562)
+++ trunk/bibdesk/BDSKArxivParser.m     2018-09-07 18:49:02 UTC (rev 22563)
@@ -156,6 +156,7 @@
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
     BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
     BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
+    BOOL doiIsURL = [[sud stringArrayForKey:BDSKRemoteURLFieldsKey] 
containsObject:BDSKDoiString];
     
     NSMutableArray *items = [NSMutableArray arrayWithCapacity:0];
     
@@ -178,10 +179,11 @@
         // search for arXiv ID
         node = [arxivLinkNode singleNodeForXPathExpression:arxivIDNodePath];
         if (node) {
-            if ((string = [node stringValue])) {
-                if ([string hasCaseInsensitivePrefix:@"arXiv:"])
-                    string = [string substringFromIndex:6];
-                [pubFields setValue:string forKey:@"Eprint"];
+            NSString *eprint = nil;
+            if ((eprint = [node stringValue])) {
+                if ([eprint hasCaseInsensitivePrefix:@"arXiv:"])
+                    eprint = [string substringFromIndex:6];
+                [pubFields setValue:eprint forKey:@"Eprint"];
             }
             if ((string = [node stringValueOfAttribute:@"href"])) {
                 // fix relative urls
@@ -191,6 +193,13 @@
                     [pubFields setValue:string forKey:BDSKUrlString];
                 if (addLinkedFiles)
                     [pubFiles addObject:[BDSKLinkedFile 
linkedFileWithURLString:string]];
+            } else if (eprint) {
+                // fill URL from arxiv ID if we did not find a link
+                string = [NSString stringWithFormat:@"https://%@/pdf/%@.pdf";, 
[url host], eprint];
+                if (addUrlField)
+                    [pubFields setValue:string forKey:BDSKUrlString];
+                if (addLinkedFiles)
+                    [pubFiles addObject:[BDSKLinkedFile 
linkedFileWithURLString:string]];
             }
         }
         
@@ -215,6 +224,8 @@
             // successfully found the result PDF url
             if ((string = [node stringValue])) {
                 [pubFields setValue:string forKey:BDSKDoiString];
+                if (addLinkedFiles && doiIsURL)
+                    [pubFiles addObject:[BDSKLinkedFile 
linkedFileWithURLString:[@"https://doi.org/"; stringByAppendingString:[[node 
stringValue] stringByAddingPercentEscapes]]]];
             }
         }
         
@@ -293,10 +304,6 @@
             }
         }
         
-        // fill URL from arxiv ID if we did not find a link
-        if ([pubFields valueForKey:BDSKUrlString] == nil && (string = 
[pubFields valueForKey:@"Eprint"]))
-            [pubFields setValue:[NSString 
stringWithFormat:@"https://%@/pdf/%@.pdf";, [url host], string] 
forKey:BDSKUrlString];
-        
         BibItem *item = [[BibItem alloc] initWithType:BDSKArticleString 
citeKey:nil pubFields:pubFields files:pubFiles isNew:YES];
         [items addObject:item];
         [item release];

Modified: trunk/bibdesk/BDSKCOinSParser.m
===================================================================
--- trunk/bibdesk/BDSKCOinSParser.m     2018-09-07 18:30:27 UTC (rev 22562)
+++ trunk/bibdesk/BDSKCOinSParser.m     2018-09-07 18:49:02 UTC (rev 22563)
@@ -118,6 +118,7 @@
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
     BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
     BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
+    BOOL doiIsURL = [[sud stringArrayForKey:BDSKRemoteURLFieldsKey] 
containsObject:BDSKDoiString];
     
        for (NSString *component in components) {
                NSArray * keyValue = [component 
componentsSeparatedByString:@"="];
@@ -227,13 +228,17 @@
                     if (addUrlField)
                         [fieldsDict setObject:value forKey:BDSKUrlString];
                     if (addLinkedFiles)
-                        [files addObject:[BDSKLinkedFile linkedFileWithURL:URL 
delegate:nil]];
+                        [files addObject:[BDSKLinkedFile 
linkedFileWithURLString:[URL absoluteString]]];
                                }
                                if ([value rangeOfString:@"doi" 
options:NSCaseInsensitiveSearch].location != NSNotFound) {
                                        // the value contains doi, so assume 
it's DOI information and also add it to the DOI field. There should only be a 
single occurrence of those, so add it right here to make sure the format isn't 
messed up in case multiple fields contain that substring
                                        NSRange range = [value 
rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]];
-                    if (range.length && range.location > 0)
-                                               [fieldsDict setObject:[value 
substringFromIndex:range.location] forKey:BDSKDoiString];
+                    if (range.length && range.location > 0) {
+                        NSString *doi = [value 
substringFromIndex:range.location];
+                                               [fieldsDict setObject:doi 
forKey:BDSKDoiString];
+                        if (addLinkedFiles && doiIsURL)
+                            [files addObject:[BDSKLinkedFile 
linkedFileWithURLString:[@"https://doi.org/"; stringByAppendingString:[doi 
stringByAddingPercentEscapes]]]];
+                    }
                 }
                        }
                        else if ([key isEqualToString:@"rft.isbn"]) { 

Modified: trunk/bibdesk/BDSKSpringerParser.m
===================================================================
--- trunk/bibdesk/BDSKSpringerParser.m  2018-09-07 18:30:27 UTC (rev 22562)
+++ trunk/bibdesk/BDSKSpringerParser.m  2018-09-07 18:49:02 UTC (rev 22563)
@@ -159,6 +159,7 @@
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
     BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
     BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
+    BOOL doiIsURL = [[sud stringArrayForKey:BDSKRemoteURLFieldsKey] 
containsObject:BDSKDoiString];
     
     if (addUrlField) {
         // URL to PDF
@@ -168,6 +169,8 @@
         filesArray = [NSMutableArray array];
         // URL to PDF
         [filesArray addObject:[BDSKLinkedFile linkedFileWithURL:[NSURL 
URLWithString:@"fulltext.pdf" relativeToURL:url] delegate:nil]];
+        if (doi && doiIsURL)
+            [filesArray addObject:[BDSKLinkedFile linkedFileWithURL:[NSURL 
URLWithString:[@"https://doi.org/"; stringByAppendingString:[doi 
stringByAddingPercentEscapes]]] delegate:nil]];
     }
     
        return [[BibItem alloc] initWithType:pubType citeKey:nil 
pubFields:pubFields files:filesArray isNew:YES];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to