#!/usr/bin/env ruby
#
# post something to an annotea server...
#
# this lives at http://www.w3.org/2001/sw/Europe/200209/annodemo/annomake.rb
#	$Id: annomake.rb,v 1.3 2002/10/18 18:09:23 charles Exp $
#
# License: This software is covered by the W3C Software License.
#	See http://www.w3.org/Consortium/Legal/copyright-software for details 
#
# Usage: annotate <target> <annotation> [<creator> [<type>]]
#
# Output: RDF for an annotation on <target> that points to <annotation> 
#
# todo: interpret options
#	Should test whether the annotation is an available body 
#		or should be passed to the server as content for an annotations
#	Error Checking
#	Make this into a class
#	use options
#

# interpret the command line

target	= ARGV[0]
body	= ARGV[1]
creator	= (ARGV[2] || 'Anonymous Coward')
type	= (ARGV[3] || 'Comment')

# collect the rest of the data

theTime = Time.now.gmtime
now = theTime.strftime("%Y-%m-%dT%H:%MZ")
# now = Time.gm.now.strftime("%Y-%m-%dT%H:%MZ")

target =~ /([^#]+)(#.*)$/
resource = $1
frag_ID = $2

if frag_ID
  context = resource + frag_ID
  else
  context = resource = target
end

# output RDF

puts '<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'
puts '       xmlns:a="http://www.w3.org/2000/10/annotation-ns#"'
puts '       xmlns:d="http://purl.org/dc/elements/1.1/">'
puts ' <r:Description>'
puts '  <r:type resource="http://www.w3.org/2000/10/annotation-ns#Annotation"/>'
puts '  <r:type resource="http://www.w3.org/2000/10/annotationType#' + type + '"/>'
puts '  <a:annotates r:resource="' + resource + '"/>'
puts '  <a:context r:resource="' + context + '"/>'
puts "  <d:creator>#{creator}</d:creator>"
puts "  <a:created>#{now}</a:created>"
puts "  <d:date>#{now}</d:date>"
puts '  <a:body r:resource="' + body + '"/>'
puts ' </r:Description>'
puts '</r:RDF>'
