public static String prefixWithAndSuffixWithoutSlash(String path) { if(Strings.isEmpty(path)){ return path; } if(path.startsWith("/")){ return suffixWithoutSlash(path); }else{ return "/" + suffixWithoutSlash(path); } }
private int comparePaths(String p1, String p2) { String dir1 = Paths.getDirPath(p1); String dir2 = Paths.getDirPath(p2); String file1 = Paths.getFileName(p1); String file2 = Paths.getFileName(p2); if(dir1.equals(dir2)) { return result(file1.compareTo(file2)); }else if(dir1.startsWith(dir2)) { return -1; }else if(dir2.startsWith(dir1)) { return 1; }else { return result(dir1.compareTo(dir2)); } }
private String entityName(String filename) { String name = Paths.getFileNameWithoutExtension(filename); return namingStrategy.entityName(name); }
public static File createRelative(File parent, final String relativePath){ if(parent.isDirectory()) { return new File(Paths.suffixWithSlash(parent.getAbsolutePath()) + Paths.prefixWithoutSlash(relativePath)); }else{ return new File(Paths.getDirPath(parent.getAbsolutePath()) + Paths.prefixWithoutSlash(relativePath)); } }
/** * Creates a new http request of the given base url and relative path. */ default HttpRequest request(String baseUrl, String path) { return request(Paths.suffixWithoutSlash(baseUrl) + Paths.prefixWithSlash(path)); }
public static String prefixAndSuffixWithoutSlash(String path){ if(Strings.isEmpty(path)){ return path; } return suffixWithoutSlash(prefixWithoutSlash(path)); }
protected boolean doCheckOperationExists(RestdContext context, RouteBuilder r, Routes routes, boolean container) { final String verb = r.getMethod(); final String path = r.getPathTemplate().getTemplate(); final String fullPath = container ? path : Paths.suffixWithSlash(context.getApi().getBasePath()) + Paths.prefixWithoutSlash(path);
public CssUrlRewriter(String path, String css) { this.path = Paths.suffixWithSlash(path); this.css = css; this.chars = new StringBuilder(css); this.end = chars.length() - 1; this.pos = -1; }
String filename = Paths.getFileNameWithoutExtension(Paths.getFileName(relativePath)); String entityName = Strings.substringBefore(relativePath, "/"); String localeName = Locales.extractFromFilename(filename);
public static String path(String root, Resource file) { String childPath = Urls.decode(Paths.normalize(file.getFilepath())); root = Paths.prefixAndSuffixWithSlash(root); int index = childPath.indexOf(root); if(index <= 0) { throw new IllegalStateException("Invalid root '" + root + "' at '" + file.getURLString() + "'"); } String relativePath = Paths.prefixWithAndSuffixWithoutSlash(childPath.substring(index + root.length())); return Strings.removeEnd(relativePath, "/" + file.getFilename()); }
/** * This implementation returns the name of the file that this class path * resource refers to. * @see org.springframework.util.StringUtils#getFileName(String) */ @Override public String getFilename() { return Paths.getFileName(this.path); }
public SimpleAppResource(Resource resource, boolean defaultOverride, float order, String path) { this.resource = resource; this.defaultOverride = defaultOverride; this.order = order; this.path = Paths.prefixWithoutSlash(path); }
private static Resource initAppDirectoryByConfig() { String path = System.getProperty(PROP_DIR); if(!Strings.isEmpty(path)) { if(Paths.isExplicitRelativePath(path)) { path = Resources.createFileResource(System.getProperty("user.dir")).createRelative(path).getFilepath(); } if(Urls.isClasspath(path)) { return checkDir(Resources.getResource(Paths.suffixWithSlash(path)), "project"); }else { return checkDir(Resources.createFileResource(new File(path)), "project"); } } return null; }
/** * Create a new ClassPathResource with optional ClassLoader and Class. * Only for internal usage. * @param path relative or absolute path within the classpath * @param classLoader the class loader to load the resource with, if any * @param clazz the class to load resources with, if any */ protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) { this.path = Paths.normalize(path); this.classLoader = classLoader; this.clazz = clazz; }
public RestdModel(EntityMapping entityMapping, String path, Map<String,Object> attrs) { super(attrs); this.entityMapping = entityMapping; this.path = Paths.prefixWithAndSuffixWithoutSlash(path); }
@Override public SimpleFileResource createRelative(String relativePath) { String pathToUse = Paths.normalize(Paths.applyRelative(this.path1, relativePath)); return new SimpleFileResource(pathToUse); }
public static boolean mkdirs(File file) { String folder = Paths.getDirPath(file.getAbsolutePath()); return new File(folder).mkdirs(); }
protected String parseUrl(String url,ServerInfo serverInfo){ if(!needParse(url)){ return url; } URI uri = URI.create(Strings.replace(serverInfo.getServerUrl(), " ", "%20")); String resolvedUrl = Urls.resolveUrlExpr(url, uri); if(needParse(resolvedUrl)){ return serverInfo.getServerUrl()+Paths.prefixWithSlash(resolvedUrl); } return resolvedUrl; }
RemoteSettings settings = new RemoteSettings(); settings.setRemoteType(RemoteType.rest); settings.setEndpoint(Paths.suffixWithSlash(entity.getServiceUrl())); settings.setRelativePath(Paths.prefixWithoutSlash(entity.getServicePath())); em.setRemoteSettings(settings);
public static String prefixAndSuffixWithSlash(String path){ if(Strings.isEmpty(path)){ return path; } if(path.startsWith("/")){ return suffixWithSlash(path); }else{ return "/" + suffixWithSlash(path); } }