XML-CompareML / lib / XML / CompareML / HTML.pm

package XML::CompareML::HTML;

use strict;
use warnings;

use Carp;
use File::Spec;

use CGI ();
use XML::LibXSLT;

use XML::CompareML::ConfigData;

use base 'XML::CompareML::Base';

__PACKAGE__->mk_accessors(qw(
    _data_dir
    _xml_parser
    _stylesheet
    ));

sub _initialize
{
    my $self = shift;

    $self->SUPER::_initialize(@_);

    my (%args) = (@_);

    my $data_dir = $args{'data_dir'} ||
        XML::CompareML::ConfigData->config('extradata_install_path')->[0];

    $self->_data_dir($data_dir);

    $self->_xml_parser(XML::LibXML->new());

    my $xslt = XML::LibXSLT->new();

    my $style_doc = $self->_xml_parser()->parse_file(
            File::Spec->catfile(
                $self->_data_dir(), 
                "compare-ml.xslt"
            ),
        );

    $self->_stylesheet($xslt->parse_stylesheet($style_doc));

    return 0;
}

=head2 $to-html->process()

Do the actual processing using the XSLT stylesheet.

=cut 

sub process
{
    my ($self, $args) = @_;

=begin RELAX_NG_VALIDATION

    my $ret_code;

    eval
    {
        $ret_code = $self->_rng()->validate($source_dom);
    };

    if (defined($ret_code) && ($ret_code == 0))
    {
        # It's OK.
    }
    else
    {
        confess "RelaxNG validation failed [\$ret_code == $ret_code ; $@]";
    }

=end RELAX_NG_VALIDATION

=cut

    my $stylesheet = $self->_stylesheet();

    my $results = $stylesheet->transform($self->dom());

    print {*{$self->{o}}} $stylesheet->output_string($results);

    return 0;
}

=head1 NAME

XML::CompareML::HTML - convert CompareML to XHTML

=head1 SYNOPSIS

See L<XML::CompareXML>.

=head1 METHODS

=cut

=head2 $converter->gen_systems_list({output_handle => \*STDOUT})

Generates a list of li's with links to the systems, not unlike:

L<http://better-scm.berlios.de/comparison/>

=cut

sub gen_systems_list
{
    my ($self, %args) = @_;

    my $fh = $args{output_handle};

    my @implementations = $self->_findnodes("/comparison/meta/implementations/impl");

    foreach my $impl (@implementations)
    {
        my $name = $self->_impl_get_tag_text($impl, "name");
        my $url = $self->_impl_get_tag_text($impl, "url");
        my $fullname = $self->_impl_get_tag_text($impl, "fullname");
        my $vendor = $self->_impl_get_tag_text($impl, "vendor");
        if (!defined($url))
        {
            die "URL not specified for implementation $name.";
        }
        print {$fh} qq{<li><a href="} . CGI::escapeHTML($url) . qq{">} . 
            CGI::escapeHTML(defined($fullname) ? $fullname : $name) . 
            qq{</a>} . (defined($vendor) ? " by $vendor" : "") .
            qq{</li>\n}
            ;
    }
}

=head1 AUTHOR

Shlomi Fish, L<http://www.shlomifish.org/>.

=head1 SEE ALSO

L<XML::CompareML>

=head1 COPYRIGHT AND LICENSE

Copyright 2004, Shlomi Fish. All rights reserved.

You can use, modify and distribute this module under the terms of the MIT X11
license. ( L<http://www.opensource.org/licenses/mit-license.php> ).

=cut

1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.