UploadFileUtils { protected String removeFileName( String filename ) { if ( null != filename ) { int dotIndex = filename.indexOf( DOT ); if ( 0 < dotIndex ) { int len = filename.length(); ++dotIndex; if ( len > dotIndex ) { return filename.substring( dotIndex ).replaceAll( "[^a-zA-Z0-9_.-]", "_" ); } } return StringUtil.EMPTY_STRING; } return null; } UploadFileUtils( IPentahoSession sessionValue ); boolean process(); boolean process( InputStream inputStream ); boolean checkLimits( long itemSize ); boolean checkLimits( long itemSize, boolean compressed ); String getFileName(); void setFileName( String value ); boolean isShouldUnzip(); void setShouldUnzip( boolean value ); boolean isTemporary(); void setTemporary( boolean value ); void setWriter( Writer value ); Writer getWriter(); void setUploadedFileItem( FileItem value ); FileItem getUploadedFileItem(); String getPath(); File getPathDir(); String getRelativePath(); static final String DEFAULT_RELATIVE_UPLOAD_FILE_PATH; }
@Test public void testGetAllExtensions() throws Exception { UploadFileUtils testUtils = new UploadFileUtils( null ); assertNull( testUtils.removeFileName( null ) ); assertEquals( "", testUtils.removeFileName( "" ) ); assertEquals( "", testUtils.removeFileName( "aaaa" ) ); assertEquals( "", testUtils.removeFileName( " bb " ) ); assertEquals( "a", testUtils.removeFileName( "b.a" ) ); assertEquals( "b.a", testUtils.removeFileName( "c.b.a" ) ); assertEquals( "c.b.a", testUtils.removeFileName( "d.c.b.a" ) ); assertEquals( "_________-__________-_____test.csv", testUtils.removeFileName( "TestCSVspecialchar.$&#%^( )!- ;[ ]{ }`@-_+=',test.csv" ) ); assertEquals( "Tes____CSVspecialchar._________-__________-_____test.dat", testUtils.removeFileName( "_.Tes~ºª_CSVspecialchar.$&#%^( )!- ;[ ]{ }`@-_+=',test.dat" ) ); }