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