Class: EADSerializer

Inherits:
ASpaceExport::Serializer show all
Includes:
SerializeExtraContainerValues
Defined in:
backend/app/exporters/serializers/ead.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from SerializeExtraContainerValues

#altrender_calculator, included, #manage_containers_serialize_container

Methods inherited from ASpaceExport::Serializer

inherited, serializer_for, serializer_for?, with_namespace

Class Method Details

+ (Object) add_serialize_step(serialize_step)

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.



10
11
12
13
# File 'backend/app/exporters/serializers/ead.rb', line 10

def self.add_serialize_step(serialize_step)
  @extra_serialize_steps ||= []
  @extra_serialize_steps << serialize_step
end

+ (Object) run_serialize_step(data, xml, fragments, context)



15
16
17
18
19
# File 'backend/app/exporters/serializers/ead.rb', line 15

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

Instance Method Details

- (Object) extract_head_text(content, backup = "")

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



194
195
196
197
198
199
200
201
202
# File 'backend/app/exporters/serializers/ead.rb', line 194

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

- (Object) handle_linebreaks(content)



33
34
35
36
37
38
39
40
41
42
43
# File 'backend/app/exporters/serializers/ead.rb', line 33

def handle_linebreaks(content)
  # if there's already p tags, just leave as is
  return content if ( content.strip =~ /^<p(\s|\/|>)/ or content.strip.length < 1 )
  blocks = content.split("\n\n").select { |b| !b.strip.empty? }
  if blocks.length > 1
    content = blocks.inject("") { |c,n| c << "<p>#{n.chomp}</p>"  }
  else
    content = "<p>#{content.strip}</p>"
  end
  content
end

- (Object) prefix_id(id)



23
24
25
26
27
28
29
30
31
# File 'backend/app/exporters/serializers/ead.rb', line 23

def prefix_id(id)
  if id.nil? or id.empty? or id == 'null'
    ""
  elsif id =~ /^#{@id_prefix}/
    id
  else
    "#{@id_prefix}#{id}"
  end
end

- (Object) sanitize_mixed_content(content, context, fragments, allow_p = false)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'backend/app/exporters/serializers/ead.rb', line 49

def sanitize_mixed_content(content, context, fragments, allow_p = false  )
#    return "" if content.nil?
  # 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("&amp;", "&") #thanks, Nokogiri
    end
  rescue
    context.cdata content
  end
end

- (Object) serialize_bibliographies(data, xml, fragments)



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'backend/app/exporters/serializers/ead.rb', line 545

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

- (Object) serialize_child(data, xml, fragments, c_depth = 1)



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
# File 'backend/app/exporters/serializers/ead.rb', line 204

