Revision 1249 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/FileTools.java

View differences:

FileTools.java
2 2

  
3 3
import java.io.File;
4 4
import org.apache.commons.io.FilenameUtils;
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
5 7

  
6 8
public class FileTools {
9
    private static Logger logger = LoggerFactory.getLogger(FileTools.class);
7 10

  
8 11
	static File relativizeFile(File rootFolder, File file) {
9 12
		if (rootFolder == null) {
......
17 20
		// isDir = file.isDirectory();
18 21
		isDir = rootFolder.isDirectory();
19 22
		String basePath = rootFolder.getAbsolutePath();
23
                if( basePath == null ) {
24
                    logger.warn("Can't get absolute path, no relativize file '"+rootFolder.toString()+"'.");
25
                    return file;
26
                }
20 27
		
21 28
		String targetPath = FilenameUtils.normalize(file.getPath());
29
                if( targetPath == null ) {
30
                    logger.warn("Can't normalize path, no relativize file '"+file.getAbsolutePath()+"'.");
31
                    return file;
32
                }
22 33
		
23 34
		String pathSeparator = File.separator;
24 35
		// We need the -1 argument to split to make sure we get a trailing
25 36
		// "" token if the base ends in the path separator and is therefore
26 37
		// a directory. We require directory paths to end in the path
27 38
		// separator -- otherwise they are indistinguishable from files.
28
		String[] base = basePath.split(Pattern_quote(pathSeparator), -1);
29
		String[] target = targetPath.split(Pattern_quote(pathSeparator), 0);
39
                String pathSeparatorQuoted = Pattern_quote(pathSeparator);
30 40

  
41
		String[] base = basePath.split(pathSeparatorQuoted, -1);
42
		String[] target = targetPath.split(pathSeparatorQuoted, 0);
43

  
31 44
		// First get all the common elements. Store them as a string,
32 45
		// and also count how many of them there are.
33 46
		String common = "";

Also available in: Unified diff