Revision: 22014
          http://sourceforge.net/p/bibdesk/svn/22014
Author:   hofman
Date:     2018-02-22 16:07:40 +0000 (Thu, 22 Feb 2018)
Log Message:
-----------
avoid early return from parsers

Modified Paths:
--------------
    trunk/bibdesk/BDSKHCiteParser.m
    trunk/bibdesk/BDSKHubmedParser.m
    trunk/bibdesk/BDSKProjectEuclidParser.m

Modified: trunk/bibdesk/BDSKHCiteParser.m
===================================================================
--- trunk/bibdesk/BDSKHCiteParser.m     2018-02-22 16:00:08 UTC (rev 22013)
+++ trunk/bibdesk/BDSKHCiteParser.m     2018-02-22 16:07:40 UTC (rev 22014)
@@ -70,15 +70,6 @@
 
     NSArray *mainNodes = [[[self xmlDocument] rootElement] 
nodesForXPath:containsCitationPath error:&error];
     
-    if ([mainNodes count] == 0) {
-        // bail out with an XML error if the Xpath query fails
-        if (error == nil) {
-            error = [NSError mutableLocalErrorWithCode:kBDSKWebParserFailed 
localizedDescription:NSLocalizedString(@"No search results found", @"Web parser 
error")];
-            [error setValue:NSLocalizedString(@"Unable to parse this page.  
Please report this to BibDesk's developers and provide the URL.", @"Web parser 
error") forKey:NSLocalizedRecoverySuggestionErrorKey];
-        }
-        [[self delegate] webParser:self didFinishWithSuccess:NO error:error];
-        return;
-    }
     
     for (NSXMLNode *obj in mainNodes) {
         NSMutableDictionary *rd = nil;
@@ -94,8 +85,13 @@
                                                  isNew:YES] autorelease];
         [items addObject:item];
     }
-    
-    [self didFinishStartingFindingItems:items withSuccess:YES error:nil];
+        
+    if ([items count] == 0 && error == nil) {
+        error = [NSError mutableLocalErrorWithCode:kBDSKWebParserFailed 
localizedDescription:NSLocalizedString(@"No search results found", @"Web parser 
error")];
+        [error setValue:NSLocalizedString(@"Unable to parse this page.  Please 
report this to BibDesk's developers and provide the URL.", @"Web parser error") 
forKey:NSLocalizedRecoverySuggestionErrorKey];
+    }
+
+    [self didFinishStartingFindingItems:items withSuccess:[items count] > 0 
error:error];
 }
 
 - (NSMutableDictionary *)dictionaryFromCitationNode:(NSXMLNode *)citationNode{

Modified: trunk/bibdesk/BDSKHubmedParser.m
===================================================================
--- trunk/bibdesk/BDSKHubmedParser.m    2018-02-22 16:00:08 UTC (rev 22013)
+++ trunk/bibdesk/BDSKHubmedParser.m    2018-02-22 16:07:40 UTC (rev 22014)
@@ -65,25 +65,24 @@
     NSURL *url = [self URL];
     AGRegex *regex = [AGRegex regexWithPattern:@".*uids=([0-9]+).*"];
     AGRegexMatch *match = [regex findInString:[url query]];
+    NSError *error = nil;
     
-    if(match == nil){
-        NSError *error = [NSError 
mutableLocalErrorWithCode:kBDSKWebParserFailed 
localizedDescription:NSLocalizedString(@"No search results found", @"Web parser 
error")];
+    if (match == nil) {
+        error = [NSError mutableLocalErrorWithCode:kBDSKWebParserFailed 
localizedDescription:NSLocalizedString(@"No search results found", @"Web parser 
error")];
         [error setValue:NSLocalizedString(@"Unable to parse this page.  Please 
report this to BibDesk's developers and provide the URL.", @"Web parser error") 
forKey:NSLocalizedRecoverySuggestionErrorKey];
-        [[self delegate] webParser:self didFinishWithSuccess:NO error:error];
-        return;
-    }
-    
-    NSString *uidString = [match groupAtIndex:1];
-    
-    NSURL *btURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://%@/export/bibtex.cgi?uids=%@&format=.txt";, [url 
host], uidString]];
-    
-    NSString *linkedURLString = [NSString 
stringWithFormat:@"http://%@/fulltext.cgi?uids=%@";, [url host], uidString];
+    } else {
+        NSString *uidString = [match groupAtIndex:1];
+        
+        NSURL *btURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://%@/export/bibtex.cgi?uids=%@&format=.txt";, [url 
host], uidString]];
+        
+        NSString *linkedURLString = [NSString 
stringWithFormat:@"http://%@/fulltext.cgi?uids=%@";, [url host], uidString];
 
-    NSURLRequest *request = [NSURLRequest requestWithURL:btURL 
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
+        NSURLRequest *request = [NSURLRequest requestWithURL:btURL 
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
 
-    [self addDownloadWithRequest:request contextInfo:linkedURLString];
+        [self addDownloadWithRequest:request contextInfo:linkedURLString];
+    }
     
-    [self didFinishStartingFindingItems:nil withSuccess:YES error:nil];
+    [self didFinishStartingFindingItems:nil withSuccess:error == nil 
error:error];
 }
 
 - (void)downloadDidFinish:(BDSKCitationDownload *)download {

Modified: trunk/bibdesk/BDSKProjectEuclidParser.m
===================================================================
--- trunk/bibdesk/BDSKProjectEuclidParser.m     2018-02-22 16:00:08 UTC (rev 
22013)
+++ trunk/bibdesk/BDSKProjectEuclidParser.m     2018-02-22 16:07:40 UTC (rev 
22014)
@@ -65,71 +65,76 @@
        NSError * error;
     
        NSArray * identifiers = [[[self xmlDocument] rootElement] 
nodesForXPath:@".//div[@id='identifier']/p" error:&error];
-       if ( [identifiers count] == 0 ) {
+       
+    NSArray *MRRequests = nil;
+    NSArray *ZMathRequests = nil;
+
+    if ( [identifiers count] == 0 ) {// no matches, return an error
+        
         if (error == nil) {
             error = [NSError mutableLocalErrorWithCode:kBDSKWebParserFailed 
localizedDescription:NSLocalizedString(@"No search results found", @"Web parser 
error")];
             [error setValue:NSLocalizedString(@"Unable to parse this page.  
Please report this to BibDesk's developers and provide the URL.", @"Web parser 
error") forKey:NSLocalizedRecoverySuggestionErrorKey];
         }
-        [[self delegate] webParser:self didFinishWithSuccess:NO error:error];
-        return;
-    } // no identifier on this page => probably a non-article page on the site 
=> return empty array
-       
-       NSXMLElement * identifier = [identifiers objectAtIndex:0];
-       NSString * identifierString = [identifier stringValue];
-       
-       AGRegex * MRRegexp = [AGRegex regexWithPattern:@"MR([1-9][0-9]*)" 
options:0];
-       AGRegex * ZMathRegexp = [AGRegex regexWithPattern:@"Zentralblatt.* 
([0-9.]+)" options:0];
-       AGRegexMatch * match;
-       
-    NSString * myMRID = nil;
-    NSString * myZMathID = nil;
-    
-       // find IDs for the item itself
-       match = [MRRegexp findInString:identifierString];
-    myMRID = [[match string] substringWithRange:[match rangeAtIndex:1]];
-    if (myMRID == nil) {
-        match = [ZMathRegexp findInString:identifierString];
-        myZMathID = [[match string] substringWithRange:[match rangeAtIndex:1]];
-    }
-    
-       // Set up arrays for the lists of MathSciNet and Zentralblatt IDs. 
These will have the ID for the current element at position 0 and contain NSNull 
when no ID is found for the respective service.
-       NSArray * references = [[[self xmlDocument] rootElement] 
nodesForXPath:@".//div[@id='references']/div[@class='ref-block']" error:&error];
-    NSMutableArray * MRIDs = [NSMutableArray arrayWithObjects:myMRID, nil];
-       NSMutableArray * ZMathIDs = [NSMutableArray arrayWithObjects:myZMathID, 
nil];
-       
-       for (NSXMLElement * reference in references) {
-               NSString * referenceString = [reference stringValue];
+        
+    } else {
+        
+        NSXMLElement * identifier = [identifiers objectAtIndex:0];
+        NSString * identifierString = [identifier stringValue];
+        
+        AGRegex * MRRegexp = [AGRegex regexWithPattern:@"MR([1-9][0-9]*)" 
options:0];
+        AGRegex * ZMathRegexp = [AGRegex regexWithPattern:@"Zentralblatt.* 
([0-9.]+)" options:0];
+        AGRegexMatch * match;
+        
+        NSString * myMRID = nil;
+        NSString * myZMathID = nil;
+        
+        // find IDs for the item itself
+        match = [MRRegexp findInString:identifierString];
+        myMRID = [[match string] substringWithRange:[match rangeAtIndex:1]];
+        if (myMRID == nil) {
+            match = [ZMathRegexp findInString:identifierString];
+            myZMathID = [[match string] substringWithRange:[match 
rangeAtIndex:1]];
+        }
+        
+        // Set up arrays for the lists of MathSciNet and Zentralblatt IDs. 
These will have the ID for the current element at position 0 and contain NSNull 
when no ID is found for the respective service.
+        NSArray * references = [[[self xmlDocument] rootElement] 
nodesForXPath:@".//div[@id='references']/div[@class='ref-block']" error:&error];
+        NSMutableArray * MRIDs = [NSMutableArray arrayWithObjects:myMRID, nil];
+        NSMutableArray * ZMathIDs = [NSMutableArray 
arrayWithObjects:myZMathID, nil];
+        
+        for (NSXMLElement * reference in references) {
+            NSString * referenceString = [reference stringValue];
 
-               match = [MRRegexp findInString:referenceString];
-               NSString * referenceID = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
-        if (referenceID) {
-            [MRIDs addObject:referenceID];
-        } else {
-            match = [ZMathRegexp findInString:referenceString];
-            referenceID = [[match string] substringWithRange:[match 
rangeAtIndex:1]];
-            if (referenceID)
-                [ZMathIDs addObject:referenceID];
+            match = [MRRegexp findInString:referenceString];
+            NSString * referenceID = [[match string] substringWithRange:[match 
rangeAtIndex:1]];
+            if (referenceID) {
+                [MRIDs addObject:referenceID];
+            } else {
+                match = [ZMathRegexp findInString:referenceString];
+                referenceID = [[match string] substringWithRange:[match 
rangeAtIndex:1]];
+                if (referenceID)
+                    [ZMathIDs addObject:referenceID];
+            }
         }
-       }
-       
-    NSArray *MRRequests = [BDSKMathSciNetParser bibTeXRequestsForMRIDs:MRIDs 
referrer:[self URL] error:&error];
-    
-    NSString *myIdentifier = myMRID ? identifierString : nil;
-    for (NSURLRequest *request in MRRequests) {
-        NSDictionary *contextInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass", 
myIdentifier, @"identifier", nil];
-        [self addDownloadWithRequest:request contextInfo:contextInfo];
-        myIdentifier = nil;
+        
+        MRRequests = [BDSKMathSciNetParser bibTeXRequestsForMRIDs:MRIDs 
referrer:[self URL] error:&error];
+        
+        NSString *myIdentifier = myMRID ? identifierString : nil;
+        for (NSURLRequest *request in MRRequests) {
+            NSDictionary *contextInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[BDSKMathSciNetParser class], @"parserClass", 
myIdentifier, @"identifier", nil];
+            [self addDownloadWithRequest:request contextInfo:contextInfo];
+            myIdentifier = nil;
+        }
+        
+        ZMathRequests = [BDSKZentralblattParser 
bibTeXRequestsForZMathIDs:ZMathIDs referrer:[self URL] error:&error];
+        
+        myIdentifier = myZMathID ? identifierString : nil;
+        for (NSURLRequest *request in ZMathRequests) {
+            NSDictionary *contextInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass", 
myIdentifier, @"myIdentifier", nil];
+            [self addDownloadWithRequest:request contextInfo:contextInfo];
+            myIdentifier = nil;
+        }
     }
     
-    NSArray *ZMathRequests = [BDSKZentralblattParser 
bibTeXRequestsForZMathIDs:ZMathIDs referrer:[self URL] error:&error];
-    
-    myIdentifier = myZMathID ? identifierString : nil;
-    for (NSURLRequest *request in ZMathRequests) {
-        NSDictionary *contextInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[BDSKZentralblattParser class], @"parserClass", 
myIdentifier, @"myIdentifier", nil];
-        [self addDownloadWithRequest:request contextInfo:contextInfo];
-        myIdentifier = nil;
-    }
-    
     BOOL success = [MRRequests count] > 0 || [ZMathRequests count] > 0;
     [self didFinishStartingFindingItems:nil withSuccess:success error:error];
 }

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to