/* * Scholar.Ingester.MARC_Record.js * Stefano Bargioni, Pontificia Universitˆ della Santa Croce - Biblioteca * Trattamento di record MARC in JavaScript * * Original version copyright (C) 2005 Stefano Bargioni, licensed under the LGPL * (Available at http://www.pusc.it/bib/mel/Scholar.Ingester.MARC_Record.js) * * This library is free software; you can redistribute it or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ Scholar.Ingester.MARC_Record = function() { // new MARC record this.VERSIONE = '2.6.6b'; this.VERSIONE_data ='2005-05-10'; this.leader = { record_length:'00000', record_status:'n', // acdnp type_of_record:' ', bibliographic_level:' ', type_of_control:' ', character_coding_scheme:' ', indicator_count:'2', subfield_code_length:'2', base_address_of_data:'00000', encoding_level:' ', descriptive_cataloging_form:' ', linked_record_requirement:' ', entry_map:'4500' }; // 24 chars this.field_terminator = '\x1E'; this.record_terminator = '\x1D'; this.subfield_delimiter = '\x1F'; this.directory = ''; this.directory_terminator = this.field_terminator; this.variable_fields = new Array(); return this; } Scholar.Ingester.MARC_Record.prototype.load = function(s,f) { // loads record s passed in format f if (f == 'binary') { this.leader.record_length = '00000'; this.leader.record_status = s.substr(5,1); this.leader.type_of_record = s.substr(6,1); this.leader.bibliographic_level = s.substr(7,1); this.leader.type_of_control = s.substr(8,1); this.leader.character_coding_scheme = s.substr(9,1); this.leader.indicator_count = '2'; this.leader.subfield_code_length = '2'; this.leader.base_address_of_data = '00000'; this.leader.encoding_level = s.substr(17,1); this.leader.descriptive_cataloging_form = s.substr(18,1); this.leader.linked_record_requirement = s.substr(19,1); this.leader.entry_map = '4500'; this.directory = ''; this.directory_terminator = this.field_terminator; this.variable_fields = new Array(); // loads fields var campi = s.split(this.field_terminator); var k; for (k=1; k<-1+campi.length; k++) { // the first and the last are unuseful // the first is the header + directory, the last is the this.record_terminator var tag = campi[0].substr(24+(k-1)*12,3); var ind1 = ''; var ind2 = ''; var value = campi[k]; if (tag.substr(0,2) != '00') { ind1 = campi[k].substr(0,1); ind2 = campi[k].substr(1,1); value = campi[k].substr(2); } this.add_field(tag,ind1,ind2,value); } } else if (f == 'MARC_Harvard') { var linee = s.split('\n'); for (var i=0; i '008' && tag < '899') { // jumps low and high tags, also H03 and similia if (tag != '040') this.add_field(tag,ind1,ind2,value); } } this.add_field_005(); } else if (f == 'MARC_BNI') { var linee = s.split('\n'); for (var i=0; i '008' && tag < '899') { // jumps low and high tags if (tag != '040') this.add_field(tag,ind1,ind2,value); } } this.add_field_005(); } else if (f == 'MARC_Loc') { // MARC copiato dal browser dal sito catalog.loc.gov var linee = s.split('\n'); for (var i=0; i '008' && tag < '899') { // jumps low and high tags if (tag != '040') this.add_field(tag,ind1,ind2,value); } } this.add_field_005(); } else if (f == 'MARC_PAC') { var linee = s.split('\n'); for (var i=0; i '008' && tag < '899') { // jumps low and high tags if (tag != '040') this.add_field(tag,ind1,ind2,value); } } this.add_field_005(); } this.update_record_length(); this.update_base_address_of_data(); return this; } Scholar.Ingester.MARC_Record.prototype.update_base_address_of_data = function() { // updates the base_address this.leader.base_address_of_data = this._zero_fill(24+this.variable_fields.length*12+1,5); return this.leader.base_address_of_data; } Scholar.Ingester.MARC_Record.prototype.update_displacements = function() { // rebuilds the directory var displ = 0; this.directory = ''; for (var i=0; i 0) return true; return false; } Scholar.Ingester.MARC_Record.prototype.MARC_field = function(rec,tag,ind1,ind2,value) { // new MARC gield this.tag = tag; this.occ = rec.count_occ(tag)+1; // occurrence order no. this.ind1 = ind1; if (this.ind1 == '') this.ind1 = ' '; this.ind2 = ind2; if (this.ind2 == '') this.ind2 = ' '; if (tag.substr(0,2) == '00') { this.ind1 = ''; this.ind2 = ''; } this.value = value; return this; } Scholar.Ingester.MARC_Record.prototype.display = function(type) { // displays record in format type type = type.toLowerCase(); if (type == 'binary') return this.show_leader() + this.directory + this.field_terminator + this.show_fields() + this.record_terminator; if (type == 'html') { var s = ''; var l = R.show_leader(); s += ''; var i; for (i=0; i'; s += ''; s += ''; var v = this.variable_fields[i].value; if (this.variable_fields[i].tag == '008') v = v.replace(/ /g,' '); s += ''; s += ''; } s += '
000'+l+'
'+ind1+''+ind2+''+this._ddagger(v)+'
'; return s; } if (type == 'xml') { s = ''; s += ''; s += ''+this.show_leader()+''; // var i; for (i=0; i'+this.variable_fields[i].value+''; else { var subfields = this.variable_fields[i].value.split(this.subfield_delimiter); // alert(this.variable_fields[i].value+' '+subfields.length); // test if (subfields.length == 1) subfields[1] = '?'+this.variable_fields[i].value; var sf = ''; for (var j=1; j'+subfields[j].substr(1)+''; } s += '' + sf + ''; } } s += ''; return s; } if (type == 'xml-html') { s = this.display('xml'); // abbellimenti s = s.replace(/\/,'\n '); s = s.replace(/\ s = s.replace(/\/g,'>'); // colore alle keyword s = s.replace(/(controlfield|datafield|collection|record|leader|subfield)/g,'$1'); s = s.replace(/(tag|code|ind1|ind2)=/g,'$1='); return s; } return false; } Scholar.Ingester.MARC_Record.prototype.get_field = function(tag) { // returns an array of values, one for each occurrence var v = new Array(); var i; for (i=0; i= this.directory.length) alert('Internal error!'); this.directory = this.directory.substr(0,i) + this.directory.substr(i+12); // updates lengths this.update_base_address_of_data(); this.update_displacements(); this.update_record_length(); return true; } Scholar.Ingester.MARC_Record.prototype._ddagger = function(s) { // display doubledagger in html code s = s.replace(/\%1F(.)/g, "‡$1"); s = s.replace(/\x1F(.)/g, "‡$1"); return s; } Scholar.Ingester.MARC_Record.prototype._trim = function(s) { // eliminates blanks from both sides s = s.replace(/\s+$/,''); return s.replace(/^\s+/,''); } Scholar.Ingester.MARC_Record.prototype._zero_fill = function(s,l) { // left '0' padding of s, up to l (l<=15) var t = '000000000000000'; t = t+s; return t.substr(t.length-l,l); } Scholar.Ingester.MARC_Record.prototype.version = function() { // returns version and date return 'MARC Editor Lite '+this.VERSIONE+' ('+this.VERSIONE_data+')'; }