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