#!/bin/bash

##   Copy the files from where the editors work on them to here
##   (and also set up a bunch of .files used for later stages)

. date-config

# config of editors came from .surls and
# http://www.w3.org/2002/01/tr-automation/tr-biblio-ui

# where are the sparql document directories?
Q=../..

if [ ! -d shared ]; then
  ln -s $Q/shared .
fi

if [ "$DT" != `basename $PWD` ]; then
   echo "Run this in .../pub/$DT"
   exit 1
fi

function run
{   # useful for debugging
# echo "$@"
"$@" > /dev/null
}

# build up various useful data for use in second pass
rm -f .docs .comma-validate .comma-css-validate .comma-pubrules .comma-mirror .comma-checklinks .shortnames .longnames .ref-* .refx-* .urls .surls .wbs-docs-* .checklinks

echo "<cite><a href=\"http://www.w3.org/TR/2012/WD-turtle-20120710/\">Turtle:
Terse RDF Triple Language</a></cite>, E Prud'hommeaux, G Carothers, Editors, W3C Working Draft, 10 July 2012, http://www.w3.org/TR/2012/WD-turtle-20120710/. <a href=\"http://www.w3.org/TR/turtle/\" title=\"Latest version of Turtle\">Latest version</a> available at http://www.w3.org/TR/turtle/." > .ref-turtle

function save_vars
{
ln -s ../$Q/$L/$O $D/.spec

# or should I put them as shell-variables into a .vars file?
SU=http://www.w3.org/TR/$S
echo -n $M > $D/.maturity
echo -n $MNAME > $D/.maturity-name
echo -n $PREV > $D/.prev
echo -n $S > $D/.shortname

U="http://www.w3.org/TR/2012/$D"
echo "<li><a href=\"$U\">$TITLE</a><!-- $S --></li>" >> .docs

echo -n " $U" >> .urls
echo "$SU/" >> .surls
echo -n " $U,validate" >> .comma-validate
echo -n " $U,cssvalidate" >> .comma-css-validate
echo -n " $U/,pubrules" >> .comma-pubrules
echo -n " $U/,mirror" >> .comma-mirror
echo -n " $U,checklinks" >> .comma-checklinks
echo -n "$S " >> .shortnames
echo -n "$D " >> .longnames

ln -s ../$Q/$L $D/.home

SS=`echo $S|sed s/sparql11-//`
echo "<cite><a href=\"$U\">$TITLE</a></cite>, $CREDITS, W3C $MNAME, $DAY1 $MONTH_NAME $YEAR, $U. <a href=\"$SU/\" title=\"Latest version of $TITLE\">Latest version</a> available at $SU." > .ref-$SS
echo "<cite><a href=\"$U\">$TITLE</a></cite>, $CREDITS, W3C $MNAME, $DAY1 $MONTH_NAME $YEAR, $U. <a href=\"$SU/\" title=\"Latest version of $TITLE\">Latest version</a> available at $SU." > .refx-$S

if [ "$M" == "PR" -o "$M" == "PER" ]; then
  echo "" >> .wbs-docs-1
  echo "<p>" >> .wbs-docs-1
  echo "<a href=\"$U\">$TITLE</a><br/>" >> .wbs-docs-1
  echo "$CREDITS<br/>" >> .wbs-docs-1
  echo "W3C $MNAME, $DAY1 $MONTH_NAME $YEAR<br/>" >> .wbs-docs-1
  echo "This version: <a href=\"$U\">$U</a><br/>" >> .wbs-docs-1
  echo "Latest version: <a href=\"$SU\">$SU</a><br/>" >> .wbs-docs-1
  echo "Previous: <a href=\"$PREV\">$PREV</a><br/>" >> .wbs-docs-1
  echo "</p>" >> .wbs-docs-1

  echo "<a href=\"$U#changelog\">$TITLE</a>" >> .wbs-docs-2
fi

echo "checklink -qbs --sleep 0 $U > $D/.checklinks.txt &" >> .checklinks

}

################################################################


# maturity for next few
M=PR
MNAME="Proposed Recommendation"

TITLE="SPARQL 1.1 Overview"
CREDITS="SPARQL Working Group, Editors"
S=sparql11-overview
L=sparql11-overview
PREV=http://www.w3.org/TR/2012/WD-sparql11-overview-20120501/
D=$M-$S-$DT
O=Overview.xml
run mkdir -p $D
run cp -a $Q/shared/local.css $D
run cp -a $Q/$L/Overview.xml $D
# BAD COPY, skip it: run cp -a $Q/$L/xmlspec.xsl $D
run ln -s $D d01
save_vars

TITLE="SPARQL 1.1 Query Language"
CREDITS="S. Harris, A. Seaborne, Editors"
S=sparql11-query
L=query-1.1
PREV=http://www.w3.org/TR/2012/WD-sparql11-query-20120724/
D=$M-$S-$DT
O=rq25.xml
run mkdir -p $D
run cp -a $Q/$L/rq25.xml $D/Overview.xml
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/xmlspec.xsl $D
run cp -a $Q/$L/REC-xml.xsl $D
run cp -a $Q/$L/xmlspec.dtd $D
run cp -a $Q/$L/sparql.xsl $D
run cp -a $Q/$L/diffspec.xsl $D
run ln -s $D d02
save_vars

