bulkrax 10.0.2 → 10.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +81 -1
- data/app/models/bulkrax/oai_entry.rb +18 -6
- data/app/parsers/bulkrax/application_parser.rb.orig +545 -0
- data/app/services/bulkrax/oai_record_fields.rb +125 -0
- data/app/services/bulkrax/oai_thumbnail_transforms.rb +110 -0
- data/app/services/bulkrax/oai_thumbnail_url.rb +217 -0
- data/config/locales/bulkrax.de.yml +16 -3
- data/config/locales/bulkrax.en.yml +14 -3
- data/config/locales/bulkrax.es.yml +16 -3
- data/config/locales/bulkrax.fr.yml +18 -3
- data/config/locales/bulkrax.it.yml +16 -3
- data/config/locales/bulkrax.pt-BR.yml +16 -3
- data/config/locales/bulkrax.zh.yml +12 -3
- data/lib/bulkrax/version.rb +1 -1
- metadata +7 -6
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bulkrax
|
|
4
|
+
# A read only index of the values an OAI record carries, built from the record's
|
|
5
|
+
# already parsed XML.
|
|
6
|
+
#
|
|
7
|
+
# Field names are independent of the importer's mappings. Any scalar element
|
|
8
|
+
# can be named. A name must resolve to one namespace URI and local name. Prefix
|
|
9
|
+
# aliases for the same URI refer to the same field. For repeated fields, the
|
|
10
|
+
# first nonblank value in document order wins.
|
|
11
|
+
#
|
|
12
|
+
# @see Bulkrax::OaiThumbnailUrl
|
|
13
|
+
class OaiRecordFields
|
|
14
|
+
# This record does not carry a usable value for the named field.
|
|
15
|
+
class UnresolvedField < ::StandardError; end
|
|
16
|
+
|
|
17
|
+
class_attribute :header_fields, instance_accessor: false, default: %w[identifier datestamp setSpec status].freeze
|
|
18
|
+
|
|
19
|
+
# @param record [OAI::Record]
|
|
20
|
+
def initialize(record)
|
|
21
|
+
@record = record
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @param scope [:field, :header] :field for the record's metadata, :header for the OAI header
|
|
25
|
+
# @param name [String] a qualified name as written in the feed (e.g. "dc:title"), a bare local
|
|
26
|
+
# name, or - for the :header scope - one of {header_fields}
|
|
27
|
+
# @return [String] the value, as text
|
|
28
|
+
# @raise [UnresolvedField] when the record has no single nonblank value for the name
|
|
29
|
+
def fetch(scope, name)
|
|
30
|
+
value = scope == :header ? header_value(name) : metadata_value(name)
|
|
31
|
+
raise UnresolvedField, "#{scope}:#{name} is blank for this record" if value.blank?
|
|
32
|
+
|
|
33
|
+
value
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def header_value(name)
|
|
39
|
+
raise UnresolvedField, "header:#{name} is not an OAI header field" unless self.class.header_fields.include?(name)
|
|
40
|
+
|
|
41
|
+
case name
|
|
42
|
+
when 'identifier' then text_of(@record.header.identifier)
|
|
43
|
+
when 'datestamp' then text_of(@record.header.datestamp)
|
|
44
|
+
when 'status' then text_of(@record.header.status)
|
|
45
|
+
when 'setSpec' then Array.wrap(@record.header.set_spec).map { |set| text_of(set) }.detect(&:present?)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def metadata_value(name)
|
|
50
|
+
candidates = index.fetch(:by_name).fetch(name, [])
|
|
51
|
+
raise UnresolvedField, "field:#{name} is not in this record" if candidates.empty?
|
|
52
|
+
|
|
53
|
+
raise UnresolvedField, "field:#{name} is ambiguous across XML namespaces" if candidates.length > 1
|
|
54
|
+
|
|
55
|
+
index.fetch(:values)[candidates.first]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def index
|
|
59
|
+
@index ||= build_index
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def build_index
|
|
63
|
+
values = {}
|
|
64
|
+
by_name = Hash.new { |names, name| names[name] = [] }
|
|
65
|
+
|
|
66
|
+
each_scalar_element(@record.metadata) do |node|
|
|
67
|
+
local_name = node.name.to_s
|
|
68
|
+
namespace = namespace_of(node)
|
|
69
|
+
key = [namespace&.href.presence, local_name]
|
|
70
|
+
prefix = namespace&.prefix.presence
|
|
71
|
+
register_name(by_name, local_name, key)
|
|
72
|
+
register_name(by_name, "#{prefix}:#{local_name}", key) if prefix
|
|
73
|
+
|
|
74
|
+
values[key] ||= text_of(node).presence
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
{ values: values, by_name: by_name }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def register_name(by_name, name, key)
|
|
81
|
+
keys = by_name[name]
|
|
82
|
+
keys << key unless keys.include?(key)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @yieldparam node [Object<#name, #content>] an element without element children
|
|
86
|
+
def each_scalar_element(node, &block)
|
|
87
|
+
element_children(node).each do |child|
|
|
88
|
+
if element_children(child).empty?
|
|
89
|
+
yield(child)
|
|
90
|
+
else
|
|
91
|
+
each_scalar_element(child, &block)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def element_children(node)
|
|
97
|
+
return [] unless node.respond_to?(:children)
|
|
98
|
+
|
|
99
|
+
node.children.select { |child| element?(child) }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def element?(node)
|
|
103
|
+
return node.element? if node.respond_to?(:element?)
|
|
104
|
+
|
|
105
|
+
node.respond_to?(:node_type) && node.node_type == :element
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def namespace_of(node)
|
|
109
|
+
return node.namespace if node.respond_to?(:namespace)
|
|
110
|
+
|
|
111
|
+
node.namespaces.namespace
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def text_of(node)
|
|
115
|
+
text = if node.respond_to?(:content)
|
|
116
|
+
node.content
|
|
117
|
+
elsif node.respond_to?(:text)
|
|
118
|
+
node.text
|
|
119
|
+
else
|
|
120
|
+
node
|
|
121
|
+
end
|
|
122
|
+
text.to_s.strip
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bulkrax
|
|
4
|
+
# A bounded pipeline of literal text operations, never Ruby expressions.
|
|
5
|
+
class OaiThumbnailTransforms
|
|
6
|
+
class InvalidPipeline < StandardError; end
|
|
7
|
+
|
|
8
|
+
QUOTED_STRING = %r{"(?:[^"\\\x00-\x1f]|\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4}))*"}.freeze
|
|
9
|
+
ARGUMENTS = {
|
|
10
|
+
'split' => [:string, :position].freeze,
|
|
11
|
+
'downcase' => [].freeze,
|
|
12
|
+
'remove_prefix' => [:string].freeze,
|
|
13
|
+
'remove_suffix' => [:string].freeze,
|
|
14
|
+
'replace' => [:string, :string].freeze
|
|
15
|
+
}.freeze
|
|
16
|
+
MAX_STEPS = 8
|
|
17
|
+
MAX_ARGUMENT_BYTES = 128
|
|
18
|
+
MAX_VALUE_BYTES = 16_384
|
|
19
|
+
|
|
20
|
+
def initialize(pipeline)
|
|
21
|
+
@scanner = StringScanner.new(pipeline)
|
|
22
|
+
@steps = parse
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def apply(value)
|
|
26
|
+
@steps.each do |name, arguments|
|
|
27
|
+
return nil if value.blank? || value.bytesize > MAX_VALUE_BYTES
|
|
28
|
+
|
|
29
|
+
value = transform(value, name, arguments)
|
|
30
|
+
end
|
|
31
|
+
value if value.present? && value.bytesize <= MAX_VALUE_BYTES
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def parse
|
|
37
|
+
steps = []
|
|
38
|
+
until @scanner.eos?
|
|
39
|
+
consume(/\|/)
|
|
40
|
+
@scanner.skip(/\s*/)
|
|
41
|
+
name = @scanner.scan(/[a-z_]+/)
|
|
42
|
+
types = ARGUMENTS[name]
|
|
43
|
+
raise InvalidPipeline, 'Unknown thumbnail transform' unless types
|
|
44
|
+
raise InvalidPipeline, 'Too many thumbnail transforms' if steps.size >= MAX_STEPS
|
|
45
|
+
|
|
46
|
+
arguments = types.empty? ? [] : parse_arguments(types)
|
|
47
|
+
raise InvalidPipeline, 'Search text must not be empty' if %w[split replace].include?(name) && arguments.first.empty?
|
|
48
|
+
|
|
49
|
+
steps << [name, arguments]
|
|
50
|
+
@scanner.skip(/\s*/)
|
|
51
|
+
end
|
|
52
|
+
steps
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def parse_arguments(types)
|
|
56
|
+
consume(/\(/)
|
|
57
|
+
arguments = types.each_with_index.map do |type, index|
|
|
58
|
+
consume(/,/) unless index.zero?
|
|
59
|
+
@scanner.skip(/\s*/)
|
|
60
|
+
type == :string ? parse_string : parse_position
|
|
61
|
+
end
|
|
62
|
+
consume(/\)/)
|
|
63
|
+
arguments
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def consume(pattern)
|
|
67
|
+
@scanner.skip(/\s*/)
|
|
68
|
+
raise InvalidPipeline, 'Malformed thumbnail transform' unless @scanner.skip(pattern)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def parse_string
|
|
72
|
+
token = @scanner.scan(QUOTED_STRING)
|
|
73
|
+
raise InvalidPipeline, 'Expected a double-quoted string' unless token
|
|
74
|
+
|
|
75
|
+
value = JSON.parse(token)
|
|
76
|
+
raise InvalidPipeline, 'Thumbnail transform argument is too long' if value.bytesize > MAX_ARGUMENT_BYTES
|
|
77
|
+
|
|
78
|
+
value
|
|
79
|
+
rescue JSON::ParserError
|
|
80
|
+
raise InvalidPipeline, 'Invalid escape in thumbnail transform string'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def parse_position
|
|
84
|
+
token = @scanner.scan(/[+-]?[0-9]{1,9}/)
|
|
85
|
+
raise InvalidPipeline, 'Split position must be a nonzero integer' unless token
|
|
86
|
+
|
|
87
|
+
position = Integer(token, 10)
|
|
88
|
+
raise InvalidPipeline, 'Split position must be a nonzero integer' if position.zero?
|
|
89
|
+
|
|
90
|
+
position
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def transform(value, name, arguments)
|
|
94
|
+
case name
|
|
95
|
+
when 'split' then split_at(value, *arguments)
|
|
96
|
+
when 'downcase' then value.downcase
|
|
97
|
+
when 'remove_prefix' then value.delete_prefix(arguments.first)
|
|
98
|
+
when 'remove_suffix' then value.delete_suffix(arguments.first)
|
|
99
|
+
when 'replace' then value.gsub(arguments.first) { arguments.last }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def split_at(value, separator, position)
|
|
104
|
+
# A string separator of one space has special behavior in Ruby's split.
|
|
105
|
+
# An escaped internal pattern keeps every separator literal.
|
|
106
|
+
index = position.positive? ? position - 1 : position
|
|
107
|
+
value.split(Regexp.new(Regexp.escape(separator)), -1)[index]
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bulkrax
|
|
4
|
+
# Renders the OAI importer's "Thumbnail URL" setting as data; the setting is
|
|
5
|
+
# never evaluated as code.
|
|
6
|
+
#
|
|
7
|
+
# A setting is either a plain URL, used exactly as written, or a URL that names
|
|
8
|
+
# values from the record being harvested:
|
|
9
|
+
#
|
|
10
|
+
# https://images.example.org/thumb/{field:dc:identifier}
|
|
11
|
+
# https://images.example.org/thumb?cover={field:dc:identifier}&label={field:dc:title}
|
|
12
|
+
# https://images.example.org/thumb/{header:identifier}
|
|
13
|
+
#
|
|
14
|
+
# +{field:NAME}+ names an element of the record's metadata and +{header:NAME}+ an
|
|
15
|
+
# OAI header field, so a metadata identifier cannot be confused with the header's.
|
|
16
|
+
# Names are looked up as literal keys (see {Bulkrax::OaiRecordFields}).
|
|
17
|
+
#
|
|
18
|
+
# Every setting must be an http(s) URL with a literal host and a usable port, whether
|
|
19
|
+
# or not it names any values; a valid plain URL is used byte for byte.
|
|
20
|
+
#
|
|
21
|
+
# A selector may only appear in a path segment or a query value; the scheme, host
|
|
22
|
+
# and port must be literal. Each value is encoded once for the component it lands
|
|
23
|
+
# in, and the rendered URL is never rescanned, so feed text cannot introduce URL
|
|
24
|
+
# delimiters, change the destination, or supply a selector of its own.
|
|
25
|
+
class OaiThumbnailUrl
|
|
26
|
+
# The setting cannot be used as written and the operator needs to change it.
|
|
27
|
+
class InvalidTemplate < ::StandardError; end
|
|
28
|
+
|
|
29
|
+
MIGRATION_HINT = 'Bulkrax no longer evaluates the OAI thumbnail URL. Use a plain http(s) URL, or name ' \
|
|
30
|
+
'a field from the feed, e.g. https://images.example.org/thumb/{field:dc:identifier}'
|
|
31
|
+
|
|
32
|
+
LEGACY_SYNTAX = /<%|%>|\#\{/.freeze
|
|
33
|
+
PLACEHOLDER = /\{(?:[^{}"]|#{OaiThumbnailTransforms::QUOTED_STRING})*\}/.freeze
|
|
34
|
+
# Index of a hidden selector; the capture is the index into the placeholder store.
|
|
35
|
+
PLACEHOLDER_TOKEN = /\{([0-9]+)\}/.freeze
|
|
36
|
+
SELECTOR = /\A(field|header):([^\s|]+)\z/.freeze
|
|
37
|
+
LITERAL_AUTHORITY = %r{\Ahttps?://[^\s/?\#]+}i.freeze
|
|
38
|
+
|
|
39
|
+
# @param template [String] the importer's thumbnail_url setting
|
|
40
|
+
# @param record [OAI::Record] the record being harvested
|
|
41
|
+
# @return [String] the rendered URL
|
|
42
|
+
# @raise [InvalidTemplate] when the setting is malformed
|
|
43
|
+
# @raise [Bulkrax::OaiRecordFields::UnresolvedField] when the record cannot supply a named value
|
|
44
|
+
def self.render(template:, record:)
|
|
45
|
+
new(template).render(record: record)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @param template [String]
|
|
49
|
+
# @raise [InvalidTemplate]
|
|
50
|
+
def initialize(template)
|
|
51
|
+
@template = template.to_s
|
|
52
|
+
@tokens = parse
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @param record [OAI::Record]
|
|
56
|
+
# @return [String]
|
|
57
|
+
def render(record:)
|
|
58
|
+
fields = Bulkrax::OaiRecordFields.new(record)
|
|
59
|
+
|
|
60
|
+
@tokens.map { |token| render_token(token, fields) }.join
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def render_token(token, fields)
|
|
66
|
+
kind, *rest = token
|
|
67
|
+
return rest.first if kind == :literal
|
|
68
|
+
|
|
69
|
+
scope, name, component, transforms = rest
|
|
70
|
+
value = fields.fetch(scope, name)
|
|
71
|
+
value = transforms.apply(value) if transforms
|
|
72
|
+
raise OaiRecordFields::UnresolvedField, "#{scope}:#{name} has no usable transformed value" unless value
|
|
73
|
+
|
|
74
|
+
encode(value, component)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Encodes for the component the value lands in, exactly once.
|
|
78
|
+
def encode(value, component)
|
|
79
|
+
case component
|
|
80
|
+
when :query then CGI.escape(value)
|
|
81
|
+
else encode_path_segment(value)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# url_encode covers everything that could add or cross a URL delimiter, but it leaves dots alone,
|
|
86
|
+
# and a segment of only dots would move the path when a server normalized it.
|
|
87
|
+
def encode_path_segment(value)
|
|
88
|
+
encoded = ERB::Util.url_encode(value)
|
|
89
|
+
return encoded unless encoded.match?(/\A\.+\z/)
|
|
90
|
+
|
|
91
|
+
encoded.gsub('.', '%2E')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def parse
|
|
95
|
+
invalid!('uses template syntax Bulkrax no longer supports') if @template.match?(LEGACY_SYNTAX)
|
|
96
|
+
|
|
97
|
+
# The authority is read from the setting as written, so a selector can never stand in
|
|
98
|
+
# for the scheme, host or port, however the rest of the URL parses.
|
|
99
|
+
authority, rest = authority_and_remainder
|
|
100
|
+
|
|
101
|
+
# Hide quoted URL delimiters inside selectors from the URL parser. Tokens
|
|
102
|
+
# are restored by index before parsing the selector, never after rendering.
|
|
103
|
+
placeholders = []
|
|
104
|
+
remainder = rest.gsub(PLACEHOLDER) { |placeholder| "{#{placeholders.push(placeholder).length - 1}}" }
|
|
105
|
+
URI.parse(authority + remainder.gsub(PLACEHOLDER_TOKEN, 'x')) # Validate literal URL syntax without selector text.
|
|
106
|
+
return [[:literal, @template]] unless templated?
|
|
107
|
+
|
|
108
|
+
[[:literal, authority]] + component_tokens(remainder, placeholders)
|
|
109
|
+
rescue URI::Error
|
|
110
|
+
invalid!('is not a valid http(s) URL')
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @return [Array<String>] the literal authority and the remaining URL components
|
|
114
|
+
# @raise [InvalidTemplate]
|
|
115
|
+
def authority_and_remainder
|
|
116
|
+
authority = @template[LITERAL_AUTHORITY]
|
|
117
|
+
invalid!('must begin with a literal http(s) scheme, host and port') unless valid_authority?(authority)
|
|
118
|
+
|
|
119
|
+
remainder = @template[authority.length..]
|
|
120
|
+
return [authority, remainder] if remainder.empty? || remainder.start_with?('/', '?', '#')
|
|
121
|
+
|
|
122
|
+
invalid!("must separate its host from the rest of the URL with '/', '?' or '#'")
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def invalid!(reason)
|
|
126
|
+
raise InvalidTemplate, "The OAI thumbnail URL #{reason}. #{MIGRATION_HINT}"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def valid_authority?(authority)
|
|
130
|
+
return false if authority.nil? || braces?(authority) || authority.end_with?(':')
|
|
131
|
+
|
|
132
|
+
uri = URI.parse(authority)
|
|
133
|
+
uri.is_a?(URI::HTTP) && uri.host.present? && (1..65_535).cover?(uri.port)
|
|
134
|
+
rescue URI::Error
|
|
135
|
+
false
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Splits everything after the authority into its path, query and fragment.
|
|
139
|
+
def component_tokens(remainder, placeholders)
|
|
140
|
+
fragment_index = remainder.index('#')
|
|
141
|
+
fragment = fragment_index ? remainder[fragment_index..] : ''
|
|
142
|
+
path_and_query = fragment_index ? remainder[0...fragment_index] : remainder
|
|
143
|
+
path, separator, query = path_and_query.partition('?')
|
|
144
|
+
|
|
145
|
+
if braces?(fragment)
|
|
146
|
+
raise InvalidTemplate, "#{@template.inspect} names a field in its fragment; only path segments " \
|
|
147
|
+
"and query values may name a field. #{MIGRATION_HINT}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
tokens = tokenize(path, :path, placeholders)
|
|
151
|
+
tokens += [[:literal, separator]] + query_tokens(query, placeholders) if separator.present?
|
|
152
|
+
tokens << [:literal, fragment] if fragment.present?
|
|
153
|
+
tokens
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def query_tokens(query, placeholders)
|
|
157
|
+
query.split('&', -1).each_with_index.flat_map do |parameter, index|
|
|
158
|
+
name, separator, value = parameter.partition('=')
|
|
159
|
+
if braces?(name)
|
|
160
|
+
raise InvalidTemplate, "#{@template.inspect} names a field outside a query value; only path " \
|
|
161
|
+
"segments and query values may name a field. #{MIGRATION_HINT}"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
tokens = index.positive? ? [[:literal, '&']] : []
|
|
165
|
+
tokens << [:literal, name + separator] if (name + separator).present?
|
|
166
|
+
tokens + tokenize(value, :query, placeholders)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def tokenize(text, component, placeholders)
|
|
171
|
+
tokens = []
|
|
172
|
+
position = 0
|
|
173
|
+
|
|
174
|
+
while (match = PLACEHOLDER_TOKEN.match(text, position))
|
|
175
|
+
tokens << literal_token(text[position...match.begin(0)])
|
|
176
|
+
tokens << selector_token(placeholders.fetch(match[1].to_i), component)
|
|
177
|
+
position = match.end(0)
|
|
178
|
+
end
|
|
179
|
+
tokens << literal_token(text[position..])
|
|
180
|
+
|
|
181
|
+
tokens.compact
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def literal_token(text)
|
|
185
|
+
return nil if text.blank?
|
|
186
|
+
raise InvalidTemplate, "#{@template.inspect} has an unmatched '{' or '}'. #{MIGRATION_HINT}" if braces?(text)
|
|
187
|
+
|
|
188
|
+
[:literal, text]
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def selector_token(placeholder, component)
|
|
192
|
+
selector, pipe, pipeline = placeholder[1..-2].partition('|')
|
|
193
|
+
match = SELECTOR.match(pipe.empty? ? selector : selector.rstrip)
|
|
194
|
+
raise InvalidTemplate, "#{placeholder} is not a field or header selector. #{MIGRATION_HINT}" if match.nil?
|
|
195
|
+
|
|
196
|
+
scope = match[1].to_sym
|
|
197
|
+
name = match[2]
|
|
198
|
+
if scope == :header && !Bulkrax::OaiRecordFields.header_fields.include?(name)
|
|
199
|
+
raise InvalidTemplate, "#{placeholder} is not an OAI header field; the header fields are " \
|
|
200
|
+
"#{Bulkrax::OaiRecordFields.header_fields.join(', ')}. #{MIGRATION_HINT}"
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
transforms = OaiThumbnailTransforms.new(pipe + pipeline) unless pipe.empty?
|
|
204
|
+
[:selector, scope, name, component, transforms]
|
|
205
|
+
rescue OaiThumbnailTransforms::InvalidPipeline => e
|
|
206
|
+
raise InvalidTemplate, "#{e.message}. #{MIGRATION_HINT}"
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def templated?
|
|
210
|
+
braces?(@template)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def braces?(text)
|
|
214
|
+
text.to_s.match?(/[{}]/)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
@@ -151,13 +151,26 @@ de:
|
|
|
151
151
|
override_rights_statement: Wenn diese Option aktiviert ist, wird immer die ausgewählte Rechteanweisung verwendet. Wenn sie deaktiviert ist, wird dc:rights aus dem Datensatz verwendet und der angegebene Wert nur dann, wenn dc:rights leer ist.
|
|
152
152
|
thumbnail_url_html: |
|
|
153
153
|
<p>
|
|
154
|
-
Die Thumbnail-URL
|
|
154
|
+
Die Thumbnail-URL wird so verwendet, wie sie eingegeben wurde, oder sie kann Felder aus jedem
|
|
155
|
+
geernteten Datensatz benennen. Die Namen sind die Elementnamen im Feed: <code>{field:NAME}</code>
|
|
156
|
+
liest die Metadaten des Datensatzes, <code>{header:NAME}</code> liest den OAI-Header. Zum Beispiel:
|
|
155
157
|
</p>
|
|
156
158
|
<p>
|
|
157
|
-
|
|
159
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
158
160
|
</p>
|
|
159
161
|
<p>
|
|
160
|
-
|
|
162
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
163
|
+
</p>
|
|
164
|
+
<p>
|
|
165
|
+
Ein Name darf nur in einem Pfadsegment oder in einem Abfragewert vorkommen; Schema, Host und
|
|
166
|
+
Port müssen wörtlich angegeben werden, und jeder Wert wird für Sie URL-codiert. Die
|
|
167
|
+
Einstellung muss eine http- oder https-URL sein, auch wenn sie kein Feld benennt. Um nur
|
|
168
|
+
einen Teil eines Wertes zu verwenden, fügen Sie <code>|</code> und eine Umwandlung hinzu:
|
|
169
|
+
<code>{header:identifier | split(":", -1)}</code> ist der letzte durch Doppelpunkt
|
|
170
|
+
getrennte Teil des Identifikators. Datensätze ohne das genannte Feld werden ohne Thumbnail
|
|
171
|
+
importiert. ERB wie <%= identifier.split(':').last %> wird nicht mehr
|
|
172
|
+
unterstützt und wird abgelehnt; ein Importer mit einer solchen Einstellung lässt seine
|
|
173
|
+
Einträge fehlschlagen, bis die Einstellung geändert wird.
|
|
161
174
|
</p>
|
|
162
175
|
labels:
|
|
163
176
|
set: Menge (Quelle)
|
|
@@ -153,13 +153,24 @@ en:
|
|
|
153
153
|
override_rights_statement: If checked, always use the selected rights statement. If unchecked, use dc:rights from the record and only use the provided value if dc:rights is blank.
|
|
154
154
|
thumbnail_url_html: |
|
|
155
155
|
<p>
|
|
156
|
-
The Thumbnail URL
|
|
156
|
+
The Thumbnail URL is used as written, or it can name fields from each harvested record.
|
|
157
|
+
Names are the element names in the feed: <code>{field:NAME}</code> reads the record's
|
|
158
|
+
metadata and <code>{header:NAME}</code> reads the OAI header. For example:
|
|
157
159
|
</p>
|
|
158
160
|
<p>
|
|
159
|
-
|
|
161
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
160
162
|
</p>
|
|
161
163
|
<p>
|
|
162
|
-
|
|
164
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
165
|
+
</p>
|
|
166
|
+
<p>
|
|
167
|
+
A name may only appear in a path segment or a query value; the scheme, host and port must
|
|
168
|
+
be literal, and each value is URL encoded for you. Whether or not it names a field, the
|
|
169
|
+
setting must be an http or https URL. To use part of a value, add <code>|</code> and a
|
|
170
|
+
transform: <code>{header:identifier | split(":", -1)}</code> is the last colon-separated
|
|
171
|
+
piece of the identifier. Records without the named field are imported without a thumbnail.
|
|
172
|
+
ERB such as <%= identifier.split(':').last %> is no longer supported and is
|
|
173
|
+
rejected; an importer that still has one fails its entries until the setting is changed.
|
|
163
174
|
</p>
|
|
164
175
|
labels:
|
|
165
176
|
set: Set (source)
|
|
@@ -151,13 +151,26 @@ es:
|
|
|
151
151
|
override_rights_statement: Si está marcada, usar siempre la declaración de derechos seleccionada. Si no está marcada, usar dc:rights del registro y usar solo el valor proporcionado si dc:rights está en blanco.
|
|
152
152
|
thumbnail_url_html: |
|
|
153
153
|
<p>
|
|
154
|
-
La URL en miniatura
|
|
154
|
+
La URL en miniatura se usa tal como se escribe, o puede nombrar campos de cada registro
|
|
155
|
+
recolectado. Los nombres son los nombres de los elementos del feed: <code>{field:NAME}</code>
|
|
156
|
+
lee los metadatos del registro y <code>{header:NAME}</code> lee la cabecera OAI. Por ejemplo:
|
|
155
157
|
</p>
|
|
156
158
|
<p>
|
|
157
|
-
|
|
159
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
158
160
|
</p>
|
|
159
161
|
<p>
|
|
160
|
-
|
|
162
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
163
|
+
</p>
|
|
164
|
+
<p>
|
|
165
|
+
Un nombre solo puede aparecer en un segmento de la ruta o en el valor de un parámetro de
|
|
166
|
+
consulta; el esquema, el host y el puerto deben ser literales, y cada valor se codifica
|
|
167
|
+
para la URL automáticamente. Nombre o no un campo, el valor configurado debe ser una URL
|
|
168
|
+
http o https. Para usar solo parte de un valor, añada <code>|</code> y una transformación:
|
|
169
|
+
<code>{header:identifier | split(":", -1)}</code> es la última parte del identificador
|
|
170
|
+
separada por dos puntos. Los registros que no tienen el campo nombrado se importan sin
|
|
171
|
+
miniatura. ERB como <%= identifier.split(':').last %> ya no es compatible y
|
|
172
|
+
se rechaza; un importador que todavía lo tenga hará fallar sus entradas hasta que se
|
|
173
|
+
cambie la configuración.
|
|
161
174
|
</p>
|
|
162
175
|
labels:
|
|
163
176
|
set: Conjunto (fuente)
|
|
@@ -151,13 +151,28 @@ fr:
|
|
|
151
151
|
override_rights_statement: Si cette option est cochée, utiliser systématiquement la déclaration de droits sélectionnée. Sinon, utiliser la valeur de dc:rights de l'enregistrement et uniquement si dc:rights est vide.
|
|
152
152
|
thumbnail_url_html: |
|
|
153
153
|
<p>
|
|
154
|
-
L'URL de la miniature
|
|
154
|
+
L'URL de la miniature est utilisée telle qu'elle est saisie, ou elle peut nommer des champs
|
|
155
|
+
de chaque enregistrement moissonné. Les noms sont les noms des éléments du flux :
|
|
156
|
+
<code>{field:NAME}</code> lit les métadonnées de l'enregistrement et
|
|
157
|
+
<code>{header:NAME}</code> lit l'en-tête OAI. Par exemple :
|
|
155
158
|
</p>
|
|
156
159
|
<p>
|
|
157
|
-
|
|
160
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
158
161
|
</p>
|
|
159
162
|
<p>
|
|
160
|
-
|
|
163
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
164
|
+
</p>
|
|
165
|
+
<p>
|
|
166
|
+
Un nom ne peut apparaître que dans un segment de chemin ou dans la valeur d'un paramètre de
|
|
167
|
+
requête ; le schéma, l'hôte et le port doivent être littéraux, et chaque valeur est encodée
|
|
168
|
+
pour l'URL automatiquement. Qu'elle nomme un champ ou non, la valeur saisie doit être une
|
|
169
|
+
URL http ou https. Pour n'utiliser qu'une partie d'une valeur, ajoutez <code>|</code> et une
|
|
170
|
+
transformation : <code>{header:identifier | split(":", -1)}</code> correspond à la dernière
|
|
171
|
+
partie de l'identifiant séparée par deux-points. Les enregistrements dépourvus du champ
|
|
172
|
+
nommé sont importés sans miniature. Les modèles ERB tels que
|
|
173
|
+
<%= identifier.split(':').last %> ne sont plus pris en charge et sont rejetés ;
|
|
174
|
+
un importateur qui en conserve un fera échouer ses entrées jusqu'à la modification du
|
|
175
|
+
paramètre.
|
|
161
176
|
</p>
|
|
162
177
|
labels:
|
|
163
178
|
set: Ensemble (source)
|
|
@@ -151,13 +151,26 @@ it:
|
|
|
151
151
|
override_rights_statement: Se selezionata, utilizza sempre l'istruzione dei diritti selezionata. Se non selezionata, utilizza dc:rights dal record e utilizza il valore fornito solo se dc:rights è vuoto.
|
|
152
152
|
thumbnail_url_html: |
|
|
153
153
|
<p>
|
|
154
|
-
L'URL miniatura
|
|
154
|
+
L'URL miniatura viene usato così come è scritto, oppure può indicare campi di ogni record
|
|
155
|
+
raccolto. I nomi sono i nomi degli elementi presenti nel feed: <code>{field:NAME}</code>
|
|
156
|
+
legge i metadati del record e <code>{header:NAME}</code> legge l'header OAI. Ad esempio:
|
|
155
157
|
</p>
|
|
156
158
|
<p>
|
|
157
|
-
|
|
159
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
158
160
|
</p>
|
|
159
161
|
<p>
|
|
160
|
-
|
|
162
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
163
|
+
</p>
|
|
164
|
+
<p>
|
|
165
|
+
Un nome può comparire solo in un segmento del percorso o nel valore di un parametro della
|
|
166
|
+
query; schema, host e porta devono essere letterali e ogni valore viene codificato per
|
|
167
|
+
l'URL automaticamente. Indichi o no un campo, l'impostazione deve essere un URL http o
|
|
168
|
+
https. Per usare solo una parte di un valore, aggiungere <code>|</code> e una
|
|
169
|
+
trasformazione: <code>{header:identifier | split(":", -1)}</code> è l'ultima parte
|
|
170
|
+
dell'identificatore separata dai due punti. I record privi del campo indicato vengono
|
|
171
|
+
importati senza miniatura. ERB come <%= identifier.split(':').last %> non è
|
|
172
|
+
più supportato e viene rifiutato; un importatore che lo conserva fa fallire le proprie
|
|
173
|
+
voci finché l'impostazione non viene modificata.
|
|
161
174
|
</p>
|
|
162
175
|
labels:
|
|
163
176
|
set: Set (fonte)
|
|
@@ -151,13 +151,26 @@ pt-BR:
|
|
|
151
151
|
override_rights_statement: Se selecionada, use sempre a declaração de direitos escolhida. Se desmarcada, use o valor de dc:rights do registro e utilize o valor fornecido somente se dc:rights estiver em branco.
|
|
152
152
|
thumbnail_url_html: |
|
|
153
153
|
<p>
|
|
154
|
-
A URL em miniatura
|
|
154
|
+
A URL em miniatura é usada exatamente como foi escrita, ou pode nomear campos de cada
|
|
155
|
+
registro coletado. Os nomes são os nomes dos elementos do feed: <code>{field:NAME}</code>
|
|
156
|
+
lê os metadados do registro e <code>{header:NAME}</code> lê o cabeçalho OAI. Por exemplo:
|
|
155
157
|
</p>
|
|
156
158
|
<p>
|
|
157
|
-
|
|
159
|
+
https://images.example.org/thumb/{field:dc:identifier}?size=L
|
|
158
160
|
</p>
|
|
159
161
|
<p>
|
|
160
|
-
|
|
162
|
+
https://images.example.org/thumb/{header:identifier | split(":", -1)}?size=L
|
|
163
|
+
</p>
|
|
164
|
+
<p>
|
|
165
|
+
Um nome só pode aparecer em um segmento do caminho ou no valor de um parâmetro de consulta;
|
|
166
|
+
o esquema, o host e a porta devem ser literais, e cada valor é codificado para a URL
|
|
167
|
+
automaticamente. Nomeie ou não um campo, a configuração deve ser uma URL http ou https.
|
|
168
|
+
Para usar apenas parte de um valor, acrescente <code>|</code> e uma transformação:
|
|
169
|
+
<code>{header:identifier | split(":", -1)}</code> é a última parte do identificador
|
|
170
|
+
separada por dois-pontos. Registros sem o campo indicado são importados sem miniatura.
|
|
171
|
+
ERB como <%= identifier.split(':').last %> não é mais suportado e é
|
|
172
|
+
rejeitado; um importador que ainda tenha um falhará suas entradas até que a configuração
|
|
173
|
+
seja alterada.
|
|
161
174
|
</p>
|
|
162
175
|
labels:
|
|
163
176
|
set: Conjunto (fonte)
|