blob: 3f9731acf3eec7efb14243a82ba1cc1562923335 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package org.openslx.util;
import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class FsUtil
{
private static final Logger LOGGER = LogManager.getLogger( FsUtil.class );
public static String getRelativePath( File absolutePath, File parentDir )
{
String file;
String dir;
try {
file = absolutePath.getCanonicalPath();
dir = parentDir.getCanonicalPath() + File.separator;
} catch ( Exception e ) {
LOGGER.error( "Could not get relative path for " + absolutePath.toString(), e );
return null;
}
if ( !file.startsWith( dir ) )
return null;
return file.substring( dir.length() );
}
public static String sanitizeFileName( String fileName )
{
fileName = fileName.replaceAll( "[^a-zA-Z0-9_\\-]+", "_" );
if ( fileName.length() > 40 )
fileName = fileName.substring( 0, 40 );
return fileName;
}
}
|