-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRIS.js
2550 lines (2215 loc) · 73.3 KB
/
RIS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"translatorID":"32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7",
"translatorType":3,
"label":"RIS",
"creator":"Simon Kornblith",
"target":"ris",
"minVersion":"1.0.2",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2010-12-16 23:48:00"
}
/**
================================
To use this RIS.js:
================================
- To correctly import File Attachments, you must edit RIS.js and place the
absolute path to your EndNote PDF folder:
<path_to_folder_where_EndNote_library_lives>/<EndNote_library_name>.Data/PDF/
in the variable "RIS_internalPDFPath."
- If you want to get attached PDFs for Journal Articles, you need to go into
the Refman Output Style in style editor (in EndNote X14 for Mac, you get
there via Edit->Output Styles->Open Style Manager) and change L1 from
outputting "URL" to outputting "File Attachments". So the line will go
from looking like this:
L1 - `URL|`
to looking like this:
L1 - `File Attachments|`
I'd probably make a copy of the style, too, before you change anything.
--------------------------------
Notes on how this RIS.js works:
--------------------------------
- If you have lots of files attached to a given reference, Zotero will
sometimes freeze up. 3 or 4 usually works just fine. This code contains
a variable, "RIS_maxImports", that defines how many import files it will
process per reference before storing subsequent ones in notes, such that you
can import them by hand later. It will also attach a note and log debug
messages each time it encounters a file that it doesn't import, so if you
want to know which files you need to update, turn on debugging before you
run your import, then search for "RIS.js" in the debug output.
- * If you disable all addons other than zotero and python when you run a large
import, it makes it much less likely you will break Firefox, even if you
have lots of attachments on some references.
- the variable "RIS_risFieldToImportFieldMap", defined around line 1065, is the
master mapping of RIS tags to their processing instructions. RIS tags are
either mapped directly to an EndNote field (CN is dumped into "callNumber" field):
CN : new ImportField( ImportField.IN_TYPE_DIRECT, "callNumber", null, false ),
or passed to a function for processing (A3 is passed to "processCreator" function):
A3 : new ImportField( ImportField.IN_TYPE_FUNCTION, "", processCreator, true ),
Any tag that isn't in the map will be appended to the reference as a note.
- processing functions are defined above "RIS_risFieldToImportFieldMap", in
alphabetical order. They should accept the following arguments:
- item_IN - Zotero Item instance that we are populating.
- tag_IN - String name of tag we are currently processing.
- value_IN - String value of current tag (if multiple lines, will be a space-delimited concatenation of values from each line).
- valueArray_IN - optional Array of values if multiple values for a given tag.
- To add a new processing function, define the function, then either update the
mapping for the field you will process to reflect that it is now being
passed to a function instead of being placed directly into a field or add
a new row for the mapping.
- Example of turning a direct mapping into a function (pass CN to "processCN"
instead of just putting it in the "callNumber" zotero field):
CN : new ImportField( ImportField.IN_TYPE_DIRECT, "callNumber", null, false ),
becomes (after defining processCN()):
CN : new ImportField( ImportField.IN_TYPE_FUNCTION, "", processCN, false ),
- processTY() is where the itemType is set, based on the reference type in the
TY tag.
- Regular Expression seem to make Firefox more likely to go out to lunch when
combined with PDF import and processing, so I removed all from my code in
this file.
*/
Zotero.configure("dataMode", "line");
Zotero.addOption("exportNotes", true);
Zotero.addOption("exportCharset", "UTF-8");
// full path to EndNote directory that contains included files, including trailing slash.
var RIS_internalPDFPath = "";
var RIS_maxImports = 20;
var RIS_unknownTag = "RIS_unknown";
function detectImport() {
var line;
var i = 0;
while((line = Zotero.read()) !== false) {
line = line.replace(/^\s+/, "");
if(line != "") {
if(line.substr(0, 6).match(/^TY {1,2}- /)) {
return true;
} else {
if(i++ > 3) {
return false;
}
}
}
}
}
var fieldMap = {
ID:"itemID",
T1:"title",
T3:"series",
JF:"publicationTitle",
CY:"place",
JA:"journalAbbreviation"
//M3:"DOI",
};
var inputFieldMap = {
AB:"abstractNote",
CN:"callNumber",
CT:"title",
CY:"place",
//ET:"edition",
TI:"title"
};
// TODO: figure out if these are the best types for letter, interview, webpage
// TODO: EDBOOK = book, too. Need to rewrite so the EndNote code is the key,
// references value of Zotero type, since multiple EndNote types can map
// to one Zotero type. Probably need to keep original type around, too, so
// we can reference it (since EDBOOK and BOOK have different output, for
// instance).
var typeMap = {
artwork:"ART",
audioRecording:"SOUND",
bill:"BILL",
blogPost:"ELEC",
book:"BOOK",
bookSection:"CHAP",
case:"CASE",
computerProgram:"COMP",
conferencePaper:"CONF",
dictionaryEntry:"DICT",
document:"GEN",
email:"ICOMM",
film:"MPCT",
forumPost:"ICOMM",
hearing:"HEAR",
instantMessage:"ICOMM",
interview:"PCOMM",
journalArticle:"JOUR",
letter:"PCOMM",
magazineArticle:"MGZN",
manuscript:"PAMP",
map:"MAP",
newspaperArticle:"NEWS",
patent:"PAT",
//podcast:"GEN",
podcast:"SOUND",
presentation:"GEN",
radioBroadcast:"GEN",
report:"RPRT",
statute:"STAT",
thesis:"THES",
tvBroadcast:"GEN",
videoRecording:"VIDEO",
webpage:"ELEC"
};
// supplements outputTypeMap for importing
// TODO: DATA, MUSIC
// instead, making this the master for all inputs (duplication, but there can
// be multiple RIS types that map to a given Zotero item type).
var inputTypeMap = {
ABST : "journalArticle",
ADVS : "film",
AGGR : "webpage", //supposed to be Aggregated Database... No database item type?
ART : "artwork",
BILL : "bill",
BLOG : "blogPost",
BOOK : "book",
CASE : "case",
CHAP : "bookSection",
CHART : "artwork",
CLSWK : "document", // supposed to be "Classical Work"
COMP : "computerProgram",
CONF : "conferencePaper",
CPAPER : "conferencePaper",
CTLG : "magazineArticle",
DATA : "webpage", // supposed to be Dataset, but no item type for data yet?
DBASE : "webpage", // supposed to be Online Database, but no item type for data yet?
DICT : "dictionaryEntry",
EBOOK : "book",
EDBOOK : "book",
EJOUR : "webpage", // Electronic Journal in EndNote - just a web page?
//ELEC : "blogPost",
ELEC : "webpage",
EQUA : "artwork", // supposed to be "Equation"
FIGURE : "artwork", // supposed to be "Figure"
//GEN : "presentation",
//GEN : "tvBroadcast",
//GEN : "radioBroadcast",
//GEN : "podcast",
GEN : "document",
GOVDOC : "document", // supposed to match "Government Document"
GRANT : "document", // supposed to be "Grant" or "Grant application".
HEAR : "hearing",
//ICOMM : "instantMessage",
//ICOMM : "forumPost",
ICOMM : "email",
INPR : "manuscript",
JFULL : "journalArticle",
JOUR : "journalArticle",
LEGAL : "statute", // supposed to match "Legal Rule or Regulation"
MANSCPT : "manuscript",
MAP : "map",
MGZN : "magazineArticle",
MPCT : "film",
MULTI : "webpage", // supposed to match "Online Multimedia".
MUSIC : "audioRecording", // supposed to match "Muscial Score".
NEWS : "newspaperArticle",
PAMP : "manuscript",
PAT : "patent",
//PCOMM : "letter",
PCOMM : "interview", // supposed to match to "Personal Communication"
RPRT : "report",
SER : "book",
SLIDE : "artwork",
SOUND : "audioRecording",
STAND : "document", // supposed to map to "Standard"
STAT : "statute",
THES : "thesis",
UNBILL : "manuscript",
UNPB : "manuscript",
VIDEO : "videoRecording",
WEB : "webpage"
};
/**
* Class ImportField
* object for each RIS property that holds:
* - inType - type of input mapping - either "direct" (get direct mapping to Zotero item property from inMapping) or "function" (get function pointer of function used to process RIS property from inFunction).
* - inMapping - if mapping between RIS field and Zotero item property is direct (inType = "direct"), name of associated Zotero item property.
* - inFunction - if mapping between RIS field and Zotero item is complicated (inType = "function"), so if different for different types, or lots of translation required, then this reference stores a function pointer to a function with a standard signature (use signature of function processLinkTag( item_IN, tag_IN, value_IN, valueArray_IN )) that accepts item, tag name, value, and an optional value array, uses those values to appropriately process incoming tag, place the results in the item passed in.
* - isInSpec - boolean variable, set to true if RIS property is from actual spec, false if not.
* - all library functions re-used across multiple RIS properties.
* - method to accept item_IN, tag_IN, value_IN, valueArray_IN and deal with the internal configuration of the ImportField, return item_IN with the RIS tag appropriately processed.
*/
function ImportField( inType_IN, inMapping_IN, inFunction_IN, isInSpec_IN )
{
// properties
this.inType = inType_IN;
this.inMapping = inMapping_IN;
this.inFunction = inFunction_IN;
this.isInSpec = isInSpec_IN;
// methods
this.addCreatorName = addCreatorName;
this.processImportField = function( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// declare variables
var myType = "";
// get type
myType = this.inType;
// direct or function?
if ( myType == ImportField.IN_TYPE_DIRECT )
{
// direct mapping - place value in item.
item_OUT[ this.inMapping ] = value_IN;
}
else if ( myType == ImportField.IN_TYPE_DIRECT_APPEND )
{
// direct mapping - if already a value, append item, separated by
// a " ".
if ( item_OUT[ this.inMapping ] )
{
// nothing in the field now, so just store value.
item_OUT[ this.inMapping ] = item_OUT[ this.inMapping ] + " " + value_IN;
}
else
{
// nothing in the field now, so just store value.
item_OUT[ this.inMapping ] = value_IN;
}
}
else if ( myType == ImportField.IN_TYPE_FUNCTION )
{
// process using a function, not a direct mapping.
item_OUT = this.inFunction( item_IN, tag_IN, value_IN, valueArray_IN );
}
return item_IN;
} //-- end function processImportField() --//
} //-- end class ImportField --//
ImportField.IN_TYPE_DIRECT_APPEND = "directAppend";
ImportField.IN_TYPE_DIRECT = "direct";
ImportField.IN_TYPE_FUNCTION = "function";
/**
* addCreatorName()
* Accepts the item we want to add a creator to, the name of the creator, and
* the type of the creator. Parses name, then adds to item.
*
* @param item_IN - item we are adding creator to.
* @param name_IN - string name of creator.
* @param type_IN - type of creator we are adding.
*/
function addCreatorName( item_IN, name_IN, type_IN )
{
// declare variables
var nameArray = null;
// parse name.
nameArray = name_IN.split(/, ?/);
item_IN.creators.push({lastName:nameArray[0], firstName:nameArray[1], creatorType:type_IN});
} //-- end function addCreatorName() --//
/**
* stringReplace()
* Accepts a string in which we want to find and replace strings, a string to
* find, and a string to replace any matches with. If string_IN or find_IN
* are empty, returns the string passed in.
*
* @param string_IN - string we will search and replace within.
* @param find_IN - string we are searching for.
* @param replaceWith_IN - string we will replace matches with.
* @return String - string with all instances of find_IN replaced by replaceWith_IN.
*/
function stringReplace( string_IN, find_IN, replaceWith_IN )
{
// return reference
var string_OUT = "";
// declare variables
var subStringArray = -1;
var subStringCount = -1;
// put input string in output argument.
string_OUT = string_IN;
// got something passed in?
if ( ( string_OUT != null ) && ( string_OUT != "" ) )
{
// make sure we have a find string
if ( ( find_IN != null ) && ( find_IN != "" ) )
{
// split on the string passed in.
subStringArray = string_IN.split( find_IN );
// then, use join to put them back together again, with
// replaceWith_IN between each.
string_OUT = subStringArray.join( replaceWith_IN );
} //-- end check to see if find string is present. --//
} //-- end check to see if string we are working with is present. --//
return string_OUT;
} //-- end function stringReplace() --//
/**
* addDate()
* Accepts the item we want to add a date to, the name of the field where the
* date should be stored, and the date value. Parses date, adds to item.
*
* @param item_IN - item we are adding creator to.
* @param fieldName_IN - string name of field in item where we'll place date once it is transformed.
* @param value_IN - date value we are processing.
* @param append_IN - boolean, true if we want to append to existing value in fieldName_IN (after, separated by a space), false if not.
*/
function addDate( item_IN, fieldName_IN, value_IN, append_IN )
{
// year or date
var cleanedValue = "";
var parsedDate = null;
var epochTime = NaN;
var isDateParsed = false;
var parsedDateParts = null;
var dateParts = null;
var dashIndex = -1;
var tempInt = -1;
var finalValue = "";
// use cleanedValue instead of value_IN
cleanedValue = value_IN;
// DEBUG
Zotero.debug( " *** in RIS.js->addDate() - 1: Date = '" + cleanedValue + "', target = '" + fieldName_IN + "'" );
// see if has dashes, and so is probably a date with dashes instead of
// slashes.
dashIndex = value_IN.indexOf( "-" );
if ( dashIndex > -1 )
{
// has dashes (instead of "/"?). Try converting to slashes before splitting.
cleanedValue = stringReplace( cleanedValue, "-", "/" );
}
// DEBUG
Zotero.debug( " *** in RIS.js->addDate() - 2: after Dash replace - Date = '" + cleanedValue + "', target = '" + fieldName_IN + "'" );
// first, parse by splitting, as we did before.
dateParts = cleanedValue.split("/");
// Try using JS Date object to parse date - First, remove periods - Firefox
// can't parse dates where month abbreviation has a period after it.
cleanedValue = stringReplace( cleanedValue, ".", "" );
// initialize variables
parsedDateParts = new Array();
// parse using Date.
epochTime = Date.parse( cleanedValue );
// success?
if ( isNaN( epochTime ) == false )
{
// yes - use Date to populate dateParts
parsedDate = new Date( cleanedValue );
// place parts
parsedDateParts[ 0 ] = parsedDate.getFullYear(); // 0 = year.
parsedDateParts[ 1 ] = parsedDate.getMonth() + 1; // 1 = month, from 1 to 12.
parsedDateParts[ 2 ] = parsedDate.getDate(); // 2 = date in month, starting at 1 for first day.
// DEBUG
Zotero.debug( " *** in RIS.js->addDate() - 3: after Date.parse() - Date '" + cleanedValue + "' converted to year = '" + parsedDateParts[ 0 ] + "'; month = '" + parsedDateParts[ 1 ] + "'; date = '" + parsedDateParts[ 2 ] + "'" );
}
// see if Date.parse() was successful.
if ( parsedDateParts.length > 0 )
{
// it was. Need to make sure that we don't screw up a single year.
// is the dateParts array length = 1?
if ( dateParts.length == 1 )
{
// it is. Could be a year. Only use parsed results if this sole
// value = NaN, or if it is an int, if it is not 4 digits.
tempInt = parseInt( dateParts[ 0 ] );
if ( ( isNaN( tempInt ) == true ) || ( tempInt.toString().length != 4 ) )
{
// Since the string passed in is either not a number or not
// length 4, and we have a successful parse, this indicates
// that we should use the parsed date parts, not the ones
// from splitting on "/".
dateParts = parsedDateParts;
}
}
else
{
// not just a year, use the Date.parse() results.
dateParts = parsedDateParts;
}
} //-- check if the Date.parse() was successful.
// DEBUG
Zotero.debug( " *** in RIS.js->addDate() - 4: after all parse logic, date '" + cleanedValue + "' converted to: year = '" + dateParts[ 0 ] + "'; month = '" + dateParts[ 1 ] + "'; date = '" + dateParts[ 2 ] + "'; post-date = '" + dateParts[ 3 ] + "'" );
// now, back to previous logic - we've done all we can do at this point.
if ( dateParts.length == 1 )
{
// technically, if there's only one date part, the file isn't valid
// RIS, but EndNote writes this, so we have to too
// Nick: RIS spec example records also only contain a single part
// even though it says the slashes are not optional (?)
//item_IN[ fieldName_IN ] = value_IN;
finalValue = value_IN;
}
else
{
// more than one part. Try using Date to parse date string, so we can
// support more date formats. Won't work if it actually contains a
// trailing space and notes, but in that case, we fall back to
// existing logic.
// if month, convert month to internal format expected by Date (0-11).
var month = parseInt( dateParts[ 1 ] );
if ( month )
{
month--;
}
else
{
month = undefined;
}
// convert Date to Zotero format, store in field.
//item_IN[ fieldName_IN ] = Zotero.Utilities.formatDate({year:dateParts[0],
finalValue = Zotero.Utilities.formatDate({year:dateParts[0],
month:month,
day:dateParts[2],
part:dateParts[3]});
}
// got a final Value?
if ( ( finalValue != null ) && ( finalValue != "" ) )
{
// do we append?
if ( append_IN == true )
{
// append
finalValue = item_IN[ fieldName_IN ] + " " + finalValue;
}
else
{
// no append, just overwrite
item_IN[ fieldName_IN ] = finalValue;
}
}
} //-- end function addDate() --//
function addMisc( item_IN, tag_IN, value_IN, valueArray_IN )
{
// Can't get accessDate to show up no matter what I do.
// In EndNote, for web pages, Access Date is stored in M1.
//if ( ( tag_IN == "M1" ) && ( item_IN.itemType == "webpage" ) )
//{
// we are a web page. Append this to the accessDate field.
//appendToItemField( item_OUT, "accessDate", value_IN, ", " );
//addDate( item_OUT, "accessDate", value_IN, true )
//}
//else
//{
// Append miscellaneous fields to extra field.
appendToItemField( item_IN, "extra", value_IN, "; " );
//}
} //-- end function addMisc() --//
function addNote( item_IN, tag_IN, value_IN, valueArray_IN )
{
// notes
if ( value_IN != item_IN.title ) // why does EndNote do this!?
{
item_IN.notes.push({note:value_IN});
}
} //-- end function addNote() --//
function addProcessingNote( item_IN, tag_IN, value_IN, valueArray_IN, message_IN )
{
var message = "";
// generate message.
message = " *** In RIS.js, processing note: value = " + value_IN + "; message = " + message_IN;
// add Note
addNote( item_IN, tag_IN, message, valueArray_IN );
} //-- end function addNote() --//
function appendToItemField( item_IN, fieldName_IN, value_IN, appendString_IN )
{
// return reference
var item_OUT = "";
// set item_OUT to item_IN
item_OUT = item_IN;
// got a field name?
if ( ( fieldName_IN != null ) && ( fieldName_IN != null ) )
{
// see if already something in the field.
if ( item_OUT[ fieldName_IN ] )
{
// There is. Make sure we weren't passed nothing (if nothing,
// do nothing).
if ( ( value_IN != null ) && ( value_IN != null ) )
{
// got something. Append it.
item_OUT[ fieldName_IN ] += appendString_IN + value_IN;
}
}
else
{
item_OUT[ fieldName_IN ] = value_IN;
}
}
return item_OUT;
} //-- end function appendToItemField() --//
function processBT( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// ignore, unless this is a book or unpublished work, as per spec
if ( item_OUT.itemType == "book" || item_OUT.itemType == "manuscript" )
{
item_OUT.title = value_IN;
}
else
{
item_OUT.backupPublicationTitle = value_IN;
}
return item_OUT;
} //-- end function processBT() --//
/**
* function processCreator()
* Purpose: Breaks out processing of creator.
*
*
* Parameters:
* @param item_IN - Zotero Item instance that we are populating.
* @param tag_IN - String name of tag we are currently processing.
* @param value_IN - String value of current tag (if multiple lines, will be a space-delimited concatenation of values from each line).
* @param valueArray_IN - Array of String links we need to process.
*/
function processCreator( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
if ( tag_IN == "A1" || tag_IN == "AU" )
{
// primary author (patent: inventor)
// store Zotero "creator type" in temporary variable
var tempType;
if ( item_OUT.itemType == "patent" )
{
tempType = "inventor";
}
// see if EDBOOK - if so, then AU = editor, not author.
else if ( item_OUT.originalItemType == "EDBOOK" )
{
tempType = "editor";
}
else
{
tempType = "author";
}
//var names = value.split(/, ?/);
//item.creators.push({lastName:names[0], firstName:names[1], creatorType:tempType});
addCreatorName( item_OUT, value_IN, tempType );
}
else if ( tag_IN == "ED" )
{
//var names = value.split(/, ?/);
//item.creators.push({lastName:names[0], firstName:names[1], creatorType:"editor"});
addCreatorName( item_OUT, value_IN, "editor" );
}
else if ( tag_IN == "A2" )
{
// contributing author (patent: assignee)
if ( item_OUT.itemType == "patent" )
{
if (item_OUT.assignee)
{
// Patents can have multiple assignees (applicants) but Zotero only allows a single
// assignee field, so we have to concatenate them together
item_OUT.assignee += ", " + value_IN;
}
else
{
item_OUT.assignee = value_IN;
}
}
else if ( item_OUT.itemType == "book" )
{
// EndNote puts Series Editor in A2.
addCreatorName( item_OUT, value_IN, "seriesEditor" );
}
else if ( item_OUT.itemType == "bookSection" )
{
// EndNote puts Editor in A2.
addCreatorName( item_OUT, value_IN, "editor" );
}
else
{
//var names = value.split(/, ?/);
//item.creators.push({lastName:names[0], firstName:names[1], creatorType:"contributor"});
addCreatorName( item_OUT, value_IN, "contributor" );
}
}
// in RefMan spec, this is "Series Author"
else if ( tag_IN == "A3" )
{
// EndNote puts Series Editor in A3 in chapters of edited books.
addCreatorName( item_OUT, value_IN, "seriesEditor" );
}
return item_OUT;
} //-- end function processCreator() --//
function processDA( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// the DA tag is usually used by EndNote to hold access date (stored in
// zotero in "accessDate").
addDate( item_IN, "accessDate", value_IN, false );
return item_OUT;
} //-- end function processDA() --//
function processEP( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// end page
if ( value_IN )
{
if( !item_OUT.pages )
{
item_OUT.pages = value_IN;
}
else if ( value_IN != item_OUT.pages )
{
item_OUT.pages += "-" + value_IN;
}
}
return item_OUT;
} //-- end function processEP() --//
function processET( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
if ( item_OUT.itemType == "journalArticle" )
{
// if journal article, in EndNote, ET = date accessed online
item_OUT.accessDate = value_IN;
}
else
{
// If not journal article, ET = edition.
item_OUT.edition = value_IN;
}
return item_OUT;
} //-- end function processEP() --//
function processIS( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// Issue Number (patent: patentNumber)
if ( item_OUT.itemType == "patent" )
{
item_OUT.patentNumber = value_IN;
}
else
{
item_OUT.issue = value_IN;
}
return item_OUT;
} //-- end function processEP() --//
function processJO( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// conference paper or not?
if ( item_OUT.itemType == "conferencePaper" )
{
item_OUT.conferenceName = value_IN;
}
else
{
item_OUT.publicationTitle = value_IN;
}
return item_OUT;
} //-- end function processJO() --//
function processKW( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
var item_OUT = item_IN;
// declare variables
var lineArray = null;
var i = -1;
var currentLine = "";
var tagArray = null;
// keywords/tags
// technically, treating newlines as new tags breaks the RIS spec, but
// it's required to work with EndNote
// first, check to see if newlines
if ( value_IN.indexOf( "\n" ) > -1 )
{
lineArray = value_IN.split( "\n" );
}
else
{
lineArray = new Array();
lineArray.push( value_IN );
}
// see if lineArray length is greater than 0
if ( lineArray.length > 0 )
{
// loop over each item in array. Split each on ";" and add result to
// tagArray.
tagArray = new Array();
for( i = 0; i < lineArray.length; i++ )
{
// get current line
currentLine = lineArray[ i ];
tagArray = tagArray.concat( currentLine.split( ";" ) );
}
}
else
{
tagArray = new Array();
tagArray.push( value_IN );
}
item_OUT.tags = item_OUT.tags.concat( tagArray );
return item_OUT;
} //-- end function processKW() --//
/**
* function processLinkTag()
* Purpose: Broke out more sophisticated processing of links, so we get proper
* MIME types, actual file names, etc.
* Preconditions: can deal with the EndNote way of outputting multiple links
* (one to a line) and the spec way (one line, semi-colon delimited list)
* but not both (multiple lines where 2nd and subsequent lines are not
* preceded by "L1 - " but do have semi-colon delimited lists of links).
* In this hybrid case of brokenness, this won't work (though it wouldn't be
* hard to deal with this, too - see comment inside loop, just after grabbing
* current value).
*
* Parameters:
* @param item_IN - Zotero Item instance that we are populating.
* @param tag_IN - String name of tag we are currently processing.
* @param value_IN - String value of current tag (if multiple lines, will be a space-delimited concatenation of values from each line).
* @param valueArray_IN - Array of String links we need to process.
*/
function processLinkTag( item_IN, tag_IN, value_IN, valueArray_IN )
{
// return reference
item_OUT = null;
// declare variables
var linkType_URL = "url";
var linkType_file = "file";
var linkType_ENFile = "enfile";
var myLinkType = "";
var myMIMEType = "";
var myFileName = "";
var valueArray = "";
var testArray = "";
var arraySize = -1;
var currentValue = "";
var currentValueUpcase = "";
var fileLinkCount = -1;
var overflowNote = "";
// string substitution variables
var subStartIndex = -1;
var subFilePath = -1;
var internalPDFString = "INTERNAL-PDF://";
Zotero.debug( "*** In RIS.js->processLinkTag, tag_IN: " + tag_IN + "; value:" + value_IN );
// now, process attachments based on tag and linkType
if( tag_IN == "UR" )
{
item_IN.url = value_IN;
// see if semi-colon delimited...
testArray = value_IN.split( ";" );
if ( testArray.length > 1 )
{
// loop over semi-colon-delimited list of URLs.
arraySize = testArray.length;
for( i = 0; i < arraySize; i++ )
{
// get current Value
currentValue = testArray[ i ];
// add to list of attachments
item_IN.attachments.push({url:currentValue});
}
}
else
{
// juat the one - add to list of attachments
item_IN.attachments.push({url:value_IN});
}
Zotero.debug( "*** In RIS.js->processLinkTag, item_IN.URL: " + item_IN.url + "; attachments:" + item_IN.attachments );
}
else if( tag_IN == "L1" )
{
// see if there is anything in valueArray_IN
valueArray = valueArray_IN;
if ( ( valueArray == null ) || ( valueArray.length == 0 ) )
{
// try breaking the value passed in up on semi-colons.
valueArray = new Array();
// split on semi-colon.
testArray = value_IN.split( ";" );
// got anything?
if ( testArray.length > 0 )
{
valueArray = testArray;
}
else
{
valueArray.push( value_IN );
}
}
else if ( valueArray.length == 1 )
{
// one value - need to make sure we process semi-colon-delimited list if
// present. Grab the single value and see if it is a semi-colon delimited
// list. If so, we should make a new array with each semi-colon-delimited value as an
// entry.
currentValue = valueArray[ 0 ];
testArray = currentValue.split( ";" );