| 1 | package XML::CompareML::HTML; | ||
| 2 | |||
| 3 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 4 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 4 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 4 | ▶ | use CGI (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 4 | ▶ | use XML::LibXSLT; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | |||
| 12 | use XML::CompareML::ConfigData; | ||
| 13 | |||
| 14 | use base 'XML::CompareML::Base'; | ||
| 15 | |||
| 16 | __PACKAGE__->mk_accessors(qw( | ||
| 17 | _data_dir | ||
| 18 | _xml_parser | ||
| 19 | _stylesheet | ||
| 20 | )); | ||
| 21 | |||
| 22 | sub _initialize | ||
| 23 | { | ||
| 24 | my $self = shift; | ||
| 25 | |||
| 26 | $self->SUPER::_initialize(@_); | ||
| 27 | |||
| 28 | my (%args) = (@_); | ||
| 29 | |||
| 30 | my $data_dir = $args{'data_dir'} || | ||
| 31 | XML::CompareML::ConfigData->config('extradata_install_path')->[0]; | ||
| 32 | |||
| 33 | $self->_data_dir($data_dir); | ||
| 34 | |||
| 35 | $self->_xml_parser(XML::LibXML->new()); | ||
| 36 | |||
| 37 | my $xslt = XML::LibXSLT->new(); | ||
| 38 | |||
| 39 | my $style_doc = $self->_xml_parser()->parse_file( | ||
| 40 | File::Spec->catfile( | ||
| 41 | $self->_data_dir(), | ||
| 42 | "compare-ml.xslt" | ||
| 43 | ), | ||
| 44 | ); | ||
| 45 | |||
| 46 | $self->_stylesheet($xslt->parse_stylesheet($style_doc)); | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | =head2 $to-html->process() | ||
| 52 | |||
| 53 | Do the actual processing using the XSLT stylesheet. | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub process | ||
| 58 | { | ||
| 59 | my ($self, $args) = @_; | ||
| 60 | |||
| 61 | =begin RELAX_NG_VALIDATION | ||
| 62 | |||
| 63 | my $ret_code; | ||
| 64 | |||
| 65 | eval | ||
| 66 | { | ||
| 67 | $ret_code = $self->_rng()->validate($source_dom); | ||
| 68 | }; | ||
| 69 | |||
| 70 | if (defined($ret_code) && ($ret_code == 0)) | ||
| 71 | { | ||
| 72 | # It's OK. | ||
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | confess "RelaxNG validation failed [\$ret_code == $ret_code ; $@]"; | ||
| 77 | } | ||
| 78 | |||
| 79 | =end RELAX_NG_VALIDATION | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | my $stylesheet = $self->_stylesheet(); | ||
| 84 | |||
| 85 | my $results = $stylesheet->transform($self->dom()); | ||
| 86 | |||
| 87 | print {*{$self->{o}}} $stylesheet->output_string($results); | ||
| 88 | |||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | =head1 NAME | ||
| 93 | |||
| 94 | XML::CompareML::HTML - convert CompareML to XHTML | ||
| 95 | |||
| 96 | =head1 SYNOPSIS | ||
| 97 | |||
| 98 | See L<XML::CompareXML>. | ||
| 99 | |||
| 100 | =head1 METHODS | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | =head2 $converter->gen_systems_list({output_handle => \*STDOUT}) | ||
| 105 | |||
| 106 | Generates a list of li's with links to the systems, not unlike: | ||
| 107 | |||
| 108 | L<http://better-scm.berlios.de/comparison/> | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | sub gen_systems_list | ||
| 113 | { | ||
| 114 | my ($self, %args) = @_; | ||
| 115 | |||
| 116 | my $fh = $args{output_handle}; | ||
| 117 | |||
| 118 | my @implementations = $self->_findnodes("/comparison/meta/implementations/impl"); | ||
| 119 | |||
| 120 | foreach my $impl (@implementations) | ||
| 121 | { | ||
| 122 | my $name = $self->_impl_get_tag_text($impl, "name"); | ||
| 123 | my $url = $self->_impl_get_tag_text($impl, "url"); | ||
| 124 | my $fullname = $self->_impl_get_tag_text($impl, "fullname"); | ||
| 125 | my $vendor = $self->_impl_get_tag_text($impl, "vendor"); | ||
| 126 | if (!defined($url)) | ||
| 127 | { | ||
| 128 | die "URL not specified for implementation $name."; | ||
| 129 | } | ||
| 130 | print {$fh} qq{<li><a href="} . CGI::escapeHTML($url) . qq{">} . | ||
| 131 | CGI::escapeHTML(defined($fullname) ? $fullname : $name) . | ||
| 132 | qq{</a>} . (defined($vendor) ? " by $vendor" : "") . | ||
| 133 | qq{</li>\n} | ||
| 134 | ; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Shlomi Fish, L<http://www.shlomifish.org/>. | ||
| 141 | |||
| 142 | =head1 SEE ALSO | ||
| 143 | |||
| 144 | L<XML::CompareML> | ||
| 145 | |||
| 146 | =head1 COPYRIGHT AND LICENSE | ||
| 147 | |||
| 148 | Copyright 2004, Shlomi Fish. All rights reserved. | ||
| 149 | |||
| 150 | You can use, modify and distribute this module under the terms of the MIT X11 | ||
| 151 | license. ( L<http://www.opensource.org/licenses/mit-license.php> ). | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | 1; | ||