Revision: 27526
          http://sourceforge.net/p/bibdesk/svn/27526
Author:   hofman
Date:     2022-06-02 16:18:20 +0000 (Thu, 02 Jun 2022)
Log Message:
-----------
convenience method to add a linked URL and/or set the URL field based on prefs, 
for use by parsers

Modified Paths:
--------------
    trunk/bibdesk/BDSKACLParser.m
    trunk/bibdesk/BDSKDBLPGroupServer.m
    trunk/bibdesk/BDSKHubmedParser.m
    trunk/bibdesk/BDSKIEEEXploreParser.m
    trunk/bibdesk/BDSKMathSciNetParser.m
    trunk/bibdesk/BDSKNumdamParser.m
    trunk/bibdesk/BDSKProjectEuclidParser.m
    trunk/bibdesk/BDSKZentralblattParser.m
    trunk/bibdesk/BibItem.h
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKACLParser.m
===================================================================
--- trunk/bibdesk/BDSKACLParser.m       2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BDSKACLParser.m       2022-06-02 16:18:20 UTC (rev 27526)
@@ -60,20 +60,16 @@
 
 - (void)addPDFURLsToItems:(NSArray *)bibtexItems {
     if ([bibtexItems count] > 0) {
-        BOOL addLinkedFiles = NO == [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKUseLocalUrlAndUrlKey];
         for (BibItem *item in bibtexItems) {
             NSString *url = [item valueOfField:BDSKUrlString];
             if ([NSString isEmptyString:url] == NO) {
                 if ([[url pathExtension] isCaseInsensitiveEqual:@"pdf"] == NO) 
{
                     NSString *pdfURL = [([url hasSuffix:@"/"] ? [url 
substringToIndex:[url length] - 1] : url) stringByAppendingString:@".pdf"];
-                    if (addLinkedFiles) {
-                        [item addFileForURL:[NSURL URLWithString:pdfURL] 
autoFile:NO runScriptHook:NO];
-                        [[url retain] autorelease];
-                    }
+                    [[url retain] autorelease];
                     [item setField:BDSKUrlString toValue:pdfURL];
+                    [item addURLString:pdfURL];
                 }
-                if (addLinkedFiles)
-                    [item addFileForURL:[NSURL URLWithString:url] autoFile:NO 
runScriptHook:NO];
+                [item addURLString:url];
             }
         }
     }

Modified: trunk/bibdesk/BDSKDBLPGroupServer.m
===================================================================
--- trunk/bibdesk/BDSKDBLPGroupServer.m 2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BDSKDBLPGroupServer.m 2022-06-02 16:18:20 UTC (rev 27526)
@@ -430,9 +430,6 @@
 
 - (NSArray *)currentFetchedPublications {
     NSMutableArray *allPubs = [NSMutableArray array];
-    NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-    BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
     NSUInteger i, iMax = [bibtexFetches count];
     
     for (i = 0; i < iMax; i++) {
@@ -447,18 +444,10 @@
                     NSString *url;
                     if ((url = [urls objectForKey:@"doi"]) && [NSString 
isEmptyString:[pub valueOfField:BDSKDoiString inherit:NO]])
                         [pub setField:BDSKDoiString toValue:url];
-                    if ((url = [urls objectForKey:@"url"])) {
-                        if (addUrlField && [NSString isEmptyString:[pub 
valueOfField:BDSKUrlString inherit:NO]])
-                            [pub setField:BDSKUrlString toValue:url];
-                        if (addLinkedFiles)
-                            [pub addFileForURL:[NSURL URLWithString:url] 
autoFile:NO runScriptHook:NO];
-                    }
-                    if ((url = [urls objectForKey:@"ee"])) {
-                        if (addUrlField && [NSString isEmptyString:[pub 
valueOfField:BDSKUrlString inherit:NO]])
-                            [pub setField:BDSKUrlString toValue:url];
-                        if (addLinkedFiles)
-                            [pub addFileForURL:[NSURL URLWithString:url] 
autoFile:NO runScriptHook:NO];
-                    }
+                    if ((url = [urls objectForKey:@"url"]))
+                        [pub addURLString:url];
+                    if ((url = [urls objectForKey:@"ee"]))
+                        [pub addURLString:url];
                 }
                 [allPubs addObject:pub];
             }

Modified: trunk/bibdesk/BDSKHubmedParser.m
===================================================================
--- trunk/bibdesk/BDSKHubmedParser.m    2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BDSKHubmedParser.m    2022-06-02 16:18:20 UTC (rev 27526)
@@ -81,18 +81,8 @@
 - (NSArray *)itemsFromDownload:(BDSKCitationDownload *)download error:(NSError 
**)outError {
     NSArray *items = [super itemsFromDownload:download error:outError];
     
-    BibItem *item = [items firstObject];
+    [[items firstObject] addURLString:[download contextInfo]];
     
-    if (item) {
-        NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-        BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-        BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
-        if (addUrlField && [NSString isEmptyString:[item 
valueOfField:BDSKUrlString inherit:NO]])
-            [item setField:BDSKUrlString toValue:[download contextInfo]];
-        if (addLinkedFiles)
-            [item addFileForURL:[NSURL URLWithString:[download contextInfo]] 
autoFile:NO runScriptHook:NO];
-    }
-    
     return items;
 }
 

Modified: trunk/bibdesk/BDSKIEEEXploreParser.m
===================================================================
--- trunk/bibdesk/BDSKIEEEXploreParser.m        2022-06-02 15:46:25 UTC (rev 
27525)
+++ trunk/bibdesk/BDSKIEEEXploreParser.m        2022-06-02 16:18:20 UTC (rev 
27526)
@@ -128,15 +128,7 @@
     
     BibItem *item = [items firstObject];
     
-    if (item) {
-        NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-        BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-        BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
-        if (addUrlField && [NSString isEmptyString:[item 
valueOfField:BDSKUrlString inherit:NO]])
-            [item setField:BDSKUrlString toValue:[download contextInfo]];
-        if (addLinkedFiles)
-            [item addFileForURL:[NSURL URLWithString:[download contextInfo]] 
autoFile:NO runScriptHook:NO];
-    }
+    [[items firstObject] addURLString:[download contextInfo]];
     
     return items;
 }

