
XML::Filter::XML_Directory_2XHTML - SAX2 filter for munging XML::Directory::SAX output into XHTML

use strict;
package MySAX;
use base qw (XML::SAX::Base);
use Image::Magick;
sub parse_uri {
my $self = shift;
my $uri = shift;
my $magick = Image::Magick->new();
if (my $err = $magick->Read($uri)) {
carp $err;
return 0;
}
if (my $comment = $magick->Get("comment")) {
$self->SUPER::start_element({Name=>"p"});
$self->SUPER::characters({Data=>$comment});
$self->SUPER::end_element({Name=>"p"});
}
return 1;
}
package main;
use IO::File;
use XML::SAX::Writer;
use XML::Directory::SAX;
use XML::Filter::XML_Directory_2XHTML;
my $file = IO::File->new(">/htdocs/myimages/index.html");
my $writer = XML::SAX::Writer->new(Output=>$file);
my $filter = XML::Filter::XML_Directory_2XHTML->new(Handler=>$writer);
$filter->set_encoding("ISO-8858-1");
# As Canadian as possible, under the circumstances
$filter->set_lang("en-ca");
# Define some images to associate with directory listing.
$filter->set_images({
# Some defaults
directory => {src=>"/icons/dir.gif",height=>20,width=>20},
file => {src=>"/icons/unknown.gif",height=>20,width=>20},
# An image for a file whose media type
# as defined by MIME::Types is 'image'.
# This is the case for .pl and .pm files
image => {src=>"/icons/image3.gif",height=>20,width=>20},
});
# This package inherits from XML::Filter::XML_Directory_2::Base
# which defines a framework for defining event based callbacks
# and handlers.
$filter->set_callbacks({
link => sub { return "file://".$_[0]; },
# This is not the greatest example because
# this is actually what the linktext is set
# to if no 'linktext' callback or handler is
# defined but you get the idea.
linktext => sub { return &basename($_[0]); },
title => sub { return "woot woot woot"; },
});
$filter->set_handlers({
file => MySAX::File->new(Handler=>$writer),
});
# In turn, XML::Filter::XML_Directory_2::Base inherits from
# XML::Filter::XML_Directory_Pruner which provides hooks for
# restricting the output of XML::Directory::SAX
$filter->exclude(ending=>[".html"]);
my $directory = XML::Directory::SAX->new(depth=>0,detail=>2,Handler=>$filter);
$directory->order_by("a");
$directory->parse_dir("/htdocs/myimages");

SAX2 filter for munging XML::Directory::SAX output into XHTML.

This package allows for the following event callbacks and/or handlers to be registered:
Since this functionaliy is inherited from XML::Filter::XML_Directory_2::Base, please consult the documentation for that package for details.
Modify the linktext for the current document. The default value is the filename itself.
Define additional output to follow the name of the current file.
Define additional output to follow the name of the current directory.
Modify the value of the HTML a@href attribute for the current document. The default value is the absolute path of the document itself.
Modify the linktext for the current document. The default value is the filename itself.
Set the value of the HTML <title> element for your document. The default is the absolute path of the directory you are parsing.
Define additional output to follow the name of the current file.
Define additional output to follow the name of the current directory.

Each directory and file in the XML::Directory output is wrapped in HTML <div> elements. Each element is assigned a class attributes whose name matches the type of file, either a file or directory.
The default CSS styles for those classes are :
.file {
border:1px dotted #ccc;
margin-left:10px;
margin-bottom:5px;
margin-top:5px;
padding-right:50px;
}
.directory {
border:1px dotted #666;
margin-left:10px;
margin-bottom:10px;
}
.thumbnail { display: inline; }
They can be altered by passing a user-defined CSS stylesheet via the filter's set_styles object method. You may also use the set_style method to override the default and assign styles via the HTML <style> element.
Example HTML output:
<div class = "(file|directory)" id = "..."> <div class = "thumbnail"> <img src = "..." /> </div> <a href = "...">Hello World picture</a> </div>

Object constructor. Returns an object. Woot!
Set the language code to be assigned to the <html@xml:lang> and <html@lang> attributes.
Define image files to be included with a file or a directory.
Valid arguments are a hash ref whose key may be :
Each key defines a value which is also a hash reference whose keys are :
String. Required.
Int. Required.
Int. Required.
String.
Alternately, you may pass a code reference as the key value. If you do, your code reference wil be passed the absolute path of the current file as the first, and only, argument.
Your code reference should return a hash reference whose key/value pairs are the same as those outlined above.
Define additional stylesheets for your document.
Valid arguments are an array reference of hash reference. Each hash ref may contain the following keys:
String. Required.
String. Default is "stylesheet"
String. Default is "all"
You may use this method to override the default styles altogether without also assigning remote stylesheets.
$pkg->set_style(\qq(.file{ border:2px dotted pink};));
Define scripts for your document.
Valid arguments are an array reference of hash reference. Each hash ref may contain the following keys:
String. Required.
Please consults the docs for XML::Filter::XML_Directory_2::Base for details
Please consults the docs for XML::Filter::XML_Directory_2::Base for details

1.3.1

July 22, 2002

Aaron Straup Cope


XML::Filter::XML_Directory_2::Base

Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.