| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.mockftpserver.fake.filesystem; |
| 17 | |
|
| 18 | |
import org.mockftpserver.core.util.Assert; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public class WindowsFakeFileSystem extends AbstractFakeFileSystem { |
| 37 | |
|
| 38 | |
public static final char SEPARATOR = '\\'; |
| 39 | |
private static final String VALID_PATTERN = "\\p{Alpha}\\:" + "(\\\\|(\\\\[^\\\\\\:\\*\\?\\<\\>\\|\\\"]+)+)"; |
| 40 | |
//static final VALID_PATTERN = /\p{Alpha}\:(\\|(\\[^\\\:\*\?\<\>\|\"]+)+)/ |
| 41 | |
private static final String LAN_PREFIX = "\\\\"; |
| 42 | |
|
| 43 | |
/** |
| 44 | |
* Construct a new instance and initialize the directoryListingFormatter to a WindowsDirectoryListingFormatter. |
| 45 | |
*/ |
| 46 | 84 | public WindowsFakeFileSystem() { |
| 47 | 84 | this.setDirectoryListingFormatter(new WindowsDirectoryListingFormatter()); |
| 48 | 84 | } |
| 49 | |
|
| 50 | |
//------------------------------------------------------------------------- |
| 51 | |
// Abstract Or Overridden Method Implementations |
| 52 | |
//------------------------------------------------------------------------- |
| 53 | |
|
| 54 | |
/** |
| 55 | |
* Return the normalized and unique key used to access the file system entry. Windows is case-insensitive, |
| 56 | |
* so normalize all paths to lower-case. |
| 57 | |
* |
| 58 | |
* @param path - the path |
| 59 | |
* @return the corresponding normalized key |
| 60 | |
*/ |
| 61 | |
protected String getFileSystemEntryKey(String path) { |
| 62 | 1145 | return normalize(path).toLowerCase(); |
| 63 | |
} |
| 64 | |
|
| 65 | |
protected char getSeparatorChar() { |
| 66 | 8938 | return SEPARATOR; |
| 67 | |
} |
| 68 | |
|
| 69 | |
/** |
| 70 | |
* Return true if the specified path designates a valid (absolute) file path. For Windows |
| 71 | |
* paths, a path is valid if it starts with a drive specifier followed by |
| 72 | |
* '\' or '/', or if it starts with "\\". |
| 73 | |
* |
| 74 | |
* @param path - the path |
| 75 | |
* @return true if path is valid, false otherwise |
| 76 | |
* @throws AssertionError - if path is null |
| 77 | |
*/ |
| 78 | |
protected boolean isValidName(String path) { |
| 79 | |
// \/:*?"<>| |
| 80 | 333 | Assert.notNull(path, "path"); |
| 81 | 330 | String standardized = path.replace('/', '\\'); |
| 82 | 330 | return standardized.matches(VALID_PATTERN) || standardized.startsWith(LAN_PREFIX); |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
protected boolean isSeparator(char c) { |
| 92 | 37 | return c == '\\' || c == '/'; |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
protected boolean isRoot(String pathComponent) { |
| 99 | 477 | return pathComponent.indexOf(":") != -1; |
| 100 | |
} |
| 101 | |
|
| 102 | |
} |