Modified: trunk/bibdesk/BDSKMathSciNetParser.m
===================================================================
--- trunk/bibdesk/BDSKMathSciNetParser.m        2022-06-02 15:46:25 UTC (rev 
27525)
+++ trunk/bibdesk/BDSKMathSciNetParser.m        2022-06-02 16:18:20 UTC (rev 
27526)
@@ -164,17 +164,10 @@
     }
     
     // Add a URL reference pointing to the review's web page to each record.
-    NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-    BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
-    
     for (BibItem * item in results) {
         NSString * MRNumber = [[item citeKey] stringByRemovingPrefix:@"MR"];
-        NSURL * MRItemURL = [[NSURL URLWithString:[@"/mathscinet-getitem?mr=" 
stringByAppendingString:MRNumber] relativeToURL:[download URL]] absoluteURL];
-        if (addUrlField)
-            [item setField:BDSKUrlString toValue:[MRItemURL absoluteString]];
-        if (addLinkedFiles)
-            [item addFileForURL:MRItemURL autoFile:NO runScriptHook:NO];
+        NSString * MRItemURL = [[NSURL 
URLWithString:[@"/mathscinet-getitem?mr=" stringByAppendingString:MRNumber] 
relativeToURL:[download URL]] absoluteString];
+        [item addURLString:MRItemURL];
     }
     
     return results;

