summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbjoern <bjoern@localhost>2005-09-10 09:00:28 +0000
committerbjoern <bjoern@localhost>2005-09-10 09:00:28 +0000
commit6dc904c8cab91e03f1fff8ca5540a3f33dd1a62e (patch)
tree25a33323e83c203d6eeeb57f73ff62ed2f26451f
parent1641e3de4dc9be76fe8c50eb5b35a53ee976fc7e (diff)
downloadmarkup-validator-6dc904c8cab91e03f1fff8ca5540a3f33dd1a62e.zip
markup-validator-6dc904c8cab91e03f1fff8ca5540a3f33dd1a62e.tar.gz
markup-validator-6dc904c8cab91e03f1fff8ca5540a3f33dd1a62e.tar.bz2
templates for alternate output formats
-rwxr-xr-xhttpd/cgi-bin/check339
-rw-r--r--share/templates/en_US/earl_n3.tmpl46
-rw-r--r--share/templates/en_US/earl_xml.tmpl54
-rw-r--r--share/templates/en_US/xml_output.tmpl69
4 files changed, 264 insertions, 244 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check
index d995656..60212c1 100755
--- a/httpd/cgi-bin/check
+++ b/httpd/cgi-bin/check
@@ -9,7 +9,7 @@
# This source code is available under the license at:
# http://www.w3.org/Consortium/Legal/copyright-software
#
-# $Id: check,v 1.446 2005-09-10 07:06:27 bjoern Exp $
+# $Id: check,v 1.447 2005-09-10 09:00:28 bjoern Exp $
#
# Disable buffering on STDOUT!
@@ -190,7 +190,7 @@ Directory not readable (permission denied): @_r
#
# Strings
- $VERSION = q$Revision: 1.446 $;
+ $VERSION = q$Revision: 1.447 $;
$VERSION =~ s/Revision: ([\d\.]+) /$1/;
#
@@ -290,6 +290,31 @@ my $H = HTML::Template->new(
cache => TRUE,
);
+# templates for alternate output formats
+my $XMLT = HTML::Template->new(
+ filename => File::Spec->catfile($CFG->{Paths}->{Templates},
+ 'en_US', 'xml_output.tmpl'),
+ die_on_bad_params => FALSE,
+ loop_context_vars => TRUE,
+ cache => TRUE,
+);
+my $EARLT = HTML::Template->new(
+ filename => File::Spec->catfile($CFG->{Paths}->{Templates},
+ 'en_US', 'earl_xml.tmpl'),
+ die_on_bad_params => FALSE,
+ loop_context_vars => TRUE,
+ cache => TRUE,
+ global_vars => TRUE,
+);
+my $N3T = HTML::Template->new(
+ filename => File::Spec->catfile($CFG->{Paths}->{Templates},
+ 'en_US', 'earl_n3.tmpl'),
+ die_on_bad_params => FALSE,
+ loop_context_vars => TRUE,
+ cache => TRUE,
+ global_vars => TRUE,
+);
+
$File->{T} = $T;
$File->{E} = $E;
$File->{H} = $H;
@@ -660,46 +685,21 @@ if ($File->{Namespace}) {
}
if ($File->{Opt}->{Output} eq 'xml') {
- &report_xml($File);
+ prep_template($File, $XMLT);
+ fin_template($File, $XMLT);
+ report_xml($File, $XMLT);
} elsif ($File->{Opt}->{Output} eq 'earl') {
- &report_earl($File);
+ prep_template($File, $EARLT);
+ fin_template($File, $EARLT);
+ report_earl($File, $EARLT);
} elsif ($File->{Opt}->{Output} eq 'n3') {
- &report_n3($File);
+ prep_template($File, $N3T);
+ fin_template($File, $N3T);
+ report_n3($File, $N3T);
} else {
&prep_template($File, $T);
-
- if (! $File->{Doctype} and ($File->{Version} eq 'unknown' or $File->{Version} eq 'SGML' or (!$File->{Version}))) {
-
- # @@TODO@@ we should try falling back on other version
- # info, such as the ones stored in Version_ESIS
- $T->param(file_version => '(no Doctype found)');
- }
- else {
- $T->param(file_version => $File->{Version});
- }
- my $num_errors = scalar @{$File->{Errors}};
- if ($num_errors >0)
- {
- $T->param(has_errors => 1);
- }
- $T->param(valid_errors_num => $num_errors);
- my ($number_of_errors, $reported_errors) = &report_errors($File);
- if ($number_of_errors > 1) {
- $number_of_errors = "$number_of_errors errors"
- }
- else {
- $number_of_errors = "$number_of_errors error"
- }
- $T->param(file_errors => $reported_errors);
- $T->param(number_of_errors => $number_of_errors);
- if ($File->{'Is Valid'}) {
- $T->param(VALID => TRUE);
- $T->param(valid_status => 'Valid');
- &report_valid($File, $T);
- } else {
- $T->param(VALID => FALSE);
- $T->param(valid_status => 'Invalid');
- }
+
+ fin_template($File, $T);
$T->param(file_warnings => $File->{Warnings});
$T->param(file_source => &source($File))
@@ -750,6 +750,7 @@ sub prep_template ($$) {
$T->param(file_size => $File->{Size});
$T->param(file_contenttype => $File->{ContentType});
$T->param(file_charset => $File->{Charset}->{Use});
+ $T->param(file_doctype => $File->{DOCTYPE});
#
# Output options...
@@ -791,6 +792,44 @@ sub prep_template ($$) {
}
}
+sub fin_template ($$) {
+ my $File = shift;
+ my $T = shift;
+
+ if (! $File->{Doctype} and ($File->{Version} eq 'unknown' or $File->{Version} eq 'SGML' or (!$File->{Version}))) {
+
+ # @@TODO@@ we should try falling back on other version
+ # info, such as the ones stored in Version_ESIS
+ $T->param(file_version => '(no Doctype found)');
+ }
+ else {
+ $T->param(file_version => $File->{Version});
+ }
+ my $num_errors = scalar @{$File->{Errors}};
+ if ($num_errors >0)
+ {
+ $T->param(has_errors => 1);
+ }
+ $T->param(valid_errors_num => $num_errors);
+ my ($number_of_errors, $reported_errors) = &report_errors($File);
+ if ($number_of_errors > 1) {
+ $number_of_errors = "$number_of_errors errors"
+ }
+ else {
+ $number_of_errors = "$number_of_errors error"
+ }
+ $T->param(file_errors => $reported_errors);
+ $T->param(number_of_errors => $number_of_errors);
+ if ($File->{'Is Valid'}) {
+ $T->param(VALID => TRUE);
+ $T->param(valid_status => 'Valid');
+ &report_valid($File, $T);
+ } else {
+ $T->param(VALID => FALSE);
+ $T->param(valid_status => 'Invalid');
+ }
+}
+
#
# Output "This page is Valid" report.
sub report_valid {
@@ -1654,165 +1693,28 @@ sub find_encodings
# Return an XML report for the page.
sub report_xml {
my $File = shift;
+ my $template = shift;
- my $valid = ($File->{'Is Valid'} ? 'Valid' : 'Invalid');
- my $errs = ($File->{'Is Valid'} ? '0' : scalar @{$File->{Errors}});
- if ($File->{E}->param('fatal_http_error')) {
- $valid = 'Could not validate';
- }
+ # TODO: restore
+ # if ($File->{E}->param('fatal_http_error')) {
+ # $valid = 'Could not validate';
+ # }
- print <<".EOF.";
-Content-Type: application/xml; charset=UTF-8
-X-W3C-Validator-Status: $valid
-X-W3C-Validator-Errors: $errs
-
-<?xml version="1.0" encoding="UTF-8"?>
-<?xml-stylesheet type="text/xsl" href="xml-results.xsl"?>
-<!DOCTYPE result [
- <!ELEMENT result (meta, warnings?, messages?)>
- <!ATTLIST result
- version CDATA #FIXED '0.9.1'
- >
-
- <!ELEMENT meta (uri, modified, server, size, encoding, doctype, errors)>
- <!ELEMENT uri (#PCDATA)>
- <!ELEMENT modified (#PCDATA)>
- <!ELEMENT server (#PCDATA)>
- <!ELEMENT size (#PCDATA)>
- <!ELEMENT encoding (#PCDATA)>
- <!ELEMENT doctype (#PCDATA)>
- <!ELEMENT errors (#PCDATA)>
-
- <!ELEMENT warnings (warning)+>
- <!ELEMENT warning (#PCDATA)>
-
- <!ELEMENT messages (msg)*>
- <!ELEMENT msg (#PCDATA)>
- <!ATTLIST msg
- line CDATA #IMPLIED
- col CDATA #IMPLIED
- offset CDATA #IMPLIED
- >
-]>
-.EOF.
-
- print qq(
-<result>
- <meta>
- <uri>), &ent($File->{URI}), qq(</uri>
- <modified>), &ent($File->{Modified}), qq(</modified>
- <server>), &ent($File->{Server}), qq(</server>
- <size>), &ent($File->{Size}), qq(</size>
- <encoding>), &ent($File->{Charset}->{Use}), qq(</encoding>
- <doctype>), &ent($File->{DOCTYPE}), qq(</doctype>
- <errors>), $errs, qq(</errors>
- </meta>
-);
-
- #@@FIXME: This is borked after templatification.
- # &add_warning($File, 'note', 'Note:', <<".EOF.");
- # This interface is highly experimental and the output *will* change
- # -- probably even several times -- before finished. Do *not* rely on it!
- # See http://validator.w3.org/docs/users.html#api-warning
- # .EOF.
- #@@FIXME;
-
- if (defined $File->{Warnings} and scalar @{$File->{Warnings}}) {
- print qq( <warnings>\n);
- printf qq( <warning>%s</warning>\n),
- &ent($_->{Message}) for @{$File->{Warnings}};
- print qq( </warnings>\n);
- }
-
- if (defined $File->{Errors} and scalar @{$File->{Errors}}) {
- print qq( <messages>\n);
-
- foreach my $err (@{$File->{Errors}}) {
- printf <<".EOF.", &ent($err->{msg});
- <msg line="$err->{line}" col="$err->{char}">%s</msg>
-.EOF.
- }
- print qq( </messages>\n);
- }
- print qq(</result>\n);
+ print $template->output;
}
#
# Return an EARL report for the page.
sub report_earl {
my $File = shift;
+ my $template = shift;
- my $valid = ($File->{'Is Valid'} ? 'Valid' : 'Invalid');
- my $errs = ($File->{'Is Valid'} ? '0' : scalar @{$File->{Errors}});
- if ($File->{E}->param('fatal_http_error')) {
- $valid = 'Could not validate';
- }
-
- print <<".EOF.";
-Content-Type: application/rdf+xml; charset=UTF-8
-X-W3C-Validator-Status: $valid
-X-W3C-Validator-Errors: $errs
-
-<?xml version="1.0" encoding="UTF-8"?>
-<rdf:RDF
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns="http://www.w3.org/2001/03/earl/1.0-test#"
- xmlns:val="http://validator.w3.org/this_will_change/do_not_rely_on_it!">
-
- <Assertor rdf:about="http://validator.w3.org/">
- <name>W3 Validator</name>
- <contactInfo rdf:resource="http://validator.w3.org/about.html"/>
- <testMode rdf:resource="http://www.w3.org/2001/03/earl/1.00#Auto" />
-
-.EOF.
-
- unless ($File->{'Is Valid'}) {
- printf <<".EOF.", &ent($File->{URI});
- <asserts>
- <Assertion rdf:ID="result">
- <subject rdf:resource="%s" />
- <result rdf:resource="http://www.w3.org/2001/03/earl/1.00#fails" />
- <testCase rdf:resource="http://www.w3.org/MarkUp/" />
- <note>Invalid!</note>
- </Assertion>
- </asserts>
-.EOF.
+ # TODO: restore
+ # if ($File->{E}->param('fatal_http_error')) {
+ # $valid = 'Could not validate';
+ # }
- my $errnum = 0 ;
- foreach my $err (@{$File->{Errors}}) {
- ++$errnum ;
- printf <<".EOF.", &ent($File->{URI}), &ent($err->{msg});
- <asserts>
- <Assertion rdf:ID="err$errnum">
- <subject rdf:parseType="Resource">
- <reprOf rdf:resource="%s"/>
- <val:line>$err->{line}</val:line>
- <val:column>$err->{char}</val:column>
- </subject>
- <result rdf:resource="http://www.w3.org/2003/03/earl/1.00#fails" />
- <testCase rdf:resource="http://www.w3.org/Markup/" />
- <note>%s</note>
- </Assertion>
- </asserts>
-.EOF.
- }
- } else {
- printf <<".EOF.", &ent($File->{URI});
- <asserts>
- <Assertion>
- <subject rdf:resource="%s" />
- <result rdf:resource="http://www.w3.org/2001/03/earl/1.00#passes" />
- <testCase rdf:resource="http://www.w3.org/MarkUp/" />
- <note>Valid!</note>
- </Assertion>
- </asserts>
-.EOF.
- }
-
- print <<".EOF.";
- </Assertor>
-</rdf:RDF>
-.EOF.
+ print $template->output;
}
#
@@ -1821,65 +1723,14 @@ X-W3C-Validator-Errors: $errs
# @@TODO: escape output;
sub report_n3 {
my $File = shift;
+ my $template = shift;
- my $valid = ($File->{'Is Valid'} ? 'Valid' : 'Invalid');
- my $errs = ($File->{'Is Valid'} ? '0' : scalar @{$File->{Errors}});
- if ($File->{E}->param('fatal_http_error')) {
- $valid = 'Could not validate';
- }
-
- print <<".EOF.";
-Content-Type: text/plain; charset=UTF-8
-X-W3C-Validator-Status: $valid
-X-W3C-Validator-Errors: $errs
-
-\@prefix earl: <http://www.w3.org/2001/03/earl/1.0-test#> .
-\@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-\@prefix val: <http://validator.w3.org/this_will_change/do_not_rely_on_it!> .
-
-<http://validator.w3.org/> a earl:Assertor;
- earl:name "W3 Validator";
- earl:asserts
-.EOF.
+ # TODO: restore
+ # if ($File->{E}->param('fatal_http_error')) {
+ # $valid = 'Could not validate';
+ # }
- unless ($File->{'Is Valid'}) {
- for (my $i = 0; $i <= scalar @{$File->{Errors}}; $i++) {
- my $err = $File->{Errors}->[$i];
- print <<".EOF.";
- [
- earl:testMode earl:Auto;
- rdf:predicate earl:fails;
- rdf:subject [
- val:column "$err->{char}";
- val:line "$err->{line}";
- earl:testSubject <$File->{URI}>
- ];
- rdf:object [
- earl:id <http://www.w3.org/HTML/>;
- earl:note """$err->{msg} """
- ]
-.EOF.
-
- if ($i == scalar @{$File->{Errors}}) {
- print " ]\n";
- } else {
- print " ],\n";
- }
- }
- } else {
- print <<".EOF.";
- [
- earl:testMode earl:Auto;
- rdf:predicate earl:passes;
- rdf:subject [earl:testSubject <$File->{URI}>];
- rdf:object [
- earl:id <http://www.w3.org/HTML/>;
- earl:note "Valid"
- ]
- ]
-.EOF.
- }
- print " .\n";
+ print $template->output;
}
#
diff --git a/share/templates/en_US/earl_n3.tmpl b/share/templates/en_US/earl_n3.tmpl
new file mode 100644
index 0000000..c3e9507
--- /dev/null
+++ b/share/templates/en_US/earl_n3.tmpl
@@ -0,0 +1,46 @@
+Content-Type: text/plain; charset=UTF-8
+X-W3C-Validator-Status: <TMPL_VAR NAME="valid_status">
+X-W3C-Validator-Errors: <TMPL_VAR NAME="number_of_errors">
+
+@prefix earl: <http://www.w3.org/2001/03/earl/1.0-test#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix val: <http://validator.w3.org/this_will_change/do_not_rely_on_it!> .
+
+<http://validator.w3.org/> a earl:Assertor;
+ earl:name "W3 Validator";
+ earl:asserts
+<TMPL_IF NAME="VALID">
+ [
+ earl:testMode earl:Auto;
+ rdf:predicate earl:passes;
+ rdf:subject [earl:testSubject <<TMPL_VAR NAME="file_uri">>];
+ rdf:object [
+ earl:id <http://www.w3.org/HTML/>;
+ earl:note "Valid"
+ ]
+ ]
+<TMPL_ELSE>
+<TMPL_LOOP NAME="file_errors">
+ [
+ earl:testMode earl:Auto;
+ rdf:predicate earl:fails;
+ rdf:subject [
+ val:column "<TMPL_VAR NAME="char">";
+ val:line "<TMPL_VAR NAME="line">";
+ earl:testSubject <<TMPL_VAR NAME="file_uri">>
+ ];
+ rdf:object [
+ earl:id <http://www.w3.org/HTML/>;
+ earl:note """<TMPL_VAR NAME="msg">"""
+ ]
+<TMPL_IF __last__>
+ ]
+<TMPL_ELSE>
+ ],
+</TMPL_IF>
+</TMPL_LOOP>
+</TMPL_IF>
+
+.
+
+# EOF
diff --git a/share/templates/en_US/earl_xml.tmpl b/share/templates/en_US/earl_xml.tmpl
new file mode 100644
index 0000000..c5a9710
--- /dev/null
+++ b/share/templates/en_US/earl_xml.tmpl
@@ -0,0 +1,54 @@
+Content-Type: application/rdf+xml; charset=UTF-8
+X-W3C-Validator-Status: <TMPL_VAR NAME="valid_status">
+X-W3C-Validator-Errors: <TMPL_VAR NAME="number_of_errors">
+
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns="http://www.w3.org/2001/03/earl/1.0-test#"
+ xmlns:val="http://validator.w3.org/this_will_change/do_not_rely_on_it!">
+
+ <Assertor rdf:about="http://validator.w3.org/">
+ <name>W3 Validator</name>
+ <contactInfo rdf:resource="http://validator.w3.org/about.html"/>
+ <testMode rdf:resource="http://www.w3.org/2001/03/earl/1.00#Auto" />
+
+<TMPL_IF NAME="VALID">
+ <asserts>
+ <Assertion>
+ <subject rdf:resource="<TMPL_VAR NAME="file_uri" ESCAPE="HTML">" />
+ <result rdf:resource="http://www.w3.org/2001/03/earl/1.00#passes" />
+ <testCase rdf:resource="http://www.w3.org/MarkUp/" />
+ <note>Valid!</note>
+ </Assertion>
+ </asserts>
+<TMPL_ELSE>
+
+ <asserts>
+ <Assertion rdf:ID="result">
+ <subject rdf:resource="<TMPL_VAR NAME="file_uri" ESCAPE="HTML">" />
+ <result rdf:resource="http://www.w3.org/2001/03/earl/1.00#fails" />
+ <testCase rdf:resource="http://www.w3.org/MarkUp/" />
+ <note>Invalid!</note>
+ </Assertion>
+ </asserts>
+
+<TMPL_LOOP NAME="file_errors">
+ <asserts>
+ <Assertion rdf:ID="err<TMPL_VAR NAME="__counter__" ESCAPE="HTML">">
+ <subject rdf:parseType="Resource">
+ <reprOf rdf:resource="<TMPL_VAR NAME="file_uri" ESCAPE="HTML">"/>
+ <val:line><TMPL_VAR NAME="line" ESCAPE="HTML"></val:line>
+ <val:column><TMPL_VAR NAME="char" ESCAPE="HTML"></val:column>
+ </subject>
+ <result rdf:resource="http://www.w3.org/2003/03/earl/1.00#fails" />
+ <testCase rdf:resource="http://www.w3.org/Markup/" />
+ <note><TMPL_VAR NAME="msg" ESCAPE="HTML"></note>
+ </Assertion>
+ </asserts>
+</TMPL_LOOP>
+</TMPL_IF>
+
+ </Assertor>
+</rdf:RDF>
+
diff --git a/share/templates/en_US/xml_output.tmpl b/share/templates/en_US/xml_output.tmpl
new file mode 100644
index 0000000..b55d476
--- /dev/null
+++ b/share/templates/en_US/xml_output.tmpl
@@ -0,0 +1,69 @@
+Content-Type: application/xml; charset=UTF-8
+X-W3C-Validator-Status: <TMPL_VAR NAME="valid_status">
+X-W3C-Validator-Errors: <TMPL_VAR NAME="number_of_errors">
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ FIXME: text/xsl is not a registered media type
+-->
+<?xml-stylesheet type="text/xsl" href="xml-results.xsl"?>
+
+<!--
+ This interface is highly experimental and the output *will* change
+ (probably even several times) before finished. Do *not* rely on it!
+ See http://validator.w3.org/docs/users.html#api-warning
+-->
+
+<!DOCTYPE result [
+ <!ELEMENT result (meta, warnings?, messages?)>
+ <!ATTLIST result
+ version CDATA #FIXED '0.9.1'
+ >
+
+ <!ELEMENT meta (uri, modified, server, size, encoding, doctype, errors)>
+ <!ELEMENT uri (#PCDATA)>
+ <!ELEMENT modified (#PCDATA)>
+ <!ELEMENT server (#PCDATA)>
+ <!ELEMENT size (#PCDATA)>
+ <!ELEMENT encoding (#PCDATA)>
+ <!ELEMENT doctype (#PCDATA)>
+ <!ELEMENT errors (#PCDATA)>
+
+ <!ELEMENT warnings (warning)+>
+ <!ELEMENT warning (#PCDATA)>
+
+ <!ELEMENT messages (msg)*>
+ <!ELEMENT msg (#PCDATA)>
+ <!ATTLIST msg
+ line CDATA #IMPLIED
+ col CDATA #IMPLIED
+ offset CDATA #IMPLIED
+ >
+]>
+
+<result>
+ <meta>
+ <uri><TMPL_VAR NAME="file_uri" ESCAPE="HTML"></uri>
+ <modified><TMPL_VAR NAME="file_modified" ESCAPE="HTML"></modified>
+ <server><TMPL_VAR NAME="file_server" ESCAPE="HTML"></server>
+ <size><TMPL_VAR NAME="file_size" ESCAPE="HTML"></size>
+ <encoding><TMPL_VAR NAME="file_charset" ESCAPE="HTML"></encoding>
+ <doctype><TMPL_VAR NAME="file_doctype" ESCAPE="HTML"></doctype>
+ <errors><TMPL_VAR NAME="number_of_errors" ESCAPE="HTML"></errors>
+ </meta>
+
+ <warnings>
+<TMPL_LOOP NAME="file_warnings">
+ <warning><TMPL_VAR NAME="Message" ESCAPE="HTML"></warning>
+</TMPL_LOOP>
+ </warnings>
+
+ <messages>
+<TMPL_LOOP NAME="file_errors">
+ <msg line="<TMPL_VAR NAME="line" ESCAPE="HTML">"
+ col="<TMPL_VAR NAME="char" ESCAPE="HTML">"
+ ><TMPL_VAR NAME="msg" ESCAPE="HTML"></msg>
+</TMPL_LOOP>
+ </messages>
+
+</result>