Revision: 22525
          http://sourceforge.net/p/bibdesk/svn/22525
Author:   hofman
Date:     2018-08-24 14:51:01 +0000 (Fri, 24 Aug 2018)
Log Message:
-----------
Check for element before getting attribute

Modified Paths:
--------------
    trunk/bibdesk/BDSKACMDLParser.m
    trunk/bibdesk/BDSKArxivParser.m
    trunk/bibdesk/BDSKAsynchronousWebParser.m
    trunk/bibdesk/BDSKCiteULikeParser.m
    trunk/bibdesk/BDSKDOIWebParser.m
    trunk/bibdesk/BDSKHCiteParser.m
    trunk/bibdesk/BDSKIEEEXploreParser.m
    trunk/bibdesk/BDSKIUCrParser.m
    trunk/bibdesk/BDSKSIAMParser.m
    trunk/bibdesk/BDSKScienceDirectParser.m
    trunk/bibdesk/DOMNode_BDSKExtensions.h
    trunk/bibdesk/DOMNode_BDSKExtensions.m

Modified: trunk/bibdesk/BDSKACMDLParser.m
===================================================================
--- trunk/bibdesk/BDSKACMDLParser.m     2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKACMDLParser.m     2018-08-24 14:51:01 UTC (rev 22525)
@@ -38,6 +38,7 @@
 
 #import "BDSKACMDLParser.h"
 #import <AGRegex/AGRegex.h>
+#import "DOMNode_BDSKExtensions.h"
 
 
 @implementation BDSKACMDLParser
@@ -45,7 +46,7 @@
 + (NSString *)citationNodeXPath { return 
@"./head/meta[@name='citation_abstract_html_url']/@content"; }
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    NSString *nodeString = [[NSURL URLWithString:[(DOMElement *)node 
getAttribute:@"content"]] query];
+    NSString *nodeString = [[NSURL URLWithString:[node 
stringValueOfAttribute:@"content"]] query];
 
     AGRegex *doiRegex = [AGRegex regexWithPattern:@"^id=([0-9]+)\\.([0-9]+)$"];
     AGRegexMatch *match = [doiRegex findInString:nodeString];

Modified: trunk/bibdesk/BDSKArxivParser.m
===================================================================
--- trunk/bibdesk/BDSKArxivParser.m     2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKArxivParser.m     2018-08-24 14:51:01 UTC (rev 22525)
@@ -181,7 +181,7 @@
                     string = [string substringFromIndex:6];
                 [pubFields setValue:string forKey:@"Eprint"];
             }
