Apache-XBEL
view release on metacpan or search on metacpan
lib/Apache/XBEL.pm view on Meta::CPAN
if ((stat(__FILE__))[9] > $cache_mtime ) {
$apache->log->debug("Cache is out of sync with handler.");
return ($cache,0);
}
if ((stat($file))[9] > $cache_mtime ) {
$apache->log->debug("Cache is out of sync with XBEL file.");
return ($cache,0);
}
my $xsl_file = $apache->dir_config("XslPath");
if ((stat($xsl_file))[9] > $cache_mtime) {
$apache->log->debug("Cache is out of sync with stylesheet.");
$xsl_stylesheet = $xml_parser->parse_file($xsl_file);
$xsl_transformer = $xsl_parser->parse_stylesheet($xsl_stylesheet);
return ($cache,0);
}
return ($cache,1);
}
sub path2node {
my @path = map { "folder[\@id=\"$_\"]"; } @_;
return join("/","","xbel",@path);
}
sub render_slice {
my $apache = shift;
my $file = shift;
my $doc = shift;
my $node = shift;
#
my $owner = $doc->find(qq(/xbel/info/metadata[\@owner]));
my $ver = $doc->version();
my $enc = $doc->encoding();
my $dom = XML::LibXML::Document->createDocument($ver,$enc);
my $xbel = XML::LibXML::Element->new(qq(xbel));
my $info = XML::LibXML::Element->new(qq(info));
my $meta = XML::LibXML::Element->new(qq(metadata));
$meta->setAttribute("owner",$owner);
my $title = XML::LibXML::Element->new(qq(title));
$title->appendText($doc->find(qq(/xbel/title)));
my $desc = XML::LibXML::Element->new(qq(desc));
$desc->appendText($doc->find(qq(/xbel/desc)));
$info->appendChild($meta);
$xbel->appendChild($title);
$xbel->appendChild($info);
$xbel->appendChild($desc);
# Add support to expand <alias>
# elements here. This is slated
# for version 1.5
$xbel->appendChild($node);
$dom->setDocumentElement($xbel);
#
if (my $fh = &get_fh($apache,$file)) {
# WTF doesn't Apache::File
# have a print method?
print $fh $dom->toString();
undef $dom;
$fh->close();
return 1;
}
return 0;
}
sub get_fh {
my $apache = shift;
my $file = shift;
my $fh = Apache::File->new();
if (! $fh->open(">$file")) {
$apache->log->error("Failed to open $file for writing : $!\n");
return SERVER_ERROR;
}
return &lock_cache($apache,$fh);
}
sub lock_cache {
my $apache = shift;
my $fh = shift;
my $success = 0;
my $tries = 0;
while ($tries++ < 10) {
return $fh if ($success = flock($fh,2));
sleep(1);
}
$apache->log->error("Failed to lock file for writing.");
return undef;
}
# This is here so that, eventually, it can
# be sub-classed.
sub load_file {
return $_[0];
}
=head1 VERSION
1.3
=head1 DATE
$Date: 2004/03/01 21:25:11 $
=head1 AUTHOR
Aaron Straup Cope <ascope@cpan.org>
=head1 SEE ALSO
http://pyxml.sourceforge.net/topics/xbel/
http://aaronland.info/perl/apache/xbel/example/1.3
http://aaronland.info/xsl/xbel/apache-xbel
=head1 NOTES
=over 4
=item *
If you are running this handler on a server that is also running
AxKit, pre version 1.5, Apache::XBEL may periodically fail and
return a server error. Some reports have suggested that reloading
the page may cause the widget to load properly. Or not.
=item *
Hooks for munging outliner documents with Text::Outline have been
removed as of release 1.3. They may come back, at a later date, in
a separate Apache::XBEL::Outline package.
=back
=head1 TO DO
=over 4
=item *
Replace nested 'div' elements with some flavour of nested lists and
de-couple CSS from apache-xbel.xsl. De-couple JavaScript from
apache-xbel.xsl These changes are slated for version 1.4
=item *
Support for expanding <alias> elements. This is slated for version
1.5
=item *
Support for mod_perl 2.0. This is slated for version 2.0
=back
=head1 BUGS
Please report all bugs to : http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache::XBEL
=head1 LICENSE
Copyright (c) 2001-2004 Aaron Straup Cope. All Rights Reserved.
This is free software, you may use it and distribute it under
the same terms as Perl itself.
=cut
return 1;
( run in 1.470 second using v1.01-cache-2.11-cpan-97f6503c9c8 )