1 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
2 |
## $Id$ |
## $Id$ |
3 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.5 2003/05/13 08:06:13 joko |
6 |
|
## filled "sub sendQuery": query xml document via XPath |
7 |
|
## |
8 |
|
## Revision 1.4 2003/02/11 05:17:24 joko |
9 |
|
## + fix: childnode metadata now gets set propery |
10 |
|
## |
11 |
|
## Revision 1.3 2003/01/19 03:15:43 joko |
12 |
|
## + modified header |
13 |
|
## |
14 |
|
## Revision 1.2 2003/01/19 02:14:11 joko |
15 |
|
## + proposal for more abstract filesystem-query-interface |
16 |
|
## |
17 |
## Revision 1.1 2002/12/03 15:52:53 joko |
## Revision 1.1 2002/12/03 15:52:53 joko |
18 |
## + initial check-in |
## + initial check-in |
19 |
## |
## ------------------------------------------------------------------------ |
|
## -------------------------------------------------------------------------------- |
|
20 |
|
|
21 |
|
|
22 |
package Data::Storage::Handler::Files; |
package Data::Storage::Handler::Files; |
28 |
|
|
29 |
use Data::Dumper; |
use Data::Dumper; |
30 |
#use Data::Storage::Result::Files; |
#use Data::Storage::Result::Files; |
31 |
|
use Data::Storage::Result::Hash; |
32 |
|
|
33 |
# get logger instance |
# get logger instance |
34 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
55 |
#print "======\n"; |
#print "======\n"; |
56 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
57 |
#print Dumper($self->{locator}); |
#print Dumper($self->{locator}); |
58 |
|
my @keys = keys %{$self->{locator}->{files}}; |
59 |
|
$self->{meta}->{childnodes} = \@keys; |
60 |
return $self->{locator}->{files}; |
return $self->{locator}->{files}; |
61 |
} |
} |
62 |
|
|
66 |
return $self->{locator}->{files}->{$name}; |
return $self->{locator}->{files}->{$name}; |
67 |
} |
} |
68 |
|
|
69 |
|
# Query xml file by default. |
70 |
|
# FIXME: Move most code one level deeper into Data::Storage::Handler::XML. |
71 |
|
sub sendQuery { |
72 |
|
# transform query to searchrules |
73 |
|
# addSearchRule( ... ) |
74 |
|
# addSearchRule( ... ) |
75 |
|
# addSearchRule( ... ) |
76 |
|
# runSearch( ... ) |
77 |
|
# returnSearchResult( ... ) |
78 |
|
|
79 |
|
my $self = shift; |
80 |
|
my $query = shift; |
81 |
|
|
82 |
|
print __PACKAGE__ . ": sendQuery(" . Dumper($query) . ")"; |
83 |
|
|
84 |
|
my $file = $query->{node}; |
85 |
|
# NEW [2003-04-23]: DataItem compatibility |
86 |
|
$file ||= $query->{options}->{GUID}; |
87 |
|
|
88 |
|
if (!$file) { |
89 |
|
print "Filename was empty!", "\n"; |
90 |
|
return; |
91 |
|
} |
92 |
|
|
93 |
|
# --- from OEF::YAA::Jobs --- |
94 |
|
# issue the query |
95 |
|
|
96 |
|
# V1 - from YAA::Xyz, hardcoded, won't work here |
97 |
|
#my $xpq = "*/target[\@name=\"$name\"]"; |
98 |
|
|
99 |
|
# V2 - more generic: XPath query builder (three way fallback) |
100 |
|
my $xpq; |
101 |
|
|
102 |
|
$xpq = $query->{options}->{filter}->{xpq} if ref $query->{options}->{filter}; |
103 |
|
|
104 |
|
# map a GUID to a xml-name attribute which is searched anywhere ('*/*') |
105 |
|
#$xpq = '*/' . $query->{options}->{GUID} if (!$xpq && $query->{options}->{GUID}); |
106 |
|
$xpq = '*/*[@name="' . $query->{options}->{GUID} . '"]' if (!$xpq && $query->{options}->{GUID}); |
107 |
|
|
108 |
|
$xpq = '*' if !$xpq; |
109 |
|
#print "xpq: $xpq", "\n"; |
110 |
|
|
111 |
|
#$xpq = '*/source/select[@key="SOC"]'; |
112 |
|
# decode somehow(?) special escaped quote (") which could reach us as (e.g.): |
113 |
|
# 'xpq' => '*[@key=\\"SOC\\"]' |
114 |
|
$xpq =~ s!\\"!"!g; |
115 |
|
|
116 |
|
my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); |
117 |
|
$mdbe->sendQuery($xpq); |
118 |
|
|
119 |
|
# V1 - first attempts |
120 |
|
#my $subtree = $mdbe->toSimpleTree(); |
121 |
|
|
122 |
|
# V2 - will cause major behavior change in result! |
123 |
|
$mdbe->circumflex('result'); |
124 |
|
my $subtree = $mdbe->toEasyTree(); |
125 |
|
$subtree = $subtree->{content}->[0]; |
126 |
|
# --- from OEF::YAA::Jobs --- |
127 |
|
|
128 |
|
# V1 - direct mode |
129 |
|
print "subtree: " . Dumper($subtree); |
130 |
|
#return $subtree; |
131 |
|
|
132 |
|
#print Dumper($query); |
133 |
|
print "xpq: $xpq", "\n"; |
134 |
|
|
135 |
|
# V2 - wrapped via a result object providing a more generic api to e.g. iterate through items |
136 |
|
my $result = Data::Storage::Result::Hash->new( RESULTHANDLE => $subtree ); |
137 |
|
return $result; |
138 |
|
|
139 |
|
} |
140 |
|
|
141 |
|
sub addSearchRule { |
142 |
|
|
143 |
|
} |
144 |
|
|
145 |
|
sub runSearch { |
146 |
|
|
147 |
|
} |
148 |
|
|
149 |
1; |
1; |
150 |
|
__END__ |