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