TITLE="SPARQL 1.1 Update"
CREDITS="P. Gearon, A. Passant, A. Polleres, Editors"
S=sparql11-update
L=update-1.1
PREV=http://www.w3.org/TR/2012/WD-sparql11-update-20120105/
D=$M-$S-$DT
O=Overview.xml
run mkdir -p $D
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/Overview.xml $D
run cp -a $Q/$L/shortcuts.xml $D
run ln -s $D d03
save_vars

TITLE="SPARQL1.1 Service Description"
CREDITS="G. Williams, Editor"
S=sparql11-service-description
L=service-description-1.1
PREV=http://www.w3.org/TR/2012/WD-sparql11-service-description-20120105/
D=$M-$S-$DT
O=xmlspec.xml
run mkdir -p $D
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/xmlspec.xml $D/Overview.xml
run ln -s $D d04
save_vars

TITLE="SPARQL 1.1 Federated Query"
CREDITS="E. Prud'hommeaux, C. Buil-Aranda, Editors"
S=sparql11-federated-query
L=fed
PREV=http://www.w3.org/TR/2011/WD-sparql11-federated-query-20111117/
D=$M-$S-$DT
O=service.xml
run mkdir -p $D
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/service.xml $D/Overview.xml
run ln -s $D d05
save_vars

TITLE="SPARQL 1.1 Query Results JSON Format"
CREDITS="A. Seaborne, Editor"
S=sparql11-results-json
L=json-results
PREV=http://www.w3.org/TR/2011/WD-sparql11-results-json-20110913/
D=$M-$S-$DT
O=json-results.xml
run mkdir -p $D
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/xmlspec.xsl $D
run cp -a $Q/$L/sparql.xsl $D
run cp -a $Q/$L/xmlspec.dtd $D
run cp -a $Q/$L/REC-xml.xsl $D
run cp -a $Q/$L/diffspec.xsl $D
run cp -a $Q/$L/json-results.xml $D/Overview.xml
run ln -s $D d06
save_vars

TITLE="SPARQL 1.1 Query Results CSV and TSV Formats"
CREDITS="A. Seaborne, Editor"
S=sparql11-results-csv-tsv
L=csv-tsv-results
PREV=http://www.w3.org/TR/2012/WD-sparql11-results-csv-tsv-20120501/
D=$M-$S-$DT
O=results-csv-tsv.html
run mkdir -p $D
######    BUT IT'S RE-SPEC!   NEEDS TO BE SAVED BY HAND!
run cp -a $Q/$L/results-csv-tsv-saved.html $D/Overview.html
run cp -a $Q/shared/local.css $D
run ln -s $D d07
save_vars

M=PER
MNAME="Proposed Edited Recommendation"

TITLE="SPARQL Query Results XML Format"
CREDITS="D. Beckett, J. Broekstra, Editors"
S=rdf-sparql-XMLres
L=xmlres
PREV=http://www.w3.org/TR/2008/REC-rdf-sparql-XMLres-20080115/
D=$M-$S-$DT
O=index.html
run mkdir -p $D
run cp -a $Q/$L/index.html $D/Overview.html
run cp -a $Q/shared/local.css $D
run ln -s $D d08
save_vars

M=CR
MNAME="Candidate Recommendation"

TITLE="SPARQL 1.1 Entailment Regimes"
CREDITS="B. Glimm, C. Ogbuji, Editors"
S=sparql11-entailment
L=entailment
PREV=http://www.w3.org/TR/2012/WD-sparql11-entailment-20120105/
D=$M-$S-$DT
O=xmlspec.xml
run mkdir -p $D
#run cp -a $Q/$L/Overview.html $D
run cp -a $Q/$L/xmlspec.xml $D/Overview.xml
run cp -a $Q/$L/local.css $D
run cp -a $Q/$L/*.png $D
run ln -s $D d09
save_vars

TITLE="SPARQL 1.1 Protocol"
CREDITS="L. Feigenbaum, G. Williams, K. Clark, E. Torres, Editors"
S=sparql11-protocol
L=protocol-1.1
PREV=http://www.w3.org/TR/2012/WD-sparql11-protocol-20120105/
D=$M-$S-$DT
O=Overview.xml
run mkdir -p $D
run cp -a $Q/$L/Overview.xml $D
run cp -a $Q/shared/local.css $D
run cp -a $Q/$L/*wsdl $D
run cp -a $Q/$L/*xsd $D
run ln -s $D d10
save_vars

TITLE="SPARQL 1.1 Graph Store HTTP Protocol"
CREDITS="C. Ogbuji, Editor"
S=sparql11-http-rdf-update
L=http-rdf-update
PREV=http://www.w3.org/TR/2012/WD-sparql11-http-rdf-update-20120501/
D=$M-$S-$DT
O=Overview.html
run mkdir -p $D
run cp -a $Q/$L/Overview.html $D
run cp -a $Q/$L/*.jpg $D
run cp -a $Q/shared/local.css $D
run ln -s $D d11
save_vars

