/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php

interface STREAMSequenceInterface {
 public function SequenceStart(&$args = NULL);
 public function Start(&$args = NULL);
 public function End();
 public function SequenceEnd();
}

abstract class STREAMHandler extends VIRTUALStreamWriter implements STREAMSequenceInterface, STREAMWriterInterface {
 var $next;
 var $saved_next = false;

 var $object;
 var $flags;

 var $filemode = false;
 
 var $extension;
 
 function __construct(STREAMObjectInterface $object = NULL, STREAMHandler $next = NULL, $flags = 0) {
    $this->object = $object;
    $this->next = $next;
    $this->flags = $flags;
 }
 
 function Connect(STREAMHandler $next) {
    if ($this->next) $this->next->Connect($next);
    else $this->next = $next;

    return $next;
 }
 
 function ConnectFilter(FILTER $object, $flags = 0) {
    return $this->Connect(new STREAMFilter($object, NULL, $flags));
 }

 function ConnectOutput(STREAMObjectInterface $object, $flags = 0) {
    return $this->Connect(new STREAMOutput($object, NULL, $flags));
 }

 function ConnectFileWriter(IO $object, $flags = 0) {
    return $this->Connect(new STREAMFileWriter($object, NULL, $flags));
 }
 
 function SequenceStart(&$args = NULL) {
    if ($this->next) {
	if (($args)&&($args['expected_blocks']===1)) {
	    if ($this->next->flags&STREAM::OPTIONAL) { 
		$ptr = $this->next;
		while ($ptr->flags&STREAM::OPTIONAL) {
		    $filemode = $ptr->filemode;
		    $ptr = $ptr->next;
		}
		
		$filereader = false;
		if ($this->filemode) {
		    if (!$filemode) {
			$filereader = true;
		    }
		} else {
		    if ($filemode) {
			    /* Actually, we need optional filters only before 
			    STREAMOutput to suppress unneccessary grouping.
			    Since it doesn't need filemode predcessor we don't
			    expect such situation and don't want to implement it */
			throw new ADEIException(translate("This filter configuration is not supported yet"));
		    }
		}
		
		$this->saved_next = $this->next;
		if ($filereader) {
		    $this->next = new STREAMFileReader(NULL, $ptr);
		} else {
		    $this->next = $ptr;
		}
		
	    }
	}
	
	if ($this->object) {
	    $this->extension = $this->object->GetExtension();
	    if ($args) {
		if ($args['extension'] != $this->extension) {
		    $new_args = $args;
		    $new_args['extension'] = $this->extension;
		    $args = &$new_args;
		}
	    } else {
		$args = array('extension' => $this->extension);
	    }    
	} else
	    $this->extension = false;

	$this->next->SequenceStart($args);
    }
 }

 function Start(&$args = NULL) {
    if ($this->next) {
	if ($this->extension) {
	    if ($args) {
		if ($args['extension'] != $this->extension) {
		    $new_args = $args;
		    $new_args['extension'] = $this->extension;
		    $args = &$new_args;
		}
	    } else {
		$args = array('extension' => $this->extension);
	    }    
	}
	$this->next->Start($args);
    }
 }

 function End() {
    if ($this->next) $this->next->End();
 }
 
 function SequenceEnd() {
    if ($this->next) {
	$this->next->SequenceEnd();
	
	if ($this->saved_next) {
	    $this->next = $this->saved_next;
	    $this->saved_next = false;
	}
    }
 }

 function WriteData(&$data) {
    if ($this->object)
	$this->object->WriteData($data);
    else if ($this->next)
	$this->next->WriteData($data);
 }
 
 function WriteFile($file) {
    if ($this->object)
	$this->object->WriteFile($file);
    else if ($this->next)
	$this->next->WriteFile($file);
 }
 
 function RequestFilemode() {
    return false;
 }
  
 function GetContentType() {
    if ($this->next) {
	$type = $this->next->GetContentType();
	if ($type) return $type;
    }
    
    if ($this->object)
	return $this->object->GetContentType();
    
    return false;
 }
 
 function GetExtension() {
    if ($this->next) {
	$ext = $this->next->GetExtension();
	if ($ext) return $ext;
    }

    if ($this->object)
	return $this->object->GetExtension();

    return false;
 }
 
 function GetSpecials() {
    if ($this->object) {
	$myres = $this->object->GetSpecials();
    } else {
	$myres = false;
    }
    
    if ($this->next) {
	$res = $this->next->GetSpecials();
    } else {
	$res = false;
    }
    
    if ($res) {
	if (is_string($myres))
	    array_push($res, $myres);
	else if (is_array($myres))
	    $res = array_merge($res, $myres);
	else
	    throw new ADEIException(translate("Unsupported specials"));
	return $res;
    }
    
    if (is_string($myres)) return array($myres);
    return $myres;
 }
}


require("streamoutput.php");
require("streamfilter.php");
require("streamfilewriter.php");
require("streamfilereader.php");

?>