def serialize_child(data, xml, fragments, c_depth = 1)
  begin
  return if data["publish"] === false && !@include_unpublished

  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

      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)

      # TODO: Clean this up more; there's probably a better way to do this.
      # For whatever reason, the old ead_containers method was not working
      # on archival_objects (see migrations/models/ead.rb).

      data.instances.each do |inst|
        case
        when inst.has_key?('container') && !inst['container'].nil?
          serialize_container(inst, xml, fragments)
        when inst.has_key?('digital_object') && !inst['digital_object']['_resolved'].nil?
          serialize_digital_object(inst['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

- (Object) serialize_container(inst, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 378

def serialize_container(inst, xml, fragments)
  containers = []
  @parent_id = nil
  (1..3).each do |n|
    atts = {}
    next unless inst['container'].has_key?("type_#{n}") && inst['container'].has_key?("indicator_#{n}")
    @container_id = prefix_id(SecureRandom.hex)

    atts[:parent] = @parent_id unless @parent_id.nil?
    atts[:id] = @container_id
    @parent_id = @container_id

    atts[:type] = inst['container']["type_#{n}"]
    text = inst['container']["indicator_#{n}"]
    if n == 1 && inst['instance_type']
      atts[:label] = I18n.t("enumerations.instance_instance_type.#{inst['instance_type']}", :default => inst['instance_type'])
      if inst['container']["barcode_1"]
        atts[:label] << " (#{inst['container']['barcode_1']})"
      end
    end
    xml.container(atts) {
       sanitize_mixed_content(text, xml, fragments)
    }
  end
end

- (Object) serialize_controlaccess(data, xml, fragments)



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'backend/app/exporters/serializers/ead.rb', line 303

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

- (Object) serialize_dates(obj, xml, fragments)



471
472
473
474
475
476
477
478
479
# File 'backend/app/exporters/serializers/ead.rb', line 471

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

- (Object) serialize_did_notes(data, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 482

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

- (Object) serialize_digital_object(digital_object, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 404

def serialize_digital_object(digital_object, xml, fragments)
  return if digital_object["publish"] === false && !@include_unpublished
  file_versions = digital_object['file_versions']
  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.empty?
    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
    }
  else
    file_versions.each do |file_version|
      atts['xlink:href'] = file_version['file_uri'] || digital_object['digital_object_id']
      atts['xlink:actuate'] = file_version['xlink_actuate_attribute'] || 'onRequest'
      atts['xlink:show'] = file_version['xlink_show_attribute'] || 'new'
      xml.dao(atts) {
        xml.daodesc{ sanitize_mixed_content(content, xml, fragments, true) } if content
      }
    end
  end

end

- (Object) serialize_eadheader(data, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 602

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

- (Object) serialize_extents(obj, xml, fragments)



447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'backend/app/exporters/serializers/ead.rb', line 447

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

- (Object) serialize_indexes(data, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 566

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

- (Object) serialize_nondid_notes(data, xml, fragments)



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'backend/app/exporters/serializers/ead.rb', line 527

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

- (Object) serialize_note_content(note, xml, fragments)



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'backend/app/exporters/serializers/ead.rb', line 508

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

- (Object) serialize_origination(data, xml, fragments)



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
# File 'backend/app/exporters/serializers/ead.rb', line 277

def serialize_origination(data, xml, fragments)
  unless data.creators_and_sources.nil?
    data.creators_and_sources.each do |link|
      agent = link['_resolved']
      role = link['role']
      relator = link['relator']
      sort_name = agent['display_name']['sort_name']
      rules = agent['display_name']['rules']
      source = agent['display_name']['source']
      node_name = case agent['agent_type']
                  when 'agent_person'; 'persname'
                  when 'agent_family'; 'famname'
                  when 'agent_corporate_entity'; 'corpname'
                  end
      xml.origination(:label => role) {
       atts = {:role => relator, :source => source, :rules => rules}
       atts.reject! {|k, v| v.nil?}

        xml.send(node_name, atts) {
          sanitize_mixed_content(sort_name, xml, fragments )
        }
      }
    end
  end
end

- (Object) serialize_subnotes(subnotes, xml, fragments, include_p = true)



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
# File 'backend/app/exporters/serializers/ead.rb', line 324

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

- (Object) stream(data)



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
# File 'backend/app/exporters/serializers/ead.rb', line 72

def stream(data)
  @stream_handler = ASpaceExport::StreamHandler.new
  @fragments = ASpaceExport::RawXMLHandler.new
  @include_unpublished = data.include_unpublished?
  @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

    xml.ead(                  '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') {

      xml.text (
        @stream_handler.buffer { |xml, new_fragments|
          serialize_eadheader(data, xml, new_fragments)
        })

      atts = {:level => data.level, :otherlevel => data.other_level}

      if data.publish === false
        if @include_unpublished
          atts[:audience] = 'internal'
        else
          return
        end
      end

      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('.')

          serialize_extents(data, xml, @fragments)

          serialize_dates(data, xml, @fragments)

          serialize_did_notes(data, xml, @fragments)

          data.instances_with_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

- (Object) strip_p(content)



45
46
47
# File 'backend/app/exporters/serializers/ead.rb', line 45

def strip_p(content)
  content.gsub("<p>", "").gsub("</p>", "").gsub("<p/>", '')
end