1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """A resource provided to the client directly by the application."""
17
18 from muntjac.service.file_type_resolver import FileTypeResolver
19 from muntjac.terminal.application_resource import IApplicationResource
20 from muntjac.terminal.download_stream import DownloadStream
21
22
24 """C{StreamResource} is a resource provided to the client
25 directly by the application. The strean resource is fetched from URI
26 that is most often in the context of the application or window. The
27 resource is automatically registered to window in creation.
28
29 @author: Vaadin Ltd.
30 @author: Richard Lincoln
31 @version: 1.1.2
32 """
33
34 - def __init__(self, streamSource, filename, application):
35 """Creates a new stream resource for downloading from stream.
36
37 @param streamSource:
38 the source Stream.
39 @param filename:
40 the name of the file.
41 @param application:
42 the Application object.
43 """
44
45 self._streamSource = None
46
47
48 self._MIMEType = None
49
50
51 self._filename = None
52
53
54 self._application = application
55
56
57 self._bufferSize = 0
58
59
60 self._cacheTime = self.DEFAULT_CACHETIME
61
62 self.setFilename(filename)
63 self.setStreamSource(streamSource)
64
65 application.addResource(self)
66
67
69 """@see: IResource.getMIMEType"""
70 if self._MIMEType is not None:
71 return self._MIMEType
72 return FileTypeResolver.getMIMEType(self._filename)
73
74
76 """Sets the mime type of the resource.
77
78 @param MIMEType:
79 the MIME type to be set.
80 """
81 self._MIMEType = MIMEType
82
83
85 """Returns the source for this C{StreamResource}.
86 StreamSource is queried when the resource is about to be streamed
87 to the client.
88
89 @return: Source of the StreamResource.
90 """
91 return self._streamSource
92
93
95 """Sets the source for this C{StreamResource}.
96 C{StreamSource} is queried when the resource is
97 about to be streamed to the client.
98
99 @param streamSource:
100 the source to set.
101 """
102 self._streamSource = streamSource
103
104
106 """Gets the filename.
107
108 @return: the filename.
109 """
110 return self._filename
111
112
114 """Sets the filename.
115
116 @param filename:
117 the filename to set.
118 """
119 self._filename = filename
120
121
123 """@see: L{IApplicationResource.getApplication}"""
124 return self._application
125
126
137
138
140 return self._bufferSize
141
142
144 """Sets the size of the download buffer used for this resource.
145
146 @param bufferSize:
147 the size of the buffer in bytes.
148 """
149 self._bufferSize = bufferSize
150
151
153 return self._cacheTime
154
155
157 """Sets the length of cache expiration time.
158
159 This gives the adapter the possibility cache streams sent to
160 the client. The caching may be made in adapter or at the client
161 if the client supports caching. Zero or negative value disables
162 the caching of this stream.
163
164 @param cacheTime:
165 the cache time in milliseconds.
166 """
167 self._cacheTime = cacheTime
168
169
171 """Interface implemented by the source of a StreamResource.
172
173 @author: Vaadin Ltd.
174 @author: Richard Lincoln
175 @version: 1.1.2
176 """
177
179 """Returns new input stream that is used for reading the resource."""
180 pass
181