#!/usr/bin/env perl

use strict;
use CGI qw(standard);

my $q = new CGI;

print <<EOF;
Content-type: application/rdf+xml
Content-Disposition: attachment; filename=export.rdf

<?xml version="1.0"?>
<rdf:RDF xml:lang="en"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!--
  =======================================================================

   Copyright (c) 2006 The Apache Software Foundation.
   All rights reserved.

  =======================================================================
-->
  <BISData>
EOF
printf("    <Project rdf:resource=\"%s\">%s</Project>\n",
       $q->param('purl'), $q->param('pname'));
if ($q->param('ctcname') || $q->param('ctctel')) {
    printf("    <Contact>\n      <Name>%s</Name>\n      <Phone>%s</Phone>\n".
           "    </Contact>\n",
           $q->param('ctcname'), $q->param('ctctel'));
}


for my $i (1 .. 3) {
    last unless $q->param('cname'.$i);
    printf("    <Component name=\"%s\">\n      <FullName>%s</FullName>\n",
           $q->param('cname'.$i), $q->param('cdesc'.$i));
    my $req = 0;
    for my $j (1 .. 2) {
        if ($q->param('creq'.$i.$j) ne 'none') {
            $req++;
            printf("      <Requirement type=\"%s\" name=\"%s\"/>\n",
                   $q->param('creq'.$i.$j.'type'), 
                   $q->param('creq'.$i.$j));
        }
    }
    if ($req) {
        printf("      <Url type=\"source\" rdf:resource=\"%s\"/>\n",
               $q->param('csrcurl'.$i)) if $q->param('csrcurl'.$i);
        printf("      <Url type=\"binary\" rdf:resource=\"%s\"/>\n",
               $q->param('cbinurl'.$i)) if $q->param('cbinurl'.$i);
    }
    print "    </Component>\n";
}

print <<EOF;
  </BISData>
</rdf:RDF>
EOF

