/[cvs]/nfo/perl/libs/Data/Storage/Handler/Files.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Storage/Handler/Files.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Tue May 13 08:06:13 2003 UTC (21 years, 1 month ago) by joko
Branch: MAIN
Changes since 1.4: +69 -1 lines
filled "sub sendQuery": query xml document via XPath

1 joko 1.3 ## ------------------------------------------------------------------------
2 joko 1.5 ## $Id: Files.pm,v 1.4 2003/02/11 05:17:24 joko Exp $
3 joko 1.3 ## ------------------------------------------------------------------------
4 joko 1.2 ## $Log: Files.pm,v $
5 joko 1.5 ## Revision 1.4 2003/02/11 05:17:24 joko
6     ## + fix: childnode metadata now gets set propery
7     ##
8 joko 1.4 ## Revision 1.3 2003/01/19 03:15:43 joko
9     ## + modified header
10     ##
11 joko 1.3 ## Revision 1.2 2003/01/19 02:14:11 joko
12     ## + proposal for more abstract filesystem-query-interface
13     ##
14 joko 1.2 ## Revision 1.1 2002/12/03 15:52:53 joko
15     ## + initial check-in
16 joko 1.3 ## ------------------------------------------------------------------------
17 joko 1.1
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 joko 1.5 use Data::Storage::Result::Hash;
29 joko 1.1
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 joko 1.4 my @keys = keys %{$self->{locator}->{files}};
56     $self->{meta}->{childnodes} = \@keys;
57 joko 1.1 return $self->{locator}->{files};
58     }
59    
60     sub getFileByName {
61     my $self = shift;
62     my $name = shift;
63     return $self->{locator}->{files}->{$name};
64 joko 1.2 }
65    
66 joko 1.5 # Query xml file by default.
67     # FIXME: Move most code one level deeper into Data::Storage::Handler::XML.
68 joko 1.2 sub sendQuery {
69     # transform query to searchrules
70     # addSearchRule( ... )
71     # addSearchRule( ... )
72     # addSearchRule( ... )
73     # runSearch( ... )
74     # returnSearchResult( ... )
75 joko 1.5
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 joko 1.2 }
137    
138     sub addSearchRule {
139    
140     }
141    
142     sub runSearch {
143    
144 joko 1.1 }
145    
146     1;
147 joko 1.5 __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed