Revision: 22514
http://sourceforge.net/p/bibdesk/svn/22514
Author: hofman
Date: 2018-08-23 13:10:05 +0000 (Thu, 23 Aug 2018)
Log Message:
-----------
Implement class specific domnode methods in class
Modified Paths:
--------------
trunk/bibdesk/BDSKHCiteParser.m
trunk/bibdesk/DOMNode_BDSKExtensions.h
trunk/bibdesk/DOMNode_BDSKExtensions.m
Modified: trunk/bibdesk/BDSKHCiteParser.m
===================================================================
--- trunk/bibdesk/BDSKHCiteParser.m 2018-08-23 13:01:36 UTC (rev 22513)
+++ trunk/bibdesk/BDSKHCiteParser.m 2018-08-23 13:10:05 UTC (rev 22514)
@@ -44,6 +44,8 @@
@interface BDSKHCiteParser (Private)
- (NSDate *)dateFromNode:(DOMNode *)node;
+- (NSString *)fullStringValueIfABBRFromNode:(DOMNode *)node;
+- (BOOL)nodeHasContainerParent:(DOMNode *)node;
- (NSString *)BTAuthorStringFromVCardNode:(DOMNode *)node
xpath:(DOMXPathExpression *)xpath;
- (NSMutableDictionary *)dictionaryFromCitationNode:(DOMNode *)citationNode
isContainer:(BOOL)isContainer xpaths:(NSDictionary *)xpaths;
@@ -109,8 +111,8 @@
NSString *typeString = nil;
for (DOMNode *node in typeNodes) {
- if(isContainer || [node hasParentWithClassName:@"container"] == NO)
- typeString = [node fullStringValueIfABBR];
+ if(isContainer || [self nodeHasContainerParent:node] == NO)
+ typeString = [self fullStringValueIfABBRFromNode:node];
}
if(typeString != nil){
@@ -128,7 +130,7 @@
// deal with this citation's container later
// note: todo - avoid second hasParentWithClassName by finding
container
// nodes first and caching those then checking against them here. (if
necessary)
- if(isContainer || [node hasParentWithClassName:@"container"] == NO)
+ if(isContainer || [self nodeHasContainerParent:node] == NO)
[rd setObject:[node stringValue] forKey:BDSKTitleString];
}
@@ -203,7 +205,7 @@
if([[URINode nodeName] isCaseInsensitiveEqual:@"a"]){
URIString = [URINode getAttribute:@"href"];
}else{
- URIString = [URINode fullStringValueIfABBR];
+ URIString = [self fullStringValueIfABBRFromNode:URINode];
}
if([URIString hasCaseInsensitivePrefix:@"http://"] || [URIString
hasCaseInsensitivePrefix:@"https://"]){
@@ -269,12 +271,33 @@
if([fnNodes count] < 1) return @"";
- return [[fnNodes objectAtIndex:0] fullStringValueIfABBR];
+ return [self fullStringValueIfABBRFromNode:[fnNodes objectAtIndex:0]];
}
+- (BOOL)nodeHasContainerParent:(DOMNode *)node {
+ DOMNode *parent = [node parentNode];
+ do {
+ if ([parent nodeType] != DOM_ELEMENT_NODE) return NO; // handles root
node
+ if ([[[(DOMElement *)parent getAttribute:@"class"]
componentsSeparatedByString:@" "] containsObject:@"container"])
+ return YES;
+ } while ((parent = [parent parentNode]));
+ return NO;
+}
+
+- (NSString *)fullStringValueIfABBRFromNode:(DOMNode *)node {
+ 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"];
+ if (title)
+ return title;
+ }
+ return [node stringValue];
+}
+
- (NSDate *)dateFromNode:(DOMNode *)node{
- NSString *fullString = [node fullStringValueIfABBR];
+ NSString *fullString = [self fullStringValueIfABBRFromNode:node];
NSDate *d;
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
Modified: trunk/bibdesk/DOMNode_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/DOMNode_BDSKExtensions.h 2018-08-23 13:01:36 UTC (rev
22513)
+++ trunk/bibdesk/DOMNode_BDSKExtensions.h 2018-08-23 13:10:05 UTC (rev
22514)
@@ -46,8 +46,5 @@
- (NSString *)stringValue;
- (NSString *)stringValuePreservingBreaks;
-- (NSString *)fullStringValueIfABBR;
-- (NSArray *)descendantOrSelfNodesWithClassName:(NSString *)className;
-- (BOOL)hasParentWithClassName:(NSString *)className;
@end
Modified: trunk/bibdesk/DOMNode_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/DOMNode_BDSKExtensions.m 2018-08-23 13:01:36 UTC (rev
22513)
+++ trunk/bibdesk/DOMNode_BDSKExtensions.m 2018-08-23 13:10:05 UTC (rev
22514)
@@ -106,29 +106,4 @@
return string;
}
-- (NSString *)fullStringValueIfABBR {
- if ([[self nodeName] isCaseInsensitiveEqual:@"abbr"]){
- //todo: will need more robust comparison for namespaced node titles.
- // return value of title attribute instead
- NSString *title = [(DOMElement *)self getAttribute:@"title"];
- if (title)
- return title;
- }
- return [self stringValue];
-}
-
-- (NSArray *)descendantOrSelfNodesWithClassName:(NSString *)className {
- return [self nodesForXPath:[NSString
stringWithFormat:@".//*[contains(concat(' ',normalize-space(@class),' '),' %@
')]", className]];
-}
-
-- (BOOL)hasParentWithClassName:(NSString *)className {
- DOMNode *parent = [self parentNode];
- do {
- if ([parent nodeType] != DOM_ELEMENT_NODE) return NO; // handles root
node
- if ([[[(DOMElement *)parent getAttribute:@"class"]
componentsSeparatedByString:@" "] containsObject:className])
- return YES;
- } while ((parent = [parent parentNode]));
- return NO;
-}
-
@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