You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@apache.org on 2004/05/20 20:40:44 UTC
cvs commit: xml-axkit/lib/Apache/AxKit PipeCtrl.pm
mach 2004/05/20 11:40:44
Modified: lib/Apache/AxKit Tag: axkit-pipeline-2 PipeCtrl.pm
Log:
extract styles, and hiding pipeline internals from outsidee
Revision Changes Path
No revision
No revision
1.1.2.6 +132 -39 xml-axkit/lib/Apache/AxKit/Attic/PipeCtrl.pm
Index: PipeCtrl.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Attic/PipeCtrl.pm,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- PipeCtrl.pm 10 Dec 2003 22:48:53 -0000 1.1.2.5
+++ PipeCtrl.pm 20 May 2004 18:40:44 -0000 1.1.2.6
@@ -13,6 +13,7 @@
sub new{
my $class = shift;
+
my $self = {
pre_styles => [],
post_styles => [],
@@ -52,8 +53,28 @@
return $self;
}
+sub send{
+ my ( $self, $r, $provider ) = @_;
+ return $self->create_pipeline($r, $provider, 0)->send( $r );
+}
+
+sub get_subrequest_ref{
+ my ( $self, $r, $provider ) = @_;
+ return $self->create_pipeline($r, $provider, 1)->get_strref( $r );
+}
+
+
+
sub create_pipeline{
- my ($self, $r, $provider, $lastinchain) = @_;
+ my ($self, $r, $provider, $no_output) = @_;
+
+ my $styles = $self->extract_styles($r, $provider);
+
+ $self->add_styles( @$styles );
+
+ my ($transformer, $doit) = AxKit::get_output_transformer();
+
+ my $lastinchain = !($no_output || $doit || lc($r->dir_config('Filter')) eq 'on' );
# Add any pre/post defined styles into main styles list.
@@ -129,8 +150,6 @@
if($lastinchain) {
unless( $pipeline->output_binary() ) {
-
- my ($transformer, $doit) = AxKit::get_output_transformer();
if( $doit ) {
AxKit::Debug(4, "PipeCtrl: adding Output Transformer");
@@ -155,14 +174,8 @@
return scalar @{shift->{'pre_styles'}};
}
-sub create_pre_pipeline{
- my ($self, $r, $provider) = @_;
-
- AxKit::Debug(3, "PipeCtrl: Creating pre-styles pipeline");
-
- my @styles = @{$self->{'pre_styles'}};
- $self->{'pre_styles'} = [];
-
+sub _create_pipeline{
+ my ( $self, $r, $provider, @styles ) = @_;
my $i = 1;
foreach (@styles) {
$_->{'stage'} = $i++;
@@ -187,6 +200,17 @@
$pipeline->pipeline_init($r);
return $pipeline;
+}
+
+sub create_pre_pipeline{
+ my ($self, $r, $provider) = @_;
+
+ AxKit::Debug(3, "PipeCtrl: Creating pre-styles pipeline");
+
+ my @styles = @{$self->{'pre_styles'}};
+ $self->{'pre_styles'} = [];
+
+ return $self->_create_pipeline( $r, $provider, @styles );
}
sub create_post_pipeline{
@@ -196,34 +220,7 @@
my @styles = @{$self->{'post_styles'}};
$self->{'post_styles'} = [];
-
- my $i = 1;
- foreach (@styles) {
- $_->{'stage'} = $i++;
- }
-
- unshift(@styles, {
- module => 'Apache::AxKit::Pipeline::Head',
- href => undef,
- });
-
-
- my $pipeline = $provider;
-
- foreach my $style ( @styles ) {
- $pipeline = $self->create_processor($r, $style )->upstream($pipeline);
-
- if($pipeline->enable_dynamic_styles()) {
- $pipeline = Apache::AxKit::Pipeline::DoStyles->new()->upstream( $pipeline );
- }
-
- }
-
- AxKit::Debug(4, "PipeCtrl: Running Initialisation phase");
- $pipeline->pipeline_init($r);
-
- return $pipeline;
-
+ return $self->_create_pipeline( $r, $provider, @styles );
}
sub create_processor{
@@ -248,6 +245,102 @@
);
}
+
+sub extract_styles{
+ my ($self, $r, $provider) = @_;
+
+ # get preferred stylesheet and media type
+ my ($preferred, $media) = AxKit::get_style_and_media();
+ AxKit::Debug(2, "media: $media, preferred style: $preferred");
+
+ my $key = Apache::AxKit::Cache->new($r, $provider->key() .
+ ($r->path_info() || ''), $preferred, $media )->key();
+
+ AxKit::Debug(2, "getting styles and external entities from the XML");
+ # get styles/ext_ents from cache or re-parse
+
+ if (exists($AxKit::Stash{$key}) && !$provider->has_changed($AxKit::Stash{$key}{mtime}))
+ {
+ AxKit::Debug(3, "styles cached");
+ return $AxKit::Stash{$key}{'styles'};
+ }
+ else {
+ AxKit::Debug(3, "styles not cached - calling \$provider->get_styles()");
+
+ if ($preferred eq '#default') {
+ undef $preferred;
+ }
+
+ my @styles;
+
+ # need to extract the following from the XML file:
+ # DocType Public Identifier
+ # DTD filename
+ # Root element name (including namespace)
+ # use three element array @$vals
+ if( $AxKit::Cfg->IfAxAddFooProcessors($media, $preferred) || ! $AxKit::Cfg->IgnoreStylePI()) {
+
+ my ($doctype, $dtd, $root, $xml_styles) = $provider->get_xml_info( $media, $preferred );
+
+ foreach my $style (@$xml_styles) {
+ $style->{title} ||= '#default';
+ }
+
+ # Let GetMatchingProcessors to process the @$styles array
+ {
+ local $^W; # suppress "Use of uninitialized value" warnings
+ AxKit::Debug(4, "Calling GetMatchingProcessors with ($media, $preferred, $doctype, $dtd, $root)");
+ }
+ @styles = $AxKit::Cfg->GetMatchingProcessors($media, $preferred, $doctype, $dtd, $root, $xml_styles, $provider);
+ } else{
+ {
+ local $^W; # suppress "Use of uninitialized value" warnings
+ AxKit::Debug(4, "No AxAdd*Processors detected, bypassing get_styles()");
+ AxKit::Debug(4, "Calling GetMatchingProcessors with ($media, $preferred).");
+ }
+
+ @styles = $AxKit::Cfg->GetMatchingProcessors($media, $preferred, undef, undef, undef, [], $provider);
+
+ }
+ if (!@styles) {
+ throw Apache::AxKit::Exception::Declined( reason => sprintf("No styles defined for '%s'", $provider->key() ));
+ }
+
+ # get mime-type => module mapping
+ my $style_mapping = $AxKit::Cfg->StyleMap;
+
+ AxKit::Debug(3, "get_styles: loading style modules");
+ for my $style (@styles) {
+ my $mapto;
+ AxKit::Debug(4, "get_styles: looking for mapping for style type: '$style->{type}'");
+ if (!( $mapto = $style_mapping->{ $style->{type} } )) {
+ throw Apache::AxKit::Exception::Declined(
+ reason => "No implementation mapping available for type '$style->{type}'"
+ );
+ }
+
+ $style->{module} = $mapto;
+
+ # first load module if it's not already loaded.
+ eval {
+ AxKit::load_module($mapto);
+ };
+ if ($@) {
+ throw Apache::AxKit::Exception::Error(
+ -text => "Load of '$mapto' failed with: $@"
+ );
+ }
+ }
+
+ $AxKit::Stash{$key} = {
+ styles => \@styles,
+ mtime => $provider->mtime(),
+ } unless $r->dir_config('AxDisableGetStylesCache');
+
+ return \@styles;
+ }
+}
+