1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from muntjac.service.file_type_resolver import FileTypeResolver
17 from muntjac.terminal.application_resource import IApplicationResource
18 from muntjac.terminal.download_stream import DownloadStream
19
20
22 """C{ClassResource} is a named resource accessed with the
23 class loader.
24
25 This can be used to access resources such as icons, files, etc.
26
27 @author: Vaadin Ltd.
28 @author: Richard Lincoln
29 @version: 1.1.2
30 """
31
33 """Creates a new application resource instance. The resource id is
34 relative to the location of the application class.
35
36 @param args: tuple of the form
37 - (resourceName, application)
38 1. the Unique identifier of the resource within the application
39 2. the application this resource will be added to
40 - (associatedClass, resourceName, application)
41 1. the class of the which the resource is associated.
42 2. the Unique identifier of the resource within the application
43 3. the application this resource will be added to
44 """
45
46 self._bufferSize = 0
47
48
49 self._cacheTime = self.DEFAULT_CACHETIME
50
51
52 self._associatedClass = None
53
54
55 self._resourceName = None
56
57
58 self._application = None
59
60 nargs = len(args)
61 if nargs == 2:
62 resourceName, application = args
63 self._associatedClass = application.__class__
64 self._resourceName = resourceName
65 self._application = application
66 if resourceName is None:
67 raise ValueError
68 application.addResource(self)
69 elif nargs == 3:
70 associatedClass, resourceName, application = args
71 self._associatedClass = associatedClass
72 self._resourceName = resourceName
73 self._application = application
74 if (resourceName is None) or (associatedClass is None):
75 raise ValueError
76 application.addResource(self)
77 else:
78 raise ValueError, 'invalid number of arguments'
79
80
82 """Gets the MIME type of this resource.
83
84 @see: L{muntjac.terminal.resource.IResource.getMIMEType}
85 """
86 return FileTypeResolver.getMIMEType(self._resourceName)
87
88
90 """Gets the application of this resource.
91
92 @see: L{IApplicationResource.getApplication}
93 """
94 return self._application
95
96
98 """Gets the virtual filename for this resource.
99
100 @return: the file name associated to this resource.
101 @see: L{IApplicationResource.getFilename}
102 """
103 index = 0
104 idx = self._resourceName.find('/', index)
105 while idx > 0 and idx + 1 < len(self._resourceName):
106 index = idx + 1
107 idx = self._resourceName.find('/', index)
108 return self._resourceName[index:]
109
110
122
123
125 return self._bufferSize
126
127
129 """Sets the size of the download buffer used for this resource.
130
131 @param bufferSize:
132 the size of the buffer in bytes.
133 """
134 self._bufferSize = bufferSize
135
136
138 return self._cacheTime
139
140
142 """Sets the length of cache expiration time.
143
144 This gives the adapter the possibility cache streams sent to the
145 client. The caching may be made in adapter or at the client if the
146 client supports caching. Zero or negative value disables the caching
147 of this stream.
148
149 @param cacheTime:
150 the cache time in milliseconds.
151 """
152 self._cacheTime = cacheTime
153