#!/usr/local/bin/perl -T use strict; use CGI qw(standard); # The master list of data and how we tranform it into the xml we need. # 0 - the form fieldname # 1 - the xml tag name to use # 2 - attribute name if applicable # 3 - whether it's a URL, 1 = yes (append http:// if rqd), 0 = no # 4 - printf format string to use for data # my @formData = ( [ 'name', 'name', '', 0, 'Apache %s' ], [ 'homepage', 'homepage', 'rdf:resource', 1 ], [ 'pmc', 'asfext:pmc', 'rdf:resource', 0, 'http://%s.apache.org' ], [ 'sdesc', 'shortdesc' ], [ 'ldesc', 'description' ], [ 'bugdb', 'bug-database', 'rdf:resource', 1 ], [ 'mail', 'mailing-list', 'rdf:resource', 1 ], [ 'dl', 'download-page', 'rdf:resource', 1 ], [ 'lang', 'programming-language' ], [ 'cat', 'category', 'rdf:resource', 0, 'http://projects.apache.org/category/%s' ], ); my $q = new CGI; my @dtp = gmtime(); my $dt = sprintf("%d-%02d-%02d", $dtp[5] + 1900, $dtp[4] + 1, $dtp[3] ); my $projName = $q->param('name') || 'projectName'; my $thehomepage = makeURL($q->param('homepage')); # $projName is used in the response headers; ensure the name is safe as a file name $projName =~ s/[^\w-]/_/g; # Keep only alphanumeric and -; convert rest to underscore $projName .= '.rdf'; print < $dt EOF for my $i (0 .. $#formData) { next unless (my $val = $q->param($formData[$i][0])); addData($val, $i); } if ($q->param('relname')) { my $n = $q->param('relname'); my $d = $q->param('reldt'); my $v = $q->param('relvers'); print < $n $d $v EOF } if ($q->param('svnurl')) { my $s = $q->param('svnurl'); my $v = $q->param('svnhttp'); $s = 'http://'.$s unless $s =~ /^http/; $v = 'http://'.$v unless $v =~ /^http/; print < EOF } if ($q->param('giturl')) { my $s = $q->param('giturl'); my $v = $q->param('githttp'); print < EOF } if ($q->param('maintainer_name')) { my $name = $q->param('maintainer_name'); my $email = $q->param('maintainer_email'); print < $name EOF } if ($q->param('std_title')) { my $t = $q->param('std_title'); my $b = $q->param('std_body'); my $i = $q->param('std_id'); my $u = makeURL($q->param('std_url')); print < $t $b $i EOF } print < EOF exit; sub addData { my ($val, $i) = @_; print " <$formData[$i][1]"; print " $formData[$i][2]=\"" if $formData[$i][2]; print ">" unless $formData[$i][2]; $val = makeURL($val) if $formData[$i][3]; if ($formData[$i][4]) { printf($formData[$i][4], $val); } else { print $val; } print "\" />" if $formData[$i][2]; print "" unless $formData[$i][2]; print "\n"; } sub makeURL { my $u = shift; $u = 'http://'.$u unless $u =~ /^http/; return $u; }