Package muntjac :: Package terminal :: Module external_resource
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.external_resource

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  """For resources fetched from location specified by URLs.""" 
17   
18  from muntjac.service.file_type_resolver import FileTypeResolver 
19  from muntjac.terminal.resource import IResource 
20   
21   
22 -class ExternalResource(IResource):
23 """C{ExternalResource} implements source for resources fetched 24 from location specified by URLs. The resources are fetched directly by 25 the client terminal and are not fetched trough the terminal adapter. 26 27 @author: Vaadin Ltd. 28 @author: Richard Lincoln 29 @version: 1.1.2 30 """ 31
32 - def __init__(self, sourceURL, mimeType=None):
33 """Creates a new download component for downloading directly from 34 given URL. 35 36 @param sourceURL: 37 the source URL. 38 @param mimeType: 39 the MIME Type 40 """ 41 # Url of the download. 42 self._sourceURL = None 43 # MIME Type for the resource 44 self._mimeType = None 45 46 if mimeType is None: 47 if sourceURL is None: 48 raise RuntimeError('Source must be non-null') 49 self._sourceURL = sourceURL 50 else: 51 ExternalResource.__init__(self, sourceURL) 52 self._mimeType = mimeType
53 54
55 - def getURL(self):
56 """Gets the URL of the external resource. 57 58 @return: the URL of the external resource. 59 """ 60 return self._sourceURL
61 62
63 - def getMIMEType(self):
64 """Gets the MIME type of the resource. 65 66 @see: L{muntjac.terminal.resource.IResource.getMIMEType} 67 """ 68 if self._mimeType is None: 69 self._mimeType = FileTypeResolver.getMIMEType(self.getURL()) 70 return self._mimeType
71 72
73 - def setMIMEType(self, mimeType):
74 """Sets the MIME type of the resource.""" 75 self._mimeType = mimeType
76