private String detectFileName ( Resource referencedResource , Resource ntFileResource , Resource ntResourceResource ) { // detect file name String fileName = null ; // if referenced resource is not the nt:file node check for <nodename>Name property if ( ntFileResource != null && ! referencedResource . equals ( ntFileResource ) ) { fileName = referencedResource . getValueMap ( ) . get ( ntFileResource . getName ( ) + "Name" , String . class ) ; } // if not nt:file node exists and the referenced resource is not the nt:resource node check for <nodename>Name property else if ( ntFileResource == null && ! referencedResource . equals ( ntResourceResource ) ) { fileName = referencedResource . getValueMap ( ) . get ( ntResourceResource . getName ( ) + "Name" , String . class ) ; } // otherwise use node name of nt:file resource if it exists else if ( ntFileResource != null ) { fileName = ntFileResource . getName ( ) ; } // make sure filename has an extension, otherwise build virtual file name if ( ! StringUtils . contains ( fileName , "." ) ) { fileName = null ; } // if no filename found detect extension from mime type and build virtual filename if ( StringUtils . isBlank ( fileName ) ) { String fileExtension = null ; if ( ntResourceResource != null ) { String mimeType = ntResourceResource . getValueMap ( ) . get ( JcrConstants . JCR_MIMETYPE , String . class ) ; if ( StringUtils . isNotEmpty ( mimeType ) && mimeTypeService != null ) { fileExtension = mimeTypeService . getExtension ( mimeType ) ; } } if ( StringUtils . isEmpty ( fileExtension ) ) { fileExtension = "bin" ; } fileName = "file." + fileExtension ; } return fileName ; }
Detect filename for inline binary .