1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2009 Equinox Software, Inc.
3 * Mike Rylander <miker@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
17 if(!dojo._hasResource["MARC.Batch"]) {
19 dojo.require('dojox.xml.parser');
20 dojo.require('MARC.Record');
22 dojo._hasResource["MARC.Batch"] = true;
23 dojo.provide("MARC.Batch");
24 dojo.declare('MARC.Batch', null, {
26 constructor : function(kwargs) {
29 this.source = kwargs.source;
30 this.delimiter = kwargs.delimiter
31 this.current_record = 0;
33 if (this.source) this.ready = true;
34 if (!this.ready && kwargs.url) this.fetchURL( kwargs.url );
36 if (this.ready) this.parse();
40 if (dojo.isObject( this.source )) { // assume an xml collection document
41 this.source = dojo.query('record', this.source);
43 } else if (this.source.match(/^\s*</)) { // this is xml text
44 this.source = dojox.xml.parser.parse( this.source );
46 } else { // must be a marcbreaker doc. split on blank lines
47 this.source = this.source.split(/^$/);
48 this.type = 'marcbreaker';
52 fetchURL : function (u) {
58 load : function (mrc) {
66 var chunk = this.source[this.current_record++];
70 args[this.type] = chunk;
71 if (this.delimiter) args.delimiter = this.delimiter;
72 return new MARC.Record(args);