--- nfo/perl/libs/Data/Storage/Handler/Files.pm 2002/12/03 15:52:53 1.1 +++ nfo/perl/libs/Data/Storage/Handler/Files.pm 2003/05/13 16:34:26 1.6 @@ -1,11 +1,25 @@ -## -------------------------------------------------------------------------------- -## $Id: Files.pm,v 1.1 2002/12/03 15:52:53 joko Exp $ -## -------------------------------------------------------------------------------- +## ------------------------------------------------------------------------ +## $Id: Files.pm,v 1.6 2003/05/13 16:34:26 joko Exp $ +## ------------------------------------------------------------------------ ## $Log: Files.pm,v $ +## Revision 1.6 2003/05/13 16:34:26 joko +## don't use GUID when building xpq filter +## +## 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 +## +## Revision 1.3 2003/01/19 03:15:43 joko +## + modified header +## +## Revision 1.2 2003/01/19 02:14:11 joko +## + proposal for more abstract filesystem-query-interface +## ## Revision 1.1 2002/12/03 15:52:53 joko ## + initial check-in -## -## -------------------------------------------------------------------------------- +## ------------------------------------------------------------------------ package Data::Storage::Handler::Files; @@ -17,6 +31,7 @@ use Data::Dumper; #use Data::Storage::Result::Files; +use Data::Storage::Result::Hash; # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -43,6 +58,8 @@ #print "======\n"; $logger->debug( __PACKAGE__ . "->getChildNodes()" ); #print Dumper($self->{locator}); + my @keys = keys %{$self->{locator}->{files}}; + $self->{meta}->{childnodes} = \@keys; return $self->{locator}->{files}; } @@ -52,4 +69,85 @@ 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( ... ) + # addSearchRule( ... ) + # 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 { + +} + +sub runSearch { + +} + 1; +__END__