-            if ((string = [(DOMElement *)node getAttribute:@"href"])) {
+            if ((string = [node stringValueOfAttribute:@"href"])) {
                 // fix relative urls
                 if (NO == [string containsString:@"://"])
                     string = [[NSURL URLWithString:string relativeToURL:url] 
absoluteString];
@@ -195,7 +195,7 @@
         node = [arxivLinkNode singleNodeForXPathExpression:pdfURLNodePath];
         if (node) {
             // successfully found the result PDF url
-            if ((string = [(DOMElement *)node getAttribute:@"href"])) {
+            if ((string = [node stringValueOfAttribute:@"href"])) {
                 // fix relative urls
                 if (NO == [string containsString:@"://"])
                     string = [[NSURL URLWithString:string relativeToURL:url] 
absoluteString];

Modified: trunk/bibdesk/BDSKAsynchronousWebParser.m
===================================================================
--- trunk/bibdesk/BDSKAsynchronousWebParser.m   2018-08-24 14:41:53 UTC (rev 
22524)
+++ trunk/bibdesk/BDSKAsynchronousWebParser.m   2018-08-24 14:51:01 UTC (rev 
22525)
@@ -106,7 +106,7 @@
 + (NSString *)citationNodeXPath { return @""; }
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    return [(DOMElement *)node getAttribute:@"href"];
+    return [node stringValueOfAttribute:@"href"];
 }
 
 - (void)downloadDidFinish:(BDSKCitationDownload *)download {

Modified: trunk/bibdesk/BDSKCiteULikeParser.m
===================================================================
--- trunk/bibdesk/BDSKCiteULikeParser.m 2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKCiteULikeParser.m 2018-08-24 14:51:01 UTC (rev 22525)
@@ -37,13 +37,15 @@
 
 #import "BDSKCiteULikeParser.h"
 #import "BibItem.h"
+#import "DOMNode_BDSKExtensions.h"
 
+
 @implementation BDSKCiteULikeParser
 
 + (NSString *)citationNodeXPath { return 
@"./body//div[@id='export']/table//td/a[text()='BibTeX']"; }
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    NSMutableString *urlString = [[[(DOMElement *)node getAttribute:@"href"] 
mutableCopy] autorelease];
+    NSMutableString *urlString = [[[node stringValueOfAttribute:@"href"] 
mutableCopy] autorelease];
     
     [urlString replaceOccurrencesOfString:@"/bibtex_options/" 
withString:@"/bibtex/" options:NSCaseInsensitiveSearch range:NSMakeRange(0, 
[urlString length])];
     

Modified: trunk/bibdesk/BDSKDOIWebParser.m
===================================================================
--- trunk/bibdesk/BDSKDOIWebParser.m    2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKDOIWebParser.m    2018-08-24 14:51:01 UTC (rev 22525)
@@ -78,7 +78,7 @@
     node = [rootElement singleNodeForXPath:headMetaDoiXPath];
     
     if (node) {
-        doi = [(DOMElement *)node getAttribute:@"content"];
+        doi = [node stringValueOfAttribute:@"content"];
         if (doi && (match = [doiRegex findInString:doi])) {
             doi = [match groupAtIndex:3];
             if ([[match groupAtIndex:1] hasPrefix:@"http"] == NO)
@@ -91,7 +91,7 @@
         nodes = [rootElement nodesForXPath:bodyADoiXPath];
         
         for (node in nodes) {
-            doi = [(DOMElement *)node getAttribute:@"href"];
+            doi = [node stringValueOfAttribute:@"href"];
             if (doi && (match = [doiRegex findInString:doi])) {
                 doi = [[match groupAtIndex:3] 
stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]];
                 if ([dois containsObject:doi] == NO)

Modified: trunk/bibdesk/BDSKHCiteParser.m
===================================================================
--- trunk/bibdesk/BDSKHCiteParser.m     2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKHCiteParser.m     2018-08-24 14:51:01 UTC (rev 22525)
@@ -202,7 +202,7 @@
         NSString *URIString = nil;
         
         if([[node nodeName] isCaseInsensitiveEqual:@"a"]){
-            URIString = [(DOMElement *)node getAttribute:@"href"];
+            URIString = [node stringValueOfAttribute:@"href"];
         }else{
             URIString = [self fullStringValueIfABBRFromNode:node];
         }
@@ -274,7 +274,7 @@
     DOMNode *parent = [node parentNode];
     do {
         if ([parent nodeType] != DOM_ELEMENT_NODE) return NO; // handles root 
node
-        if ([[[(DOMElement *)parent getAttribute:@"class"] 
componentsSeparatedByString:@" "] containsObject:@"container"])
+        if ([[[parent stringValueOfAttribute:@"class"] 
componentsSeparatedByString:@" "] containsObject:@"container"])
             return YES;
     } while ((parent = [parent parentNode]));
     return NO;
@@ -284,7 +284,7 @@
     if ([[node nodeName] isCaseInsensitiveEqual:@"abbr"]){
         //todo: will need more robust comparison for namespaced node titles.
         // return value of title attribute instead
-        NSString *title = [(DOMElement *)node getAttribute:@"title"];
+        NSString *title = [node stringValueOfAttribute:@"title"];
         if (title)
             return title;
     }

Modified: trunk/bibdesk/BDSKIEEEXploreParser.m
===================================================================
--- trunk/bibdesk/BDSKIEEEXploreParser.m        2018-08-24 14:41:53 UTC (rev 
22524)
+++ trunk/bibdesk/BDSKIEEEXploreParser.m        2018-08-24 14:51:01 UTC (rev 
22525)
@@ -88,8 +88,8 @@
         // parse all links on a TOC page
         NSArray *abstractPlusLinkNodes = [[[self domDocument] documentElement] 
nodesForXPath:containsAbstractPlusLinkNode];
                
-        for (DOMElement *aplinknode in abstractPlusLinkNodes) {
-            NSString *hrefValue = [aplinknode getAttribute:@"href"];
+        for (DOMNode *aplinknode in abstractPlusLinkNodes) {
+            NSString *hrefValue = [aplinknode stringValueOfAttribute:@"href"];
             [abstractPageURLs addObject:[NSURL URLWithString:hrefValue 
relativeToURL:url]];
         }
     }

Modified: trunk/bibdesk/BDSKIUCrParser.m
===================================================================
--- trunk/bibdesk/BDSKIUCrParser.m      2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKIUCrParser.m      2018-08-24 14:51:01 UTC (rev 22525)
@@ -37,6 +37,7 @@
  */
 
 #import "BDSKIUCrParser.h"
+#import "DOMNode_BDSKExtensions.h"
 
 
 @implementation BDSKIUCrParser
@@ -44,7 +45,7 @@
 + (NSString *)citationNodeXPath { return 
@"./body//table[@class='citation']//td/input[@name='cnor' and 
string-length(@value)!=0]"; }
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    NSString *cnorValue = [(DOMElement *)node getAttribute:@"value"];
+    NSString *cnorValue = [node stringValueOfAttribute:@"value"];
     return 
[@"//scripts.iucr.org/cgi-bin/biblio?Action=download&saveas=BIBTeX&cnor=" 
stringByAppendingString:cnorValue];
 }
 

Modified: trunk/bibdesk/BDSKSIAMParser.m
===================================================================
--- trunk/bibdesk/BDSKSIAMParser.m      2018-08-24 14:41:53 UTC (rev 22524)
+++ trunk/bibdesk/BDSKSIAMParser.m      2018-08-24 14:51:01 UTC (rev 22525)
@@ -37,14 +37,14 @@
  */
 
 #import "BDSKSIAMParser.h"
+#import "DOMNode_BDSKExtensions.h"
 
-
 @implementation BDSKSIAMParser
 
 + (NSString *)citationNodeXPath { return @"./body//a[text()='Download 
Citations']"; }
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    NSMutableString *hrefValue = [[[(DOMElement *)node getAttribute:@"href"] 
mutableCopy] autorelease];
+    NSMutableString *hrefValue = [[[node stringValueOfAttribute:@"href"] 
mutableCopy] autorelease];
     NSRange range = [hrefValue rangeOfString:@"showCitFormats" 
options:NSCaseInsensitiveSearch];
     if (range.location != NSNotFound)
         [hrefValue replaceCharactersInRange:range 
withString:@"downloadCitation"];

Modified: trunk/bibdesk/BDSKScienceDirectParser.m
===================================================================
--- trunk/bibdesk/BDSKScienceDirectParser.m     2018-08-24 14:41:53 UTC (rev 
22524)
+++ trunk/bibdesk/BDSKScienceDirectParser.m     2018-08-24 14:51:01 UTC (rev 
22525)
@@ -37,13 +37,15 @@
  */
 
 #import "BDSKScienceDirectParser.h"
+#import "DOMNode_BDSKExtensions.h"
 
+
 @implementation BDSKScienceDirectParser
 
 + (NSString *)citationNodeXPath { return @"./head/meta[@name='citation_pii']"; 
}
 
 + (NSString *)citationURLStringFromNode:(DOMNode *)node {
-    NSString *piiValue = [(DOMElement *)node getAttribute:@"content"];
+    NSString *piiValue = [node stringValueOfAttribute:@"content"];
     return [NSString 
stringWithFormat:@"https://www.sciencedirect.com/sdfe/arp/cite?pii=%@&format=text%%2Fx-bibtex&withabstract=true";,
 piiValue];
 }
 

Modified: trunk/bibdesk/DOMNode_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/DOMNode_BDSKExtensions.h      2018-08-24 14:41:53 UTC (rev 
22524)
+++ trunk/bibdesk/DOMNode_BDSKExtensions.h      2018-08-24 14:51:01 UTC (rev 
22525)
@@ -48,5 +48,6 @@
 
 - (NSString *)stringValue;
 - (NSString *)stringValuePreservingBreaks;
+- (NSString *)stringValueOfAttribute:(NSString *)attrName;
 
 @end

Modified: trunk/bibdesk/DOMNode_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/DOMNode_BDSKExtensions.m      2018-08-24 14:41:53 UTC (rev 
22524)
+++ trunk/bibdesk/DOMNode_BDSKExtensions.m      2018-08-24 14:51:01 UTC (rev 
22525)
@@ -113,4 +113,10 @@
     return string;
 }
 
+- (NSString *)stringValueOfAttribute:(NSString *)attrName {
+    if ([self nodeType] != DOM_ELEMENT_NODE)
+        return nil;
+    return[(DOMElement *)self getAttribute:attrName];
+}
+
 @end

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to