/[cvs]/nfo/perl/libs/XML/XUpdate/XSLT.pm
ViewVC logotype

Diff of /nfo/perl/libs/XML/XUpdate/XSLT.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Thu May 1 23:40:32 2003 UTC revision 1.5 by joko, Tue May 6 14:24:06 2003 UTC
# Line 7  Line 7 
7  #    $Id$  #    $Id$
8  #  #
9  #    $Log$  #    $Log$
10    #    Revision 1.5  2003/05/06 14:24:06  joko
11    #    doesn't use Carp any more
12    #    updated pod
13    #    attempt to rewrite xml to make it more human readable using helper modules from CPAN (node indentation, etc.)
14    #
15  #    Revision 1.4  2003/05/01 23:40:32  joko  #    Revision 1.4  2003/05/01 23:40:32  joko
16  #    minor update: commented debugging part  #    minor update: commented debugging part
17  #  #
# Line 25  Line 30 
30    
31  =head1 NAME  =head1 NAME
32    
33  XML::XUpdate::XSLT - A perl module for updating xml documents using XUpdate via XSLT.    XML::XUpdate::XSLT - A perl module for updating xml documents using XUpdate via XSLT.
34    
35    
36  =head3 Overview  =head3 Overview
# Line 63  XML::XUpdate::XSLT - A perl module for u Line 68  XML::XUpdate::XSLT - A perl module for u
68        
69    Q: Can we mimic/use the interface of the - already established - 'xupdate' program???    Q: Can we mimic/use the interface of the - already established - 'xupdate' program???
70        
71    Q: Should we follow the CRUD path first? (CRUD means: Create, Retrieve, Update, Delete)    Q: Should we follow the CRUD path first?
72          (CRUD is the acronym for the datastore action primitives: Create, Retrieve, Update, Delete)
73    S?: Proposal: XML::XUpdate::XSLT::API uses XML::XUpdate::XSLT::CRUD    S?: Proposal: XML::XUpdate::XSLT::API uses XML::XUpdate::XSLT::CRUD
74    
75    
# Line 72  XML::XUpdate::XSLT - A perl module for u Line 78  XML::XUpdate::XSLT - A perl module for u
78    o What about proper encoding? (ISO-8859-1 or UTF-8)    o What about proper encoding? (ISO-8859-1 or UTF-8)
79    o Is it possible to create the required "xsl_template.xml" at runtime via XSL itself?    o Is it possible to create the required "xsl_template.xml" at runtime via XSL itself?
80    o Cache contents of external files (*.xml). Performance!    o Cache contents of external files (*.xml). Performance!
81      o Can exception / error-code handling be improved somehow?
82          Esp.: It would be interesting, if the XUpdate payload actually could be applied, or not...
83        
84    
85  =cut  =cut
# Line 84  package XML::XUpdate::XSLT; Line 92  package XML::XUpdate::XSLT;
92  use strict;  use strict;
93  use warnings;  use warnings;
94    
 use XML::XSLT 0.41;  
 use Carp;  
 use File::Basename;  
95  use Data::Dumper;  use Data::Dumper;
96    use File::Basename;
97    use XML::XSLT 0.41;
98    use XML::XUpdate::Rewrite;
99    
100  # Namespace constants  # Namespace constants
101    
# Line 145  sub open_document { Line 153  sub open_document {
153  sub open_xupdate {  sub open_xupdate {
154    my $self = shift;    my $self = shift;
155    my $xml = shift;    my $xml = shift;
156    # FIXME: check for filename, filehandle and URL (etc.)    # FIXME: check for filename, filehandle and U<RL (etc.)
157    $self->{XML}->{xupdate} = $xml;    $self->{XML}->{xupdate} = $xml;
158  }  }
159    
# Line 156  sub process { Line 164  sub process {
164  }  }
165    
166  # First, translate the xupdate payload to xsl.  # First, translate the xupdate payload to xsl.
167  # FIXME: do DOM only!  # FIXME: do DOM only! (don't use "->toString")
168  sub _calculate {  sub _calculate {
169    my $self = shift;    my $self = shift;
170    $self->{XSLT_ENGINE_PREP} = XML::XSLT->new(    $self->{XSLT_ENGINE_PREP} = XML::XSLT->new(
# Line 190  sub _apply { Line 198  sub _apply {
198        
199  sub toString {  sub toString {
200    my $self = shift;    my $self = shift;
201    return $self->{XML}->{result};    
202      # use rest of argument list as hash of option values
203      my $options = {@_};
204      
205      # short circuit - just return what we have - don't modify anything
206      return $self->{XML}->{result} unless $options and $options->{rewrite};
207      
208      # Rewrite the xml document with certain engine to desired style.
209      # 'engine' defaults to "XMLParser" if not specified.
210      my $rewrite = XML::XUpdate::Rewrite->new( style => $options->{mode}, engine => $options->{using} );
211      $rewrite->set_document( $self->{XML}->{result} );
212      # TODO: Implement a configurable fallback here to return the un-rewritten payload if desired.
213      $rewrite->process() or die(__PACKAGE__ . ": Error while rewriting XML document.");
214      return $rewrite->get_document();
215  }  }
216    
217    
218  ######################################################################  ######################################################################
219  # AUXILIARY METHODS  # AUXILIARY METHODS
220    
221  # Argument parsing (with backwards compatibility hook).  # Argument list parsing.
222    # ... from XML::XUpdate::LibXML (w/o backwards compatibility hook).
223    # Could this make up a Class::AutoFill::__read_arglist which transparently
224    # makes object attributes from constructor arguments in a configurable way?
225  sub __parse_args {  sub __parse_args {
226    my $self = shift;    my $self = shift;
227    my %args;    my %args;
228    
229    if(@_ % 2 ) {    if ( @_ % 2 ) {
230      $args{dummy} = shift;      $args{dummy} = shift;
231      %args = (%args, @_);      %args = (%args, @_);
232    } else {    } else {
# Line 228  sub __slurp_file { Line 252  sub __slurp_file {
252    if (! -e $filename) {    if (! -e $filename) {
253      $filename = dirname(__FILE__) . "/$filename";      $filename = dirname(__FILE__) . "/$filename";
254      if (! -e $filename) {      if (! -e $filename) {
255        croak("File $filename does not exist.");        die("File $filename does not exist.");
256      }      }
257    }    }
258        

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed