private final String getFilename ( Context context , String pid , String dsid , Date asOfDateTime , String MIMETYPE ) throws Exception { String filename = "" ; String extension = "" ; // check sources in order for ( String source : m_datastreamFilenameSource . split ( " " ) ) { // try and get filename and extension from specified source if ( source . equals ( "rels" ) ) { filename = getFilenameFromRels ( context , pid , dsid , MIMETYPE ) ; if ( ! filename . isEmpty ( ) ) extension = getExtension ( filename , m_datastreamExtensionMappingRels , MIMETYPE ) ; } else { if ( source . equals ( "id" ) ) { filename = getFilenameFromId ( pid , dsid , MIMETYPE ) ; if ( ! filename . isEmpty ( ) ) extension = getExtension ( filename , m_datastreamExtensionMappingId , MIMETYPE ) ; } else { if ( source . equals ( "label" ) ) { filename = getFilenameFromLabel ( context , pid , dsid , asOfDateTime , MIMETYPE ) ; if ( ! filename . isEmpty ( ) ) extension = getExtension ( filename , m_datastreamExtensionMappingLabel , MIMETYPE ) ; } else { logger . warn ( "Unknown datastream filename source specified in datastreamFilenameSource in fedora.fcfg: " + source + ". Please specify zero or more of: rels id label" ) ; } } } // if we've got one by here, quit loop if ( ! filename . isEmpty ( ) ) break ; } // if not determined from above use the default if ( filename . isEmpty ( ) ) { filename = m_datastreamDefaultFilename ; extension = getExtension ( m_datastreamDefaultFilename , m_datastreamExtensionMappingDefault , MIMETYPE ) ; } // clean up filename - remove illegal chars if ( extension . isEmpty ( ) ) { return ILLEGAL_FILENAME_REGEX . matcher ( filename ) . replaceAll ( "" ) ; } else { return ILLEGAL_FILENAME_REGEX . matcher ( filename + "." + extension ) . replaceAll ( "" ) ; } }
Generate a filename and extension for a datastream based on configuration preferences . Filename can be based on a definition in RELS - INT the datastream label or the datastream ID . These sources can be specified in order of preference together with using a default filename . The extension is based on a mime - type - to - extension mapping configuration file ; alternatively if the filename determined already includes an extension that can be specified instead .