-
Notifications
You must be signed in to change notification settings - Fork 226
/
ead.rb
835 lines (676 loc) · 28.7 KB
/
ead.rb
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
# encoding: utf-8
require 'nokogiri'
require 'securerandom'
require 'cgi'
class EADSerializer < ASpaceExport::Serializer
serializer_for :ead
# Allow plugins to hook in to record processing by providing their own
# serialization step (a class with a 'call' method accepting the arguments
# defined in `run_serialize_step`.
def self.add_serialize_step(serialize_step)
@extra_serialize_steps ||= []
@extra_serialize_steps << serialize_step
end
def self.run_serialize_step(data, xml, fragments, context)
Array(@extra_serialize_steps).each do |step|
step.new.call(data, xml, fragments, context)
end
end
def prefix_id(id)
if id.nil? or id.empty? or id == 'null'
""
elsif id =~ /^#{@id_prefix}/
id
else
"#{@id_prefix}#{id}"
end
end
def xml_errors(content)
# there are message we want to ignore. annoying that java xml lib doesn't
# use codes like libxml does...
ignore = [ /Namespace prefix .* is not defined/, /The prefix .* is not bound/ ]
ignore = Regexp.union(ignore)
# the "wrap" is just to ensure that there is a psuedo root element to eliminate a "false" error
Nokogiri::XML("<wrap>#{content}</wrap>").errors.reject { |e| e.message =~ ignore }
end
# ANW-716: We may have content with a mix of loose '&' chars that need to be escaped, along with pre-escaped HTML entities
# Example:
# c => "This is the < test & for the <title>Sanford & Son</title>
# escape_content(c) => "This is the < test & for the <title>Sanford & Son</title>
# we want to leave the pre-escaped entities alone, and escape the loose & chars
def escape_content(content)
# first, find any pre-escaped entities and "mark" them by replacing & with @@
# so something like < becomes @@lt;
# and Ӓ becomes @@#1234
content.gsub!(/&\w+;/) {|t| t.gsub('&', '@@')}
content.gsub!(/&#\d{4}/) {|t| t.gsub('&', '@@')}
content.gsub!(/&#\d{3}/) {|t| t.gsub('&', '@@')}
# now we know that all & characters remaining are not part of some pre-escaped entity, and we can escape them safely
content.gsub!('&', '&')
# 'unmark' our pre-escaped entities
content.gsub!(/@@\w+;/) {|t| t.gsub('@@', '&')}
content.gsub!(/@@#\d{4}/) {|t| t.gsub('@@', '&')}
content.gsub!(/@@#\d{3}/) {|t| t.gsub('@@', '&')}
return content
end
def handle_linebreaks(content)
# 4archon...
content.gsub!("\n\t", "\n\n")
# if there's already p tags, just leave as is
return content if ( content.strip =~ /^<p(\s|\/|>)/ or content.strip.length < 1 )
original_content = content
blocks = content.split("\n\n").select { |b| !b.strip.empty? }
if blocks.length > 1
content = blocks.inject("") do |c,n|
c << "<p>#{escape_content(n.chomp)}</p>"
end
else
content = "<p>#{escape_content(content.strip)}</p>"
end
# just return the original content if there's still problems
xml_errors(content).any? ? original_content : content
end
def strip_p(content)
content.gsub("<p>", "").gsub("</p>", "").gsub("<p/>", '')
end
def remove_smart_quotes(content)
content = content.gsub(/\xE2\x80\x9C/, '"').gsub(/\xE2\x80\x9D/, '"').gsub(/\xE2\x80\x98/, "\'").gsub(/\xE2\x80\x99/, "\'")
end
def sanitize_mixed_content(content, context, fragments, allow_p = false )
# return "" if content.nil?
# remove smart quotes from text
content = remove_smart_quotes(content)
# br's should be self closing
content = content.gsub("<br>", "<br/>").gsub("</br>", '')
# lets break the text, if it has linebreaks but no p tags.
if allow_p
content = handle_linebreaks(content)
else
content = strip_p(content)
end
begin
if ASpaceExport::Utils.has_html?(content)
context.text (fragments << content )
else
context.text content.gsub("&", "&") #thanks, Nokogiri
end
rescue
context.cdata content
end
end
def stream(data)
@stream_handler = ASpaceExport::StreamHandler.new
@fragments = ASpaceExport::RawXMLHandler.new
@include_unpublished = data.include_unpublished?
@include_daos = data.include_daos?
@use_numbered_c_tags = data.use_numbered_c_tags?
@id_prefix = I18n.t('archival_object.ref_id_export_prefix', :default => 'aspace_')
doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
begin
ead_attributes = {
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd',
'xmlns:xlink' => 'http://www.w3.org/1999/xlink'
}
if data.publish === false
ead_attributes['audience'] = 'internal'
end
xml.ead( ead_attributes ) {
xml.text (
@stream_handler.buffer { |xml, new_fragments|
serialize_eadheader(data, xml, new_fragments)
})
atts = {:level => data.level, :otherlevel => data.other_level}
atts.reject! {|k, v| v.nil?}
xml.archdesc(atts) {
xml.did {
if (val = data.language)
xml.langmaterial {
xml.language(:langcode => val) {
xml.text I18n.t("enumerations.language_iso639_2.#{val}", :default => val)
}
}
end
if (val = data.repo.name)
xml.repository {
xml.corpname { sanitize_mixed_content(val, xml, @fragments) }
}
end
if (val = data.title)
xml.unittitle { sanitize_mixed_content(val, xml, @fragments) }
end
serialize_origination(data, xml, @fragments)
xml.unitid (0..3).map{|i| data.send("id_#{i}")}.compact.join('.')
if @include_unpublished
data.external_ids.each do |exid|
xml.unitid ({ "audience" => "internal", "type" => exid['source'], "identifier" => exid['external_id']}) { xml.text exid['external_id']}
end
end
serialize_extents(data, xml, @fragments)
serialize_dates(data, xml, @fragments)
serialize_did_notes(data, xml, @fragments)
data.instances_with_sub_containers.each do |instance|
serialize_container(instance, xml, @fragments)
end
EADSerializer.run_serialize_step(data, xml, @fragments, :did)
}# </did>
data.digital_objects.each do |dob|
serialize_digital_object(dob, xml, @fragments)
end
serialize_nondid_notes(data, xml, @fragments)
serialize_bibliographies(data, xml, @fragments)
serialize_indexes(data, xml, @fragments)
serialize_controlaccess(data, xml, @fragments)
EADSerializer.run_serialize_step(data, xml, @fragments, :archdesc)
xml.dsc {
data.children_indexes.each do |i|
xml.text(
@stream_handler.buffer {|xml, new_fragments|
serialize_child(data.get_child(i), xml, new_fragments)
}
)
end
}
}
}
rescue => e
xml.text "ASPACE EXPORT ERROR : YOU HAVE A PROBLEM WITH YOUR EXPORT OF YOUR RESOURCE. THE FOLLOWING INFORMATION MAY HELP:\n
MESSAGE: #{e.message.inspect} \n
TRACE: #{e.backtrace.inspect} \n "
end
end
doc.doc.root.add_namespace nil, 'urn:isbn:1-931666-22-9'
Enumerator.new do |y|
@stream_handler.stream_out(doc, @fragments, y)
end
end
# this extracts <head> content and returns it. optionally, you can provide a
# backup text node that will be returned if there is no <head> nodes in the
# content
def extract_head_text(content, backup = "")
content ||= ""
match = content.strip.match(/<head( [^<>]+)?>(.+?)<\/head>/)
if match.nil? # content has no head so we return it as it
return [content, backup ]
else
[ content.gsub(match.to_a.first, ''), match.to_a.last]
end
end
def serialize_child(data, xml, fragments, c_depth = 1)
begin
return if data["publish"] === false && !@include_unpublished
return if data["suppressed"] === true
tag_name = @use_numbered_c_tags ? :"c#{c_depth.to_s.rjust(2, '0')}" : :c
atts = {:level => data.level, :otherlevel => data.other_level, :id => prefix_id(data.ref_id)}
if data.publish === false
atts[:audience] = 'internal'
end
atts.reject! {|k, v| v.nil?}
xml.send(tag_name, atts) {
xml.did {
if (val = data.title)
xml.unittitle { sanitize_mixed_content( val,xml, fragments) }
end
if !data.component_id.nil? && !data.component_id.empty?
xml.unitid data.component_id
end
if @include_unpublished
data.external_ids.each do |exid|
xml.unitid ({ "audience" => "internal", "type" => exid['source'], "identifier" => exid['external_id']}) { xml.text exid['external_id']}
end
end
serialize_origination(data, xml, fragments)
serialize_extents(data, xml, fragments)
serialize_dates(data, xml, fragments)
serialize_did_notes(data, xml, fragments)
EADSerializer.run_serialize_step(data, xml, fragments, :did)
data.instances_with_sub_containers.each do |instance|
serialize_container(instance, xml, @fragments)
end
if @include_daos
data.instances_with_digital_objects.each do |instance|
serialize_digital_object(instance['digital_object']['_resolved'], xml, fragments)
end
end
}
serialize_nondid_notes(data, xml, fragments)
serialize_bibliographies(data, xml, fragments)
serialize_indexes(data, xml, fragments)
serialize_controlaccess(data, xml, fragments)
EADSerializer.run_serialize_step(data, xml, fragments, :archdesc)
data.children_indexes.each do |i|
xml.text(
@stream_handler.buffer {|xml, new_fragments|
serialize_child(data.get_child(i), xml, new_fragments, c_depth + 1)
}
)
end
}
rescue => e
xml.text "ASPACE EXPORT ERROR : YOU HAVE A PROBLEM WITH YOUR EXPORT OF ARCHIVAL OBJECTS. THE FOLLOWING INFORMATION MAY HELP:\n
MESSAGE: #{e.message.inspect} \n
TRACE: #{e.backtrace.inspect} \n "
end
end
def serialize_origination(data, xml, fragments)
unless data.creators_and_sources.nil?
data.creators_and_sources.each do |link|
agent = link['_resolved']
published = agent['publish'] === true
next if !published && !@include_unpublished
role = link['role']
relator = link['relator']
sort_name = agent['display_name']['sort_name']
rules = agent['display_name']['rules']
source = agent['display_name']['source']
authfilenumber = agent['display_name']['authority_id']
node_name = case agent['agent_type']
when 'agent_person'; 'persname'
when 'agent_family'; 'famname'
when 'agent_corporate_entity'; 'corpname'
end
origination_attrs = {:label => role}
origination_attrs[:audience] = 'internal' unless published
xml.origination(origination_attrs) {
atts = {:role => relator, :source => source, :rules => rules, :authfilenumber => authfilenumber}
atts.reject! {|k, v| v.nil?}
xml.send(node_name, atts) {
sanitize_mixed_content(sort_name, xml, fragments )
}
}
end
end
end
def serialize_controlaccess(data, xml, fragments)
if (data.controlaccess_subjects.length + data.controlaccess_linked_agents.length) > 0
xml.controlaccess {
data.controlaccess_subjects.each do |node_data|
xml.send(node_data[:node_name], node_data[:atts]) {
sanitize_mixed_content( node_data[:content], xml, fragments, ASpaceExport::Utils.include_p?(node_data[:node_name]) )
}
end
data.controlaccess_linked_agents.each do |node_data|
xml.send(node_data[:node_name], node_data[:atts]) {
sanitize_mixed_content( node_data[:content], xml, fragments,ASpaceExport::Utils.include_p?(node_data[:node_name]) )
}
end
} #</controlaccess>
end
end
def serialize_subnotes(subnotes, xml, fragments, include_p = true)
subnotes.each do |sn|
next if sn["publish"] === false && !@include_unpublished
audatt = sn["publish"] === false ? {:audience => 'internal'} : {}
title = sn['title']
case sn['jsonmodel_type']
when 'note_text'
sanitize_mixed_content(sn['content'], xml, fragments, include_p )
when 'note_chronology'
xml.chronlist(audatt) {
xml.head { sanitize_mixed_content(title, xml, fragments) } if title
sn['items'].each do |item|
xml.chronitem {
if (val = item['event_date'])
xml.date { sanitize_mixed_content( val, xml, fragments) }
end
if item['events'] && !item['events'].empty?
xml.eventgrp {
item['events'].each do |event|
xml.event { sanitize_mixed_content(event, xml, fragments) }
end
}
end
}
end
}
when 'note_orderedlist'
atts = {:type => 'ordered', :numeration => sn['enumeration']}.reject{|k,v| v.nil? || v.empty? || v == "null" }.merge(audatt)
xml.list(atts) {
xml.head { sanitize_mixed_content(title, xml, fragments) } if title
sn['items'].each do |item|
xml.item { sanitize_mixed_content(item,xml, fragments)}
end
}
when 'note_definedlist'
xml.list({:type => 'deflist'}.merge(audatt)) {
xml.head { sanitize_mixed_content(title,xml, fragments) } if title
sn['items'].each do |item|
xml.defitem {
xml.label { sanitize_mixed_content(item['label'], xml, fragments) } if item['label']
xml.item { sanitize_mixed_content(item['value'],xml, fragments )} if item['value']
}
end
}
end
end
end
def serialize_container(inst, xml, fragments)
atts = {}
sub = inst['sub_container']
top = sub['top_container']['_resolved']
atts[:id] = prefix_id(SecureRandom.hex)
last_id = atts[:id]
atts[:type] = top['type']
text = top['indicator']
atts[:label] = I18n.t("enumerations.instance_instance_type.#{inst['instance_type']}",
:default => inst['instance_type'])
atts[:label] << " [#{top['barcode']}]" if top['barcode']
if (cp = top['container_profile'])
atts[:altrender] = cp['_resolved']['url'] || cp['_resolved']['name']
end
xml.container(atts) {
sanitize_mixed_content(text, xml, fragments)
}
(2..3).each do |n|
atts = {}
next unless sub["type_#{n}"]
atts[:id] = prefix_id(SecureRandom.hex)
atts[:parent] = last_id
last_id = atts[:id]
atts[:type] = sub["type_#{n}"]
text = sub["indicator_#{n}"]
xml.container(atts) {
sanitize_mixed_content(text, xml, fragments)
}
end
end
# set daoloc audience attr == 'internal' if this is an unpublished && include_unpublished is set
def get_audience_flag_for_file_version(file_version)
if file_version['file_uri'] &&
(file_version['publish'] == false && @include_unpublished)
return "internal"
else
return "external"
end
end
def serialize_digital_object(digital_object, xml, fragments)
return if digital_object["publish"] === false && !@include_unpublished
return if digital_object["suppressed"] === true
# ANW-285: Only serialize file versions that are published, unless include_unpublished flag is set
file_versions_to_display = digital_object['file_versions'].select {|fv| fv['publish'] == true || @include_unpublished }
title = digital_object['title']
date = digital_object['dates'][0] || {}
atts = digital_object["publish"] === false ? {:audience => 'internal'} : {}
content = ""
content << title if title
content << ": " if date['expression'] || date['begin']
if date['expression']
content << date['expression']
elsif date['begin']
content << date['begin']
if date['end'] != date['begin']
content << "-#{date['end']}"
end
end
atts['xlink:title'] = digital_object['title'] if digital_object['title']
if file_versions_to_display.empty?
atts['xlink:type'] = 'simple'
atts['xlink:href'] = digital_object['digital_object_id']
atts['xlink:actuate'] = 'onRequest'
atts['xlink:show'] = 'new'
xml.dao(atts) {
xml.daodesc{ sanitize_mixed_content(content, xml, fragments, true) } if content
}
elsif file_versions_to_display.length == 1
file_version = file_versions_to_display.first
atts['xlink:type'] = 'simple'
atts['xlink:actuate'] = file_version['xlink_actuate_attribute'] || 'onRequest'
atts['xlink:show'] = file_version['xlink_show_attribute'] || 'new'
atts['xlink:role'] = file_version['use_statement'] if file_version['use_statement']
atts['xlink:href'] = file_version['file_uri']
atts['xlink:audience'] = get_audience_flag_for_file_version(file_version)
xml.dao(atts) {
xml.daodesc{ sanitize_mixed_content(content, xml, fragments, true) } if content
}
else
xml.daogrp( atts.merge( { 'xlink:type' => 'extended'} ) ) {
xml.daodesc{ sanitize_mixed_content(content, xml, fragments, true) } if content
file_versions_to_display.each do |file_version|
atts['xlink:type'] = 'locator'
atts['xlink:href'] = file_version['file_uri']
atts['xlink:role'] = file_version['use_statement'] if file_version['use_statement']
atts['xlink:title'] = file_version['caption'] if file_version['caption']
atts['xlink:audience'] = get_audience_flag_for_file_version(file_version)
xml.daoloc(atts)
end
}
end
end
def serialize_extents(obj, xml, fragments)
if obj.extents.length
obj.extents.each do |e|
next if e["publish"] === false && !@include_unpublished
audatt = e["publish"] === false ? {:audience => 'internal'} : {}
xml.physdesc({:altrender => e['portion']}.merge(audatt)) {
if e['number'] && e['extent_type']
xml.extent({:altrender => 'materialtype spaceoccupied'}) {
sanitize_mixed_content("#{e['number']} #{I18n.t('enumerations.extent_extent_type.'+e['extent_type'], :default => e['extent_type'])}", xml, fragments)
}
end
if e['container_summary']
xml.extent({:altrender => 'carrier'}) {
sanitize_mixed_content( e['container_summary'], xml, fragments)
}
end
xml.physfacet { sanitize_mixed_content(e['physical_details'],xml, fragments) } if e['physical_details']
xml.dimensions { sanitize_mixed_content(e['dimensions'],xml, fragments) } if e['dimensions']
}
end
end
end
def serialize_dates(obj, xml, fragments)
obj.archdesc_dates.each do |node_data|
next if node_data["publish"] === false && !@include_unpublished
audatt = node_data["publish"] === false ? {:audience => 'internal'} : {}
xml.unitdate(node_data[:atts].merge(audatt)){
sanitize_mixed_content( node_data[:content],xml, fragments )
}
end
end
def serialize_did_notes(data, xml, fragments)
data.notes.each do |note|
next if note["publish"] === false && !@include_unpublished
next unless data.did_note_types.include?(note['type'])
audatt = note["publish"] === false ? {:audience => 'internal'} : {}
content = ASpaceExport::Utils.extract_note_text(note, @include_unpublished)
att = { :id => prefix_id(note['persistent_id']) }.reject {|k,v| v.nil? || v.empty? || v == "null" }
att ||= {}
case note['type']
when 'dimensions', 'physfacet'
xml.physdesc(audatt) {
xml.send(note['type'], att) {
sanitize_mixed_content( content, xml, fragments, ASpaceExport::Utils.include_p?(note['type']) )
}
}
else
xml.send(note['type'], att.merge(audatt)) {
sanitize_mixed_content(content, xml, fragments,ASpaceExport::Utils.include_p?(note['type']))
}
end
end
end
def serialize_note_content(note, xml, fragments)
return if note["publish"] === false && !@include_unpublished
audatt = note["publish"] === false ? {:audience => 'internal'} : {}
content = note["content"]
atts = {:id => prefix_id(note['persistent_id']) }.reject{|k,v| v.nil? || v.empty? || v == "null" }.merge(audatt)
head_text = note['label'] ? note['label'] : I18n.t("enumerations._note_types.#{note['type']}", :default => note['type'])
content, head_text = extract_head_text(content, head_text)
xml.send(note['type'], atts) {
xml.head { sanitize_mixed_content(head_text, xml, fragments) } unless ASpaceExport::Utils.headless_note?(note['type'], content )
sanitize_mixed_content(content, xml, fragments, ASpaceExport::Utils.include_p?(note['type']) ) if content
if note['subnotes']
serialize_subnotes(note['subnotes'], xml, fragments, ASpaceExport::Utils.include_p?(note['type']))
end
}
end
def serialize_nondid_notes(data, xml, fragments)
data.notes.each do |note|
next if note["publish"] === false && !@include_unpublished
next if note['internal']
next if note['type'].nil?
next unless data.archdesc_note_types.include?(note['type'])
audatt = note["publish"] === false ? {:audience => 'internal'} : {}
if note['type'] == 'legalstatus'
xml.accessrestrict(audatt) {
serialize_note_content(note, xml, fragments)
}
else
serialize_note_content(note, xml, fragments)
end
end
end
def serialize_bibliographies(data, xml, fragments)
data.bibliographies.each do |note|
next if note["publish"] === false && !@include_unpublished
content = ASpaceExport::Utils.extract_note_text(note, @include_unpublished)
note_type = note["type"] ? note["type"] : "bibliography"
head_text = note['label'] ? note['label'] : I18n.t("enumerations._note_types.#{note_type}", :default => note_type )
audatt = note["publish"] === false ? {:audience => 'internal'} : {}
atts = {:id => prefix_id(note['persistent_id']) }.reject{|k,v| v.nil? || v.empty? || v == "null" }.merge(audatt)
xml.bibliography(atts) {
xml.head { sanitize_mixed_content(head_text, xml, fragments) }
sanitize_mixed_content( content, xml, fragments, true)
note['items'].each do |item|
xml.bibref { sanitize_mixed_content( item, xml, fragments) } unless item.empty?
end
}
end
end
def serialize_indexes(data, xml, fragments)
data.indexes.each do |note|
next if note["publish"] === false && !@include_unpublished
audatt = note["publish"] === false ? {:audience => 'internal'} : {}
content = ASpaceExport::Utils.extract_note_text(note, @include_unpublished)
head_text = nil
if note['label']
head_text = note['label']
elsif note['type']
head_text = I18n.t("enumerations._note_types.#{note['type']}", :default => note['type'])
end
atts = {:id => prefix_id(note["persistent_id"]) }.reject{|k,v| v.nil? || v.empty? || v == "null" }.merge(audatt)
content, head_text = extract_head_text(content, head_text)
xml.index(atts) {
xml.head { sanitize_mixed_content(head_text,xml,fragments ) } unless head_text.nil?
sanitize_mixed_content(content, xml, fragments, true)
note['items'].each do |item|
next unless (node_name = data.index_item_type_map[item['type']])
xml.indexentry {
atts = item['reference'] ? {:target => prefix_id( item['reference']) } : {}
if (val = item['value'])
xml.send(node_name) { sanitize_mixed_content(val, xml, fragments )}
end
if (val = item['reference_text'])
xml.ref(atts) {
sanitize_mixed_content( val, xml, fragments)
}
end
}
end
}
end
end
def serialize_eadheader(data, xml, fragments)
eadheader_atts = {:findaidstatus => data.finding_aid_status,
:repositoryencoding => "iso15511",
:countryencoding => "iso3166-1",
:dateencoding => "iso8601",
:langencoding => "iso639-2b"}.reject{|k,v| v.nil? || v.empty? || v == "null"}
xml.eadheader(eadheader_atts) {
eadid_atts = {:countrycode => data.repo.country,
:url => data.ead_location,
:mainagencycode => data.mainagencycode}.reject{|k,v| v.nil? || v.empty? || v == "null" }
xml.eadid(eadid_atts) {
xml.text data.ead_id
}
xml.filedesc {
xml.titlestmt {
titleproper = ""
titleproper += "#{data.finding_aid_title} " if data.finding_aid_title
titleproper += "#{data.title}" if ( data.title && titleproper.empty? )
titleproper += "<num>#{(0..3).map{|i| data.send("id_#{i}")}.compact.join('.')}</num>"
xml.titleproper("type" => "filing") { sanitize_mixed_content(data.finding_aid_filing_title, xml, fragments)} unless data.finding_aid_filing_title.nil?
xml.titleproper { sanitize_mixed_content(titleproper, xml, fragments) }
xml.subtitle { sanitize_mixed_content(data.finding_aid_subtitle, xml, fragments) } unless data.finding_aid_subtitle.nil?
xml.author { sanitize_mixed_content(data.finding_aid_author, xml, fragments) } unless data.finding_aid_author.nil?
xml.sponsor { sanitize_mixed_content( data.finding_aid_sponsor, xml, fragments) } unless data.finding_aid_sponsor.nil?
}
unless data.finding_aid_edition_statement.nil?
xml.editionstmt {
sanitize_mixed_content(data.finding_aid_edition_statement, xml, fragments, true )
}
end
xml.publicationstmt {
xml.publisher { sanitize_mixed_content(data.repo.name,xml, fragments) }
if data.repo.image_url
xml.p ( { "id" => "logostmt" } ) {
xml.extref ({"xlink:href" => data.repo.image_url,
"xlink:actuate" => "onLoad",
"xlink:show" => "embed",
"xlink:type" => "simple"
})
}
end
if (data.finding_aid_date)
xml.p {
val = data.finding_aid_date
xml.date { sanitize_mixed_content( val, xml, fragments) }
}
end
unless data.addresslines.empty?
xml.address {
data.addresslines.each do |line|
xml.addressline { sanitize_mixed_content( line, xml, fragments) }
end
if data.repo.url
xml.addressline ( "URL: " ) {
xml.extptr ( {
"xlink:href" => data.repo.url,
"xlink:title" => data.repo.url,
"xlink:type" => "simple",
"xlink:show" => "new"
} )
}
end
}
end
}
if (data.finding_aid_series_statement)
val = data.finding_aid_series_statement
xml.seriesstmt {
sanitize_mixed_content( val, xml, fragments, true )
}
end
if ( data.finding_aid_note )
val = data.finding_aid_note
xml.notestmt { xml.note { sanitize_mixed_content( val, xml, fragments, true )} }
end
}
xml.profiledesc {
creation = "This finding aid was produced using ArchivesSpace on <date>#{Time.now}</date>."
xml.creation { sanitize_mixed_content( creation, xml, fragments) }
if (val = data.finding_aid_language)
xml.langusage (fragments << val)
end
if (val = data.descrules)
xml.descrules { sanitize_mixed_content(val, xml, fragments) }
end
}
if data.revision_statements.length > 0
xml.revisiondesc {
data.revision_statements.each do |rs|
if rs['description'] && rs['description'].strip.start_with?('<')
xml.text (fragments << rs['description'] )
else
xml.change {
rev_date = rs['date'] ? rs['date'] : ""
xml.date (fragments << rev_date )
xml.item (fragments << rs['description']) if rs['description']
}
end
end
}
end
}
end
end