Modified: trunk/bibdesk/BDSKNumdamParser.m
===================================================================
--- trunk/bibdesk/BDSKNumdamParser.m    2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BDSKNumdamParser.m    2022-06-02 16:18:20 UTC (rev 27526)
@@ -148,9 +148,6 @@
     if ([results count] > 0 && content != nil) {
         // add Numdam URL to item's own record
         BibItem *item = [results objectAtIndex:0];
-        NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-        BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-        BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
         
         if ( [item isKindOfClass:[BibItem class]] ) {
             AGRegex * URLRegexp = [AGRegex regexWithPattern:@"stable URL: 
([a-zA-Z0-9:=./?_]*)" options:0];
@@ -158,12 +155,8 @@
             if ([match count] >= 2) {
                 NSString * myURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
                 
-                if ( myURLString ) {
-                    if ( addUrlField )
-                        [(BibItem *)item setField:BDSKUrlString 
toValue:myURLString];
-                    if ( addLinkedFiles )
-                        [item insertObject:[BDSKLinkedFile 
linkedFileWithURLString:myURLString] inFilesAtIndex:0];
-                }
+                if ( myURLString )
+                    [item addURLString:myURLString];
             }
         }
     }

Modified: trunk/bibdesk/BDSKProjectEuclidParser.m
===================================================================
--- trunk/bibdesk/BDSKProjectEuclidParser.m     2022-06-02 15:46:25 UTC (rev 
27525)
+++ trunk/bibdesk/BDSKProjectEuclidParser.m     2022-06-02 16:18:20 UTC (rev 
27526)
@@ -139,9 +139,6 @@
     if ([results count] > 0 && myIdentifier != nil) {
         // add Project Euclid URL to item's own record
         NSObject * item = [results objectAtIndex:0];
-        NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-        BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-        BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
         
         if ( [item isKindOfClass:[BibItem class]] ) {
             AGRegex * ProjectEuclidRegexp = [AGRegex 
regexWithPattern:@"(https://projecteuclid.org/[^\\s]*)" options:0];
@@ -148,12 +145,8 @@
             AGRegexMatch * match = [ProjectEuclidRegexp 
findInString:myIdentifier];
             NSString * projectEuclidURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
             
-            if ( projectEuclidURLString ) {
-                if ( addUrlField )
-                    [(BibItem *)item setField:BDSKUrlString 
toValue:projectEuclidURLString];
-                if ( addLinkedFiles )
-                    [(BibItem *)item insertObject:[BDSKLinkedFile 
linkedFileWithURLString:projectEuclidURLString] inFilesAtIndex:0];
-            }
+            if ( projectEuclidURLString )
+                [(BibItem *)item addURLString:projectEuclidURLString];
         }
     }
     

Modified: trunk/bibdesk/BDSKZentralblattParser.m
===================================================================
--- trunk/bibdesk/BDSKZentralblattParser.m      2022-06-02 15:46:25 UTC (rev 
27525)
+++ trunk/bibdesk/BDSKZentralblattParser.m      2022-06-02 16:18:20 UTC (rev 
27526)
@@ -142,20 +142,12 @@
     bibTeXString = [umlautFixer replaceWithString:@"{$1}" 
inString:bibTeXString];
     
     NSArray * results = [parser itemsFromBibTeXString:bibTeXString 
error:outError];
-    NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
-    BOOL addUrlField = addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
     
     // Add a URL reference to the review's web page to each record.
     for (BibItem * item in results) {
         NSString * ZMathID = [item citeKey];
         NSString * ZMathItemURLString = [NSString 
stringWithFormat:@"https://zbmath.org/search/?format=complete&q=an:%@";, 
ZMathID];
-        NSURL * ZMathItemURL = [NSURL URLWithString:ZMathItemURLString];
-        if ( addUrlField && [NSString isEmptyString:[item 
valueOfField:BDSKUrlString]] )
-            [item setField:BDSKUrlString toValue:ZMathItemURLString];
-        if (addLinkedFiles)
-            [item addFileForURL:ZMathItemURL autoFile:NO runScriptHook:NO];
-        
+        [item addURLString:ZMathItemURLString];
     }
     
     return results;

Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h     2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BibItem.h     2022-06-02 16:18:20 UTC (rev 27526)
@@ -135,6 +135,8 @@
 
 - (void)noteFilesChanged:(BOOL)isFile;
 
+- (void)addURLString:(NSString *)urlString;
+
 - (BOOL)migrateFilesWithRemoveOptions:(BDSKRemoveFieldsOption)removeMask 
numberOfAddedFiles:(NSInteger *)numberOfAddedFiles 
numberOfRemovedFields:(NSInteger *)numberOfRemovedFields error:(NSError 
**)outError;
 
 @property (nonatomic, readonly) NSArray *localFiles;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2022-06-02 15:46:25 UTC (rev 27525)
+++ trunk/bibdesk/BibItem.m     2022-06-02 16:18:20 UTC (rev 27526)
@@ -2794,6 +2794,15 @@
     return YES;
 }
 
+- (void)addURLString:(NSString *)urlString {
+    NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
+    BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
+    if (addLinkedFiles)
+        [self addFileForURL:[NSURL URLWithString:urlString] autoFile:NO 
runScriptHook:NO];
+    if ([NSString isEmptyAsComplexString:[self valueOfField:BDSKUrlString 
inherit:NO]] && (addLinkedFiles == NO || [sud 
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud 
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO))
+        [self setField:BDSKUrlString toValue:urlString];
+}
+
 - (void)noteFilesChanged:(BOOL)isFile {
     // this is called after filing a linked file
     NSString *key = isFile ? BDSKLocalFileString : BDSKRemoteURLString;

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