--- nfo/perl/libs/Data/Storage/Handler/Files.pm 2003/02/11 05:17:24 1.4 +++ nfo/perl/libs/Data/Storage/Handler/Files.pm 2003/05/13 08:06:13 1.5 @@ -1,7 +1,10 @@ ## ------------------------------------------------------------------------ -## $Id: Files.pm,v 1.4 2003/02/11 05:17:24 joko Exp $ +## $Id: Files.pm,v 1.5 2003/05/13 08:06:13 joko Exp $ ## ------------------------------------------------------------------------ ## $Log: Files.pm,v $ +## Revision 1.5 2003/05/13 08:06:13 joko +## filled "sub sendQuery": query xml document via XPath +## ## Revision 1.4 2003/02/11 05:17:24 joko ## + fix: childnode metadata now gets set propery ## @@ -25,6 +28,7 @@ use Data::Dumper; #use Data::Storage::Result::Files; +use Data::Storage::Result::Hash; # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -62,6 +66,8 @@ return $self->{locator}->{files}->{$name}; } +# Query xml file by default. +# FIXME: Move most code one level deeper into Data::Storage::Handler::XML. sub sendQuery { # transform query to searchrules # addSearchRule( ... ) @@ -69,6 +75,67 @@ # addSearchRule( ... ) # runSearch( ... ) # returnSearchResult( ... ) + + my $self = shift; + my $query = shift; + + print __PACKAGE__ . ": sendQuery(" . Dumper($query) . ")"; + + my $file = $query->{node}; + # NEW [2003-04-23]: DataItem compatibility + $file ||= $query->{options}->{GUID}; + + if (!$file) { + print "Filename was empty!", "\n"; + return; + } + + # --- from OEF::YAA::Jobs --- + # issue the query + + # V1 - from YAA::Xyz, hardcoded, won't work here + #my $xpq = "*/target[\@name=\"$name\"]"; + + # V2 - more generic: XPath query builder (three way fallback) + my $xpq; + + $xpq = $query->{options}->{filter}->{xpq} if ref $query->{options}->{filter}; + + # map a GUID to a xml-name attribute which is searched anywhere ('*/*') + #$xpq = '*/' . $query->{options}->{GUID} if (!$xpq && $query->{options}->{GUID}); + $xpq = '*/*[@name="' . $query->{options}->{GUID} . '"]' if (!$xpq && $query->{options}->{GUID}); + + $xpq = '*' if !$xpq; + #print "xpq: $xpq", "\n"; + + #$xpq = '*/source/select[@key="SOC"]'; + # decode somehow(?) special escaped quote (") which could reach us as (e.g.): + # 'xpq' => '*[@key=\\"SOC\\"]' + $xpq =~ s!\\"!"!g; + + my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); + $mdbe->sendQuery($xpq); + + # V1 - first attempts + #my $subtree = $mdbe->toSimpleTree(); + + # V2 - will cause major behavior change in result! + $mdbe->circumflex('result'); + my $subtree = $mdbe->toEasyTree(); + $subtree = $subtree->{content}->[0]; + # --- from OEF::YAA::Jobs --- + + # V1 - direct mode + print "subtree: " . Dumper($subtree); + #return $subtree; + + #print Dumper($query); + print "xpq: $xpq", "\n"; + + # V2 - wrapped via a result object providing a more generic api to e.g. iterate through items + my $result = Data::Storage::Result::Hash->new( RESULTHANDLE => $subtree ); + return $result; + } sub addSearchRule { @@ -80,3 +147,4 @@ } 1; +__END__