Revision: 21969
          http://sourceforge.net/p/bibdesk/svn/21969
Author:   hofman
Date:     2018-02-19 22:11:51 +0000 (Mon, 19 Feb 2018)
Log Message:
-----------
Add error item when download or bibtex parsing fails

Modified Paths:
--------------
    trunk/bibdesk/BDSKCiteULikeParser.m
    trunk/bibdesk/BDSKLinkedBibTeXParser.m
    trunk/bibdesk/BDSKMASParser.m
    trunk/bibdesk/BDSKMathSciNetParser.m
    trunk/bibdesk/BDSKNumdamParser.m
    trunk/bibdesk/BDSKProjectEuclidParser.m
    trunk/bibdesk/BDSKZentralblattParser.m

Modified: trunk/bibdesk/BDSKCiteULikeParser.m
===================================================================
--- trunk/bibdesk/BDSKCiteULikeParser.m 2018-02-19 21:54:02 UTC (rev 21968)
+++ trunk/bibdesk/BDSKCiteULikeParser.m 2018-02-19 22:11:51 UTC (rev 21969)
@@ -82,7 +82,9 @@
                 [items addObject:bibtexItem];
             } else {
                 // display a fake item in the table so the user knows one of 
the items failed to parse, but still gets the rest of the data
-                NSString *errMsg = NSLocalizedString(@"Unable to parse as 
BibTeX", @"Web parser error");
+                NSString *errMsg = [error localizedDescription];
+                if (errMsg == nil)
+                    errMsg = NSLocalizedString(@"Unable to parse as BibTeX", 
@"Web parser error");
                 NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, nil];
                 BibItem *errorItem = [[BibItem alloc] 
initWithType:BDSKMiscString citeKey:nil pubFields:pubFields isNew:YES];
                 [items addObject:errorItem];

Modified: trunk/bibdesk/BDSKLinkedBibTeXParser.m
===================================================================
--- trunk/bibdesk/BDSKLinkedBibTeXParser.m      2018-02-19 21:54:02 UTC (rev 
21968)
+++ trunk/bibdesk/BDSKLinkedBibTeXParser.m      2018-02-19 22:11:51 UTC (rev 
21969)
@@ -137,7 +137,9 @@
         [items addObject:bibtexItem];
     } else {
         // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
-        NSString *errMsg = NSLocalizedString(@"Unable to parse as BibTeX", 
@"Web parser error");
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
         NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
         BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
         [items addObject:errorItem];

Modified: trunk/bibdesk/BDSKMASParser.m
===================================================================
--- trunk/bibdesk/BDSKMASParser.m       2018-02-19 21:54:02 UTC (rev 21968)
+++ trunk/bibdesk/BDSKMASParser.m       2018-02-19 22:11:51 UTC (rev 21969)
@@ -117,7 +117,9 @@
     
     if ([items count] == 0) {
         // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
-        NSString *errMsg = NSLocalizedString(@"Unable to parse as BibTeX", 
@"Web parser error");
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
         NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
         BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
         items = [NSArray arrayWithObjects:errorItem, nil];

Modified: trunk/bibdesk/BDSKMathSciNetParser.m
===================================================================
--- trunk/bibdesk/BDSKMathSciNetParser.m        2018-02-19 21:54:02 UTC (rev 
21968)
+++ trunk/bibdesk/BDSKMathSciNetParser.m        2018-02-19 22:11:51 UTC (rev 
21969)
@@ -107,6 +107,17 @@
     if (bibTeXString)
         results = [BDSKMathSciNetParser bibItemsFromBibTeXString:bibTeXString 
fromURL:[download URL] error:&error];
     
+    if ([results count] == 0) {
+        // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
+        NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
+        BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
+        results = [NSArray arrayWithObjects:errorItem, nil];
+        [errorItem release];
+    }
+    
     [self didFinishDownload:download findingItems:results withSuccess:YES 
error:nil];
 }
 

Modified: trunk/bibdesk/BDSKNumdamParser.m
===================================================================
--- trunk/bibdesk/BDSKNumdamParser.m    2018-02-19 21:54:02 UTC (rev 21968)
+++ trunk/bibdesk/BDSKNumdamParser.m    2018-02-19 22:11:51 UTC (rev 21969)
@@ -155,23 +155,32 @@
     Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
     NSString *content = [contextInfo objectForKey:@"content"];
     
-    if (bibTeXString) {
+    if (bibTeXString)
         results = [parserClass bibItemsFromBibTeXString:bibTeXString 
fromURL:[download URL] error:&error];
-        if (content && [results count] > 0) {
-            // add Numdam URL to item's own record
-            BibItem *item = [results objectAtIndex:0];
-            if ( [item isKindOfClass:[BibItem class]] ) {
-                AGRegex * URLRegexp = [AGRegex regexWithPattern:@"stable URL: 
([a-zA-Z0-9:=./?_]*)" options:0];
-                AGRegexMatch * match = [URLRegexp findInString:content];
-                if ([match count] >= 2) {
-                    NSString * myURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
-                    NSURL * myURL = [NSURL URLWithString:myURLString];
-                    if ( myURL ) {
-                        BOOL added = [(BibItem *)item addFileForURL:myURL 
autoFile:NO runScriptHook:NO];
-                        if (added) {
-                            NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
-                            [(BibItem *)item moveFilesAtIndexes:indexSet 
toIndex:0];
-                        }
+    
+    if ([results count] == 0) {
+        // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
+        NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
+        BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
+        results = [NSArray arrayWithObjects:errorItem, nil];
+        [errorItem release];
+    } else if (content) {
+        // add Numdam URL to item's own record
+        BibItem *item = [results objectAtIndex:0];
+        if ( [item isKindOfClass:[BibItem class]] ) {
+            AGRegex * URLRegexp = [AGRegex regexWithPattern:@"stable URL: 
([a-zA-Z0-9:=./?_]*)" options:0];
+            AGRegexMatch * match = [URLRegexp findInString:content];
+            if ([match count] >= 2) {
+                NSString * myURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
+                NSURL * myURL = [NSURL URLWithString:myURLString];
+                if ( myURL ) {
+                    BOOL added = [(BibItem *)item addFileForURL:myURL 
autoFile:NO runScriptHook:NO];
+                    if (added) {
+                        NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
+                        [(BibItem *)item moveFilesAtIndexes:indexSet 
toIndex:0];
                     }
                 }
             }

Modified: trunk/bibdesk/BDSKProjectEuclidParser.m
===================================================================
--- trunk/bibdesk/BDSKProjectEuclidParser.m     2018-02-19 21:54:02 UTC (rev 
21968)
+++ trunk/bibdesk/BDSKProjectEuclidParser.m     2018-02-19 22:11:51 UTC (rev 
21969)
@@ -147,25 +147,33 @@
     Class parserClass = (Class)[contextInfo objectForKey:@"parserClass"];
     NSString *myIdentifier = [contextInfo objectForKey:@"myIdentifier"];
     
-    if (bibTeXString) {
+    if (bibTeXString)
         // parse the bibTeX string with the correct parser
         results = [parserClass bibItemsFromBibTeXString:bibTeXString 
fromURL:[download URL] error:&error];
-        
-        if (myIdentifier && [results count] > 0) {
-            // add Project Euclid URL to item's own record
-            NSObject * item = [results objectAtIndex:0];
-            if ( [item isKindOfClass:[BibItem class]] ) {
-                AGRegex * ProjectEuclidRegexp = [AGRegex 
regexWithPattern:@"(https://projecteuclid.org/[^\\s]*)" options:0];
-                AGRegexMatch * match = [ProjectEuclidRegexp 
findInString:myIdentifier];
-                NSString * projectEuclidURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
-                NSURL * projectEuclidURL = [NSURL 
URLWithString:projectEuclidURLString];
-                
-                if ( projectEuclidURL ) {
-                    BOOL added = [(BibItem *)item 
addFileForURL:projectEuclidURL autoFile:NO runScriptHook:NO];
-                    if ( added ) {
-                        NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
-                        [(BibItem *)item moveFilesAtIndexes:indexSet 
toIndex:0];
-                    }
+    
+    if ([results count] == 0) {
+        // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
+        NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
+        BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
+        results = [NSArray arrayWithObjects:errorItem, nil];
+        [errorItem release];
+    } else if (myIdentifier) {
+        // add Project Euclid URL to item's own record
+        NSObject * item = [results objectAtIndex:0];
+        if ( [item isKindOfClass:[BibItem class]] ) {
+            AGRegex * ProjectEuclidRegexp = [AGRegex 
regexWithPattern:@"(https://projecteuclid.org/[^\\s]*)" options:0];
+            AGRegexMatch * match = [ProjectEuclidRegexp 
findInString:myIdentifier];
+            NSString * projectEuclidURLString = [[match string] 
substringWithRange:[match rangeAtIndex:1]];
+            NSURL * projectEuclidURL = [NSURL 
URLWithString:projectEuclidURLString];
+            
+            if ( projectEuclidURL ) {
+                BOOL added = [(BibItem *)item addFileForURL:projectEuclidURL 
autoFile:NO runScriptHook:NO];
+                if ( added ) {
+                    NSIndexSet * indexSet = [NSIndexSet 
indexSetWithIndex:[(BibItem *)item countOfFiles] - 1];
+                    [(BibItem *)item moveFilesAtIndexes:indexSet toIndex:0];
                 }
             }
         }

Modified: trunk/bibdesk/BDSKZentralblattParser.m
===================================================================
--- trunk/bibdesk/BDSKZentralblattParser.m      2018-02-19 21:54:02 UTC (rev 
21968)
+++ trunk/bibdesk/BDSKZentralblattParser.m      2018-02-19 22:11:51 UTC (rev 
21969)
@@ -107,7 +107,18 @@
     if (bibTeXString)
         results = [BDSKZentralblattParser 
bibItemsFromBibTeXString:bibTeXString fromURL:[download URL] error:&error];
     
-    [self didFinishDownload:download findingItems:results withSuccess:YES 
error:nil];
+    if ([results count] == 0) {
+        // display a fake item in the table so the user knows one of the items 
failed to parse, but still gets the rest of the data
+        NSString *errMsg = [[download error] localizedDescription];
+        if (errMsg == nil)
+            errMsg = NSLocalizedString(@"Unable to parse as BibTeX", @"Web 
parser error");
+        NSDictionary *pubFields = [NSDictionary 
dictionaryWithObjectsAndKeys:errMsg, BDSKTitleString, [[download URL] 
absoluteString], BDSKUrlString, nil];
+        BibItem *errorItem = [[BibItem alloc] initWithType:BDSKMiscString 
citeKey:nil pubFields:pubFields isNew:YES];
+        results = [NSArray arrayWithObjects:errorItem, nil];
+        [errorItem release];
+    }
+    
+[self didFinishDownload:download findingItems:results withSuccess:YES 
error:nil];
 }
 
 /*

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