From 0518572c40d5b4a031ee3abe8563578ac92ebe35 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 15 Mar 2006 05:16:20 +0000 Subject: [PATCH] using try-catch and some methods instead of properties -- looking good so far git-svn-id: svn://svn.open-ils.org/ILS/trunk@3356 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../backend/catalog/biblio_fingerprint.js | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/javascript/backend/catalog/biblio_fingerprint.js b/Open-ILS/src/javascript/backend/catalog/biblio_fingerprint.js index aa1648bdc3..b5f73a2269 100644 --- a/Open-ILS/src/javascript/backend/catalog/biblio_fingerprint.js +++ b/Open-ILS/src/javascript/backend/catalog/biblio_fingerprint.js @@ -9,19 +9,29 @@ var mods_ns = new Namespace('http://www.loc.gov/mods/'); default xml namespace = mods_ns; var t = null; +var a = null; function extract_typed_title( ti ) { - log_debug(ti.toString()); - return ti.(hasOwnProperty("@type") && @type == 'uniform')[0] || - ti.(hasOwnProperty("@type") && @type == 'translated')[0] || - ti.(hasOwnProperty("@type") && @type == 'alternative')[0]; + try { + var types = ['uniform','translated','alternative']; + for ( var j in types ) { + for ( var i in ti ) { + if (ti[i].attribute("type") == types[j]) + return ti[i]; + } + } + + } catch (e) { + log_debug(e); + return ti[0]; + } } function extract_author( au ) { log_debug(au.toString()); - if ( au..role.length > 0 ) au = au.(role.text == 'creator' || role.text == 'author'); + if ( au..role.length() > 0 ) au = au.(role.text == 'creator' || role.text == 'author'); if ( au.(hasOwnProperty("@type")) ) { au = au.(@type == 'personal')[0] || @@ -41,10 +51,10 @@ if (modsdoc.typeOfResource != 'text') { quality = 10; // Look in related items for a good title - for ( var index in modsdoc.relatedItem.( /^(?:host)|(?:series)$/.test(@type) ) ) { + for ( var index in modsdoc.relatedItem.( hasOwnProperty('@type') && @type != 'series' && @type != 'host' ) ) { var ri = modsdoc.relatedItem[index]; if ( ri.(!hasOwnProperty("@type") )) { - t = extract_typed_title( ti.titleInfo.(hasOwnProperty('@type')) ); + t = extract_typed_title( ri.titleInfo.(hasOwnProperty('@type')) ); if (!t) { t = ri.titleInfo[0]; quality += 10; @@ -61,7 +71,7 @@ if (modsdoc.typeOfResource != 'text') { // Couldn't find a usable title in a related item if (t == null) { - t = extract_typed_title( modsdoc.titleInfo.(hasOwnProperty('@type')) ); + t = extract_typed_title( modsdoc.titleInfo ); if (!t) { t = modsdoc.titleInfo[0]; quality += 5; @@ -75,8 +85,7 @@ if (modsdoc.typeOfResource != 'text') { } else { quality = 20; - if (modsdoc.titleInfo.(hasOwnProperty('@type'))) - t = extract_typed_title( modsdoc.titleInfo ); + t = extract_typed_title( modsdoc.titleInfo ); if (t == null) { t = modsdoc.titleInfo[0]; -- 2.43.2