Revision: 22524
http://sourceforge.net/p/bibdesk/svn/22524
Author: hofman
Date: 2018-08-24 14:41:53 +0000 (Fri, 24 Aug 2018)
Log Message:
-----------
Use string constants for xpaths
Modified Paths:
--------------
trunk/bibdesk/BDSKDOIWebParser.m
Modified: trunk/bibdesk/BDSKDOIWebParser.m
===================================================================
--- trunk/bibdesk/BDSKDOIWebParser.m 2018-08-24 14:35:53 UTC (rev 22523)
+++ trunk/bibdesk/BDSKDOIWebParser.m 2018-08-24 14:41:53 UTC (rev 22524)
@@ -42,22 +42,19 @@
#import "NSString_BDSKExtensions.h"
#import <AGRegex/AGRegex.h>
+static NSString *headMetaDoiXPath = @"./head/meta[contains(' citation_doi doi
prism.doi dc.identifier ',concat('
',translate(@name,'ACDEFIMNOPRST','acdefimnoprst'),' ')) and
(starts-with(translate(@content,'DOI','doi'),'doi:') or
starts-with(@content,'10.'))]";
+static NSString *bodyADoiXPath =
@"./body//a[starts-with(@href,'https://doi.org/') or
starts-with(@href,'http://dx.doi.org/')]";
@implementation BDSKDOIWebParser
+ (BOOL)canParseDocument:(DOMDocument *)domDocument fromURL:(NSURL *)url {
DOMNode *rootElement = [domDocument documentElement];
- NSString *doiXPath;
NSArray *nodes;
- doiXPath = @"./head/meta[contains(' citation_doi doi prism.doi
dc.identifier ',concat(' ',translate(@name,'ACDEFIMNOPRST','acdefimnoprst'),'
')) and (starts-with(translate(@content,'DOI','doi'),'doi:') or
starts-with(@content,'10.'))]";
-
- if (nil != [rootElement singleNodeForXPath:doiXPath])
+ if (nil != [rootElement singleNodeForXPath:headMetaDoiXPath])
return YES;
- doiXPath = @"./body//a[starts-with(@href,'https://doi.org/') or
starts-with(@href,'http://dx.doi.org/')]";
-
- if (nil != [rootElement singleNodeForXPath:doiXPath])
+ if (nil != [rootElement singleNodeForXPath:bodyADoiXPath])
return YES;
NSString *text = [[domDocument body] textContent];
@@ -78,8 +75,7 @@
AGRegexMatch *match;
NSString *doi;
- doiXPath = @"./head/meta[contains(' citation_doi doi prism.doi
dc.identifier ',concat(' ',translate(@name,'ACDEFIMNOPRST','acdefimnoprst'),'
')) and (starts-with(translate(@content,'DOI','doi'),'doi:') or
starts-with(@content,'10.'))]";
- node = [rootElement singleNodeForXPath:doiXPath];
+ node = [rootElement singleNodeForXPath:headMetaDoiXPath];
if (node) {
doi = [(DOMElement *)node getAttribute:@"content"];
@@ -92,8 +88,7 @@
}
if ([dois count] == 0) {
- doiXPath = @"./body//a[starts-with(@href,'https://doi.org/') or
starts-with(@href,'http://dx.doi.org/')]";
- nodes = [rootElement nodesForXPath:doiXPath];
+ nodes = [rootElement nodesForXPath:bodyADoiXPath];
for (node in nodes) {
doi = [(DOMElement *)node getAttribute:@"href"];
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