@@ -144,12 +144,6 @@ cls.ResourceUtil.mime_type_map = {
144144 "application/x-silverlight-app" : "silverlight"
145145}
146146
147- cls . ResourceUtil . type_to_string_map = {
148- "css" : "CSS" ,
149- "pdf" : "PDF" ,
150- "postscript" : "PostScript"
151- } ;
152-
153147/**
154148 * Returns the most sensible way of getting this resource,
155149 * as datauri or string, based on the mime type.
@@ -188,55 +182,38 @@ cls.ResourceUtil.mime_to_type = function(mime, extension)
188182 }
189183}
190184
191- cls . ResourceUtil . path_to_type = function ( path )
185+ /**
186+ * Returns the most sensible type based on
187+ * the mimeType and extension of resource
188+ */
189+ cls . ResourceUtil . guess_type = function ( mime , extension )
192190{
193- if ( path )
194- {
195- var extension = path . slice ( path . lastIndexOf ( "." ) + 1 ) . toLowerCase ( ) ;
196- var query = extension . indexOf ( "?" ) ;
197- if ( query != - 1 )
198- extension = extension . slice ( 0 , query ) ;
199- var hash = extension . indexOf ( "#" ) ;
200- if ( hash != - 1 )
201- extension = extension . slice ( 0 , hash ) ;
202- return extension && this . extension_type_map [ extension ] ;
203- }
204- }
191+ // For "application/octet-stream" we check by extension even though we have a mime
192+ if ( ! mime || mime . toLowerCase ( ) === "application/octet-stream" )
193+ return this . extension_type_map [ extension ] ;
205194
206- cls . ResourceUtil . url_path = function ( url )
207- {
208- if ( ! url ) { return null ; }
209- var firstslash = url . replace ( "://" , "xxx" ) . indexOf ( "/" ) ;
210- var querystart = url . indexOf ( "?" ) ;
211- if ( querystart == - 1 ) { querystart = url . length ; }
212- var path = url . slice ( firstslash , querystart ) ;
213- return path ;
195+ return this . mime_to_type ( mime ) ;
214196}
215197
216- cls . ResourceUtil . url_filename = function ( url )
198+ /**
199+ * Returns meta_data of a cls.ResourceInfo
200+ */
201+ cls . ResourceUtil . get_meta_data = function ( resourceInfo )
217202{
218- var path = cls . ResourceUtil . url_path ( url ) ;
219- var lastslash = path . lastIndexOf ( "/" ) ;
220- if (
221- lastslash === - 1 || // no slash or
222- path === "/" // the path _is_ a slash means there is no file name
223- )
203+ var data = resourceInfo . data ;
204+ if ( ! data )
205+ return ;
206+
207+ if ( resourceInfo . type == 'image' )
224208 {
225- return null ;
209+ var i = new Image ( ) ;
210+ i . src = data . content . stringData ;
211+ if ( i . naturalWidth )
212+ return i . naturalWidth + '\u00D7' + i . naturalHeight ;
213+ else
214+ return 'vectorial image' ;
226215 }
227- else {
228- return path . slice ( lastslash + 1 ) ;
229- }
230- }
231-
232- cls . ResourceUtil . url_host = function ( url )
233- {
234- if ( ! url ) { return null ; }
235- var host = url . replace ( / \w + ?: \/ \/ / , "" ) ;
236- var firstslash = host . indexOf ( "/" ) ;
237- host = host . slice ( 0 , firstslash == - 1 ? host . length : firstslash ) ;
238- return host ;
239- }
216+ } ;
240217
241218cls . ResourceUtil . header_presets = [
242219 { name : ui_strings . S_NETWORK_HEADER_OVERRIDES_PRESET_NONE , headers : "" } ,
0 commit comments