Extract the final component of the given path which is assumed to be a base name and generate a ContextName from that base name. @param path The path that ends in a base name @return the ContextName generated from the given base name
(String path)
| 224 | * @return the {@link ContextName} generated from the given base name |
| 225 | */ |
| 226 | public static ContextName extractFromPath(String path) { |
| 227 | // Convert '\' to '/' |
| 228 | path = path.replace("\\", "/"); |
| 229 | // Remove trailing '/'. Use while just in case a value ends in /// |
| 230 | while (path.endsWith("/")) { |
| 231 | path = path.substring(0, path.length() - 1); |
| 232 | } |
| 233 | |
| 234 | int lastSegment = path.lastIndexOf('/'); |
| 235 | if (lastSegment > 0) { |
| 236 | path = path.substring(lastSegment + 1); |
| 237 | } |
| 238 | |
| 239 | return new ContextName(path, true); |
| 240 | } |
| 241 | } |