Class: Cul::Fedora::Arm::FoxmlBuilder

Inherits:
Object
  • Object
show all
Includes:
Image
Defined in:
lib/cul/fedora/arm/foxml_builder.rb

Constant Summary collapse

STATIC_IMAGE_DEFAULTS =
{
  :content_model => 'ldpd:StaticImageAggregator',
  :title => 'Image Aggregator',
  :title_attr => 'Image Aggregator',
  :dc_type => 'Image',
}
CONTENT_DEFAULTS =
{
  :content_model => 'ldpd:ContentAggregator',
  :title => 'Generic Content Aggregator',
  :title_attr => 'Generic Content Aggregator',
  :dc_type => 'InteractiveResource',
}
METADATA_DEFAULTS =
{
  :content_model => 'ldpd:MODSMetadata',
  :dc_type => 'Text',
  :dc_format => 'text/xml'
}
RESOURCE_DEFAULTS =
{
  :content_model => 'ldpd:Resource'
}
DEFAULTS =
{
  :staticimage_aggregator => STATIC_IMAGE_DEFAULTS,
  :content_aggregator => CONTENT_DEFAULTS,
  :metadata => METADATA_DEFAULTS,
  :image_resource => RESOURCE_DEFAULTS,
  :resource => RESOURCE_DEFAULTS
}
TEMPLATES =
{
  :aggregator => Cul::Fedora::Arm::AGGREGATOR_FOXML,
  :metadata => Cul::Fedora::Arm::METADATA_FOXML,
  :resource => Cul::Fedora::Arm::RESOURCE_FOXML
}
METADATA_FOR =
"<cul:metadataFor rdf:resource=\"info:fedora/%s\" />"
MEMBER_OF =
"<cul:memberOf rdf:resource=\"info:fedora/%s\" />"
UTF8_MARKER =
"\xEF\xBB\xBF"

Instance Method Summary collapse

Instance Method Details

#build(value_hash) ⇒ Object



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
# File 'lib/cul/fedora/arm/foxml_builder.rb', line 209

def build(value_hash)         
  template_type = value_hash[:template_type]
  model_type = value_hash[:model_type]
  value_default_key = (template_type.downcase + "_" + model_type.downcase).intern
  subs = {}
  if(DEFAULTS.has_key?(value_default_key))
    subs = DEFAULTS[value_default_key].merge(value_hash)
    now  = Time.now
    subs[:timestamp] = now.strftime("%Y-%m-%dT%H:%M:%S.000Z")
    subs[:rels] = build_rels(subs)
  else
    subs = value_hash.merge({:timestamp=>Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")})
    subs[:rels] = build_rels(subs)
  end
  if (subs.has_key?(:source))
    subs[:source].strip!
    if(subs[:source].length > 0)
      if (subs[:source].index('http:') != 0)
        if(subs[:model_type].eql?('Metadata'))
          subs[:metadata] = File.open(subs[:source]){|file| file.read() }
          subs.merge!(parse_mods(subs[:metadata]))
        end
        realpath = ""
        begin
          realpath = Pathname.new(subs[:source]).realpath
        rescue
          realpath = subs[:source]
        end
        subs[:source] = 'file://' + realpath
        subs[:datastream_type] = 'E'
      else
        subs[:datastream_type] = 'M'
      end
    end
  end

  template_key = model_type.downcase.intern
  if(TEMPLATES.has_key?(template_key))
    return sub_values(subs,TEMPLATES[template_key])
  else
    raise "Unknown model type #{value_hash[:model_type]}"
  end
end