1 |
<? |
2 |
/** |
3 |
* This file contains a Data::Lift actor component. |
4 |
* |
5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
* @package org.netfrag.glib |
7 |
* @name Data::Lift::hash::filter::XPath |
8 |
* |
9 |
*/ |
10 |
|
11 |
/** |
12 |
* Cvs-Log: |
13 |
* |
14 |
* $Id: Generic.php,v 1.18 2003/04/11 00:55:49 joko Exp $ |
15 |
* |
16 |
* $Log: Generic.php,v $ |
17 |
* |
18 |
*/ |
19 |
|
20 |
/** |
21 |
* Data::Lift::hash::filter::XPath |
22 |
* |
23 |
* Enriches payload hash with additional key 'xpq'. |
24 |
* |
25 |
* |
26 |
* @author Andreas Motl <andreas.motl@ilo.de> |
27 |
* @copyright (c) 2003 - All Rights reserved. |
28 |
* @license GNU LGPL (GNU Lesser General Public License) |
29 |
* |
30 |
* @link http://www.netfrag.org/~joko/ |
31 |
* @link http://www.gnu.org/licenses/lgpl.txt |
32 |
* |
33 |
* @package org.netfrag.glib |
34 |
* @subpackage DataLift |
35 |
* @name Data::Lift::hash::filter::XPath |
36 |
* |
37 |
* @link http://cvs.netfrag.org/php/libs/org.netfrag.glib |
38 |
* |
39 |
*/ |
40 |
class Data_Lift_hash_filter_XPath { |
41 |
|
42 |
function perform(&$args) { |
43 |
|
44 |
// mode 1: dotted query expression, probably ident |
45 |
if ($dotted = $args[dotted]) { |
46 |
|
47 |
print "dotted: $dotted<br/>"; |
48 |
|
49 |
// extract parts from dotted query string |
50 |
|
51 |
//$parts = split('\.', $dotted); |
52 |
|
53 |
//$args[xpq] = '*/*[@name="cli"]'; |
54 |
if ($parts = split(':', $dotted)) { |
55 |
$node = $parts[0]; |
56 |
$attrib = $parts[1]; |
57 |
} else { |
58 |
$node = $dotted; |
59 |
} |
60 |
|
61 |
$ident = $args[ident]; |
62 |
|
63 |
// check triple |
64 |
$nodeparts = split('\.', $node); |
65 |
|
66 |
/* |
67 |
if (sizeof($nodeparts) == 3) { |
68 |
$attrib = array_pop($nodeparts); |
69 |
$node = join('.', $nodeparts); |
70 |
} else { |
71 |
if ($ident) { |
72 |
$attrib = $ident; |
73 |
unset($ident); |
74 |
} |
75 |
} |
76 |
*/ |
77 |
|
78 |
// FIXME: ??? |
79 |
$chain = array('*'); |
80 |
|
81 |
// FIXME: ??? |
82 |
if ($ident) { |
83 |
array_push($nodeparts, $ident); |
84 |
} |
85 |
|
86 |
for ($i = 0; $i <= sizeof($nodeparts); $i = $i + 2) { |
87 |
$elem = $nodeparts[$i]; |
88 |
if (!$elem) { continue; } |
89 |
array_push($chain, '/' . $elem); |
90 |
if ($elem = $nodeparts[$i + 1]) { |
91 |
array_push($chain, '[@*="' . $elem . '"]'); |
92 |
} |
93 |
} |
94 |
|
95 |
|
96 |
// build xpq string |
97 |
|
98 |
/* |
99 |
// discard 'root' |
100 |
//array_shift($parts); |
101 |
$tmp = str_replace('.', '/', $node); |
102 |
$tmp = str_replace('root', '*', $tmp); |
103 |
$xpq = '*/' . $tmp; |
104 |
|
105 |
//$xpq = '*/*[@name="transfer merge backend to frontend"]'; |
106 |
|
107 |
if ($attrib) { |
108 |
//print "ATTRIB: $attrib<br/>"; |
109 |
$xpq .= '[@*="' . $attrib . '"]'; |
110 |
} |
111 |
|
112 |
if ($ident) { |
113 |
// V1 - valid |
114 |
//$xpq .= '[@name="' . $ident . '"]'; |
115 |
// V2 - ??? |
116 |
//$xpq .= '[@*="' . $ident . '"]'; |
117 |
// V3 |
118 |
$xpq .= "/$ident"; |
119 |
} |
120 |
*/ |
121 |
|
122 |
$xpq = join('', $chain); |
123 |
print "xpq: $xpq<br/>"; |
124 |
|
125 |
// manipulate hashref |
126 |
unset($args[dotted]); |
127 |
unset($args[ident]); |
128 |
$args[xpq] = $xpq; |
129 |
|
130 |
|
131 |
// mode 2: ident only [as of 2003-04-16] |
132 |
// und hier ein smiley für die manu: ;-) |
133 |
} elseif ($args[ident]) { |
134 |
//$args[xpq] = '*/*/' . $args[ident]; |
135 |
//$args[xpq] = '//*/' . $args[ident]; |
136 |
//$args[xpq] = '*//' . $args[ident]; |
137 |
//$args[xpq] = '*/select/*'; |
138 |
//$args[xpq] = '*/*'; |
139 |
//$args[xpq] = '*'; |
140 |
//$args[xpq] = '*/source/select'; |
141 |
$args[xpq] = '*/' . $args[ident]; |
142 |
//$args[xpq] = '*'; |
143 |
//$args[xpq] = '*/source/select'; |
144 |
unset($args[dotted]); |
145 |
unset($args[ident]); |
146 |
} |
147 |
|
148 |
//print Dumper($args); |
149 |
|
150 |
return $args; |
151 |
|
152 |
} |
153 |
|
154 |
} |
155 |
|
156 |
?> |