Class: XmlJats::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_jats_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filestream) ⇒ Resolver

Returns a new instance of Resolver.



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
# File 'lib/xml_jats_resolver.rb', line 9

def initialize(filestream)
  @filestream = filestream
  @dtds = {
    # NLM
    '-//NLM//DTD Journal Archiving and Interchange DTD v1.0 20021201//EN': 'archiving_dtd/archiving/1.0/dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v1.1 20031101//EN': 'archiving_dtd/archiving/1.1/dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v2.0 20040830//EN': 'archiving_dtd/archiving/2.0/dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v2.1 20050630//EN': 'archiving_dtd/archiving/2.1/dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v2.2 20060430//EN': 'archiving_dtd/archiving/2.2/dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v2.3 20070202//EN': 'archiving_dtd/archiving/2.3/dtd/',
    '-//NLM//DTD Journal Archiving with OASIS Tables v2.3 20070813//EN': 'archiving_dtd/archiving/2.3/oasis_dtd/',
    '-//NLM//DTD Journal Archiving and Interchange DTD v3.0 20080202//EN': 'archiving_dtd/archiving/3.0/dtd/',
    '-//NLM//DTD Journal Archiving with OASIS Tables v3.0 20080202//EN': 'archiving_dtd/archiving/3.0/oasis_dtd/',
    '-//NLM//DTD Journal Publishing DTD v1.0 20030210//EN': 'archiving_dtd/publishing/1.0/dtd/',
    '-//NLM//DTD Journal Publishing DTD v1.1 20031101//EN': 'archiving_dtd/publishing/1.1/dtd/',
    '-//NLM//DTD Journal Publishing DTD v2.0 20040830//EN': 'archiving_dtd/publishing/2.0/dtd/',
    '-//NLM//DTD Journal Publishing DTD v2.1 20050630//EN': 'archiving_dtd/publishing/2.1/dtd/',
    '-//NLM//DTD Journal Publishing DTD v2.2 20060430//EN': 'archiving_dtd/publishing/2.2/dtd/',
    '-//NLM//DTD Journal Publishing DTD v2.3 20070202//EN': 'archiving_dtd/publishing/2.3/dtd/',
    '-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN': 'archiving_dtd/publishing/3.0/dtd/',
    # NISO
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v0.4 20110131//EN': 'jats/archiving/0.4/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD (OASIS Tables) v0.4 20110131//EN': 'jats/archiving/0.4/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN': 'jats/archiving/1.0/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables v1.0 20120330//EN': 'jats/archiving/1.0/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.1 20151215//EN': 'jats/archiving/1.1/mathml2_dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with MathML3 v1.1 20151215//EN': 'jats/archiving/1.1/mathml3_dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables v1.1 20151215//EN': 'jats/archiving/1.1/oasis_mathml2_dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.1 20151215//EN': 'jats/archiving/1.1/oasis_mathml3_dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.2d1 20170631//EN': 'jats/archiving/1.2d1/oasis_mathml3_dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v0.4 20110131//EN': 'jats/publishing/0.4/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD (OASIS Tables) v0.4 20110131//EN': 'jats/publishing/0.4/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.0 20120330//EN': 'jats/publishing/1.0/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables v1.0 20120330//EN': 'jats/publishing/1.0/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1 20151215//EN': 'jats/publishing/1.1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with MathML3 v1.1 20151215//EN': 'jats/publishing/1.1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables v1.1 20151215//EN': 'jats/publishing/1.1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.1 20151215//EN': 'jats/publishing/1.1d1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d1 20130915//EN': 'jats/publishing/1.1d1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with MathML3 v1.1d1 20130915//EN': 'jats/publishing/1.1d1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables v1.1d1 20130915//EN': 'jats/publishing/1.1d1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.1d1 20130915//EN': 'jats/publishing/1.1d1/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d2 20140930//EN': 'jats/publishing/1.1d2/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with MathML3 v1.1d2 20140930//EN': 'jats/publishing/1.1d2/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables v1.1d2 20140930//EN': 'jats/publishing/1.1d2/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.1d2 20140930//EN': 'jats/publishing/1.1d2/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d3 20150301//EN': 'jats/publishing/1.1d3/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with MathML3 v1.1d3 20150301//EN': 'jats/publishing/1.1d3/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables v1.1d3 20150301//EN': 'jats/publishing/1.1d3/dtd/',
    '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.1d3 20150301//EN': 'jats/publishing/1.1d3/dtd/',

    # BITS
    '-//NLM//DTD BITS Book Interchange DTD with OASIS and XHTML Tables v2.0 20151225//EN': 'jats/archiving/2.0/bits_oasis_xhtml_tables_dtd',

    # Atypon
    '-//Atypon//DTD Atypon Systems Archival NLM DTD Suite v2.2.0 20090301//EN': 'atypon/2.2/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.0 20090430//EN': 'atypon/3.0.0/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.1 20100714//EN': 'atypon/3.0.1/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.2 20101108//EN': 'atypon/3.0.3/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.4 20110308//EN': 'atypon/3.0.4/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.5 20110520//EN': 'atypon/3.0.5/dtd/',
    '-//Atypon//DTD Atypon Systems Journal Archiving and Interchange NLM DTD v3.0.6 20130326//EN': 'atypon/3.0.6/dtd/',
    '-//Atypon//DTD Atypon JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.1.1 20160223//EN': 'atypon/v1.1.1/dtd/Atypon-archive-oasis-article1-mathml3.dtd'
  }
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/xml_jats_resolver.rb', line 7

def errors
  @errors
end

Instance Method Details

#dtd_path(identifier = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/xml_jats_resolver.rb', line 75

def dtd_path(identifier = nil)
  if identifier.nil?
    xml = Nokogiri::XML.parse(@filestream)
    unless xml.internal_subset
      raise XmlJats::DoctypeError
    end
    unless xml.internal_subset.external_id
      raise XmlJats::PublicIdentifierNotDeclared
    end
    identifier ||= xml.internal_subset.external_id.to_sym
  end
  dtds_path = File.dirname(__FILE__)
  dtd = @dtds[identifier]
  unless dtd
    raise XmlJats::PublicIdentifierNotSupported, "Public identifier not supported: #{identifier}"
  end
  File.join(dtds_path, 'dtd', dtd)
end

#parse(url = nil) ⇒ Object



94
95
96
97
98
# File 'lib/xml_jats_resolver.rb', line 94

def parse(url = nil)
  url ||= dtd_path
  options = Nokogiri::XML::ParseOptions::DTDVALID
  Nokogiri::XML.parse(@filestream, url, nil, options)
end