Revision: 27524
http://sourceforge.net/p/bibdesk/svn/27524
Author: hofman
Date: 2022-06-02 15:37:56 +0000 (Thu, 02 Jun 2022)
Log Message:
-----------
Convenience method to create bibitem with optional linked files and/or Url field
Modified Paths:
--------------
trunk/bibdesk/BDSKArxivParser.m
trunk/bibdesk/BDSKCOinSParser.m
trunk/bibdesk/BDSKIACRParser.m
trunk/bibdesk/BDSKISIGroupServer.m
trunk/bibdesk/BDSKSpringerParser.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
Modified: trunk/bibdesk/BDSKArxivParser.m
===================================================================
--- trunk/bibdesk/BDSKArxivParser.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BDSKArxivParser.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -155,17 +155,12 @@
AGRegex *journalRegex3 = [AGRegex
regexWithPattern:@"(.+[^0-9])([0-9]+):(.*),([0-9]{4})"
options:AGRegexMultiline];
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
- BOOL doiIsURL = [BDSKDoiString isRemoteURLField];
-
NSMutableArray *items = [NSMutableArray arrayWithCapacity:0];
for (DOMNode *arxivSearchResult in arxivSearchResults) {
NSMutableDictionary *pubFields = [NSMutableDictionary dictionary];
- NSMutableArray *pubFiles = [NSMutableArray array];
+ NSMutableArray *pubURLs = [NSMutableArray array];
NSString *string = nil;
NSArray *nodes;
DOMNode *node;
@@ -190,10 +185,7 @@
// fix relative urls
if (NO == [string containsString:@"://"])
string = [[NSURL URLWithString:string relativeToURL:url]
absoluteString];
- if (addUrlField)
- [pubFields setValue:string forKey:BDSKUrlString];
- if (addLinkedFiles)
- [pubFiles addObject:[BDSKLinkedFile
linkedFileWithURLString:string]];
+ [pubURLs addObject:string];
}
}
@@ -207,17 +199,11 @@
string = [[NSURL URLWithString:string relativeToURL:url]
absoluteString];
if ([[string lowercaseString] hasSuffix:@".pdf"] == NO)
string = [string stringByAppendingString:@".pdf"];
- if (addUrlField)
- [pubFields setValue:string forKey:BDSKUrlString];
- if (addLinkedFiles)
- [pubFiles insertObject:[BDSKLinkedFile
linkedFileWithURLString:string] atIndex:0];
+ [pubURLs insertObject:string atIndex:0];
}
} else if ((string = [pubFields objectForKey:@"Eprint"])) {
string = [NSString stringWithFormat:@"https://%@/pdf/%@.pdf", [url
host], string];
- if (addUrlField)
- [pubFields setValue:string forKey:BDSKUrlString];
- if (addLinkedFiles)
- [pubFiles insertObject:[BDSKLinkedFile
linkedFileWithURLString:string] atIndex:0];
+ [pubURLs insertObject:string atIndex:0];
}
// search for DOI
@@ -226,8 +212,8 @@
// successfully found the result DOI
if ((string = [node stringValue])) {
[pubFields setValue:string forKey:BDSKDoiString];
- if (addLinkedFiles && doiIsURL)
- [pubFiles addObject:[BDSKLinkedFile
linkedFileWithURLString:[@"https://doi.org/" stringByAppendingString:[[node
stringValue] stringByAddingPercentEscapesForPath]]]];
+ if ([BDSKDoiString isRemoteURLField])
+ [pubURLs addObject:[@"https://doi.org/"
stringByAppendingString:[[node stringValue]
stringByAddingPercentEscapesForPath]]];
}
}
@@ -304,7 +290,7 @@
}
}
- BibItem *item = [[BibItem alloc] initWithType:BDSKArticleString
citeKey:nil pubFields:pubFields files:pubFiles isNew:YES];
+ BibItem *item = [[BibItem alloc] initWithType:BDSKArticleString
citeKey:nil pubFields:pubFields URLStrings:pubURLs];
[items addObject:item];
[item release];
Modified: trunk/bibdesk/BDSKCOinSParser.m
===================================================================
--- trunk/bibdesk/BDSKCOinSParser.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BDSKCOinSParser.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -108,7 +108,7 @@
return nil;
NSMutableDictionary *fieldsDict = [NSMutableDictionary dictionary];
- NSMutableArray *files = [NSMutableArray array];
+ NSMutableArray *urls = [NSMutableArray array];
NSString * publicationType = BDSKMiscString;
NSString * startPage = nil;
NSString * endPage = nil;
@@ -116,10 +116,6 @@
NSString * auLast = nil;
NSString * auInitials = nil;
NSString * auSuffix = nil;
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
- BOOL doiIsURL = [BDSKDoiString isRemoteURLField];
for (NSString *component in components) {
NSArray * keyValue = [component
componentsSeparatedByString:@"="];
@@ -226,10 +222,7 @@
NSURL * URL = [NSURL URLWithString:value];
if (URL && ([@"http"
isCaseInsensitiveEqual:[URL scheme]] || [@"https" isCaseInsensitiveEqual:[URL
scheme]])) {
// add http/https URLs to the FileView items only, rather
than the Url field. This lets us process more than one of them and avoid adding
links to library catalogue entries to the BibTeX record. I haven't seen other
usable URL typese yet.
- if (addUrlField)
- [fieldsDict setObject:value forKey:BDSKUrlString];
- if (addLinkedFiles)
- [files addObject:[BDSKLinkedFile
linkedFileWithURLString:[URL absoluteString]]];
+ [urls addObject:[URL absoluteString]];
}
if ([value rangeOfString:@"doi"
options:NSCaseInsensitiveSearch].location != NSNotFound) {
// the value contains doi, so assume
it's DOI information and also add it to the DOI field. There should only be a
single occurrence of those, so add it right here to make sure the format isn't
messed up in case multiple fields contain that substring
@@ -237,8 +230,8 @@
if (range.length && range.location > 0) {
NSString *doi = [value
substringFromIndex:range.location];
[fieldsDict setObject:doi
forKey:BDSKDoiString];
- if (addLinkedFiles && doiIsURL)
- [files addObject:[BDSKLinkedFile
linkedFileWithURLString:[@"https://doi.org/" stringByAppendingString:[doi
stringByAddingPercentEscapesForPath]]]];
+ if ([BDSKDoiString isRemoteURLField])
+ [urls addObject:[@"https://doi.org/"
stringByAppendingString:[doi stringByAddingPercentEscapesForPath]]];
}
}
}
@@ -319,8 +312,7 @@
return [[[BibItem alloc] initWithType:publicationType
citeKey:nil
pubFields:fieldsDict
- files:files
- isNew:YES] autorelease];
+ URLStrings:urls] autorelease];
}
// Process the document.
Modified: trunk/bibdesk/BDSKIACRParser.m
===================================================================
--- trunk/bibdesk/BDSKIACRParser.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BDSKIACRParser.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -71,10 +71,6 @@
// is this a search results page or an individual article?
BOOL isSearch = [[[url path] lowercaseString]
isEqualToString:@"/cgi-bin/search.pl"];
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
-
// construct the source item(s) to parse
NSArray *sources = nil;
DOMElement *rootElement = [[self domDocument] documentElement];
@@ -102,7 +98,7 @@
for (DOMNode *sourceNode in sources) {
NSMutableDictionary *pubFields = [NSMutableDictionary
dictionary];
- NSArray *filesArray = nil;
+ NSArray *urlsArray = nil;
NSString *pathToSearch = nil;
DOMNode *node;
NSString *string;
@@ -135,18 +131,13 @@
if ((year != nil) && (reportNum != nil)) {
[pubFields setValue:year forKey:BDSKYearString];
[pubFields setValue:[NSString
stringWithFormat:@"Cryptology ePrint Archive, Report %@/%@", year, reportNum]
forKey:@"Note"];
- if (addUrlField)
- [pubFields setValue:[urlBaseString
stringByAppendingPathExtension:@"pdf"] forKey:BDSKUrlString];
- if (addLinkedFiles) {
- filesArray = [NSArray arrayWithObjects:
- [BDSKLinkedFile linkedFileWithURL:[NSURL
URLWithString:[urlBaseString stringByAppendingPathExtension:@"pdf"]]
delegate:nil],
- [BDSKLinkedFile linkedFileWithURL:[NSURL
URLWithString:urlBaseString] delegate:nil], nil];
- }
+ urlsArray = [NSArray arrayWithObjects:
+ [urlBaseString stringByAppendingPathExtension:@"pdf"],
urlBaseString, nil];
[pubFields setValue:[NSString
stringWithFormat:@"\\url{%@}", urlBaseString] forKey:@"Eprint"];
}
// add item
- BibItem *item = [[BibItem alloc] initWithType:BDSKMiscString
citeKey:nil pubFields:pubFields files:filesArray isNew:YES];
+ BibItem *item = [[BibItem alloc] initWithType:BDSKMiscString
citeKey:nil pubFields:pubFields URLStrings:urlsArray];
[items addObject:item];
[item release];
Modified: trunk/bibdesk/BDSKISIGroupServer.m
===================================================================
--- trunk/bibdesk/BDSKISIGroupServer.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BDSKISIGroupServer.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -603,7 +603,7 @@
- (BibItem *)newItemFromInfo:(NSDictionary *)pubInfo {
NSMutableDictionary *pubFields = [pubInfo mutableCopy];
- NSArray *files = nil;
+ NSArray *urls = nil;
NSString *pubType = [pubFields objectForKey:BDSKPubTypeString];
[pubFields removeObjectForKey:BDSKPubTypeString];
@@ -614,19 +614,16 @@
// insert the WOK URL into the normal file array if shouldn't be put
elsewhere
if (ISIURLFieldName)
[pubFields setObject:wokURL forKey:ISIURLFieldName];
- else if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey])
- [pubFields setObject:wokURL forKey:BDSKUrlString];
- else
- files = [[NSArray alloc] initWithObjects:[BDSKLinkedFile
linkedFileWithURL:[NSURL URLWithStringByNormalizingPercentEscapes:wokURL]
delegate:nil], nil];
+ urls = [[NSArray alloc] initWithObjects:wokURL, nil];
}
- BibItem *pub = [[BibItem alloc] initWithType:pubType citeKey:nil
pubFields:pubFields files:files isNew:YES];
+ BibItem *pub = [[BibItem alloc] initWithType:pubType citeKey:nil
pubFields:pubFields URLStrings:urls];
// we set the macroResolver so we know the fields of this item may refer
to it, so we can prevent scripting from adding this to the wrong document
[pub setMacroResolver:[group macroResolver]];
[pubFields release];
- [files release];
+ [urls release];
return pub;
}
Modified: trunk/bibdesk/BDSKSpringerParser.m
===================================================================
--- trunk/bibdesk/BDSKSpringerParser.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BDSKSpringerParser.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -59,7 +59,8 @@
DOMNode *node = [domDocument documentElement];
NSMutableDictionary *pubFields = [NSMutableDictionary dictionary];
- NSMutableArray *filesArray = nil;
+ NSMutableArray *urlsArray = [NSMutableArray array];
+;
NSString *pubType = BDSKMiscString;
// set publication type
@@ -157,25 +158,13 @@
}
}
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
- BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
- BOOL doiIsURL = [BDSKDoiString isRemoteURLField];
+ // URL to PDF
+ [urlsArray addObject:[[NSURL URLWithString:@"fulltext.pdf"
relativeToURL:url] absoluteString]];
+ if ([BDSKDoiString isRemoteURLField])
+ [urlsArray addObject:[@"https://doi.org/" stringByAppendingString:[doi
stringByAddingPercentEscapesForPath]]];
- if (addUrlField) {
- // URL to PDF
- [pubFields setValue:[[NSURL URLWithString:@"fulltext.pdf"
relativeToURL:url] absoluteString] forKey:BDSKUrlString];
- }
- if (addLinkedFiles) {
- filesArray = [NSMutableArray array];
- // URL to PDF
- [filesArray addObject:[BDSKLinkedFile linkedFileWithURL:[NSURL
URLWithString:@"fulltext.pdf" relativeToURL:url] delegate:nil]];
- if (doi && doiIsURL)
- [filesArray addObject:[BDSKLinkedFile linkedFileWithURL:[NSURL
URLWithString:[@"https://doi.org/" stringByAppendingString:[doi
stringByAddingPercentEscapesForPath]]] delegate:nil]];
- }
+ return [[BibItem alloc] initWithType:pubType citeKey:nil
pubFields:pubFields URLStrings:urlsArray];
- return [[BibItem alloc] initWithType:pubType citeKey:nil
pubFields:pubFields files:filesArray isNew:YES];
-
}
+ (NSString *)citationNodeXPath { return @"./body//a[@data-gtmlabel='BIB']"; }
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BibItem.h 2022-06-02 15:37:56 UTC (rev 27524)
@@ -184,6 +184,8 @@
- (id)initWithType:(NSString *)type citeKey:(NSString *)key
pubFields:(NSDictionary *)fieldsDict isNew:(BOOL)isNew;
+- (id)initWithType:(NSString *)type citeKey:(NSString *)key
pubFields:(NSMutableDictionary *)fieldsDict URLStrings:(NSArray *)urlsArray;
+
/*!
@method dealloc
@abstract deallocates the receiver and its data objects.
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2022-06-02 06:30:17 UTC (rev 27523)
+++ trunk/bibdesk/BibItem.m 2022-06-02 15:37:56 UTC (rev 27524)
@@ -298,6 +298,24 @@
return self;
}
+- (id)initWithType:(NSString *)type citeKey:(NSString *)key
pubFields:(NSMutableDictionary *)fieldsDict URLStrings:(NSArray *)urlsArray{
+ NSMutableArray *filesArray = nil;
+ if ([urlsArray count]) {
+ NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
+ BOOL addLinkedFiles = NO == [sud boolForKey:BDSKUseLocalUrlAndUrlKey];
+ BOOL addUrlField = addLinkedFiles == NO || [sud
boolForKey:BDSKAutomaticallyConvertURLFieldsKey] == NO || [sud
boolForKey:BDSKRemoveConvertedRemoteURLFieldsKey] == NO;
+ if (addLinkedFiles)
+ filesArray = [NSMutableArray array];
+ for (NSString *url in urlsArray) {
+ if (addLinkedFiles)
+ [filesArray addObject:[BDSKLinkedFile
linkedFileWithURLString:url]];
+ if ([fieldsDict objectForKey:BDSKUrlString] && addUrlField)
+ [(NSMutableDictionary *)fieldsDict setObject:url
forKey:BDSKUrlString];
+ }
+ }
+ return [self initWithType:type citeKey:citeKey pubFields:fieldsDict
files:filesArray isNew:YES];
+}
+
+ (NSString *)defaultCiteKey {
return defaultCiteKey;
}
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